From 0b4d17f8dfc2817a21197d4e6772c099ab7da23b Mon Sep 17 00:00:00 2001 From: Ivan KaiSD Korystin Date: Tue, 17 Jun 2014 01:52:31 +0400 Subject: [PATCH] minor fixes in ActionTintBy.cs new actions: ActionFadeBy.cs ActionTintTo.cs --- README.md | 19 ++++++----- src/ActionsInterval/ActionFadeBy.cs | 37 ++++++++++++++++++++++ src/ActionsInterval/ActionTintBy.cs | 5 +++ src/ActionsInterval/ActionTintTo.cs | 49 +++++++++++++++++++++++++++++ src/Examples/SampleActions.cs | 8 +++-- 5 files changed, 107 insertions(+), 11 deletions(-) create mode 100644 src/ActionsInterval/ActionFadeBy.cs create mode 100644 src/ActionsInterval/ActionTintTo.cs diff --git a/README.md b/README.md index c8e8abd..daf9653 100644 --- a/README.md +++ b/README.md @@ -15,27 +15,30 @@ See the examples folder, there's a sample script there. You can also subclass the Actor and add all the actions you want to the Start() method. -### Included actions (ready and WIP) +### Included actions (ready and WIP) +All actions are designed to word in 3D scene (i.e. using Vector3 for movement, rotation and scaling). +You can use it in 2D with apropriate vectors, but i'm going to add support for 2D actions soon. Base actions - [x] Sequence - [x] Parallel - [x] Repeat and Loop *implemented in one action* -- [ ] Reverse +- [ ] Reverse *not yet, but every reversable action has working reverse() method* Interval actions +- [x] Delay and RandomDelay *implemented in one action* - [x] MoveTo - [x] MoveBy - [x] RotateTo - [x] RotateBy - [x] ScaleTo - [x] ScaleBy -- [x] TintBy -- [x] Delay and RandomDelay *implemented in one action* -- [ ] TintTo -- [ ] FadeOut -- [ ] FadeIn -- [ ] FadeTo +- [x] TintBy *if you want to manipulate alpha, your material must support transparency* +- [x] TintTo *if you want to manipulate alpha, your material must support transparency* +- [ ] FadeOut *if you want to manipulate alpha, your material must support transparency* +- [ ] FadeIn *if you want to manipulate alpha, your material must support transparency* +- [ ] FadeTo *if you want to manipulate alpha, your material must support transparency* +- [x] FadeBy *if you want to manipulate alpha, your material must support transparency* - [ ] JumpTo - [ ] JumpBy - [ ] Bezier diff --git a/src/ActionsInterval/ActionFadeBy.cs b/src/ActionsInterval/ActionFadeBy.cs new file mode 100644 index 0000000..43b50ff --- /dev/null +++ b/src/ActionsInterval/ActionFadeBy.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using UnityEngine; + +class ActionFadeBy : ActionInterval +{ + public float delta; + + public ActionFadeBy(float tgtDelta, float tgtDuration) + : base(tgtDuration) + { + delta = tgtDelta; + } + + public override Action clone() + { + return new ActionFadeBy(delta, duration); + } + + public override Action reverse() + { + return new ActionFadeBy(-delta, duration); + } + + public override void start() + { + base.start(); + } + + public override void stepInterval(float dt) + { + float d = dt / duration; + Color tgtColor = target.gameObject.renderer.material.color; + tgtColor[3] += delta * d; + target.gameObject.renderer.material.color = tgtColor; + } +} \ No newline at end of file diff --git a/src/ActionsInterval/ActionTintBy.cs b/src/ActionsInterval/ActionTintBy.cs index cdc2eec..5440f4c 100644 --- a/src/ActionsInterval/ActionTintBy.cs +++ b/src/ActionsInterval/ActionTintBy.cs @@ -13,6 +13,11 @@ class ActionTintBy : ActionInterval color = tgtColor * coeff; } + public ActionTintBy(Vector3 tgtColor, float tgtDuration) + : this(new Vector4(tgtColor.x, tgtColor.y, tgtColor.z), tgtDuration) + { + } + public override Action clone() { return new ActionTintBy(color / coeff, duration); diff --git a/src/ActionsInterval/ActionTintTo.cs b/src/ActionsInterval/ActionTintTo.cs new file mode 100644 index 0000000..0707956 --- /dev/null +++ b/src/ActionsInterval/ActionTintTo.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using UnityEngine; + +class ActionTintTo : ActionInterval +{ + public Vector4 color; + public Vector4 path; + protected const float coeff = 1F / 255F; + + public ActionTintTo(Vector4 tgtColor, float tgtDuration) + : base(tgtDuration) + { + color = tgtColor * coeff; + path = Vector4.zero; + } + + public ActionTintTo(Vector3 tgtColor, float tgtDuration) + : this(new Vector4(tgtColor.x, tgtColor.y, tgtColor.z), tgtDuration) + { + } + + public override Action clone() + { + return new ActionTintTo(color / coeff, duration); + } + + public override void start() + { + base.start(); + Color tgtColor = target.gameObject.renderer.material.color; + path[0] = color[0] - tgtColor[0]; + path[1] = color[1] - tgtColor[1]; + path[2] = color[2] - tgtColor[2]; + path[3] = color[3] - tgtColor[3]; + } + + public override void stepInterval(float dt) + { + float d = dt / duration; + Vector4 tgt = path * d; + Color tgtColor = target.gameObject.renderer.material.color; + tgtColor[0] += tgt[0]; + tgtColor[1] += tgt[1]; + tgtColor[2] += tgt[2]; + tgtColor[3] += tgt[3]; + target.gameObject.renderer.material.color = tgtColor; + } +} \ No newline at end of file diff --git a/src/Examples/SampleActions.cs b/src/Examples/SampleActions.cs index 6e9f6d5..4b5c019 100644 --- a/src/Examples/SampleActions.cs +++ b/src/Examples/SampleActions.cs @@ -7,14 +7,16 @@ public class SampleActions : MonoBehaviour { Action seq = new ActionRepeat (new ActionSequence(new Action[] { - new ActionTintBy(new Vector4(-50,50,-50,-50),1), new ActionParallel(new Action[] { new ActionMoveBy(new Vector3(10, 0, 0), 1), new ActionMoveBy(new Vector3(0, 10, 0), 1), - // new ActionRotateBy(new Vector3(90, 0, 0), 1) + new ActionRotateBy(new Vector3(90, 0, 0), 1), + new ActionTintBy(new Vector4(-50, 50, -150, 0), 1) }), new ActionScaleBy(new Vector3(2, 2, 1), 1), new ActionScaleBy(new Vector3(0.5F, 0.5F, 2), 1), + new ActionFadeBy(-1F, 2), + new ActionFadeBy(1F, 2), new ActionDelay(1), new ActionRepeat(new ActionSequence(new Action[] { new ActionHide(), @@ -28,7 +30,7 @@ public class SampleActions : MonoBehaviour new ActionMoveTo(new Vector3(0, 0, 10), 1), new ActionScaleTo(new Vector3(2, 2, 2), 1), new ActionRotateTo(new Vector3(0, 0, 0), 1), - new ActionTintBy(new Vector4(50,-50,50,50),3) + new ActionTintTo(new Vector4(67, 105, 181, 255),3) }), 5); gameObject.SendMessage("AttachAction", seq); }