From db81d597562776e858d45ac994b85be6a4fe99c3 Mon Sep 17 00:00:00 2001 From: Ivan KaiSD Korystin Date: Tue, 17 Jun 2014 02:05:43 +0400 Subject: [PATCH] new actions: ActionFadeIn.cs ActionFadeOut.cs ActionFadeTo.cs --- README.md | 6 ++--- src/ActionsInterval/ActionFadeBy.cs | 5 ---- src/ActionsInterval/ActionFadeIn.cs | 22 ++++++++++++++++++ src/ActionsInterval/ActionFadeOut.cs | 22 ++++++++++++++++++ src/ActionsInterval/ActionFadeTo.cs | 34 ++++++++++++++++++++++++++++ src/Examples/SampleActions.cs | 8 +++---- 6 files changed, 85 insertions(+), 12 deletions(-) create mode 100644 src/ActionsInterval/ActionFadeIn.cs create mode 100644 src/ActionsInterval/ActionFadeOut.cs create mode 100644 src/ActionsInterval/ActionFadeTo.cs diff --git a/README.md b/README.md index daf9653..8c337cd 100644 --- a/README.md +++ b/README.md @@ -35,9 +35,9 @@ Interval actions - [x] ScaleBy - [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] FadeOut *if you want to manipulate alpha, your material must support transparency* +- [x] FadeIn *if you want to manipulate alpha, your material must support transparency* +- [x] 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 diff --git a/src/ActionsInterval/ActionFadeBy.cs b/src/ActionsInterval/ActionFadeBy.cs index 43b50ff..7ee39c9 100644 --- a/src/ActionsInterval/ActionFadeBy.cs +++ b/src/ActionsInterval/ActionFadeBy.cs @@ -22,11 +22,6 @@ class ActionFadeBy : ActionInterval return new ActionFadeBy(-delta, duration); } - public override void start() - { - base.start(); - } - public override void stepInterval(float dt) { float d = dt / duration; diff --git a/src/ActionsInterval/ActionFadeIn.cs b/src/ActionsInterval/ActionFadeIn.cs new file mode 100644 index 0000000..ed80f4b --- /dev/null +++ b/src/ActionsInterval/ActionFadeIn.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using UnityEngine; + +class ActionFadeIn : ActionFadeTo +{ + + public ActionFadeIn(float tgtDuration) + : base(1, tgtDuration) + { + } + + public override Action clone() + { + return new ActionFadeIn(duration); + } + + public override Action reverse() + { + return new ActionFadeIn(duration); + } +} \ No newline at end of file diff --git a/src/ActionsInterval/ActionFadeOut.cs b/src/ActionsInterval/ActionFadeOut.cs new file mode 100644 index 0000000..dd82570 --- /dev/null +++ b/src/ActionsInterval/ActionFadeOut.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using UnityEngine; + +class ActionFadeOut : ActionFadeTo +{ + + public ActionFadeOut(float tgtDuration) + : base(0, tgtDuration) + { + } + + public override Action clone() + { + return new ActionFadeOut(duration); + } + + public override Action reverse() + { + return new ActionFadeOut(duration); + } +} \ No newline at end of file diff --git a/src/ActionsInterval/ActionFadeTo.cs b/src/ActionsInterval/ActionFadeTo.cs new file mode 100644 index 0000000..7784a71 --- /dev/null +++ b/src/ActionsInterval/ActionFadeTo.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using UnityEngine; + +class ActionFadeTo : ActionInterval +{ + public float value; + public float delta; + + public ActionFadeTo(float tgtValue, float tgtDuration) + : base(tgtDuration) + { + value = tgtValue; + } + + public override Action clone() + { + return new ActionFadeTo(value, duration); + } + + public override void start() + { + base.start(); + delta = value - target.gameObject.renderer.material.color.a; + } + + 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/Examples/SampleActions.cs b/src/Examples/SampleActions.cs index 4b5c019..10567cb 100644 --- a/src/Examples/SampleActions.cs +++ b/src/Examples/SampleActions.cs @@ -7,16 +7,15 @@ public class SampleActions : MonoBehaviour { Action seq = new ActionRepeat (new ActionSequence(new Action[] { + new ActionFadeIn(2), 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 ActionTintBy(new Vector4(-50, 50, -150, 0), 1) + new ActionTintBy(new Vector4(-50, 50, -150), 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(), @@ -30,7 +29,8 @@ 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 ActionTintTo(new Vector4(67, 105, 181, 255),3) + new ActionFadeOut(2), + new ActionSetTint(new Vector4(67, 105, 181)) }), 5); gameObject.SendMessage("AttachAction", seq); }