From 1eb196b076778e63c8edef047e4fe560e68998a9 Mon Sep 17 00:00:00 2001 From: Shakthi Prasad G S Date: Sun, 19 Jul 2015 22:23:45 +0530 Subject: [PATCH 01/15] Welcome to actor. --- .../Scripts/TestCases/TestActions.cs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/Assets/Plugins/UnityActions/Scripts/TestCases/TestActions.cs b/Assets/Plugins/UnityActions/Scripts/TestCases/TestActions.cs index bedb880..f2e6b10 100644 --- a/Assets/Plugins/UnityActions/Scripts/TestCases/TestActions.cs +++ b/Assets/Plugins/UnityActions/Scripts/TestCases/TestActions.cs @@ -6,6 +6,14 @@ public class TestActions : MonoBehaviour { public Transform movingObject; + + IEnumerator anANimtion() + { + var anActor = new Actor(movingObject); + yield return anActor.MoveBy(10,new Vector3(10,10,10)); + yield return anActor.MoveTo(4,new Vector3(10,10,10)); + } + void Start () { // Action.Run(movingObject,new MoveBy(10 ,new Vector3(10,1,1))); @@ -13,9 +21,9 @@ void Start () // - Action.Run(movingObject,new Spawn(new MoveBy(10 ,new Vector3(10,1,1)),new MoveBy(10,new Vector3(0,30,0)),new RotateBy(10,new Vector3(0,180,0)))); - // Action.Run(movingObject,new RotateBy(5,new Vector3(10,0,0))); - // +// Action.Run(movingObject,new Spawn(new MoveBy(10 ,new Vector3(10,1,1)),new MoveBy(10,new Vector3(0,30,0)),new RotateBy(10,new Vector3(0,180,0)))); +// // Action.Run(movingObject,new RotateBy(5,new Vector3(10,0,0))); +// // // Sequence q= new Sequence(new MoveBy(3 ,new Vector3(10,1,1)), // new RotateBy(5,new Vector3(180,0,0)), @@ -33,6 +41,10 @@ void Start () //Action.Run(movingObject,new RepeatForever(new RotateBy(0.5f,new Vector3(10,0,0)))); + + + StartCoroutine(anANimtion); + } void Update () From cfc45e00e542ef6f93d05ec22bfb6334a3f304ee Mon Sep 17 00:00:00 2001 From: Shakthi Prasad G S Date: Mon, 20 Jul 2015 07:04:15 +0530 Subject: [PATCH 02/15] Added implemented action actions (Code is failed to work) --- .../UnityActions/Scripts/Actions/Actor.cs | 53 +++++++++++++++++++ .../Scripts/Actions/Actor.cs.meta | 12 +++++ .../Scripts/TestCases/TestActions.cs | 2 +- 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 Assets/Plugins/UnityActions/Scripts/Actions/Actor.cs create mode 100644 Assets/Plugins/UnityActions/Scripts/Actions/Actor.cs.meta diff --git a/Assets/Plugins/UnityActions/Scripts/Actions/Actor.cs b/Assets/Plugins/UnityActions/Scripts/Actions/Actor.cs new file mode 100644 index 0000000..945a94a --- /dev/null +++ b/Assets/Plugins/UnityActions/Scripts/Actions/Actor.cs @@ -0,0 +1,53 @@ +using UnityEngine; +using System.Collections; + + +namespace CC +{ + +public class Actor { + + Transform transform; + FiniteTimeAction action; + + public Actor(Transform transform) + { + this.transform=transform; + } + + + public IEnumerator RunAction(FiniteTimeAction anAction) + { + if(action !=null) + Debug.LogError("An action is already running"); + else + { + action = anAction; + + Action.Run(transform,action); + yield return new WaitForSeconds(action.GetDuration()); + while(!action.IsDone()) + { + yield return null; + } + action=null; + } + + } + + public IEnumerator MoveBy(float duraction,Vector3 diff) + { + Debug.Log("Comming here"); + + yield return RunAction(new CC.MoveBy(duraction,diff)); + } + + public IEnumerator MoveTo(float duraction,Vector3 destination) + { + Debug.Log("Comming here"); + yield return RunAction(new CC.MoveTo(duraction,destination)); + } + + +} +} \ No newline at end of file diff --git a/Assets/Plugins/UnityActions/Scripts/Actions/Actor.cs.meta b/Assets/Plugins/UnityActions/Scripts/Actions/Actor.cs.meta new file mode 100644 index 0000000..6afca56 --- /dev/null +++ b/Assets/Plugins/UnityActions/Scripts/Actions/Actor.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: cc8320165bac94ccea2209b0d7bfb374 +timeCreated: 1437353674 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/UnityActions/Scripts/TestCases/TestActions.cs b/Assets/Plugins/UnityActions/Scripts/TestCases/TestActions.cs index f2e6b10..e53c590 100644 --- a/Assets/Plugins/UnityActions/Scripts/TestCases/TestActions.cs +++ b/Assets/Plugins/UnityActions/Scripts/TestCases/TestActions.cs @@ -43,7 +43,7 @@ void Start () - StartCoroutine(anANimtion); + StartCoroutine(anANimtion()); } From 8deac85181dedf5fe64b70d15bc265a988db6023 Mon Sep 17 00:00:00 2001 From: Shakthi Prasad G S Date: Fri, 31 Jul 2015 08:24:08 +0530 Subject: [PATCH 03/15] Actor script working --- Assets/Plugins/UnityActions/Scripts/Actions/Actor.cs | 8 ++++---- .../Plugins/UnityActions/Scripts/TestCases/TestActions.cs | 8 ++++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Assets/Plugins/UnityActions/Scripts/Actions/Actor.cs b/Assets/Plugins/UnityActions/Scripts/Actions/Actor.cs index 945a94a..1980d03 100644 --- a/Assets/Plugins/UnityActions/Scripts/Actions/Actor.cs +++ b/Assets/Plugins/UnityActions/Scripts/Actions/Actor.cs @@ -37,15 +37,15 @@ public IEnumerator RunAction(FiniteTimeAction anAction) public IEnumerator MoveBy(float duraction,Vector3 diff) { - Debug.Log("Comming here"); - yield return RunAction(new CC.MoveBy(duraction,diff)); + + + return RunAction(new CC.MoveBy(duraction,diff)); } public IEnumerator MoveTo(float duraction,Vector3 destination) { - Debug.Log("Comming here"); - yield return RunAction(new CC.MoveTo(duraction,destination)); + return RunAction(new CC.MoveTo(duraction,destination)); } diff --git a/Assets/Plugins/UnityActions/Scripts/TestCases/TestActions.cs b/Assets/Plugins/UnityActions/Scripts/TestCases/TestActions.cs index e53c590..cecc77b 100644 --- a/Assets/Plugins/UnityActions/Scripts/TestCases/TestActions.cs +++ b/Assets/Plugins/UnityActions/Scripts/TestCases/TestActions.cs @@ -10,8 +10,12 @@ public class TestActions : MonoBehaviour IEnumerator anANimtion() { var anActor = new Actor(movingObject); - yield return anActor.MoveBy(10,new Vector3(10,10,10)); - yield return anActor.MoveTo(4,new Vector3(10,10,10)); + yield return StartCoroutine(anActor.MoveBy(3,new Vector3(10,10,10))); + + Debug.Log("y"); + + yield return StartCoroutine(anActor.MoveTo(4,new Vector3(0,0,0))); + Debug.Log("z"); } void Start () From 1c89d97deaf1733d608ddb8ddc7e4e1606d70e90 Mon Sep 17 00:00:00 2001 From: Shakthi Prasad G S Date: Sat, 1 Aug 2015 13:51:36 +0530 Subject: [PATCH 04/15] syntax sugar for actor --- .../UnityActions/Scripts/Actions/Actor.cs | 59 +++++++++++++++---- .../Scripts/TestCases/TestActions.cs | 8 +-- 2 files changed, 50 insertions(+), 17 deletions(-) diff --git a/Assets/Plugins/UnityActions/Scripts/Actions/Actor.cs b/Assets/Plugins/UnityActions/Scripts/Actions/Actor.cs index 1980d03..5c41a53 100644 --- a/Assets/Plugins/UnityActions/Scripts/Actions/Actor.cs +++ b/Assets/Plugins/UnityActions/Scripts/Actions/Actor.cs @@ -5,10 +5,37 @@ namespace CC { + + + public class Director:MonoBehaviour + { + + public static Director Setup(Actor actor) + { + Director runner = actor.transform.GetComponent(); + if(runner == null) + { + runner = actor.transform.gameObject.AddComponent(); + } + + + return runner; + } + + } + + + + + + public class Actor { - Transform transform; - FiniteTimeAction action; + + + + public Transform transform; + public FiniteTimeAction action; public Actor(Transform transform) { @@ -16,14 +43,20 @@ public Actor(Transform transform) } - public IEnumerator RunAction(FiniteTimeAction anAction) - { + + + + + + + public IEnumerator YieldAction(FiniteTimeAction anAction) + { if(action !=null) Debug.LogError("An action is already running"); else { action = anAction; - + Action.Run(transform,action); yield return new WaitForSeconds(action.GetDuration()); while(!action.IsDone()) @@ -33,19 +66,21 @@ public IEnumerator RunAction(FiniteTimeAction anAction) action=null; } - } - - public IEnumerator MoveBy(float duraction,Vector3 diff) - { + + } - return RunAction(new CC.MoveBy(duraction,diff)); + public Coroutine MoveBy(float duraction,Vector3 diff) + { + Director runner =Director.Setup(this); + return runner.StartCoroutine(YieldAction(new CC.MoveBy(duraction,diff))); } - public IEnumerator MoveTo(float duraction,Vector3 destination) + public Coroutine MoveTo(float duraction,Vector3 destination) { - return RunAction(new CC.MoveTo(duraction,destination)); + Director runner =Director.Setup(this); + return runner.StartCoroutine(YieldAction(new CC.MoveTo(duraction,destination))); } diff --git a/Assets/Plugins/UnityActions/Scripts/TestCases/TestActions.cs b/Assets/Plugins/UnityActions/Scripts/TestCases/TestActions.cs index cecc77b..8e3bcd3 100644 --- a/Assets/Plugins/UnityActions/Scripts/TestCases/TestActions.cs +++ b/Assets/Plugins/UnityActions/Scripts/TestCases/TestActions.cs @@ -9,13 +9,11 @@ public class TestActions : MonoBehaviour IEnumerator anANimtion() { - var anActor = new Actor(movingObject); - yield return StartCoroutine(anActor.MoveBy(3,new Vector3(10,10,10))); + var anActor = new Actor(movingObject); + yield return anActor.MoveBy(3,new Vector3(10,10,10)); + yield return anActor.MoveTo(4,new Vector3(0,0,0)); - Debug.Log("y"); - yield return StartCoroutine(anActor.MoveTo(4,new Vector3(0,0,0))); - Debug.Log("z"); } void Start () From 9daf8f7e3cf945b55761b402123b96f3e37487b7 Mon Sep 17 00:00:00 2001 From: Shakthi Prasad G S Date: Sun, 2 Aug 2015 00:12:11 +0530 Subject: [PATCH 05/15] Generalized actor actions --- .../UnityActions/Scripts/Actions/Actor.cs | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/Assets/Plugins/UnityActions/Scripts/Actions/Actor.cs b/Assets/Plugins/UnityActions/Scripts/Actions/Actor.cs index 5c41a53..8481f7d 100644 --- a/Assets/Plugins/UnityActions/Scripts/Actions/Actor.cs +++ b/Assets/Plugins/UnityActions/Scripts/Actions/Actor.cs @@ -70,18 +70,23 @@ public IEnumerator YieldAction(FiniteTimeAction anAction) } - - public Coroutine MoveBy(float duraction,Vector3 diff) - { + public Coroutine PerformAction(FiniteTimeAction anAction) + { Director runner =Director.Setup(this); - return runner.StartCoroutine(YieldAction(new CC.MoveBy(duraction,diff))); - } + return runner.StartCoroutine(YieldAction(anAction)); - public Coroutine MoveTo(float duraction,Vector3 destination) - { - Director runner =Director.Setup(this); - return runner.StartCoroutine(YieldAction(new CC.MoveTo(duraction,destination))); - } + } + + public Coroutine MoveBy(float aduration,Vector3 diff) + { + return PerformAction(new CC.MoveBy(aduration,diff)); + + } + + public Coroutine MoveTo(float duraction,Vector3 targetPos) + { + return PerformAction(new CC.MoveTo(duraction,targetPos)); + } } From fac738d774ca4677cbe598bc8a9a01222bca2f69 Mon Sep 17 00:00:00 2001 From: Shakthi Prasad G S Date: Sun, 2 Aug 2015 21:48:41 +0530 Subject: [PATCH 06/15] Added clone and reverse actions --- .../UnityActions/Scripts/Actions/Action.cs | 37 +++- .../Scripts/Actions/ActionInterval.cs | 171 ++++++++++++++++-- 2 files changed, 179 insertions(+), 29 deletions(-) diff --git a/Assets/Plugins/UnityActions/Scripts/Actions/Action.cs b/Assets/Plugins/UnityActions/Scripts/Actions/Action.cs index a5379da..aaa0deb 100644 --- a/Assets/Plugins/UnityActions/Scripts/Actions/Action.cs +++ b/Assets/Plugins/UnityActions/Scripts/Actions/Action.cs @@ -4,7 +4,7 @@ namespace CC { - public class Action : BaseAction + public abstract class Action : BaseAction { protected Transform target; bool isStarted; @@ -21,14 +21,9 @@ public static void Run(Transform targetTransform ,Action anAction) ActionRunner.Setup(targetTransform,anAction); } - public virtual void LerpAction(float delta) - { - } + public abstract void LerpAction(float delta); - public virtual void Update(float delta) - { - - } + public abstract void Update(float delta); public virtual void StartWithTarget(Transform inTarget) { @@ -45,6 +40,20 @@ public virtual bool IsDone() { return true; } + + + + + + /** Returns a new action that performs the exactly the reverse action. + * + * @return A new action that performs the exactly the reverse action. + */ + public abstract Action Reverse() ; + + + public abstract Action Clone(); + } @@ -57,7 +66,7 @@ public virtual bool IsDone() * Infinite time actions are valid. */ - public class FiniteTimeAction : Action + public abstract class FiniteTimeAction : Action { protected float duration; @@ -65,6 +74,16 @@ public float GetDuration() { return duration; } + + public FiniteTimeAction(float aduration) + { + duration = aduration; + } + + + + + } } diff --git a/Assets/Plugins/UnityActions/Scripts/Actions/ActionInterval.cs b/Assets/Plugins/UnityActions/Scripts/Actions/ActionInterval.cs index bf9cad1..0d66b9f 100644 --- a/Assets/Plugins/UnityActions/Scripts/Actions/ActionInterval.cs +++ b/Assets/Plugins/UnityActions/Scripts/Actions/ActionInterval.cs @@ -20,7 +20,7 @@ then running it again in Reverse mode. Example: Action *pingPongAction = Sequence::actions(action, action.reverse(), nullptr); */ - public class ActionInterval : FiniteTimeAction + public abstract class ActionInterval : FiniteTimeAction { float completedTime; bool isFirstTick; @@ -29,11 +29,11 @@ public float GetCompletedTime() { return completedTime; } - protected ActionInterval() + protected ActionInterval():base(0) { } - public ActionInterval(float duration) + public ActionInterval(float duration):base(duration) { completedTime = 0; this.duration = duration; @@ -83,8 +83,28 @@ public override void StartWithTarget(Transform inTarget) // Extra action for making a Sequence or Spawn when only adding one action to it. class ExtraAction : FiniteTimeAction { - public ExtraAction() + public ExtraAction():base(0) {} + + public override void LerpAction (float delta) + { + + } + + public override void Update (float delta) + { + + } + + public override Action Reverse () + { + return new ExtraAction(); + } + + public override Action Clone () + { + return new ExtraAction(); + } }; @@ -169,14 +189,7 @@ private Sequence( bool dummy,FiniteTimeAction[] list):base(1) } - public Sequence( FiniteTimeAction action1,FiniteTimeAction action2) - { - float totalduration = action1.GetDuration()+action2.GetDuration(); - duration = totalduration; - finiteTimeActions[0]=action1; - finiteTimeActions[1]=action2; - } @@ -262,10 +275,28 @@ public override void LerpAction(float t) - + public Sequence( FiniteTimeAction action1,FiniteTimeAction action2) + { + float totalduration = action1.GetDuration()+action2.GetDuration(); + duration = totalduration; + + finiteTimeActions[0]=action1; + finiteTimeActions[1]=action2; + } + public override Action Reverse () + { + FiniteTimeAction action1 = finiteTimeActions[1].Reverse() as FiniteTimeAction; + FiniteTimeAction action0 = finiteTimeActions[0].Reverse() as FiniteTimeAction ; + return new Sequence(action1,action0); + } + + public override Action Clone () + { + return new Sequence(finiteTimeActions[0].Clone() as FiniteTimeAction,finiteTimeActions[1].Clone() as FiniteTimeAction); + } } @@ -359,7 +390,15 @@ public override bool IsDone() return _total == _times; } + public override Action Reverse() + { + return new Repeat(_innerAction.Reverse() as FiniteTimeAction, _times); + } + public override Action Clone() + { + return new Repeat(_innerAction.Clone() as FiniteTimeAction, _times); + } @@ -412,10 +451,21 @@ public override bool IsDone() return false; } -// RepeatForever Reverse() const -// { -// return RepeatForever::create(_innerAction->reverse()); -// } + public override Action Reverse() + { + return new RepeatForever(_innerAction.Reverse() as ActionInterval); + } + + + public override Action Clone() + { + return new RepeatForever(_innerAction as ActionInterval); + } + + public override void LerpAction (float delta) + { + throw new System.NotImplementedException (); + } // }; @@ -435,7 +485,10 @@ public DelayTime(float d):base(d) } - + + + + // // Overrides // @@ -445,7 +498,22 @@ public DelayTime(float d):base(d) public override void LerpAction(float time) { + } + + + + public override Action Reverse() + { + return new DelayTime(duration); + } + + + public override Action Clone() + { + return new DelayTime(duration); + } + }; @@ -562,7 +630,18 @@ public override void LerpAction(float time) protected FiniteTimeAction _one; protected FiniteTimeAction _two; - + + + public override Action Clone() + { + return new Spawn(_one.Clone() as FiniteTimeAction,_two.Clone() as FiniteTimeAction); + } + + public override Action Reverse() + { + return new Spawn(_one.Reverse() as FiniteTimeAction ,_two.Reverse() as FiniteTimeAction ); + } + }; @@ -584,7 +663,18 @@ public MoveTo(float duration ,Vector3 endPosition ):base(duration) { this.endPosition = endPosition; } - + + public override Action Reverse () + { + throw new System.NotImplementedException (); + } + + + public override Action Clone () + { + return new MoveTo(duration,endPosition); + } + public override void LerpAction(float deltaTime) { target.position = Vector3.Lerp(startPosition,endPosition,deltaTime); @@ -635,6 +725,18 @@ public override void StartWithTarget(Transform inTarget) base.StartWithTarget(inTarget); _previousPosition = startPosition = inTarget.position; } + + public override Action Reverse () + { + return new MoveBy(duration,-_positionDelta); + } + + + public override Action Clone () + { + return new MoveBy(duration,_positionDelta); + } + } @@ -652,6 +754,12 @@ public RotateTo(float duration, Vector3 dstAngle3D):base(duration) _dstAngle = Quaternion.Euler(dstAngle3D); } + + public RotateTo(float duration, Quaternion deltaAngle3D):base(duration) + { + _diffAngle = deltaAngle3D; + + } public override void LerpAction(float deltaTime) @@ -667,7 +775,16 @@ public override void StartWithTarget(Transform inTarget) } - + public override Action Reverse () + { + throw new System.NotImplementedException (); + } + + public override Action Clone () + { + return new RotateTo(duration,_dstAngle); + } + protected Quaternion _dstAngle; protected Quaternion _startRotation; @@ -689,6 +806,12 @@ public RotateBy(float duration, Vector3 deltaAngle3D):base(duration) _diffAngle = Quaternion.Euler(deltaAngle3D); } + + public RotateBy(float duration, Quaternion deltaAngle3D):base(duration) + { + _diffAngle = deltaAngle3D; + + } public override void LerpAction(float deltaTime) @@ -703,7 +826,15 @@ public override void StartWithTarget(Transform inTarget) _dstAngle = _diffAngle * _startRotation; } + public override Action Reverse () + { + return new RotateTo(duration,Quaternion.Inverse( _diffAngle)); + } + public override Action Clone () + { + return new RotateTo(duration,_diffAngle); + } protected Quaternion _dstAngle; From 27605bf474e48e3b1543e23d70f92e31f6436fda Mon Sep 17 00:00:00 2001 From: Shakthi Prasad G S Date: Mon, 3 Aug 2015 00:15:04 +0530 Subject: [PATCH 07/15] Added jump by --- .../Scripts/Actions/ActionInterval.cs | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/Assets/Plugins/UnityActions/Scripts/Actions/ActionInterval.cs b/Assets/Plugins/UnityActions/Scripts/Actions/ActionInterval.cs index 0d66b9f..336147f 100644 --- a/Assets/Plugins/UnityActions/Scripts/Actions/ActionInterval.cs +++ b/Assets/Plugins/UnityActions/Scripts/Actions/ActionInterval.cs @@ -843,8 +843,93 @@ public override Action Clone () }; + + + + + public class JumpBy : ActionInterval + { + /** + * Creates the action. + * @param duration Duration time, in seconds. + * @param position The jumping distance. + * @param height The jumping height. + * @param jumps The jumping times. + * + */ + public JumpBy(float aduration, Vector3 position, float height, int jumps):base(aduration) + { + _delta = position; + _height = height; + _jumps = jumps; + + } + + // + // Overrides + // + public override Action Clone () + { + return new JumpBy(duration,_delta,_height,_jumps); + } + + + + public override Action Reverse () + { + return new JumpBy(duration,-_delta,_height,_jumps); + } + public override void StartWithTarget(Transform aTransform) + { + base.StartWithTarget(aTransform); + _previousPos = _startPosition = aTransform.position; + + } + /** + * @param time In seconds. + */ + public override void LerpAction(float t) + { + //TODO: Implement 3d jump + // parabolic jump (since v0.8.2) + if (target) + { + float frac = (t * _jumps)% 1.0f ; + float y = _height * 4 * frac * (1 - frac); + y += _delta.y * t; + float x = _delta.x * t; + //#if CC_ENABLE_STACKABLE_ACTIONS + Vector3 currentPos = target.position; + Vector3 diff = currentPos - _previousPos; + _startPosition = diff + _startPosition; + Vector3 newPos = _startPosition + new Vector3(x,y,0); + target.position= newPos; + _previousPos = newPos; +// #else +// _target->setPosition(_startPosition + Vec2(x,y)); +// #endif // !CC_ENABLE_STACKABLE_ACTIONS + } + } + + + protected Vector3 _startPosition; + protected Vector3 _delta; + protected float _height; + protected int _jumps; + protected Vector3 _previousPos; + + }; + + + + + + + + + From 57c7aeac62b42fbac5a3119a83083fe3be155e3e Mon Sep 17 00:00:00 2001 From: Shakthi Prasad G S Date: Sun, 16 Aug 2015 23:34:21 +0530 Subject: [PATCH 08/15] Fixed actor --- .../UnityActions/Scripts/Actions/Actor.cs | 45 +++++-------------- .../Scripts/TestCases/TestActions.cs | 13 ++++-- 2 files changed, 21 insertions(+), 37 deletions(-) diff --git a/Assets/Plugins/UnityActions/Scripts/Actions/Actor.cs b/Assets/Plugins/UnityActions/Scripts/Actions/Actor.cs index 8481f7d..14d42e5 100644 --- a/Assets/Plugins/UnityActions/Scripts/Actions/Actor.cs +++ b/Assets/Plugins/UnityActions/Scripts/Actions/Actor.cs @@ -7,42 +7,22 @@ namespace CC - public class Director:MonoBehaviour - { - - public static Director Setup(Actor actor) - { - Director runner = actor.transform.GetComponent(); - if(runner == null) - { - runner = actor.transform.gameObject.AddComponent(); - } - - - return runner; - } - - } - - - +public class Actor:MonoBehaviour { - - -public class Actor { - - - - - public Transform transform; public FiniteTimeAction action; - public Actor(Transform transform) - { - this.transform=transform; - } + + static public Actor GetActor(Transform intransform) + { + Actor actor = intransform.GetComponent(); + if(actor == null) + { + actor = intransform.gameObject.AddComponent(); + } + return actor; + } @@ -72,8 +52,7 @@ public IEnumerator YieldAction(FiniteTimeAction anAction) public Coroutine PerformAction(FiniteTimeAction anAction) { - Director runner =Director.Setup(this); - return runner.StartCoroutine(YieldAction(anAction)); + return StartCoroutine(YieldAction(anAction)); } diff --git a/Assets/Plugins/UnityActions/Scripts/TestCases/TestActions.cs b/Assets/Plugins/UnityActions/Scripts/TestCases/TestActions.cs index 8e3bcd3..39d87f8 100644 --- a/Assets/Plugins/UnityActions/Scripts/TestCases/TestActions.cs +++ b/Assets/Plugins/UnityActions/Scripts/TestCases/TestActions.cs @@ -7,12 +7,17 @@ public class TestActions : MonoBehaviour public Transform movingObject; - IEnumerator anANimtion() + IEnumerator anAnimation() { - var anActor = new Actor(movingObject); - yield return anActor.MoveBy(3,new Vector3(10,10,10)); + Actor anActor = Actor.GetActor(movingObject); + yield return anActor.MoveBy(3,new Vector3(10,10,10)); + + Debug.Log("Now cube must be at the top of the screen"); + + yield return anActor.MoveTo(4,new Vector3(0,0,0)); + Debug.Log("Both the action completed now must be completed at 4+3=7 seconds"); } @@ -45,7 +50,7 @@ void Start () - StartCoroutine(anANimtion()); + StartCoroutine(anAnimation()); } From a19103894058734c1bb8a7144d673cd769ea5386 Mon Sep 17 00:00:00 2001 From: Shakthi Prasad G S Date: Mon, 17 Aug 2015 00:02:09 +0530 Subject: [PATCH 09/15] Updated md file --- README.md | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ad1b61d..7de466d 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,21 @@ -# UnityActions -This is Port of Cocos2d actions to unity. Enjoy! Hoped to replace *-tween libraries. +# Unity Actions +Unity Actions is a port of Cocos2d actions to unity. +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. -Making an animation may not be simpler than this. - +With actiobs making an animation may not be simpler than this. +```c# Action.Run(aTransform,new MoveBy(10 ,new Vector3(10,1,1))); +``` +Above code move transforms 'aTransform' by Vector3(10,1,1) in 10 seconds. Now this basic one, more complex example follows. +```c# + Sequence q= new Sequence(new MoveBy(3 ,new Vector3(10,1,1)), + new RotateBy(5,new Vector3(180,0,0)), + new MoveBy(3 ,new Vector3(-10,1,1)), + new RotateBy(3,new Vector3(0,60,0)) + + ); + Action.Run(movingObject, new Repeat(q,2)); + +``` \ No newline at end of file From ff33c5a28ddb6534925c83ffa2c5aeb78234d6f9 Mon Sep 17 00:00:00 2001 From: Shakthi Prasad G S Date: Mon, 17 Aug 2015 00:35:14 +0530 Subject: [PATCH 10/15] Updated readme --- README.md | 63 +++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 54 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 7de466d..977a7ab 100644 --- a/README.md +++ b/README.md @@ -4,18 +4,63 @@ Unity Actions is a port of Cocos2d actions to unity. 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. -With actiobs making an animation may not be simpler than this. +With actions, making an animation may not be simpler than this. ```c# Action.Run(aTransform,new MoveBy(10 ,new Vector3(10,1,1))); ``` -Above code move transforms 'aTransform' by Vector3(10,1,1) in 10 seconds. Now this basic one, more complex example follows. +Above code move transforms 'aTransform' by Vector3(10,1,1) in 10 seconds. Now this is basic one, more complex example follows. ```c# - Sequence q= new Sequence(new MoveBy(3 ,new Vector3(10,1,1)), - new RotateBy(5,new Vector3(180,0,0)), - new MoveBy(3 ,new Vector3(-10,1,1)), - new RotateBy(3,new Vector3(0,60,0)) + Sequence seq= new Sequence(new MoveBy(3 ,new Vector3(10,1,1)), + new RotateBy(5,new Vector3(180,0,0)), + new MoveBy(3 ,new Vector3(-10,1,1)), + new RotateBy(3,new Vector3(0,60,0)) + ); + + Action.Run(movingObject, new Repeat(seq,2)); - ); - Action.Run(movingObject, new Repeat(q,2)); +``` +That must be self-explanatory. + +# Welcome Actors! +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. + +```c# +public Transform movingObject; + +IEnumerator anAnimation() +{ + Actor anActor = Actor.GetActor(movingObject); + yield return anActor.MoveBy(3,new Vector3(10,10,10)); + + Debug.Log("Now cube must be at the top of the screen"); + + yield return anActor.MoveTo(4,new Vector3(0,0,0)); + + Debug.Log("Both the action completed now must be completed at 4+3=7 seconds"); +} + +void Start() +{ + StartCoroutine(anAnimation()); +} +``` +Code you see here is *actually* part of **Actor** testcase! Isn't it intutive, and as simple as writing a *screenwriting*. +## Contribution +There is a lot of sugar in cocos2d in waiting to be ported to Unity3d! All contribution are eagerly accepted. +### Todos + + - Write Testcases + - Port CCFiniteActions,... + - Add Code Comments + - Add Night Mode + +License +---- +MIT + +**Free Software, Hell Yeah!** -- hehe markdown porked from http://dillinger.io + + +- [Cocos2d iphone project ](https://github.com/cocos2d/cocos2d-objc) +- [Cosco2d-X project](https://github.com/cocos2d/cocos2d-x) -``` \ No newline at end of file From e1ca8695b8476f7e1e6b499a90ff4aa88353c0ff Mon Sep 17 00:00:00 2001 From: Shakthi Prasad G S Date: Mon, 17 Aug 2015 00:39:11 +0530 Subject: [PATCH 11/15] Fix syntax error in markdown --- README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 977a7ab..0306aea 100644 --- a/README.md +++ b/README.md @@ -47,17 +47,16 @@ void Start() Code you see here is *actually* part of **Actor** testcase! Isn't it intutive, and as simple as writing a *screenwriting*. ## Contribution There is a lot of sugar in cocos2d in waiting to be ported to Unity3d! All contribution are eagerly accepted. -### Todos +## Todos - Write Testcases - Port CCFiniteActions,... - Add Code Comments - Add Night Mode -License ----- +## License MIT - +--- **Free Software, Hell Yeah!** -- hehe markdown porked from http://dillinger.io From aa8fac608127df51ca038d147806b8328440c877 Mon Sep 17 00:00:00 2001 From: Shakthi Prasad G S Date: Mon, 17 Aug 2015 00:41:54 +0530 Subject: [PATCH 12/15] More syntax fixes --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0306aea..0a02856 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ void Start() StartCoroutine(anAnimation()); } ``` -Code you see here is *actually* part of **Actor** testcase! Isn't it intutive, and as simple as writing a *screenwriting*. +Code you see here is *actually* part of **Actor** testcase! Isn't it intutive, and as simple as *screenwriting*. ## Contribution There is a lot of sugar in cocos2d in waiting to be ported to Unity3d! All contribution are eagerly accepted. ## Todos From b68b1789ac4e7c263cf6cd6b89cee4bc9dae4983 Mon Sep 17 00:00:00 2001 From: Shakthi Prasad G S Date: Mon, 17 Aug 2015 00:49:03 +0530 Subject: [PATCH 13/15] Updated todo --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0a02856..5f48ed5 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ IEnumerator anAnimation() yield return anActor.MoveTo(4,new Vector3(0,0,0)); - Debug.Log("Both the action completed now must be completed at 4+3=7 seconds"); + Debug.Log("Both the action completed now. Must be completed at 4+3=7 seconds"); } void Start() @@ -50,7 +50,7 @@ There is a lot of sugar in cocos2d in waiting to be ported to Unity3d! All cont ## Todos - Write Testcases - - Port CCFiniteActions,... + - Port CCInstantActions,CCTransitions... - Add Code Comments - Add Night Mode From 1fe481590f1366018dec7bc17fdb669adfe99e37 Mon Sep 17 00:00:00 2001 From: Shakthi Prasad G S Date: Mon, 17 Aug 2015 00:56:23 +0530 Subject: [PATCH 14/15] Fixed license info --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5f48ed5..094971b 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ With actions, making an animation may not be simpler than this. ```c# Action.Run(aTransform,new MoveBy(10 ,new Vector3(10,1,1))); ``` -Above code move transforms 'aTransform' by Vector3(10,1,1) in 10 seconds. Now this is basic one, more complex example follows. +Above code move/transforms 'aTransform' by Vector3(10,1,1) units in 10 seconds. Now this is basic one, more complex example follows. ```c# Sequence seq= new Sequence(new MoveBy(3 ,new Vector3(10,1,1)), new RotateBy(5,new Vector3(180,0,0)), @@ -55,7 +55,7 @@ There is a lot of sugar in cocos2d in waiting to be ported to Unity3d! All cont - Add Night Mode ## License -MIT +Apache License --- **Free Software, Hell Yeah!** -- hehe markdown porked from http://dillinger.io From 4c65aec178f89d2238b8e2c32294618cd9887245 Mon Sep 17 00:00:00 2001 From: Shakthi Prasad G S Date: Mon, 17 Aug 2015 00:59:18 +0530 Subject: [PATCH 15/15] Removed copycat todo! --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 094971b..cf49e74 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ There is a lot of sugar in cocos2d in waiting to be ported to Unity3d! All cont - Write Testcases - Port CCInstantActions,CCTransitions... - Add Code Comments - - Add Night Mode + ## License Apache License