예제 #1
0
 /// <summary>If 'e' isn't null, this method removes 'method' from its <see cref="PersistentCallsList"/>.</summary>
 public static void RemovePersistentCall(ref UltEventBase e, Action method)
 {
     if (e != null)
     {
         e.RemovePersistentCall(method);
     }
 }
예제 #2
0
        /************************************************************************************************************************/

        /// <summary>Copies the contents of this the 'target' event to this event.</summary>
        public virtual void CopyFrom(UltEventBase target)
        {
            if (target._PersistentCalls == null)
            {
                _PersistentCalls = null;
            }
            else
            {
                if (_PersistentCalls == null)
                {
                    _PersistentCalls = new List <PersistentCall>();
                }
                else
                {
                    _PersistentCalls.Clear();
                }

                for (int i = 0; i < target._PersistentCalls.Count; i++)
                {
                    var call = new PersistentCall();
                    call.CopyFrom(target._PersistentCalls[i]);
                    _PersistentCalls.Add(call);
                }
            }

            DynamicCallsBase = target.DynamicCallsBase;

#if UNITY_EDITOR
            _DynamicCallInvocationList = target._DynamicCallInvocationList;
#endif
        }
예제 #3
0
        /************************************************************************************************************************/

        /// <summary>
        /// Acquire a delegate based on the <see cref="Target"/> and <see cref="MethodName"/> and invoke it.
        /// </summary>
        public object Invoke()
        {
            if (Method == null)
            {
                Debug.LogWarning("Attempted to Invoke a PersistentCall which couldn't find it's method: " + MethodName);
                return(null);
            }

            object[] parameters;
            if (_PersistentArguments != null && _PersistentArguments.Length > 0)
            {
                parameters = ArrayCache <object> .GetTempArray(_PersistentArguments.Length);

                for (int i = 0; i < parameters.Length; i++)
                {
                    parameters[i] = _PersistentArguments[i].Value;
                }
            }
            else
            {
                parameters = null;
            }

            UltEventBase.UpdateLinkedValueOffsets();

#if UNITY_EDITOR
            // Somehow Unity ends up getting a UnityEngine.Object which pretends to be null.
            // But only in the Editor. At runtime it properly deserialized the target as null.

            // When calling a static method it just gets ignored. But when calling a constructor with a target, it
            // attempts to apply it to the existing object, which won't work because it's the wrong type.

            if (_Method.IsConstructor)
            {
                return(_Method.Invoke(null, parameters));
            }
#endif

            return(_Method.Invoke(_Target, parameters));
        }