diff --git a/UI Auto Animation/Assets/UI Auto Animation/Scripts/UIAutoAnimation.cs b/UI Auto Animation/Assets/UI Auto Animation/Scripts/UIAutoAnimation.cs
index aada739..2d63ed6 100644
--- a/UI Auto Animation/Assets/UI Auto Animation/Scripts/UIAutoAnimation.cs
+++ b/UI Auto Animation/Assets/UI Auto Animation/Scripts/UIAutoAnimation.cs
@@ -27,34 +27,71 @@ public void EntranceAnimation()
{
//Stop any running animation before triggering a new one
StopAllCoroutines();
- StartCoroutine(EntranceAlphaEnumeration());
- StartCoroutine(EntrancePositionEnumeration());
- StartCoroutine(EntranceScaleEnumeration());
- StartCoroutine(EntranceRotationEnumeration());
- AutoTriggerCalculation(animationEntrancePresets);
+ var activeComponentList = GetActiveComponentList();
+ var activeIndices = GetActiveComponentIndexList();
+
+ StartCoroutine(EntranceAlphaEnumeration(activeComponentList, activeIndices));
+ StartCoroutine(EntrancePositionEnumeration(activeComponentList, activeIndices));
+ StartCoroutine(EntranceScaleEnumeration(activeComponentList, activeIndices));
+ StartCoroutine(EntranceRotationEnumeration(activeComponentList, activeIndices));
+
+ AutoTriggerCalculation(animationEntrancePresets, activeComponentList);
}
+
public void ExitAnimation()
{
//Stop any running animation before triggering a new one
StopAllCoroutines();
- StartCoroutine(ExitAlphaEnumeration());
- StartCoroutine(ExitPositionEnumeration());
- StartCoroutine(ExitScaleEnumeration());
- StartCoroutine(ExitRotationEnumeration());
- AutoTriggerCalculation(animationExitPresets);
+ var activeComponentList = GetActiveComponentList();
+ var activeIndices = GetActiveComponentIndexList();
+
+ StartCoroutine(ExitAlphaEnumeration(activeComponentList, activeIndices));
+ StartCoroutine(ExitPositionEnumeration(activeComponentList, activeIndices));
+ StartCoroutine(ExitScaleEnumeration(activeComponentList, activeIndices));
+ StartCoroutine(ExitRotationEnumeration(activeComponentList, activeIndices));
+
+ AutoTriggerCalculation(animationExitPresets, activeComponentList);
}
+ ///
+ /// Get the list of components on active game objects
+ ///
+ /// Filtered component list
+ private List GetActiveComponentList()
+ {
+ // returns empty list if no active component is found
+ return componentList.FindAll(c => c.gameObject.activeSelf);
+ }
+
+ ///
+ /// Get list of active component indices.
+ /// This is used to index active components in global lists
+ /// such as rectTransformList, originalPosition, etc.
+ ///
+ /// List of indices
+ private List GetActiveComponentIndexList()
+ {
+ List activeComponentIndexList = new List();
+ for (int i = 0; i < componentList.Count; i++)
+ {
+ if (componentList[i].gameObject.activeSelf)
+ {
+ activeComponentIndexList.Add(i);
+ }
+ }
+ return activeComponentIndexList;
+ }
#region Enumeration Functions
- private IEnumerator EntranceAlphaEnumeration()
+ private IEnumerator EntranceAlphaEnumeration(List activeComponentList, List activeIndices)
{
- if (componentList.Count > 0 && animationEntrancePresets.useAlphaAnimation == true)
+ if (activeComponentList.Count > 0 && animationEntrancePresets.useAlphaAnimation == true)
{
/// Set starting state where the UI is invisible
- SetAllColorAlpha_Zero();
+ SetAllColorAlpha_Zero(activeComponentList);
/// Delay the animation
yield return new WaitForSeconds(animationEntrancePresets.alphaDelay);
@@ -62,22 +99,22 @@ private IEnumerator EntranceAlphaEnumeration()
/// Calculate delay per element
/// The top-most UI on the list gets 0 second delay.
/// Each subsequent element gets delayed by the amount.
- float[] delayPerItem = CalculateDelayPerItem(DelayPerItemType.TopToBottom, animationEntrancePresets.delayPerElementAlpha);
+ float[] delayPerItem = CalculateDelayPerItem(activeComponentList, DelayPerItemType.TopToBottom, animationEntrancePresets.delayPerElementAlpha);
/// Keep track of the time for each UI on the list
/// because each UI has a different starting time based on the delay
- float[] elapsedTime = new float[componentList.Count];
+ float[] elapsedTime = new float[activeComponentList.Count];
/// Animate the fade in animation
- while (elapsedTime[componentList.Count - 1] < animationEntrancePresets.alphaDuration)
+ while (elapsedTime[activeComponentList.Count - 1] < animationEntrancePresets.alphaDuration)
{
- for (int i = 0; i < componentList.Count; i++)
+ for (int i = 0; i < activeComponentList.Count; i++)
{
//Don't do anything when the animation for this item is already finished.
if (elapsedTime[i] >= animationEntrancePresets.alphaDuration)
{
//Set its final state
- SetColorAlpha(componentList[i], originalAlpha[i]);
+ SetColorAlpha(activeComponentList[i], originalAlpha[activeIndices[i]]);
continue;
}
@@ -94,8 +131,8 @@ private IEnumerator EntranceAlphaEnumeration()
//Calculate current alpha
float curveValue = animationEntrancePresets.curveAlpha.Evaluate(t);
- float currentAlpha = Mathf.Lerp(0, originalAlpha[i], curveValue);
- SetColorAlpha(componentList[i], currentAlpha);
+ float currentAlpha = Mathf.Lerp(0, originalAlpha[activeIndices[i]], curveValue);
+ SetColorAlpha(activeComponentList[i], currentAlpha);
elapsedTime[i] += Time.deltaTime;
}
@@ -108,7 +145,7 @@ private IEnumerator EntranceAlphaEnumeration()
SetAllColorAlpha_Original();
}
- private IEnumerator ExitAlphaEnumeration()
+ private IEnumerator ExitAlphaEnumeration(List activeComponentList, List activeIndices)
{
if (componentList.Count > 0 && animationExitPresets.useAlphaAnimation == true)
{
@@ -121,22 +158,22 @@ private IEnumerator ExitAlphaEnumeration()
/// Calculate delay per element
/// The bottom-most UI on the list gets 0 second delay.
/// Each subsequent element gets delayed by the amount.
- float[] delayPerItem = CalculateDelayPerItem(DelayPerItemType.BottomToTop, animationExitPresets.delayPerElementAlpha);
+ float[] delayPerItem = CalculateDelayPerItem(activeComponentList, DelayPerItemType.BottomToTop, animationExitPresets.delayPerElementAlpha);
/// Keep track of the time for each UI on the list
/// because each UI has a different starting time based on the delay
- float[] elapsedTime = new float[componentList.Count];
+ float[] elapsedTime = new float[activeComponentList.Count];
/// Animate the fade out animation
while (elapsedTime[0] < animationExitPresets.alphaDuration)
{
- for (int i = 0; i < componentList.Count; i++)
+ for (int i = 0; i < activeComponentList.Count; i++)
{
//Don't do anything when the animation for this item is already finished.
if (elapsedTime[i] > animationExitPresets.alphaDuration)
{
//Set its final state
- SetColorAlpha(componentList[i], 0);
+ SetColorAlpha(activeComponentList[i], 0);
continue;
}
@@ -152,8 +189,8 @@ private IEnumerator ExitAlphaEnumeration()
//Calculate current alpha
float curveValue = animationEntrancePresets.curveAlpha.Evaluate(t);
- float currentAlpha = Mathf.Lerp(originalAlpha[i], 0, curveValue);
- SetColorAlpha(componentList[i], currentAlpha);
+ float currentAlpha = Mathf.Lerp(originalAlpha[activeIndices[i]], 0, curveValue);
+ SetColorAlpha(activeComponentList[i], currentAlpha);
elapsedTime[i] += Time.deltaTime;
}
@@ -162,42 +199,42 @@ private IEnumerator ExitAlphaEnumeration()
//There are always inaccuracies when dealing with float values
//So to keep it safe, when the final loop is done, set everything to its final state.
- SetAllColorAlpha_Zero();
+ SetAllColorAlpha_Zero(activeComponentList);
}
}
- private IEnumerator EntrancePositionEnumeration()
+ private IEnumerator EntrancePositionEnumeration(List activeComponentList, List activeIndices)
{
- if (componentList.Count > 0 && animationEntrancePresets.usePositionAnimation == true)
+ if (activeComponentList.Count > 0 && animationEntrancePresets.usePositionAnimation == true)
{
/// Set starting state where the UI is invisible
- SetAllPosition_Offset(animationEntrancePresets);
+ SetAllPosition_Offset(animationEntrancePresets, activeIndices);
/// Delay the animation
yield return new WaitForSeconds(animationEntrancePresets.positionDelay);
- Vector2[] offsetPositionList = CreateOffsetPositionList(animationEntrancePresets);
+ Vector2[] offsetPositionList = CreateOffsetPositionList(animationEntrancePresets, activeIndices);
/// Calculate delay per element
/// The top-most UI on the list gets 0 second delay.
/// Each subsequent element gets delayed by the amount.
- float[] delayPerItem = CalculateDelayPerItem(DelayPerItemType.TopToBottom, animationEntrancePresets.delayPerElementPosition);
+ float[] delayPerItem = CalculateDelayPerItem(activeComponentList, DelayPerItemType.TopToBottom, animationEntrancePresets.delayPerElementPosition);
/// Keep track of the time for each UI on the list
/// because each UI has a different starting time based on the delay
- float[] elapsedTime = new float[componentList.Count];
+ float[] elapsedTime = new float[activeComponentList.Count];
/// Animate the fade in animation
- while (elapsedTime[componentList.Count - 1] < animationEntrancePresets.positionDuration)
+ while (elapsedTime[activeComponentList.Count - 1] < animationEntrancePresets.positionDuration)
{
- for (int i = 0; i < componentList.Count; i++)
+ for (int i = 0; i < activeComponentList.Count; i++)
{
//Don't do anything when the animation for this item is already finished.
if (elapsedTime[i] > animationEntrancePresets.positionDuration)
{
//Set its final state
- SetPosition(rectTransformList[i], originalPosition[i]);
+ SetPosition(rectTransformList[activeIndices[i]], originalPosition[activeIndices[i]]);
continue;
}
@@ -214,8 +251,8 @@ private IEnumerator EntrancePositionEnumeration()
//Calculate current position
float curveValue = animationEntrancePresets.curvePosition.Evaluate(t);
- Vector2 currentPosition = Vector2.Lerp(offsetPositionList[i], originalPosition[i], curveValue);
- SetPosition(rectTransformList[i], currentPosition);
+ Vector2 currentPosition = Vector2.Lerp(offsetPositionList[i], originalPosition[activeIndices[i]], curveValue);
+ SetPosition(rectTransformList[activeIndices[i]], currentPosition);
elapsedTime[i] += Time.deltaTime;
}
@@ -231,9 +268,9 @@ private IEnumerator EntrancePositionEnumeration()
ResetAllLayoutGroup();
}
- private IEnumerator ExitPositionEnumeration()
+ private IEnumerator ExitPositionEnumeration(List activeComponentList, List activeIndices)
{
- if (componentList.Count > 0 && animationExitPresets.usePositionAnimation == true)
+ if (activeComponentList.Count > 0 && animationExitPresets.usePositionAnimation == true)
{
/// Set starting state where the UI is invisible
SetAllPosition_Original();
@@ -242,27 +279,27 @@ private IEnumerator ExitPositionEnumeration()
yield return new WaitForSeconds(animationExitPresets.positionDelay);
- Vector2[] offsetPositionList = CreateOffsetPositionList(animationExitPresets);
+ Vector2[] offsetPositionList = CreateOffsetPositionList(animationExitPresets, activeIndices);
/// Calculate delay per element
/// The bottom-most UI on the list gets 0 second delay.
/// Each subsequent element gets delayed by the amount.
- float[] delayPerItem = CalculateDelayPerItem(DelayPerItemType.BottomToTop, animationExitPresets.delayPerElementPosition);
+ float[] delayPerItem = CalculateDelayPerItem(activeComponentList, DelayPerItemType.BottomToTop, animationExitPresets.delayPerElementPosition);
/// Keep track of the time for each UI on the list
/// because each UI has a different starting time based on the delay
- float[] elapsedTime = new float[componentList.Count];
+ float[] elapsedTime = new float[activeComponentList.Count];
/// Animate the fade out animation
while (elapsedTime[0] < animationExitPresets.positionDuration)
{
- for (int i = 0; i < componentList.Count; i++)
+ for (int i = 0; i < activeComponentList.Count; i++)
{
//Don't do anything when the animation for this item is already finished.
if (elapsedTime[i] > animationExitPresets.positionDuration)
{
//Set its final state
- SetPosition(rectTransformList[i], offsetPositionList[i]);
+ SetPosition(rectTransformList[activeIndices[i]], offsetPositionList[i]);
continue;
}
@@ -278,8 +315,8 @@ private IEnumerator ExitPositionEnumeration()
//Calculate current position
float curveValue = animationExitPresets.curvePosition.Evaluate(t);
- Vector2 currentPosition = Vector2.Lerp(originalPosition[i], offsetPositionList[i], curveValue);
- SetPosition(rectTransformList[i], currentPosition);
+ Vector2 currentPosition = Vector2.Lerp(originalPosition[activeIndices[i]], offsetPositionList[i], curveValue);
+ SetPosition(rectTransformList[activeIndices[i]], currentPosition);
elapsedTime[i] += Time.deltaTime;
}
@@ -290,43 +327,43 @@ private IEnumerator ExitPositionEnumeration()
//There are always inaccuracies when dealing with float values
//So to keep it safe, when the final loop is done, set everything to its final state.
- SetAllPosition_Offset(animationExitPresets);
+ SetAllPosition_Offset(animationExitPresets, activeIndices);
ResetAllLayoutGroup();
}
}
- private IEnumerator EntranceScaleEnumeration()
+ private IEnumerator EntranceScaleEnumeration(List activeComponentList, List activeIndices)
{
- if (componentList.Count > 0 && animationEntrancePresets.useScaleAnimation == true)
+ if (activeComponentList.Count > 0 && animationEntrancePresets.useScaleAnimation == true)
{
/// Set starting state where the UI is invisible
- SetAllScale_Offset(animationEntrancePresets);
+ SetAllScale_Offset(animationEntrancePresets, activeIndices);
/// Delay the animation
yield return new WaitForSeconds(animationEntrancePresets.scaleDelay);
- Vector3[] offsetScaleList = CreateOffsetScaleList(animationEntrancePresets);
+ Vector3[] offsetScaleList = CreateOffsetScaleList(animationEntrancePresets, activeIndices);
/// Calculate delay per element
/// The top-most UI on the list gets 0 second delay.
/// Each subsequent element gets delayed by the amount.
- float[] delayPerItem = CalculateDelayPerItem(DelayPerItemType.TopToBottom, animationEntrancePresets.delayPerElementScale);
+ float[] delayPerItem = CalculateDelayPerItem(activeComponentList, DelayPerItemType.TopToBottom, animationEntrancePresets.delayPerElementScale);
/// Keep track of the time for each UI on the list
/// because each UI has a different starting time based on the delay
- float[] elapsedTime = new float[componentList.Count];
+ float[] elapsedTime = new float[activeComponentList.Count];
/// Animate the fade in animation
- while (elapsedTime[componentList.Count - 1] < animationEntrancePresets.scaleDuration)
+ while (elapsedTime[activeComponentList.Count - 1] < animationEntrancePresets.scaleDuration)
{
- for (int i = 0; i < componentList.Count; i++)
+ for (int i = 0; i < activeComponentList.Count; i++)
{
//Don't do anything when the animation for this item is already finished.
if (elapsedTime[i] > animationEntrancePresets.scaleDuration)
{
//Set its final state
- SetScale(rectTransformList[i], originalScale[i]);
+ SetScale(rectTransformList[activeIndices[i]], originalScale[activeIndices[i]]);
continue;
}
@@ -343,8 +380,8 @@ private IEnumerator EntranceScaleEnumeration()
//Calculate current scale
float curveValue = animationEntrancePresets.curveScale.Evaluate(t);
- Vector3 currentScale = Vector3.Lerp(offsetScaleList[i], originalScale[i], curveValue);
- SetScale(rectTransformList[i], currentScale);
+ Vector3 currentScale = Vector3.Lerp(offsetScaleList[i], originalScale[activeIndices[i]], curveValue);
+ SetScale(rectTransformList[activeIndices[i]], currentScale);
elapsedTime[i] += Time.deltaTime;
}
@@ -358,9 +395,9 @@ private IEnumerator EntranceScaleEnumeration()
SetAllScale_Original();
}
- private IEnumerator ExitScaleEnumeration()
+ private IEnumerator ExitScaleEnumeration(List activeComponentList, List activeIndices)
{
- if (componentList.Count > 0 && animationExitPresets.useScaleAnimation == true)
+ if (activeComponentList.Count > 0 && animationExitPresets.useScaleAnimation == true)
{
/// Set starting state where the UI is invisible
SetAllScale_Original();
@@ -369,27 +406,27 @@ private IEnumerator ExitScaleEnumeration()
yield return new WaitForSeconds(animationExitPresets.scaleDelay);
- Vector3[] offsetScaleList = CreateOffsetScaleList(animationExitPresets);
+ Vector3[] offsetScaleList = CreateOffsetScaleList(animationExitPresets, activeIndices);
/// Calculate delay per element
/// The bottom-most UI on the list gets 0 second delay.
/// Each subsequent element gets delayed by the amount.
- float[] delayPerItem = CalculateDelayPerItem(DelayPerItemType.BottomToTop, animationExitPresets.delayPerElementScale);
+ float[] delayPerItem = CalculateDelayPerItem(activeComponentList, DelayPerItemType.BottomToTop, animationExitPresets.delayPerElementScale);
/// Keep track of the time for each UI on the list
/// because each UI has a different starting time based on the delay
- float[] elapsedTime = new float[componentList.Count];
+ float[] elapsedTime = new float[activeComponentList.Count];
/// Animate the fade out animation
while (elapsedTime[0] < animationExitPresets.scaleDuration)
{
- for (int i = 0; i < componentList.Count; i++)
+ for (int i = 0; i < activeComponentList.Count; i++)
{
//Don't do anything when the animation for this item is already finished.
if (elapsedTime[i] > animationExitPresets.scaleDuration)
{
//Set its final state
- SetScale(rectTransformList[i], offsetScaleList[i]);
+ SetScale(rectTransformList[activeIndices[i]], offsetScaleList[i]);
continue;
}
@@ -405,8 +442,8 @@ private IEnumerator ExitScaleEnumeration()
//Calculate current scale
float curveValue = animationExitPresets.curveScale.Evaluate(t);
- Vector3 currentScale = Vector3.Lerp(originalScale[i], offsetScaleList[i], curveValue);
- SetScale(rectTransformList[i], currentScale);
+ Vector3 currentScale = Vector3.Lerp(originalScale[activeIndices[i]], offsetScaleList[i], curveValue);
+ SetScale(rectTransformList[activeIndices[i]], currentScale);
elapsedTime[i] += Time.deltaTime;
}
@@ -416,42 +453,42 @@ private IEnumerator ExitScaleEnumeration()
//There are always inaccuracies when dealing with float values
//So to keep it safe, when the final loop is done, set everything to its final state.
- SetAllScale_Offset(animationExitPresets);
+ SetAllScale_Offset(animationExitPresets, activeIndices);
}
}
- private IEnumerator EntranceRotationEnumeration()
+ private IEnumerator EntranceRotationEnumeration(List activeComponentList, List activeIndices)
{
- if (componentList.Count > 0 && animationEntrancePresets.useRotationAnimation == true)
+ if (activeComponentList.Count > 0 && animationEntrancePresets.useRotationAnimation == true)
{
/// Set starting state where the UI is invisible
- SetAllRotation_Offset(animationEntrancePresets);
+ SetAllRotation_Offset(animationEntrancePresets, activeIndices);
/// Delay the animation
yield return new WaitForSeconds(animationEntrancePresets.rotationDelay);
- Vector3[] offsetRotationList = CreateOffsetRotationList(animationEntrancePresets);
+ Vector3[] offsetRotationList = CreateOffsetRotationList(animationEntrancePresets, activeIndices);
/// Calculate delay per element
/// The top-most UI on the list gets 0 second delay.
/// Each subsequent element gets delayed by the amount.
- float[] delayPerItem = CalculateDelayPerItem(DelayPerItemType.TopToBottom, animationEntrancePresets.delayPerElementRotation);
+ float[] delayPerItem = CalculateDelayPerItem(activeComponentList, DelayPerItemType.TopToBottom, animationEntrancePresets.delayPerElementRotation);
/// Keep track of the time for each UI on the list
/// because each UI has a different starting time based on the delay
- float[] elapsedTime = new float[componentList.Count];
+ float[] elapsedTime = new float[activeComponentList.Count];
/// Animate the fade in animation
- while (elapsedTime[componentList.Count - 1] < animationEntrancePresets.rotationDuration)
+ while (elapsedTime[activeComponentList.Count - 1] < animationEntrancePresets.rotationDuration)
{
- for (int i = 0; i < componentList.Count; i++)
+ for (int i = 0; i < activeComponentList.Count; i++)
{
//Don't do anything when the animation for this item is already finished.
if (elapsedTime[i] > animationEntrancePresets.rotationDuration)
{
//Set its final state
- SetRotation(rectTransformList[i], originalRotation[i]);
+ SetRotation(rectTransformList[activeIndices[i]], originalRotation[activeIndices[i]]);
continue;
}
@@ -468,8 +505,8 @@ private IEnumerator EntranceRotationEnumeration()
//Calculate current rotation
float curveValue = animationEntrancePresets.curveRotation.Evaluate(t);
- Vector3 currentRotation = Vector3.Lerp(offsetRotationList[i], originalRotation[i], curveValue);
- SetRotation(rectTransformList[i], currentRotation);
+ Vector3 currentRotation = Vector3.Lerp(offsetRotationList[i], originalRotation[activeIndices[i]], curveValue);
+ SetRotation(rectTransformList[activeIndices[i]], currentRotation);
elapsedTime[i] += Time.deltaTime;
}
@@ -483,9 +520,9 @@ private IEnumerator EntranceRotationEnumeration()
SetAllRotation_Original();
}
- private IEnumerator ExitRotationEnumeration()
+ private IEnumerator ExitRotationEnumeration(List activeComponentList, List activeIndices)
{
- if (componentList.Count > 0 && animationExitPresets.useRotationAnimation == true)
+ if (activeComponentList.Count > 0 && animationExitPresets.useRotationAnimation == true)
{
/// Set starting state where the UI is invisible
SetAllRotation_Original();
@@ -495,27 +532,27 @@ private IEnumerator ExitRotationEnumeration()
- Vector3[] offsetRotationList = CreateOffsetRotationList(animationExitPresets);
+ Vector3[] offsetRotationList = CreateOffsetRotationList(animationExitPresets, activeIndices);
/// Calculate delay per element
/// The bottom-most UI on the list gets 0 second delay.
/// Each subsequent element gets delayed by the amount.
- float[] delayPerItem = CalculateDelayPerItem(DelayPerItemType.BottomToTop, animationExitPresets.delayPerElementRotation);
+ float[] delayPerItem = CalculateDelayPerItem(activeComponentList, DelayPerItemType.BottomToTop, animationExitPresets.delayPerElementRotation);
/// Keep track of the time for each UI on the list
/// because each UI has a different starting time based on the delay
- float[] elapsedTime = new float[componentList.Count];
+ float[] elapsedTime = new float[activeComponentList.Count];
/// Animate the fade out animation
while (elapsedTime[0] < animationExitPresets.rotationDuration)
{
- for (int i = 0; i < componentList.Count; i++)
+ for (int i = 0; i < activeComponentList.Count; i++)
{
//Don't do anything when the animation for this item is already finished.
if (elapsedTime[i] > animationExitPresets.rotationDuration)
{
//Set its final state
- SetRotation(rectTransformList[i], offsetRotationList[i]);
+ SetRotation(rectTransformList[activeIndices[i]], offsetRotationList[i]);
continue;
}
@@ -531,8 +568,8 @@ private IEnumerator ExitRotationEnumeration()
//Calculate current rotation
float curveValue = animationExitPresets.curveRotation.Evaluate(t);
- Vector3 currentRotation = Vector3.Lerp(originalRotation[i], offsetRotationList[i], curveValue);
- SetRotation(rectTransformList[i], currentRotation);
+ Vector3 currentRotation = Vector3.Lerp(originalRotation[activeIndices[i]], offsetRotationList[i], curveValue);
+ SetRotation(rectTransformList[activeIndices[i]], currentRotation);
elapsedTime[i] += Time.deltaTime;
}
@@ -542,7 +579,7 @@ private IEnumerator ExitRotationEnumeration()
//There are always inaccuracies when dealing with float values
//So to keep it safe, when the final loop is done, set everything to its final state.
- SetAllRotation_Offset(animationExitPresets);
+ SetAllRotation_Offset(animationExitPresets, activeIndices);
}
}
#endregion
@@ -665,14 +702,18 @@ private void GetComponentsList()
/// Calculate the AutoTrigger if it's used
///
///
- private void AutoTriggerCalculation(SOAnimationPresets animationPresets)
+ private void AutoTriggerCalculation(SOAnimationPresets animationPresets, List activeComponentList)
{
if (animationPresets.autoTrigger != SOAnimationPresets.AutoTrigger.DoNothing)
{
- float alphaDuration = (componentList.Count * animationPresets.delayPerElementAlpha) + animationPresets.alphaDuration;
- float positionDuration = (componentList.Count * animationPresets.delayPerElementPosition) + animationPresets.positionDuration;
- float scaleDuration = (componentList.Count * animationPresets.delayPerElementScale) + animationPresets.scaleDuration;
- float rotationDuration = (componentList.Count * animationPresets.delayPerElementRotation) + animationPresets.rotationDuration;
+ float alphaDuration = !animationPresets.useAlphaAnimation ? 0 :
+ (activeComponentList.Count * animationPresets.delayPerElementAlpha) + animationPresets.alphaDuration;
+ float positionDuration = !animationPresets.usePositionAnimation ? 0 :
+ (activeComponentList.Count * animationPresets.delayPerElementPosition) + animationPresets.positionDuration;
+ float scaleDuration = !animationPresets.useScaleAnimation ? 0 :
+ (activeComponentList.Count * animationPresets.delayPerElementScale) + animationPresets.scaleDuration;
+ float rotationDuration = !animationPresets.useRotationAnimation ? 0 :
+ (activeComponentList.Count * animationPresets.delayPerElementRotation) + animationPresets.rotationDuration;
float maxEntranceDuration = Mathf.Max(alphaDuration, positionDuration, scaleDuration, rotationDuration);
if (animationPresets.autoTrigger == SOAnimationPresets.AutoTrigger.TriggerExitAnimation)
@@ -693,17 +734,17 @@ private void AutoTriggerCalculation(SOAnimationPresets animationPresets)
/// TopToBottom is used in entrance animation. BottomToTop is used in exit animation
/// Specify to get the delayPerElement value from entrance or exit presets
/// Array of delayPerItem to count the animation delay in each element on the list
- private float[] CalculateDelayPerItem(DelayPerItemType delayPerItemType, float delayPerElement)
+ private float[] CalculateDelayPerItem(List components, DelayPerItemType delayPerItemType, float delayPerElement)
{
- float[] delayPerItem = new float[componentList.Count];
- for (int i = 0; i < componentList.Count; i++)
+ float[] delayPerItem = new float[components.Count];
+ for (int i = 0; i < components.Count; i++)
{
//For "Top to Bottom" used in Entrance Animation, it gives the first item on the list
//value timer 0 second, and increment each item by delayPerItem in the AnimationPresets.
//For "Bottom to Top" used in Exit Animation, it does the opposite, where the last item is given 0
//and increment each item backwards.
- int increment = (delayPerItemType == DelayPerItemType.TopToBottom) ? i : (componentList.Count - 1 - i);
+ int increment = (delayPerItemType == DelayPerItemType.TopToBottom) ? i : (components.Count - 1 - i);
delayPerItem[i] = delayPerElement * increment;
}
return delayPerItem;
@@ -735,14 +776,11 @@ private void SetColorAlpha(Component component, float value)
/// Set all components' alpha to zero.
/// This is used at the start of the entrance animation and at the end of exit animation.
///
- private void SetAllColorAlpha_Zero()
+ private void SetAllColorAlpha_Zero(List components)
{
- if (componentList.Count > 0)
+ for (int i = 0; i < components.Count; i++)
{
- for (int i = 0; i < componentList.Count; i++)
- {
- SetColorAlpha(componentList[i], 0);
- }
+ SetColorAlpha(components[i], 0);
}
}
@@ -790,14 +828,14 @@ private void SetAllPosition_Original()
/// Set all components' position to its animation-ready offset position.
/// This is used at the start of the entrance animation and at the end of exit animation.
///
- public void SetAllPosition_Offset(SOAnimationPresets animationPresets)
+ public void SetAllPosition_Offset(SOAnimationPresets animationPresets, List activeIndices)
{
- if (rectTransformList.Length > 0)
+ if (activeIndices.Count > 0)
{
- Vector2[] offsetPositionList = CreateOffsetPositionList(animationPresets);
- for (int i = 0; i < rectTransformList.Length; i++)
+ Vector2[] offsetPositionList = CreateOffsetPositionList(animationPresets, activeIndices);
+ for (int i = 0; i < activeIndices.Count; i++)
{
- SetPosition(rectTransformList[i], offsetPositionList[i]);
+ SetPosition(rectTransformList[activeIndices[i]], offsetPositionList[i]);
}
}
}
@@ -832,14 +870,14 @@ private void SetAllScale_Original()
/// This is used at the start of the entrance animation and at the end of exit animation.
///
///
- private void SetAllScale_Offset(SOAnimationPresets animationPresets)
+ private void SetAllScale_Offset(SOAnimationPresets animationPresets, List activeIndices)
{
- if (rectTransformList.Length > 0)
+ if (activeIndices.Count > 0)
{
- Vector3[] offsetScaleList = CreateOffsetScaleList(animationPresets);
- for (int i = 0; i < rectTransformList.Length; i++)
+ Vector3[] offsetScaleList = CreateOffsetScaleList(animationPresets, activeIndices);
+ for (int i = 0; i < activeIndices.Count; i++)
{
- SetScale(rectTransformList[i], offsetScaleList[i]);
+ SetScale(rectTransformList[activeIndices[i]], offsetScaleList[i]);
}
}
}
@@ -875,14 +913,14 @@ private void SetAllRotation_Original()
/// This is used at the start of the entrance animation and at the end of exit animation.
///
///
- private void SetAllRotation_Offset(SOAnimationPresets animationPresets)
+ private void SetAllRotation_Offset(SOAnimationPresets animationPresets, List activeIndices)
{
- if (rectTransformList.Length > 0)
+ if (activeIndices.Count > 0)
{
- Vector3[] offsetRotationList = CreateOffsetRotationList(animationPresets);
- for (int i = 0; i < rectTransformList.Length; i++)
+ Vector3[] offsetRotationList = CreateOffsetRotationList(animationPresets, activeIndices);
+ for (int i = 0; i < activeIndices.Count; i++)
{
- SetRotation(rectTransformList[i], offsetRotationList[i]);
+ SetRotation(rectTransformList[activeIndices[i]], offsetRotationList[i]);
}
}
}
@@ -894,12 +932,12 @@ private void SetAllRotation_Offset(SOAnimationPresets animationPresets)
/// Specify which animationPresets to get the right offsetPosition value (entrance or exit animation)
///
/// Vector2 array detailing each offset position for interpolation
- private Vector2[] CreateOffsetPositionList(SOAnimationPresets animationPresets)
+ private Vector2[] CreateOffsetPositionList(SOAnimationPresets animationPresets, List activeIndices)
{
- Vector2[] offsetPositionList = new Vector2[componentList.Count];
- for (int i = 0; i < componentList.Count; i++)
+ Vector2[] offsetPositionList = new Vector2[activeIndices.Count];
+ for (int i = 0; i < activeIndices.Count; i++)
{
- Vector2 offset = originalPosition[i] + animationPresets.offsetPosition;
+ Vector2 offset = originalPosition[activeIndices[i]] + animationPresets.offsetPosition;
offsetPositionList[i] = offset;
}
return offsetPositionList;
@@ -912,12 +950,12 @@ private Vector2[] CreateOffsetPositionList(SOAnimationPresets animationPresets)
/// Specify which animationPresets to get the right offsetScale value (entrance or exit animation)
///
/// Vector2 array detailing each offset scale for interpolation
- private Vector3[] CreateOffsetScaleList(SOAnimationPresets animationPresets)
+ private Vector3[] CreateOffsetScaleList(SOAnimationPresets animationPresets, List activeIndices)
{
- Vector3[] offsetScaleList = new Vector3[componentList.Count];
- for (int i = 0; i < componentList.Count; i++)
+ Vector3[] offsetScaleList = new Vector3[activeIndices.Count];
+ for (int i = 0; i < activeIndices.Count; i++)
{
- Vector3 offset = originalScale[i] * animationPresets.offsetScale;
+ Vector3 offset = originalScale[activeIndices[i]] * animationPresets.offsetScale;
offsetScaleList[i] = offset;
}
return offsetScaleList;
@@ -930,12 +968,12 @@ private Vector3[] CreateOffsetScaleList(SOAnimationPresets animationPresets)
/// Specify which animationPresets to get the right offsetRotation value (entrance or exit animation)
///
/// Vector2 array detailing each offset rotation for interpolation
- private Vector3[] CreateOffsetRotationList(SOAnimationPresets animationPresets)
+ private Vector3[] CreateOffsetRotationList(SOAnimationPresets animationPresets, List activeIndices)
{
- Vector3[] offsetRotationList = new Vector3[componentList.Count];
- for (int i = 0; i < componentList.Count; i++)
+ Vector3[] offsetRotationList = new Vector3[activeIndices.Count];
+ for (int i = 0; i < activeIndices.Count; i++)
{
- Vector3 offset = originalRotation[i] + animationPresets.offsetRotation;
+ Vector3 offset = originalRotation[activeIndices[i]] + animationPresets.offsetRotation;
offsetRotationList[i] = offset;
}
return offsetRotationList;