/// <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); } MonoBehaviour mb = callback.Target as MonoBehaviour; return(mTarget == mb && string.Equals(mMethodName, GetMethodName(callback))); #elif UNITY_FLASH return(callback == mCachedCallback); #else return(callback.Equals(mCachedCallback)); #endif } if (obj is UEventDelegate) { UEventDelegate del = obj as UEventDelegate; return(mTarget == del.mTarget && string.Equals(mMethodName, del.mMethodName)); } return(false); }
/// <summary> /// Assign a new event delegate. /// </summary> static public void Set(List <UEventDelegate> list, UEventDelegate del) { if (list != null) { list.Clear(); list.Add(del); } }
/// <summary> /// Assign a new event delegate. /// </summary> static public UEventDelegate Set(List <UEventDelegate> list, Callback callback) { if (list != null) { UEventDelegate del = new UEventDelegate(callback); list.Clear(); list.Add(del); return(del); } return(null); }
/// <summary> /// Remove an OnFinished delegate. Will work even while iterating through the list when the tweener has finished its operation. /// </summary> public void RemoveOnFinished(UEventDelegate del) { if (onFinished != null) { onFinished.Remove(del); } if (mTemp != null) { mTemp.Remove(del); } }
/// <summary> /// Execute an entire list of delegates. /// </summary> static public void Execute(List <UEventDelegate> list) { if (list != null) { for (int i = 0; i < list.Count;) { UEventDelegate 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; } } }
/// <summary> /// Convenience function to check if the specified list of delegates can be executed. /// </summary> static public bool IsValid(List <UEventDelegate> list) { if (list != null) { for (int i = 0, imax = list.Count; i < imax; ++i) { UEventDelegate del = list[i]; if (del != null && del.isValid) { return(true); } } } return(false); }
/// <summary> /// Remove an existing event delegate from the list. /// </summary> static public bool Remove(List <UEventDelegate> list, Callback callback) { if (list != null) { for (int i = 0, imax = list.Count; i < imax; ++i) { UEventDelegate del = list[i]; if (del != null && del.Equals(callback)) { list.RemoveAt(i); return(true); } } } return(false); }
/// <summary> /// Append a new event delegate to the list. /// </summary> static public UEventDelegate Add(List <UEventDelegate> list, Callback callback, bool oneShot) { if (list != null) { for (int i = 0, imax = list.Count; i < imax; ++i) { UEventDelegate del = list[i]; if (del != null && del.Equals(callback)) { return(del); } } UEventDelegate ed = new UEventDelegate(callback); ed.oneShot = oneShot; list.Add(ed); return(ed); } Debug.LogWarning("Attempting to add a callback to a list that's null"); return(null); }
/// <summary> /// Append a new event delegate to the list. /// </summary> static public void Add(List <UEventDelegate> list, UEventDelegate ev, bool oneShot) { if (ev.mRawDelegate || ev.target == null || string.IsNullOrEmpty(ev.methodName)) { Add(list, ev.mCachedCallback, oneShot); } else if (list != null) { for (int i = 0, imax = list.Count; i < imax; ++i) { UEventDelegate del = list[i]; if (del != null && del.Equals(ev)) { return; } } UEventDelegate copy = new UEventDelegate(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"); } }
/// <summary> /// Append a new event delegate to the list. /// </summary> static public void Add(List <UEventDelegate> list, UEventDelegate ev) { Add(list, ev, ev.oneShot); }
/// <summary> /// Convenience function -- add a new OnFinished event delegate (here for to be consistent with RemoveOnFinished). /// </summary> public void AddOnFinished(UEventDelegate del) { UEventDelegate.Add(onFinished, del); }
/// <summary> /// Convenience function -- set a new OnFinished event delegate (here for to be consistent with RemoveOnFinished). /// </summary> public void SetOnFinished(UEventDelegate del) { UEventDelegate.Set(onFinished, del); }
/// <summary> /// Update the tweening factor and call the virtual update function. /// </summary> void Update() { float delta = ignoreTimeScale ? URealTime.deltaTime : Time.deltaTime; float time = ignoreTimeScale ? URealTime.time : Time.time; if (!mStarted) { mStarted = true; mStartTime = time + delay; } if (time < mStartTime) { return; } // Advance the sampling factor mFactor += amountPerDelta * delta; // Loop style simply resets the play factor after it exceeds 1. if (style == Style.Loop) { if (mFactor > 1f) { mFactor -= Mathf.Floor(mFactor); } } else if (style == Style.PingPong) { // Ping-pong style reverses the direction if (mFactor > 1f) { mFactor = 1f - (mFactor - Mathf.Floor(mFactor)); mAmountPerDelta = -mAmountPerDelta; } else if (mFactor < 0f) { mFactor = -mFactor; mFactor -= Mathf.Floor(mFactor); mAmountPerDelta = -mAmountPerDelta; } } // If the factor goes out of range and this is a one-time tweening operation, disable the script if ((style == Style.Once) && (duration == 0f || mFactor > 1f || mFactor < 0f)) { mFactor = Mathf.Clamp01(mFactor); Sample(mFactor, true); // Disable this script unless the function calls above changed something if (duration == 0f || (mFactor == 1f && mAmountPerDelta > 0f || mFactor == 0f && mAmountPerDelta < 0f)) { enabled = false; } if (current == null) { current = this; if (onFinished != null) { mTemp = onFinished; onFinished = new List <UEventDelegate>(); // Notify the listener delegates UEventDelegate.Execute(mTemp); // Re-add the previous persistent delegates for (int i = 0; i < mTemp.Count; ++i) { UEventDelegate ed = mTemp[i]; if (ed != null && !ed.oneShot) { UEventDelegate.Add(onFinished, ed, ed.oneShot); } } mTemp = null; } // Deprecated legacy functionality support if (eventReceiver != null && !string.IsNullOrEmpty(callWhenFinished)) { eventReceiver.SendMessage(callWhenFinished, this, SendMessageOptions.DontRequireReceiver); } current = null; } } else { Sample(mFactor, false); } }