├── Assets ├── UnityActions │ ├── Scene │ │ ├── TestActions.unity │ │ ├── UITestActions.unity │ │ ├── TestActions.unity.meta │ │ └── UITestActions.unity.meta │ ├── Scene.meta │ ├── Scripts.meta │ └── Scripts │ │ ├── Actions.meta │ │ ├── TestCases.meta │ │ ├── Actions │ │ ├── BaseAction.cs │ │ ├── UISettings.cs │ │ ├── Actor.cs.meta │ │ ├── Action.cs.meta │ │ ├── BaseAction.cs.meta │ │ ├── EaseAction.cs.meta │ │ ├── ScaleTo.cs.meta │ │ ├── UIFadeIn.cs.meta │ │ ├── UIFadeOut.cs.meta │ │ ├── UIFadeTo.cs.meta │ │ ├── UISettings.cs.meta │ │ ├── ActionInstant.cs.meta │ │ ├── ActionInterval.cs.meta │ │ ├── ActionRunner.cs.meta │ │ ├── TweenFunctions.cs.meta │ │ ├── UImageFadeTo.cs.meta │ │ ├── ScaleTo.cs │ │ ├── ActionRunner.cs │ │ ├── UImageFadeTo.cs │ │ ├── Action.cs │ │ ├── UIFadeTo.cs │ │ ├── UIFadeIn.cs │ │ ├── Actor.cs │ │ ├── UIFadeOut.cs │ │ ├── ActionInstant.cs │ │ ├── TweenFunctions.cs │ │ ├── ActionInterval.cs │ │ └── EaseAction.cs │ │ └── TestCases │ │ ├── TestUI.cs.meta │ │ ├── TestActions.cs.meta │ │ ├── TestUI.cs │ │ └── TestActions.cs └── UnityActions.meta ├── .gitignore └── README.md /Assets/UnityActions/Scene/TestActions.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shakthi/UnityActions/HEAD/Assets/UnityActions/Scene/TestActions.unity -------------------------------------------------------------------------------- /Assets/UnityActions/Scene/UITestActions.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shakthi/UnityActions/HEAD/Assets/UnityActions/Scene/UITestActions.unity -------------------------------------------------------------------------------- /Assets/UnityActions/Scene/TestActions.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6cb53cf94b35c4b05b9db125719078fa 3 | timeCreated: 1436873372 4 | licenseType: Free 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/UnityActions/Scene/UITestActions.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d4050ac9f785548dfad6542cd397d820 3 | timeCreated: 1486923646 4 | licenseType: Free 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/UnityActions.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c4f9db8bce01a452e9493bd4079f5756 3 | folderAsset: yes 4 | timeCreated: 1487397963 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/UnityActions/Scene.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9ab7be914f25a492b99103580f69a391 3 | folderAsset: yes 4 | timeCreated: 1436873378 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/UnityActions/Scripts.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ab3af2344f167422aa09bf009c8e7106 3 | folderAsset: yes 4 | timeCreated: 1436873386 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/UnityActions/Scripts/Actions.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 23132efa0bcfa4af9bceb160ac82b928 3 | folderAsset: yes 4 | timeCreated: 1436873451 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/UnityActions/Scripts/TestCases.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 873fa7edace28460594457d30e93c562 3 | folderAsset: yes 4 | timeCreated: 1436873908 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/UnityActions/Scripts/Actions/BaseAction.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections.Generic; 3 | 4 | 5 | 6 | namespace CC 7 | { 8 | 9 | public class BaseAction 10 | { 11 | protected const float epsilon = 1.192092896e-07F; 12 | 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Assets/UnityActions/Scripts/Actions/UISettings.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | 5 | //TODO: Remove this file 6 | namespace CC 7 | { 8 | public enum UISetup 9 | { 10 | noUIObject = 0, 11 | canvasRenderer = 1, 12 | canvasGroup = 2 13 | } 14 | } -------------------------------------------------------------------------------- /Assets/UnityActions/Scripts/Actions/Actor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cc8320165bac94ccea2209b0d7bfb374 3 | timeCreated: 1437353674 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/UnityActions/Scripts/Actions/Action.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5acc06cd4410b44088ba63765d037e84 3 | timeCreated: 1437099286 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/UnityActions/Scripts/Actions/BaseAction.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 491545b439b874e1bbcd492e529e08e3 3 | timeCreated: 1436873687 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/UnityActions/Scripts/Actions/EaseAction.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f1c9f41d2adc8491e8fd318411c3f44a 3 | timeCreated: 1467450577 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/UnityActions/Scripts/Actions/ScaleTo.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 89a2f7dd6132f024f89d7898fd2a640c 3 | timeCreated: 1481243283 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/UnityActions/Scripts/Actions/UIFadeIn.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5fdea2916230e4e3aa89e9aec5cab4f2 3 | timeCreated: 1486923650 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/UnityActions/Scripts/Actions/UIFadeOut.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b9b2d4b1a890a4eed89840a85baf45b1 3 | timeCreated: 1486923650 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/UnityActions/Scripts/Actions/UIFadeTo.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c54840935b5bb4ea796e8e838dc15f15 3 | timeCreated: 1486923650 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/UnityActions/Scripts/Actions/UISettings.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 74cc416d10d2d4898bc2c5439dc41e8b 3 | timeCreated: 1486923675 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/UnityActions/Scripts/TestCases/TestUI.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0ad87d164fe2742769208a9ba64ebcbf 3 | timeCreated: 1486923649 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/UnityActions/Scripts/Actions/ActionInstant.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8e93a5d2eeed343b6a3e5831eddce1fd 3 | timeCreated: 1467442587 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/UnityActions/Scripts/Actions/ActionInterval.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3fff040811ffb4ca9902c213acd1e2e3 3 | timeCreated: 1437099324 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/UnityActions/Scripts/Actions/ActionRunner.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 69a787124531d4986823e785fca37578 3 | timeCreated: 1437100556 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/UnityActions/Scripts/Actions/TweenFunctions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8eb4fd261f6d74eea9d98c2d19090002 3 | timeCreated: 1467471742 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/UnityActions/Scripts/Actions/UImageFadeTo.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c13b9edd3a6dd4836b107549073fbb35 3 | timeCreated: 1486923675 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/UnityActions/Scripts/TestCases/TestActions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4f6ecf733f15e468c82e96fa8b8f7ff3 3 | timeCreated: 1436873935 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | [Ll]ibrary/ 2 | [Tt]emp/ 3 | [Oo]bj/ 4 | [Bb]uild/ 5 | 6 | # Autogenerated VS/MD solution and project files 7 | *.csproj 8 | *.unityproj 9 | *.sln 10 | *.suo 11 | *.tmp 12 | *.user 13 | *.userprefs 14 | *.pidb 15 | *.booproj 16 | 17 | # Unity3D generated meta files 18 | *.pidb.meta 19 | 20 | # Unity3D Generated File On Crash Reports 21 | sysinfo.txt 22 | ProjectSettings 23 | -------------------------------------------------------------------------------- /Assets/UnityActions/Scripts/TestCases/TestUI.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEngine.UI; 3 | using System.Collections; 4 | 5 | using CC; 6 | 7 | public class TestUI : MonoBehaviour 8 | { 9 | public Transform textTest; 10 | // Use this for initialization 11 | void Start() 12 | { 13 | Sequence q = new Sequence(new UIFadeTo(0.8f,0.5f),new UIFadeTo(0.5f,1.0f) ); 14 | Action.Run(textTest,new RepeatForever (q) ); 15 | 16 | //Actor anActor = Actor.GetActor(textTest); 17 | //anActor.UIFadeOut(1.0f); 18 | } 19 | 20 | // Update is called once per frame 21 | void Update() 22 | { 23 | 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Assets/UnityActions/Scripts/Actions/ScaleTo.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using System; 4 | 5 | namespace CC 6 | { 7 | 8 | public class ScaleTo : ActionInterval 9 | { 10 | protected float startScale; 11 | 12 | protected float endScale_x; 13 | protected float endScale_y; 14 | protected float endScale_z; 15 | 16 | protected Vector3 _startScale; 17 | protected Vector3 _endScale; 18 | 19 | public ScaleTo(float duration, float scaleTo): base(duration) 20 | { 21 | _endScale = new Vector3(scaleTo, scaleTo, scaleTo); 22 | } 23 | public override Action Clone() 24 | { 25 | throw new NotImplementedException(); 26 | } 27 | 28 | public override void LerpAction(float delta) 29 | { 30 | target.localScale = Vector3.Lerp(_startScale,_endScale,delta); 31 | } 32 | 33 | public override Action Reverse() 34 | { 35 | throw new NotImplementedException(); 36 | } 37 | 38 | public override void StartWithTarget(Transform inTarget) 39 | { 40 | base.StartWithTarget(inTarget); 41 | _startScale = inTarget.localScale; 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /Assets/UnityActions/Scripts/Actions/ActionRunner.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections.Generic; 3 | 4 | 5 | 6 | namespace CC 7 | { 8 | 9 | class ActionRunner:MonoBehaviour 10 | { 11 | 12 | 13 | 14 | 15 | 16 | public List actionsToRun; 17 | 18 | void Update() 19 | { 20 | 21 | for(int i=0;i(); 54 | if(runner == null) 55 | { 56 | runner = inTarget.gameObject.AddComponent(); 57 | runner.actionsToRun = new List(); 58 | } 59 | runner.actionsToRun.Add(anAction); 60 | 61 | 62 | 63 | } 64 | 65 | 66 | } 67 | 68 | 69 | 70 | 71 | 72 | 73 | } 74 | -------------------------------------------------------------------------------- /Assets/UnityActions/Scripts/Actions/UImageFadeTo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using UnityEngine; 6 | 7 | namespace CC 8 | { 9 | public class UImageFadeTo : ActionInterval 10 | { 11 | private float startAlpha; 12 | private float endAlpha; 13 | private UnityEngine.UI.Image image; 14 | public UImageFadeTo(float duration, float alphaEnd) : base(duration) 15 | { 16 | this.duration = duration; 17 | this.endAlpha = alphaEnd; 18 | } 19 | 20 | public override Action Clone() 21 | { 22 | throw new NotImplementedException(); 23 | } 24 | 25 | public override void LerpAction(float delta) 26 | { 27 | Color c = image.color; 28 | c.a = Mathf.Lerp(startAlpha, endAlpha, delta); 29 | image.color = c; 30 | } 31 | 32 | public override Action Reverse() 33 | { 34 | throw new NotImplementedException(); 35 | } 36 | 37 | public override void StartWithTarget(Transform inTarget) 38 | { 39 | base.StartWithTarget(inTarget); 40 | if (inTarget.GetComponent() != null) 41 | { 42 | image = inTarget.GetComponent(); 43 | startAlpha = image.color.a; 44 | Debug.Log("Breakpoint Tracking"); 45 | } 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Assets/UnityActions/Scripts/Actions/Action.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace CC 4 | { 5 | 6 | 7 | public abstract class Action : BaseAction 8 | { 9 | protected Transform target; 10 | bool isStarted; 11 | 12 | 13 | public bool IsStarted() 14 | { 15 | return isStarted; 16 | } 17 | 18 | 19 | public static void Run(Transform targetTransform ,Action anAction) 20 | { 21 | ActionRunner.Setup(targetTransform,anAction); 22 | } 23 | 24 | public abstract void LerpAction(float delta); 25 | 26 | public abstract void Update(float delta); 27 | 28 | public virtual void StartWithTarget(Transform inTarget) 29 | { 30 | target = inTarget; 31 | isStarted = true; 32 | } 33 | 34 | public virtual void Stop() 35 | { 36 | target = null; 37 | } 38 | 39 | public virtual bool IsDone() 40 | { 41 | return true; 42 | } 43 | 44 | 45 | 46 | 47 | 48 | /** Returns a new action that performs the exactly the reverse action. 49 | * 50 | * @return A new action that performs the exactly the reverse action. 51 | */ 52 | public abstract Action Reverse() ; 53 | 54 | 55 | public abstract Action Clone(); 56 | 57 | } 58 | 59 | 60 | /** @class FiniteTimeAction 61 | * @brief 62 | * Base class actions that do have a finite time duration. 63 | * Possible actions: 64 | * - An action with a duration of 0 seconds. 65 | * - An action with a duration of 35.5 seconds. 66 | * Infinite time actions are valid. 67 | */ 68 | 69 | public abstract class FiniteTimeAction : Action 70 | { 71 | protected float duration; 72 | 73 | public float GetDuration() 74 | { 75 | return duration; 76 | } 77 | 78 | public FiniteTimeAction(float aduration) 79 | { 80 | duration = aduration; 81 | } 82 | 83 | 84 | 85 | 86 | 87 | } 88 | 89 | } 90 | 91 | -------------------------------------------------------------------------------- /Assets/UnityActions/Scripts/Actions/UIFadeTo.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using System; 4 | 5 | namespace CC 6 | { 7 | public class UIFadeTo : ActionInterval 8 | { 9 | private float startAlpha; 10 | private float endAlpha; 11 | private CanvasRenderer canvasRenderer; 12 | private CanvasGroup canvasGroup; 13 | private UISetup UIMode; 14 | 15 | public UIFadeTo(float duration = 1.0f, float alphaEndp = 0.5f) : base(duration) 16 | { 17 | endAlpha = alphaEndp; 18 | } 19 | 20 | public override CC.Action Reverse() 21 | { 22 | throw new System.NotImplementedException(); 23 | } 24 | 25 | public override CC.Action Clone() 26 | { 27 | throw new System.NotImplementedException(); 28 | } 29 | 30 | public override void LerpAction(float delta) 31 | { 32 | if (UIMode == UISetup.canvasRenderer) 33 | { 34 | canvasRenderer.SetAlpha(Mathf.Lerp(startAlpha, endAlpha, delta)); 35 | } 36 | else if (UIMode == UISetup.canvasGroup) 37 | { 38 | canvasGroup.alpha = Mathf.Lerp(startAlpha, endAlpha, delta); 39 | } 40 | } 41 | 42 | public override void StartWithTarget(Transform inTarget) 43 | { 44 | base.StartWithTarget(inTarget); 45 | if (inTarget.GetComponent() != null) 46 | { 47 | UIMode = UISetup.canvasRenderer; 48 | canvasRenderer = inTarget.GetComponent(); 49 | startAlpha = canvasRenderer.GetAlpha(); 50 | } 51 | else if (inTarget.GetComponent() != null) 52 | { 53 | UIMode = UISetup.canvasGroup; 54 | canvasGroup = inTarget.GetComponent(); 55 | startAlpha = canvasGroup.alpha; 56 | } 57 | else 58 | { 59 | Debug.LogError("This object doesn't have CanvasRenderer or CanvasGroup"); 60 | } 61 | } 62 | } 63 | } -------------------------------------------------------------------------------- /Assets/UnityActions/Scripts/Actions/UIFadeIn.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | namespace CC 5 | { 6 | /* 7 | *@class UIFadeIn. 8 | *@brief This class will make the effect of the fadeIn on the UI elements. 9 | * Warning this cannot be used in 3D objects 10 | */ 11 | public class UIFadeIn : ActionInterval 12 | { 13 | private float startAlpha = 0.0f;//TODO: 14 | private float endAlpha = 1.0f; 15 | private CanvasRenderer canvasRenderer; 16 | private CanvasGroup canvasGroup; 17 | private UISetup UIMode; 18 | 19 | //By default this will be 1 second 20 | public UIFadeIn(float duration = 1.0f) : base(duration) 21 | { 22 | 23 | } 24 | 25 | public override Action Reverse() 26 | { 27 | return null; 28 | } 29 | 30 | public override Action Clone() 31 | { 32 | return null; 33 | } 34 | 35 | public override void LerpAction(float delta) 36 | { 37 | if (UIMode == UISetup.canvasRenderer) 38 | { 39 | canvasRenderer.SetAlpha(Mathf.Lerp(startAlpha, endAlpha, delta)); 40 | } 41 | else if (UIMode == UISetup.canvasGroup) 42 | { 43 | canvasGroup.alpha = Mathf.Lerp(startAlpha, endAlpha, delta); 44 | } 45 | } 46 | 47 | public override void StartWithTarget(Transform inTarget) 48 | { 49 | base.StartWithTarget(inTarget); 50 | if (inTarget.GetComponent() != null) 51 | { 52 | UIMode = UISetup.canvasRenderer; 53 | canvasRenderer = inTarget.GetComponent(); 54 | canvasRenderer.SetAlpha(0.0f); 55 | } 56 | else if (inTarget.GetComponent() != null) 57 | { 58 | UIMode = UISetup.canvasGroup; 59 | canvasGroup = inTarget.GetComponent(); 60 | canvasGroup.alpha = 0.0f; 61 | } 62 | else 63 | { 64 | Debug.LogError("This object doesn't have CanvasRenderer or CanvasGroup"); 65 | } 66 | } 67 | } 68 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Unity Actions 2 | 3 | Unity Actions is a port of Cocos2d actions to unity. 4 | 5 | Actions are one of the powerfull feature of cocos2d that I always missed in Unity3d. I never satisfied with iTween or related library. This code line by line port of original cocos2d (Cosos2d-X actually) code. 6 | 7 | With actions, making an animation may not be simpler than this. 8 | ```c# 9 | Action.Run(aTransform,new MoveBy(10,new Vector3(10,1,1))); 10 | ``` 11 | Above code move/transforms 'aTransform' by Vector3(10,1,1) units in 10 seconds. Now this is basic one, more complex example follows. 12 | ```c# 13 | Sequence seq= new Sequence(new MoveBy(3,new Vector3(10,1,1)), 14 | new RotateBy(5,new Vector3(180,0,0)), 15 | new MoveBy(3,new Vector3(-10,1,1)), 16 | new RotateBy(3,new Vector3(0,60,0)) 17 | ); 18 | 19 | Action.Run(movingObject, new Repeat(seq,2)); 20 | 21 | ``` 22 | That must be self-explanatory. 23 | 24 | # Welcome Actors! 25 | Power of cocos2d actions and Unity3d coroutines can be nicely combined to produce yet more powerfull feature called **Actors**. Right now it can be thought as syntax sugar over action. 26 | 27 | ```c# 28 | public Transform movingObject; 29 | 30 | IEnumerator anAnimation() 31 | { 32 | Actor anActor = Actor.GetActor(movingObject); 33 | yield return anActor.MoveBy(3,new Vector3(10,10,10)); 34 | 35 | Debug.Log("Now cube must be at the top of the screen"); 36 | 37 | yield return anActor.MoveTo(4,new Vector3(0,0,0)); 38 | 39 | Debug.Log("Both the action completed now. Must be completed at 4+3=7 seconds"); 40 | } 41 | 42 | void Start() 43 | { 44 | StartCoroutine(anAnimation()); 45 | } 46 | ``` 47 | Code you see here is *actually* part of **Actor** testcase! Isn't it intutive, and as simple as *screenwriting*. 48 | ## Contribution 49 | There is a lot of sugar in cocos2d in waiting to be ported to Unity3d! All contribution are eagerly accepted. 50 | ## Todos 51 | 52 | - Write Testcases 53 | - Port CCInstantActions,CCTransitions... 54 | - Add Code Comments 55 | 56 | 57 | ## License 58 | Apache License 59 | --- 60 | **Free Software, Hell Yeah!** -- hehe markdown forked from http://dillinger.io 61 | 62 | 63 | - [Cocos2d iphone project ](https://github.com/cocos2d/cocos2d-objc) 64 | - [Cosco2d-X project](https://github.com/cocos2d/cocos2d-x) 65 | 66 | -------------------------------------------------------------------------------- /Assets/UnityActions/Scripts/Actions/Actor.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | 5 | namespace CC 6 | { 7 | 8 | 9 | 10 | public class Actor:MonoBehaviour { 11 | 12 | public FiniteTimeAction action; 13 | 14 | 15 | 16 | static public Actor GetActor(Transform intransform) 17 | { 18 | Actor actor = intransform.GetComponent(); 19 | if(actor == null) 20 | { 21 | actor = intransform.gameObject.AddComponent(); 22 | } 23 | 24 | return actor; 25 | } 26 | 27 | 28 | 29 | 30 | 31 | 32 | public IEnumerator YieldAction(FiniteTimeAction anAction) 33 | { 34 | if(action !=null) 35 | Debug.LogError("An action is already running"); 36 | else 37 | { 38 | action = anAction; 39 | 40 | Action.Run(transform,action); 41 | yield return new WaitForSeconds(action.GetDuration()); 42 | while(!action.IsDone()) 43 | { 44 | yield return null; 45 | } 46 | action=null; 47 | } 48 | 49 | 50 | } 51 | 52 | 53 | public Coroutine PerformAction(FiniteTimeAction anAction) 54 | { 55 | return StartCoroutine(YieldAction(anAction)); 56 | } 57 | 58 | public Coroutine Sequence(params FiniteTimeAction[] list) 59 | { 60 | return PerformAction(new CC.Sequence(list)); 61 | } 62 | 63 | public Coroutine Spawn(params FiniteTimeAction[] list) 64 | { 65 | return PerformAction(new CC.Spawn(list)); 66 | } 67 | 68 | public Coroutine MoveBy(float aduration,Vector3 diff) 69 | { 70 | return PerformAction(new CC.MoveBy(aduration,diff)); 71 | } 72 | 73 | public Coroutine MoveTo(float duraction,Vector3 targetPos) 74 | { 75 | return PerformAction(new CC.MoveTo(duraction,targetPos)); 76 | } 77 | 78 | } 79 | 80 | public static class ActorExtensions { 81 | 82 | public static Coroutine RunAction(this MonoBehaviour component, FiniteTimeAction action) { 83 | return Actor.GetActor (component.transform).PerformAction (action); 84 | } 85 | 86 | public static Coroutine RunSequence(this MonoBehaviour component, params FiniteTimeAction[] actions) { 87 | return Actor.GetActor (component.transform).Sequence (actions); 88 | } 89 | 90 | public static Coroutine RunSpawn(this MonoBehaviour component, params FiniteTimeAction[] actions) { 91 | return Actor.GetActor (component.transform).Spawn (actions); 92 | } 93 | 94 | } 95 | 96 | } -------------------------------------------------------------------------------- /Assets/UnityActions/Scripts/Actions/UIFadeOut.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEngine.UI; 3 | using System.Collections; 4 | 5 | 6 | 7 | namespace CC 8 | { 9 | /// 10 | /// Class UIFadeOut. Class that makes the action of fading a Canvas Group. 11 | /// Warning This only works with UI elements, do not use 3D elements 12 | /// 13 | /// Longer comments can be associated with a type or member 14 | /// through the remarks tag 15 | public class UIFadeOut : ActionInterval 16 | { 17 | private float startAlpha = 1.0f; 18 | private float endAlpha = 0.0f; 19 | private CanvasRenderer canvasRenderer; 20 | private CanvasGroup canvasGroup; 21 | private UISetup UIMode; 22 | 23 | /// 24 | /// The class constructor. 25 | public UIFadeOut(float duration = 1.0f) : base(duration) 26 | { 27 | 28 | } 29 | 30 | public override Action Reverse() 31 | { 32 | return null; 33 | } 34 | 35 | public override Action Clone() 36 | { 37 | return null; 38 | } 39 | 40 | public override void LerpAction(float delta) 41 | { 42 | if (UIMode == UISetup.canvasRenderer) 43 | { 44 | canvasRenderer.SetAlpha(Mathf.Lerp(startAlpha, endAlpha, delta)); 45 | } 46 | else if (UIMode == UISetup.canvasGroup) 47 | { 48 | canvasGroup.alpha = Mathf.Lerp(startAlpha, endAlpha, delta); 49 | } 50 | } 51 | 52 | public override void StartWithTarget(Transform inTarget) 53 | { 54 | base.StartWithTarget(inTarget); 55 | if (inTarget.GetComponent() != null) 56 | { 57 | UIMode = UISetup.canvasRenderer; 58 | canvasRenderer = inTarget.GetComponent(); 59 | canvasRenderer.SetAlpha(1.0f); 60 | } 61 | else if (inTarget.GetComponent() != null) 62 | { 63 | UIMode = UISetup.canvasGroup; 64 | canvasGroup = inTarget.GetComponent(); 65 | canvasGroup.alpha = 1.0f; 66 | } 67 | else 68 | { 69 | Debug.LogError("This object doesn't have CanvasRenderer or CanvasGroup"); 70 | } 71 | } 72 | } 73 | } -------------------------------------------------------------------------------- /Assets/UnityActions/Scripts/TestCases/TestActions.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using CC; 4 | 5 | public class TestActions : MonoBehaviour 6 | { 7 | public Transform movingObject; 8 | 9 | 10 | IEnumerator anAnimation() 11 | { 12 | Actor anActor = Actor.GetActor(movingObject); 13 | yield return anActor.MoveBy(3,new Vector3(10,10,10)); 14 | 15 | Debug.Log("Now cube must be at the top of the screen"); 16 | 17 | 18 | yield return anActor.MoveTo(4,new Vector3(0,0,0)); 19 | 20 | Debug.Log("Both the action completed now must be completed at 4+3=7 seconds"); 21 | 22 | } 23 | 24 | 25 | IEnumerator ShowDemo() 26 | { 27 | Debug.Log(" exicuting sequence and with ease actions "); 28 | ResetMovingObject(); 29 | Sequence q2= new Sequence(new EaseOut( new MoveBy(3 ,new Vector3(3,1,1)),0.2f), 30 | new EaseExponentialInOut(new RotateBy(5,new Vector3(180,0,0))), 31 | new MoveBy(3 ,new Vector3(-3,1,1)), 32 | new EaseBounceIn(new RotateBy(3,new Vector3(0,60,0))) 33 | 34 | ); 35 | Action.Run(movingObject, new Repeat(q2,2)); 36 | yield return new WaitForSeconds(30); 37 | 38 | 39 | yield return StartCoroutine(anAnimation()); 40 | 41 | Debug.Log("Actor demo done. Now exicuting two actions parallely "); 42 | 43 | Action.Run(movingObject,new MoveBy(10 ,new Vector3(10,1,1))); 44 | Action.Run(movingObject,new RotateBy(5,new Vector3(180,0,0))); 45 | 46 | yield return new WaitForSeconds(11); 47 | 48 | 49 | 50 | Debug.Log(" Now exicuting sequence and repeat-2 actions "); 51 | ResetMovingObject(); 52 | Sequence q= new Sequence(new MoveBy(3 ,new Vector3(3,1,1)), 53 | new RotateBy(5,new Vector3(180,0,0)), 54 | new MoveBy(3 ,new Vector3(-3,1,1)), 55 | new RotateBy(3,new Vector3(0,60,0)) 56 | 57 | ); 58 | Action.Run(movingObject, new Repeat(q,2)); 59 | yield return new WaitForSeconds(30); 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | Debug.Log(" Now exicuting Spawn actions "); 68 | ResetMovingObject(); 69 | Action.Run(movingObject,new Spawn(new MoveBy(10 ,new Vector3(2,1,1)),new MoveBy(10,new Vector3(0,3,0)),new RotateBy(10,new Vector3(0,180,0)))); 70 | yield return new WaitForSeconds(10); 71 | 72 | 73 | Debug.Log(" All tests are completed "); 74 | 75 | 76 | 77 | } 78 | 79 | Vector3 originalPosition; 80 | Quaternion originalRotation; 81 | Vector3 originalScale; 82 | 83 | void ResetMovingObject() 84 | { 85 | movingObject.position=originalPosition; 86 | movingObject.rotation=originalRotation; 87 | movingObject.localScale=originalScale; 88 | } 89 | 90 | 91 | void Start () 92 | { 93 | 94 | originalPosition=movingObject.position; 95 | originalRotation=movingObject.rotation; 96 | originalScale=movingObject.localScale; 97 | 98 | StartCoroutine(ShowDemo()); 99 | 100 | } 101 | 102 | } 103 | -------------------------------------------------------------------------------- /Assets/UnityActions/Scripts/Actions/ActionInstant.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | namespace CC 5 | { 6 | /** 7 | @brief Instant actions are immediate actions. They don't have a duration like 8 | the CCIntervalAction actions. 9 | */ 10 | 11 | public abstract class ActionInstant : FiniteTimeAction 12 | { 13 | bool completed = false; 14 | 15 | 16 | public override bool IsDone() 17 | { 18 | return completed; 19 | } 20 | 21 | public ActionInstant():base(0) 22 | { 23 | 24 | } 25 | 26 | 27 | public override void Update(float delta) 28 | { 29 | LerpAction(1f); 30 | completed = true; 31 | } 32 | 33 | public abstract void DoAction(); 34 | 35 | public override void LerpAction(float delta) 36 | { 37 | DoAction(); 38 | 39 | } 40 | 41 | 42 | } 43 | 44 | public class Show : ActionInstant 45 | { 46 | 47 | public override void DoAction() 48 | { 49 | 50 | target.GetComponent().enabled = true; 51 | 52 | } 53 | 54 | public override Action Clone() 55 | { 56 | return new Show(); 57 | } 58 | 59 | public override Action Reverse() 60 | { 61 | return new Hide(); 62 | } 63 | 64 | 65 | } 66 | 67 | 68 | 69 | public class Hide : ActionInstant 70 | { 71 | 72 | public override void DoAction() 73 | { 74 | 75 | target.GetComponent().enabled = false; 76 | 77 | } 78 | 79 | public override Action Clone() 80 | { 81 | return new Hide(); 82 | } 83 | 84 | public override Action Reverse() 85 | { 86 | return new Show(); 87 | } 88 | 89 | 90 | } 91 | 92 | 93 | public class ToggleVisiblilty : ActionInstant 94 | { 95 | 96 | public override void DoAction() 97 | { 98 | 99 | target.GetComponent().enabled = !target.GetComponent().enabled; 100 | 101 | } 102 | 103 | public override Action Clone() 104 | { 105 | return new ToggleVisiblilty(); 106 | } 107 | 108 | public override Action Reverse() 109 | { 110 | return new ToggleVisiblilty(); 111 | } 112 | 113 | 114 | } 115 | 116 | public class RemoveSelf : ActionInstant 117 | { 118 | public override Action Clone() 119 | { 120 | return new RemoveSelf(); 121 | } 122 | 123 | public override Action Reverse() 124 | { 125 | return new RemoveSelf(); 126 | } 127 | 128 | public override void DoAction() 129 | { 130 | GameObject.Destroy(target.gameObject); 131 | 132 | } 133 | 134 | 135 | 136 | } 137 | 138 | 139 | 140 | public class Place : ActionInstant 141 | { 142 | Vector3 targetPosition; 143 | 144 | public Place(Vector3 position) 145 | { 146 | targetPosition = position; 147 | } 148 | public override Action Clone() 149 | { 150 | return new Place(targetPosition); 151 | } 152 | 153 | public override Action Reverse() 154 | { 155 | return new Place(targetPosition); 156 | } 157 | 158 | public override void DoAction() 159 | { 160 | target.position = targetPosition; 161 | 162 | } 163 | 164 | 165 | 166 | } 167 | 168 | 169 | 170 | 171 | public class FlipX : ActionInstant 172 | { 173 | bool flip=false; 174 | 175 | public FlipX(bool isFlip) 176 | { 177 | flip = isFlip; 178 | } 179 | public override Action Clone() 180 | { 181 | return new FlipX(flip); 182 | } 183 | 184 | public override Action Reverse() 185 | { 186 | return new FlipX(!flip); 187 | } 188 | 189 | public override void DoAction() 190 | { 191 | target.GetComponent().flipX = flip; 192 | 193 | } 194 | 195 | 196 | 197 | } 198 | 199 | 200 | public class FlipY : ActionInstant 201 | { 202 | bool flip=false; 203 | 204 | public FlipY(bool isFlip) 205 | { 206 | flip = isFlip; 207 | } 208 | public override Action Clone() 209 | { 210 | return new FlipY(flip); 211 | } 212 | 213 | public override Action Reverse() 214 | { 215 | return new FlipY(!flip); 216 | } 217 | 218 | public override void DoAction() 219 | { 220 | target.GetComponent().flipY = flip; 221 | 222 | } 223 | 224 | 225 | 226 | } 227 | 228 | 229 | 230 | public class Call : ActionInstant 231 | { 232 | public delegate void CallDelegate(Transform atransform); 233 | CallDelegate function; 234 | 235 | public Call(CallDelegate aFunction) 236 | { 237 | function = aFunction; 238 | } 239 | public override Action Clone() 240 | { 241 | return new Call(function); 242 | } 243 | 244 | public override Action Reverse() 245 | { 246 | return new Call(function); 247 | } 248 | 249 | public override void DoAction() 250 | { 251 | function(target); 252 | } 253 | 254 | 255 | 256 | } 257 | 258 | 259 | 260 | } 261 | 262 | -------------------------------------------------------------------------------- /Assets/UnityActions/Scripts/Actions/TweenFunctions.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | namespace CC 5 | { 6 | 7 | static public class tweenfunc { 8 | 9 | public enum TweenType 10 | { 11 | CUSTOM_EASING = -1, 12 | 13 | Linear, 14 | 15 | Sine_EaseIn, 16 | Sine_EaseOut, 17 | Sine_EaseInOut, 18 | 19 | 20 | Quad_EaseIn, 21 | Quad_EaseOut, 22 | Quad_EaseInOut, 23 | 24 | Cubic_EaseIn, 25 | Cubic_EaseOut, 26 | Cubic_EaseInOut, 27 | 28 | Quart_EaseIn, 29 | Quart_EaseOut, 30 | Quart_EaseInOut, 31 | 32 | Quint_EaseIn, 33 | Quint_EaseOut, 34 | Quint_EaseInOut, 35 | 36 | Expo_EaseIn, 37 | Expo_EaseOut, 38 | Expo_EaseInOut, 39 | 40 | Circ_EaseIn, 41 | Circ_EaseOut, 42 | Circ_EaseInOut, 43 | 44 | Elastic_EaseIn, 45 | Elastic_EaseOut, 46 | Elastic_EaseInOut, 47 | 48 | Back_EaseIn, 49 | Back_EaseOut, 50 | Back_EaseInOut, 51 | 52 | Bounce_EaseIn, 53 | Bounce_EaseOut, 54 | Bounce_EaseInOut, 55 | 56 | TWEEN_EASING_MAX = 10000 57 | }; 58 | 59 | 60 | 61 | 62 | public static float tweenTo(float time, TweenType type, float[] easingParam) 63 | { 64 | float delta = 0; 65 | 66 | switch (type) 67 | { 68 | case TweenType.CUSTOM_EASING: 69 | delta = customEase(time, easingParam); 70 | break; 71 | 72 | case TweenType.Linear: 73 | delta = linear(time); 74 | break; 75 | 76 | case TweenType.Sine_EaseIn: 77 | delta = sineEaseIn(time); 78 | break; 79 | case TweenType.Sine_EaseOut: 80 | delta = sineEaseOut(time); 81 | break; 82 | case TweenType.Sine_EaseInOut: 83 | delta = sineEaseInOut(time); 84 | break; 85 | 86 | case TweenType.Quad_EaseIn: 87 | delta = quadEaseIn(time); 88 | break; 89 | case TweenType.Quad_EaseOut: 90 | delta = quadEaseOut(time); 91 | break; 92 | case TweenType.Quad_EaseInOut: 93 | delta = quadEaseInOut(time); 94 | break; 95 | 96 | case TweenType.Cubic_EaseIn: 97 | delta = cubicEaseIn(time); 98 | break; 99 | case TweenType.Cubic_EaseOut: 100 | delta = cubicEaseOut(time); 101 | break; 102 | case TweenType.Cubic_EaseInOut: 103 | delta = cubicEaseInOut(time); 104 | break; 105 | 106 | case TweenType.Quart_EaseIn: 107 | delta = quartEaseIn(time); 108 | break; 109 | case TweenType.Quart_EaseOut: 110 | delta = quartEaseOut(time); 111 | break; 112 | case TweenType.Quart_EaseInOut: 113 | delta = quartEaseInOut(time); 114 | break; 115 | 116 | case TweenType.Quint_EaseIn: 117 | delta = quintEaseIn(time); 118 | break; 119 | case TweenType.Quint_EaseOut: 120 | delta = quintEaseOut(time); 121 | break; 122 | case TweenType.Quint_EaseInOut: 123 | delta = quintEaseInOut(time); 124 | break; 125 | 126 | case TweenType.Expo_EaseIn: 127 | delta = expoEaseIn(time); 128 | break; 129 | case TweenType.Expo_EaseOut: 130 | delta = expoEaseOut(time); 131 | break; 132 | case TweenType.Expo_EaseInOut: 133 | delta = expoEaseInOut(time); 134 | break; 135 | 136 | case TweenType.Circ_EaseIn: 137 | delta = circEaseIn(time); 138 | break; 139 | case TweenType.Circ_EaseOut: 140 | delta = circEaseOut(time); 141 | break; 142 | case TweenType.Circ_EaseInOut: 143 | delta = circEaseInOut(time); 144 | break; 145 | 146 | case TweenType.Elastic_EaseIn: 147 | { 148 | float period = 0.3f; 149 | if (null != easingParam) { 150 | period = easingParam[0]; 151 | } 152 | delta = elasticEaseIn(time, period); 153 | } 154 | break; 155 | case TweenType.Elastic_EaseOut: 156 | { 157 | float period = 0.3f; 158 | if (null != easingParam) { 159 | period = easingParam[0]; 160 | } 161 | delta = elasticEaseOut(time, period); 162 | } 163 | break; 164 | case TweenType.Elastic_EaseInOut: 165 | { 166 | float period = 0.3f; 167 | if (null != easingParam) { 168 | period = easingParam[0]; 169 | } 170 | delta = elasticEaseInOut(time, period); 171 | } 172 | break; 173 | 174 | 175 | case TweenType.Back_EaseIn: 176 | delta = backEaseIn(time); 177 | break; 178 | case TweenType.Back_EaseOut: 179 | delta = backEaseOut(time); 180 | break; 181 | case TweenType.Back_EaseInOut: 182 | delta = backEaseInOut(time); 183 | break; 184 | 185 | case TweenType.Bounce_EaseIn: 186 | delta = bounceEaseIn(time); 187 | break; 188 | case TweenType.Bounce_EaseOut: 189 | delta = bounceEaseOut(time); 190 | break; 191 | case TweenType.Bounce_EaseInOut: 192 | delta = bounceEaseInOut(time); 193 | break; 194 | 195 | default: 196 | delta = sineEaseInOut(time); 197 | break; 198 | } 199 | 200 | return delta; 201 | } 202 | 203 | // Linear 204 | public static float linear(float time) 205 | { 206 | return time; 207 | } 208 | 209 | 210 | // Sine Ease 211 | public static float sineEaseIn(float time) 212 | { 213 | return -1 * Mathf.Cos(time * (float)(Mathf.PI/2f)) + 1; 214 | } 215 | 216 | public static float sineEaseOut(float time) 217 | { 218 | return Mathf.Sin(time * (float)(Mathf.PI/2f)); 219 | } 220 | 221 | public static float sineEaseInOut(float time) 222 | { 223 | return -0.5f * (Mathf.Cos((float)(Mathf.PI) * time) - 1); 224 | } 225 | 226 | 227 | // Quad Ease 228 | public static float quadEaseIn(float time) 229 | { 230 | return time * time; 231 | } 232 | 233 | public static float quadEaseOut(float time) 234 | { 235 | return -1 * time * (time - 2); 236 | } 237 | 238 | public static float quadEaseInOut(float time) 239 | { 240 | time = time*2; 241 | if (time < 1) 242 | return 0.5f * time * time; 243 | --time; 244 | return -0.5f * (time * (time - 2) - 1); 245 | } 246 | 247 | 248 | 249 | // Cubic Ease 250 | public static float cubicEaseIn(float time) 251 | { 252 | return time * time * time; 253 | } 254 | public static float cubicEaseOut(float time) 255 | { 256 | time -= 1; 257 | return (time * time * time + 1); 258 | } 259 | public static float cubicEaseInOut(float time) 260 | { 261 | time = time*2; 262 | if (time < 1) 263 | return 0.5f * time * time * time; 264 | time -= 2; 265 | return 0.5f * (time * time * time + 2); 266 | } 267 | 268 | 269 | // Quart Ease 270 | public static float quartEaseIn(float time) 271 | { 272 | return time * time * time * time; 273 | } 274 | 275 | public static float quartEaseOut(float time) 276 | { 277 | time -= 1; 278 | return -(time * time * time * time - 1); 279 | } 280 | 281 | public static float quartEaseInOut(float time) 282 | { 283 | time = time*2; 284 | if (time < 1) 285 | return 0.5f * time * time * time * time; 286 | time -= 2; 287 | return -0.5f * (time * time * time * time - 2); 288 | } 289 | 290 | 291 | // Quint Ease 292 | public static float quintEaseIn(float time) 293 | { 294 | return time * time * time * time * time; 295 | } 296 | 297 | public static float quintEaseOut(float time) 298 | { 299 | time -=1; 300 | return (time * time * time * time * time + 1); 301 | } 302 | 303 | public static float quintEaseInOut(float time) 304 | { 305 | time = time*2; 306 | if (time < 1) 307 | return 0.5f * time * time * time * time * time; 308 | time -= 2; 309 | return 0.5f * (time * time * time * time * time + 2); 310 | } 311 | 312 | 313 | // Expo Ease 314 | public static float expoEaseIn(float time) 315 | { 316 | return time == 0 ? 0 : Mathf.Pow(2, 10 * (time/1 - 1)) - 1 * 0.001f; 317 | } 318 | public static float expoEaseOut(float time) 319 | { 320 | return time == 1 ? 1 : (-Mathf.Pow(2, -10 * time / 1) + 1); 321 | } 322 | public static float expoEaseInOut(float time) 323 | { 324 | time /= 0.5f; 325 | if (time < 1) 326 | { 327 | time = 0.5f * Mathf.Pow(2, 10 * (time - 1)); 328 | } 329 | else 330 | { 331 | time = 0.5f * (-Mathf.Pow(2, -10 * (time - 1)) + 2); 332 | } 333 | 334 | return time; 335 | } 336 | 337 | 338 | // Circ Ease 339 | public static float circEaseIn(float time) 340 | { 341 | return -1 * (Mathf.Sqrt(1 - time * time) - 1); 342 | } 343 | public static float circEaseOut(float time) 344 | { 345 | time = time - 1; 346 | return Mathf.Sqrt(1 - time * time); 347 | } 348 | public static float circEaseInOut(float time) 349 | { 350 | time = time * 2; 351 | if (time < 1) 352 | return -0.5f * (Mathf.Sqrt(1 - time * time) - 1); 353 | time -= 2; 354 | return 0.5f * (Mathf.Sqrt(1 - time * time) + 1); 355 | } 356 | 357 | 358 | // Elastic Ease 359 | public static float elasticEaseIn(float time, float period) 360 | { 361 | 362 | float newT = 0; 363 | if (time == 0 || time == 1) 364 | { 365 | newT = time; 366 | } 367 | else 368 | { 369 | float s = period / 4; 370 | time = time - 1; 371 | newT = -Mathf.Pow(2, 10 * time) * Mathf.Sin((time - s) * ((Mathf.PI) * 2f)/ period); 372 | } 373 | 374 | return newT; 375 | } 376 | public static float elasticEaseOut(float time, float period) 377 | { 378 | 379 | float newT = 0; 380 | if (time == 0 || time == 1) 381 | { 382 | newT = time; 383 | } 384 | else 385 | { 386 | float s = period / 4; 387 | newT = Mathf.Pow(2, -10 * time) * Mathf.Sin((time - s) * ((Mathf.PI) * 2f)/ period) + 1; 388 | } 389 | 390 | return newT; 391 | } 392 | public static float elasticEaseInOut(float time, float period) 393 | { 394 | 395 | float newT = 0; 396 | if (time == 0 || time == 1) 397 | { 398 | newT = time; 399 | } 400 | else 401 | { 402 | time = time * 2; 403 | if ( period == 0 ) 404 | { 405 | period = 0.3f * 1.5f; 406 | } 407 | 408 | float s = period / 4; 409 | 410 | time = time - 1; 411 | if (time < 0) 412 | { 413 | newT = -0.5f * Mathf.Pow(2, 10 * time) * Mathf.Sin((time -s) * ((Mathf.PI) * 2f)/ period); 414 | } 415 | else 416 | { 417 | newT = Mathf.Pow(2, -10 * time) * Mathf.Sin((time - s) * ((Mathf.PI) * 2f)/ period) * 0.5f + 1; 418 | } 419 | } 420 | return newT; 421 | } 422 | 423 | 424 | // Back Ease 425 | public static float backEaseIn(float time) 426 | { 427 | float overshoot = 1.70158f; 428 | return time * time * ((overshoot + 1) * time - overshoot); 429 | } 430 | public static float backEaseOut(float time) 431 | { 432 | float overshoot = 1.70158f; 433 | 434 | time = time - 1; 435 | return time * time * ((overshoot + 1) * time + overshoot) + 1; 436 | } 437 | public static float backEaseInOut(float time) 438 | { 439 | float overshoot = 1.70158f * 1.525f; 440 | 441 | time = time * 2; 442 | if (time < 1) 443 | { 444 | return (time * time * ((overshoot + 1) * time - overshoot)) / 2; 445 | } 446 | else 447 | { 448 | time = time - 2; 449 | return (time * time * ((overshoot + 1) * time + overshoot)) / 2 + 1; 450 | } 451 | } 452 | 453 | 454 | 455 | // Bounce Ease 456 | public static float bounceTime(float time) 457 | { 458 | if (time < 1 / 2.75) 459 | { 460 | return 7.5625f * time * time; 461 | } 462 | else if (time < 2 / 2.75) 463 | { 464 | time -= 1.5f / 2.75f; 465 | return 7.5625f * time * time + 0.75f; 466 | } 467 | else if(time < 2.5 / 2.75) 468 | { 469 | time -= 2.25f / 2.75f; 470 | return 7.5625f * time * time + 0.9375f; 471 | } 472 | 473 | time -= 2.625f / 2.75f; 474 | return 7.5625f * time * time + 0.984375f; 475 | } 476 | public static float bounceEaseIn(float time) 477 | { 478 | return 1 - bounceTime(1 - time); 479 | } 480 | 481 | public static float bounceEaseOut(float time) 482 | { 483 | return bounceTime(time); 484 | } 485 | 486 | public static float bounceEaseInOut(float time) 487 | { 488 | float newT = 0; 489 | if (time < 0.5f) 490 | { 491 | time = time * 2; 492 | newT = (1 - bounceTime(1 - time)) * 0.5f; 493 | } 494 | else 495 | { 496 | newT = bounceTime(time * 2 - 1) * 0.5f + 0.5f; 497 | } 498 | 499 | return newT; 500 | } 501 | 502 | 503 | // Custom Ease 504 | public static float customEase(float time, float[] easingParam) 505 | { 506 | if (easingParam!=null) 507 | { 508 | float tt = 1-time; 509 | return easingParam[1]*tt*tt*tt + 3*easingParam[3]*time*tt*tt + 3*easingParam[5]*time*time*tt + easingParam[7]*time*time*time; 510 | } 511 | return time; 512 | } 513 | 514 | public static float easeIn(float time, float rate) 515 | { 516 | return Mathf.Pow(time, rate); 517 | } 518 | 519 | public static float easeOut(float time, float rate) 520 | { 521 | return Mathf.Pow(time, 1 / rate); 522 | } 523 | 524 | public static float easeInOut(float time, float rate) 525 | { 526 | time *= 2; 527 | if (time < 1) 528 | { 529 | return 0.5f * Mathf.Pow(time, rate); 530 | } 531 | else 532 | { 533 | return (1.0f - 0.5f * Mathf.Pow(2 - time, rate)); 534 | } 535 | } 536 | 537 | public static float quadraticIn(float time) 538 | { 539 | return Mathf.Pow(time,2); 540 | } 541 | 542 | public static float quadraticOut(float time) 543 | { 544 | return -time*(time-2); 545 | } 546 | 547 | public static float quadraticInOut(float time) 548 | { 549 | 550 | float resultTime = time; 551 | time = time*2; 552 | if (time < 1) 553 | { 554 | resultTime = time * time * 0.5f; 555 | } 556 | else 557 | { 558 | --time; 559 | resultTime = -0.5f * (time * (time - 2) - 1); 560 | } 561 | return resultTime; 562 | } 563 | 564 | public static float bezieratFunction( float a, float b, float c, float d, float t ) 565 | { 566 | return (Mathf.Pow(1-t,3) * a + 3*t*(Mathf.Pow(1-t,2))*b + 3*Mathf.Pow(t,2)*(1-t)*c + Mathf.Pow(t,3)*d ); 567 | } 568 | 569 | } 570 | 571 | } -------------------------------------------------------------------------------- /Assets/UnityActions/Scripts/Actions/ActionInterval.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections.Generic; 3 | 4 | 5 | 6 | namespace CC 7 | { 8 | 9 | 10 | /** @class ActionInterval 11 | @brief An interval action is an action that takes place within a certain period of time. 12 | It has an start time, and a finish time. The finish time is the parameter 13 | duration plus the start time. 14 | These ActionInterval actions have some interesting properties, like: 15 | - They can run normally (default) 16 | - They can run reversed with the reverse method 17 | - They can run with the time altered with the Accelerate, AccelDeccel and Speed actions. 18 | For example, you can simulate a Ping Pong effect running the action normally and 19 | then running it again in Reverse mode. 20 | Example: 21 | Action *pingPongAction = Sequence::actions(action, action.reverse(), nullptr); 22 | */ 23 | public abstract class ActionInterval : FiniteTimeAction 24 | { 25 | float completedTime; 26 | bool isFirstTick; 27 | 28 | public float GetCompletedTime() 29 | { 30 | return completedTime; 31 | } 32 | protected ActionInterval():base(0) 33 | { 34 | 35 | } 36 | public ActionInterval(float duration):base(duration) 37 | { 38 | completedTime = 0; 39 | this.duration = duration; 40 | isFirstTick = true; 41 | if (duration == 0) 42 | { 43 | this.duration = epsilon; 44 | }else 45 | { 46 | this.duration = duration; 47 | } 48 | 49 | 50 | } 51 | 52 | 53 | public override bool IsDone() 54 | { 55 | return (completedTime >= duration); 56 | } 57 | 58 | public override void Update(float delta) 59 | { 60 | if(isFirstTick) 61 | { 62 | isFirstTick = false; 63 | completedTime = 0; 64 | } 65 | else 66 | { 67 | completedTime += delta; 68 | } 69 | 70 | LerpAction(Mathf.Max(0,Mathf.Min(1,completedTime / Mathf.Max(duration, epsilon)))); 71 | } 72 | 73 | public override void StartWithTarget(Transform inTarget) 74 | { 75 | base.StartWithTarget(inTarget); 76 | isFirstTick=true; 77 | } 78 | 79 | } 80 | 81 | 82 | 83 | // Extra action for making a Sequence or Spawn when only adding one action to it. 84 | class ExtraAction : FiniteTimeAction 85 | { 86 | public ExtraAction():base(0) 87 | {} 88 | 89 | public override void LerpAction (float delta) 90 | { 91 | 92 | } 93 | 94 | public override void Update (float delta) 95 | { 96 | 97 | } 98 | 99 | public override Action Reverse () 100 | { 101 | return new ExtraAction(); 102 | } 103 | 104 | public override Action Clone () 105 | { 106 | return new ExtraAction(); 107 | } 108 | 109 | }; 110 | 111 | 112 | 113 | /** @class Sequence 114 | * @brief Runs actions sequentially, one after another. 115 | */ 116 | class Sequence : ActionInterval 117 | { 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | int _last; 126 | float _split; 127 | 128 | 129 | FiniteTimeAction[ ] finiteTimeActions = new FiniteTimeAction[2]; 130 | 131 | 132 | //List finiteTimeActions=new List(); 133 | 134 | 135 | public Sequence(params FiniteTimeAction[] list):this(false,list) 136 | { 137 | 138 | } 139 | 140 | 141 | void AccumulateDuration() 142 | { 143 | duration= finiteTimeActions[0].GetDuration()+finiteTimeActions[1].GetDuration(); 144 | 145 | } 146 | 147 | private Sequence( bool dummy,FiniteTimeAction[] list):base(1) 148 | { 149 | if(list.Length==0) 150 | { 151 | finiteTimeActions[0]= new ExtraAction(); 152 | finiteTimeActions[1]= new ExtraAction(); 153 | AccumulateDuration(); 154 | } 155 | else if(list.Length==1) 156 | { 157 | finiteTimeActions[0]= list[0]; 158 | finiteTimeActions[1]= new ExtraAction(); 159 | 160 | AccumulateDuration(); 161 | }else if(list.Length==2) 162 | { 163 | finiteTimeActions[0]= list[0]; 164 | finiteTimeActions[1]= list[1]; 165 | 166 | 167 | }else 168 | {// GREATER THAN 2 169 | 170 | 171 | 172 | Sequence last = new Sequence (list[list.Length-2],list[list.Length-1]); 173 | 174 | for(int i= list.Length-3;i>=1;i--) 175 | { 176 | last = new Sequence(list[i],last); 177 | } 178 | 179 | 180 | finiteTimeActions[0]= list[0]; 181 | finiteTimeActions[1]= last; 182 | 183 | AccumulateDuration(); 184 | } 185 | 186 | 187 | 188 | 189 | } 190 | 191 | 192 | 193 | 194 | 195 | 196 | public override void Stop() 197 | { 198 | if( _last != - 1) 199 | { 200 | finiteTimeActions[_last].Stop(); 201 | } 202 | base.Stop(); 203 | } 204 | 205 | public override void StartWithTarget(Transform inTarget) 206 | { 207 | base.StartWithTarget(inTarget); 208 | 209 | _split = finiteTimeActions[0].GetDuration()/ GetDuration(); 210 | _last = -1; 211 | } 212 | 213 | 214 | public override void LerpAction(float t) 215 | { 216 | int found = 0; 217 | float new_t = 0.0f; 218 | 219 | if( t < _split ) { 220 | // action[0] 221 | found = 0; 222 | if( _split != 0 ) 223 | new_t = t / _split; 224 | else 225 | new_t = 1; 226 | 227 | } else { 228 | // action[1] 229 | found = 1; 230 | if ( _split == 1 ) 231 | new_t = 1; 232 | else 233 | new_t = (t-_split) / (1 - _split ); 234 | } 235 | 236 | if ( found==1 ) { 237 | 238 | if( _last == -1 ) { 239 | // action[0] was skipped, execute it. 240 | finiteTimeActions[0].StartWithTarget(target); 241 | finiteTimeActions[0].LerpAction(1.0f); 242 | finiteTimeActions[0].Stop(); 243 | } 244 | else if( _last == 0 ) 245 | { 246 | // switching to action 1. Stop action 0. 247 | finiteTimeActions[0].LerpAction(1.0f); 248 | finiteTimeActions[0].Stop(); 249 | } 250 | } 251 | else if(found==0 && _last==1 ) 252 | { 253 | // Reverse mode ? 254 | // FIXME: Bug. this case doesn't contemplate when _last==-1, found=0 and in "reverse mode" 255 | // since it will require a hack to know if an action is on reverse mode or not. 256 | // "step" should be overriden, and the "reverseMode" value propagated to inner Sequences. 257 | finiteTimeActions[1].LerpAction(0); 258 | finiteTimeActions[1].Stop(); 259 | } 260 | // Last action found and it is done. 261 | if( found == _last && finiteTimeActions[found].IsDone() ) 262 | { 263 | return; 264 | } 265 | 266 | // Last action found and it is done 267 | if( found != _last ) 268 | { 269 | finiteTimeActions[found].StartWithTarget(target); 270 | } 271 | 272 | finiteTimeActions[found].LerpAction(new_t); 273 | _last = found; 274 | } 275 | 276 | 277 | 278 | public Sequence( FiniteTimeAction action1,FiniteTimeAction action2) 279 | { 280 | float totalduration = action1.GetDuration()+action2.GetDuration(); 281 | duration = totalduration; 282 | 283 | finiteTimeActions[0]=action1; 284 | finiteTimeActions[1]=action2; 285 | } 286 | 287 | 288 | public override Action Reverse () 289 | { 290 | FiniteTimeAction action1 = finiteTimeActions[1].Reverse() as FiniteTimeAction; 291 | FiniteTimeAction action0 = finiteTimeActions[0].Reverse() as FiniteTimeAction ; 292 | 293 | return new Sequence(action1,action0); 294 | } 295 | 296 | public override Action Clone () 297 | { 298 | return new Sequence(finiteTimeActions[0].Clone() as FiniteTimeAction,finiteTimeActions[1].Clone() as FiniteTimeAction); 299 | } 300 | 301 | 302 | } 303 | 304 | 305 | 306 | /** @class Repeat 307 | * @brief Repeats an action a number of times. 308 | * To repeat an action forever use the RepeatForever action. 309 | */ 310 | 311 | class Repeat : ActionInterval 312 | { 313 | 314 | 315 | protected int _times; 316 | protected int _total; 317 | protected float _nextDt; 318 | /** Inner action */ 319 | protected FiniteTimeAction _innerAction; 320 | 321 | public Repeat(FiniteTimeAction action, int times) 322 | { 323 | _times=times; 324 | duration = action.GetDuration() * times; 325 | 326 | _innerAction=action; 327 | } 328 | 329 | 330 | 331 | 332 | public override void StartWithTarget(Transform target) 333 | { 334 | _total = 0; 335 | _nextDt = _innerAction.GetDuration()/duration; 336 | base.StartWithTarget(target); 337 | _innerAction.StartWithTarget(target); 338 | } 339 | 340 | 341 | public override void Stop() 342 | { 343 | _innerAction.Stop(); 344 | base.Stop(); 345 | } 346 | 347 | 348 | public override void LerpAction(float dt) 349 | { 350 | if (dt >= _nextDt) 351 | { 352 | while (dt > _nextDt && _total < _times) 353 | { 354 | 355 | _innerAction.LerpAction(1.0f); 356 | _total++; 357 | 358 | _innerAction.Stop(); 359 | _innerAction.StartWithTarget(target); 360 | _nextDt = _innerAction.GetDuration()/duration * (_total+1); 361 | } 362 | 363 | // fix for issue #1288, incorrect end value of repeat 364 | if(dt >= 1.0f && _total < _times) 365 | { 366 | _total++; 367 | } 368 | 369 | // don't set an instant action back or update it, it has no use because it has no duration 370 | if (_total == _times) 371 | { 372 | _innerAction.LerpAction(1); 373 | _innerAction.Stop(); 374 | } 375 | else 376 | { 377 | // issue #390 prevent jerk, use right update 378 | _innerAction.LerpAction(dt - (_nextDt - _innerAction.GetDuration()/duration)); 379 | } 380 | 381 | } 382 | else 383 | { 384 | _innerAction.LerpAction(dt * _times % 1.0f); 385 | } 386 | } 387 | 388 | public override bool IsDone() 389 | { 390 | return _total == _times; 391 | } 392 | 393 | public override Action Reverse() 394 | { 395 | return new Repeat(_innerAction.Reverse() as FiniteTimeAction, _times); 396 | } 397 | 398 | public override Action Clone() 399 | { 400 | return new Repeat(_innerAction.Clone() as FiniteTimeAction, _times); 401 | } 402 | 403 | 404 | 405 | }; 406 | 407 | 408 | 409 | 410 | 411 | /** @class RepeatForever 412 | * @brief Repeats an action for ever. 413 | To repeat the an action for a limited number of times use the Repeat action. 414 | * @warning This action can't be Sequenceable because it is not an IntervalAction. 415 | */ 416 | class RepeatForever : ActionInterval 417 | { 418 | 419 | /** Inner action */ 420 | protected ActionInterval _innerAction; 421 | 422 | 423 | public RepeatForever(ActionInterval action) 424 | { 425 | _innerAction = action; 426 | } 427 | 428 | public override void StartWithTarget(Transform target) 429 | { 430 | base.StartWithTarget(target); 431 | _innerAction.StartWithTarget(target); 432 | } 433 | 434 | public override void Update(float dt) 435 | { 436 | _innerAction.Update(dt); 437 | if (_innerAction.IsDone()) 438 | { 439 | float diff = _innerAction.GetCompletedTime() - _innerAction.GetDuration(); 440 | if (diff > _innerAction.GetDuration()) 441 | diff = diff % _innerAction.GetDuration(); 442 | _innerAction.StartWithTarget(target); 443 | // to prevent jerk. issue #390, 1247 444 | _innerAction.Update(0.0f); 445 | _innerAction.Update(diff); 446 | } 447 | } 448 | 449 | public override bool IsDone() 450 | { 451 | return false; 452 | } 453 | 454 | public override Action Reverse() 455 | { 456 | return new RepeatForever(_innerAction.Reverse() as ActionInterval); 457 | } 458 | 459 | 460 | public override Action Clone() 461 | { 462 | return new RepeatForever(_innerAction as ActionInterval); 463 | } 464 | 465 | public override void LerpAction (float delta) 466 | { 467 | throw new System.NotImplementedException (); 468 | } 469 | 470 | // 471 | }; 472 | 473 | 474 | /** @class DelayTime 475 | * @brief Delays the action a certain amount of seconds. 476 | */ 477 | public class DelayTime : ActionInterval 478 | { 479 | /** 480 | * Creates the action. 481 | * @param d Duration time, in seconds. 482 | */ 483 | public DelayTime(float d):base(d) 484 | { 485 | 486 | 487 | } 488 | 489 | 490 | 491 | 492 | // 493 | // Overrides 494 | // 495 | /** 496 | * @param time In seconds. 497 | */ 498 | public override void LerpAction(float time) 499 | { 500 | 501 | 502 | } 503 | 504 | 505 | 506 | public override Action Reverse() 507 | { 508 | return new DelayTime(duration); 509 | } 510 | 511 | 512 | public override Action Clone() 513 | { 514 | return new DelayTime(duration); 515 | } 516 | 517 | }; 518 | 519 | 520 | 521 | 522 | /** @class Spawn 523 | * @brief Spawn a new action immediately 524 | */ 525 | public class Spawn : ActionInterval 526 | { 527 | 528 | 529 | public Spawn(params FiniteTimeAction[] arrayOfActions):this(false,arrayOfActions) 530 | { 531 | 532 | } 533 | 534 | 535 | 536 | Spawn(bool dummy,FiniteTimeAction[] list) 537 | { 538 | 539 | 540 | if(list.Length<3) 541 | Debug.LogError("Array length should greater than 2"); 542 | 543 | Spawn last = new Spawn (list[list.Length-2],list[list.Length-1]); 544 | 545 | for(int i= list.Length-3;i>=1;i--) 546 | { 547 | last = new Spawn(list[i],last); 548 | } 549 | 550 | 551 | _one= list[0]; 552 | _two= last; 553 | 554 | AccumulateDuration(_one,_two); 555 | 556 | 557 | 558 | } 559 | 560 | void AccumulateDuration (FiniteTimeAction action1, FiniteTimeAction action2) 561 | { 562 | float d1 = _one.GetDuration (); 563 | float d2 = _two.GetDuration (); 564 | duration = Mathf.Max (d1, d2); 565 | if (d1 > d2) { 566 | _two = new Sequence (action2, new DelayTime (d1 - d2)); 567 | } 568 | else 569 | if (d1 < d2) { 570 | _one = new Sequence (action1, new DelayTime (d2 - d1)); 571 | } 572 | } 573 | 574 | 575 | public Spawn(FiniteTimeAction action1, FiniteTimeAction action2) 576 | { 577 | //CCASSERT(action1 != nullptr, "action1 can't be nullptr!"); 578 | //CCASSERT(action2 != nullptr, "action2 can't be nullptr!"); 579 | 580 | 581 | 582 | 583 | _one = action1; 584 | _two = action2; 585 | 586 | AccumulateDuration (action1, action2); 587 | 588 | 589 | 590 | 591 | 592 | } 593 | 594 | 595 | 596 | // 597 | // Overrides 598 | // 599 | public override void StartWithTarget(Transform target) 600 | { 601 | base.StartWithTarget(target); 602 | _one.StartWithTarget(target); 603 | _two.StartWithTarget(target); 604 | 605 | } 606 | public override void Stop() 607 | { 608 | _one.Stop(); 609 | _two.Stop(); 610 | base.Stop(); 611 | 612 | 613 | } 614 | /** 615 | * @param time In seconds. 616 | */ 617 | public override void LerpAction(float time) 618 | { 619 | if (_one !=null) 620 | { 621 | _one.LerpAction(time); 622 | } 623 | if (_two!=null) 624 | { 625 | _two.LerpAction(time); 626 | } 627 | 628 | } 629 | 630 | 631 | protected FiniteTimeAction _one; 632 | protected FiniteTimeAction _two; 633 | 634 | 635 | public override Action Clone() 636 | { 637 | return new Spawn(_one.Clone() as FiniteTimeAction,_two.Clone() as FiniteTimeAction); 638 | } 639 | 640 | public override Action Reverse() 641 | { 642 | return new Spawn(_one.Reverse() as FiniteTimeAction ,_two.Reverse() as FiniteTimeAction ); 643 | } 644 | 645 | 646 | }; 647 | 648 | 649 | 650 | 651 | 652 | 653 | /** @class MoveTo 654 | * @brief Moves a trasform to the position endposition 655 | 656 | */ 657 | public class MoveTo : ActionInterval 658 | { 659 | Vector3 endPosition; 660 | Vector3 startPosition; 661 | 662 | public MoveTo(float duration ,Vector3 endPosition ):base(duration) 663 | { 664 | this.endPosition = endPosition; 665 | } 666 | 667 | public override Action Reverse () 668 | { 669 | throw new System.NotImplementedException (); 670 | } 671 | 672 | 673 | public override Action Clone () 674 | { 675 | return new MoveTo(duration,endPosition); 676 | } 677 | 678 | public override void LerpAction(float deltaTime) 679 | { 680 | target.position = Vector3.Lerp(startPosition,endPosition,deltaTime); 681 | 682 | } 683 | 684 | public override void StartWithTarget(Transform inTarget) 685 | { 686 | base.StartWithTarget(inTarget); 687 | startPosition = inTarget.position; 688 | } 689 | 690 | } 691 | 692 | 693 | /** @class MoveBy 694 | @brief Moves a trasform by modifying it's position attribute. 695 | delta is relative to the position of the object. 696 | Several MoveBy actions can be concurrently called, and the resulting 697 | movement will be the sum of individual movements. 698 | */ 699 | public class MoveBy : ActionInterval 700 | { 701 | Vector3 startPosition,_previousPosition; 702 | Vector3 _positionDelta; 703 | 704 | public MoveBy(float duration ,Vector3 delta ):base(duration) 705 | { 706 | _positionDelta=delta; 707 | } 708 | 709 | public override void LerpAction(float deltaTime) 710 | { 711 | Vector3 currentPos = target.position; 712 | Vector3 diff = currentPos - _previousPosition; 713 | startPosition = startPosition + diff; 714 | Vector3 newPos = startPosition + (_positionDelta * deltaTime); 715 | target.position = newPos; 716 | _previousPosition = newPos; 717 | 718 | 719 | 720 | //target.position = startPosition + delta * deltaTime ; 721 | } 722 | 723 | public override void StartWithTarget(Transform inTarget) 724 | { 725 | base.StartWithTarget(inTarget); 726 | _previousPosition = startPosition = inTarget.position; 727 | } 728 | 729 | public override Action Reverse () 730 | { 731 | return new MoveBy(duration,-_positionDelta); 732 | } 733 | 734 | 735 | public override Action Clone () 736 | { 737 | return new MoveBy(duration,_positionDelta); 738 | } 739 | 740 | 741 | } 742 | 743 | 744 | 745 | 746 | /** @class RotateTo 747 | * @brief Rotates a Transform to a certain angle by modifying it's rotation attribute. 748 | The direction will be decided by the shortest angle. 749 | */ 750 | public class RotateTo : ActionInterval 751 | { 752 | public RotateTo(float duration, Vector3 dstAngle3D):base(duration) 753 | { 754 | _dstAngle = Quaternion.Euler(dstAngle3D); 755 | 756 | } 757 | 758 | public RotateTo(float duration, Quaternion deltaAngle3D):base(duration) 759 | { 760 | _diffAngle = deltaAngle3D; 761 | 762 | } 763 | 764 | 765 | public override void LerpAction(float deltaTime) 766 | { 767 | target.rotation = Quaternion.Lerp(_startRotation,_dstAngle,deltaTime); 768 | } 769 | 770 | public override void StartWithTarget(Transform inTarget) 771 | { 772 | base.StartWithTarget(inTarget); 773 | _startRotation = inTarget.rotation; 774 | _diffAngle = _dstAngle * Quaternion.Inverse( _startRotation); 775 | } 776 | 777 | 778 | public override Action Reverse () 779 | { 780 | throw new System.NotImplementedException (); 781 | } 782 | 783 | public override Action Clone () 784 | { 785 | return new RotateTo(duration,_dstAngle); 786 | } 787 | 788 | 789 | protected Quaternion _dstAngle; 790 | protected Quaternion _startRotation; 791 | protected Quaternion _diffAngle; 792 | 793 | 794 | }; 795 | 796 | 797 | 798 | /** @class RotateBy 799 | * @brief Rotates a Node object clockwise a number of degrees by modifying it's rotation attribute. 800 | */ 801 | 802 | public class RotateBy : ActionInterval 803 | { 804 | public RotateBy(float duration, Vector3 deltaAngle3D):base(duration) 805 | { 806 | _diffAngle = Quaternion.Euler(deltaAngle3D); 807 | 808 | } 809 | 810 | public RotateBy(float duration, Quaternion deltaAngle3D):base(duration) 811 | { 812 | _diffAngle = deltaAngle3D; 813 | 814 | } 815 | 816 | 817 | public override void LerpAction(float deltaTime) 818 | { 819 | target.rotation = Quaternion.Lerp(_startRotation,_dstAngle,deltaTime); 820 | } 821 | 822 | public override void StartWithTarget(Transform inTarget) 823 | { 824 | base.StartWithTarget(inTarget); 825 | _startRotation = inTarget.rotation; 826 | _dstAngle = _diffAngle * _startRotation; 827 | } 828 | 829 | public override Action Reverse () 830 | { 831 | return new RotateBy(duration,Quaternion.Inverse( _diffAngle)); 832 | } 833 | 834 | public override Action Clone () 835 | { 836 | return new RotateBy(duration,_diffAngle); 837 | } 838 | 839 | 840 | protected Quaternion _dstAngle; 841 | protected Quaternion _startRotation; 842 | protected Quaternion _diffAngle; 843 | 844 | 845 | }; 846 | 847 | 848 | 849 | 850 | public class JumpBy : ActionInterval 851 | { 852 | 853 | /** 854 | * Creates the action. 855 | * @param duration Duration time, in seconds. 856 | * @param position The jumping distance. 857 | * @param height The jumping height. 858 | * @param jumps The jumping times. 859 | * 860 | */ 861 | public JumpBy(float aduration, Vector3 position, float height, int jumps):base(aduration) 862 | { 863 | _delta = position; 864 | _height = height; 865 | _jumps = jumps; 866 | 867 | } 868 | 869 | // 870 | // Overrides 871 | // 872 | public override Action Clone () 873 | { 874 | return new JumpBy(duration,_delta,_height,_jumps); 875 | } 876 | 877 | 878 | 879 | public override Action Reverse () 880 | { 881 | return new JumpBy(duration,-_delta,_height,_jumps); 882 | } 883 | public override void StartWithTarget(Transform aTransform) 884 | { 885 | base.StartWithTarget(aTransform); 886 | _previousPos = _startPosition = aTransform.position; 887 | 888 | } 889 | /** 890 | * @param time In seconds. 891 | */ 892 | public override void LerpAction(float t) 893 | { 894 | //TODO: Implement 3d jump 895 | // parabolic jump (since v0.8.2) 896 | if (target) 897 | { 898 | float frac = (t * _jumps)% 1.0f ; 899 | float y = _height * 4 * frac * (1 - frac); 900 | y += _delta.y * t; 901 | float x = _delta.x * t; 902 | //#if CC_ENABLE_STACKABLE_ACTIONS 903 | Vector3 currentPos = target.position; 904 | Vector3 diff = currentPos - _previousPos; 905 | _startPosition = diff + _startPosition; 906 | Vector3 newPos = _startPosition + new Vector3(x,y,0); 907 | target.position= newPos; 908 | _previousPos = newPos; 909 | // #else 910 | // _target->setPosition(_startPosition + Vec2(x,y)); 911 | // #endif // !CC_ENABLE_STACKABLE_ACTIONS 912 | } 913 | } 914 | 915 | 916 | 917 | protected Vector3 _startPosition; 918 | protected Vector3 _delta; 919 | protected float _height; 920 | protected int _jumps; 921 | protected Vector3 _previousPos; 922 | 923 | }; 924 | 925 | /// 926 | /// Move a Transform Object to a parabolic position simulating a jump position by modifying it's position attribute 927 | /// 928 | public class JumpTo : JumpBy 929 | { 930 | protected Vector3 _endPosition; 931 | public JumpTo(float aduration, Vector3 position, float height, int jumps) : base(aduration, position, height, jumps) 932 | { 933 | _endPosition = position; 934 | } 935 | public override void StartWithTarget(Transform aTransform) 936 | { 937 | base.StartWithTarget(aTransform); 938 | _delta = new Vector3(_endPosition.x - _startPosition.x, _endPosition.y - _startPosition.y, _endPosition.z - _startPosition.z); 939 | } 940 | } 941 | } -------------------------------------------------------------------------------- /Assets/UnityActions/Scripts/Actions/EaseAction.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | namespace CC 5 | { 6 | 7 | public abstract class ActionEase : ActionInterval 8 | 9 | { protected ActionInterval inner; 10 | 11 | public ActionInterval getInnerAction() 12 | { 13 | return inner; 14 | } 15 | 16 | 17 | 18 | public ActionEase(ActionInterval inner ) 19 | { 20 | this.inner = inner; 21 | this.duration = inner.GetDuration(); 22 | } 23 | 24 | 25 | 26 | public override void StartWithTarget(Transform inTarget) 27 | { 28 | base.StartWithTarget(inTarget); 29 | inner.StartWithTarget(inTarget); 30 | } 31 | 32 | public override void Stop() 33 | { 34 | 35 | inner.Stop(); 36 | base.Stop(); 37 | } 38 | 39 | 40 | 41 | 42 | 43 | } 44 | 45 | 46 | /** 47 | @brief Base class for Easing actions with rate parameters 48 | @ingroup Actions 49 | */ 50 | public abstract class EaseRateAction : ActionEase 51 | { 52 | 53 | /** set rate value for the actions */ 54 | public float Rate 55 | { 56 | get { return m_fRate; } 57 | set { m_fRate = value; } 58 | } 59 | 60 | 61 | /** Initializes the action with the inner action and the rate parameter */ 62 | public EaseRateAction(ActionInterval pAction, float rate):base(pAction) 63 | { 64 | m_fRate = rate; 65 | 66 | } 67 | 68 | public ActionInterval reverse() 69 | { 70 | return null; 71 | } 72 | 73 | 74 | float m_fRate; 75 | } 76 | 77 | 78 | 79 | 80 | public class EaseIn : EaseRateAction 81 | { 82 | 83 | /** 84 | @brief Create the action with the inner action and the rate parameter. 85 | @param action The pointer of the inner action. 86 | @param rate The value of the rate parameter. 87 | @return A pointer of EaseIn action. If creation failed, return nil. 88 | */ 89 | public EaseIn(ActionInterval action, float rate):base(action, rate) 90 | { 91 | 92 | } 93 | 94 | 95 | 96 | 97 | public override Action Clone() 98 | { 99 | // no copy constructor 100 | if (inner!=null) 101 | return new EaseIn((ActionInterval)inner.Clone(), this.Rate); 102 | 103 | return null; 104 | } 105 | 106 | public override void LerpAction(float dt) 107 | { 108 | inner.LerpAction(tweenfunc.easeIn(dt, this.Rate)); 109 | } 110 | 111 | public override Action Reverse() 112 | { 113 | return new EaseIn((ActionInterval)inner.Reverse(), 1f / this.Rate); 114 | } 115 | 116 | 117 | }; 118 | 119 | 120 | 121 | 122 | 123 | /** 124 | @class EaseOut 125 | @brief EaseOut action with a rate. 126 | @details The timeline of inner action will be changed by: 127 | \f${ time }^ { (1/rate) }\f$. 128 | @ingroup Actions 129 | */ 130 | public class EaseOut : EaseRateAction 131 | { 132 | 133 | 134 | public EaseOut(ActionInterval action, float rate):base(action, rate) 135 | { 136 | 137 | } 138 | 139 | public override Action Clone() 140 | { 141 | // no copy constructor 142 | if (inner!=null) 143 | return new EaseOut((ActionInterval)inner.Clone(), this.Rate); 144 | 145 | return null; 146 | } 147 | 148 | public override void LerpAction(float dt) 149 | { 150 | inner.LerpAction(tweenfunc.easeOut(dt, this.Rate)); 151 | } 152 | 153 | public override Action Reverse() 154 | { 155 | return new EaseOut((ActionInterval)inner.Reverse(), 1f / this.Rate); 156 | } 157 | }; 158 | 159 | 160 | 161 | 162 | 163 | 164 | /** 165 | @class EaseInOut 166 | @brief EaseInOut action with a rate 167 | @details If time * 2 < 1, the timeline of inner action will be changed by: 168 | \f$0.5*{ time }^{ rate }\f$. 169 | Else, the timeline of inner action will be changed by: 170 | \f$1.0-0.5*{ 2-time }^{ rate }\f$. 171 | @ingroup Actions 172 | */ 173 | public class EaseInOut : EaseRateAction 174 | { 175 | 176 | /** 177 | @brief Create the action with the inner action and the rate parameter. 178 | @param action The pointer of the inner action. 179 | @param rate The value of the rate parameter. 180 | @return A pointer of EaseInOut action. If creation failed, return nil. 181 | */ 182 | public EaseInOut(ActionInterval action, float rate):base(action, rate) 183 | {} 184 | 185 | public override Action Clone() 186 | { 187 | // no copy constructor 188 | if (inner!=null) 189 | return new EaseInOut((ActionInterval)inner.Clone(), this.Rate); 190 | 191 | return null; 192 | } 193 | 194 | public override void LerpAction(float dt) 195 | { 196 | inner.LerpAction(tweenfunc.easeInOut(dt, this.Rate)); 197 | } 198 | 199 | public override Action Reverse() 200 | { 201 | return new EaseInOut((ActionInterval)inner.Reverse(), 1f / this.Rate); 202 | } 203 | }; 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | /** 212 | @class EaseExponentialIn 213 | @brief Ease Exponential In action. 214 | @details The timeline of inner action will be changed by: 215 | \f${ 2 }^{ 10*(time-1) }-1*0.001\f$. 216 | @ingroup Actions 217 | */ 218 | public class EaseExponentialIn : ActionEase 219 | { 220 | 221 | /** 222 | @brief Create the action with the inner action. 223 | @param action The pointer of the inner action. 224 | @return A pointer of EaseExponentialIn action. If creation failed, return nil. 225 | */ 226 | public EaseExponentialIn(ActionInterval action):base(action) 227 | {} 228 | 229 | public override Action Clone() 230 | { 231 | // no copy constructor 232 | if (inner!=null) 233 | return new EaseExponentialIn((ActionInterval)inner.Clone()); 234 | 235 | return null; 236 | } 237 | 238 | public override void LerpAction(float dt) 239 | { 240 | inner.LerpAction(tweenfunc.expoEaseIn(dt)); 241 | } 242 | 243 | public override Action Reverse() 244 | { 245 | return new EaseExponentialIn((ActionInterval)inner.Reverse()); 246 | } 247 | }; 248 | 249 | 250 | 251 | 252 | /** 253 | @class EaseExponentialOut 254 | @brief Ease Exponential Out 255 | @details The timeline of inner action will be changed by: 256 | \f$1-{ 2 }^{ -10*(time-1) }\f$. 257 | @ingroup Actions 258 | */ 259 | public class EaseExponentialOut : ActionEase 260 | { 261 | 262 | /** 263 | @brief Create the action with the inner action. 264 | @param action The pointer of the inner action. 265 | @return A pointer of EaseExponentialOut action. If creation failed, return nil. 266 | */ 267 | public EaseExponentialOut(ActionInterval action):base(action) 268 | {} 269 | 270 | public override Action Clone() 271 | { 272 | // no copy constructor 273 | if (inner!=null) 274 | return new EaseExponentialOut((ActionInterval)inner.Clone()); 275 | 276 | return null; 277 | } 278 | 279 | public override void LerpAction(float dt) 280 | { 281 | inner.LerpAction(tweenfunc.expoEaseOut(dt)); 282 | } 283 | 284 | public override Action Reverse() 285 | { 286 | return new EaseExponentialOut((ActionInterval)inner.Reverse()); 287 | } 288 | }; 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | /** 298 | @class EaseExponentialInOut 299 | @brief Ease Exponential InOut 300 | @details If time * 2 < 1, the timeline of inner action will be changed by: 301 | \f$0.5*{ 2 }^{ 10*(time-1) }\f$. 302 | else, the timeline of inner action will be changed by: 303 | \f$0.5*(2-{ 2 }^{ -10*(time-1) })\f$. 304 | @ingroup Actions 305 | */ 306 | public class EaseExponentialInOut : ActionEase 307 | { 308 | 309 | /** 310 | @brief Create the action with the inner action. 311 | @param action The pointer of the inner action. 312 | @return A pointer of EaseExponentialInOut action. If creation failed, return nil. 313 | */ 314 | public EaseExponentialInOut(ActionInterval action):base(action) 315 | {} 316 | 317 | public override Action Clone() 318 | { 319 | // no copy constructor 320 | if (inner!=null) 321 | return new EaseExponentialInOut((ActionInterval)inner.Clone()); 322 | 323 | return null; 324 | } 325 | 326 | public override void LerpAction(float dt) 327 | { 328 | inner.LerpAction(tweenfunc.expoEaseInOut(dt)); 329 | } 330 | 331 | public override Action Reverse() 332 | { 333 | return new EaseExponentialInOut((ActionInterval)inner.Reverse()); 334 | } 335 | }; 336 | 337 | 338 | 339 | 340 | 341 | /** 342 | @class EaseElastic 343 | @brief Ease Elastic abstract class 344 | @since v0.8.2 345 | @ingroup Actions 346 | */ 347 | public abstract class EaseElastic : ActionEase 348 | { 349 | 350 | /** 351 | @brief Set period of the wave in radians. 352 | @param fPeriod The value will be set. 353 | */ 354 | public float Period 355 | { 356 | get { 357 | return _period; 358 | } 359 | set { 360 | _period = value; 361 | } 362 | } 363 | 364 | /**ram action The pointer of the inner action. 365 | @param period Period of the wave in radians. Default is 0.3. 366 | @return Return true when the initialization success, otherwise return false. 367 | */ 368 | public EaseElastic(ActionInterval interval, float period=5f):base(interval) 369 | { 370 | _period = period; 371 | } 372 | 373 | 374 | protected float _period; 375 | 376 | 377 | }; 378 | 379 | 380 | 381 | 382 | 383 | 384 | /** 385 | @class EaseElasticIn 386 | @brief Ease Elastic In action. 387 | @details If time == 0 or time == 1, the timeline of inner action will not be changed. 388 | Else, the timeline of inner action will be changed by: 389 | \f$-{ 2 }^{ 10*(time-1) }*sin((time-1-\frac { period }{ 4 } )*\pi *2/period)\f$. 390 | @warning This action doesn't use a bijective function. 391 | Actions like Sequence might have an unexpected result when used with this action. 392 | @since v0.8.2 393 | @ingroup Actions 394 | */ 395 | public class EaseElasticIn : EaseElastic 396 | { 397 | 398 | /** 399 | @brief Create the EaseElasticIn action with the inner action and the period in radians. 400 | @param action The pointer of the inner action. 401 | @param period Period of the wave in radians. 402 | @return A pointer of EaseElasticIn action. If creation failed, return nil. 403 | */ 404 | 405 | 406 | public EaseElasticIn(ActionInterval interval, float period):base(interval,period) 407 | { 408 | 409 | } 410 | 411 | 412 | 413 | 414 | public override void LerpAction(float dt) 415 | { 416 | inner.LerpAction(tweenfunc.expoEaseIn(dt)); 417 | } 418 | 419 | 420 | 421 | public override Action Clone() 422 | { 423 | // no copy constructor 424 | if (inner!=null) 425 | return new EaseElasticIn((ActionInterval)inner.Clone(),this.Period); 426 | 427 | return null; 428 | } 429 | 430 | 431 | 432 | public override Action Reverse() 433 | { 434 | return new EaseElasticIn((ActionInterval)inner.Reverse(),this.Period); 435 | } 436 | 437 | 438 | }; 439 | 440 | 441 | 442 | 443 | 444 | public class EaseElasticOut : EaseElastic 445 | { 446 | 447 | /** 448 | @brief Create the EaseElasticIn action with the inner action and the period in radians. 449 | @param action The pointer of the inner action. 450 | @param period Period of the wave in radians. 451 | @return A pointer of EaseElasticIn action. If creation failed, return nil. 452 | */ 453 | 454 | 455 | public EaseElasticOut(ActionInterval interval, float period):base(interval,period) 456 | { 457 | 458 | } 459 | 460 | 461 | 462 | 463 | public override void LerpAction(float dt) 464 | { 465 | inner.LerpAction(tweenfunc.expoEaseOut(dt)); 466 | } 467 | 468 | 469 | 470 | public override Action Clone() 471 | { 472 | // no copy constructor 473 | if (inner!=null) 474 | return new EaseElasticOut((ActionInterval)inner.Clone(),this.Period); 475 | 476 | return null; 477 | } 478 | 479 | 480 | 481 | public override Action Reverse() 482 | { 483 | return new EaseElasticOut((ActionInterval)inner.Reverse(),this.Period); 484 | } 485 | 486 | 487 | }; 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | public class EaseElasticInOut : EaseElastic 496 | { 497 | 498 | /** 499 | @brief Create the EaseElasticIn action with the inner action and the period in radians. 500 | @param action The pointer of the inner action. 501 | @param period Period of the wave in radians. 502 | @return A pointer of EaseElasticIn action. If creation failed, return nil. 503 | */ 504 | 505 | 506 | public EaseElasticInOut(ActionInterval interval, float period):base(interval,period) 507 | { 508 | 509 | } 510 | 511 | 512 | 513 | 514 | public override void LerpAction(float dt) 515 | { 516 | inner.LerpAction(tweenfunc.expoEaseInOut(dt)); 517 | } 518 | 519 | 520 | 521 | public override Action Clone() 522 | { 523 | // no copy constructor 524 | if (inner!=null) 525 | return new EaseElasticInOut((ActionInterval)inner.Clone(),this.Period); 526 | 527 | return null; 528 | } 529 | 530 | 531 | 532 | public override Action Reverse() 533 | { 534 | return new EaseElasticInOut((ActionInterval)inner.Reverse(),this.Period); 535 | } 536 | 537 | 538 | }; 539 | 540 | 541 | 542 | 543 | 544 | 545 | 546 | 547 | 548 | 549 | 550 | 551 | 552 | public abstract class EaseBounce : ActionEase 553 | { 554 | 555 | 556 | public EaseBounce(ActionInterval interval):base(interval) 557 | { 558 | } 559 | 560 | // Overrides 561 | 562 | 563 | 564 | 565 | 566 | 567 | 568 | }; 569 | 570 | 571 | 572 | 573 | 574 | public class EaseBounceIn : ActionEase 575 | { 576 | 577 | 578 | public EaseBounceIn(ActionInterval interval):base(interval) 579 | { 580 | } 581 | 582 | // Overrides 583 | 584 | 585 | 586 | public override void LerpAction(float dt) 587 | { 588 | inner.LerpAction(tweenfunc.bounceEaseIn(dt)); 589 | } 590 | 591 | public override Action Clone() 592 | { 593 | // no copy constructor 594 | if (inner!=null) 595 | return new EaseBounceIn((ActionInterval)inner.Clone()); 596 | 597 | return null; 598 | } 599 | 600 | 601 | 602 | public override Action Reverse() 603 | { 604 | return new EaseBounceIn((ActionInterval)inner.Reverse()); 605 | } 606 | 607 | }; 608 | 609 | 610 | 611 | 612 | 613 | public class EaseBounceOut : ActionEase 614 | { 615 | 616 | 617 | public EaseBounceOut(ActionInterval interval):base(interval) 618 | { 619 | } 620 | 621 | // Overrides 622 | 623 | 624 | 625 | public override void LerpAction(float dt) 626 | { 627 | inner.LerpAction(tweenfunc.bounceEaseOut(dt)); 628 | } 629 | 630 | public override Action Clone() 631 | { 632 | // no copy constructor 633 | if (inner!=null) 634 | return new EaseBounceOut((ActionInterval)inner.Clone()); 635 | 636 | return null; 637 | } 638 | 639 | 640 | 641 | public override Action Reverse() 642 | { 643 | return new EaseBounceOut((ActionInterval)inner.Reverse()); 644 | } 645 | 646 | }; 647 | 648 | 649 | 650 | 651 | 652 | 653 | 654 | public class EaseBounceInOut : ActionEase 655 | { 656 | 657 | 658 | public EaseBounceInOut(ActionInterval interval):base(interval) 659 | { 660 | } 661 | 662 | // Overrides 663 | 664 | 665 | 666 | public override void LerpAction(float dt) 667 | { 668 | inner.LerpAction(tweenfunc.bounceEaseInOut(dt)); 669 | } 670 | 671 | public override Action Clone() 672 | { 673 | // no copy constructor 674 | if (inner!=null) 675 | return new EaseBounceInOut((ActionInterval)inner.Clone()); 676 | 677 | return null; 678 | } 679 | 680 | 681 | 682 | public override Action Reverse() 683 | { 684 | return new EaseBounceInOut((ActionInterval)inner.Reverse()); 685 | } 686 | 687 | }; 688 | 689 | 690 | 691 | /** 692 | @class EaseBackIn 693 | @brief EaseBackIn action. 694 | @warning This action doesn't use a bijective function. 695 | Actions like Sequence might have an unexpected result when used with this action. 696 | @since v0.8.2 697 | @ingroup Actions 698 | */ 699 | public class EaseBackIn : ActionEase 700 | { 701 | 702 | /** 703 | @brief Create the action with the inner action. 704 | @param action The pointer of the inner action. 705 | @return A pointer of EaseBackIn action. If creation failed, return nil. 706 | */ 707 | public EaseBackIn(ActionInterval interval):base(interval) 708 | { 709 | } 710 | 711 | 712 | 713 | public override void LerpAction(float dt) 714 | { 715 | inner.LerpAction(tweenfunc.backEaseIn(dt)); 716 | } 717 | 718 | public override Action Clone() 719 | { 720 | // no copy constructor 721 | if (inner!=null) 722 | return new EaseBackIn((ActionInterval)inner.Clone()); 723 | 724 | return null; 725 | } 726 | 727 | 728 | 729 | public override Action Reverse() 730 | { 731 | return new EaseBackIn((ActionInterval)inner.Reverse()); 732 | } 733 | 734 | }; 735 | 736 | /** 737 | @class EaseBackOut 738 | @brief EaseBackOut action. 739 | @warning This action doesn't use a bijective function. 740 | Actions like Sequence might have an unexpected result when used with this action. 741 | @since v0.8.2 742 | @ingroup Actions 743 | */ 744 | public class EaseBackOut : ActionEase 745 | { 746 | 747 | /** 748 | @brief Create the action with the inner action. 749 | @param action The pointer of the inner action. 750 | @return A pointer of EaseBackOut action. If creation failed, return nil. 751 | */ 752 | public EaseBackOut(ActionInterval interval):base(interval) 753 | { 754 | } 755 | 756 | 757 | 758 | public override void LerpAction(float dt) 759 | { 760 | inner.LerpAction(tweenfunc.backEaseOut(dt)); 761 | } 762 | 763 | public override Action Clone() 764 | { 765 | // no copy constructor 766 | if (inner!=null) 767 | return new EaseBackOut((ActionInterval)inner.Clone()); 768 | 769 | return null; 770 | } 771 | 772 | 773 | 774 | public override Action Reverse() 775 | { 776 | return new EaseBackOut((ActionInterval)inner.Reverse()); 777 | } 778 | }; 779 | 780 | /** 781 | @class EaseBackInOut 782 | @brief EaseBackInOut action. 783 | @warning This action doesn't use a bijective function. 784 | Actions like Sequence might have an unexpected result when used with this action. 785 | @since v0.8.2 786 | @ingroup Actions 787 | */ 788 | public class EaseBackInOut : ActionEase 789 | { 790 | 791 | /** 792 | @brief Create the action with the inner action. 793 | @param action The pointer of the inner action. 794 | @return A pointer of EaseBackInOut action. If creation failed, return nil. 795 | */ 796 | public EaseBackInOut(ActionInterval interval):base(interval) 797 | { 798 | } 799 | 800 | 801 | 802 | public override void LerpAction(float dt) 803 | { 804 | inner.LerpAction(tweenfunc.backEaseInOut(dt)); 805 | } 806 | 807 | public override Action Clone() 808 | { 809 | // no copy constructor 810 | if (inner!=null) 811 | return new EaseBackInOut((ActionInterval)inner.Clone()); 812 | 813 | return null; 814 | } 815 | 816 | 817 | 818 | public override Action Reverse() 819 | { 820 | return new EaseBackInOut((ActionInterval)inner.Reverse()); 821 | } 822 | }; 823 | 824 | 825 | 826 | 827 | 828 | 829 | /** 830 | @class EaseBezierAction 831 | @brief Ease Bezier 832 | @ingroup Actions 833 | */ 834 | public class EaseBezierAction : ActionEase 835 | { 836 | 837 | 838 | /** 839 | @brief Set the bezier parameters. 840 | */ 841 | 842 | public void SetBezierParamer( float p0, float p1, float p2, float p3) 843 | { 844 | _p0 = p0; 845 | _p1 = p1; 846 | _p2 = p2; 847 | _p3 = p3; 848 | } 849 | 850 | 851 | 852 | 853 | 854 | /** 855 | @brief Create the action with the inner action. 856 | @param action The pointer of the inner action. 857 | @return A pointer of EaseBezierAction action. If creation failed, return nil. 858 | */ 859 | public EaseBezierAction(ActionInterval interval):base(interval) 860 | { 861 | } 862 | 863 | 864 | 865 | public override void LerpAction(float dt) 866 | { 867 | inner.LerpAction(tweenfunc.bezieratFunction(_p0,_p1,_p2,_p3,dt)); 868 | } 869 | 870 | public override Action Clone() 871 | { 872 | // no copy constructor 873 | 874 | 875 | 876 | if (inner!=null) 877 | { 878 | EaseBezierAction action = new EaseBezierAction((ActionInterval)inner.Clone()); 879 | action.SetBezierParamer(_p0,_p1,_p2,_p3); 880 | return action; 881 | } 882 | 883 | return null; 884 | } 885 | 886 | 887 | 888 | public override Action Reverse() 889 | { 890 | 891 | if (inner!=null) 892 | { 893 | EaseBezierAction action = new EaseBezierAction((ActionInterval)inner.Clone()); 894 | action.SetBezierParamer(_p3,_p2,_p1,_p0); 895 | return action; 896 | } 897 | 898 | return null; 899 | 900 | } 901 | 902 | float _p0; 903 | float _p1; 904 | float _p2; 905 | float _p3; 906 | 907 | 908 | }; 909 | 910 | 911 | 912 | 913 | 914 | /** 915 | @class EaseQuadraticActionIn 916 | @brief Ease Quadratic In 917 | @ingroup Actions 918 | */ 919 | public class EaseQuadraticActionIn : ActionEase 920 | { 921 | 922 | /** 923 | @brief Create the action with the inner action. 924 | @param action The pointer of the inner action. 925 | @return A pointer of EaseQuadraticActionIn action. If creation failed, return nil. 926 | */ 927 | public EaseQuadraticActionIn(ActionInterval interval):base(interval) 928 | { 929 | } 930 | 931 | 932 | 933 | public override void LerpAction(float dt) 934 | { 935 | inner.LerpAction(tweenfunc.quadEaseIn (dt)); 936 | } 937 | 938 | public override Action Clone() 939 | { 940 | // no copy constructor 941 | if (inner!=null) 942 | return new EaseQuadraticActionIn((ActionInterval)inner.Clone()); 943 | 944 | return null; 945 | } 946 | 947 | 948 | 949 | public override Action Reverse() 950 | { 951 | return new EaseQuadraticActionIn((ActionInterval)inner.Reverse()); 952 | } 953 | 954 | }; 955 | 956 | 957 | 958 | 959 | 960 | /** 961 | @class EaseQuadraticActionOut 962 | @brief Ease Quadratic Out 963 | @ingroup Actions 964 | */ 965 | public class EaseQuadraticActionOut : ActionEase 966 | { 967 | 968 | /** 969 | @brief Create the action with the inner action. 970 | @param action The pointer of the inner action. 971 | @return A pointer of EaseQuadraticActionOut action. If creation failed, return nil. 972 | */ 973 | public EaseQuadraticActionOut(ActionInterval interval):base(interval) 974 | { 975 | } 976 | 977 | 978 | 979 | public override void LerpAction(float dt) 980 | { 981 | inner.LerpAction(tweenfunc.quadEaseOut (dt)); 982 | } 983 | 984 | public override Action Clone() 985 | { 986 | // no copy constructor 987 | if (inner!=null) 988 | return new EaseQuadraticActionOut((ActionInterval)inner.Clone()); 989 | 990 | return null; 991 | } 992 | 993 | 994 | 995 | public override Action Reverse() 996 | { 997 | return new EaseQuadraticActionOut((ActionInterval)inner.Reverse()); 998 | } 999 | 1000 | }; 1001 | 1002 | 1003 | 1004 | 1005 | 1006 | /** 1007 | @class EaseQuadraticActionInOut 1008 | @brief Ease Quadratic InOut 1009 | @ingroup Actions 1010 | */ 1011 | public class EaseQuadraticActionInOut : ActionEase 1012 | { 1013 | 1014 | /** 1015 | @brief Create the action with the inner action. 1016 | @param action The pointer of the inner action. 1017 | @return A pointer of EaseQuadraticActionInOut action. If creation failed, return nil. 1018 | */ 1019 | 1020 | public EaseQuadraticActionInOut(ActionInterval interval):base(interval) 1021 | { 1022 | } 1023 | 1024 | 1025 | 1026 | public override void LerpAction(float dt) 1027 | { 1028 | inner.LerpAction(tweenfunc.quadEaseInOut (dt)); 1029 | } 1030 | 1031 | public override Action Clone() 1032 | { 1033 | // no copy constructor 1034 | if (inner!=null) 1035 | return new EaseQuadraticActionInOut((ActionInterval)inner.Clone()); 1036 | 1037 | return null; 1038 | } 1039 | 1040 | 1041 | 1042 | public override Action Reverse() 1043 | { 1044 | return new EaseQuadraticActionInOut((ActionInterval)inner.Reverse()); 1045 | } 1046 | }; 1047 | 1048 | 1049 | 1050 | 1051 | 1052 | /** 1053 | @class EaseQuarticActionIn 1054 | @brief Ease Quartic In 1055 | @ingroup Actions 1056 | */ 1057 | public class EaseQuarticActionIn : ActionEase 1058 | { 1059 | 1060 | /** 1061 | @brief Create the action with the inner action. 1062 | @param action The pointer of the inner action. 1063 | @return A pointer of EaseQuarticActionIn action. If creation failed, return nil. 1064 | */ 1065 | public EaseQuarticActionIn(ActionInterval interval):base(interval) 1066 | { 1067 | } 1068 | 1069 | 1070 | 1071 | public override void LerpAction(float dt) 1072 | { 1073 | inner.LerpAction(tweenfunc.quartEaseIn (dt)); 1074 | } 1075 | 1076 | public override Action Clone() 1077 | { 1078 | // no copy constructor 1079 | if (inner!=null) 1080 | return new EaseQuarticActionIn((ActionInterval)inner.Clone()); 1081 | 1082 | return null; 1083 | } 1084 | 1085 | 1086 | 1087 | public override Action Reverse() 1088 | { 1089 | return new EaseQuarticActionIn((ActionInterval)inner.Reverse()); 1090 | } 1091 | }; 1092 | 1093 | 1094 | 1095 | 1096 | /** 1097 | @class EaseQuarticActionOut 1098 | @brief Ease Quartic Out 1099 | @ingroup Actions 1100 | */ 1101 | public class EaseQuarticActionOut : ActionEase 1102 | { 1103 | 1104 | /** 1105 | @brief Create the action with the inner action. 1106 | @param action The pointer of the inner action. 1107 | @return A pointer of EaseQuarticActionOut action. If creation failed, return nil. 1108 | */ 1109 | public EaseQuarticActionOut(ActionInterval interval):base(interval) 1110 | { 1111 | } 1112 | 1113 | 1114 | 1115 | public override void LerpAction(float dt) 1116 | { 1117 | inner.LerpAction(tweenfunc.quartEaseIn (dt)); 1118 | } 1119 | 1120 | public override Action Clone() 1121 | { 1122 | // no copy constructor 1123 | if (inner!=null) 1124 | return new EaseQuarticActionOut((ActionInterval)inner.Clone()); 1125 | 1126 | return null; 1127 | } 1128 | 1129 | 1130 | 1131 | public override Action Reverse() 1132 | { 1133 | return new EaseQuarticActionOut((ActionInterval)inner.Reverse()); 1134 | } 1135 | }; 1136 | 1137 | 1138 | 1139 | 1140 | 1141 | /** 1142 | @class EaseQuarticActionInOut 1143 | @brief Ease Quartic InOut 1144 | @ingroup Actions 1145 | */ 1146 | public class EaseQuarticActionInOut : ActionEase 1147 | { 1148 | 1149 | /** 1150 | @brief Create the action with the inner action. 1151 | @param action The pointer of the inner action. 1152 | @return A pointer of EaseQuarticActionInOut action. If creation failed, return nil. 1153 | */ 1154 | public EaseQuarticActionInOut(ActionInterval interval):base(interval) 1155 | { 1156 | } 1157 | 1158 | 1159 | 1160 | public override void LerpAction(float dt) 1161 | { 1162 | inner.LerpAction(tweenfunc.quartEaseInOut (dt)); 1163 | } 1164 | 1165 | public override Action Clone() 1166 | { 1167 | // no copy constructor 1168 | if (inner!=null) 1169 | return new EaseQuarticActionInOut((ActionInterval)inner.Clone()); 1170 | 1171 | return null; 1172 | } 1173 | 1174 | 1175 | 1176 | public override Action Reverse() 1177 | { 1178 | return new EaseQuarticActionInOut((ActionInterval)inner.Reverse()); 1179 | } 1180 | }; 1181 | 1182 | 1183 | 1184 | 1185 | 1186 | public class EaseQuinticActionIn : ActionEase 1187 | { 1188 | 1189 | /** 1190 | @brief Create the action with the inner action. 1191 | @param action The pointer of the inner action. 1192 | @return A pointer of EaseQuarticActionInOut action. If creation failed, return nil. 1193 | */ 1194 | public EaseQuinticActionIn(ActionInterval interval):base(interval) 1195 | { 1196 | } 1197 | 1198 | 1199 | 1200 | public override void LerpAction(float dt) 1201 | { 1202 | inner.LerpAction(tweenfunc.quintEaseIn (dt)); 1203 | } 1204 | 1205 | public override Action Clone() 1206 | { 1207 | // no copy constructor 1208 | if (inner!=null) 1209 | return new EaseQuinticActionIn((ActionInterval)inner.Clone()); 1210 | 1211 | return null; 1212 | } 1213 | 1214 | 1215 | 1216 | public override Action Reverse() 1217 | { 1218 | return new EaseQuinticActionIn((ActionInterval)inner.Reverse()); 1219 | } 1220 | }; 1221 | 1222 | public class EaseQuinticActionOut : ActionEase 1223 | { 1224 | 1225 | /** 1226 | @brief Create the action with the inner action. 1227 | @param action The pointer of the inner action. 1228 | @return A pointer of EaseQuarticActionInOut action. If creation failed, return nil. 1229 | */ 1230 | public EaseQuinticActionOut(ActionInterval interval):base(interval) 1231 | { 1232 | } 1233 | 1234 | 1235 | 1236 | public override void LerpAction(float dt) 1237 | { 1238 | inner.LerpAction(tweenfunc.quintEaseOut (dt)); 1239 | } 1240 | 1241 | public override Action Clone() 1242 | { 1243 | // no copy constructor 1244 | if (inner!=null) 1245 | return new EaseQuinticActionOut((ActionInterval)inner.Clone()); 1246 | 1247 | return null; 1248 | } 1249 | 1250 | 1251 | 1252 | public override Action Reverse() 1253 | { 1254 | return new EaseQuinticActionOut((ActionInterval)inner.Reverse()); 1255 | } 1256 | }; 1257 | 1258 | 1259 | 1260 | public class EaseQuinticActionInOut : ActionEase 1261 | { 1262 | 1263 | /** 1264 | @brief Create the action with the inner action. 1265 | @param action The pointer of the inner action. 1266 | @return A pointer of EaseQuarticActionInOut action. If creation failed, return nil. 1267 | */ 1268 | public EaseQuinticActionInOut(ActionInterval interval):base(interval) 1269 | { 1270 | } 1271 | 1272 | 1273 | 1274 | public override void LerpAction(float dt) 1275 | { 1276 | inner.LerpAction(tweenfunc.quintEaseInOut (dt)); 1277 | } 1278 | 1279 | public override Action Clone() 1280 | { 1281 | // no copy constructor 1282 | if (inner!=null) 1283 | return new EaseQuinticActionInOut((ActionInterval)inner.Clone()); 1284 | 1285 | return null; 1286 | } 1287 | 1288 | 1289 | 1290 | public override Action Reverse() 1291 | { 1292 | return new EaseQuinticActionInOut((ActionInterval)inner.Reverse()); 1293 | } 1294 | }; 1295 | 1296 | 1297 | 1298 | 1299 | 1300 | 1301 | public class EaseCircleActionIn : ActionEase 1302 | { 1303 | 1304 | /** 1305 | @brief Create the action with the inner action. 1306 | @param action The pointer of the inner action. 1307 | @return A pointer of EaseQuarticActionInOut action. If creation failed, return nil. 1308 | */ 1309 | public EaseCircleActionIn(ActionInterval interval):base(interval) 1310 | { 1311 | } 1312 | 1313 | 1314 | 1315 | public override void LerpAction(float dt) 1316 | { 1317 | inner.LerpAction(tweenfunc.circEaseIn (dt)); 1318 | } 1319 | 1320 | public override Action Clone() 1321 | { 1322 | // no copy constructor 1323 | if (inner!=null) 1324 | return new EaseCircleActionIn((ActionInterval)inner.Clone()); 1325 | 1326 | return null; 1327 | } 1328 | 1329 | 1330 | 1331 | public override Action Reverse() 1332 | { 1333 | return new EaseCircleActionIn((ActionInterval)inner.Reverse()); 1334 | } 1335 | }; 1336 | 1337 | public class EaseCircleActionOut : ActionEase 1338 | { 1339 | 1340 | /** 1341 | @brief Create the action with the inner action. 1342 | @param action The pointer of the inner action. 1343 | @return A pointer of EaseQuarticActionInOut action. If creation failed, return nil. 1344 | */ 1345 | public EaseCircleActionOut(ActionInterval interval):base(interval) 1346 | { 1347 | } 1348 | 1349 | 1350 | 1351 | public override void LerpAction(float dt) 1352 | { 1353 | inner.LerpAction(tweenfunc.circEaseOut (dt)); 1354 | } 1355 | 1356 | public override Action Clone() 1357 | { 1358 | // no copy constructor 1359 | if (inner!=null) 1360 | return new EaseCircleActionOut((ActionInterval)inner.Clone()); 1361 | 1362 | return null; 1363 | } 1364 | 1365 | 1366 | 1367 | public override Action Reverse() 1368 | { 1369 | return new EaseCircleActionOut((ActionInterval)inner.Reverse()); 1370 | } 1371 | }; 1372 | 1373 | 1374 | 1375 | 1376 | 1377 | 1378 | 1379 | 1380 | public class EaseCircleActionInOut : ActionEase 1381 | { 1382 | 1383 | /** 1384 | @brief Create the action with the inner action. 1385 | @param action The pointer of the inner action. 1386 | @return A pointer of EaseQuarticActionInOut action. If creation failed, return nil. 1387 | */ 1388 | public EaseCircleActionInOut(ActionInterval interval):base(interval) 1389 | { 1390 | } 1391 | 1392 | 1393 | 1394 | public override void LerpAction(float dt) 1395 | { 1396 | inner.LerpAction(tweenfunc.circEaseInOut (dt)); 1397 | } 1398 | 1399 | public override Action Clone() 1400 | { 1401 | // no copy constructor 1402 | if (inner!=null) 1403 | return new EaseCircleActionInOut((ActionInterval)inner.Clone()); 1404 | 1405 | return null; 1406 | } 1407 | 1408 | 1409 | 1410 | public override Action Reverse() 1411 | { 1412 | return new EaseCircleActionInOut((ActionInterval)inner.Reverse()); 1413 | } 1414 | }; 1415 | 1416 | 1417 | 1418 | 1419 | 1420 | 1421 | public class EaseCubicActionIn : ActionEase 1422 | { 1423 | 1424 | /** 1425 | @brief Create the action with the inner action. 1426 | @param action The pointer of the inner action. 1427 | @return A pointer of EaseQuarticActionInOut action. If creation failed, return nil. 1428 | */ 1429 | public EaseCubicActionIn(ActionInterval interval):base(interval) 1430 | { 1431 | } 1432 | 1433 | 1434 | 1435 | public override void LerpAction(float dt) 1436 | { 1437 | inner.LerpAction(tweenfunc.cubicEaseIn (dt)); 1438 | } 1439 | 1440 | public override Action Clone() 1441 | { 1442 | // no copy constructor 1443 | if (inner!=null) 1444 | return new EaseCubicActionIn((ActionInterval)inner.Clone()); 1445 | 1446 | return null; 1447 | } 1448 | 1449 | 1450 | 1451 | public override Action Reverse() 1452 | { 1453 | return new EaseCubicActionIn((ActionInterval)inner.Reverse()); 1454 | } 1455 | }; 1456 | 1457 | 1458 | 1459 | 1460 | public class EaseCubicActionOut : ActionEase 1461 | { 1462 | 1463 | /** 1464 | @brief Create the action with the inner action. 1465 | @param action The pointer of the inner action. 1466 | @return A pointer of EaseQuarticActionInOut action. If creation failed, return nil. 1467 | */ 1468 | public EaseCubicActionOut(ActionInterval interval):base(interval) 1469 | { 1470 | } 1471 | 1472 | 1473 | 1474 | public override void LerpAction(float dt) 1475 | { 1476 | inner.LerpAction(tweenfunc.cubicEaseOut (dt)); 1477 | } 1478 | 1479 | public override Action Clone() 1480 | { 1481 | // no copy constructor 1482 | if (inner!=null) 1483 | return new EaseCubicActionOut((ActionInterval)inner.Clone()); 1484 | 1485 | return null; 1486 | } 1487 | 1488 | 1489 | 1490 | public override Action Reverse() 1491 | { 1492 | return new EaseCubicActionOut((ActionInterval)inner.Reverse()); 1493 | } 1494 | }; 1495 | 1496 | 1497 | 1498 | public class EaseCubicActionInOut : ActionEase 1499 | { 1500 | 1501 | /** 1502 | @brief Create the action with the inner action. 1503 | @param action The pointer of the inner action. 1504 | @return A pointer of EaseQuarticActionInOut action. If creation failed, return nil. 1505 | */ 1506 | public EaseCubicActionInOut(ActionInterval interval):base(interval) 1507 | { 1508 | } 1509 | 1510 | 1511 | 1512 | public override void LerpAction(float dt) 1513 | { 1514 | inner.LerpAction(tweenfunc.cubicEaseInOut (dt)); 1515 | } 1516 | 1517 | public override Action Clone() 1518 | { 1519 | // no copy constructor 1520 | if (inner!=null) 1521 | return new EaseCubicActionInOut((ActionInterval)inner.Clone()); 1522 | 1523 | return null; 1524 | } 1525 | 1526 | 1527 | 1528 | public override Action Reverse() 1529 | { 1530 | return new EaseCubicActionInOut((ActionInterval)inner.Reverse()); 1531 | } 1532 | }; 1533 | 1534 | 1535 | } 1536 | 1537 | --------------------------------------------------------------------------------