修复了选曲的问题 优化了ui
This commit is contained in:
@@ -0,0 +1,271 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AiryUI
|
||||
{
|
||||
|
||||
|
||||
[ExecuteInEditMode]
|
||||
public class Anchors
|
||||
{
|
||||
|
||||
|
||||
private static float parentRectWidth, parentRectHeight;
|
||||
|
||||
private static RectTransform rectTransform;
|
||||
|
||||
private static float thisRectWidth, thisRectHeight;
|
||||
|
||||
private static Vector3 rectInitialPosition;
|
||||
private static Vector2 minAnchors;
|
||||
private static Vector2 maxAnchors;
|
||||
private static Vector2 rectPositionRelativeToParent;
|
||||
private static Vector2 initialPivot;
|
||||
|
||||
private static float rectWidthRatio;
|
||||
private static float rectHeightRatio;
|
||||
|
||||
private static void SetInitialValues ()
|
||||
{
|
||||
// Initial Position, because we will reset the position later.
|
||||
rectInitialPosition = rectTransform.localPosition;
|
||||
initialPivot = rectTransform.pivot;
|
||||
|
||||
rectTransform.pivot = new Vector2 ( 0.5f , 0.5f );
|
||||
|
||||
// Screen dimensions.
|
||||
// 15-12-2018 We do not use Screen.width and Screen.height here, because these variables are only set correctly in play mode, in edit mode, they return the size of the game window, it's a litte bit tricky -_- .
|
||||
// 16-12-2018 We do not use screen dimensions anymore. Instead we use the parent rect's dimensions.
|
||||
|
||||
//string[] resolution = UnityEditor.UnityStats.screenRes.Split('x');
|
||||
//screenWidth = int.Parse(resolution[0]);
|
||||
//screenHeight = int.Parse(resolution[1]);
|
||||
|
||||
parentRectWidth = rectTransform.parent.GetComponent<RectTransform> ().rect.width;
|
||||
parentRectHeight = rectTransform.parent.GetComponent<RectTransform> ().rect.height;
|
||||
|
||||
// Rect dimensions.
|
||||
thisRectWidth = rectTransform.rect.width;
|
||||
thisRectHeight = rectTransform.rect.height;
|
||||
|
||||
// Relative position, width, and height. We add 0.5 to X and Y coordinates becuase the center in local space is (0, 0) while the center in world space (0.5, 0.5).
|
||||
rectPositionRelativeToParent = new Vector2 ( ( rectTransform.localPosition.x / parentRectWidth ) + 0.5f , ( rectTransform.localPosition.y / parentRectHeight ) + 0.5f );
|
||||
|
||||
// rectWidthRatio and rectHeightRatio return the ratio of the current rect's dimensions relative to screen. e.g if parent rect's width = 400 and current rect's width = 100, then rectWidthRatio will be 0.25
|
||||
rectWidthRatio = thisRectWidth / parentRectWidth;
|
||||
rectHeightRatio = thisRectHeight / parentRectHeight;
|
||||
|
||||
float minX = rectPositionRelativeToParent.x - ( rectWidthRatio / 2 );
|
||||
float minY = rectPositionRelativeToParent.y - ( rectHeightRatio / 2 );
|
||||
|
||||
float maxX = rectPositionRelativeToParent.x + ( rectWidthRatio / 2 );
|
||||
float maxY = rectPositionRelativeToParent.y + ( rectHeightRatio / 2 );
|
||||
|
||||
minAnchors = new Vector2 ( minX , minY );
|
||||
maxAnchors = new Vector2 ( maxX , maxY );
|
||||
}
|
||||
|
||||
public static void SetAnchorsToRect ( RectTransform rect )
|
||||
{
|
||||
// Done in 17-12-2018 ----------- It took too much time.
|
||||
// First, We will get the current position, width, and height of the rect transform, because we will reset these values after setting the anchor.
|
||||
// That's because when the anchors positions change, they autmatically change the coordinates of the rect transform.
|
||||
// Second, we will get the width and height of the parent rect transform.
|
||||
// Second, we will get the width and height of this rect transform.
|
||||
// Third, we have to find the rect transform's position in relativity with parent width, and height. (rectTransform.position.x / parent.width)
|
||||
|
||||
rectTransform = rect;
|
||||
|
||||
// Here we calculate the min and max anchors.
|
||||
SetInitialValues ();
|
||||
|
||||
// And finally setting the anchors.
|
||||
|
||||
rectTransform.anchorMin = minAnchors;
|
||||
rectTransform.anchorMax = maxAnchors;
|
||||
|
||||
// Resetting the rect to its initial position, width, and height.
|
||||
rectTransform.pivot = initialPivot;
|
||||
rectTransform.localPosition = rectInitialPosition;
|
||||
|
||||
rectTransform.SetSizeWithCurrentAnchors ( RectTransform.Axis.Vertical , thisRectHeight );
|
||||
rectTransform.SetSizeWithCurrentAnchors ( RectTransform.Axis.Horizontal , thisRectWidth );
|
||||
}
|
||||
|
||||
public static void SetAnchorsCenter ( RectTransform rect )
|
||||
{
|
||||
rectTransform = rect;
|
||||
initialPivot = rectTransform.pivot;
|
||||
|
||||
SetInitialValues ();
|
||||
|
||||
rectTransform.anchorMin = new Vector2 ( 0.5f , 0.5f );
|
||||
rectTransform.anchorMax = new Vector2 ( 0.5f , 0.5f );
|
||||
|
||||
// Resetting the rect to its initial position, width, and height.
|
||||
rectTransform.pivot = initialPivot;
|
||||
rectTransform.localPosition = rectInitialPosition;
|
||||
|
||||
rectTransform.SetSizeWithCurrentAnchors ( RectTransform.Axis.Vertical , thisRectHeight );
|
||||
rectTransform.SetSizeWithCurrentAnchors ( RectTransform.Axis.Horizontal , thisRectWidth );
|
||||
}
|
||||
|
||||
public static void SetAnchorsTop ( RectTransform rect )
|
||||
{
|
||||
rectTransform = rect;
|
||||
initialPivot = rectTransform.pivot;
|
||||
|
||||
SetInitialValues ();
|
||||
|
||||
rectTransform.anchorMin = new Vector2 ( 0.5f , 1 );
|
||||
rectTransform.anchorMax = new Vector2 ( 0.5f , 1 );
|
||||
|
||||
// Resetting the rect to its initial position, width, and height.
|
||||
rectTransform.pivot = initialPivot;
|
||||
rectTransform.localPosition = rectInitialPosition;
|
||||
|
||||
rectTransform.SetSizeWithCurrentAnchors ( RectTransform.Axis.Vertical , thisRectHeight );
|
||||
rectTransform.SetSizeWithCurrentAnchors ( RectTransform.Axis.Horizontal , thisRectWidth );
|
||||
}
|
||||
|
||||
public static void SetAnchorsBottom ( RectTransform rect )
|
||||
{
|
||||
rectTransform = rect;
|
||||
initialPivot = rectTransform.pivot;
|
||||
|
||||
SetInitialValues ();
|
||||
|
||||
rectTransform.anchorMin = new Vector2 ( 0.5f , 0 );
|
||||
rectTransform.anchorMax = new Vector2 ( 0.5f , 0 );
|
||||
|
||||
// Resetting the rect to its initial position, width, and height.
|
||||
rectTransform.pivot = initialPivot;
|
||||
rectTransform.localPosition = rectInitialPosition;
|
||||
|
||||
rectTransform.SetSizeWithCurrentAnchors ( RectTransform.Axis.Vertical , thisRectHeight );
|
||||
rectTransform.SetSizeWithCurrentAnchors ( RectTransform.Axis.Horizontal , thisRectWidth );
|
||||
}
|
||||
|
||||
public static void SetAnchorsRight ( RectTransform rect )
|
||||
{
|
||||
rectTransform = rect;
|
||||
initialPivot = rectTransform.pivot;
|
||||
|
||||
SetInitialValues ();
|
||||
|
||||
rectTransform.anchorMin = new Vector2 ( 1 , 0.5f );
|
||||
rectTransform.anchorMax = new Vector2 ( 1 , 0.5f );
|
||||
|
||||
// Resetting the rect to its initial position, width, and height.
|
||||
rectTransform.pivot = initialPivot;
|
||||
rectTransform.localPosition = rectInitialPosition;
|
||||
|
||||
rectTransform.SetSizeWithCurrentAnchors ( RectTransform.Axis.Vertical , thisRectHeight );
|
||||
rectTransform.SetSizeWithCurrentAnchors ( RectTransform.Axis.Horizontal , thisRectWidth );
|
||||
}
|
||||
|
||||
public static void SetAnchorsLeft ( RectTransform rect )
|
||||
{
|
||||
rectTransform = rect;
|
||||
initialPivot = rectTransform.pivot;
|
||||
|
||||
SetInitialValues ();
|
||||
|
||||
rectTransform.anchorMin = new Vector2 ( 0 , 0.5f );
|
||||
rectTransform.anchorMax = new Vector2 ( 0 , 0.5f );
|
||||
|
||||
// Resetting the rect to its initial position, width, and height.
|
||||
rectTransform.pivot = initialPivot;
|
||||
rectTransform.localPosition = rectInitialPosition;
|
||||
|
||||
rectTransform.SetSizeWithCurrentAnchors ( RectTransform.Axis.Vertical , thisRectHeight );
|
||||
rectTransform.SetSizeWithCurrentAnchors ( RectTransform.Axis.Horizontal , thisRectWidth );
|
||||
}
|
||||
|
||||
public static void SetAnchorsTopRight ( RectTransform rect )
|
||||
{
|
||||
rectTransform = rect;
|
||||
initialPivot = rectTransform.pivot;
|
||||
|
||||
SetInitialValues ();
|
||||
|
||||
rectTransform.anchorMin = Vector2.one;
|
||||
rectTransform.anchorMax = Vector2.one;
|
||||
|
||||
// Resetting the rect to its initial position, width, and height.
|
||||
rectTransform.pivot = initialPivot;
|
||||
rectTransform.localPosition = rectInitialPosition;
|
||||
|
||||
rectTransform.SetSizeWithCurrentAnchors ( RectTransform.Axis.Vertical , thisRectHeight );
|
||||
rectTransform.SetSizeWithCurrentAnchors ( RectTransform.Axis.Horizontal , thisRectWidth );
|
||||
}
|
||||
|
||||
public static void SetAnchorsTopLeft ( RectTransform rect )
|
||||
{
|
||||
rectTransform = rect;
|
||||
initialPivot = rectTransform.pivot;
|
||||
|
||||
SetInitialValues ();
|
||||
|
||||
rectTransform.anchorMin = new Vector2 ( 0 , 1 );
|
||||
rectTransform.anchorMax = new Vector2 ( 0 , 1 );
|
||||
|
||||
// Resetting the rect to its initial position, width, and height.
|
||||
rectTransform.pivot = initialPivot;
|
||||
rectTransform.localPosition = rectInitialPosition;
|
||||
|
||||
rectTransform.SetSizeWithCurrentAnchors ( RectTransform.Axis.Vertical , thisRectHeight );
|
||||
rectTransform.SetSizeWithCurrentAnchors ( RectTransform.Axis.Horizontal , thisRectWidth );
|
||||
}
|
||||
|
||||
public static void SetAnchorsBottomRight ( RectTransform rect )
|
||||
{
|
||||
rectTransform = rect;
|
||||
initialPivot = rectTransform.pivot;
|
||||
|
||||
SetInitialValues ();
|
||||
|
||||
rectTransform.anchorMin = new Vector2 ( 1 , 0 );
|
||||
rectTransform.anchorMax = new Vector2 ( 1 , 0 );
|
||||
|
||||
// Resetting the rect to its initial position, width, and height.
|
||||
rectTransform.pivot = initialPivot;
|
||||
rectTransform.localPosition = rectInitialPosition;
|
||||
|
||||
rectTransform.SetSizeWithCurrentAnchors ( RectTransform.Axis.Vertical , thisRectHeight );
|
||||
rectTransform.SetSizeWithCurrentAnchors ( RectTransform.Axis.Horizontal , thisRectWidth );
|
||||
}
|
||||
|
||||
public static void SetAnchorsBottomLeft ( RectTransform rect )
|
||||
{
|
||||
rectTransform = rect;
|
||||
initialPivot = rectTransform.pivot;
|
||||
|
||||
SetInitialValues ();
|
||||
|
||||
rectTransform.anchorMin = Vector2.zero;
|
||||
rectTransform.anchorMax = Vector2.zero;
|
||||
|
||||
// Resetting the rect to its initial position, width, and height.
|
||||
rectTransform.pivot = initialPivot;
|
||||
rectTransform.localPosition = rectInitialPosition;
|
||||
|
||||
rectTransform.SetSizeWithCurrentAnchors ( RectTransform.Axis.Vertical , thisRectHeight );
|
||||
rectTransform.SetSizeWithCurrentAnchors ( RectTransform.Axis.Horizontal , thisRectWidth );
|
||||
}
|
||||
|
||||
public static void SetRectToAnchor ( RectTransform rect )
|
||||
{
|
||||
rectTransform = rect;
|
||||
initialPivot = rectTransform.pivot;
|
||||
|
||||
rectTransform.pivot = initialPivot;
|
||||
|
||||
rectTransform.offsetMin = Vector2.zero;
|
||||
rectTransform.offsetMax = Vector2.zero;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1908b58820c26f94489349886e3424cf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: 0f44a0ceee9527f4a99c043c83e5d37d, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 135898
|
||||
packageName: Airy UI 2 - Easy UI Animation
|
||||
packageVersion: 2.0.2
|
||||
assetPath: Assets/Airy UI/Scripts/Anchors.cs
|
||||
uploadId: 760159
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9a8dff8c7bdaea24098c5c167c761c64
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 300
|
||||
icon: {fileID: 2800000, guid: 3a66e1d307308d041a8b9c7a714f2639, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 135898
|
||||
packageName: Airy UI 2 - Easy UI Animation
|
||||
packageVersion: 2.0.2
|
||||
assetPath: Assets/Airy UI/Scripts/AnimatedElement.cs
|
||||
uploadId: 760159
|
||||
@@ -0,0 +1,108 @@
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine.Events;
|
||||
using UnityEditor;
|
||||
|
||||
namespace AiryUI
|
||||
{
|
||||
|
||||
|
||||
[DisallowMultipleComponent]
|
||||
[AddComponentMenu ( "Airy UI/Animated Elements Group" )]
|
||||
public class AnimatedElementsGroup : MonoBehaviour
|
||||
{
|
||||
|
||||
|
||||
[Tooltip ( "Aniamted elements managed by this Animation Manager" )]
|
||||
public List<AnimatedElement> animatedElements = new List<AnimatedElement> ();
|
||||
|
||||
|
||||
[Tooltip ( "TRUE: the Animated Elements linked to this group will be animated when this game object is enabled.\nFALSE: every animated element linked to this group is on it own." )]
|
||||
public bool showAnimaitonOnEnable;
|
||||
|
||||
|
||||
public UnityEvent OnShow;
|
||||
public UnityEvent OnHide;
|
||||
|
||||
|
||||
|
||||
//====================================
|
||||
|
||||
|
||||
|
||||
private void OnEnable ()
|
||||
{
|
||||
animatedElements.RemoveAll ( a => a == null );
|
||||
|
||||
foreach ( var item in animatedElements )
|
||||
{
|
||||
if ( item.group == null )
|
||||
item.group = this;
|
||||
}
|
||||
|
||||
if ( showAnimaitonOnEnable )
|
||||
{
|
||||
ShowGroup ();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void ShowGroup ()
|
||||
{
|
||||
gameObject.SetActive ( true );
|
||||
|
||||
foreach ( var element in animatedElements )
|
||||
{
|
||||
element.ShowElement ();
|
||||
}
|
||||
|
||||
OnShow?.Invoke ();
|
||||
}
|
||||
|
||||
|
||||
public void HideGroup ()
|
||||
{
|
||||
foreach ( var element in animatedElements )
|
||||
{
|
||||
element.HideElement ();
|
||||
}
|
||||
|
||||
OnHide?.Invoke ();
|
||||
}
|
||||
|
||||
|
||||
public void UpdateElementsInChildren ()
|
||||
{
|
||||
animatedElements = GetComponentsInChildren<AnimatedElement> ( true ).Where ( a => a.isControlledByGroup ).ToList ();
|
||||
|
||||
foreach ( var c in animatedElements )
|
||||
{
|
||||
c.group = this;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#if UNITY_EDITOR
|
||||
|
||||
|
||||
[MenuItem ( "GameObject/Airy UI/Animated Elements Group" , false , 0 )]
|
||||
private static void HierarchyCreateMenu ( MenuCommand menuCommand )
|
||||
{
|
||||
GameObject newGameObject = new GameObject ( "Animated Elements Group" );
|
||||
|
||||
newGameObject.AddComponent<AnimatedElementsGroup> ();
|
||||
|
||||
GameObjectUtility.SetParentAndAlign ( newGameObject , menuCommand.context as GameObject );
|
||||
|
||||
Undo.RegisterCreatedObjectUndo ( newGameObject , "Create " + newGameObject.name );
|
||||
|
||||
Selection.activeObject = newGameObject;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 048ea60d7d5ddcb4f9571521619af551
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 400
|
||||
icon: {fileID: 2800000, guid: 20e204a63dd92db4789aa5672485efb3, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 135898
|
||||
packageName: Airy UI 2 - Easy UI Animation
|
||||
packageVersion: 2.0.2
|
||||
assetPath: Assets/Airy UI/Scripts/AnimatedElementsGroup.cs
|
||||
uploadId: 760159
|
||||
@@ -0,0 +1,187 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace AiryUI
|
||||
{
|
||||
public class AnimationPositions : MonoBehaviour
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Used for initializing the position from a certian corner.
|
||||
/// </summary>
|
||||
/// <param name="initialPosition">the start position of the transform</param>
|
||||
/// <param name="rectTransform">the rect transform</param>
|
||||
/// <param name="animationStartPosition">BottomRight, UpRight, BottomLeft, UpLeft, Up, Bottom, Left, Or Right</param>
|
||||
/// <param name="animationFromCornerStartFromType">Screen or Rect</param>
|
||||
/// <returns></returns>
|
||||
public static Vector3 GetStartPositionFromCorner
|
||||
( Vector3 initialPosition , RectTransform rectTransform , AnimationStartPosition animationStartPosition )
|
||||
{
|
||||
float startPositionX = 0;
|
||||
float startPositionY = 0;
|
||||
|
||||
var containerCanvas = rectTransform.GetComponent<AnimatedElement> ().containerCanvas;
|
||||
var canvasRect = containerCanvas.GetComponent<RectTransform> ();
|
||||
|
||||
switch ( animationStartPosition )
|
||||
{
|
||||
case ( AnimationStartPosition.Up ):
|
||||
|
||||
startPositionX = initialPosition.x;
|
||||
startPositionY = ( canvasRect.sizeDelta.y / 2 ) + ( rectTransform.rect.height / 2 );
|
||||
|
||||
break;
|
||||
|
||||
case ( AnimationStartPosition.Bottom ):
|
||||
|
||||
startPositionX = initialPosition.x;
|
||||
startPositionY = -( canvasRect.sizeDelta.y / 2 ) - ( rectTransform.rect.height * rectTransform.localScale.y / 2 );
|
||||
|
||||
break;
|
||||
|
||||
case ( AnimationStartPosition.Left ):
|
||||
|
||||
startPositionX = -( canvasRect.sizeDelta.x / 2 ) - ( rectTransform.rect.width * rectTransform.localScale.x / 2 );
|
||||
startPositionY = initialPosition.y;
|
||||
|
||||
break;
|
||||
|
||||
case ( AnimationStartPosition.Right ):
|
||||
|
||||
startPositionX = ( canvasRect.sizeDelta.x / 2 ) + ( rectTransform.rect.width * rectTransform.localScale.x / 2 );
|
||||
startPositionY = initialPosition.y;
|
||||
|
||||
break;
|
||||
|
||||
case ( AnimationStartPosition.BottomRight ):
|
||||
|
||||
startPositionX = ( canvasRect.sizeDelta.x / 2 ) + ( rectTransform.rect.width * rectTransform.localScale.x / 2 );
|
||||
startPositionY = -( canvasRect.sizeDelta.y / 2 ) - ( rectTransform.rect.height * rectTransform.localScale.y / 2 );
|
||||
|
||||
break;
|
||||
|
||||
case ( AnimationStartPosition.BottomLeft ):
|
||||
|
||||
startPositionX = -( canvasRect.sizeDelta.x / 2 ) - ( rectTransform.rect.width * rectTransform.localScale.x / 2 );
|
||||
startPositionY = -( canvasRect.sizeDelta.y / 2 ) - ( rectTransform.rect.height * rectTransform.localScale.y / 2 );
|
||||
|
||||
break;
|
||||
|
||||
case ( AnimationStartPosition.UpRight ):
|
||||
|
||||
startPositionX = ( canvasRect.sizeDelta.x / 2 ) + ( rectTransform.rect.width * rectTransform.localScale.x / 2 );
|
||||
startPositionY = ( canvasRect.sizeDelta.y / 2 ) + ( rectTransform.rect.height * rectTransform.localScale.y / 2 );
|
||||
|
||||
|
||||
break;
|
||||
|
||||
case ( AnimationStartPosition.UpLeft ):
|
||||
|
||||
startPositionX = -( canvasRect.sizeDelta.x / 2 ) - ( rectTransform.rect.width * rectTransform.localScale.x / 2 );
|
||||
startPositionY = ( canvasRect.sizeDelta.y / 2 ) + ( rectTransform.rect.height * rectTransform.localScale.y / 2 );
|
||||
|
||||
break;
|
||||
|
||||
case ( AnimationStartPosition.Center ):
|
||||
|
||||
startPositionX = 0;
|
||||
startPositionY = 0;
|
||||
|
||||
break;
|
||||
|
||||
case ( AnimationStartPosition.UpCenter ):
|
||||
|
||||
startPositionX = 0;
|
||||
startPositionY = ( canvasRect.sizeDelta.y / 2 ) + ( rectTransform.rect.height * rectTransform.localScale.y / 2 );
|
||||
|
||||
break;
|
||||
|
||||
case ( AnimationStartPosition.BottomCenter ):
|
||||
|
||||
startPositionX = 0;
|
||||
startPositionY = -( canvasRect.sizeDelta.y / 2 ) - ( rectTransform.rect.height * rectTransform.localScale.y / 2 );
|
||||
|
||||
break;
|
||||
|
||||
case ( AnimationStartPosition.RightCenter ):
|
||||
|
||||
startPositionX = ( canvasRect.sizeDelta.x / 2 ) + ( rectTransform.rect.width * rectTransform.localScale.x / 2 );
|
||||
startPositionY = 0;
|
||||
|
||||
break;
|
||||
|
||||
case ( AnimationStartPosition.LeftCenter ):
|
||||
|
||||
startPositionX = -( canvasRect.sizeDelta.x / 2 ) - ( rectTransform.rect.width * rectTransform.localScale.x / 2 );
|
||||
startPositionY = 0;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
Vector3 startPos = new Vector3 ( startPositionX , startPositionY , 0 );
|
||||
|
||||
|
||||
//==============================================================================================
|
||||
|
||||
|
||||
Vector3 addedVector = Vector3.zero;
|
||||
var parent = rectTransform.parent;
|
||||
var parentLocalPosition = parent.gameObject.Equals ( containerCanvas.gameObject ) ? Vector3.zero : parent.localPosition;
|
||||
|
||||
|
||||
switch ( animationStartPosition )
|
||||
{
|
||||
case ( AnimationStartPosition.Center ):
|
||||
|
||||
addedVector = new Vector3 ( -parentLocalPosition.x , -parentLocalPosition.y , 0 );
|
||||
startPos = new Vector3 ( startPos.x + addedVector.x , startPos.y + addedVector.y , 0 );
|
||||
|
||||
break;
|
||||
|
||||
case ( AnimationStartPosition.Up ):
|
||||
case ( AnimationStartPosition.Bottom ):
|
||||
|
||||
addedVector = new Vector3 ( 0 , -parentLocalPosition.y , 0 );
|
||||
startPos = startPos + addedVector;
|
||||
|
||||
break;
|
||||
|
||||
case ( AnimationStartPosition.Right ):
|
||||
case ( AnimationStartPosition.Left ):
|
||||
|
||||
addedVector = new Vector3 ( -parentLocalPosition.x , 0 , 0 );
|
||||
startPos = startPos + addedVector;
|
||||
|
||||
break;
|
||||
|
||||
case ( AnimationStartPosition.UpCenter ):
|
||||
case ( AnimationStartPosition.BottomCenter ):
|
||||
|
||||
addedVector = new Vector3 ( 0 , -parentLocalPosition.y , 0 );
|
||||
startPos = new Vector3 ( -parentLocalPosition.x , startPos.y + addedVector.y , 0 );
|
||||
|
||||
break;
|
||||
|
||||
case ( AnimationStartPosition.RightCenter ):
|
||||
case ( AnimationStartPosition.LeftCenter ):
|
||||
|
||||
addedVector = new Vector3 ( -parentLocalPosition.x , 0 , 0 );
|
||||
startPos = new Vector3 ( startPos.x + addedVector.x , -parentLocalPosition.y , 0 );
|
||||
|
||||
break;
|
||||
|
||||
case ( AnimationStartPosition.UpLeft ):
|
||||
case ( AnimationStartPosition.UpRight ):
|
||||
case ( AnimationStartPosition.BottomLeft ):
|
||||
case ( AnimationStartPosition.BottomRight ):
|
||||
|
||||
addedVector = new Vector3 ( -parentLocalPosition.x , -parentLocalPosition.y , 0 );
|
||||
startPos = startPos + addedVector;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return ( startPos );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 28ab1c11203c7df43bb2e04b9dbae4dd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: 0727ad002e9a86b499cb1f23b7bf175b, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 135898
|
||||
packageName: Airy UI 2 - Easy UI Animation
|
||||
packageVersion: 2.0.2
|
||||
assetPath: Assets/Airy UI/Scripts/AnimationPositions.cs
|
||||
uploadId: 760159
|
||||
@@ -0,0 +1,51 @@
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
|
||||
namespace AiryUI
|
||||
{
|
||||
|
||||
|
||||
[DisallowMultipleComponent]
|
||||
public abstract class CloseButton : MonoBehaviour
|
||||
{
|
||||
|
||||
|
||||
public BackButtonAffects backButtonAffects;
|
||||
public AnimatedElement affectedAnimatedElement;
|
||||
public AnimatedElementsGroup affectedAnimatedElementsGroup;
|
||||
|
||||
|
||||
|
||||
public virtual void DoBack ()
|
||||
{
|
||||
if ( backButtonAffects == BackButtonAffects.AnimatedElement )
|
||||
{
|
||||
if ( affectedAnimatedElementsGroup == null )
|
||||
{
|
||||
Debug.LogError ( "<color=orange><b>[Airy UI]</color></b> <color=red><b>X</color></b> Affected Animated Element is null, please set it" , gameObject );
|
||||
return;
|
||||
}
|
||||
|
||||
affectedAnimatedElement.HideElement ();
|
||||
}
|
||||
else if ( backButtonAffects == BackButtonAffects.AnimatedElementsGroup )
|
||||
{
|
||||
if ( affectedAnimatedElementsGroup == null )
|
||||
{
|
||||
Debug.LogError ( "<color=orange><b>[Airy UI]</color></b> <color=red><b>X</color></b> Affected Animated Elements Group is null, please set it" , gameObject );
|
||||
return;
|
||||
}
|
||||
|
||||
affectedAnimatedElementsGroup.HideGroup ();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public enum BackButtonAffects { AnimatedElement, AnimatedElementsGroup }
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2858f6c67272dd14383549fcdd22c15a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: 16954819a70521f49a68dbfc436a4076, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 135898
|
||||
packageName: Airy UI 2 - Easy UI Animation
|
||||
packageVersion: 2.0.2
|
||||
assetPath: Assets/Airy UI/Scripts/CloseButton.cs
|
||||
uploadId: 760159
|
||||
@@ -0,0 +1,993 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
|
||||
namespace AiryUI
|
||||
{
|
||||
[AddComponentMenu("Airy UI/CustomAnimated Element")]
|
||||
public class CustomAnimatedElement : AnimatedElement
|
||||
{
|
||||
public ComponentsToAnimate componentsToAnimate_SHOW;
|
||||
public ComponentsToAnimate componentsToAnimate_HIDE;
|
||||
|
||||
public List<TransformAnimationRecord> TransformAnimationRecords_SHOW = new List<TransformAnimationRecord>();
|
||||
public List<GraphicAnimationRecord> GraphicAnimationRecords_SHOW = new List<GraphicAnimationRecord>();
|
||||
public List<TransformAndGraphicAnimationRecord> TransformAndGraphicAnimationRecords_SHOW = new List<TransformAndGraphicAnimationRecord>();
|
||||
|
||||
public List<TransformAnimationRecord> TransformAnimationRecords_HIDE = new List<TransformAnimationRecord>();
|
||||
public List<GraphicAnimationRecord> GraphicAnimationRecords_HIDE = new List<GraphicAnimationRecord>();
|
||||
public List<TransformAndGraphicAnimationRecord> TransformAndGraphicAnimationRecords_HIDE = new List<TransformAndGraphicAnimationRecord>();
|
||||
|
||||
[Min(0.01f)] public float currentRecordDuration = 0.5f;
|
||||
public float currentRecordDelay = 0;
|
||||
|
||||
public bool loop = false;
|
||||
|
||||
private GraphicType graphicType;
|
||||
|
||||
private Graphic graphic;
|
||||
private Image img;
|
||||
//private Text txt;
|
||||
private TextMeshPro txt_m;
|
||||
|
||||
private TransformAnimationRecord initialRectValues;
|
||||
private GraphicAnimationRecord initialGraphicValues;
|
||||
|
||||
private TransformAnimationRecord transformRecord_beforeRecrod;
|
||||
private GraphicAnimationRecord graphicRecord_beforeRecrod;
|
||||
private TransformAndGraphicAnimationRecord transformAndGraphicRecord_beforeRecrod;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
currentRunningCoroutine = EmptyCoroutine();
|
||||
|
||||
rectTransformComponent = GetComponent<RectTransform>();
|
||||
graphic = GetComponent<Graphic>();
|
||||
|
||||
InitializeValues();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if (!initializeComplete)
|
||||
InitializeValues();
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (animateOnEnable)
|
||||
{
|
||||
ShowElement();
|
||||
}
|
||||
}
|
||||
|
||||
private void InitializeValues()
|
||||
{
|
||||
initialRectValues = new TransformAnimationRecord()
|
||||
{
|
||||
Position = rectTransformComponent.localPosition,
|
||||
Scale = rectTransformComponent.localScale,
|
||||
Rotation = rectTransformComponent.eulerAngles,
|
||||
};
|
||||
|
||||
if (graphic)
|
||||
{
|
||||
if (graphic is Image)
|
||||
{
|
||||
graphicType = GraphicType.Image;
|
||||
img = GetComponent<Image>();
|
||||
}
|
||||
// else if (graphic is Text)
|
||||
// {
|
||||
// graphicType = GraphicType.Text;
|
||||
// txt = GetComponent<Text>();
|
||||
// }
|
||||
else if (graphic is TextMeshProUGUI)
|
||||
{
|
||||
graphicType = GraphicType.Text;
|
||||
txt_m = GetComponent<TextMeshPro>();
|
||||
}
|
||||
|
||||
initialGraphicValues = new GraphicAnimationRecord()
|
||||
{
|
||||
Color = graphic.color,
|
||||
Sprite = (graphicType == GraphicType.Image) ? img?.sprite : null,
|
||||
Text = (graphicType == GraphicType.Text) ? txt_m?.text : "",
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public override void ShowElement()
|
||||
{
|
||||
gameObject.SetActive(true);
|
||||
StopAllCoroutines();
|
||||
|
||||
if (disableShowAnimation)
|
||||
{
|
||||
OnShowComplete.Invoke();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!initializeComplete)
|
||||
InitializeValues();
|
||||
|
||||
switch (componentsToAnimate_SHOW)
|
||||
{
|
||||
case (ComponentsToAnimate.Transform):
|
||||
|
||||
if (currentRunningCoroutine != null)
|
||||
StopCoroutine(currentRunningCoroutine);
|
||||
|
||||
currentRunningCoroutine = AnimateTransform_SHOW();
|
||||
StartCoroutine(currentRunningCoroutine);
|
||||
|
||||
break;
|
||||
|
||||
case (ComponentsToAnimate.Graphic):
|
||||
|
||||
if (currentRunningCoroutine != null)
|
||||
StopCoroutine(currentRunningCoroutine);
|
||||
|
||||
currentRunningCoroutine = AnimateGraphic_SHOW();
|
||||
StartCoroutine(currentRunningCoroutine);
|
||||
|
||||
break;
|
||||
|
||||
case (ComponentsToAnimate.Both):
|
||||
|
||||
if (currentRunningCoroutine != null)
|
||||
StopCoroutine(currentRunningCoroutine);
|
||||
|
||||
currentRunningCoroutine = AnimateTransformAndGraphic_SHOW();
|
||||
StartCoroutine(currentRunningCoroutine);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public override void HideElement()
|
||||
{
|
||||
OnHideComplete.AddListener(ResetAll);
|
||||
|
||||
if (disableHideAnimation)
|
||||
{
|
||||
OnHideComplete.Invoke();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
switch (componentsToAnimate_HIDE)
|
||||
{
|
||||
case (ComponentsToAnimate.Transform):
|
||||
|
||||
if (currentRunningCoroutine != null)
|
||||
StopCoroutine(currentRunningCoroutine);
|
||||
|
||||
currentRunningCoroutine = AnimateTransform_HIDE();
|
||||
StartCoroutine(currentRunningCoroutine);
|
||||
|
||||
break;
|
||||
|
||||
case (ComponentsToAnimate.Graphic):
|
||||
|
||||
if (currentRunningCoroutine != null)
|
||||
StopCoroutine(currentRunningCoroutine);
|
||||
|
||||
currentRunningCoroutine = AnimateGraphic_HIDE();
|
||||
StartCoroutine(currentRunningCoroutine);
|
||||
|
||||
break;
|
||||
|
||||
case (ComponentsToAnimate.Both):
|
||||
|
||||
if (currentRunningCoroutine != null)
|
||||
StopCoroutine(currentRunningCoroutine);
|
||||
|
||||
currentRunningCoroutine = AnimateTransformAndGraphic_HIDE();
|
||||
StartCoroutine(currentRunningCoroutine);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#region Show Coroutines
|
||||
|
||||
|
||||
private IEnumerator AnimateTransform_SHOW()
|
||||
{
|
||||
if (delayEnabled)
|
||||
yield return WaitForSeconds_SHOW(showDelay);
|
||||
|
||||
if (TransformAnimationRecords_SHOW.Count > 1)
|
||||
{
|
||||
if (loop)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (OnShow != null)
|
||||
OnShow.Invoke();
|
||||
|
||||
for (int i = 1; i < TransformAnimationRecords_SHOW.Count; i++)
|
||||
{
|
||||
yield return WaitForSeconds_SHOW(TransformAnimationRecords_SHOW[i - 1].Delay);
|
||||
|
||||
float elapsedTime = 0;
|
||||
while (elapsedTime <= TransformAnimationRecords_SHOW[i - 1].Duration)
|
||||
{
|
||||
float t = elapsedTime / TransformAnimationRecords_SHOW[i - 1].Duration;
|
||||
|
||||
rectTransformComponent.localPosition = Vector3.Lerp(TransformAnimationRecords_SHOW[i - 1].Position, TransformAnimationRecords_SHOW[i].Position, t);
|
||||
rectTransformComponent.localScale = Vector3.Lerp(TransformAnimationRecords_SHOW[i - 1].Scale, TransformAnimationRecords_SHOW[i].Scale, t);
|
||||
|
||||
rectTransformComponent.eulerAngles = Vector3.Lerp(TransformAnimationRecords_SHOW[i - 1].Rotation, TransformAnimationRecords_SHOW[i].Rotation, t);
|
||||
|
||||
elapsedTime += DeltaTimeFor_SHOW;
|
||||
yield return (null);
|
||||
}
|
||||
|
||||
#region Set Final Values
|
||||
|
||||
rectTransformComponent.localPosition = TransformAnimationRecords_SHOW[i].Position;
|
||||
rectTransformComponent.localScale = TransformAnimationRecords_SHOW[i].Scale;
|
||||
rectTransformComponent.eulerAngles = TransformAnimationRecords_SHOW[i].Rotation;
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
if (OnShowComplete != null)
|
||||
OnShowComplete.Invoke();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (OnShow != null)
|
||||
OnShow.Invoke();
|
||||
|
||||
for (int i = 1; i < TransformAnimationRecords_SHOW.Count; i++)
|
||||
{
|
||||
yield return WaitForSeconds_SHOW(TransformAnimationRecords_SHOW[i - 1].Delay);
|
||||
|
||||
float elapsedTime = 0;
|
||||
while (elapsedTime <= TransformAnimationRecords_SHOW[i - 1].Duration)
|
||||
{
|
||||
float t = elapsedTime / TransformAnimationRecords_SHOW[i - 1].Duration;
|
||||
|
||||
rectTransformComponent.localPosition = Vector3.Lerp(TransformAnimationRecords_SHOW[i - 1].Position, TransformAnimationRecords_SHOW[i].Position, t);
|
||||
rectTransformComponent.localScale = Vector3.Lerp(TransformAnimationRecords_SHOW[i - 1].Scale, TransformAnimationRecords_SHOW[i].Scale, t);
|
||||
|
||||
rectTransformComponent.eulerAngles = Vector3.Lerp(TransformAnimationRecords_SHOW[i - 1].Rotation, TransformAnimationRecords_SHOW[i].Rotation, t);
|
||||
|
||||
elapsedTime += DeltaTimeFor_SHOW;
|
||||
yield return (null);
|
||||
}
|
||||
|
||||
#region Set Final Values
|
||||
|
||||
rectTransformComponent.localPosition = TransformAnimationRecords_SHOW[i].Position;
|
||||
rectTransformComponent.localScale = TransformAnimationRecords_SHOW[i].Scale;
|
||||
rectTransformComponent.eulerAngles = TransformAnimationRecords_SHOW[i].Rotation;
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
if (OnShowComplete != null)
|
||||
OnShowComplete.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator AnimateGraphic_SHOW()
|
||||
{
|
||||
if (delayEnabled)
|
||||
yield return WaitForSeconds_SHOW(showDelay);
|
||||
|
||||
if (GraphicAnimationRecords_SHOW.Count > 1)
|
||||
{
|
||||
if (loop)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (OnShow != null)
|
||||
OnShow.Invoke();
|
||||
|
||||
for (int i = 1; i < GraphicAnimationRecords_SHOW.Count; i++)
|
||||
{
|
||||
yield return WaitForSeconds_SHOW(GraphicAnimationRecords_SHOW[i - 1].Delay);
|
||||
|
||||
float elapsedTime = 0;
|
||||
while (elapsedTime <= GraphicAnimationRecords_SHOW[i - 1].Duration)
|
||||
{
|
||||
float t = elapsedTime / GraphicAnimationRecords_SHOW[i - 1].Duration;
|
||||
|
||||
if (graphicType == GraphicType.Image)
|
||||
{
|
||||
Image img = graphic as Image;
|
||||
if (GraphicAnimationRecords_SHOW[i - 1].Sprite)
|
||||
{
|
||||
img.sprite = GraphicAnimationRecords_SHOW[i - 1].Sprite;
|
||||
}
|
||||
img.color = Color.Lerp(GraphicAnimationRecords_SHOW[i - 1].Color, GraphicAnimationRecords_SHOW[i].Color, t);
|
||||
}
|
||||
|
||||
else if (graphicType == GraphicType.Text)
|
||||
{
|
||||
TextMeshProUGUI txt = graphic as TextMeshProUGUI;
|
||||
if (!string.IsNullOrEmpty(GraphicAnimationRecords_SHOW[i - 1].Text))
|
||||
{
|
||||
txt.text = GraphicAnimationRecords_SHOW[i - 1].Text;
|
||||
txt.color = Color.Lerp(GraphicAnimationRecords_SHOW[i - 1].Color, GraphicAnimationRecords_SHOW[i].Color, t);
|
||||
}
|
||||
}
|
||||
|
||||
elapsedTime += DeltaTimeFor_SHOW;
|
||||
yield return (null);
|
||||
}
|
||||
|
||||
#region Set Final Values
|
||||
|
||||
if (graphicType == GraphicType.Image)
|
||||
{
|
||||
Image img = graphic as Image;
|
||||
img.sprite = GraphicAnimationRecords_SHOW[i].Sprite;
|
||||
img.color = GraphicAnimationRecords_SHOW[i].Color;
|
||||
}
|
||||
else if (graphicType == GraphicType.Text)
|
||||
{
|
||||
TextMeshProUGUI txt = graphic as TextMeshProUGUI;
|
||||
txt.text = GraphicAnimationRecords_SHOW[i].Text;
|
||||
txt.color = GraphicAnimationRecords_SHOW[i].Color;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
if (OnShowComplete != null)
|
||||
OnShowComplete.Invoke();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (OnShow != null)
|
||||
OnShow.Invoke();
|
||||
|
||||
for (int i = 1; i < GraphicAnimationRecords_SHOW.Count; i++)
|
||||
{
|
||||
yield return WaitForSeconds_SHOW(GraphicAnimationRecords_SHOW[i - 1].Delay);
|
||||
|
||||
float elapsedTime = 0;
|
||||
while (elapsedTime <= GraphicAnimationRecords_SHOW[i - 1].Duration)
|
||||
{
|
||||
float t = elapsedTime / GraphicAnimationRecords_SHOW[i - 1].Duration;
|
||||
|
||||
if (graphicType == GraphicType.Image)
|
||||
{
|
||||
Image img = graphic as Image;
|
||||
if (GraphicAnimationRecords_SHOW[i - 1].Sprite)
|
||||
img.sprite = GraphicAnimationRecords_SHOW[i - 1].Sprite;
|
||||
img.color = Color.Lerp(GraphicAnimationRecords_SHOW[i - 1].Color, GraphicAnimationRecords_SHOW[i].Color, t);
|
||||
}
|
||||
|
||||
else if (graphicType == GraphicType.Text)
|
||||
{
|
||||
TextMeshProUGUI txt = graphic as TextMeshProUGUI;
|
||||
if (!string.IsNullOrEmpty(GraphicAnimationRecords_SHOW[i - 1].Text))
|
||||
txt.text = GraphicAnimationRecords_SHOW[i - 1].Text;
|
||||
txt.color = Color.Lerp(GraphicAnimationRecords_SHOW[i - 1].Color, GraphicAnimationRecords_SHOW[i].Color, t);
|
||||
}
|
||||
|
||||
elapsedTime += DeltaTimeFor_SHOW;
|
||||
yield return (null);
|
||||
}
|
||||
|
||||
#region Set Final Values
|
||||
|
||||
if (graphicType == GraphicType.Image)
|
||||
{
|
||||
Image img = graphic as Image;
|
||||
if (GraphicAnimationRecords_SHOW[i].Sprite)
|
||||
img.sprite = GraphicAnimationRecords_SHOW[i].Sprite;
|
||||
img.color = GraphicAnimationRecords_SHOW[i].Color;
|
||||
}
|
||||
else if (graphicType == GraphicType.Text)
|
||||
{
|
||||
TextMeshProUGUI txt = graphic as TextMeshProUGUI;
|
||||
if (!string.IsNullOrEmpty(GraphicAnimationRecords_SHOW[i].Text))
|
||||
txt.text = GraphicAnimationRecords_SHOW[i].Text;
|
||||
txt.color = GraphicAnimationRecords_SHOW[i].Color;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
if (OnShowComplete != null)
|
||||
OnShowComplete.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator AnimateTransformAndGraphic_SHOW()
|
||||
{
|
||||
if (TransformAndGraphicAnimationRecords_SHOW.Count > 1)
|
||||
{
|
||||
if (delayEnabled)
|
||||
yield return WaitForSeconds_SHOW(showDelay);
|
||||
|
||||
if (loop)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (OnShow != null)
|
||||
OnShow.Invoke();
|
||||
|
||||
for (int i = 1; i < TransformAndGraphicAnimationRecords_SHOW.Count; i++)
|
||||
{
|
||||
yield return WaitForSeconds_SHOW(TransformAndGraphicAnimationRecords_SHOW[i - 1].Delay);
|
||||
|
||||
float elapsedTime = 0;
|
||||
while (elapsedTime <= TransformAndGraphicAnimationRecords_SHOW[i - 1].Duration)
|
||||
{
|
||||
float t = elapsedTime / TransformAndGraphicAnimationRecords_SHOW[i - 1].Duration;
|
||||
|
||||
rectTransformComponent.localPosition = Vector3.Lerp(TransformAndGraphicAnimationRecords_SHOW[i - 1].Position, TransformAndGraphicAnimationRecords_SHOW[i].Position, t);
|
||||
rectTransformComponent.localScale = Vector3.Lerp(TransformAndGraphicAnimationRecords_SHOW[i - 1].Scale, TransformAndGraphicAnimationRecords_SHOW[i].Scale, t);
|
||||
rectTransformComponent.eulerAngles = Vector3.Lerp(TransformAndGraphicAnimationRecords_SHOW[i - 1].Rotation, TransformAndGraphicAnimationRecords_SHOW[i].Rotation, t);
|
||||
|
||||
if (graphicType == GraphicType.Image)
|
||||
{
|
||||
Image img = graphic as Image;
|
||||
if (TransformAndGraphicAnimationRecords_SHOW[i - 1].Sprite)
|
||||
{
|
||||
img.sprite = TransformAndGraphicAnimationRecords_SHOW[i - 1].Sprite;
|
||||
}
|
||||
img.color = Color.Lerp(TransformAndGraphicAnimationRecords_SHOW[i - 1].Color, TransformAndGraphicAnimationRecords_SHOW[i].Color, t);
|
||||
}
|
||||
|
||||
else if (graphicType == GraphicType.Text)
|
||||
{
|
||||
TextMeshProUGUI txt = graphic as TextMeshProUGUI;
|
||||
if (!string.IsNullOrEmpty(TransformAndGraphicAnimationRecords_SHOW[i - 1].Text))
|
||||
{
|
||||
txt.text = TransformAndGraphicAnimationRecords_SHOW[i - 1].Text;
|
||||
}
|
||||
txt.color = Color.Lerp(TransformAndGraphicAnimationRecords_SHOW[i - 1].Color, TransformAndGraphicAnimationRecords_SHOW[i].Color, t);
|
||||
}
|
||||
|
||||
elapsedTime += DeltaTimeFor_SHOW;
|
||||
yield return (null);
|
||||
}
|
||||
|
||||
#region Set Final Values
|
||||
|
||||
rectTransformComponent.localPosition = TransformAndGraphicAnimationRecords_SHOW[i].Position;
|
||||
rectTransformComponent.localScale = TransformAndGraphicAnimationRecords_SHOW[i].Scale;
|
||||
rectTransformComponent.eulerAngles = TransformAndGraphicAnimationRecords_SHOW[i].Rotation;
|
||||
|
||||
if (graphicType == GraphicType.Image)
|
||||
{
|
||||
Image img = graphic as Image;
|
||||
if (TransformAndGraphicAnimationRecords_SHOW[i].Sprite)
|
||||
img.color = TransformAndGraphicAnimationRecords_SHOW[i].Color;
|
||||
}
|
||||
else if (graphicType == GraphicType.Text)
|
||||
{
|
||||
TextMeshProUGUI txt = graphic as TextMeshProUGUI;
|
||||
if (!string.IsNullOrEmpty(TransformAndGraphicAnimationRecords_SHOW[i].Text))
|
||||
txt.color = TransformAndGraphicAnimationRecords_SHOW[i].Color;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
if (OnShowComplete != null)
|
||||
OnShowComplete.Invoke();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
if (OnShow != null)
|
||||
OnShow.Invoke();
|
||||
|
||||
for (int i = 1; i < TransformAndGraphicAnimationRecords_SHOW.Count; i++)
|
||||
{
|
||||
yield return WaitForSeconds_SHOW(TransformAndGraphicAnimationRecords_SHOW[i - 1].Delay);
|
||||
|
||||
float elapsedTime = 0;
|
||||
while (elapsedTime <= TransformAndGraphicAnimationRecords_SHOW[i - 1].Duration)
|
||||
{
|
||||
float t = elapsedTime / TransformAndGraphicAnimationRecords_SHOW[i - 1].Duration;
|
||||
|
||||
rectTransformComponent.localPosition = Vector3.Lerp(TransformAndGraphicAnimationRecords_SHOW[i - 1].Position, TransformAndGraphicAnimationRecords_SHOW[i].Position, t);
|
||||
rectTransformComponent.localScale = Vector3.Lerp(TransformAndGraphicAnimationRecords_SHOW[i - 1].Scale, TransformAndGraphicAnimationRecords_SHOW[i].Scale, t);
|
||||
rectTransformComponent.eulerAngles = Vector3.Lerp(TransformAndGraphicAnimationRecords_SHOW[i - 1].Rotation, TransformAndGraphicAnimationRecords_SHOW[i].Rotation, t);
|
||||
|
||||
if (graphicType == GraphicType.Image)
|
||||
{
|
||||
Image img = graphic as Image;
|
||||
if (TransformAndGraphicAnimationRecords_SHOW[i - 1].Sprite)
|
||||
img.sprite = TransformAndGraphicAnimationRecords_SHOW[i - 1].Sprite;
|
||||
|
||||
img.color = Color.Lerp(TransformAndGraphicAnimationRecords_SHOW[i - 1].Color, TransformAndGraphicAnimationRecords_SHOW[i].Color, t);
|
||||
}
|
||||
|
||||
else if (graphicType == GraphicType.Text)
|
||||
{
|
||||
TextMeshProUGUI txt = graphic as TextMeshProUGUI;
|
||||
if (!string.IsNullOrEmpty(TransformAndGraphicAnimationRecords_SHOW[i - 1].Text))
|
||||
txt.text = TransformAndGraphicAnimationRecords_SHOW[i - 1].Text;
|
||||
|
||||
txt.color = Color.Lerp(TransformAndGraphicAnimationRecords_SHOW[i - 1].Color, TransformAndGraphicAnimationRecords_SHOW[i].Color, t);
|
||||
}
|
||||
|
||||
elapsedTime += DeltaTimeFor_SHOW;
|
||||
yield return (null);
|
||||
}
|
||||
|
||||
#region Set Final Values
|
||||
|
||||
rectTransformComponent.localPosition = TransformAndGraphicAnimationRecords_SHOW[i].Position;
|
||||
rectTransformComponent.localScale = TransformAndGraphicAnimationRecords_SHOW[i].Scale;
|
||||
rectTransformComponent.eulerAngles = TransformAndGraphicAnimationRecords_SHOW[i].Rotation;
|
||||
|
||||
if (graphicType == GraphicType.Image)
|
||||
{
|
||||
Image img = graphic as Image;
|
||||
img.color = TransformAndGraphicAnimationRecords_SHOW[i].Color;
|
||||
}
|
||||
else if (graphicType == GraphicType.Text)
|
||||
{
|
||||
TextMeshProUGUI txt = graphic as TextMeshProUGUI;
|
||||
txt.color = TransformAndGraphicAnimationRecords_SHOW[i].Color;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
if (OnShowComplete != null)
|
||||
OnShowComplete.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
//==========================================================================================
|
||||
//==========================================================================================
|
||||
|
||||
#region Hide Coroutines
|
||||
|
||||
private IEnumerator AnimateTransform_HIDE()
|
||||
{
|
||||
if (delayEnabled)
|
||||
yield return WaitForSeconds_HIDE(hideDelay);
|
||||
|
||||
if (OnShow != null)
|
||||
OnShow.Invoke();
|
||||
|
||||
for (int i = 1; i < TransformAnimationRecords_HIDE.Count; i++)
|
||||
{
|
||||
yield return WaitForSeconds_HIDE(TransformAnimationRecords_HIDE[i - 1].Delay);
|
||||
|
||||
float elapsedTime = 0;
|
||||
while (elapsedTime <= TransformAnimationRecords_HIDE[i - 1].Duration)
|
||||
{
|
||||
float t = elapsedTime / TransformAnimationRecords_HIDE[i - 1].Duration;
|
||||
|
||||
rectTransformComponent.localPosition = Vector3.Lerp(TransformAnimationRecords_HIDE[i - 1].Position, TransformAnimationRecords_HIDE[i].Position, t);
|
||||
rectTransformComponent.localScale = Vector3.Lerp(TransformAnimationRecords_HIDE[i - 1].Scale, TransformAnimationRecords_HIDE[i].Scale, t);
|
||||
rectTransformComponent.eulerAngles = Vector3.Lerp(TransformAnimationRecords_HIDE[i - 1].Rotation, TransformAnimationRecords_HIDE[i].Rotation, t);
|
||||
|
||||
elapsedTime += DeltaTimeFor_HIDE;
|
||||
yield return (null);
|
||||
}
|
||||
|
||||
#region Set Final Values
|
||||
|
||||
rectTransformComponent.localPosition = TransformAnimationRecords_HIDE[i].Position;
|
||||
rectTransformComponent.localScale = TransformAnimationRecords_HIDE[i].Scale;
|
||||
rectTransformComponent.eulerAngles = TransformAnimationRecords_HIDE[i].Rotation;
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
gameObject.SetActive(false);
|
||||
|
||||
if (OnHideComplete != null)
|
||||
OnHideComplete.Invoke();
|
||||
}
|
||||
|
||||
private IEnumerator AnimateGraphic_HIDE()
|
||||
{
|
||||
if (delayEnabled)
|
||||
yield return WaitForSeconds_HIDE(hideDelay);
|
||||
|
||||
if (OnShow != null)
|
||||
OnShow.Invoke();
|
||||
|
||||
for (int i = 1; i < GraphicAnimationRecords_HIDE.Count; i++)
|
||||
{
|
||||
yield return WaitForSeconds_HIDE(GraphicAnimationRecords_HIDE[i - 1].Delay);
|
||||
|
||||
float elapsedTime = 0;
|
||||
while (elapsedTime <= GraphicAnimationRecords_HIDE[i - 1].Duration)
|
||||
{
|
||||
float t = elapsedTime / GraphicAnimationRecords_HIDE[i - 1].Duration;
|
||||
|
||||
if (graphicType == GraphicType.Image)
|
||||
{
|
||||
Image img = graphic as Image;
|
||||
if (GraphicAnimationRecords_HIDE[i - 1].Sprite)
|
||||
img.sprite = GraphicAnimationRecords_HIDE[i - 1].Sprite;
|
||||
img.color = Color.Lerp(GraphicAnimationRecords_HIDE[i - 1].Color, GraphicAnimationRecords_HIDE[i].Color, t);
|
||||
}
|
||||
|
||||
else if (graphicType == GraphicType.Text)
|
||||
{
|
||||
TextMeshProUGUI txt = graphic as TextMeshProUGUI;
|
||||
if (!string.IsNullOrEmpty(GraphicAnimationRecords_HIDE[i - 1].Text))
|
||||
txt.text = GraphicAnimationRecords_HIDE[i - 1].Text;
|
||||
txt.color = Color.Lerp(GraphicAnimationRecords_HIDE[i - 1].Color, GraphicAnimationRecords_HIDE[i].Color, t);
|
||||
}
|
||||
|
||||
elapsedTime += DeltaTimeFor_HIDE;
|
||||
yield return (null);
|
||||
}
|
||||
|
||||
#region Set Final Values
|
||||
|
||||
if (graphicType == GraphicType.Image)
|
||||
{
|
||||
Image img = graphic as Image;
|
||||
img.color = GraphicAnimationRecords_HIDE[i].Color;
|
||||
}
|
||||
else if (graphicType == GraphicType.Text)
|
||||
{
|
||||
TextMeshProUGUI txt = graphic as TextMeshProUGUI;
|
||||
txt.color = GraphicAnimationRecords_HIDE[i].Color;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
gameObject.SetActive(false);
|
||||
|
||||
if (OnHideComplete != null)
|
||||
OnHideComplete.Invoke();
|
||||
}
|
||||
|
||||
private IEnumerator AnimateTransformAndGraphic_HIDE()
|
||||
{
|
||||
if (delayEnabled)
|
||||
yield return WaitForSeconds_HIDE(hideDelay);
|
||||
|
||||
if (OnShow != null)
|
||||
OnShow.Invoke();
|
||||
|
||||
for (int i = 1; i < TransformAndGraphicAnimationRecords_HIDE.Count; i++)
|
||||
{
|
||||
yield return WaitForSeconds_HIDE(TransformAndGraphicAnimationRecords_HIDE[i - 1].Delay);
|
||||
|
||||
float elapsedTime = 0;
|
||||
while (elapsedTime <= TransformAndGraphicAnimationRecords_HIDE[i - 1].Duration)
|
||||
{
|
||||
float t = elapsedTime / TransformAndGraphicAnimationRecords_HIDE[i - 1].Duration;
|
||||
|
||||
rectTransformComponent.localPosition = Vector3.Lerp(TransformAndGraphicAnimationRecords_HIDE[i - 1].Position, TransformAndGraphicAnimationRecords_HIDE[i].Position, t);
|
||||
rectTransformComponent.localScale = Vector3.Lerp(TransformAndGraphicAnimationRecords_HIDE[i - 1].Scale, TransformAndGraphicAnimationRecords_HIDE[i].Scale, t);
|
||||
rectTransformComponent.eulerAngles = Vector3.Lerp(TransformAndGraphicAnimationRecords_HIDE[i - 1].Rotation, TransformAndGraphicAnimationRecords_HIDE[i].Rotation, t);
|
||||
|
||||
if (graphicType == GraphicType.Image)
|
||||
{
|
||||
Image img = graphic as Image;
|
||||
if (TransformAndGraphicAnimationRecords_HIDE[i].Sprite)
|
||||
img.sprite = TransformAndGraphicAnimationRecords_HIDE[i].Sprite;
|
||||
img.color = Color.Lerp(TransformAndGraphicAnimationRecords_HIDE[i - 1].Color, TransformAndGraphicAnimationRecords_HIDE[i].Color, t);
|
||||
}
|
||||
|
||||
else if (graphicType == GraphicType.Text)
|
||||
{
|
||||
TextMeshProUGUI txt = graphic as TextMeshProUGUI;
|
||||
if (!string.IsNullOrEmpty(TransformAndGraphicAnimationRecords_HIDE[i].Text))
|
||||
txt.text = TransformAndGraphicAnimationRecords_HIDE[i].Text;
|
||||
txt.color = Color.Lerp(TransformAndGraphicAnimationRecords_HIDE[i - 1].Color, TransformAndGraphicAnimationRecords_HIDE[i].Color, t);
|
||||
}
|
||||
|
||||
elapsedTime += DeltaTimeFor_HIDE;
|
||||
yield return (null);
|
||||
}
|
||||
|
||||
#region Set Final Values
|
||||
|
||||
rectTransformComponent.localPosition = TransformAndGraphicAnimationRecords_HIDE[i].Position;
|
||||
rectTransformComponent.localScale = TransformAndGraphicAnimationRecords_HIDE[i].Scale;
|
||||
rectTransformComponent.eulerAngles = TransformAndGraphicAnimationRecords_HIDE[i].Rotation;
|
||||
|
||||
if (graphicType == GraphicType.Image)
|
||||
{
|
||||
Image img = graphic as Image;
|
||||
if (TransformAndGraphicAnimationRecords_HIDE[i].Sprite)
|
||||
img.sprite = TransformAndGraphicAnimationRecords_HIDE[i].Sprite;
|
||||
img.color = TransformAndGraphicAnimationRecords_HIDE[i].Color;
|
||||
}
|
||||
else if (graphicType == GraphicType.Text)
|
||||
{
|
||||
TextMeshProUGUI txt = graphic as TextMeshProUGUI;
|
||||
if (!string.IsNullOrEmpty(TransformAndGraphicAnimationRecords_HIDE[i].Text))
|
||||
txt.text = TransformAndGraphicAnimationRecords_HIDE[i].Text;
|
||||
txt.color = TransformAndGraphicAnimationRecords_HIDE[i].Color;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
gameObject.SetActive(false);
|
||||
|
||||
if (OnHideComplete != null)
|
||||
OnHideComplete.Invoke();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private void ResetAll()
|
||||
{
|
||||
rectTransformComponent.localPosition = initialRectValues.Position;
|
||||
rectTransformComponent.localScale = initialRectValues.Scale;
|
||||
rectTransformComponent.eulerAngles = initialRectValues.Rotation;
|
||||
|
||||
if (graphicType == GraphicType.Image)
|
||||
{
|
||||
Image img = graphic as Image;
|
||||
img.sprite = initialGraphicValues.Sprite;
|
||||
img.color = initialGraphicValues.Color;
|
||||
}
|
||||
|
||||
else if (graphicType == GraphicType.Text)
|
||||
{
|
||||
TextMeshProUGUI txt = graphic as TextMeshProUGUI;
|
||||
txt.text = initialGraphicValues.Text;
|
||||
txt.color = initialGraphicValues.Color;
|
||||
}
|
||||
}
|
||||
|
||||
public void Record(GameObject gObject, AnimationShowOrHide showOrHide)
|
||||
{
|
||||
rectTransformComponent = gObject.GetComponent<RectTransform>();
|
||||
graphic = gObject.GetComponent<Graphic>();
|
||||
|
||||
RecordValues(showOrHide, false);
|
||||
}
|
||||
|
||||
public void EnterRecordMode(GameObject gObject, AnimationShowOrHide showOrHide)
|
||||
{
|
||||
rectTransformComponent = gObject.GetComponent<RectTransform>();
|
||||
graphic = gObject.GetComponent<Graphic>();
|
||||
|
||||
transformRecord_beforeRecrod = null;
|
||||
graphicRecord_beforeRecrod = null;
|
||||
transformAndGraphicRecord_beforeRecrod = null;
|
||||
|
||||
RecordValues(showOrHide, true);
|
||||
}
|
||||
|
||||
public void ExitRecordMode(GameObject gObject, AnimationShowOrHide showOrHide)
|
||||
{
|
||||
rectTransformComponent = gObject.GetComponent<RectTransform>();
|
||||
graphic = gObject.GetComponent<Graphic>();
|
||||
|
||||
ReturnValuesAfterRecord(gObject, showOrHide);
|
||||
}
|
||||
|
||||
private void RecordValues(AnimationShowOrHide showOrHide, bool recordModeActive)
|
||||
{
|
||||
ComponentsToAnimate componentsToAnimate = (showOrHide == AnimationShowOrHide.Show) ? componentsToAnimate_SHOW : componentsToAnimate_HIDE;
|
||||
|
||||
switch (componentsToAnimate)
|
||||
{
|
||||
case (ComponentsToAnimate.Transform):
|
||||
TransformAnimationRecord transformRecord = new TransformAnimationRecord()
|
||||
{
|
||||
Duration = currentRecordDuration,
|
||||
Delay = currentRecordDelay,
|
||||
|
||||
Position = rectTransformComponent.localPosition,
|
||||
Scale = rectTransformComponent.localScale,
|
||||
Rotation = new Vector3
|
||||
(
|
||||
rectTransformComponent.eulerAngles.x > 180 ? rectTransformComponent.eulerAngles.x - 360 : rectTransformComponent.eulerAngles.x,
|
||||
rectTransformComponent.eulerAngles.y > 180 ? rectTransformComponent.eulerAngles.y - 360 : rectTransformComponent.eulerAngles.y,
|
||||
rectTransformComponent.eulerAngles.z > 180 ? rectTransformComponent.eulerAngles.z - 360 : rectTransformComponent.eulerAngles.z
|
||||
)
|
||||
};
|
||||
|
||||
if (recordModeActive)
|
||||
{
|
||||
transformRecord_beforeRecrod = transformRecord;
|
||||
return;
|
||||
}
|
||||
|
||||
if (showOrHide == AnimationShowOrHide.Show)
|
||||
TransformAnimationRecords_SHOW.Add(transformRecord);
|
||||
else
|
||||
TransformAnimationRecords_HIDE.Add(transformRecord);
|
||||
|
||||
break;
|
||||
|
||||
case (ComponentsToAnimate.Graphic):
|
||||
if (graphic is Image)
|
||||
{
|
||||
img = graphic as Image;
|
||||
graphicType = GraphicType.Image;
|
||||
}
|
||||
else if (graphic is TextMeshPro)
|
||||
{
|
||||
txt_m = graphic as TextMeshPro;
|
||||
graphicType = GraphicType.Text;
|
||||
}
|
||||
|
||||
GraphicAnimationRecord graphicRecord = new GraphicAnimationRecord()
|
||||
{
|
||||
Duration = currentRecordDuration,
|
||||
Delay = currentRecordDelay,
|
||||
|
||||
Color = graphic.color,
|
||||
Sprite = (graphicType == GraphicType.Image) ? img.sprite : null,
|
||||
Text = (graphicType == GraphicType.Text) ? txt_m.text : ""
|
||||
};
|
||||
|
||||
if (recordModeActive)
|
||||
{
|
||||
graphicRecord_beforeRecrod = graphicRecord;
|
||||
return;
|
||||
}
|
||||
|
||||
if (showOrHide == AnimationShowOrHide.Show)
|
||||
GraphicAnimationRecords_SHOW.Add(graphicRecord);
|
||||
else
|
||||
GraphicAnimationRecords_HIDE.Add(graphicRecord);
|
||||
break;
|
||||
|
||||
case (ComponentsToAnimate.Both):
|
||||
if (graphic is Image)
|
||||
{
|
||||
img = graphic as Image;
|
||||
graphicType = GraphicType.Image;
|
||||
}
|
||||
else if (graphic is TextMeshProUGUI)
|
||||
{
|
||||
txt_m = graphic as TextMeshPro;
|
||||
graphicType = GraphicType.Text;
|
||||
}
|
||||
|
||||
TransformAndGraphicAnimationRecord transformAndGrapihcRecord = new TransformAndGraphicAnimationRecord()
|
||||
{
|
||||
Duration = currentRecordDuration,
|
||||
Delay = currentRecordDelay,
|
||||
|
||||
Position = rectTransformComponent.localPosition,
|
||||
Scale = rectTransformComponent.localScale,
|
||||
Rotation = new Vector3
|
||||
(
|
||||
rectTransformComponent.eulerAngles.x > 180 ? rectTransformComponent.eulerAngles.x - 360 : rectTransformComponent.eulerAngles.x,
|
||||
rectTransformComponent.eulerAngles.y > 180 ? rectTransformComponent.eulerAngles.y - 360 : rectTransformComponent.eulerAngles.y,
|
||||
rectTransformComponent.eulerAngles.z > 180 ? rectTransformComponent.eulerAngles.z - 360 : rectTransformComponent.eulerAngles.z
|
||||
),
|
||||
|
||||
Color = graphic.color,
|
||||
Sprite = (graphicType == GraphicType.Image) ? img.sprite : null,
|
||||
Text = (graphicType == GraphicType.Text) ? txt_m.text : ""
|
||||
};
|
||||
|
||||
if (recordModeActive)
|
||||
{
|
||||
transformAndGraphicRecord_beforeRecrod = transformAndGrapihcRecord;
|
||||
return;
|
||||
}
|
||||
|
||||
if (showOrHide == AnimationShowOrHide.Show)
|
||||
TransformAndGraphicAnimationRecords_SHOW.Add(transformAndGrapihcRecord);
|
||||
else
|
||||
TransformAndGraphicAnimationRecords_HIDE.Add(transformAndGrapihcRecord);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void ReturnValuesAfterRecord(GameObject gObject, AnimationShowOrHide showOrHide)
|
||||
{
|
||||
ComponentsToAnimate componentsToAnimate = (showOrHide == AnimationShowOrHide.Show) ? componentsToAnimate_SHOW : componentsToAnimate_HIDE;
|
||||
|
||||
switch (componentsToAnimate)
|
||||
{
|
||||
case (ComponentsToAnimate.Transform):
|
||||
rectTransformComponent.localPosition = transformRecord_beforeRecrod.Position;
|
||||
rectTransformComponent.localScale = transformRecord_beforeRecrod.Scale;
|
||||
rectTransformComponent.eulerAngles = transformRecord_beforeRecrod.Rotation;
|
||||
|
||||
break;
|
||||
case (ComponentsToAnimate.Graphic):
|
||||
graphic.color = graphicRecord_beforeRecrod.Color;
|
||||
|
||||
if (graphic is Image)
|
||||
gObject.GetComponent<Image>().sprite = graphicRecord_beforeRecrod.Sprite;
|
||||
else if (graphic is TextMeshProUGUI)
|
||||
gObject.GetComponent<TextMeshProUGUI>().text = graphicRecord_beforeRecrod.Text;
|
||||
|
||||
break;
|
||||
case (ComponentsToAnimate.Both):
|
||||
rectTransformComponent.localPosition = transformAndGraphicRecord_beforeRecrod.Position;
|
||||
rectTransformComponent.localScale = transformAndGraphicRecord_beforeRecrod.Scale;
|
||||
rectTransformComponent.eulerAngles = transformAndGraphicRecord_beforeRecrod.Rotation;
|
||||
|
||||
graphic.color = transformAndGraphicRecord_beforeRecrod.Color;
|
||||
if (graphic is Image)
|
||||
gObject.GetComponent<Image>().sprite = transformAndGraphicRecord_beforeRecrod.Sprite;
|
||||
else if (graphic is TextMeshProUGUI)
|
||||
gObject.GetComponent<TextMeshProUGUI>().text = transformAndGraphicRecord_beforeRecrod.Text;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
transformRecord_beforeRecrod = null;
|
||||
graphicRecord_beforeRecrod = null;
|
||||
transformAndGraphicRecord_beforeRecrod = null;
|
||||
}
|
||||
|
||||
public enum ComponentsToAnimate
|
||||
{
|
||||
Transform = 0, Graphic = 1, Both = 2
|
||||
}
|
||||
|
||||
public enum AnimationShowOrHide
|
||||
{
|
||||
Show = 0, Hide = 1
|
||||
}
|
||||
|
||||
private enum GraphicType
|
||||
{
|
||||
Image = 0, Text = 1
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class TransformAnimationRecord
|
||||
{
|
||||
public float Delay;
|
||||
[Min(0.01f)] public float Duration = 0.5f;
|
||||
|
||||
public Vector3 Position; // The anchored position.
|
||||
public Vector3 Scale;
|
||||
public Vector3 Rotation;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class GraphicAnimationRecord
|
||||
{
|
||||
public float Delay;
|
||||
[Min(0.01f)] public float Duration = 0.5f;
|
||||
|
||||
[Tooltip("Only works if the game object has Image component")] public Sprite Sprite;
|
||||
[Tooltip("Only works if the game object has Text component")] public string Text;
|
||||
public Color Color;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class TransformAndGraphicAnimationRecord
|
||||
{
|
||||
public float Delay;
|
||||
[Min(0.01f)] public float Duration = 0.5f;
|
||||
|
||||
public Vector3 Position;
|
||||
public Vector3 Scale;
|
||||
public Vector3 Rotation;
|
||||
|
||||
[Tooltip("Only works if the game object has Image component")] public Sprite Sprite;
|
||||
[Tooltip("Only works if the game object has Text component")] public string Text;
|
||||
public Color Color;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c69e9fcc3b192734a80b5e34d3132db6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: 7302f66924eef9247b9bc469e954b55c, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 135898
|
||||
packageName: Airy UI 2 - Easy UI Animation
|
||||
packageVersion: 2.0.2
|
||||
assetPath: Assets/Airy UI/Scripts/CustomAnimatedElement.cs
|
||||
uploadId: 760159
|
||||
@@ -0,0 +1,77 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
namespace AiryUI
|
||||
{
|
||||
|
||||
|
||||
public class EscButtonController : MonoBehaviour
|
||||
{
|
||||
|
||||
|
||||
public List<EscCloseButton> esc_buttons = new List<EscCloseButton> ();
|
||||
|
||||
|
||||
public static EscButtonController Instance;
|
||||
|
||||
|
||||
private void Awake ()
|
||||
{
|
||||
if ( Instance == null )
|
||||
Instance = this;
|
||||
else
|
||||
Destroy ( gameObject );
|
||||
}
|
||||
|
||||
|
||||
private void Update ()
|
||||
{
|
||||
if ( Input.GetKeyDown ( KeyCode.Escape ) )
|
||||
{
|
||||
DoBack ();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void DoBack ()
|
||||
{
|
||||
if ( esc_buttons.Count > 0 )
|
||||
{
|
||||
var last_button = esc_buttons [ esc_buttons.Count - 1 ];
|
||||
|
||||
if ( last_button != null )
|
||||
{
|
||||
last_button.DoBack ();
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError ( "<color=orange><b>[Airy UI]</color></b> <color=red><b>X</color></b> there's a missing item in <b>'ESC Button Controller'</b>, please check your list again!" , gameObject );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void AddButtonToList ( EscCloseButton backButton )
|
||||
{
|
||||
if ( !esc_buttons.Contains ( backButton ) )
|
||||
{
|
||||
esc_buttons.Add ( backButton );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void RemoveButtonFromList ( EscCloseButton backButton )
|
||||
{
|
||||
if ( esc_buttons.Contains ( backButton ) )
|
||||
{
|
||||
esc_buttons.Remove ( backButton );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 20d6b40c8f6527141812c945d9ab89a4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: 385aabfb1d7577e4eab41a95a7aa5c6e, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 135898
|
||||
packageName: Airy UI 2 - Easy UI Animation
|
||||
packageVersion: 2.0.2
|
||||
assetPath: Assets/Airy UI/Scripts/EscButtonController.cs
|
||||
uploadId: 760159
|
||||
@@ -0,0 +1,118 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
namespace AiryUI
|
||||
{
|
||||
|
||||
|
||||
[AddComponentMenu ( "Airy UI/Esc Close Button" )]
|
||||
public class EscCloseButton : CloseButton
|
||||
{
|
||||
|
||||
|
||||
private EscButtonController manager;
|
||||
|
||||
|
||||
private void Awake ()
|
||||
{
|
||||
InstantiateController ();
|
||||
|
||||
if ( backButtonAffects == BackButtonAffects.AnimatedElement )
|
||||
{
|
||||
if ( affectedAnimatedElement == null )
|
||||
{
|
||||
Debug.LogError ( "<color=orange><b>[Airy UI]</color></b> <color=red><b>X</color></b> Affected Animated Element is null, please set it" , gameObject );
|
||||
return;
|
||||
}
|
||||
|
||||
affectedAnimatedElement.OnShow.AddListener ( () => EscButtonController.Instance.AddButtonToList ( this ) );
|
||||
affectedAnimatedElement.OnHide.AddListener ( () => EscButtonController.Instance.RemoveButtonFromList ( this ) );
|
||||
}
|
||||
else if ( backButtonAffects == BackButtonAffects.AnimatedElementsGroup )
|
||||
{
|
||||
if ( affectedAnimatedElementsGroup == null )
|
||||
{
|
||||
Debug.LogError ( "<color=orange><b>[Airy UI]</color></b> <color=red><b>X</color></b> Affected Animated Elements Group is null, please set it" , gameObject );
|
||||
return;
|
||||
}
|
||||
affectedAnimatedElementsGroup.OnShow.AddListener ( () => EscButtonController.Instance.AddButtonToList ( this ) );
|
||||
affectedAnimatedElementsGroup.OnHide.AddListener ( () => EscButtonController.Instance.RemoveButtonFromList ( this ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void Start ()
|
||||
{
|
||||
InstantiateController ();
|
||||
}
|
||||
|
||||
|
||||
private void OnEnable ()
|
||||
{
|
||||
InstantiateController ();
|
||||
}
|
||||
|
||||
|
||||
private void OnValidate ()
|
||||
{
|
||||
InstantiateController ();
|
||||
|
||||
manager = FindObjectOfType<EscButtonController> ();
|
||||
|
||||
if ( manager != null )
|
||||
{
|
||||
if ( !manager.esc_buttons.Contains ( this ) )
|
||||
{
|
||||
//manager.esc_buttons.Add ( this );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void Reset ()
|
||||
{
|
||||
InstantiateController ();
|
||||
}
|
||||
|
||||
|
||||
public override void DoBack ()
|
||||
{
|
||||
base.DoBack ();
|
||||
}
|
||||
|
||||
|
||||
private void InstantiateController ()
|
||||
{
|
||||
if ( !FindObjectOfType<EscButtonController> () )
|
||||
{
|
||||
GameObject controller = new GameObject ( "[Airy UI] Esc Button Controller" );
|
||||
controller.AddComponent<EscButtonController> ();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#if UNITY_EDITOR
|
||||
|
||||
|
||||
[MenuItem ( "GameObject/Airy UI/Esc Close Button" , false , 2 )]
|
||||
private static void HierarchyCreateMenu ( MenuCommand menuCommand )
|
||||
{
|
||||
GameObject newGameObject = new GameObject ( "Esc Close Button" );
|
||||
|
||||
newGameObject.AddComponent<EscCloseButton> ();
|
||||
|
||||
GameObjectUtility.SetParentAndAlign ( newGameObject , menuCommand.context as GameObject );
|
||||
|
||||
Undo.RegisterCreatedObjectUndo ( newGameObject , "Create " + newGameObject.name );
|
||||
|
||||
Selection.activeObject = newGameObject;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7f91f9ffb1c2c1041bff92bcaecf4752
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: 135e03f43ae12554e87964b6cc57b425, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 135898
|
||||
packageName: Airy UI 2 - Easy UI Animation
|
||||
packageVersion: 2.0.2
|
||||
assetPath: Assets/Airy UI/Scripts/EscCloseButton.cs
|
||||
uploadId: 760159
|
||||
@@ -0,0 +1,93 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
|
||||
namespace AiryUI
|
||||
{
|
||||
|
||||
|
||||
[RequireComponent ( typeof ( Image ) )]
|
||||
[RequireComponent ( typeof ( Button ) )]
|
||||
[RequireComponent ( typeof ( AnimatedElement ) )]
|
||||
[AddComponentMenu ( "Airy UI/UI Close Button" )]
|
||||
public class UICloseButton : CloseButton
|
||||
{
|
||||
|
||||
|
||||
public Button buttonComponent;
|
||||
|
||||
|
||||
private AnimatedElement myAnimatedElement;
|
||||
|
||||
|
||||
private void Awake ()
|
||||
{
|
||||
buttonComponent = buttonComponent ? GetComponent<Button> () : buttonComponent;
|
||||
myAnimatedElement = GetComponent<AnimatedElement> ();
|
||||
|
||||
|
||||
buttonComponent.onClick.AddListener ( DoBack );
|
||||
|
||||
|
||||
if ( backButtonAffects == BackButtonAffects.AnimatedElement && affectedAnimatedElement != null )
|
||||
{
|
||||
affectedAnimatedElement.OnShow.AddListener ( myAnimatedElement.ShowElement );
|
||||
}
|
||||
else if ( backButtonAffects == BackButtonAffects.AnimatedElementsGroup && affectedAnimatedElementsGroup != null && !affectedAnimatedElementsGroup.animatedElements.Contains ( myAnimatedElement ) )
|
||||
{
|
||||
affectedAnimatedElementsGroup.animatedElements.Add ( myAnimatedElement );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void Reset ()
|
||||
{
|
||||
buttonComponent = GetComponent<Button> ();
|
||||
}
|
||||
|
||||
|
||||
private void OnValidate ()
|
||||
{
|
||||
buttonComponent = GetComponent<Button> ();
|
||||
|
||||
if ( backButtonAffects == BackButtonAffects.AnimatedElementsGroup && affectedAnimatedElementsGroup != null && !affectedAnimatedElementsGroup.animatedElements.Contains ( GetComponent<AnimatedElement> () ) )
|
||||
{
|
||||
affectedAnimatedElementsGroup.animatedElements.Add ( GetComponent<AnimatedElement> () );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public override void DoBack ()
|
||||
{
|
||||
base.DoBack ();
|
||||
|
||||
myAnimatedElement.HideElement ();
|
||||
}
|
||||
|
||||
|
||||
#if UNITY_EDITOR
|
||||
|
||||
|
||||
[MenuItem ( "GameObject/Airy UI/UI Close Button" , false , 1 )]
|
||||
private static void HierarchyCreateMenu ( MenuCommand menuCommand )
|
||||
{
|
||||
GameObject newGameObject = new GameObject ( "UI Close Button" );
|
||||
|
||||
newGameObject.AddComponent<UICloseButton> ();
|
||||
|
||||
GameObjectUtility.SetParentAndAlign ( newGameObject , menuCommand.context as GameObject );
|
||||
|
||||
Undo.RegisterCreatedObjectUndo ( newGameObject , "Create " + newGameObject.name );
|
||||
|
||||
Selection.activeObject = newGameObject;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 17cdd31cbca20554baf3a78326c9e6b7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: dac0515b2a64d0449b98bccca9da0dc0, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 135898
|
||||
packageName: Airy UI 2 - Easy UI Animation
|
||||
packageVersion: 2.0.2
|
||||
assetPath: Assets/Airy UI/Scripts/UICloseButton.cs
|
||||
uploadId: 760159
|
||||
Reference in New Issue
Block a user