/// <summary>This will reset the <b>CurrentTiming</b>, <b>CurrentQueue</b>, and <b>CurrentSpeed</b> values.</summary> public static void ResetState() { defaultQueue = null; ResetTiming(); ResetQueue(); ResetSpeed(); }
public static T Register <T>(Stack <T> pool, float duration) where T : LeanState, new() { // Make sure the transition manager exists if (Instances.Count == 0) { new GameObject("LeanTransition").AddComponent <LeanTransition>(); } // Setup initial data var state = pool.Count > 0 ? pool.Pop() : new T(); state.Age = -1.0f; state.Duration = duration; state.Skip = false; if (currentSpeed > 0.0f) { state.Duration /= currentSpeed; } state.Prev.Clear(); state.Next.Clear(); // Join to previous transition? if (currentQueue != null) { state.BeginAfter(currentQueue); currentQueue = defaultQueue; } // Make this the new head currentHead = state; // Register data with the correct list var finalUpdate = GetTiming(currentTiming); switch (finalUpdate) { case LeanTiming.UnscaledFixedUpdate: unscaledFixedUpdateStates.Add(state); break; case LeanTiming.UnscaledLateUpdate: unscaledLateUpdateStates.Add(state); break; case LeanTiming.UnscaledUpdate: unscaledUpdateStates.Add(state); break; case LeanTiming.Update: updateStates.Add(state); break; case LeanTiming.LateUpdate: lateUpdateStates.Add(state); break; case LeanTiming.FixedUpdate: fixedUpdateStates.Add(state); break; } return(state); }
public static LeanState Register(LeanState state, float duration) { state.Duration = duration; // Execute immediately? if (duration == 0.0f && state.Prev.Count == 0) { FinishState(state); if (previousState == state) { previousState = null; } return(null); } // Register for later execution? else { if (currentSpeed > 0.0f) { state.Duration /= currentSpeed; } // Convert currentTiming if it's set to default, then register the state in the correct list var finalUpdate = GetTiming(currentTiming); switch (finalUpdate) { case LeanTiming.UnscaledFixedUpdate: unscaledFixedUpdateStates.Add(state); break; case LeanTiming.UnscaledLateUpdate: unscaledLateUpdateStates.Add(state); break; case LeanTiming.UnscaledUpdate: unscaledUpdateStates.Add(state); break; case LeanTiming.Update: updateStates.Add(state); break; case LeanTiming.LateUpdate: lateUpdateStates.Add(state); break; case LeanTiming.FixedUpdate: fixedUpdateStates.Add(state); break; } } if (OnRegistered != null) { OnRegistered(state); } return(state); }
/// <summary>If a transition is being animated in the editor, then the target object may not update, so this method will automatically dirty it so that it will.</summary> private static void DirtyTarget(LeanState transition) { if (Application.isPlaying == false) { var targetField = transition.GetType().GetField("Target"); if (targetField != null) { var target = targetField.GetValue(transition) as Object; if (target != null) { EditorUtility.SetDirty(target); } } } }
private static void FinishState(LeanState state) { // Activate all chained states and clear them for (var j = state.Next.Count - 1; j >= 0; j--) { state.Next[j].Prev.Remove(state); } state.Next.Clear(); // Make sure we call update one final time with a progress value of exactly 1.0 if (state.Skip == false) { state.Update(1.0f); } #if UNITY_EDITOR DirtyTarget(state); #endif state.Despawn(); }
private void UpdateAll(List <LeanState> states, float delta) { currentHead = null; for (var i = states.Count - 1; i >= 0; i--) { var state = states[i]; // Only update if the previous transitions have finished if (state.Prev.Count == 0) { // If the transition age is negative, it hasn't started yet if (state.Age < 0.0f) { state.Age = 0.0f; // If this newly beginning transition is identical to an already registered one, mark the existing one as conflicting so it doesn't get updated RemoveConflictsBefore(states, state, i); // Begin the transition (this will often copy the current state of the variable that is being transitioned) state.Begin(); } // Age state.Age += delta; // Finished? if (state.Age >= state.Duration) { // Activate all chained states and clear them for (var j = state.Next.Count - 1; j >= 0; j--) { state.Next[j].Prev.Remove(state); } state.Next.Clear(); // Make sure we call update one final time with a progress value of exactly 1.0 if (state.Skip == false) { state.Update(1.0f); } #if UNITY_EDITOR DirtyTarget(state); #endif state.Despawn(); states.RemoveAt(i); } // Update else { if (state.Skip == false) { state.Update(state.Age / state.Duration); } #if UNITY_EDITOR DirtyTarget(state); #endif } } } }
/// <summary>This will reset any previously called <b>CurrentQueue</b> calls.</summary> public static void ResetQueue() { currentQueue = null; }
/// <summary>This allows you to specify which transition must finish before the next transition can begin.</summary> public static GameObject QueueTransition(this UnityEngine.GameObject target, LeanState beginAfter) { LeanTransition.CurrentQueue = beginAfter; return(target); }
/// <summary>This allows you to specify which transition must finish before the next transition can begin.</summary> public static T QueueTransition <T>(this T target, LeanState beginAfter) where T : Component { LeanTransition.CurrentQueue = beginAfter; return(target); }
/// <summary>If you want this transition to begin after another completes, then call this method.</summary> public void BeginAfter(LeanState previousState) { Prev.Add(previousState); previousState.Next.Add(this); }
private void HandleFinished(LeanState state) { states.Remove(state); }
private void HandleRegistered(LeanState state) { states.Add(state); }