diff --git a/Assets/Airy UI.meta b/Assets/Airy UI.meta new file mode 100644 index 00000000..02179a63 --- /dev/null +++ b/Assets/Airy UI.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 98bf3013986885e42b9a3008e96d1ab6 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Airy UI/Documentaion.pdf b/Assets/Airy UI/Documentaion.pdf new file mode 100644 index 00000000..eb0d0ec0 Binary files /dev/null and b/Assets/Airy UI/Documentaion.pdf differ diff --git a/Assets/Airy UI/Documentaion.pdf.meta b/Assets/Airy UI/Documentaion.pdf.meta new file mode 100644 index 00000000..5620be47 --- /dev/null +++ b/Assets/Airy UI/Documentaion.pdf.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: bc34832782a9bb946ae1d279f2d64b5d +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 135898 + packageName: Airy UI 2 - Easy UI Animation + packageVersion: 2.0.2 + assetPath: Assets/Airy UI/Documentaion.pdf + uploadId: 760159 diff --git a/Assets/Airy UI/Editor.meta b/Assets/Airy UI/Editor.meta new file mode 100644 index 00000000..f5726f63 --- /dev/null +++ b/Assets/Airy UI/Editor.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: dfb6c47b156dfbe409d45250c3ada088 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Airy UI/Editor/Anchors_Window.cs b/Assets/Airy UI/Editor/Anchors_Window.cs new file mode 100644 index 00000000..544f0302 --- /dev/null +++ b/Assets/Airy UI/Editor/Anchors_Window.cs @@ -0,0 +1,451 @@ +using UnityEngine; +using UnityEditor; + + +namespace AiryUI +{ + + public class Anchors_Window : EditorWindow + { + private static EditorWindow window; + private GUIStyle buttonContentStyle; + + + private bool infoFoldout; + private Vector2 windowScroll; + + + [MenuItem ( "Airy UI/Anchors Window" , priority = 1 )] + private static void ShowWindow () + { + window = GetWindow ( "Anchors Window" ); + + window.maxSize = new Vector2 ( 345 , 430 ); + window.minSize = new Vector2 ( 345 , 430 ); + window.Show (); + } + + + private void OnGUI () + { + windowScroll = EditorGUILayout.BeginScrollView ( windowScroll , false , false ); + + //GUI.color = Color.gray; + //WindowTitle_LABEL (); + //GUI.color = Color.white; + + EditorGUILayout.Space ( 20 ); + + ImportantInfo (); + + GUILayout.Space ( 20 ); + + GUI.color = Color.white; + + DrawWindow (); + + DrawRateBox (); + DrawYoutube (); + + EditorGUILayout.EndScrollView (); + } + + + private void WindowTitle_LABEL () + { + GUILayout.Space ( 10 ); + + var titleLabelStyle = new GUIStyle ( GUI.skin.label ) { alignment = TextAnchor.UpperCenter , fontSize = 30 , fontStyle = FontStyle.Bold , fixedHeight = 50 }; + + EditorGUILayout.LabelField ( "Anchors Editor" , titleLabelStyle ); + EditorGUILayout.Space (); EditorGUILayout.Space (); EditorGUILayout.Space (); + + GUILayout.Space ( 30 ); + } + + + private void ImportantInfo () + { + infoFoldout = EditorGUILayout.BeginFoldoutHeaderGroup ( infoFoldout , "Important Info" ); + if ( infoFoldout ) + { + GUI.color = Color.white; + + EditorGUILayout.HelpBox ( "Scale of RectTransform must be (1, 1, 1) in order for the anchors to be exact." , MessageType.Warning ); + EditorGUILayout.HelpBox ( "Sometimes, you may need to set anchors twice if the pivot is not centered." , MessageType.Info ); + EditorGUILayout.HelpBox ( "You can select multiple Game Objects, and use the shortcut ctrl, shift, q or ctrl, shift, w" , MessageType.Info ); + } + } + + + [MenuItem ( "Airy UI/Anchors/Set Anchors To Fit Rect %#q" , priority = 2 )] + public static void SetAnchorsToRectOnSelectedGameObjects_Shortcut () + { + SetAnchorsToRectOnSelectedGameObjects (); + } + + + [MenuItem ( "Airy UI/Anchors/Align Selected To Anchors %#w" , priority = 2 )] + public static void SetRectToAnchorsOnSelectedGameObjects_Shortcut () + { + SetRectToAnchorsOnSelectedGameObjects (); + } + + + private void DrawWindow () + { + EditorGUILayout.BeginHorizontal (); + + + SetButtonStyle ( new Color ( 0.31f , 0.51f , 1 ) , fontSize: 11 , height: 100 ); + GUIContent buttonContent = new GUIContent ( "↖ ↗\n↙ ↘\nANCHORS TO RECT\n\nctrl, shift, q" ); + + if ( GUILayout.Button ( buttonContent , buttonContentStyle ) ) + { + SetAnchorsToRectOnSelectedGameObjects (); + } + + + SetButtonStyle ( new Color ( 0.74f , 0 , 0.37f ) , fontSize: 11 , height: 100 ); + buttonContent = new GUIContent ( "↘ ↙\n↗ ↖\nRECT TO ANCHORS\n\nctrl, shift, w" ); + + + if ( GUILayout.Button ( buttonContent , buttonContentStyle ) ) + { + SetRectToAnchorsOnSelectedGameObjects (); + } + + EditorGUILayout.EndHorizontal (); + + GUILayout.Space ( 10 ); + + EditorGUILayout.BeginHorizontal (); + + + SetButtonStyle ( new Color ( 0 , 1 , 0.9f ) , fontSize: 11 , 30 ); + buttonContent = new GUIContent ( "↖" ); + + + if ( GUILayout.Button ( buttonContent , buttonContentStyle ) ) + { + foreach ( var g in Selection.gameObjects ) + { + RectTransform rectTransform = g.GetComponent (); + + if ( rectTransform != null ) + { + Undo.RecordObject ( rectTransform , "Set Anchors" ); + Anchors.SetAnchorsTopLeft ( rectTransform ); + } + } + + if ( Selection.gameObjects.Length > 0 ) + PrintDoneMessage (); + } + + + SetButtonStyle ( new Color ( 0 , 1 , 0.9f ) , fontSize: 11 , 30 ); + buttonContent = new GUIContent ( "▲" ); + + + if ( GUILayout.Button ( buttonContent , buttonContentStyle ) ) + { + foreach ( var g in Selection.gameObjects ) + { + RectTransform rectTransform = g.GetComponent (); + + if ( rectTransform != null ) + { + Undo.RecordObject ( rectTransform , "Set Anchors" ); + Anchors.SetAnchorsTop ( rectTransform ); + } + } + + if ( Selection.gameObjects.Length > 0 ) + PrintDoneMessage (); + } + + + SetButtonStyle ( new Color ( 0 , 1 , 0.9f ) , fontSize: 11 , 30 ); + buttonContent = new GUIContent ( "↗" ); + + + if ( GUILayout.Button ( buttonContent , buttonContentStyle ) ) + { + foreach ( var g in Selection.gameObjects ) + { + RectTransform rectTransform = g.GetComponent (); + + if ( rectTransform != null ) + { + Undo.RecordObject ( rectTransform , "Set Anchors" ); + Anchors.SetAnchorsTopRight ( rectTransform ); + } + } + + if ( Selection.gameObjects.Length > 0 ) + PrintDoneMessage (); + } + + EditorGUILayout.EndHorizontal (); + + EditorGUILayout.BeginHorizontal (); + + + SetButtonStyle ( new Color ( 0 , 1 , 0.9f ) , fontSize: 11 , 30 ); + buttonContent = new GUIContent ( "◄" ); + + + if ( GUILayout.Button ( buttonContent , buttonContentStyle ) ) + { + foreach ( var g in Selection.gameObjects ) + { + RectTransform rectTransform = g.GetComponent (); + + if ( rectTransform != null ) + { + Undo.RecordObject ( rectTransform , "Set Anchors" ); + Anchors.SetAnchorsLeft ( rectTransform ); + } + } + + if ( Selection.gameObjects.Length > 0 ) + PrintDoneMessage (); + } + + + SetButtonStyle ( new Color ( 1 , 0.46f , 0 ) , fontSize: 11 , 30 ); + buttonContent = new GUIContent ( "●" ); + + + if ( GUILayout.Button ( buttonContent , buttonContentStyle ) ) + { + foreach ( var g in Selection.gameObjects ) + { + RectTransform rectTransform = g.GetComponent (); + + if ( rectTransform != null ) + { + Undo.RecordObject ( rectTransform , "Set Anchors" ); + Anchors.SetAnchorsCenter ( rectTransform ); + } + } + + if ( Selection.gameObjects.Length > 0 ) + PrintDoneMessage (); + } + + + SetButtonStyle ( new Color ( 0 , 1 , 0.9f ) , fontSize: 11 , 30 ); + buttonContent = new GUIContent ( "►" ); + + + if ( GUILayout.Button ( buttonContent , buttonContentStyle ) ) + { + foreach ( var g in Selection.gameObjects ) + { + RectTransform rectTransform = g.GetComponent (); + + if ( rectTransform != null ) + { + Undo.RecordObject ( rectTransform , "Set Anchors" ); + Anchors.SetAnchorsRight ( rectTransform ); + } + } + + if ( Selection.gameObjects.Length > 0 ) + PrintDoneMessage (); + } + + EditorGUILayout.EndHorizontal (); + + EditorGUILayout.BeginHorizontal (); + + + SetButtonStyle ( new Color ( 0 , 1 , 0.9f ) , fontSize: 11 , 30 ); + buttonContent = new GUIContent ( "↙" ); + + + if ( GUILayout.Button ( buttonContent , buttonContentStyle ) ) + { + foreach ( var g in Selection.gameObjects ) + { + RectTransform rectTransform = g.GetComponent (); + + if ( rectTransform != null ) + { + Undo.RecordObject ( rectTransform , "Set Anchors" ); + Anchors.SetAnchorsBottomLeft ( rectTransform ); + } + } + if ( Selection.gameObjects.Length > 0 ) + PrintDoneMessage (); + + } + + + SetButtonStyle ( new Color ( 0 , 1 , 0.9f ) , fontSize: 11 , 30 ); + buttonContent = new GUIContent ( "▼" ); + + + if ( GUILayout.Button ( buttonContent , buttonContentStyle ) ) + { + foreach ( var g in Selection.gameObjects ) + { + RectTransform rectTransform = g.GetComponent (); + + if ( rectTransform != null ) + { + Undo.RecordObject ( rectTransform , "Set Anchors" ); + Anchors.SetAnchorsBottom ( rectTransform ); + } + } + if ( Selection.gameObjects.Length > 0 ) + PrintDoneMessage (); + } + + + SetButtonStyle ( new Color ( 0 , 1 , 0.9f ) , fontSize: 11 , 30 ); + buttonContent = new GUIContent ( "↘" ); + + + if ( GUILayout.Button ( buttonContent , buttonContentStyle ) ) + { + foreach ( var g in Selection.gameObjects ) + { + RectTransform rectTransform = g.GetComponent (); + + if ( rectTransform != null ) + { + Undo.RecordObject ( rectTransform , "Set Anchors" ); + Anchors.SetAnchorsBottomRight ( rectTransform ); + } + } + + if ( Selection.gameObjects.Length > 0 ) + PrintDoneMessage (); + } + + EditorGUILayout.EndHorizontal (); + + + EditorGUILayout.Space ( 20 ); + } + + + private void DrawRateBox () + { + GUILayout.Label ( "If you like Airy UI, Please Rate it On Asset Store ♡" ); + + SetButtonStyle ( new Color ( 0.317f , 1 , 0.43f ) , fontSize: 15 , height: 30 , width: 338 , alignment: TextAnchor.MiddleLeft ); + + GUIContent buttonContent = new GUIContent ( " Rate ♡" , SetIcon ( "asset_store.png" ) ); + + if ( GUILayout.Button ( buttonContent , buttonContentStyle ) ) + Application.OpenURL ( "https://assetstore.unity.com/packages/tools/gui/airy-ui-easy-ui-animation-135898" ); + + GUILayout.Space ( 10 ); + } + + + private void DrawYoutube () + { + GUILayout.Label ( "And also, take a visit to my GameDev Youtube channel" ); + + SetButtonStyle ( new Color ( 0.31f , 0.51f , 1 ) , fontSize: 15 , height: 30 , width: 338 , alignment: TextAnchor.MiddleLeft ); + + GUIContent buttonContent = new GUIContent ( " Visit ♡" , SetIcon ( "youtube.png" ) ); + + if ( GUILayout.Button ( buttonContent , buttonContentStyle ) ) + Application.OpenURL ( "https://youtube.com/ahmedsabrygamedev" ); + } + + + private void SetButtonStyle ( Color backgroundColor , int fontSize = 0 , float height = 0 , float width = 0 , TextAnchor alignment = TextAnchor.MiddleCenter ) + { + GUI.backgroundColor = backgroundColor; + buttonContentStyle = null; + buttonContentStyle = new GUIStyle ( GUI.skin.button ); + + buttonContentStyle.alignment = alignment; + buttonContentStyle.normal.textColor = Color.white; + buttonContentStyle.hover.textColor = Color.yellow; + + if ( height != 0 ) + buttonContentStyle.fixedHeight = height; + + if ( width != 0 ) + buttonContentStyle.fixedWidth = width; + + if ( fontSize != 0 ) + buttonContentStyle.fontSize = fontSize; + + buttonContentStyle.fontStyle = FontStyle.Bold; + } + + + private Texture2D SetIcon ( string icon ) + { + Texture2D buttonIcon = AssetDatabase.LoadAssetAtPath ( "Assets/Airy UI/Sprites/Icons/" + icon ); + + return buttonIcon; + } + + + + private static void SetAnchorsToRectOnSelectedGameObjects () + { + GameObject [] selectedGameObjects = Selection.gameObjects; + + foreach ( var g in selectedGameObjects ) + { + RectTransform rectTransform = g.GetComponent (); + + if ( rectTransform != null ) + { + Undo.RecordObject ( rectTransform , "Set Anchors" ); + Anchors.SetAnchorsToRect ( rectTransform ); + + } + } + + PrintDoneMessage (); + } + + + private static void SetRectToAnchorsOnSelectedGameObjects () + { + GameObject [] selectedGameObjects = Selection.gameObjects; + + foreach ( var g in selectedGameObjects ) + { + RectTransform rectTransform = g.GetComponent (); + + if ( rectTransform != null ) + { + Undo.RecordObject ( rectTransform , "Set Anchors" ); + Anchors.SetRectToAnchor ( rectTransform ); + + } + } + + PrintDoneMessage (); + } + + + + private static void PrintDoneMessage () + { + Debug.Log ( "[Airy UI]" + + "" + + " anchors set for " + + Selection.gameObjects.Length + + " game object/s" ); + } + + + + } + + +} \ No newline at end of file diff --git a/Assets/Airy UI/Editor/Anchors_Window.cs.meta b/Assets/Airy UI/Editor/Anchors_Window.cs.meta new file mode 100644 index 00000000..99bd32f1 --- /dev/null +++ b/Assets/Airy UI/Editor/Anchors_Window.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: b54607e6e292a474491ff4e6f8e143f5 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 76009eabd85feab4db90da457c751412, 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/Editor/Anchors_Window.cs + uploadId: 760159 diff --git a/Assets/Airy UI/Editor/AnimatedElement_Inspector.cs b/Assets/Airy UI/Editor/AnimatedElement_Inspector.cs new file mode 100644 index 00000000..585c4bde --- /dev/null +++ b/Assets/Airy UI/Editor/AnimatedElement_Inspector.cs @@ -0,0 +1,775 @@ +using UnityEngine; +using UnityEditor; + +namespace AiryUI +{ + [CustomEditor(typeof(AnimatedElement))] + [CanEditMultipleObjects] + public class AnimatedElement_Inspector : Editor + { + + + private AnimatedElement animatedElement; + + + //=================== + + + private SerializedProperty _isControlledByGroup; + private SerializedProperty _group; + + + //=================== + + + private SerializedProperty _showTimeMode; + private SerializedProperty _hideTimeMode; + + + //=================== + + + private SerializedProperty _disableShowAnimation; + private SerializedProperty _disableHideAnimation; + private SerializedProperty _containerCanvas; + private SerializedProperty _animateOnEnable; + private SerializedProperty _animationShowDuration; + + + //=================== + + + private SerializedProperty _addBounciness; + private SerializedProperty _bouncinessPower; + private SerializedProperty _bouncinessDuration; + + + //=================== + + + private SerializedProperty _animationHideDuration; + private SerializedProperty _rotateFrom; + private SerializedProperty _rotateTo; + private SerializedProperty _showAnimationType; + private SerializedProperty _hideAnimationType; + private SerializedProperty _fadeChildren; + private SerializedProperty _animationMoveFrom; + private SerializedProperty _animationMoveTo; + private SerializedProperty _delayEnabled; + private SerializedProperty _showDelay; + private SerializedProperty _hideDelay; + private SerializedProperty _onShowEvent; + private SerializedProperty _onHideEvent; + private SerializedProperty _onShowCompleteEvent; + private SerializedProperty _onHideCompleteEvent; + + + //=================== + + + private int currentTabIndex = 0; + + + //=================== + + + private bool basicFoldout_SHOW; + private bool animationFoldout_SHOW; + private bool delayFoldout_SHOW; + private bool bouncinessFoldout_SHOW; + private bool eventsFoldout_SHOW; + + + //=================== + + + private bool basicFoldout_HIDE; + private bool animationFoldout_HIDE; + private bool delayFoldout_HIDE; + private bool eventsFoldout_HIDE; + + + //=================== + + + private Color showPropsColor = new Color(0.52f, 1, 0.8f, 1); + private Color hidePropsColor = new Color(1, 0.66f, 0.66f, 1); + + + //=================== + + + private void OnEnable() + { + GetSavedInspectorValues(); + + animatedElement = (AnimatedElement)target; + + _isControlledByGroup = serializedObject.FindProperty("isControlledByGroup"); + _group = serializedObject.FindProperty("group"); + + _disableShowAnimation = serializedObject.FindProperty("disableShowAnimation"); + _disableHideAnimation = serializedObject.FindProperty("disableHideAnimation"); + + _containerCanvas = serializedObject.FindProperty("containerCanvas"); + + _showTimeMode = serializedObject.FindProperty("showTimeMode"); + _hideTimeMode = serializedObject.FindProperty("hideTimeMode"); + + _addBounciness = serializedObject.FindProperty("addBounciness"); + _bouncinessPower = serializedObject.FindProperty("bouncinessPower"); + _bouncinessDuration = serializedObject.FindProperty("bouncinessDuration"); + + _animateOnEnable = serializedObject.FindProperty("animateOnEnable"); + + _animationShowDuration = serializedObject.FindProperty("animationShowDuration"); + _animationHideDuration = serializedObject.FindProperty("animationHideDuration"); + + _rotateFrom = serializedObject.FindProperty("rotateFrom"); + _rotateTo = serializedObject.FindProperty("rotateTo"); + + _showAnimationType = serializedObject.FindProperty("showAnimationType"); + _hideAnimationType = serializedObject.FindProperty("hideAnimationType"); + + _fadeChildren = serializedObject.FindProperty("fadeChildren"); + + _animationMoveFrom = serializedObject.FindProperty("animationMoveFrom"); + _animationMoveTo = serializedObject.FindProperty("animationMoveTo"); + + _delayEnabled = serializedObject.FindProperty("delayEnabled"); + _showDelay = serializedObject.FindProperty("showDelay"); + _hideDelay = serializedObject.FindProperty("hideDelay"); + + _onShowEvent = serializedObject.FindProperty("OnShow"); + _onHideEvent = serializedObject.FindProperty("OnHide"); + _onShowCompleteEvent = serializedObject.FindProperty("OnShowComplete"); + _onHideCompleteEvent = serializedObject.FindProperty("OnHideComplete"); + } + + + public override void OnInspectorGUI() + { + if (animatedElement.GetComponent()) + { + EditorGUILayout.HelpBox("You can't add 'Animated Element' on a game object that has 'Animated Elements Group' !", MessageType.Error); + + animatedElement.enabled = false; + animatedElement.disableShowAnimation = true; + animatedElement.disableHideAnimation = true; + + // Don't draw anything. + return; + } + + + Undo.RecordObject(animatedElement, "animated element"); + GeneralSettings(); + + DrawLinkedGroup(); + + DrawTabs(); + + if (currentTabIndex == 0) + { + if (!animatedElement.disableShowAnimation) + { + GUI.color = showPropsColor; + basicFoldout_SHOW = EditorGUILayout.BeginFoldoutHeaderGroup(basicFoldout_SHOW, "Basic"); + if (basicFoldout_SHOW) + { + GUI.color = Color.white; + DrawAnimateOnEnable_TOGGLE(); + DrawAnimationShowTimeMode_DROPDOWN(); + } + + EditorGUILayout.EndFoldoutHeaderGroup(); + GUILayout.Space(20); + + //=================== + + GUI.color = showPropsColor; + animationFoldout_SHOW = EditorGUILayout.BeginFoldoutHeaderGroup(animationFoldout_SHOW, "Animation"); + if (animationFoldout_SHOW) + { + GUI.color = Color.white; + DrawShowAnimationType_GRID(); + DrawAnimationShowDuration_INPUT(); + DrawShowAnimationRotation_PROPERTIES(); + DrawFadeChildrenShow_TOGGLE(); + } + + EditorGUILayout.EndFoldoutHeaderGroup(); + GUILayout.Space(20); + + //=================== + + GUI.color = showPropsColor; + delayFoldout_SHOW = EditorGUILayout.BeginFoldoutHeaderGroup(delayFoldout_SHOW, "Delay"); + if (delayFoldout_SHOW) + { + GUI.color = Color.white; + DrawShowAnimationDelay_PROPERTIES(); + DrawChildrenShowDelays_BUTTONS(); + } + + EditorGUILayout.EndFoldoutHeaderGroup(); + GUILayout.Space(20); + + //=================== + + GUI.color = showPropsColor; + bouncinessFoldout_SHOW = EditorGUILayout.BeginFoldoutHeaderGroup(bouncinessFoldout_SHOW, "Bounciness"); + if (bouncinessFoldout_SHOW) + { + GUI.color = Color.white; + DrawAnimationShowBounciness(); + } + + EditorGUILayout.EndFoldoutHeaderGroup(); + GUILayout.Space(20); + + //=================== + + GUI.color = showPropsColor; + eventsFoldout_SHOW = EditorGUILayout.BeginFoldoutHeaderGroup(eventsFoldout_SHOW, "Events"); + if (eventsFoldout_SHOW) + { + GUI.color = Color.white; + DrawOnShow_EVENT(); + DrawOnShowComplete_EVENT(); + } + + EditorGUILayout.EndFoldoutHeaderGroup(); + GUILayout.Space(20); + + //=================== + } + else + { + GUI.color = Color.white; + DrawOnShowComplete_EVENT(); + } + + EditorGUILayout.EndFoldoutHeaderGroup(); + GUILayout.Space(20); + } + else if (currentTabIndex == 1) + { + if (!animatedElement.disableHideAnimation) + { + GUI.color = hidePropsColor; + basicFoldout_HIDE = EditorGUILayout.BeginFoldoutHeaderGroup(basicFoldout_HIDE, "Basic"); + if (basicFoldout_HIDE) + { + GUI.color = Color.white; + DrawAnimationHideTimeMode_DROPDOWN(); + } + + EditorGUILayout.EndFoldoutHeaderGroup(); + GUILayout.Space(20); + + //=================== + + GUI.color = hidePropsColor; + animationFoldout_HIDE = EditorGUILayout.BeginFoldoutHeaderGroup(animationFoldout_HIDE, "Animation"); + if (animationFoldout_HIDE) + { + GUI.color = Color.white; + DrawHideAnimationType_GRID(); + DrawAnimationHideDuration_INPUT(); + DrawHideAnimationRotaion_PROPERTIES(); + DrawFadeChildrenHide_TOGGLE(); + } + + EditorGUILayout.EndFoldoutHeaderGroup(); + GUILayout.Space(20); + + //=================== + + GUI.color = hidePropsColor; + delayFoldout_HIDE = EditorGUILayout.BeginFoldoutHeaderGroup(delayFoldout_HIDE, "Delay"); + if (delayFoldout_HIDE) + { + GUI.color = Color.white; + DrawHideAnimationDelay_PROPERTIES(); + DrawChildrenHideDelays_BUTTONS(); + } + + EditorGUILayout.EndFoldoutHeaderGroup(); + GUILayout.Space(20); + + //=================== + + GUI.color = hidePropsColor; + eventsFoldout_HIDE = EditorGUILayout.BeginFoldoutHeaderGroup(eventsFoldout_HIDE, "Events"); + if (eventsFoldout_HIDE) + { + GUI.color = Color.white; + DrawOnHide_EVENT(); + DrawOnHideComplete_EVENT(); + } + + EditorGUILayout.EndFoldoutHeaderGroup(); + GUILayout.Space(20); + + //=================== + } + else + { + GUI.color = Color.white; + DrawOnHideComplete_EVENT(); + } + } + + serializedObject.ApplyModifiedProperties(); + SaveInspectorValues(); + } + + + private void GeneralSettings() + { + //DrawInspectorTitle_LABEL ( "Animated UI Element" , true , false ); + + GUILayout.Space(10); + + GUI.color = showPropsColor; + EditorGUILayoutExtensions.ToggleLeft(_disableShowAnimation, new GUIContent("Disable Show Animation")); + + GUI.color = hidePropsColor; + EditorGUILayoutExtensions.ToggleLeft(_disableHideAnimation, new GUIContent("Disable Hide Animation")); + + GUILayout.Space(10); + + GUI.color = Color.white; + DrawContainerCanvas_FIELD(); + + GUILayout.Space(10); + } + + + private void DrawLinkedGroup() + { + EditorGUILayoutExtensions.ToggleLeft(_isControlledByGroup, new GUIContent("Is Controlled By Group?")); + if (animatedElement.isControlledByGroup) + { + EditorGUILayout.PropertyField(_group); + } + } + + + private void DrawTabs() + { + GUILayout.Space(20); + + currentTabIndex = GUILayout.Toolbar(currentTabIndex, new string[] { "Show Animation", "Hide Animation" }); + + GUILayout.Space(20); + } + + + private void DrawContainerCanvas_FIELD() + { + EditorGUILayout.BeginHorizontal(); + + EditorGUILayout.PropertyField(_containerCanvas, new GUIContent("Container Canvas")); + + if (GUILayout.Button("Auto Find")) + { + foreach (var go in Selection.gameObjects) + { + go.GetComponent().containerCanvas = go.GetComponentInParent(); + } + } + + EditorGUILayout.EndHorizontal(); + + if (animatedElement.containerCanvas == null) + { + EditorGUILayout.HelpBox("Please assign the container canvas in order to get the most accurate results and to avoid errors !", MessageType.Warning); + } + + GUILayout.Space(10); + } + + + private void DrawInspectorTitle_LABEL(string text, bool spaceBefore, bool spaceAfter) + { + if (spaceBefore) + GUILayout.Space(20); + + var titleLabelStyle = new GUIStyle(GUI.skin.label) { alignment = TextAnchor.UpperCenter, fontSize = 20, fontStyle = FontStyle.Bold, fixedHeight = 50 }; + + EditorGUILayout.LabelField(text, titleLabelStyle); + + if (spaceAfter) + GUILayout.Space(20); + } + + + private void DrawAnimationShowTimeMode_DROPDOWN() + { + EditorGUILayout.PropertyField(_showTimeMode, new GUIContent("Time Mode")); + + GUILayout.Space(10); + } + + + private void DrawAnimationHideTimeMode_DROPDOWN() + { + EditorGUILayout.PropertyField(_hideTimeMode, new GUIContent("Time Mode")); + + GUILayout.Space(10); + } + + + private void DrawAnimateOnEnable_TOGGLE() + { + EditorGUILayoutExtensions.ToggleLeft(_animateOnEnable, new GUIContent("Animate On Enable")); + + if (animatedElement.isControlledByGroup && animatedElement.group != null) + { + animatedElement.animateOnEnable = false; + EditorGUILayout.HelpBox("You can't enable 'Animate On Enable' because this Animated Element is controlled by an 'Animated Elements Group'", MessageType.None); + } + + GUILayout.Space(10); + } + + + private void DrawShowAnimationType_GRID() + { + EditorGUILayout.PropertyField(_showAnimationType, new GUIContent("Animation")); + + if (animatedElement.showAnimationType == AnimationType.FadeColor) + { + EditorGUILayout.HelpBox("Note: This GameObject must have a graphical component (Image, Text, or RawImage) in order to fade its color !", MessageType.Info); + + GUILayout.Space(10); + } + + if (animatedElement.showAnimationType == AnimationType.MoveWithScale || animatedElement.showAnimationType == AnimationType.Move) + { + GUILayout.Space(5); + EditorGUILayout.PropertyField(_animationMoveFrom, new GUIContent("Start From")); + + GUILayout.Space(5); + } + } + + + private void DrawHideAnimationType_GRID() + { + EditorGUILayout.PropertyField(_hideAnimationType, new GUIContent("Animation")); + + if (animatedElement.hideAnimationType == AnimationType.FadeColor) + { + EditorGUILayout.HelpBox("Note: This GameObject must have a graphical component (Image, Text, or RawImage) in order to fade its color !", MessageType.Info); + + GUILayout.Space(10); + } + + if (animatedElement.hideAnimationType == AnimationType.MoveWithScale || animatedElement.hideAnimationType == AnimationType.Move) + { + GUILayout.Space(5); + EditorGUILayout.PropertyField(_animationMoveTo, new GUIContent("End To")); + + GUILayout.Space(5); + } + } + + + private void DrawFadeChildrenShow_TOGGLE() + { + if (animatedElement.showAnimationType == AnimationType.FadeColor) + // animatedElement.fadeChildren = EditorGUILayout.ToggleLeft("Fade Children Simultaneously", animatedElement.fadeChildren); + EditorGUILayoutExtensions.ToggleLeft(_fadeChildren, new GUIContent("Fade Children Simultaneously")); + } + + + private void DrawFadeChildrenHide_TOGGLE() + { + if (animatedElement.hideAnimationType == AnimationType.FadeColor) + // animatedElement.fadeChildren = EditorGUILayout.ToggleLeft("Fade Children Simultaneously", animatedElement.fadeChildren); + EditorGUILayoutExtensions.ToggleLeft(_fadeChildren, new GUIContent("Fade Children Simultaneously")); + } + + + private void DrawAnimationShowDuration_INPUT() + { + EditorGUILayout.Space(); + + EditorGUILayout.PropertyField(_animationShowDuration, new GUIContent("Show Duration")); + + EditorGUILayout.Space(); EditorGUILayout.Space(); + } + + + private void DrawAnimationShowBounciness() + { + + if (animatedElement.showAnimationType == AnimationType.FadeColor) + { + EditorGUILayout.HelpBox("No Bounciness in color fading!", MessageType.None); + return; + } + + // EditorGUILayout.PropertyField(_addBounciness, new GUIContent("Add Bounciness")); + // animatedElement.addBounciness = EditorGUILayout.ToggleLeft("Add Bounciness", animatedElement.addBounciness,); + EditorGUILayoutExtensions.ToggleLeft(_addBounciness, new GUIContent("Add Bounciness")); + + if (animatedElement.addBounciness) + { + EditorGUILayout.PropertyField(_bouncinessPower, new GUIContent("Bounciness Power")); + EditorGUILayout.PropertyField(_bouncinessDuration, new GUIContent("Bounciness Duration")); + + if (animatedElement.showAnimationType == AnimationType.FadeColor) + EditorGUILayout.HelpBox("Bounciness will not affect animation when type is fading color", MessageType.Warning); + } + + GUILayout.Space(20); + + } + + + private void DrawAnimationHideDuration_INPUT() + { + GUILayout.Space(10); + + EditorGUILayout.PropertyField(_animationHideDuration, new GUIContent("Hide Duration")); + + GUILayout.Space(10); + } + + + private void DrawShowAnimationDelay_PROPERTIES() + { + EditorGUILayoutExtensions.ToggleLeft(_delayEnabled, new GUIContent("Enable Delay")); + + if (animatedElement.delayEnabled) + { + EditorGUILayout.PropertyField(_showDelay, new GUIContent("Delay")); + } + + EditorGUILayout.Space(); EditorGUILayout.Space(); + } + + + private void DrawShowAnimationRotation_PROPERTIES() + { + if (animatedElement.showAnimationType == AnimationType.Rotate) + { + // rotation from angle + EditorGUILayout.PropertyField(_rotateFrom, new GUIContent("Rotate From"), true); + GUILayout.Space(20); + } + } + + + private void DrawHideAnimationRotaion_PROPERTIES() + { + if (animatedElement.hideAnimationType == AnimationType.Rotate) + { + EditorGUILayout.PropertyField(_rotateTo, new GUIContent("Rotate To"), true); + GUILayout.Space(10); + + #region Future Update + + + //var titleLabelStyle = new GUIStyle ( GUI.skin.label ) { alignment = TextAnchor.MiddleCenter , fontSize = 13 , fontStyle = FontStyle.Normal }; + + //EditorGUILayout.LabelField ( "Rotation Pivot" , titleLabelStyle ); + + //rotationPivotGridIndex = GUILayout.SelectionGrid ( rotationPivotGridIndex , new string [] { "↖" , "▲" , "↗" , "◄" , "●" , "►" , "↙" , "▼" , "↘" } , 3 ); + + //AnimatedElement.pivotWhileRotating = ( AnimationStartPosition ) rotationPivotGridIndex; + + + #endregion + + GUILayout.Space(10); + } + } + + + private void DrawHideAnimationDelay_PROPERTIES() + { + EditorGUILayoutExtensions.ToggleLeft(_delayEnabled, new GUIContent("Enable Delay")); + + if (animatedElement.delayEnabled) + { + EditorGUILayout.PropertyField(_hideDelay, new GUIContent("Delay")); + } + + EditorGUILayout.Space(); EditorGUILayout.Space(); + } + + + private void DrawOnShow_EVENT() + { + EditorGUILayout.PropertyField(_onShowEvent, new GUIContent("On Animation Start")); + EditorGUILayout.Space(); EditorGUILayout.Space(); + } + + + private void DrawOnShowComplete_EVENT() + { + EditorGUILayout.PropertyField(_onShowCompleteEvent, new GUIContent("On Animation Complete")); + EditorGUILayout.Space(); EditorGUILayout.Space(); + } + + + private void DrawOnHide_EVENT() + { + EditorGUILayout.PropertyField(_onHideEvent, new GUIContent("On Animation Start")); + } + + + private void DrawOnHideComplete_EVENT() + { + EditorGUILayout.PropertyField(_onHideCompleteEvent, new GUIContent("On Animation Complete")); + } + + + private void DrawChildrenShowDelays_BUTTONS() + { + GUILayout.Space(20); + + EditorGUILayout.BeginHorizontal(); + + float addedTime = animatedElement.animationShowDuration; + addedTime += (animatedElement.delayEnabled) ? animatedElement.showDelay : 0; + + if (GUILayout.Button("\nShow Delays In Children")) + { + AnimatedElement[] elementsInChildren = Selection.activeGameObject.GetComponentsInChildren(); + + float step = (animatedElement.animationShowDuration / elementsInChildren.Length); + float currentValue = 0; + + for (int i = 1; i < elementsInChildren.Length; i++) + { + if (elementsInChildren[i].delayEnabled) + elementsInChildren[i].showDelay = addedTime + currentValue; + + currentValue += step; + } + Debug.Log("[Airy UI]" + + "" + + " anchors set for " + + Selection.gameObjects.Length + + " game object/s"); + Debug.Log("[Airy UI] children hide delays set for " + elementsInChildren.Length + " game objects"); + } + + //============================================== + + if (GUILayout.Button("\nShow Delays In Children")) + { + AnimatedElement[] elementsInChildren = Selection.activeGameObject.GetComponentsInChildren(); + + for (int i = 1; i < elementsInChildren.Length; i++) + { + if (elementsInChildren[i].delayEnabled) + { + elementsInChildren[i].showDelay = addedTime + UnityEngine.Random.Range(animatedElement.animationShowDuration / elementsInChildren.Length, animatedElement.animationShowDuration); + } + } + + Debug.Log("[Airy UI] children hide delays randomized for " + elementsInChildren.Length + " game objects"); + } + + EditorGUILayout.EndHorizontal(); + GUILayout.Space(20); + } + + + private void DrawChildrenHideDelays_BUTTONS() + { + EditorGUILayout.BeginHorizontal(); + + float addedTime = animatedElement.animationHideDuration; + addedTime += (animatedElement.delayEnabled) ? animatedElement.hideDelay : 0; + + if (GUILayout.Button("\nHide Delays In Children")) + { + AnimatedElement[] elementsInChildren = Selection.activeGameObject.GetComponentsInChildren(); + + float step = (animatedElement.animationHideDuration / elementsInChildren.Length); + float currentValue = 0; + + elementsInChildren[elementsInChildren.Length - 1].hideDelay = 0; + for (int i = elementsInChildren.Length - 2; i >= 1; i--) + { + if (elementsInChildren[i].delayEnabled) + elementsInChildren[i].hideDelay = step + currentValue; + + currentValue += step; + } + + Debug.Log("[Airy UI] children hide delays set for" + elementsInChildren.Length + " game objects"); + } + + //============================================== + + if (GUILayout.Button("\nHide Delays In Children")) + { + AnimatedElement[] elementsInChildren = Selection.activeGameObject.GetComponentsInChildren(); + + addedTime = animatedElement.hideDelay; + + for (int i = 1; i < elementsInChildren.Length; i++) + { + if (elementsInChildren[i].delayEnabled) + { + elementsInChildren[i].hideDelay = addedTime - UnityEngine.Random.Range(animatedElement.animationHideDuration / elementsInChildren.Length, animatedElement.animationHideDuration); + } + } + + Debug.Log("[Airy UI] children hide delays randomized for " + elementsInChildren.Length + " game objects"); + } + + EditorGUILayout.EndHorizontal(); + GUILayout.Space(20); + } + + + //=========================================================================================================== + + + private void SaveInspectorValues() + { + foreach (var id in Selection.instanceIDs) + { + EditorPrefs.SetInt("airyui/" + nameof(currentTabIndex), currentTabIndex); + + EditorPrefs.SetBool("airyui/" + nameof(basicFoldout_SHOW), basicFoldout_SHOW); + EditorPrefs.SetBool("airyui/" + nameof(animationFoldout_SHOW), animationFoldout_SHOW); + EditorPrefs.SetBool("airyui/" + nameof(delayFoldout_SHOW), delayFoldout_SHOW); + EditorPrefs.SetBool("airyui/" + nameof(bouncinessFoldout_SHOW), bouncinessFoldout_SHOW); + EditorPrefs.SetBool("airyui/" + nameof(eventsFoldout_SHOW), eventsFoldout_SHOW); + + EditorPrefs.SetBool("airyui/" + nameof(basicFoldout_HIDE), basicFoldout_HIDE); + EditorPrefs.SetBool("airyui/" + nameof(animationFoldout_HIDE), animationFoldout_HIDE); + EditorPrefs.SetBool("airyui/" + nameof(delayFoldout_HIDE), delayFoldout_HIDE); + EditorPrefs.SetBool("airyui/" + nameof(eventsFoldout_HIDE), eventsFoldout_HIDE); + } + } + + + private void GetSavedInspectorValues() + { + currentTabIndex = EditorPrefs.GetInt("airyui/" + nameof(currentTabIndex), 0); + + basicFoldout_SHOW = EditorPrefs.GetBool("airyui/" + nameof(basicFoldout_SHOW)); + animationFoldout_SHOW = EditorPrefs.GetBool("airyui/" + nameof(animationFoldout_SHOW)); + delayFoldout_SHOW = EditorPrefs.GetBool("airyui/" + nameof(delayFoldout_SHOW)); + bouncinessFoldout_SHOW = EditorPrefs.GetBool("airyui/" + nameof(bouncinessFoldout_SHOW)); + eventsFoldout_SHOW = EditorPrefs.GetBool("airyui/" + nameof(eventsFoldout_SHOW)); + + basicFoldout_HIDE = EditorPrefs.GetBool("airyui/" + nameof(basicFoldout_HIDE)); + animationFoldout_HIDE = EditorPrefs.GetBool("airyui/" + nameof(animationFoldout_HIDE)); + delayFoldout_HIDE = EditorPrefs.GetBool("airyui/" + nameof(delayFoldout_HIDE)); + eventsFoldout_HIDE = EditorPrefs.GetBool("airyui/" + nameof(eventsFoldout_HIDE)); + } + } +} \ No newline at end of file diff --git a/Assets/Airy UI/Editor/AnimatedElement_Inspector.cs.meta b/Assets/Airy UI/Editor/AnimatedElement_Inspector.cs.meta new file mode 100644 index 00000000..1eef9e6a --- /dev/null +++ b/Assets/Airy UI/Editor/AnimatedElement_Inspector.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 872041dd0a8729c4193982932cb5d8bd +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 4350cb3056a566c48ac0f3588c16a85d, 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/Editor/AnimatedElement_Inspector.cs + uploadId: 760159 diff --git a/Assets/Airy UI/Editor/AnimatedElementsGroup_Inspector.cs b/Assets/Airy UI/Editor/AnimatedElementsGroup_Inspector.cs new file mode 100644 index 00000000..eaf0e3a0 --- /dev/null +++ b/Assets/Airy UI/Editor/AnimatedElementsGroup_Inspector.cs @@ -0,0 +1,73 @@ +using UnityEngine; +using UnityEditor; + +namespace AiryUI +{ + [CustomEditor ( typeof ( AnimatedElementsGroup ) )] + [CanEditMultipleObjects] + public class AnimatedElementsGroup_Inspector : Editor + { + private AnimatedElementsGroup animatedGroup; + + + private SerializedProperty _showAnimaitonOnEnable; + private SerializedProperty animatedElements; + + + private SerializedProperty _onShowEvent; + private SerializedProperty _onHideEvent; + + + private void OnEnable () + { + animatedGroup = ( AnimatedElementsGroup ) target; + + _showAnimaitonOnEnable = serializedObject.FindProperty ( "showAnimaitonOnEnable" ); + animatedElements = serializedObject.FindProperty ( "animatedElements" ); + + _onShowEvent = serializedObject.FindProperty ( "OnShow" ); + _onHideEvent = serializedObject.FindProperty ( "OnHide" ); + } + + + public override void OnInspectorGUI () + { + Undo.RecordObject ( animatedGroup , "animated group" ); + + GUILayout.Space ( 20 ); + + EditorGUILayout.PropertyField ( _showAnimaitonOnEnable , new GUIContent ( "Animate On Enable" ) ); + + if ( animatedGroup.showAnimaitonOnEnable ) + { + EditorGUILayout.HelpBox ( "TRUE: All Animated Elements in this Group will animate automatically when this GameObject is enabled.\n\nFALSE: You control the animation by calling ShowGroup() in this script." , MessageType.None ); + } + + GUILayout.Space ( 10 ); + + EditorGUILayout.PropertyField ( animatedElements , new GUIContent ( "Animated Elements" ) ); + + GUILayout.Space ( 20 ); + + DrawOnShow_EVENT (); + DrawOnHide_EVENT (); + + GUILayout.Space ( 20 ); + + serializedObject.ApplyModifiedProperties (); + } + + + private void DrawOnShow_EVENT () + { + EditorGUILayout.PropertyField ( _onShowEvent , new GUIContent ( "On Show" ) ); + EditorGUILayout.Space (); EditorGUILayout.Space (); + } + + + private void DrawOnHide_EVENT () + { + EditorGUILayout.PropertyField ( _onHideEvent , new GUIContent ( "On Hide" ) ); + } + } +} \ No newline at end of file diff --git a/Assets/Airy UI/Editor/AnimatedElementsGroup_Inspector.cs.meta b/Assets/Airy UI/Editor/AnimatedElementsGroup_Inspector.cs.meta new file mode 100644 index 00000000..b7f7784d --- /dev/null +++ b/Assets/Airy UI/Editor/AnimatedElementsGroup_Inspector.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 2057bd040dbb83a45b41376ca5336bd5 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: c6d7f5a7c4a1c364c81769ff255bc0d9, 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/Editor/AnimatedElementsGroup_Inspector.cs + uploadId: 760159 diff --git a/Assets/Airy UI/Editor/CloseButtonController_Inspector.cs b/Assets/Airy UI/Editor/CloseButtonController_Inspector.cs new file mode 100644 index 00000000..44814e07 --- /dev/null +++ b/Assets/Airy UI/Editor/CloseButtonController_Inspector.cs @@ -0,0 +1,45 @@ +using UnityEditor; +using UnityEngine; + + +namespace AiryUI +{ + + + [CustomEditor ( typeof ( EscButtonController ) )] + [CanEditMultipleObjects] + public class CloseButtonController_Inspector : Editor + { + + private EscButtonController esc_manager; + + + private SerializedProperty _esc_buttons; + + + private void OnEnable () + { + esc_manager = ( EscButtonController ) target; + + _esc_buttons = serializedObject.FindProperty ( "esc_buttons" ); + } + + + public override void OnInspectorGUI () + { + EditorGUILayout.Space ( 10 ); + + EditorGUILayout.HelpBox ( "This game object is automatically added When you add EscBackButton please don't remove it" , MessageType.Info ); + + EditorGUILayout.Space ( 10 ); + + EditorGUILayout.PropertyField ( _esc_buttons ); + + serializedObject.ApplyModifiedProperties (); + } + + + } + + +} \ No newline at end of file diff --git a/Assets/Airy UI/Editor/CloseButtonController_Inspector.cs.meta b/Assets/Airy UI/Editor/CloseButtonController_Inspector.cs.meta new file mode 100644 index 00000000..d24dea89 --- /dev/null +++ b/Assets/Airy UI/Editor/CloseButtonController_Inspector.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 7a732036fa711b849967a979ac4753b2 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 7f02f0462f80e0340b3014e7a07c5ac2, 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/Editor/CloseButtonController_Inspector.cs + uploadId: 760159 diff --git a/Assets/Airy UI/Editor/CloseButton_Inspector.cs b/Assets/Airy UI/Editor/CloseButton_Inspector.cs new file mode 100644 index 00000000..b5c0dee4 --- /dev/null +++ b/Assets/Airy UI/Editor/CloseButton_Inspector.cs @@ -0,0 +1,83 @@ +using UnityEditor; +using UnityEngine; + + +namespace AiryUI +{ + + + [CustomEditor ( typeof ( CloseButton ) , true )] + [CanEditMultipleObjects] + public class CloseButton_Inspector : Editor + { + + + private CloseButton close_button; + + + private SerializedProperty _backButtonAffects; + private SerializedProperty _animatedElement; + private SerializedProperty _animatedElementsGroup; + + private SerializedProperty _buttonComponent; + + + private void OnEnable () + { + close_button = ( CloseButton ) target; + + _backButtonAffects = serializedObject.FindProperty ( "backButtonAffects" ); + _animatedElement = serializedObject.FindProperty ( "affectedAnimatedElement" ); + _animatedElementsGroup = serializedObject.FindProperty ( "affectedAnimatedElementsGroup" ); + + if ( close_button is UICloseButton ) + { + _buttonComponent = serializedObject.FindProperty ( "buttonComponent" ); + } + } + + + public override void OnInspectorGUI () + { + EditorGUILayout.Space ( 10 ); + + EditorGUILayout.PropertyField ( _backButtonAffects ); + + EditorGUILayout.Space ( 10 ); + + if ( close_button.backButtonAffects == BackButtonAffects.AnimatedElement ) + { + EditorGUILayout.PropertyField ( _animatedElement ); + } + else if ( close_button.backButtonAffects == BackButtonAffects.AnimatedElementsGroup ) + { + EditorGUILayout.PropertyField ( _animatedElementsGroup ); + } + + EditorGUILayout.Space ( 10 ); + + if ( close_button is UICloseButton ) + { + EditorGUILayout.PropertyField ( _buttonComponent ); + } + + serializedObject.ApplyModifiedProperties (); + } + + + private void InspectorTitle_LABEL ( string text , bool spaceBefore , bool spaceAfter ) + { + if ( spaceBefore ) + GUILayout.Space ( 20 ); + + var titleLabelStyle = new GUIStyle ( GUI.skin.label ) { alignment = TextAnchor.UpperCenter , fontSize = 20 , fontStyle = FontStyle.Bold , fixedHeight = 50 }; + + EditorGUILayout.LabelField ( text , titleLabelStyle ); + + if ( spaceAfter ) + GUILayout.Space ( 20 ); + } + } + + +} \ No newline at end of file diff --git a/Assets/Airy UI/Editor/CloseButton_Inspector.cs.meta b/Assets/Airy UI/Editor/CloseButton_Inspector.cs.meta new file mode 100644 index 00000000..6d05cf33 --- /dev/null +++ b/Assets/Airy UI/Editor/CloseButton_Inspector.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 19d50b70d8e402447a73338bd8aecf26 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 7f02f0462f80e0340b3014e7a07c5ac2, 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/Editor/CloseButton_Inspector.cs + uploadId: 760159 diff --git a/Assets/Airy UI/Editor/CustomAnimatedElement_Inspector.cs b/Assets/Airy UI/Editor/CustomAnimatedElement_Inspector.cs new file mode 100644 index 00000000..7d810860 --- /dev/null +++ b/Assets/Airy UI/Editor/CustomAnimatedElement_Inspector.cs @@ -0,0 +1,630 @@ +using UnityEngine; +using UnityEditor; + + +namespace AiryUI +{ + [CustomEditor(typeof(CustomAnimatedElement))] + [CanEditMultipleObjects] + public class CustomAnimatedElement_Inspector : Editor + { + private CustomAnimatedElement animatedElement; + + private SerializedProperty _isControlledByGroup; + + private SerializedProperty _animateOnEnable; + + //=================== + + + private SerializedProperty _showTimeMode; + private SerializedProperty _hideTimeMode; + + + //=================== + + + private SerializedProperty _group; + + + //=================== + + + private SerializedProperty _containerCanvas; + + + //=================== + + + private SerializedProperty _componentsToAnimate_SHOW; + private SerializedProperty _transformAnimationRecords_SHOW; + private SerializedProperty _graphicAnimationRecords_SHOW; + private SerializedProperty _transformAndGraphicAnimationRecords_SHOW; + + + //=================== + + + private SerializedProperty _componentsToAnimate_HIDE; + private SerializedProperty _transformAnimationRecords_HIDE; + private SerializedProperty _graphicAnimationRecords_HIDE; + private SerializedProperty _transformAndGraphicAnimationRecords_HIDE; + + + //=================== + + + private SerializedProperty _currentRecordDuration; + private SerializedProperty _currentRecordDelay; + + + //=================== + + + private SerializedProperty _showDelay; + private SerializedProperty _hideDelay; + + + //=================== + + + private SerializedProperty _onShowEvent; + private SerializedProperty _onHideEvent; + private SerializedProperty _onShowCompleteEvent; + private SerializedProperty _onHideCompleteEvent; + + + //=================== + + + private string[] tabsTexts = { "Show", "Hide" }; + private int currentTabIndex = 0; + + public float currentRecordDuration = 0.5f; + public float currentRecordStartsAt = 0; + + private bool recordModeActive; + + + //=================== + + + private Color showPropsColor = new Color(0.52f, 1, 0.8f, 1); + private Color hidePropsColor = new Color(1, 0.66f, 0.66f, 1); + + + //=================== + + + private void OnEnable() + { + GetSavedInspectorValues(); + + animatedElement = (CustomAnimatedElement)target; + + _isControlledByGroup = serializedObject.FindProperty("isControlledByGroup"); + _group = serializedObject.FindProperty("group"); + + _animateOnEnable = serializedObject.FindProperty("animateOnEnable"); + + _containerCanvas = serializedObject.FindProperty("containerCanvas"); + + _showTimeMode = serializedObject.FindProperty("showTimeMode"); + _hideTimeMode = serializedObject.FindProperty("hideTimeMode"); + + _componentsToAnimate_SHOW = serializedObject.FindProperty("componentsToAnimate_SHOW"); + _transformAnimationRecords_SHOW = serializedObject.FindProperty("TransformAnimationRecords_SHOW"); + _graphicAnimationRecords_SHOW = serializedObject.FindProperty("GraphicAnimationRecords_SHOW"); + _transformAndGraphicAnimationRecords_SHOW = serializedObject.FindProperty("TransformAndGraphicAnimationRecords_SHOW"); + + _componentsToAnimate_HIDE = serializedObject.FindProperty("componentsToAnimate_HIDE"); + _transformAnimationRecords_HIDE = serializedObject.FindProperty("TransformAnimationRecords_HIDE"); + _graphicAnimationRecords_HIDE = serializedObject.FindProperty("GraphicAnimationRecords_HIDE"); + _transformAndGraphicAnimationRecords_HIDE = serializedObject.FindProperty("TransformAndGraphicAnimationRecords_HIDE"); + + _currentRecordDuration = serializedObject.FindProperty("currentRecordDuration"); + _currentRecordDelay = serializedObject.FindProperty("currentRecordDelay"); + + _showDelay = serializedObject.FindProperty("showDelay"); + _hideDelay = serializedObject.FindProperty("hideDelay"); + + _onShowEvent = serializedObject.FindProperty("OnShow"); + _onHideEvent = serializedObject.FindProperty("OnHide"); + _onShowCompleteEvent = serializedObject.FindProperty("OnShowComplete"); + _onHideCompleteEvent = serializedObject.FindProperty("OnHideComplete"); + } + + public override void OnInspectorGUI() + { + if (animatedElement.GetComponent()) + { + EditorGUILayout.HelpBox("You can't add 'Custom Animated Element' on a game object that has 'Animated Elements Group' !", MessageType.Error); + + animatedElement.enabled = false; + animatedElement.disableShowAnimation = true; + animatedElement.disableHideAnimation = true; + + + // Don't draw anything. + return; + } + + Undo.RecordObject(animatedElement, "custom animated element"); + + GeneralSettings(); + + DrawLinkedGroup(); + + DrawAnimateOnEnable_TOGGLE(); + + Tabs(); + + if (currentTabIndex == 0) + { + EditorGUILayout.BeginVertical(SetContainerBoxStyle(new Color(0.52f, 1, 0.8f, 0.1f))); + + if (!animatedElement.disableShowAnimation) + { + + Loop_TOGGLE(); + ComponentsToAnimateShow_DROPDOWN(); + AnimationShowTimeMode_DROPDOWN(); + RecordMode_BUTTONS(); + ShowAnimationDelay_PROPS(); + Duration_PROPS(); + TransformAnimationRecordsShow_LIST(); + GraphicAnimationRecordsShow_LIST(); + TransformAndGraphicAnimationRecordsShow_LIST(); + OnShow_EVENT(); + OnShowComplete_EVENT(); + } + else + { + OnShowComplete_EVENT(); + } + + GUILayout.EndVertical(); + } + else if (currentTabIndex == 1) + { + EditorGUILayout.BeginVertical(SetContainerBoxStyle(new Color(1, 0.66f, 0.66f, 0.1f))); + + + if (!animatedElement.disableHideAnimation) + { + ComponentsToAnimateHide_DROPDOWN(); + AnimationHideTimeMode_DROPDOWN(); + RecordMode_BUTTONS(); + HideAnimationDelay_PROPS(); + Duration_PROPS(); + TransformAnimationRecordsHide_LIST(); + GraphicAnimationRecordsHide_LIST(); + TransformAndGraphicAnimationRecordsHide_LIST(); + OnHide_EVENT(); + OnHideComplete_EVENT(); + } + else + { + OnHideComplete_EVENT(); + } + + + GUILayout.EndVertical(); + } + + + serializedObject.ApplyModifiedProperties(); + SaveInspectorValues(); + } + + private void GeneralSettings() + { + //Title_LABEL (); + + GUILayout.Space(10); + + GUI.color = showPropsColor; + animatedElement.disableShowAnimation = EditorGUILayout.ToggleLeft("Disable Show Animation", animatedElement.disableShowAnimation); + + GUI.color = hidePropsColor; + animatedElement.disableHideAnimation = EditorGUILayout.ToggleLeft("Disable Hide Animation", animatedElement.disableHideAnimation); + + GUILayout.Space(10); + + GUI.color = Color.white; + ContainerCanvas(); + + GUILayout.Space(10); + } + + + private void DrawLinkedGroup() + { + animatedElement.isControlledByGroup = EditorGUILayout.ToggleLeft("Is Controlled By Group?", animatedElement.isControlledByGroup); + if (animatedElement.isControlledByGroup) + { + EditorGUILayout.PropertyField(_group); + } + + EditorGUILayout.Space(10); + } + + + private void DrawAnimateOnEnable_TOGGLE() + { + EditorGUILayoutExtensions.ToggleLeft(_animateOnEnable, new GUIContent("Animate On Enable")); + + if (animatedElement.isControlledByGroup && animatedElement.group != null) + { + animatedElement.animateOnEnable = false; + EditorGUILayout.HelpBox("You can't enable 'Animate On Enable' because this Animated Element is controlled by an 'Animated Elements Group'", MessageType.None); + } + + GUILayout.Space(10); + } + + + private void Tabs() + { + GUILayout.Space(20); + + currentTabIndex = GUILayout.Toolbar(currentTabIndex, new string[] { "Show Animation", "Hide Animation" }); + + GUILayout.Space(10); + } + + + private void ContainerCanvas() + { + EditorGUILayout.BeginHorizontal(); + + EditorGUILayout.PropertyField(_containerCanvas, new GUIContent("Container Canvas")); + + if (GUILayout.Button("Auto Find")) + { + foreach (var go in Selection.gameObjects) + { + go.GetComponent().containerCanvas = go.GetComponentInParent(); + } + } + + EditorGUILayout.EndHorizontal(); + + GUILayout.Space(10); + } + + + private GUIStyle SetContainerBoxStyle(Color color) + { + GUIStyle boxStyle = new GUIStyle("box"); + boxStyle.padding = new RectOffset(20, 20, 20, 20); + boxStyle.margin = new RectOffset(5, 5, 5, 5); + + var texture = new Texture2D(1, 1); + texture.SetPixel(0, 0, color); + texture.Apply(); + + boxStyle.normal.background = texture; + + + return boxStyle; + } + + + private void AnimationShowTimeMode_DROPDOWN() + { + EditorGUILayout.PropertyField(_showTimeMode, new GUIContent("Time Mode")); + + GUILayout.Space(10); + } + + private void AnimationHideTimeMode_DROPDOWN() + { + EditorGUILayout.PropertyField(_hideTimeMode, new GUIContent("Time Mode")); + + GUILayout.Space(10); + } + + + private void Loop_TOGGLE() + { + animatedElement.loop = EditorGUILayout.ToggleLeft("Loop", animatedElement.loop); + + GUILayout.Space(10); + } + + private void Title_LABEL() + { + GUILayout.Space(20); + var titleLabelStyle = new GUIStyle(GUI.skin.label) { alignment = TextAnchor.UpperCenter, fontSize = 20, fontStyle = FontStyle.Bold, fixedHeight = 50 }; + + EditorGUILayout.LabelField("Custom Animated Element", titleLabelStyle); + + GUILayout.Space(30); + } + + private void ComponentsToAnimateShow_DROPDOWN() + { + EditorGUILayout.PropertyField(_componentsToAnimate_SHOW, new GUIContent("What to animate"), true); + + GUI.color = Color.white; + + GUILayout.Space(20); + } + + private void ComponentsToAnimateHide_DROPDOWN() + { + //GUI.color = Color.cyan; + EditorGUILayout.PropertyField(_componentsToAnimate_HIDE, new GUIContent("What to animate"), true); + GUI.color = Color.white; + GUILayout.Space(20); + } + + private void Duration_PROPS() + { + EditorGUILayout.BeginVertical(); + + GUI.color = Color.yellow; + + EditorGUILayout.PropertyField(_currentRecordDuration); + + GUI.color = Color.green; + + EditorGUILayout.PropertyField(_currentRecordDelay); + + GUI.color = Color.white; + GUILayout.Space(20); + + EditorGUILayout.EndVertical(); + } + + private void TransformAnimationRecordsShow_LIST() + { + EditorGUILayout.BeginVertical(); + + if (animatedElement.componentsToAnimate_SHOW == CustomAnimatedElement.ComponentsToAnimate.Transform) + { + EditorGUILayout.PropertyField(_transformAnimationRecords_SHOW, new GUIContent("Animation Records")); + GUILayout.Space(20); + } + + EditorGUILayout.EndVertical(); + } + + private void TransformAnimationRecordsHide_LIST() + { + EditorGUILayout.BeginVertical(); + + if (animatedElement.componentsToAnimate_HIDE == CustomAnimatedElement.ComponentsToAnimate.Transform) + { + EditorGUILayout.PropertyField(_transformAnimationRecords_HIDE, new GUIContent("Animation Records"), true); + GUILayout.Space(20); + } + + EditorGUILayout.EndVertical(); + } + + private void GraphicAnimationRecordsShow_LIST() + { + EditorGUILayout.BeginVertical(); + + if (animatedElement.componentsToAnimate_SHOW == CustomAnimatedElement.ComponentsToAnimate.Graphic) + { + EditorGUILayout.PropertyField(_graphicAnimationRecords_SHOW, new GUIContent("Animation Records"), true); + GUILayout.Space(20); + } + + EditorGUILayout.EndVertical(); + } + + private void GraphicAnimationRecordsHide_LIST() + { + EditorGUILayout.BeginVertical(); + + if (animatedElement.componentsToAnimate_HIDE == CustomAnimatedElement.ComponentsToAnimate.Graphic) + { + EditorGUILayout.PropertyField(_graphicAnimationRecords_HIDE, new GUIContent("Animation Records"), true); + GUILayout.Space(20); + } + + EditorGUILayout.EndVertical(); + } + + private void TransformAndGraphicAnimationRecordsShow_LIST() + { + EditorGUILayout.BeginVertical(); + + if (animatedElement.componentsToAnimate_SHOW == CustomAnimatedElement.ComponentsToAnimate.Both) + { + EditorGUILayout.PropertyField(_transformAndGraphicAnimationRecords_SHOW, new GUIContent("Animation Records"), true); + GUILayout.Space(20); + } + + EditorGUILayout.EndVertical(); + } + + private void TransformAndGraphicAnimationRecordsHide_LIST() + { + EditorGUILayout.BeginVertical(); + + if (animatedElement.componentsToAnimate_HIDE == CustomAnimatedElement.ComponentsToAnimate.Both) + { + EditorGUILayout.PropertyField(_transformAndGraphicAnimationRecords_HIDE, new GUIContent("Animation Records"), true); + GUILayout.Space(20); + } + + EditorGUILayout.EndVertical(); + } + + private void RecordMode_BUTTONS() + { + EditorGUILayout.BeginHorizontal(); + + EditorGUI.BeginDisabledGroup(recordModeActive); + + GUI.color = new Color(1, 0.45f, 0, 1); + if (GUILayout.Button("●\nRECORD", new GUIStyle(GUI.skin.button) { fontSize = 12, fontStyle = FontStyle.Bold, fixedWidth = 100, richText = true })) + { + foreach (var g in Selection.gameObjects) + { + CustomAnimatedElement aniamtedElement = g.GetComponent(); + if (aniamtedElement) + { + aniamtedElement.EnterRecordMode(g, (CustomAnimatedElement.AnimationShowOrHide)currentTabIndex); + } + } + + recordModeActive = true; + } + + EditorGUI.EndDisabledGroup(); + + EditorGUILayout.Space(5); + + EditorGUI.BeginDisabledGroup(!recordModeActive); + + GUI.color = Color.yellow; + if (GUILayout.Button("■\nSTOP ", new GUIStyle(GUI.skin.button) { fontSize = 12, fontStyle = FontStyle.Bold, fixedWidth = 100, richText = true })) + { + foreach (var g in Selection.gameObjects) + { + CustomAnimatedElement aniamtedElement = g.GetComponent(); + if (aniamtedElement) + { + aniamtedElement.ExitRecordMode(g, (CustomAnimatedElement.AnimationShowOrHide)currentTabIndex); + } + } + + recordModeActive = false; + GUI.color = Color.white; + } + + + EditorGUI.EndDisabledGroup(); + + EditorGUILayout.EndHorizontal(); + + EditorGUILayout.Space(5); + + EditorGUILayout.BeginHorizontal(); + + EditorGUI.BeginDisabledGroup(!recordModeActive); + + + GUI.color = new Color(0.66f, 0, 1, 1); + + if (GUILayout.Button("⌦\nKEYFRAME", new GUIStyle(GUI.skin.button) { fontSize = 12, fontStyle = FontStyle.Bold, richText = true })) + { + if (currentTabIndex == 0) + { + foreach (var g in Selection.gameObjects) + { + CustomAnimatedElement aniamtedElement = g.GetComponent(); + if (aniamtedElement) + { + aniamtedElement.Record(g, CustomAnimatedElement.AnimationShowOrHide.Show); + } + } + } + else if (currentTabIndex == 1) + { + foreach (var g in Selection.gameObjects) + { + CustomAnimatedElement aniamtedElement = g.GetComponent(); + if (aniamtedElement) + { + aniamtedElement.Record(g, CustomAnimatedElement.AnimationShowOrHide.Hide); + } + } + } + } + + + EditorGUI.EndDisabledGroup(); + + //GUILayout.FlexibleSpace(); + EditorGUILayout.EndHorizontal(); + + GUILayout.Space(20); + } + + private void ShowAnimationDelay_PROPS() + { + GUI.color = Color.white; + animatedElement.delayEnabled = EditorGUILayout.ToggleLeft("Enable Delay", animatedElement.delayEnabled); + + if (animatedElement.delayEnabled) + { + EditorGUILayout.PropertyField(_showDelay, new GUIContent("Show Delay")); + } + + EditorGUILayout.Space(); EditorGUILayout.Space(); + } + + private void HideAnimationDelay_PROPS() + { + GUI.color = Color.white; + animatedElement.delayEnabled = EditorGUILayout.ToggleLeft("Enable Delay", animatedElement.delayEnabled); + + if (animatedElement.delayEnabled) + { + EditorGUILayout.PropertyField(_hideDelay, new GUIContent("Hide Delay")); + } + + EditorGUILayout.Space(); EditorGUILayout.Space(); + } + + private void OnShow_EVENT() + { + EditorGUILayout.BeginVertical(); + + EditorGUILayout.PropertyField(_onShowEvent, new GUIContent("On Animation Start")); + GUILayout.Space(10); + + EditorGUILayout.EndVertical(); + } + + private void OnShowComplete_EVENT() + { + EditorGUILayout.BeginVertical(); + + EditorGUILayout.PropertyField(_onShowCompleteEvent, new GUIContent("On Animation Complete")); + GUILayout.Space(10); + + EditorGUILayout.EndVertical(); + } + + private void OnHide_EVENT() + { + EditorGUILayout.BeginVertical(); + + EditorGUILayout.PropertyField(_onHideEvent, new GUIContent("On Animation Start")); + + EditorGUILayout.EndVertical(); + } + + private void OnHideComplete_EVENT() + { + EditorGUILayout.BeginVertical(); + + EditorGUILayout.PropertyField(_onHideCompleteEvent, new GUIContent("On Animation Complete")); + + EditorGUILayout.EndVertical(); + } + + //=========================================================================================================== + + private void SaveInspectorValues() + { + foreach (var id in Selection.instanceIDs) + { + EditorPrefs.SetInt("airyui/custom/" + nameof(currentTabIndex), currentTabIndex); + } + } + + private void GetSavedInspectorValues() + { + currentTabIndex = EditorPrefs.GetInt("airyui/custom/" + nameof(currentTabIndex), 0); + } + } +} \ No newline at end of file diff --git a/Assets/Airy UI/Editor/CustomAnimatedElement_Inspector.cs.meta b/Assets/Airy UI/Editor/CustomAnimatedElement_Inspector.cs.meta new file mode 100644 index 00000000..3fbcba93 --- /dev/null +++ b/Assets/Airy UI/Editor/CustomAnimatedElement_Inspector.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: ca397c1c5f6fa984abd9caafd619f284 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 5012f5c66ad8aef43950aabb25f0b7e0, 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/Editor/CustomAnimatedElement_Inspector.cs + uploadId: 760159 diff --git a/Assets/Airy UI/Editor/EditorGUILayoutExtensions.cs b/Assets/Airy UI/Editor/EditorGUILayoutExtensions.cs new file mode 100644 index 00000000..85721c5f --- /dev/null +++ b/Assets/Airy UI/Editor/EditorGUILayoutExtensions.cs @@ -0,0 +1,56 @@ +using System; +using UnityEngine; +using UnityEditor; + + +namespace AiryUI +{ + + + public static class EditorGUILayoutExtensions + { + public static void ToggleLeft(this SerializedProperty prop, GUIContent label, params GUILayoutOption[] options) + { + EditorGUI.BeginChangeCheck(); + EditorGUI.showMixedValue = prop.hasMultipleDifferentValues; + var newValue = EditorGUILayout.ToggleLeft(label, prop.boolValue, options); + EditorGUI.showMixedValue = false; + if (EditorGUI.EndChangeCheck()) + prop.boolValue = newValue; + } + + + /// + /// Create a EditorGUILayout.Slider which properly handles multi-object editing + /// We apply the 'convIn' conversion to the SerializedProperty value before exposing it as a Slider. + /// We apply the 'convOut' conversion to the Slider value to store it back to the SerializedProperty. + /// + /// The value the slider shows. This determines the position of the draggable thumb. + /// Label in front of the slider. + /// The value at the left end of the slider. + /// The value at the right end of the slider. + /// Conversion function applied on the SerializedProperty to get the Slider value + /// Conversion function applied on the Slider value to get the SerializedProperty + public static void FloatSlider( + this SerializedProperty prop, + GUIContent label, + float leftValue, float rightValue, + Func convIn, + Func convOut, + params GUILayoutOption[] options) + { + var floatValue = convIn(prop.floatValue); + EditorGUI.BeginChangeCheck(); + { + EditorGUI.showMixedValue = prop.hasMultipleDifferentValues; + { + floatValue = EditorGUILayout.Slider(label, floatValue, leftValue, rightValue, options); + } + EditorGUI.showMixedValue = false; + } + if (EditorGUI.EndChangeCheck()) + prop.floatValue = convOut(floatValue); + } + } + +} \ No newline at end of file diff --git a/Assets/Airy UI/Editor/EditorGUILayoutExtensions.cs.meta b/Assets/Airy UI/Editor/EditorGUILayoutExtensions.cs.meta new file mode 100644 index 00000000..e42de22e --- /dev/null +++ b/Assets/Airy UI/Editor/EditorGUILayoutExtensions.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: c0ec872a0a1c26340835775ab18f99ed +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 135898 + packageName: Airy UI 2 - Easy UI Animation + packageVersion: 2.0.2 + assetPath: Assets/Airy UI/Editor/EditorGUILayoutExtensions.cs + uploadId: 760159 diff --git a/Assets/Airy UI/Editor/MainWindow.cs b/Assets/Airy UI/Editor/MainWindow.cs new file mode 100644 index 00000000..bf5090ef --- /dev/null +++ b/Assets/Airy UI/Editor/MainWindow.cs @@ -0,0 +1,275 @@ +using UnityEngine; +using UnityEditor; + +namespace AiryUI +{ + public class MainWindow : EditorWindow + { + + + private static EditorWindow window; + private GUIStyle buttonContentStyle; + private Vector2 windowScroll; + + + [MenuItem ( "Airy UI/Main Window" , priority = 0 )] + private static void ShowWindow () + { + window = GetWindow ( "Airy UI" ); + window.Show (); + + window.maxSize = new Vector2 ( 370 , 650 ); + window.minSize = new Vector2 ( 370 , 620 ); + } + + + private void OnGUI () + { + windowScroll = EditorGUILayout.BeginScrollView ( windowScroll , false , false ); + + GUILayout.Space ( 20 ); + + DrawAnimationManager_BUTTONS (); + + DrawAnimatedElement_BUTTONS (); + + DrawBackBtn_BUTTONS (); + + DrawRateBox (); + + DrawYoutube (); + + EditorGUILayout.EndScrollView (); + } + + + private void WindowTitle_LABEL () + { + GUI.color = Color.white; + + + GUILayout.Space ( 10 ); + + var titleLabelStyle = new GUIStyle ( GUI.skin.label ) { alignment = TextAnchor.MiddleLeft , fontSize = 25 , fontStyle = FontStyle.Bold , fixedHeight = 50 }; + + EditorGUILayout.LabelField ( "Airy UI Main Window" , titleLabelStyle ); + GUILayout.Space ( 50 ); + } + + + private void DrawAnimationManager_BUTTONS () + { + SetButtonStyle ( new Color ( 0.48f , 0.56f , 1 ) ); + + GUIContent buttonContent = new GUIContent ( " Add Animated Elements Group" , SetIcon ( "manager_add.png" ) ); + if ( GUILayout.Button ( buttonContent , buttonContentStyle ) ) + { + foreach ( GameObject g in Selection.gameObjects ) + { + Undo.AddComponent ( g ); + } + } + + + buttonContent = new GUIContent ( " Remove Animated Elements Group" , SetIcon ( "manager_remove.png" ) ); + if ( GUILayout.Button ( buttonContent , buttonContentStyle ) ) + { + foreach ( GameObject g in Selection.gameObjects ) + { + if ( g.GetComponent () != null ) + { + Undo.DestroyObjectImmediate ( g.GetComponent () ); + } + } + } + + GUILayout.Space ( 20 ); + + } + + + private void DrawAnimatedElement_BUTTONS () + { + SetButtonStyle ( new Color ( 1 , 0.29f , 0.74f ) ); + + GUIContent buttonContent = new GUIContent ( " Add Animated Element" , SetIcon ( "animation_add.png" ) ); + if ( GUILayout.Button ( buttonContent , buttonContentStyle ) ) + { + foreach ( GameObject g in Selection.gameObjects ) + { + Undo.AddComponent ( g ); + } + } + + + buttonContent = new GUIContent ( " Add Custom Animated Element" , SetIcon ( "c_animation_add.png" ) ); + if ( GUILayout.Button ( buttonContent , buttonContentStyle ) ) + { + foreach ( GameObject g in Selection.gameObjects ) + { + if ( g.GetComponent () == null ) + { + Undo.AddComponent ( g ); + } + } + } + + + buttonContent = new GUIContent ( " Remove Animated Element" , SetIcon ( "animation_remove.png" ) ); + if ( GUILayout.Button ( buttonContent , buttonContentStyle ) ) + { + foreach ( GameObject g in Selection.gameObjects ) + { + Undo.RecordObject ( g , "Remove Animated Element" ); + if ( g.GetComponent () != null ) + Undo.DestroyObjectImmediate ( g.GetComponent () ); + + if ( g.GetComponent () != null ) + Undo.DestroyObjectImmediate ( g.GetComponent () ); + } + } + + GUILayout.Space ( 20 ); + } + + + + private void DrawBackBtn_BUTTONS () + { + SetButtonStyle ( new Color ( 1 , 0.52f , 0.28f ) ); + + + GUIContent buttonContent = new GUIContent ( " Add Esc Button" , SetIcon ( "esc_add.png" ) ); + if ( GUILayout.Button ( buttonContent , buttonContentStyle ) ) + { + foreach ( GameObject g in Selection.gameObjects ) + { + if ( g.GetComponent () == null ) + { + Undo.AddComponent ( g ); + } + } + } + + + buttonContent = new GUIContent ( " Remove Esc Button" , SetIcon ( "esc_remove.png" ) ); + if ( GUILayout.Button ( buttonContent , buttonContentStyle ) ) + { + foreach ( GameObject g in Selection.gameObjects ) + { + if ( g.GetComponent () != null ) + { + Undo.DestroyObjectImmediate ( g.GetComponent () ); + } + } + } + + GUILayout.Space ( 20 ); + + SetButtonStyle ( new Color ( 1 , 0.38f , 0.28f ) ); + + + buttonContent = new GUIContent ( " Add UI Close Button" , SetIcon ( "back_add.png" ) ); + if ( GUILayout.Button ( buttonContent , buttonContentStyle ) ) + { + foreach ( GameObject g in Selection.gameObjects ) + { + if ( g.GetComponent () == null ) + { + Undo.AddComponent ( g ); + } + } + } + + + buttonContent = new GUIContent ( " Remove UI Close Button" , SetIcon ( "back_remove.png" ) ); + if ( GUILayout.Button ( buttonContent , buttonContentStyle ) ) + { + foreach ( GameObject g in Selection.gameObjects ) + { + if ( g.GetComponent () != null ) + { + Undo.DestroyObjectImmediate ( g.GetComponent () ); + } + } + } + + + GUILayout.Space ( 20 ); + } + + + + [MenuItem ( "Airy UI/Rate On Asset Store" , priority = 15 )] + public static void RateOnAssetStore () + { + Application.OpenURL ( "https://assetstore.unity.com/packages/tools/gui/airy-ui-2-easy-ui-animation-135898#reviews" ); + } + + + [MenuItem ( "Airy UI/Suggest | Report Bug" , priority = 16 )] + public static void ReportBug () + { + Application.OpenURL ( "https://forms.gle/4a9BU3C9ScP4XBoS8" ); + } + + + [MenuItem ( "Airy UI/My Youtube Channel" , priority = 36 )] + public static void YoutubeChannel () + { + Application.OpenURL ( "https://youtube.com/ahmedsabrygamedev" ); + } + + + private void DrawRateBox () + { + GUILayout.Label ( "If you like Airy UI, Please Rate it On Asset Store ♡" ); + + SetButtonStyle ( new Color ( 0.317f , 1 , 0.43f ) , 30 ); + + GUIContent buttonContent = new GUIContent ( " Rate ♡" , SetIcon ( "asset_store.png" ) ); + + if ( GUILayout.Button ( buttonContent , buttonContentStyle ) ) + Application.OpenURL ( "https://assetstore.unity.com/packages/tools/gui/airy-ui-2-easy-ui-animation-135898#reviews" ); + + GUILayout.Space ( 10 ); + } + + + private void DrawYoutube () + { + GUILayout.Label ( "And also, take a visit to my GameDev Youtube channel" ); + + SetButtonStyle ( new Color ( 0.31f , 0.51f , 1 ) , 30 ); + + GUIContent buttonContent = new GUIContent ( " Visit ♡" , SetIcon ( "youtube.png" ) ); + + if ( GUILayout.Button ( buttonContent , buttonContentStyle ) ) + Application.OpenURL ( "https://youtube.com/ahmedsabrygamedev" ); + } + + + private void SetButtonStyle ( Color backgroundColor , float height = 40 ) + { + GUI.backgroundColor = backgroundColor; + + buttonContentStyle = new GUIStyle ( GUI.skin.button ); + + buttonContentStyle.alignment = TextAnchor.MiddleLeft; + buttonContentStyle.normal.textColor = Color.white; + buttonContentStyle.hover.textColor = Color.yellow; + buttonContentStyle.fixedHeight = height; + buttonContentStyle.fixedWidth = 361; + buttonContentStyle.fontSize = 17; + buttonContentStyle.fontStyle = FontStyle.Bold; + } + + + private Texture2D SetIcon ( string icon ) + { + Texture2D buttonIcon = AssetDatabase.LoadAssetAtPath ( "Assets/Airy UI/Sprites/Icons/" + icon ); + + return buttonIcon; + } + } +} \ No newline at end of file diff --git a/Assets/Airy UI/Editor/MainWindow.cs.meta b/Assets/Airy UI/Editor/MainWindow.cs.meta new file mode 100644 index 00000000..cf182bc9 --- /dev/null +++ b/Assets/Airy UI/Editor/MainWindow.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 1605469f191200d40b9930ba490515f1 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 0c86d94cc61dd1f4d9e208a11aed6c15, 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/Editor/MainWindow.cs + uploadId: 760159 diff --git a/Assets/Airy UI/Fonts.meta b/Assets/Airy UI/Fonts.meta new file mode 100644 index 00000000..99d7fcda --- /dev/null +++ b/Assets/Airy UI/Fonts.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: b91603473e7311242be1acb7e23cbd4b +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Airy UI/Fonts/Font 1.ttf b/Assets/Airy UI/Fonts/Font 1.ttf new file mode 100644 index 00000000..6fefec69 Binary files /dev/null and b/Assets/Airy UI/Fonts/Font 1.ttf differ diff --git a/Assets/Airy UI/Fonts/Font 1.ttf.meta b/Assets/Airy UI/Fonts/Font 1.ttf.meta new file mode 100644 index 00000000..8b3310df --- /dev/null +++ b/Assets/Airy UI/Fonts/Font 1.ttf.meta @@ -0,0 +1,29 @@ +fileFormatVersion: 2 +guid: 7e762b4b6b3331d4ea0cc148ee304a6f +TrueTypeFontImporter: + externalObjects: {} + serializedVersion: 4 + fontSize: 16 + forceTextureCase: -2 + characterSpacing: 0 + characterPadding: 1 + includeFontData: 1 + fontName: Beautiful People Personal Use + fontNames: + - Beautiful People Personal Use + fallbackFontReferences: [] + customCharacters: + fontRenderingMode: 0 + ascentCalculationMode: 1 + useLegacyBoundsCalculation: 0 + shouldRoundAdvanceValue: 1 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 135898 + packageName: Airy UI 2 - Easy UI Animation + packageVersion: 2.0.2 + assetPath: Assets/Airy UI/Fonts/Font 1.ttf + uploadId: 760159 diff --git a/Assets/Airy UI/Fonts/Font 2.ttf b/Assets/Airy UI/Fonts/Font 2.ttf new file mode 100644 index 00000000..304e608c Binary files /dev/null and b/Assets/Airy UI/Fonts/Font 2.ttf differ diff --git a/Assets/Airy UI/Fonts/Font 2.ttf.meta b/Assets/Airy UI/Fonts/Font 2.ttf.meta new file mode 100644 index 00000000..af7e945e --- /dev/null +++ b/Assets/Airy UI/Fonts/Font 2.ttf.meta @@ -0,0 +1,28 @@ +fileFormatVersion: 2 +guid: 4506bf6ca285b494ab0993e12703d5e6 +timeCreated: 1506421581 +licenseType: Store +TrueTypeFontImporter: + serializedVersion: 4 + fontSize: 16 + forceTextureCase: -2 + characterSpacing: 0 + characterPadding: 1 + includeFontData: 1 + fontName: Fredoka One + fontNames: + - Fredoka One + fallbackFontReferences: [] + customCharacters: + fontRenderingMode: 0 + ascentCalculationMode: 1 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 135898 + packageName: Airy UI 2 - Easy UI Animation + packageVersion: 2.0.2 + assetPath: Assets/Airy UI/Fonts/Font 2.ttf + uploadId: 760159 diff --git a/Assets/Airy UI/Fonts/Font 3.ttf b/Assets/Airy UI/Fonts/Font 3.ttf new file mode 100644 index 00000000..f9427d50 Binary files /dev/null and b/Assets/Airy UI/Fonts/Font 3.ttf differ diff --git a/Assets/Airy UI/Fonts/Font 3.ttf.meta b/Assets/Airy UI/Fonts/Font 3.ttf.meta new file mode 100644 index 00000000..9efd92e6 --- /dev/null +++ b/Assets/Airy UI/Fonts/Font 3.ttf.meta @@ -0,0 +1,29 @@ +fileFormatVersion: 2 +guid: 540af095b0b487a4f81d2d30c250df69 +TrueTypeFontImporter: + externalObjects: {} + serializedVersion: 4 + fontSize: 16 + forceTextureCase: -2 + characterSpacing: 0 + characterPadding: 1 + includeFontData: 1 + fontName: Merry Christmas Color + fontNames: + - Merry Christmas Color + fallbackFontReferences: [] + customCharacters: + fontRenderingMode: 0 + ascentCalculationMode: 1 + useLegacyBoundsCalculation: 0 + shouldRoundAdvanceValue: 1 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 135898 + packageName: Airy UI 2 - Easy UI Animation + packageVersion: 2.0.2 + assetPath: Assets/Airy UI/Fonts/Font 3.ttf + uploadId: 760159 diff --git a/Assets/Airy UI/Fonts/Font 4.ttf b/Assets/Airy UI/Fonts/Font 4.ttf new file mode 100644 index 00000000..d8cfc33d Binary files /dev/null and b/Assets/Airy UI/Fonts/Font 4.ttf differ diff --git a/Assets/Airy UI/Fonts/Font 4.ttf.meta b/Assets/Airy UI/Fonts/Font 4.ttf.meta new file mode 100644 index 00000000..500254f1 --- /dev/null +++ b/Assets/Airy UI/Fonts/Font 4.ttf.meta @@ -0,0 +1,28 @@ +fileFormatVersion: 2 +guid: 14f4ee6bda529af43a941a41922b6132 +TrueTypeFontImporter: + externalObjects: {} + serializedVersion: 4 + fontSize: 16 + forceTextureCase: -2 + characterSpacing: 0 + characterPadding: 1 + includeFontData: 1 + fontNames: + - Magensburg + fallbackFontReferences: [] + customCharacters: + fontRenderingMode: 0 + ascentCalculationMode: 1 + useLegacyBoundsCalculation: 0 + shouldRoundAdvanceValue: 1 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 135898 + packageName: Airy UI 2 - Easy UI Animation + packageVersion: 2.0.2 + assetPath: Assets/Airy UI/Fonts/Font 4.ttf + uploadId: 760159 diff --git a/Assets/Airy UI/Scripts.meta b/Assets/Airy UI/Scripts.meta new file mode 100644 index 00000000..b5fe2ee6 --- /dev/null +++ b/Assets/Airy UI/Scripts.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: a0cf928a42dc190459b20952c4200664 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Airy UI/Scripts/Anchors.cs b/Assets/Airy UI/Scripts/Anchors.cs new file mode 100644 index 00000000..dd10f526 --- /dev/null +++ b/Assets/Airy UI/Scripts/Anchors.cs @@ -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 ().rect.width; + parentRectHeight = rectTransform.parent.GetComponent ().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; + } + + + } +} \ No newline at end of file diff --git a/Assets/Airy UI/Scripts/Anchors.cs.meta b/Assets/Airy UI/Scripts/Anchors.cs.meta new file mode 100644 index 00000000..7d3ce66a --- /dev/null +++ b/Assets/Airy UI/Scripts/Anchors.cs.meta @@ -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 diff --git a/Assets/Airy UI/Scripts/AnimatedElement.cs b/Assets/Airy UI/Scripts/AnimatedElement.cs new file mode 100644 index 00000000..93790bae --- /dev/null +++ b/Assets/Airy UI/Scripts/AnimatedElement.cs @@ -0,0 +1,1152 @@ +using UnityEngine; +using System.Collections; +using System.Collections.Generic; +using UnityEngine.UI; +using UnityEngine.Events; +using System.Linq; + + +namespace AiryUI +{ + [AddComponentMenu ( "Airy UI/Animated Element" )] + [RequireComponent ( typeof ( RectTransform ) )] + [DisallowMultipleComponent] + public class AnimatedElement : MonoBehaviour + { + + public bool isControlledByGroup; + public AnimatedElementsGroup group; + + public UnityEvent OnShow; + public UnityEvent OnHide; + public UnityEvent OnShowComplete; + public UnityEvent OnHideComplete; + + public bool disableShowAnimation; + public bool disableHideAnimation; + + public Canvas containerCanvas; + + [Tooltip ( "Show animation on game object activation\nset to false if you want to activate this game object without animation" )] + public bool animateOnEnable = true; + + public TimeMode showTimeMode; + public TimeMode hideTimeMode; + + public AnimationType showAnimationType; + public AnimationType hideAnimationType; + public AnimationStartPosition animationMoveFrom; + public AnimationStartPosition animationMoveTo; + + public bool addBounciness; + [Range ( 0 , 1 )] public float bouncinessPower = 0.1f; + [Range ( 0 , 1 )] public float bouncinessDuration = 0.1f; + + public bool fadeChildren; + + [Min ( 0.01f )] public float animationShowDuration = 0.5f; + [Min ( 0.01f )] public float animationHideDuration = 0.5f; + + public bool delayEnabled; + public float showDelay; + public float hideDelay; + + public Vector3 rotateFrom; + public Vector3 rotateTo; + + public Vector3 worldPosition_initial; + public Vector3 localPosition_initial; + public Vector3 anchoredPosition_initial; + public Color [] childrenColors_initial; + public Vector3 scale_initial; + public Quaternion rotation_initial; + public Vector2 pivot_initial; + + protected RectTransform rectTransformComponent; + + private List graphicalComponents; + + protected bool initializeComplete = false; + + protected IEnumerator currentRunningCoroutine; + + + + private void OnEnable () + { + InitializeValues (); + + if ( isControlledByGroup ) + return; + + if ( animateOnEnable ) + { + ShowElement (); + } + } + + + private void OnValidate () + { + if ( isControlledByGroup && group != null ) + { + if ( !group.animatedElements.Contains ( this ) ) + { + group.animatedElements.Add ( this ); + } + } + else + { + if ( group != null && group.animatedElements.Contains ( this ) ) + { + group.animatedElements.Remove ( this ); + } + } + } + + + private void InitializeValues () + { + if ( initializeComplete ) + return; + + rectTransformComponent = GetComponent (); + + graphicalComponents = new List (); + if ( showAnimationType == AnimationType.FadeColor || hideAnimationType == AnimationType.FadeColor ) + { + if ( fadeChildren ) + { + graphicalComponents = GetComponentsInChildren ( true ).ToList (); + + // remove any component that has animated element, so that it animates by itself. + graphicalComponents.RemoveAll ( g => g.GetComponent () != null && g.gameObject != gameObject ); + graphicalComponents.RemoveAll ( g => g.GetComponent () != null && g.gameObject != gameObject ); + } + else + { + if ( GetComponent () ) + { + graphicalComponents.Add ( GetComponent () ); + } + } + } + + childrenColors_initial = new Color [ graphicalComponents.Count ]; + for ( int i = 0 ; i < graphicalComponents.Count ; i++ ) + { + childrenColors_initial [ i ] = graphicalComponents [ i ].color; + } + + worldPosition_initial = rectTransformComponent.position; + localPosition_initial = rectTransformComponent.localPosition; + anchoredPosition_initial = rectTransformComponent.anchoredPosition; + + scale_initial = rectTransformComponent.localScale; + rotation_initial = rectTransformComponent.rotation; + pivot_initial = rectTransformComponent.pivot; + + initializeComplete = true; + } + + + public virtual void ShowElement () + { + gameObject.SetActive ( true ); + + + if ( disableShowAnimation ) + { + gameObject.SetActive ( true ); + OnShowComplete.Invoke (); + + return; + } + + + currentRunningCoroutine = EmptyCoroutine (); + + + switch ( showAnimationType ) + { + case ( AnimationType.Scale ): + + if ( currentRunningCoroutine != null ) + StopCoroutine ( currentRunningCoroutine ); + + currentRunningCoroutine = AnimateScale_SHOW (); + StartCoroutine ( currentRunningCoroutine ); + + break; + + case ( AnimationType.Rotate ): + + if ( currentRunningCoroutine != null ) + StopCoroutine ( currentRunningCoroutine ); + + currentRunningCoroutine = AnimateRotate_SHOW (); + StartCoroutine ( currentRunningCoroutine ); + + break; + + case ( AnimationType.FadeColor ): + + if ( currentRunningCoroutine != null ) + StopCoroutine ( currentRunningCoroutine ); + + currentRunningCoroutine = AnimateFadeIn_SHOW (); + StartCoroutine ( currentRunningCoroutine ); + + break; + + case ( AnimationType.Move ): + + if ( currentRunningCoroutine != null ) + StopCoroutine ( currentRunningCoroutine ); + + currentRunningCoroutine = AnimateMove_SHOW (); + StartCoroutine ( currentRunningCoroutine ); + + break; + + case ( AnimationType.MoveWithScale ): + + if ( currentRunningCoroutine != null ) + StopCoroutine ( currentRunningCoroutine ); + + currentRunningCoroutine = AnimateMoveWithScale_SHOW (); + StartCoroutine ( currentRunningCoroutine ); + + break; + } + + + } + + + public virtual void HideElement () + { + if ( !gameObject.activeSelf ) + return; + + + if ( disableHideAnimation ) + { + gameObject.SetActive ( false ); + OnHideComplete.Invoke (); + + return; + } + + + switch ( hideAnimationType ) + { + case ( AnimationType.Scale ): + + if ( currentRunningCoroutine != null ) + StopCoroutine ( currentRunningCoroutine ); + + currentRunningCoroutine = AnimateScale_HIDE (); + StartCoroutine ( currentRunningCoroutine ); + + break; + + case ( AnimationType.Rotate ): + + if ( currentRunningCoroutine != null ) + StopCoroutine ( currentRunningCoroutine ); + + currentRunningCoroutine = AnimateRotation_HIDE (); + StartCoroutine ( currentRunningCoroutine ); + + break; + + case ( AnimationType.FadeColor ): + + if ( currentRunningCoroutine != null ) + StopCoroutine ( currentRunningCoroutine ); + + currentRunningCoroutine = AnimateFadeOut_HIDE (); + StartCoroutine ( currentRunningCoroutine ); + + break; + + case ( AnimationType.Move ): + + if ( currentRunningCoroutine != null ) + StopCoroutine ( currentRunningCoroutine ); + + currentRunningCoroutine = AnimateMove_HIDE (); + StartCoroutine ( currentRunningCoroutine ); + + break; + + case ( AnimationType.MoveWithScale ): + + if ( currentRunningCoroutine != null ) + StopCoroutine ( currentRunningCoroutine ); + + currentRunningCoroutine = AnimateMoveWithScale_HIDE (); + StartCoroutine ( currentRunningCoroutine ); + + break; + } + + + } + + + #region Show Coroutines + + + private IEnumerator AnimateMoveWithScale_SHOW () + { + InitializeValues (); + + if ( animationShowDuration <= 0 ) + yield break; + + Vector3 startPos = AnimationPositions.GetStartPositionFromCorner ( localPosition_initial , rectTransformComponent , animationMoveFrom ); + + ResetPosition (); + ResetScale ( ResetOptions.Zero ); + + #region Initialization Part + + // Here we get start color to a color with alpha = 0, and the end color to a color with alpha = 1. + + Color [] startColors = new Color [ graphicalComponents.Count ]; + Color [] endColors = new Color [ graphicalComponents.Count ]; + + for ( int i = 0 ; i < graphicalComponents.Count ; i++ ) + { + startColors [ i ] = graphicalComponents [ i ].color; + startColors [ i ].a = 0; + + endColors [ i ] = childrenColors_initial [ i ]; + } + + Vector3 targetPosition = ( addBounciness ) ? localPosition_initial + GetMoveDirection () * bouncinessPower : localPosition_initial; + Vector3 targetScale = ( addBounciness ) ? scale_initial + ( scale_initial * bouncinessPower ) : scale_initial; + + rectTransformComponent.localPosition = startPos; + + #endregion + + yield return null; + + yield return WaitForSeconds_SHOW ( delayEnabled ? showDelay : 0 ); + + OnShow?.Invoke (); + + float elapsedTime = 0; + + while ( elapsedTime <= animationShowDuration ) + { + float t = elapsedTime / animationShowDuration; + + // Here we Lerp the position and the scale as well. + rectTransformComponent.localPosition = Vector3.Lerp ( startPos , targetPosition , t ); + rectTransformComponent.localScale = Vector3.Lerp ( Vector3.zero , targetScale , t ); + + // Here we lerp the color from transparent to visible. + for ( int i = 0 ; i < graphicalComponents.Count ; i++ ) + graphicalComponents [ i ].color = Color.Lerp ( startColors [ i ] , endColors [ i ] , t ); + + elapsedTime += DeltaTimeFor_SHOW; + yield return null; + } + + + if ( addBounciness ) + { + elapsedTime = 0; + while ( elapsedTime <= bouncinessDuration ) + { + float t = elapsedTime / bouncinessDuration; + rectTransformComponent.localPosition = Vector3.Lerp ( targetPosition , localPosition_initial , t ); + rectTransformComponent.localScale = Vector3.Lerp ( targetScale , scale_initial , t ); + + elapsedTime += DeltaTimeFor_SHOW; + yield return null; + } + } + + rectTransformComponent.localPosition = localPosition_initial; + rectTransformComponent.localScale = scale_initial; + for ( int i = 0 ; i < graphicalComponents.Count ; i++ ) + graphicalComponents [ i ].color = endColors [ i ]; + + OnShowComplete?.Invoke (); + } + + private IEnumerator AnimateMove_SHOW () + { + InitializeValues (); + + if ( animationShowDuration <= 0 ) + yield break; + + Vector3 startPos = AnimationPositions.GetStartPositionFromCorner ( localPosition_initial , rectTransformComponent , animationMoveFrom ); + Vector3 targetPosition = ( addBounciness ) ? localPosition_initial + ( GetMoveDirection () * bouncinessPower ) : localPosition_initial; + + ResetPosition (); + ResetScale ( ResetOptions.Zero ); + ResetColor ( ResetOptions.Zero ); + + yield return null; + + yield return WaitForSeconds_SHOW ( delayEnabled ? showDelay : 0 ); + + OnShow?.Invoke (); + + ResetPosition (); + ResetScale ( ResetOptions.One ); + ResetColor ( ResetOptions.One ); + + // Starting animating. + float elapsedTime = 0; + rectTransformComponent.localPosition = startPos; + + while ( elapsedTime <= animationShowDuration ) + { + float t = elapsedTime / animationShowDuration; + + rectTransformComponent.localPosition = Vector3.Lerp ( startPos , targetPosition , t ); + + elapsedTime += DeltaTimeFor_SHOW; + yield return null; + } + + if ( addBounciness ) + { + elapsedTime = 0; + while ( elapsedTime <= bouncinessDuration ) + { + float t = elapsedTime / bouncinessDuration; + rectTransformComponent.localPosition = Vector3.Lerp ( targetPosition , localPosition_initial , t ); + + elapsedTime += DeltaTimeFor_SHOW; + yield return null; + } + } + + rectTransformComponent.localPosition = localPosition_initial; + + OnShowComplete?.Invoke (); + } + + private IEnumerator AnimateScale_SHOW () + { + InitializeValues (); + + if ( animationShowDuration <= 0 ) + yield break; + + ResetPosition (); + ResetScale ( ResetOptions.Zero ); + ResetColor ( ResetOptions.One ); + + yield return null; + + yield return WaitForSeconds_SHOW ( delayEnabled ? showDelay : 0 ); + + OnShow?.Invoke (); + + Vector3 targetScale = ( addBounciness ) ? scale_initial + ( scale_initial * bouncinessPower ) : scale_initial; + + float elapsedTime = 0; + while ( elapsedTime <= animationShowDuration ) + { + float t = elapsedTime / animationShowDuration; + + rectTransformComponent.localScale = Vector3.Lerp ( Vector3.zero , targetScale , t ); + + elapsedTime += DeltaTimeFor_SHOW; + yield return null; + } + + if ( addBounciness ) + { + elapsedTime = 0; + while ( elapsedTime <= bouncinessDuration ) + { + // we should scale up then scale down. + + float t = elapsedTime / bouncinessDuration; + rectTransformComponent.localScale = Vector3.Lerp ( targetScale , scale_initial , t ); + + elapsedTime += DeltaTimeFor_SHOW; + yield return null; + } + } + + rectTransformComponent.localScale = scale_initial; + + OnShowComplete?.Invoke (); + } + + private IEnumerator AnimateFadeIn_SHOW () + { + InitializeValues (); + + if ( animationShowDuration <= 0 ) + yield break; + + ResetPosition (); + ResetScale ( ResetOptions.One ); + + #region Initialization Part + + Color [] startColors = new Color [ graphicalComponents.Count ]; + Color [] endColors = new Color [ graphicalComponents.Count ]; + + for ( int i = 0 ; i < graphicalComponents.Count ; i++ ) + { + startColors [ i ] = graphicalComponents [ i ].color; + startColors [ i ].a = 0; + + endColors [ i ] = childrenColors_initial [ i ]; + } + + ResetColor ( ResetOptions.Zero ); + + #endregion + + yield return null; + + yield return WaitForSeconds_SHOW ( delayEnabled ? showDelay : 0 ); + + OnShow?.Invoke (); + + if ( fadeChildren ) + { + float elapsedTime = 0; + while ( elapsedTime <= animationShowDuration ) + { + float t = elapsedTime / animationShowDuration; + graphicalComponents [ 0 ].color = Color.Lerp ( startColors [ 0 ] , endColors [ 0 ] , t ); + for ( int i = 0 ; i < graphicalComponents.Count ; i++ ) + { + graphicalComponents [ i ].color = Color.Lerp ( startColors [ i ] , endColors [ i ] , t ); + } + + elapsedTime += DeltaTimeFor_SHOW; + yield return null; + } + for ( int i = 0 ; i < graphicalComponents.Count ; i++ ) + { + graphicalComponents [ i ].color = endColors [ i ]; + } + } + else + { + float elapsedTime = 0; + while ( elapsedTime <= animationShowDuration ) + { + float t = elapsedTime / animationShowDuration; + graphicalComponents [ 0 ].color = Color.Lerp ( startColors [ 0 ] , endColors [ 0 ] , t ); + + elapsedTime += DeltaTimeFor_SHOW; + yield return null; + } + + graphicalComponents [ 0 ].color = endColors [ 0 ]; + } + + OnShowComplete?.Invoke (); + } + + private IEnumerator AnimateRotate_SHOW () + { + InitializeValues (); + + if ( animationShowDuration <= 0 ) + yield break; + + ResetPosition (); + ResetScale ( ResetOptions.One ); + ResetColor ( ResetOptions.One ); + ResetRotation ( ResetOptions.One , true ); + + yield return null; + + yield return WaitForSeconds_SHOW ( delayEnabled ? showDelay : 0 ); + + OnShow?.Invoke (); + + Vector3 targetRotation = ( addBounciness ) ? rotation_initial.eulerAngles - ( rotateFrom * bouncinessPower ) : rotation_initial.eulerAngles; + + float elapsedTime = 0; + while ( elapsedTime <= animationShowDuration ) + { + float t = elapsedTime / animationShowDuration; + + rectTransformComponent.eulerAngles = Vector3.Lerp ( rotateFrom , targetRotation , t ); + + elapsedTime += DeltaTimeFor_SHOW; + yield return null; + } + + if ( addBounciness ) + { + elapsedTime = 0; + while ( elapsedTime <= bouncinessDuration ) + { + float t = elapsedTime / bouncinessDuration; + rectTransformComponent.eulerAngles = Vector3.Lerp ( targetRotation , rotation_initial.eulerAngles , t ); + + elapsedTime += DeltaTimeFor_SHOW; + yield return null; + } + } + + rectTransformComponent.eulerAngles = rotation_initial.eulerAngles; + + OnShowComplete?.Invoke (); + } + + + #endregion + + + //======================================================================================= + //======================================================================================= + + + #region Hide Coroutines + + + private IEnumerator AnimateFadeOut_HIDE () + { + yield return null; + if ( !initializeComplete ) + InitializeValues (); + + if ( animationHideDuration <= 0 ) + yield break; + + ResetPosition (); + ResetScale ( ResetOptions.One ); + ResetColor ( ResetOptions.One ); + + #region Initialization Part + + Color [] startColors = new Color [ graphicalComponents.Count ], endColors = new Color [ graphicalComponents.Count ]; + + for ( int i = 0 ; i < graphicalComponents.Count ; i++ ) + { + startColors [ i ] = childrenColors_initial [ i ]; + + endColors [ i ] = childrenColors_initial [ i ]; + endColors [ i ].a = 0; + } + + #endregion + + yield return WaitForSeconds_HIDE ( delayEnabled ? hideDelay : 0 ); + + OnHide?.Invoke (); + + float elapsedTime = 0; + + if ( fadeChildren ) + { + while ( elapsedTime <= animationHideDuration ) + { + float t = elapsedTime / animationHideDuration; + for ( int i = 0 ; i < graphicalComponents.Count ; i++ ) + { + graphicalComponents [ i ].color = Color.Lerp ( startColors [ i ] , endColors [ i ] , t ); + } + + elapsedTime += DeltaTimeFor_HIDE; + yield return null; + } + for ( int i = 0 ; i < graphicalComponents.Count ; i++ ) + { + graphicalComponents [ i ].color = endColors [ i ]; + } + } + else + { + while ( elapsedTime <= animationHideDuration ) + { + float t = elapsedTime / animationHideDuration; + graphicalComponents [ 0 ].color = Color.Lerp ( startColors [ 0 ] , endColors [ 0 ] , t ); + + elapsedTime += DeltaTimeFor_HIDE; + yield return null; + } + + graphicalComponents [ 0 ].color = endColors [ 0 ]; + } + + ResetDefaults (); + + OnHideComplete?.Invoke (); + } + + + private IEnumerator AnimateScale_HIDE () + { + yield return null; + if ( !initializeComplete ) + InitializeValues (); + + if ( animationHideDuration <= 0 ) + yield break; + + Vector3 startPosition = rectTransformComponent.position; + rectTransformComponent.localScale = Vector3.one; + + yield return WaitForSeconds_HIDE ( delayEnabled ? hideDelay : 0 ); + + OnHide?.Invoke (); + + float elapsedTime = 0; + + while ( elapsedTime <= animationHideDuration ) + { + float t = elapsedTime / animationHideDuration; + + rectTransformComponent.localScale = Vector3.Lerp ( Vector3.one , Vector3.zero , t ); + + elapsedTime += DeltaTimeFor_HIDE; + yield return null; + } + + rectTransformComponent.localScale = Vector3.zero; + + ResetDefaults (); + + OnHideComplete?.Invoke (); + } + + + private IEnumerator AnimateMoveWithScale_HIDE () + { + yield return null; + if ( !initializeComplete ) + InitializeValues (); + + if ( animationHideDuration <= 0 ) + yield break; + + Graphic [] images; + + if ( fadeChildren ) + images = GetComponentsInChildren (); + else + images = GetComponents (); + + Color [] startColors = new Color [ images.Length ]; + Color [] endColors = new Color [ images.Length ]; + + for ( int i = 0 ; i < images.Length ; i++ ) + { + startColors [ i ] = childrenColors_initial [ i ]; + + endColors [ i ] = images [ i ].color; + endColors [ i ].a = 0; + } + + + Vector3 startPos = localPosition_initial; + Vector3 targetPosition = AnimationPositions.GetStartPositionFromCorner ( localPosition_initial , rectTransformComponent , animationMoveTo ); + rectTransformComponent.localPosition = startPos; + + yield return WaitForSeconds_HIDE ( delayEnabled ? hideDelay : 0 ); + + OnHide?.Invoke (); + + float elapsedTime = 0; + + while ( elapsedTime <= animationHideDuration ) + { + float t = elapsedTime / animationHideDuration; + rectTransformComponent.localPosition = Vector3.Lerp ( startPos , targetPosition , t ); + rectTransformComponent.localScale = Vector3.Lerp ( Vector3.one , Vector3.zero , t ); + + for ( int i = 0 ; i < images.Length ; i++ ) + { + images [ i ].color = Color.Lerp ( startColors [ i ] , endColors [ i ] , t ); + } + + elapsedTime += DeltaTimeFor_HIDE; + yield return null; + } + + rectTransformComponent.localPosition = targetPosition; + rectTransformComponent.localScale = Vector3.zero; + + for ( int i = 0 ; i < images.Length ; i++ ) + { + images [ i ].color = endColors [ i ]; + } + + ResetDefaults (); + + OnHideComplete?.Invoke (); + } + + + private IEnumerator AnimateMove_HIDE () + { + yield return null; + if ( !initializeComplete ) + InitializeValues (); + + if ( animationHideDuration <= 0 ) + yield break; + + Vector3 startPos = localPosition_initial; + Vector3 targetPosition = AnimationPositions.GetStartPositionFromCorner ( localPosition_initial , rectTransformComponent , animationMoveTo ); + rectTransformComponent.localPosition = startPos; + + yield return WaitForSeconds_HIDE ( delayEnabled ? hideDelay : 0 ); + + OnHide?.Invoke (); + + float elapsedTime = 0; + while ( elapsedTime <= animationHideDuration ) + { + float t = elapsedTime / animationHideDuration; + rectTransformComponent.localPosition = Vector3.Lerp ( startPos , targetPosition , t ); + + elapsedTime += DeltaTimeFor_HIDE; + yield return null; + } + + rectTransformComponent.localPosition = targetPosition; + + ResetDefaults (); + + OnHideComplete?.Invoke (); + } + + + private IEnumerator AnimateRotation_HIDE () + { + yield return null; + if ( !initializeComplete ) + InitializeValues (); + + if ( animationHideDuration <= 0 ) + yield break; + + ResetPosition (); + ResetScale ( ResetOptions.One ); + ResetColor ( ResetOptions.One ); + ResetRotation ( ResetOptions.Zero , true ); + + yield return WaitForSeconds_HIDE ( delayEnabled ? hideDelay : 0 ); + + OnHide?.Invoke (); + + float elapsedTime = 0; + while ( elapsedTime <= animationHideDuration ) + { + float t = elapsedTime / animationHideDuration; + + rectTransformComponent.rotation = Quaternion.Euler ( Vector3.Lerp ( Quaternion.ToEulerAngles ( rotation_initial ) , rotateTo , t ) ); + + elapsedTime += DeltaTimeFor_HIDE; + yield return null; + } + + ResetRotation ( ResetOptions.One , false ); + + ResetDefaults (); + + OnHideComplete?.Invoke (); + } + + + #endregion + + + private void ResetDefaults () + { + ResetPosition (); + ResetScale ( ResetOptions.One ); + ResetColor ( ResetOptions.One ); + ResetRotation ( ResetOptions.Zero , true ); + + gameObject.SetActive ( false ); + } + + private void ResetPosition () + { + rectTransformComponent.anchoredPosition = anchoredPosition_initial; + } + + private void ResetColor ( ResetOptions resetOption ) + { + if ( resetOption == ResetOptions.Zero ) + { + for ( int i = 0 ; i < graphicalComponents.Count ; i++ ) + { + graphicalComponents [ i ].color = new Color ( childrenColors_initial [ i ].r , childrenColors_initial [ i ].g , childrenColors_initial [ i ].b , 0 ); + } + + //if ( fadeChildren ) + //{ + // for ( int i = 0 ; i < graphicalComponents.Count ; i++ ) + // { + // graphicalComponents [ i ].color = new Color ( childrenColors_initial [ i ].r , childrenColors_initial [ i ].g , childrenColors_initial [ i ].b , 0 ); + // } + //} + //else + //{ + // // because the index 0 is for the componet on this game object. + // graphicalComponents [ 0 ].color = new Color ( childrenColors_initial [ 0 ].r , childrenColors_initial [ 0 ].g , childrenColors_initial [ 0 ].b , 0 ); + //} + } + else if ( resetOption == ResetOptions.One ) + { + for ( int i = 0 ; i < graphicalComponents.Count ; i++ ) + { + graphicalComponents [ i ].color = childrenColors_initial [ i ]; + } + + //if ( fadeChildren ) + //{ + // for ( int i = 0 ; i < graphicalComponents.Count ; i++ ) + // { + // graphicalComponents [ i ].color = childrenColors_initial [ i ]; + // } + //} + //else + //{ + // graphicalComponents [ 0 ].color = childrenColors_initial [ 0 ]; + //} + } + } + + private void ResetScale ( ResetOptions resetOption ) + { + if ( resetOption == ResetOptions.Zero ) + { + rectTransformComponent.localScale = Vector3.zero; + } + else if ( resetOption == ResetOptions.One ) + { + rectTransformComponent.localScale = scale_initial; + } + } + + private void ResetRotation ( ResetOptions resetOption , bool show ) + { + if ( resetOption == ResetOptions.Zero ) + { + rectTransformComponent.rotation = rotation_initial; + } + else if ( resetOption == ResetOptions.One && show ) + { + rectTransformComponent.rotation = Quaternion.Euler ( rotateFrom ); + } + else if ( resetOption == ResetOptions.One && !show ) + { + rectTransformComponent.rotation = Quaternion.Euler ( rotateTo ); + } + } + + //-------------------------------------------------------------------------------------------------------- + + + private Vector3 GetMoveDirection () + { + float x = 0; + float y = 0; + + switch ( animationMoveFrom ) + { + case ( AnimationStartPosition.Up ): + + x = 0; + y = -Screen.height; + + break; + + case ( AnimationStartPosition.Bottom ): + + x = 0; + y = Screen.height; + + break; + case ( AnimationStartPosition.Right ): + + x = -Screen.width; + y = 0; + + break; + + case ( AnimationStartPosition.Left ): + + x = Screen.width; + y = 0; + + break; + + case ( AnimationStartPosition.UpLeft ): + + x = Screen.width; + y = -Screen.height; + + break; + + case ( AnimationStartPosition.UpRight ): + + x = -Screen.width; + y = -Screen.height; + + break; + + case ( AnimationStartPosition.BottomLeft ): + + x = Screen.width; + y = Screen.height; + + break; + + case ( AnimationStartPosition.BottomRight ): + + x = -Screen.width; + y = Screen.height; + + break; + + case ( AnimationStartPosition.Center ): + + x = 0; + y = -Screen.height; + + break; + } + + return ( new Vector3 ( x , y ) ); + } + + protected float DeltaTimeFor_SHOW + { + get + { + float time = 0; + + switch ( showTimeMode ) + { + case ( TimeMode.TimeScaleDependent ): + time = Time.deltaTime; + + break; + + case ( TimeMode.NotTimeScaleDependent ): + time = Time.unscaledDeltaTime; + + break; + } + + return ( time ); + } + } + + protected float DeltaTimeFor_HIDE + { + get + { + float time = 0; + + switch ( hideTimeMode ) + { + case ( TimeMode.TimeScaleDependent ): + time = Time.deltaTime; + + break; + + case ( TimeMode.NotTimeScaleDependent ): + time = Time.unscaledDeltaTime; + + break; + } + + return ( time ); + } + } + + + protected IEnumerator WaitForSeconds_SHOW ( float time ) + { + float elapsedTime = 0; + switch ( showTimeMode ) + { + case ( TimeMode.TimeScaleDependent ): + + yield return new WaitForSeconds ( time ); + + break; + + case ( TimeMode.NotTimeScaleDependent ): + + elapsedTime = 0; + while ( elapsedTime <= time ) + { + elapsedTime += DeltaTimeFor_SHOW; + yield return null; + } + + break; + } + } + + + protected IEnumerator WaitForSeconds_HIDE ( float time ) + { + switch ( hideTimeMode ) + { + case ( TimeMode.TimeScaleDependent ): + yield return new WaitForSeconds ( time ); + + break; + + case ( TimeMode.NotTimeScaleDependent ): + yield return new WaitForSecondsRealtime ( time ); + + break; + } + } + + protected IEnumerator EmptyCoroutine () + { + yield break; + } + + + //-------------------------------------------------------------------------------------------------------- + + + private enum ResetOptions + { + Zero = 0, One = 1 + } + } + + public enum AnimationType + { + Scale = 0, Rotate = 1, FadeColor = 2, Move = 3, MoveWithScale = 4 + } + + public enum AnimationStartPosition + { + Up = 0, UpCenter = 1, UpLeft = 2, UpRight = 3, + Left = 4, LeftCenter = 5, + Center = 6, + Bottom = 7, BottomCenter = 8, BottomLeft = 9, BottomRight = 10, + Right = 11, RightCenter = 12, + } + + public enum TimeMode + { + TimeScaleDependent = 0, NotTimeScaleDependent = 1 + } +} \ No newline at end of file diff --git a/Assets/Airy UI/Scripts/AnimatedElement.cs.meta b/Assets/Airy UI/Scripts/AnimatedElement.cs.meta new file mode 100644 index 00000000..ab93998e --- /dev/null +++ b/Assets/Airy UI/Scripts/AnimatedElement.cs.meta @@ -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 diff --git a/Assets/Airy UI/Scripts/AnimatedElementsGroup.cs b/Assets/Airy UI/Scripts/AnimatedElementsGroup.cs new file mode 100644 index 00000000..36a7ff56 --- /dev/null +++ b/Assets/Airy UI/Scripts/AnimatedElementsGroup.cs @@ -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 animatedElements = new List (); + + + [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 ( 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 (); + + GameObjectUtility.SetParentAndAlign ( newGameObject , menuCommand.context as GameObject ); + + Undo.RegisterCreatedObjectUndo ( newGameObject , "Create " + newGameObject.name ); + + Selection.activeObject = newGameObject; + } + + +#endif + + + } +} \ No newline at end of file diff --git a/Assets/Airy UI/Scripts/AnimatedElementsGroup.cs.meta b/Assets/Airy UI/Scripts/AnimatedElementsGroup.cs.meta new file mode 100644 index 00000000..e0c9697a --- /dev/null +++ b/Assets/Airy UI/Scripts/AnimatedElementsGroup.cs.meta @@ -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 diff --git a/Assets/Airy UI/Scripts/AnimationPositions.cs b/Assets/Airy UI/Scripts/AnimationPositions.cs new file mode 100644 index 00000000..88c7107e --- /dev/null +++ b/Assets/Airy UI/Scripts/AnimationPositions.cs @@ -0,0 +1,187 @@ +using UnityEngine; + +namespace AiryUI +{ + public class AnimationPositions : MonoBehaviour + { + + + /// + /// Used for initializing the position from a certian corner. + /// + /// the start position of the transform + /// the rect transform + /// BottomRight, UpRight, BottomLeft, UpLeft, Up, Bottom, Left, Or Right + /// Screen or Rect + /// + public static Vector3 GetStartPositionFromCorner + ( Vector3 initialPosition , RectTransform rectTransform , AnimationStartPosition animationStartPosition ) + { + float startPositionX = 0; + float startPositionY = 0; + + var containerCanvas = rectTransform.GetComponent ().containerCanvas; + var canvasRect = containerCanvas.GetComponent (); + + 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 ); + } + } +} \ No newline at end of file diff --git a/Assets/Airy UI/Scripts/AnimationPositions.cs.meta b/Assets/Airy UI/Scripts/AnimationPositions.cs.meta new file mode 100644 index 00000000..66266da6 --- /dev/null +++ b/Assets/Airy UI/Scripts/AnimationPositions.cs.meta @@ -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 diff --git a/Assets/Airy UI/Scripts/CloseButton.cs b/Assets/Airy UI/Scripts/CloseButton.cs new file mode 100644 index 00000000..ceb0c079 --- /dev/null +++ b/Assets/Airy UI/Scripts/CloseButton.cs @@ -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 ( "[Airy UI] X Affected Animated Element is null, please set it" , gameObject ); + return; + } + + affectedAnimatedElement.HideElement (); + } + else if ( backButtonAffects == BackButtonAffects.AnimatedElementsGroup ) + { + if ( affectedAnimatedElementsGroup == null ) + { + Debug.LogError ( "[Airy UI] X Affected Animated Elements Group is null, please set it" , gameObject ); + return; + } + + affectedAnimatedElementsGroup.HideGroup (); + } + } + + + } + + + public enum BackButtonAffects { AnimatedElement, AnimatedElementsGroup } + + +} \ No newline at end of file diff --git a/Assets/Airy UI/Scripts/CloseButton.cs.meta b/Assets/Airy UI/Scripts/CloseButton.cs.meta new file mode 100644 index 00000000..2e7da321 --- /dev/null +++ b/Assets/Airy UI/Scripts/CloseButton.cs.meta @@ -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 diff --git a/Assets/Airy UI/Scripts/CustomAnimatedElement.cs b/Assets/Airy UI/Scripts/CustomAnimatedElement.cs new file mode 100644 index 00000000..34f75490 --- /dev/null +++ b/Assets/Airy UI/Scripts/CustomAnimatedElement.cs @@ -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 TransformAnimationRecords_SHOW = new List(); + public List GraphicAnimationRecords_SHOW = new List(); + public List TransformAndGraphicAnimationRecords_SHOW = new List(); + + public List TransformAnimationRecords_HIDE = new List(); + public List GraphicAnimationRecords_HIDE = new List(); + public List TransformAndGraphicAnimationRecords_HIDE = new List(); + + [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(); + graphic = GetComponent(); + + 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(); + } + // else if (graphic is Text) + // { + // graphicType = GraphicType.Text; + // txt = GetComponent(); + // } + else if (graphic is TextMeshProUGUI) + { + graphicType = GraphicType.Text; + txt_m = GetComponent(); + } + + 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(); + graphic = gObject.GetComponent(); + + RecordValues(showOrHide, false); + } + + public void EnterRecordMode(GameObject gObject, AnimationShowOrHide showOrHide) + { + rectTransformComponent = gObject.GetComponent(); + graphic = gObject.GetComponent(); + + transformRecord_beforeRecrod = null; + graphicRecord_beforeRecrod = null; + transformAndGraphicRecord_beforeRecrod = null; + + RecordValues(showOrHide, true); + } + + public void ExitRecordMode(GameObject gObject, AnimationShowOrHide showOrHide) + { + rectTransformComponent = gObject.GetComponent(); + graphic = gObject.GetComponent(); + + 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().sprite = graphicRecord_beforeRecrod.Sprite; + else if (graphic is TextMeshProUGUI) + gObject.GetComponent().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().sprite = transformAndGraphicRecord_beforeRecrod.Sprite; + else if (graphic is TextMeshProUGUI) + gObject.GetComponent().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; + } +} \ No newline at end of file diff --git a/Assets/Airy UI/Scripts/CustomAnimatedElement.cs.meta b/Assets/Airy UI/Scripts/CustomAnimatedElement.cs.meta new file mode 100644 index 00000000..08a956e7 --- /dev/null +++ b/Assets/Airy UI/Scripts/CustomAnimatedElement.cs.meta @@ -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 diff --git a/Assets/Airy UI/Scripts/EscButtonController.cs b/Assets/Airy UI/Scripts/EscButtonController.cs new file mode 100644 index 00000000..188a633b --- /dev/null +++ b/Assets/Airy UI/Scripts/EscButtonController.cs @@ -0,0 +1,77 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + + +namespace AiryUI +{ + + + public class EscButtonController : MonoBehaviour + { + + + public List esc_buttons = new List (); + + + 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 ( "[Airy UI] X there's a missing item in 'ESC Button Controller', 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 ); + } + } + + + } + + +} \ No newline at end of file diff --git a/Assets/Airy UI/Scripts/EscButtonController.cs.meta b/Assets/Airy UI/Scripts/EscButtonController.cs.meta new file mode 100644 index 00000000..d8cff7cc --- /dev/null +++ b/Assets/Airy UI/Scripts/EscButtonController.cs.meta @@ -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 diff --git a/Assets/Airy UI/Scripts/EscCloseButton.cs b/Assets/Airy UI/Scripts/EscCloseButton.cs new file mode 100644 index 00000000..b0aa4bfc --- /dev/null +++ b/Assets/Airy UI/Scripts/EscCloseButton.cs @@ -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 ( "[Airy UI] X 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 ( "[Airy UI] X 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 (); + + 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 () ) + { + GameObject controller = new GameObject ( "[Airy UI] Esc Button Controller" ); + controller.AddComponent (); + } + } + + +#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 (); + + GameObjectUtility.SetParentAndAlign ( newGameObject , menuCommand.context as GameObject ); + + Undo.RegisterCreatedObjectUndo ( newGameObject , "Create " + newGameObject.name ); + + Selection.activeObject = newGameObject; + } + + +#endif + + + } +} \ No newline at end of file diff --git a/Assets/Airy UI/Scripts/EscCloseButton.cs.meta b/Assets/Airy UI/Scripts/EscCloseButton.cs.meta new file mode 100644 index 00000000..851b8791 --- /dev/null +++ b/Assets/Airy UI/Scripts/EscCloseButton.cs.meta @@ -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 diff --git a/Assets/Airy UI/Scripts/UICloseButton.cs b/Assets/Airy UI/Scripts/UICloseButton.cs new file mode 100644 index 00000000..61b9fb65 --- /dev/null +++ b/Assets/Airy UI/Scripts/UICloseButton.cs @@ -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