<commit_before>﻿/*
The MIT License (MIT)

Copyright (c) 2016 <NAME> Entertainment

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

using UnityEngine.Events;

#if UNITY_EDITOR

using UnityEditor.Events;

#endif

namespace RoaringFangs.Utility
{
    public static class Events
    {
        #region Add

        public static void AddListenerAuto(UnityEvent @event, UnityAction listener)
        {
#if UNITY_EDITOR
            UnityEventTools.AddPersistentListener(@event, listener);
#else
            @event.AddListener(listener);
#endif
        }

        public static void AddListenerAuto<T0>(UnityEvent<T0> @event, UnityAction<T0> listener)
        {
#if UNITY_EDITOR
            UnityEventTools.AddPersistentListener(@event, listener);
#else
            @event.AddListener(listener);
#endif
        }

        public static void AddListenerAuto<T0, T1>(UnityEvent<T0, T1> @event, UnityAction<T0, T1> listener)
        {
#if UNITY_EDITOR
            UnityEventTools.AddPersistentListener(@event, listener);
#else
            @event.AddListener(listener);
#endif
        }

        public static void AddListenerAuto<T0, T1, T2>(UnityEvent<T0, T1, T2> @event, UnityAction<T0, T1, T2> listener)
        {
#if UNITY_EDITOR
            UnityEventTools.AddPersistentListener(@event, listener);
#else
            @event.AddListener(listener);
#endif
        }

        public static void AddListenerAuto<T0, T1, T2, T3>(UnityEvent<T0, T1, T2, T3> @event, UnityAction<T0, T1, T2, T3> listener)
        {
#if UNITY_EDITOR
            UnityEventTools.AddPersistentListener(@event, listener);
#else
            @event.AddListener(listener);
#endif
        }

        #endregion Add

        #region Remove

        public static void RemoveListenerAuto(UnityEvent @event, UnityAction listener)
        {
#if UNITY_EDITOR
            UnityEventTools.RemovePersistentListener(@event, listener);
#else
            @event.RemoveListener(listener);
#endif
        }

        public static void RemoveListenerAuto<T0>(UnityEvent<T0> @event, UnityAction<T0> listener)
        {
#if UNITY_EDITOR
            UnityEventTools.RemovePersistentListener(@event, listener);
#else
            @event.RemoveListener(listener);
#endif
        }

        public static void RemoveListenerAuto<T0, T1>(UnityEvent<T0, T1> @event, UnityAction<T0, T1> listener)
        {
#if UNITY_EDITOR
            UnityEventTools.RemovePersistentListener(@event, listener);
#else
            @event.RemoveListener(listener);
#endif
        }

        public static void RemoveListenerAuto<T0, T1, T2>(UnityEvent<T0, T1, T2> @event, UnityAction<T0, T1, T2> listener)
        {
#if UNITY_EDITOR
            UnityEventTools.RemovePersistentListener(@event, listener);
#else
            @event.RemoveListener(listener);
#endif
        }

        public static void RemoveListenerAuto<T0, T1, T2, T3>(UnityEvent<T0, T1, T2, T3> @event, UnityAction<T0, T1, T2, T3> listener)
        {
#if UNITY_EDITOR
            UnityEventTools.RemovePersistentListener(@event, listener);
#else
            @event.RemoveListener(listener);
#endif
        }

        #endregion Remove
    }
}<commit_msg>RoaringFangs.Events improvements Added fault tolerance for adding/removing event handlers that can't normally be added as persistent events in the editor.<commit_after>﻿/*
The MIT License (MIT)

Copyright (c) 2016 <NAME> Entertainment

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

using UnityEngine.Events;
using System;
using UnityEngine;

#if UNITY_EDITOR

using UnityEditor.Events;

#endif

namespace RoaringFangs.Utility
{
    public static class Events
    {
        private static readonly string MessageWarnFallbackAdd =
@"Attempted to add event listener with non-UnityEngine.Object target to UnityEvent.
AddListenerAuto will use non-persistent fallback.";

        private static readonly string MessageWarnFallbackRemove =
@"Attempted to remove event listener with non-UnityEngine.Object target to UnityEvent.
AddListenerAuto will use non-persistent fallback for.";

        #region Add

        public static void AddListenerAuto(UnityEvent @event, UnityAction listener)
        {
#if UNITY_EDITOR
            try
            {
                UnityEventTools.AddPersistentListener(@event, listener);
            }
            catch(ArgumentException)
            {
                Debug.LogWarning(MessageWarnFallbackAdd);
                @event.AddListener(listener);
            }
#else
            @event.AddListener(listener);
#endif
        }

        public static void AddListenerAuto<T0>(UnityEvent<T0> @event, UnityAction<T0> listener)
        {
#if UNITY_EDITOR
            try
            {
                UnityEventTools.AddPersistentListener(@event, listener);
            }
            catch (ArgumentException)
            {
                Debug.LogWarning(MessageWarnFallbackAdd);
                @event.AddListener(listener);
            }
#else
            @event.AddListener(listener);
#endif
        }

        public static void AddListenerAuto<T0, T1>(UnityEvent<T0, T1> @event, UnityAction<T0, T1> listener)
        {
#if UNITY_EDITOR
            try
            {
                UnityEventTools.AddPersistentListener(@event, listener);
            }
            catch (ArgumentException)
            {
                Debug.LogWarning(MessageWarnFallbackAdd);
                @event.AddListener(listener);
            }
#else
            @event.AddListener(listener);
#endif
        }

        public static void AddListenerAuto<T0, T1, T2>(UnityEvent<T0, T1, T2> @event, UnityAction<T0, T1, T2> listener)
        {
#if UNITY_EDITOR
            try
            {
                UnityEventTools.AddPersistentListener(@event, listener);
            }
            catch (ArgumentException)
            {
                Debug.LogWarning(MessageWarnFallbackAdd);
                @event.AddListener(listener);
            }
#else
            @event.AddListener(listener);
#endif
        }

        public static void AddListenerAuto<T0, T1, T2, T3>(UnityEvent<T0, T1, T2, T3> @event, UnityAction<T0, T1, T2, T3> listener)
        {
#if UNITY_EDITOR
            try
            {
                UnityEventTools.AddPersistentListener(@event, listener);
            }
            catch (ArgumentException)
            {
                Debug.LogWarning(MessageWarnFallbackAdd);
                @event.AddListener(listener);
            }
#else
            @event.AddListener(listener);
#endif
        }

        #endregion Add

        #region Remove

        public static void RemoveListenerAuto(UnityEvent @event, UnityAction listener)
        {
#if UNITY_EDITOR
            try
            {
                UnityEventTools.RemovePersistentListener(@event, listener);
            }
            catch (ArgumentException)
            {
                Debug.LogWarning(MessageWarnFallbackRemove);
                @event.RemoveListener(listener);
            }
#else
            @event.RemoveListener(listener);
#endif
        }

        public static void RemoveListenerAuto<T0>(UnityEvent<T0> @event, UnityAction<T0> listener)
        {
#if UNITY_EDITOR
            try
            {
                UnityEventTools.RemovePersistentListener(@event, listener);
            }
            catch (ArgumentException)
            {
                Debug.LogWarning(MessageWarnFallbackRemove);
                @event.RemoveListener(listener);
            }
#else
            @event.RemoveListener(listener);
#endif
        }

        public static void RemoveListenerAuto<T0, T1>(UnityEvent<T0, T1> @event, UnityAction<T0, T1> listener)
        {
#if UNITY_EDITOR
            try
            {
                UnityEventTools.RemovePersistentListener(@event, listener);
            }
            catch (ArgumentException)
            {
                Debug.LogWarning(MessageWarnFallbackRemove);
                @event.RemoveListener(listener);
            }
#else
            @event.RemoveListener(listener);
#endif
        }

        public static void RemoveListenerAuto<T0, T1, T2>(UnityEvent<T0, T1, T2> @event, UnityAction<T0, T1, T2> listener)
        {
#if UNITY_EDITOR
            try
            {
                UnityEventTools.RemovePersistentListener(@event, listener);
            }
            catch (ArgumentException)
            {
                Debug.LogWarning(MessageWarnFallbackRemove);
                @event.RemoveListener(listener);
            }
#else
            @event.RemoveListener(listener);
#endif
        }

        public static void RemoveListenerAuto<T0, T1, T2, T3>(UnityEvent<T0, T1, T2, T3> @event, UnityAction<T0, T1, T2, T3> listener)
        {
#if UNITY_EDITOR
            try
            {
                UnityEventTools.RemovePersistentListener(@event, listener);
            }
            catch (ArgumentException)
            {
                Debug.LogWarning(MessageWarnFallbackRemove);
                @event.RemoveListener(listener);
            }
#else
            @event.RemoveListener(listener);
#endif
        }

        #endregion Remove
    }
}
{'fraction_non_alphanumeric': 0.07867307169400889, 'fraction_numerical': 0.01160155895948518, 'mean_word_length': 2.423518461061123, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '113163', 'n_tokens_mistral': 3051, 'n_tokens_neox': 2897, 'n_words': 851}