Example #1
0
        /// <summary>
        /// Assign a new event delegate.
        /// </summary>

        static public void Set(List <ThunderEvent> list, ThunderEvent del)
        {
            if (list != null)
            {
                list.Clear();
                list.Add(del);
            }
        }
Example #2
0
        /// <summary>
        /// Assign a new event delegate.
        /// </summary>

        static public ThunderEvent Set(List <ThunderEvent> list, Callback callback)
        {
            if (list != null)
            {
                ThunderEvent del = new ThunderEvent(callback);
                list.Clear();
                list.Add(del);
                return(del);
            }
            return(null);
        }
Example #3
0
        /// <summary>
        /// Execute an entire list of delegates.
        /// </summary>

        static public void Execute(List <ThunderEvent> list)
        {
            if (list != null)
            {
                int imax = list.Count;
                for (int i = 0; i < imax;)
                {
                    ThunderEvent del = list[i];

                    if (del != null)
                    {
#if !UNITY_EDITOR && !UNITY_FLASH
                        try
                        {
                            del.Execute();
                        }
                        catch (System.Exception ex)
                        {
                            if (ex.InnerException != null)
                            {
                                Debug.LogError(ex.InnerException.Message);
                            }
                            else
                            {
                                Debug.LogError(ex.Message);
                            }
                        }
#else
                        del.Execute();
#endif

                        if (i >= list.Count)
                        {
                            break;
                        }
                        if (list[i] != del)
                        {
                            continue;
                        }

                        if (del.oneShot)
                        {
                            list.RemoveAt(i);
                            continue;
                        }
                    }
                    ++i;
                }
            }
        }
Example #4
0
        /// <summary>
        /// Convenience function to check if the specified list of delegates can be executed.
        /// </summary>

        static public bool IsValid(List <ThunderEvent> list)
        {
            if (list != null)
            {
                ThunderEvent del = null;
                for (int i = 0, imax = list.Count; i < imax; ++i, del = null)
                {
                    del = list[i];
                    if (del != null && del.isValid)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Example #5
0
        /// <summary>
        /// Equality operator.
        /// </summary>

        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(!isValid);
            }

            if (obj is Callback)
            {
                Callback callback = obj as Callback;
#if REFLECTION_SUPPORT
                if (callback.Equals(mCachedCallback))
                {
                    return(true);
                }


                UnityEngine.Object target = callback.Target as UnityEngine.Object;
                return(mTarget == target && string.Equals(mMethodName, GetMethodName(callback)));
#elif UNITY_FLASH
                return(callback == mCachedCallback);
#else
                return(callback.Equals(mCachedCallback));
#endif
            }

            if (obj is Delegate)
            {
                Delegate callback = obj as Delegate;

                if (callback.Equals(mCachedCallback))
                {
                    return(true);
                }

                UnityEngine.Object target = callback.Target as UnityEngine.Object;
                return(mTarget == target && string.Equals(mMethodName, GetMethodName(callback)));
            }

            if (obj is ThunderEvent)
            {
                ThunderEvent del = obj as ThunderEvent;
                return(mTarget == del.mTarget && string.Equals(mMethodName, del.mMethodName));
            }
            return(false);
        }
Example #6
0
        /// <summary>
        /// Remove an existing event delegate from the list.
        /// </summary>

        static public bool Remove(List <ThunderEvent> list, ThunderEvent ev)
        {
            if (list != null)
            {
                ThunderEvent del = null;
                for (int i = 0, imax = list.Count; i < imax; ++i, del = null)
                {
                    del = list[i];

                    if (del != null && del.Equals(ev))
                    {
                        list.RemoveAt(i);
                        return(true);
                    }
                }
            }
            return(false);
        }
Example #7
0
        /// <summary>
        /// Append a new event delegate to the list.
        /// </summary>

        static public ThunderEvent Add(List <ThunderEvent> list, Delegate callback, bool oneShot)
        {
            if (list != null)
            {
                ThunderEvent del = null;
                for (int i = 0, imax = list.Count; i < imax; ++i, del = null)
                {
                    del = list[i];
                    if (del != null && del.Equals(callback))
                    {
                        return(del);
                    }
                }

                ThunderEvent ed = new ThunderEvent(callback);
                ed.oneShot = oneShot;
                list.Add(ed);
                return(ed);
            }
            Debug.LogWarning("Attempting to add a callback to a list that's null");
            return(null);
        }
Example #8
0
        /// <summary>
        /// Append a new event delegate to the list.
        /// </summary>

        static public void Add(List <ThunderEvent> list, ThunderEvent ev, bool oneShot)
        {
            if (ev.mRawDelegate || ev.target == null || string.IsNullOrEmpty(ev.methodName))
            {
                Add(list, ev.mCachedCallback, oneShot);
            }
            else if (list != null)
            {
                ThunderEvent del = null;
                for (int i = 0, imax = list.Count; i < imax; ++i, del = null)
                {
                    del = list[i];
                    if (del != null && del.Equals(ev))
                    {
                        return;
                    }
                }

                ThunderEvent copy = new ThunderEvent(ev.target, ev.methodName);
                copy.oneShot = oneShot;

                if (ev.mParameters != null && ev.mParameters.Length > 0)
                {
                    copy.mParameters = new Parameter[ev.mParameters.Length];
                    for (int i = 0; i < ev.mParameters.Length; ++i)
                    {
                        copy.mParameters[i] = ev.mParameters[i];
                    }
                }

                list.Add(copy);
            }
            else
            {
                Debug.LogWarning("Attempting to add a callback to a list that's null");
            }
        }
Example #9
0
        /// <summary>
        /// Append a new event delegate to the list.
        /// </summary>

        static public void Add(List <ThunderEvent> list, ThunderEvent ev)
        {
            Add(list, ev, ev.oneShot);
        }