diff --git a/README.md b/README.md
index 1fbec49..755ebae 100644
--- a/README.md
+++ b/README.md
@@ -63,8 +63,6 @@ Base actions
Interval actions
- [ ] Follow - follows another actor with the given speed for the given amount of time (of forever).
- [ ] LookAt - rotates the object to look at the given actor.
-
-*These two actions requires the using of MeshActor script instead of Actor.*
- [x] SkewBy - skews the mesh by given values.
- [ ] SkewTo - skews the mesh to the given values.
diff --git a/src/ActionsBase/Action.cs b/src/ActionsBase/Action.cs
index 4551c62..ff4f07a 100644
--- a/src/ActionsBase/Action.cs
+++ b/src/ActionsBase/Action.cs
@@ -2,80 +2,124 @@
using System.Collections.Generic;
using UnityEngine;
-public class Action
+namespace coa4u
{
- protected Actor target;
- public float duration = 0;
- protected Transform transform;
- protected Renderer renderer;
- protected bool is2d = false;
-
- public Action()
+ ///
+ /// Basic action class for subclassing. To inherit interval actions, consider using the ActionInterval as the base class.
+ ///
+ public class ActionInstant
{
- }
+ protected Actor target;
+ protected Transform transform;
+ protected Renderer renderer;
+ protected bool is2d = false;
+ private float durationValue = 0;
+ private float dtrValue = 0;
+ private bool isRunning = false;
- public virtual Action clone()
- {
- return new Action();
- }
+ public ActionInstant()
+ {
+ }
- public virtual bool isRunning()
- {
- return false;
- }
+ ///
+ /// Returns a copy of the action.
+ ///
+ public virtual ActionInstant clone()
+ {
+ return new ActionInstant();
+ }
- ///
- /// This method is called at the action start. Usable for instant and interval actions.
- ///
- public virtual Action reverse()
- {
- throw new Exception("Can reverse only the reversable interval actions");
- }
+ ///
+ /// Returns the reversed version of the action, if it is possible.
+ ///
+ public virtual ActionInstant reverse()
+ {
+ throw new Exception("Can reverse only the reversable interval actions");
+ }
- ///
- /// This method is called at the action start. Usable for instant and interval actions.
- ///
- public virtual void start()
- {
- if (target == null)
- throw new Exception("Can start the action only after it's atached to the actor");
- transform = target.gameObject.transform;
- renderer = target.gameObject.renderer;
- }
+ ///
+ /// This method is called at the action start. Usable for instant and interval actions.
+ ///
+ public virtual void start()
+ {
+ if (target == null)
+ throw new Exception("Can start the action only after it's atached to the actor");
+ transform = target.transformCached;
+ renderer = target.rendererCached;
+ }
- ///
- /// This method is called at every frame update. Not usable for instant actions.
- ///
- public virtual void step(float dt)
- {
- if (target == null)
- throw new Exception("Can update the action only after it's atached to the actor");
- }
+ ///
+ /// This method is called at every frame update. Not usable for instant actions.
+ ///
+ public virtual void step(float dt)
+ {
+ if (target == null)
+ throw new Exception("Can update the action only after it's atached to the actor");
+ }
- ///
- /// This method is called after the interval action is stopped. Not usable for instant actions.
- ///
- public virtual void stop()
- {
- if (target == null)
- throw new Exception("Can stop the action only after it's atached to the actor");
- }
+ ///
+ /// This method is called after the interval action is stopped. Not usable for instant actions.
+ ///
+ public virtual void stop()
+ {
+ if (target == null)
+ throw new Exception("Can stop the action only after it's atached to the actor");
+ }
- public void setActor(Actor actor)
- {
- target = actor;
- }
+ ///
+ /// This method sets the actor for the action.
+ ///
+ public void setActor(Actor actor)
+ {
+ target = actor;
+ }
- public virtual float dtr
- {
- get
+ ///
+ /// Readonly property. Shows the remaining time of the action.
+ ///
+ public float duration
+ {
+ get
+ {
+ return durationValue;
+ }
+
+ protected set
+ {
+ durationValue = value;
+ }
+ }
+
+ ///
+ /// Readonly property. Shows if the action is running or not.
+ ///
+ public bool running
{
- return 0;
+ get
+ {
+ return isRunning;
+ }
+
+ protected set
+ {
+ isRunning = value;
+ }
}
- protected set
+ ///
+ /// Readonly property. Contains the remaining tick time after action finished.
+ ///
+ public float dtr
{
+ get
+ {
+ return dtrValue;
+ }
+
+ protected set
+ {
+ dtrValue = value;
+ }
}
}
-
}
\ No newline at end of file
diff --git a/src/ActionsBase/ActionInterval.cs b/src/ActionsBase/ActionInterval.cs
index ad6c901..0c03791 100644
--- a/src/ActionsBase/ActionInterval.cs
+++ b/src/ActionsBase/ActionInterval.cs
@@ -2,102 +2,98 @@
using System.Collections.Generic;
using UnityEngine;
-class ActionInterval : Action
+namespace coa4u
{
- protected float timer;
- protected float timeScale;
- protected bool running;
- private float dtrdata;
-
- public ActionInterval(float tgtDuration)
- : base()
- {
- duration = tgtDuration;
- timeScale = 1F;
- dtr = 0;
- }
-
- public override Action clone()
- {
- return new ActionInterval(duration);
- }
-
- public override Action reverse()
- {
- throw new Exception("Can reverse only the reversable interval actions");
- }
-
- public override bool isRunning()
- {
- return running;
- }
-
- public override void start()
- {
- base.start();
- running = true;
- timer = 0F;
- }
-
- public override void stop()
- {
- base.stop();
- running = false;
- }
-
///
- /// Step method for interval actions. Don't override this method, when inheriting, put your code in stepInterval instead.
+ /// Interval action class for subclassing.
///
- public override void step(float dt)
+ public class ActionInterval : ActionInstant
{
- dt *= timeScale;
- base.step(dt);
- if (timer + dt > duration)
+ protected float timer;
+ protected float timeScale;
+ private float dtrdata;
+
+ public ActionInterval(float tgtDuration)
+ : base()
{
- float odt = dt;
- dt = duration - timer;
- timer += odt;
+ duration = tgtDuration;
+ timeScale = 1F;
+ dtr = 0;
}
- else
+
+ ///
+ /// Returns a copy of the action.
+ ///
+ public override ActionInstant clone()
{
- timer += dt;
+ return new ActionInterval(duration);
}
- stepInterval(dt);
- if (timer > duration)
+
+ ///
+ /// Returns the reversed version of the action, if it is possible.
+ ///
+ public override ActionInstant reverse()
{
- stop();
- dtr = timer - duration;
+ throw new Exception("Can reverse only the reversable interval actions");
}
- }
- ///
- /// Step method for interval actions. Put your code here.
- ///
- public virtual void stepInterval(float dt)
- {
- }
+ ///
+ /// This method is called at the action start.
+ ///
+ public override void start()
+ {
+ base.start();
+ running = true;
+ timer = 0F;
+ }
- ///
- /// Property to get the remaining tick time after the action has ended.
- ///
- public override float dtr
- {
- get
+ ///
+ /// This method is called after the interval action is stopped.
+ ///
+ public override void stop()
{
- return dtrdata;
+ base.stop();
+ running = false;
}
- protected set
+ ///
+ /// This method is called every frame update. Don't override this method, when inheriting, put your code in stepInterval instead.
+ ///
+ public override void step(float dt)
{
- dtrdata = value;
+ dt *= timeScale;
+ base.step(dt);
+ if (timer + dt > duration)
+ {
+ float odt = dt;
+ dt = duration - timer;
+ timer += odt;
+ }
+ else
+ {
+ timer += dt;
+ }
+ stepInterval(dt);
+ if (timer > duration)
+ {
+ stop();
+ dtr = timer - duration;
+ }
}
- }
- ///
- /// Immediately changes the time scale for this action and all nested ones.
- ///
- public void setTimeScale(float ts)
- {
- timeScale = ts;
+ ///
+ /// This method is called every frame update. Put your code here.
+ ///
+ public virtual void stepInterval(float dt)
+ {
+ }
+
+ ///
+ /// Immediately changes the time scale for this action and all nested ones.
+ ///
+ public void setTimeScale(float ts)
+ {
+ timeScale = ts;
+ }
}
}
\ No newline at end of file
diff --git a/src/ActionsBase/ActionParallel.cs b/src/ActionsBase/ActionParallel.cs
index d038b4d..fda09d8 100644
--- a/src/ActionsBase/ActionParallel.cs
+++ b/src/ActionsBase/ActionParallel.cs
@@ -2,84 +2,105 @@
using System.Collections.Generic;
using UnityEngine;
-class ActionParallel : ActionInterval
+namespace coa4u
{
- protected Action[] actions;
-
- public ActionParallel(Action action1, Action action2)
- : base(0)
- {
- actions = new Action[] {action1, action2};
- }
-
- public ActionParallel(Action[] actionsList)
- : base(0)
+ ///
+ /// Runs several actions at the same time.
+ ///
+ public class ActionParallel : ActionInterval
{
- actions = actionsList;
+ protected ActionInstant[] actions;
- }
-
- public override Action clone()
- {
- Action[] aList = new Action[actions.Length];
- for (int i = 0; i < actions.Length; i++)
+ public ActionParallel(ActionInstant action1, ActionInstant action2)
+ : base(0)
{
- aList[i] = actions[i].clone();
+ actions = new ActionInstant[] { action1, action2 };
}
- return new ActionSequence(aList);
- }
- public override Action reverse()
- {
- Action[] aList = new Action[actions.Length];
- for (int i = 0; i < actions.Length; i++)
+ public ActionParallel(ActionInstant[] actionsList)
+ : base(0)
{
- aList[i] = actions[i].reverse();
+ actions = actionsList;
+
}
- return new ActionSequence(aList);
- }
- public override void start()
- {
- base.start();
- for (int i = 0; i < actions.Length; i++)
+ ///
+ /// Returns a copy of the action.
+ ///
+ public override ActionInstant clone()
{
- actions[i].setActor(target);
- actions[i].start();
+ ActionInstant[] aList = new ActionInstant[actions.Length];
+ for (int i = 0; i < actions.Length; i++)
+ {
+ aList[i] = actions[i].clone();
+ }
+ return new ActionSequence(aList);
}
- }
- public override void step(float dt)
- {
- dt *= timeScale;
- for (int i = 0; i < actions.Length; i++)
+ ///
+ /// Returns the reversed version of the action, if it is possible.
+ ///
+ public override ActionInstant reverse()
{
- if (actions[i].isRunning())
- actions[i].step(dt);
+ ActionInstant[] aList = new ActionInstant[actions.Length];
+ for (int i = 0; i < actions.Length; i++)
+ {
+ aList[i] = actions[i].reverse();
+ }
+ return new ActionSequence(aList);
}
- bool canStopNow = true;
- float dtrdata = 0;
- for (int i = 0; i < actions.Length; i++)
+
+ ///
+ /// This method is called at the action start.
+ ///
+ public override void start()
{
- if (actions[i].isRunning())
+ base.start();
+ for (int i = 0; i < actions.Length; i++)
{
- canStopNow = false;
- dtrdata = Math.Max(actions[i].dtr, dtrdata);
+ actions[i].setActor(target);
+ actions[i].start();
}
}
- if (canStopNow)
+
+ ///
+ /// This method is called every frame update.
+ ///
+ public override void step(float dt)
{
- stop();
- dtr = dtrdata;
+ dt *= timeScale;
+ for (int i = 0; i < actions.Length; i++)
+ {
+ if (actions[i].running)
+ actions[i].step(dt);
+ }
+ bool canStopNow = true;
+ float dtrdata = 0;
+ for (int i = 0; i < actions.Length; i++)
+ {
+ if (actions[i].running)
+ {
+ canStopNow = false;
+ dtrdata = Math.Max(actions[i].dtr, dtrdata);
+ }
+ }
+ if (canStopNow)
+ {
+ stop();
+ dtr = dtrdata;
+ }
}
- }
- public override void stop()
- {
- base.stop();
- for (int i = 0; i < actions.Length; i++)
+ ///
+ /// This method is called after the interval action is stopped.
+ ///
+ public override void stop()
{
- actions[i].stop();
+ base.stop();
+ for (int i = 0; i < actions.Length; i++)
+ {
+ actions[i].stop();
+ }
}
}
}
\ No newline at end of file
diff --git a/src/ActionsBase/ActionRandom.cs b/src/ActionsBase/ActionRandom.cs
index d3de7e1..f8fa8b6 100644
--- a/src/ActionsBase/ActionRandom.cs
+++ b/src/ActionsBase/ActionRandom.cs
@@ -2,68 +2,89 @@
using System.Collections.Generic;
using UnityEngine;
-class ActionRandom : ActionInterval
+namespace coa4u
{
+ ///
+ /// Runs one random action from the given list.
+ ///
+ class ActionRandom : ActionInterval
+ {
- protected Action[] actions;
- protected int index;
+ protected ActionInstant[] actions;
+ protected int index;
- public ActionRandom(Action action1, Action action2)
- : base(0)
- {
- actions = new Action[] {action1, action2};
- }
+ public ActionRandom(ActionInstant action1, ActionInstant action2)
+ : base(0)
+ {
+ actions = new ActionInstant[] { action1, action2 };
+ }
- public ActionRandom(Action[] actionsList)
- : base(0)
- {
- actions = actionsList;
+ public ActionRandom(ActionInstant[] actionsList)
+ : base(0)
+ {
+ actions = actionsList;
- }
+ }
- public override Action clone()
- {
- Action[] aList = new Action[actions.Length];
- for (int i = 0; i < actions.Length; i++)
+ ///
+ /// Returns a copy of the action.
+ ///
+ public override ActionInstant clone()
{
- aList[i] = actions[i].clone();
+ ActionInstant[] aList = new ActionInstant[actions.Length];
+ for (int i = 0; i < actions.Length; i++)
+ {
+ aList[i] = actions[i].clone();
+ }
+ return new ActionRandom(aList);
}
- return new ActionRandom(aList);
- }
- public override Action reverse()
- {
- Action[] aList = new Action[actions.Length];
- for (int i = 0; i < actions.Length; i++)
+ ///
+ /// Returns the reversed version of the action, if it is possible.
+ ///
+ public override ActionInstant reverse()
{
- aList[i] = actions[i].reverse();
+ ActionInstant[] aList = new ActionInstant[actions.Length];
+ for (int i = 0; i < actions.Length; i++)
+ {
+ aList[i] = actions[i].reverse();
+ }
+ return new ActionRandom(aList);
}
- return new ActionRandom(aList);
- }
- public override void start()
- {
- base.start();
- index = UnityEngine.Random.Range(0, actions.Length);
- actions[index].setActor(target);
- actions[index].start();
- }
+ ///
+ /// This method is called at the action start.
+ ///
+ public override void start()
+ {
+ base.start();
+ index = UnityEngine.Random.Range(0, actions.Length);
+ actions[index].setActor(target);
+ actions[index].start();
+ }
- public override void step(float dt)
- {
- dt *= timeScale;
- if (actions[index].isRunning())
- actions[index].step(dt);
- if (!actions[index].isRunning())
+ ///
+ /// This method is called every frame update.
+ ///
+ public override void step(float dt)
{
- stop();
- dtr = actions[index].dtr;
+ dt *= timeScale;
+ if (actions[index].running)
+ actions[index].step(dt);
+ if (!actions[index].running)
+ {
+ stop();
+ dtr = actions[index].dtr;
+ }
}
- }
- public override void stop()
- {
- base.stop();
- actions[index].stop();
+ ///
+ /// This method is called after the interval action is stopped.
+ ///
+ public override void stop()
+ {
+ base.stop();
+ actions[index].stop();
+ }
}
}
\ No newline at end of file
diff --git a/src/ActionsBase/ActionRepeat.cs b/src/ActionsBase/ActionRepeat.cs
index 91e9cee..2fe321a 100644
--- a/src/ActionsBase/ActionRepeat.cs
+++ b/src/ActionsBase/ActionRepeat.cs
@@ -2,68 +2,86 @@
using System.Collections.Generic;
using UnityEngine;
-class ActionRepeat : ActionInterval
+namespace coa4u
{
- protected ActionInterval action;
- protected int count;
- protected int counter;
- protected bool forever;
-
- public ActionRepeat(ActionInterval tgtAction, int tgtCount)
- : base(0)
+ ///
+ /// Runs the given action the several times. Also can repeat the action forever.
+ ///
+ class ActionRepeat : ActionInterval
{
- action = tgtAction;
- count = tgtCount;
- counter = 0;
- forever = false;
- }
-
- public ActionRepeat(ActionInterval tgtAction)
- : base(0)
- {
- action = tgtAction;
- count = 0;
- counter = 0;
- forever = true;
- }
+ protected ActionInterval action;
+ protected int count;
+ protected int counter;
+ protected bool forever;
- public override Action clone()
- {
- return new ActionRepeat((ActionInterval) action.clone(), count);
- }
+ public ActionRepeat(ActionInterval tgtAction, int tgtCount)
+ : base(0)
+ {
+ action = tgtAction;
+ count = tgtCount;
+ counter = 0;
+ forever = false;
+ }
- public override Action reverse()
- {
- return new ActionRepeat((ActionInterval) action.reverse(), count);
- }
+ public ActionRepeat(ActionInterval tgtAction)
+ : base(0)
+ {
+ action = tgtAction;
+ count = 0;
+ counter = 0;
+ forever = true;
+ }
- public override void start()
- {
- base.start();
- action.setActor(target);
- action.start();
- counter = 0;
- }
+ ///
+ /// Returns a copy of the action.
+ ///
+ public override ActionInstant clone()
+ {
+ return new ActionRepeat((ActionInterval)action.clone(), count);
+ }
- public override void step(float dt)
- {
- dt *= timeScale;
- if (action.isRunning())
+ ///
+ /// Returns the reversed version of the action, if it is possible.
+ ///
+ public override ActionInstant reverse()
{
- action.step(dt);
+ return new ActionRepeat((ActionInterval)action.reverse(), count);
}
- if (!action.isRunning() && (forever || counter < count - 1))
+
+ ///
+ /// This method is called at the action start.
+ ///
+ public override void start()
{
- float dtrdata = action.dtr;
+ base.start();
+ action.setActor(target);
action.start();
- if (dtrdata > 0)
- action.step(dtrdata);
- counter += 1;
+ counter = 0;
}
- else if (!action.isRunning() && counter >= count - 1)
+
+ ///
+ /// This method is called every frame update.
+ ///
+ public override void step(float dt)
{
- dtr = action.dtr;
- stop();
+ dt *= timeScale;
+ if (action.running)
+ {
+ action.step(dt);
+ }
+ if (!action.running && (forever || counter < count - 1))
+ {
+ float dtrdata = action.dtr;
+ action.start();
+ if (dtrdata > 0)
+ action.step(dtrdata);
+ counter += 1;
+ }
+ else if (!action.running && counter >= count - 1)
+ {
+ dtr = action.dtr;
+ stop();
+ }
}
}
}
\ No newline at end of file
diff --git a/src/ActionsBase/ActionSequence.cs b/src/ActionsBase/ActionSequence.cs
index a105ad9..2d361a7 100644
--- a/src/ActionsBase/ActionSequence.cs
+++ b/src/ActionsBase/ActionSequence.cs
@@ -2,89 +2,110 @@
using System.Collections.Generic;
using UnityEngine;
-class ActionSequence : ActionInterval
+namespace coa4u
{
- protected Action[] actions;
- protected int index;
-
- public ActionSequence(Action action1, Action action2)
- : base(0)
+ ///
+ /// Runs several actions in a sequence.
+ ///
+ class ActionSequence : ActionInterval
{
- actions = new Action[] {action1, action2};
- }
+ protected ActionInstant[] actions;
+ protected int index;
- public ActionSequence(Action[] actionsList)
- : base(0)
- {
- actions = actionsList;
-
- }
-
- public override Action clone()
- {
- Action[] aList = new Action[actions.Length];
- for (int i = 0; i < actions.Length; i++)
+ public ActionSequence(ActionInstant action1, ActionInstant action2)
+ : base(0)
{
- aList[i] = actions[i].clone();
+ actions = new ActionInstant[] { action1, action2 };
}
- return new ActionSequence(aList);
- }
- public override Action reverse()
- {
- Action[] aList = new Action[actions.Length];
- for (int i = 0; i < actions.Length; i++)
+ public ActionSequence(ActionInstant[] actionsList)
+ : base(0)
{
- aList[actions.Length - 1 - i] = actions[i].reverse();
+ actions = actionsList;
+
}
- return new ActionSequence(aList);
- }
- public override void start()
- {
- base.start();
- index = 0;
- actions[0].setActor(target);
- actions[0].start();
- while (!actions[index].isRunning() && index < actions.Length)
+ ///
+ /// Returns a copy of the action.
+ ///
+ public override ActionInstant clone()
{
- index += 1;
- actions[index].setActor(target);
- actions[index].start();
+ ActionInstant[] aList = new ActionInstant[actions.Length];
+ for (int i = 0; i < actions.Length; i++)
+ {
+ aList[i] = actions[i].clone();
+ }
+ return new ActionSequence(aList);
}
- }
- public override void step(float dt)
- {
- dt *= timeScale;
- float dtrdata = 0;
- if (actions[index].isRunning())
+ ///
+ /// Returns the reversed version of the action, if it is possible.
+ ///
+ public override ActionInstant reverse()
{
- actions[index].step(dt);
- if (!actions[index].isRunning())
- dtrdata = actions[index].dtr;
+ ActionInstant[] aList = new ActionInstant[actions.Length];
+ for (int i = 0; i < actions.Length; i++)
+ {
+ aList[actions.Length - 1 - i] = actions[i].reverse();
+ }
+ return new ActionSequence(aList);
}
- while (!actions[index].isRunning() && index < actions.Length - 1)
+
+ ///
+ /// This method is called at the action start.
+ ///
+ public override void start()
{
- index += 1;
- actions[index].setActor(target);
- actions[index].start();
- if (actions[index].isRunning() && dtrdata > 0)
- actions[index].step(dtrdata);
+ base.start();
+ index = 0;
+ actions[0].setActor(target);
+ actions[0].start();
+ while (!actions[index].running && index < actions.Length)
+ {
+ index += 1;
+ actions[index].setActor(target);
+ actions[index].start();
+ }
}
- if (!actions[index].isRunning())
+
+ ///
+ /// This method is called every frame update.
+ ///
+ public override void step(float dt)
{
- stop();
- dtr = dtrdata;
+ dt *= timeScale;
+ float dtrdata = 0;
+ if (actions[index].running)
+ {
+ actions[index].step(dt);
+ if (!actions[index].running)
+ dtrdata = actions[index].dtr;
+ }
+ while (!actions[index].running && index < actions.Length - 1)
+ {
+ index += 1;
+ actions[index].setActor(target);
+ actions[index].start();
+ if (actions[index].running && dtrdata > 0)
+ actions[index].step(dtrdata);
+ }
+ if (!actions[index].running)
+ {
+ stop();
+ dtr = dtrdata;
+ }
}
- }
- public override void stop()
- {
- base.stop();
- for (int i = 0; i < actions.Length; i++)
+ ///
+ /// This method is called after the interval action is stopped.
+ ///
+ public override void stop()
{
- actions[i].stop();
+ base.stop();
+ for (int i = 0; i < actions.Length; i++)
+ {
+ actions[i].stop();
+ }
}
}
}
\ No newline at end of file
diff --git a/src/ActionsBase/ActionStop.cs b/src/ActionsBase/ActionStop.cs
new file mode 100644
index 0000000..2e1b770
--- /dev/null
+++ b/src/ActionsBase/ActionStop.cs
@@ -0,0 +1,34 @@
+using System;
+using System.Collections.Generic;
+using UnityEngine;
+
+namespace coa4u
+{
+ ///
+ /// This action stops all actions for the current target.
+ ///
+ class ActionStop : ActionInstant
+ {
+ public ActionStop()
+ : base()
+ {
+ }
+
+ ///
+ /// Returns a copy of the action.
+ ///
+ public override ActionInstant clone()
+ {
+ return new ActionStop();
+ }
+
+ ///
+ /// This method is called at the action start.
+ ///
+ public override void start()
+ {
+ base.start();
+ target.StopAction();
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/ActionsInstant/ActionHide.cs b/src/ActionsInstant/ActionHide.cs
index 43ec31e..662265f 100644
--- a/src/ActionsInstant/ActionHide.cs
+++ b/src/ActionsInstant/ActionHide.cs
@@ -2,22 +2,42 @@
using System.Collections.Generic;
using UnityEngine;
-class ActionHide : Action
+namespace coa4u
{
-
- public ActionHide()
- : base()
+ ///
+ /// Instantly hides the target. This action does not require the transparency support in shaders.
+ ///
+ class ActionHide : ActionInstant
{
- }
- public override Action clone()
- {
- return new ActionHide();
- }
+ public ActionHide()
+ : base()
+ {
+ }
- public override void start()
- {
- base.start();
- renderer.enabled = false;
+ ///
+ /// Returns a copy of the action.
+ ///
+ public override ActionInstant clone()
+ {
+ return new ActionHide();
+ }
+
+ ///
+ /// Returns the reversed version of the action, if it is possible.
+ ///
+ public override ActionInstant reverse()
+ {
+ return new ActionShow();
+ }
+
+ ///
+ /// This method is called at the action start.
+ ///
+ public override void start()
+ {
+ base.start();
+ renderer.enabled = false;
+ }
}
}
\ No newline at end of file
diff --git a/src/ActionsInstant/ActionLog.cs b/src/ActionsInstant/ActionLog.cs
index 8c31115..61cef4f 100644
--- a/src/ActionsInstant/ActionLog.cs
+++ b/src/ActionsInstant/ActionLog.cs
@@ -2,19 +2,44 @@
using System.Collections.Generic;
using UnityEngine;
-class ActionLog : Action
+namespace coa4u
{
- string message;
-
- public ActionLog(string tgtMessage)
- : base()
+ ///
+ /// Prints a message in Unity debug console.
+ ///
+ class ActionLog : ActionInstant
{
- message = tgtMessage;
- }
+ string message;
- public override void start()
- {
- base.start();
- Debug.Log(message);
+ public ActionLog(string tgtMessage)
+ : base()
+ {
+ message = tgtMessage;
+ }
+
+ ///
+ /// Returns a copy of the action.
+ ///
+ public override ActionInstant clone()
+ {
+ return new ActionLog(message);
+ }
+
+ ///
+ /// Returns the reversed version of the action, if it is possible.
+ ///
+ public override ActionInstant reverse()
+ {
+ return new ActionLog(message);
+ }
+
+ ///
+ /// This method is called at the action start.
+ ///
+ public override void start()
+ {
+ base.start();
+ Debug.Log(message);
+ }
}
}
\ No newline at end of file
diff --git a/src/ActionsInstant/ActionSendMessage.cs b/src/ActionsInstant/ActionSendMessage.cs
index a31dbff..e09ed61 100644
--- a/src/ActionsInstant/ActionSendMessage.cs
+++ b/src/ActionsInstant/ActionSendMessage.cs
@@ -2,43 +2,70 @@
using System.Collections.Generic;
using UnityEngine;
-class ActionSendMessage : Action
+namespace coa4u
{
- protected string message;
- protected object param;
- protected SendMessageOptions options = SendMessageOptions.DontRequireReceiver;
-
- public ActionSendMessage(string tgtMessage)
- : base()
+ ///
+ /// Sends the message to the current target. First, it checks the Actor's methods cache.
+ /// If the receiving method found in cache, it will be called directly without passing the message to the GameObject.
+ /// If there's no listener in cache, message will be sent GameObject (and Unity does it VERY slow).
+ ///
+ class ActionSendMessage : ActionInstant
{
- message = tgtMessage;
- }
+ protected string message;
+ protected object param;
+ protected SendMessageOptions options = SendMessageOptions.DontRequireReceiver;
- public ActionSendMessage(string tgtMessage, object tgtParam)
- : base()
- {
- message = tgtMessage;
- param = tgtParam;
- }
+ public ActionSendMessage(string tgtMessage)
+ : base()
+ {
+ message = tgtMessage;
+ }
- public ActionSendMessage(string tgtMessage, object tgtParam, SendMessageOptions tgtOptions)
- : base()
- {
- message = tgtMessage;
- param = tgtParam;
- options = tgtOptions;
- }
+ public ActionSendMessage(string tgtMessage, object tgtParam)
+ : base()
+ {
+ message = tgtMessage;
+ param = tgtParam;
+ }
- public override void start()
- {
- base.start();
- if (param != null)
+ public ActionSendMessage(string tgtMessage, object tgtParam, SendMessageOptions tgtOptions)
+ : base()
+ {
+ message = tgtMessage;
+ param = tgtParam;
+ options = tgtOptions;
+ }
+
+ ///
+ /// Returns a copy of the action.
+ ///
+ public override ActionInstant clone()
{
- target.SendMessage(message, param);
+ return new ActionSendMessage(message, param, options);
}
- else
+
+ ///
+ /// Returns the reversed version of the action, if it is possible.
+ ///
+ public override ActionInstant reverse()
+ {
+ return new ActionSendMessage(message, param, options);
+ }
+
+ ///
+ /// This method is called at the action start.
+ ///
+ public override void start()
{
- target.SendMessage(message);
+ base.start();
+ if (param != null)
+ {
+ target.ReceiveMessage(message, param, options);
+ }
+ else
+ {
+ target.ReceiveMessage(message, options);
+ }
}
}
}
\ No newline at end of file
diff --git a/src/ActionsInstant/ActionSetDirection.cs b/src/ActionsInstant/ActionSetDirection.cs
new file mode 100644
index 0000000..1827897
--- /dev/null
+++ b/src/ActionsInstant/ActionSetDirection.cs
@@ -0,0 +1,58 @@
+using System;
+using System.Collections.Generic;
+using UnityEngine;
+
+namespace coa4u
+{
+ ///
+ /// Instantly rotates the target to face the given point or actor.
+ ///
+ class ActionSetDirection : ActionInstant
+ {
+ protected Vector3 value;
+ protected Actor other;
+
+ public ActionSetDirection(Vector3 tgtValue)
+ : base()
+ {
+ value = tgtValue;
+ }
+
+ public ActionSetDirection(Vector2 tgtValue)
+ : this((Vector3)tgtValue)
+ {
+ is2d = true;
+ }
+
+ public ActionSetDirection(Actor tgtActor)
+ : base()
+ {
+ other = tgtActor;
+ }
+
+ ///
+ /// Returns a copy of the action.
+ ///
+ public override ActionInstant clone()
+ {
+ return new ActionSetDirection(value);
+ }
+
+ ///
+ /// This method is called at the action start.
+ ///
+ public override void start()
+ {
+ base.start();
+ if (other != null)
+ {
+ value = other.transform.position;
+ }
+ if (is2d)
+ {
+ value.z = transform.position.z;
+ }
+ transform.rotation = Quaternion.LookRotation(transform.position - value);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/ActionsInstant/ActionSetPlace.cs b/src/ActionsInstant/ActionSetPlace.cs
index daafe6f..87f375f 100644
--- a/src/ActionsInstant/ActionSetPlace.cs
+++ b/src/ActionsInstant/ActionSetPlace.cs
@@ -2,32 +2,44 @@
using System.Collections.Generic;
using UnityEngine;
-class ActionSetPlace : Action
+namespace coa4u
{
- protected Vector3 value;
-
- public ActionSetPlace(Vector3 tgtPlace)
- : base()
+ ///
+ /// Instantly moves the target to the given point.
+ ///
+ class ActionSetPlace : ActionInstant
{
- value = tgtPlace;
- }
+ protected Vector3 value;
- public ActionSetPlace(Vector2 tgtPlace)
- : this((Vector3) tgtPlace)
- {
- is2d = true;
- }
+ public ActionSetPlace(Vector3 tgtPlace)
+ : base()
+ {
+ value = tgtPlace;
+ }
- public override Action clone()
- {
- return new ActionSetPlace(value);
- }
+ public ActionSetPlace(Vector2 tgtPlace)
+ : this((Vector3)tgtPlace)
+ {
+ is2d = true;
+ }
- public override void start()
- {
- base.start();
- if (is2d)
- value.z = transform.position.z;
- transform.position = value;
+ ///
+ /// Returns a copy of the action.
+ ///
+ public override ActionInstant clone()
+ {
+ return new ActionSetPlace(value);
+ }
+
+ ///
+ /// This method is called at the action start.
+ ///
+ public override void start()
+ {
+ base.start();
+ if (is2d)
+ value.z = transform.position.z;
+ transform.position = value;
+ }
}
}
\ No newline at end of file
diff --git a/src/ActionsInstant/ActionSetRotation.cs b/src/ActionsInstant/ActionSetRotation.cs
index 85e9f41..25d8820 100644
--- a/src/ActionsInstant/ActionSetRotation.cs
+++ b/src/ActionsInstant/ActionSetRotation.cs
@@ -2,31 +2,42 @@
using System.Collections.Generic;
using UnityEngine;
-class ActionSetRotation : Action
+namespace coa4u
{
- protected Vector3 value;
-
- public ActionSetRotation(Vector3 tgtValue)
- : base()
+ ///
+ /// Instantly rotates the target.
+ ///
+ class ActionSetRotation : ActionInstant
{
- value = tgtValue;
- }
+ protected Vector3 value;
- public ActionSetRotation(float angle)
- : this(new Vector3(0, 0, angle))
- {
- is2d = true;
- }
+ public ActionSetRotation(Vector3 tgtValue)
+ : base()
+ {
+ value = tgtValue;
+ }
- public override Action clone()
- {
- return new ActionSetRotation(value);
- }
+ public ActionSetRotation(float angle)
+ : this(new Vector3(0, 0, angle))
+ {
+ is2d = true;
+ }
- public override void start()
- {
- base.start();
- transform.rotation = Quaternion.Euler(value);
+ ///
+ /// Returns a copy of the action.
+ ///
+ public override ActionInstant clone()
+ {
+ return new ActionSetRotation(value);
+ }
+ ///
+ /// This method is called at the action start.
+ ///
+ public override void start()
+ {
+ base.start();
+ transform.rotation = Quaternion.Euler(value);
+ }
}
}
\ No newline at end of file
diff --git a/src/ActionsInstant/ActionSetTint.cs b/src/ActionsInstant/ActionSetTint.cs
index 5b98adf..d9160b1 100644
--- a/src/ActionsInstant/ActionSetTint.cs
+++ b/src/ActionsInstant/ActionSetTint.cs
@@ -2,20 +2,37 @@
using System.Collections.Generic;
using UnityEngine;
-class ActionSetTint : Action
+namespace coa4u
{
- public Vector4 color;
- protected const float coeff = 1F / 255F;
-
- public ActionSetTint(Vector4 tgtColor)
- : base()
+ ///
+ /// Instantly tints the target to the given color.
+ ///
+ class ActionSetTint : ActionInstant
{
- color = tgtColor * coeff;
- }
+ public Vector4 color;
+ protected const float coeff = 1F / 255F;
- public override void start()
- {
- base.start();
- renderer.material.color = new Color(color[0], color[1], color[2], color[3]);
+ public ActionSetTint(Vector4 tgtColor)
+ : base()
+ {
+ color = tgtColor * coeff;
+ }
+
+ ///
+ /// Returns a copy of the action.
+ ///
+ public override ActionInstant clone()
+ {
+ return new ActionSetTint(color * 255F);
+ }
+
+ ///
+ /// This method is called at the action start.
+ ///
+ public override void start()
+ {
+ base.start();
+ renderer.material.color = new Color(color[0], color[1], color[2], color[3]);
+ }
}
}
\ No newline at end of file
diff --git a/src/ActionsInstant/ActionShow.cs b/src/ActionsInstant/ActionShow.cs
index 0265bf1..e5285b7 100644
--- a/src/ActionsInstant/ActionShow.cs
+++ b/src/ActionsInstant/ActionShow.cs
@@ -2,22 +2,42 @@
using System.Collections.Generic;
using UnityEngine;
-class ActionShow : Action
+namespace coa4u
{
-
- public ActionShow()
- : base()
+ ///
+ /// Instantly shows the hidden target. This action does not require the transparency support in shaders.
+ ///
+ class ActionShow : ActionInstant
{
- }
- public override Action clone()
- {
- return new ActionShow();
- }
+ public ActionShow()
+ : base()
+ {
+ }
- public override void start()
- {
- base.start();
- renderer.enabled = true;
+ ///
+ /// Returns a copy of the action.
+ ///
+ public override ActionInstant clone()
+ {
+ return new ActionShow();
+ }
+
+ ///
+ /// Returns the reversed version of the action, if it is possible.
+ ///
+ public override ActionInstant reverse()
+ {
+ return new ActionHide();
+ }
+
+ ///
+ /// This method is called at the action start.
+ ///
+ public override void start()
+ {
+ base.start();
+ renderer.enabled = true;
+ }
}
}
\ No newline at end of file
diff --git a/src/ActionsInstant/ActionToggleVisibility.cs b/src/ActionsInstant/ActionToggleVisibility.cs
index 51f7ae3..5c283a3 100644
--- a/src/ActionsInstant/ActionToggleVisibility.cs
+++ b/src/ActionsInstant/ActionToggleVisibility.cs
@@ -2,17 +2,42 @@
using System.Collections.Generic;
using UnityEngine;
-class ActionToggleVisibility : Action
+namespace coa4u
{
-
- public ActionToggleVisibility()
- : base()
+ ///
+ /// Instantly hides the target or showes it, if it's hidden. This action does not require the transparency support in shaders.
+ ///
+ class ActionToggleVisibility : ActionInstant
{
- }
- public override void start()
- {
- base.start();
- renderer.enabled = !renderer.enabled;
+ public ActionToggleVisibility()
+ : base()
+ {
+ }
+
+ ///
+ /// Returns a copy of the action.
+ ///
+ public override ActionInstant clone()
+ {
+ return new ActionToggleVisibility();
+ }
+
+ ///
+ /// Returns the reversed version of the action, if it is possible.
+ ///
+ public override ActionInstant reverse()
+ {
+ return new ActionToggleVisibility();
+ }
+
+ ///
+ /// This method is called at the action start.
+ ///
+ public override void start()
+ {
+ base.start();
+ renderer.enabled = !renderer.enabled;
+ }
}
}
\ No newline at end of file
diff --git a/src/ActionsInterval/ActionBezierAbs.cs b/src/ActionsInterval/ActionBezierAbs.cs
index d5dbbed..c105cd8 100644
--- a/src/ActionsInterval/ActionBezierAbs.cs
+++ b/src/ActionsInterval/ActionBezierAbs.cs
@@ -2,58 +2,76 @@
using System.Collections.Generic;
using UnityEngine;
-class ActionBezierAbs : ActionInterval
+namespace coa4u
{
- protected Vector3 startPoint;
- protected Vector3 endPoint;
- protected Vector3 startControlPoint;
- protected Vector3 endControlPoint;
-
- public ActionBezierAbs(Vector3 tgtStart, Vector3 tgtSCP, Vector3 tgtECP, Vector3 tgtEnd, float tgtDuration)
- : base(tgtDuration)
+ ///
+ /// Moves the target with a cubic Bezier in absolute coordinates (if the target is not in the start point, it'll be positioned there when the action starts).
+ ///
+ class ActionBezierAbs : ActionInterval
{
- startPoint = tgtStart;
- endPoint = tgtEnd;
- startControlPoint = tgtSCP;
- endControlPoint = tgtECP;
- }
+ protected Vector3 startPoint;
+ protected Vector3 endPoint;
+ protected Vector3 startControlPoint;
+ protected Vector3 endControlPoint;
- public ActionBezierAbs(Vector2 tgtStart, Vector2 tgtSCP, Vector2 tgtECP, Vector2 tgtEnd, float tgtDuration)
- : this((Vector3) tgtStart, (Vector3) tgtSCP, (Vector3) tgtECP, (Vector3) tgtEnd, tgtDuration)
- {
- is2d = true;
- }
+ public ActionBezierAbs(Vector3 tgtStart, Vector3 tgtSCP, Vector3 tgtECP, Vector3 tgtEnd, float tgtDuration)
+ : base(tgtDuration)
+ {
+ startPoint = tgtStart;
+ endPoint = tgtEnd;
+ startControlPoint = tgtSCP;
+ endControlPoint = tgtECP;
+ }
- public override Action clone()
- {
- return new ActionBezierAbs(startPoint, startControlPoint, endControlPoint, endPoint, duration);
- }
+ public ActionBezierAbs(Vector2 tgtStart, Vector2 tgtSCP, Vector2 tgtECP, Vector2 tgtEnd, float tgtDuration)
+ : this((Vector3)tgtStart, (Vector3)tgtSCP, (Vector3)tgtECP, (Vector3)tgtEnd, tgtDuration)
+ {
+ is2d = true;
+ }
- public override Action reverse()
- {
- return new ActionBezierAbs(endPoint, endControlPoint, startControlPoint, startPoint, duration);
- }
+ ///
+ /// Returns a copy of the action.
+ ///
+ public override ActionInstant clone()
+ {
+ return new ActionBezierAbs(startPoint, startControlPoint, endControlPoint, endPoint, duration);
+ }
- public override void start()
- {
- base.start();
- float z = transform.position.z;
- if (is2d)
+ ///
+ /// Returns the reversed version of the action, if it is possible.
+ ///
+ public override ActionInstant reverse()
{
- startPoint.z = z;
- endPoint.z = z;
- startControlPoint.z = z;
- endControlPoint.z = z;
+ return new ActionBezierAbs(endPoint, endControlPoint, startControlPoint, startPoint, duration);
}
- }
- public override void stepInterval(float dt)
- {
- float t = timer / duration;
- Vector3 newPosition = (((-startPoint
- + 3 * (startControlPoint - endControlPoint) + endPoint) * t
- + (3 * (startPoint + endControlPoint) - 6 * startControlPoint)) * t +
- 3 * (startControlPoint - startPoint)) * t + startPoint;
- transform.position = newPosition;
+ ///
+ /// This method is called at the action start.
+ ///
+ public override void start()
+ {
+ base.start();
+ float z = transform.position.z;
+ if (is2d)
+ {
+ startPoint.z = z;
+ endPoint.z = z;
+ startControlPoint.z = z;
+ endControlPoint.z = z;
+ }
+ }
+
+ ///
+ /// This method is called every frame update.
+ ///
+ public override void stepInterval(float dt)
+ {
+ float t = timer / duration;
+ Vector3 newPosition = (((-startPoint
+ + 3 * (startControlPoint - endControlPoint) + endPoint) * t
+ + (3 * (startPoint + endControlPoint) - 6 * startControlPoint)) * t +
+ 3 * (startControlPoint - startPoint)) * t + startPoint;
+ transform.position = newPosition;
+ }
}
}
\ No newline at end of file
diff --git a/src/ActionsInterval/ActionBezierRel.cs b/src/ActionsInterval/ActionBezierRel.cs
index 4029e04..b903c37 100644
--- a/src/ActionsInterval/ActionBezierRel.cs
+++ b/src/ActionsInterval/ActionBezierRel.cs
@@ -2,56 +2,74 @@
using System.Collections.Generic;
using UnityEngine;
-class ActionBezierRel : ActionInterval
+namespace coa4u
{
- protected Vector3 ep;
- protected Vector3 cp1;
- protected Vector3 cp2;
- protected Vector3 startPoint;
- protected Vector3 endPoint;
- protected Vector3 startControlPoint;
- protected Vector3 endControlPoint;
-
- public ActionBezierRel(Vector3 tgtSCP, Vector3 tgtECP, Vector3 tgtEnd, float tgtDuration)
- : base(tgtDuration)
+ ///
+ /// Moves the target with a cubic Bezier in relative coordinates.
+ ///
+ class ActionBezierRel : ActionInterval
{
- ep = tgtEnd;
- cp1 = tgtSCP;
- cp2 = tgtECP;
- }
+ protected Vector3 ep;
+ protected Vector3 cp1;
+ protected Vector3 cp2;
+ protected Vector3 startPoint;
+ protected Vector3 endPoint;
+ protected Vector3 startControlPoint;
+ protected Vector3 endControlPoint;
- public ActionBezierRel(Vector2 tgtSCP, Vector2 tgtECP, Vector2 tgtEnd, float tgtDuration)
- : this((Vector3)tgtSCP, (Vector3)tgtECP, (Vector3)tgtEnd, tgtDuration)
- {
- is2d = true;
- }
+ public ActionBezierRel(Vector3 tgtSCP, Vector3 tgtECP, Vector3 tgtEnd, float tgtDuration)
+ : base(tgtDuration)
+ {
+ ep = tgtEnd;
+ cp1 = tgtSCP;
+ cp2 = tgtECP;
+ }
- public override Action clone()
- {
- return new ActionBezierRel(startControlPoint, endControlPoint, endPoint, duration);
- }
+ public ActionBezierRel(Vector2 tgtSCP, Vector2 tgtECP, Vector2 tgtEnd, float tgtDuration)
+ : this((Vector3)tgtSCP, (Vector3)tgtECP, (Vector3)tgtEnd, tgtDuration)
+ {
+ is2d = true;
+ }
- public override Action reverse()
- {
- return new ActionBezierRel(-startControlPoint, -endControlPoint, -endPoint, duration);
- }
+ ///
+ /// Returns a copy of the action.
+ ///
+ public override ActionInstant clone()
+ {
+ return new ActionBezierRel(startControlPoint, endControlPoint, endPoint, duration);
+ }
- public override void start()
- {
- base.start();
- startPoint = target.transform.position;
- endPoint = startPoint + ep;
- startControlPoint = startPoint + cp1;
- endControlPoint = startControlPoint + cp2;
- }
+ ///
+ /// Returns the reversed version of the action, if it is possible.
+ ///
+ public override ActionInstant reverse()
+ {
+ return new ActionBezierRel(-startControlPoint, -endControlPoint, -endPoint, duration);
+ }
- public override void stepInterval(float dt)
- {
- float t = timer / duration;
- Vector3 newPosition = (((-startPoint
- + 3 * (startControlPoint - endControlPoint) + endPoint) * t
- + (3 * (startPoint + endControlPoint) - 6 * startControlPoint)) * t +
- 3 * (startControlPoint - startPoint)) * t + startPoint;
- transform.position = newPosition;
+ ///
+ /// This method is called at the action start.
+ ///
+ public override void start()
+ {
+ base.start();
+ startPoint = target.transform.position;
+ endPoint = startPoint + ep;
+ startControlPoint = startPoint + cp1;
+ endControlPoint = startControlPoint + cp2;
+ }
+
+ ///
+ /// This method is called every frame update.
+ ///
+ public override void stepInterval(float dt)
+ {
+ float t = timer / duration;
+ Vector3 newPosition = (((-startPoint
+ + 3 * (startControlPoint - endControlPoint) + endPoint) * t
+ + (3 * (startPoint + endControlPoint) - 6 * startControlPoint)) * t +
+ 3 * (startControlPoint - startPoint)) * t + startPoint;
+ transform.position = newPosition;
+ }
}
}
\ No newline at end of file
diff --git a/src/ActionsInterval/ActionBlink.cs b/src/ActionsInterval/ActionBlink.cs
index 3f1f228..e8310b6 100644
--- a/src/ActionsInterval/ActionBlink.cs
+++ b/src/ActionsInterval/ActionBlink.cs
@@ -2,49 +2,61 @@
using System.Collections.Generic;
using UnityEngine;
-class ActionBlink : ActionRepeat
+namespace coa4u
{
- protected bool randomDelay;
- protected ActionDelay delay = new ActionDelay(0);
- protected Action[] blinkSeq;
- protected float durationMin;
- protected float durationMax;
-
- public ActionBlink(int tgtBlinks, float tgtDuration)
- : base(null, 0)
+ ///
+ /// Blinks the target.
+ ///
+ class ActionBlink : ActionRepeat
{
- durationMin = tgtDuration;
- durationMax = tgtDuration;
- count = (tgtBlinks) * 2;
- blinkSeq = new Action[]
+ protected bool randomDelay;
+ protected ActionDelay delay = new ActionDelay(0);
+ protected ActionInstant[] blinkSeq;
+ protected float durationMin;
+ protected float durationMax;
+
+ public ActionBlink(int tgtBlinks, float tgtDuration)
+ : base(null, 0)
+ {
+ durationMin = tgtDuration;
+ durationMax = tgtDuration;
+ count = (tgtBlinks) * 2;
+ blinkSeq = new ActionInstant[]
{
new ActionToggleVisibility(),
new ActionDelay(tgtDuration / tgtBlinks)
};
- action = new ActionSequence(blinkSeq);
- }
+ action = new ActionSequence(blinkSeq);
+ }
- public ActionBlink(int tgtBlinks, float tgtDurationMin, float tgtDurationMax)
- : base(null, 0)
- {
- durationMin = tgtDurationMin;
- durationMax = tgtDurationMax;
- count = (tgtBlinks) * 2;
- blinkSeq = new Action[]
+ public ActionBlink(int tgtBlinks, float tgtDurationMin, float tgtDurationMax)
+ : base(null, 0)
+ {
+ durationMin = tgtDurationMin;
+ durationMax = tgtDurationMax;
+ count = (tgtBlinks) * 2;
+ blinkSeq = new ActionInstant[]
{
new ActionToggleVisibility(),
new ActionDelay(tgtDurationMin / tgtBlinks, tgtDurationMax / tgtBlinks)
};
- action = new ActionSequence(blinkSeq);
- }
+ action = new ActionSequence(blinkSeq);
+ }
- public override Action clone()
- {
- return new ActionBlink(count / 2 - 1, durationMin, durationMax);
- }
+ ///
+ /// Returns a copy of the action.
+ ///
+ public override ActionInstant clone()
+ {
+ return new ActionBlink(count / 2 - 1, durationMin, durationMax);
+ }
- public override Action reverse()
- {
- return new ActionBlink(count / 2 - 1, durationMin, durationMax);
+ ///
+ /// Returns the reversed version of the action, if it is possible.
+ ///
+ public override ActionInstant reverse()
+ {
+ return new ActionBlink(count / 2 - 1, durationMin, durationMax);
+ }
}
}
\ No newline at end of file
diff --git a/src/ActionsInterval/ActionDelay.cs b/src/ActionsInterval/ActionDelay.cs
index 296450d..ec2d09f 100644
--- a/src/ActionsInterval/ActionDelay.cs
+++ b/src/ActionsInterval/ActionDelay.cs
@@ -2,31 +2,40 @@
using System.Collections.Generic;
using UnityEngine;
-class ActionDelay : ActionInterval
+namespace coa4u
{
- protected float durationMin;
- protected float durationMax;
-
- public ActionDelay(float tgtDuration)
- : base(tgtDuration)
+ ///
+ /// Delays the action for the given amount of seconds.
+ ///
+ class ActionDelay : ActionInterval
{
- durationMin = tgtDuration;
- durationMax = tgtDuration;
- }
+ protected float durationMin;
+ protected float durationMax;
- public ActionDelay(float tgtDuration, float tgtDurationMax)
- : base(tgtDuration)
- {
- durationMin = tgtDuration;
- durationMax = tgtDurationMax;
- }
+ public ActionDelay(float tgtDuration)
+ : base(tgtDuration)
+ {
+ durationMin = tgtDuration;
+ durationMax = tgtDuration;
+ }
- public override void start()
- {
- base.start();
- if (durationMax != null)
+ public ActionDelay(float tgtDuration, float tgtDurationMax)
+ : base(tgtDuration)
+ {
+ durationMin = tgtDuration;
+ durationMax = tgtDurationMax;
+ }
+
+ ///
+ /// This method is called at the action start.
+ ///
+ public override void start()
{
- duration = UnityEngine.Random.Range(durationMin, durationMax);
+ base.start();
+ if (durationMax != null)
+ {
+ duration = UnityEngine.Random.Range(durationMin, durationMax);
+ }
}
}
}
\ No newline at end of file
diff --git a/src/ActionsInterval/ActionFadeBy.cs b/src/ActionsInterval/ActionFadeBy.cs
index 56b9123..77611b4 100644
--- a/src/ActionsInterval/ActionFadeBy.cs
+++ b/src/ActionsInterval/ActionFadeBy.cs
@@ -2,31 +2,46 @@
using System.Collections.Generic;
using UnityEngine;
-class ActionFadeBy : ActionInterval
+namespace coa4u
{
- protected float delta;
-
- public ActionFadeBy(float tgtDelta, float tgtDuration)
- : base(tgtDuration)
+ ///
+ /// Fades the target by the given alpha value. The tartet shaders should support transparency in order to use this action.
+ ///
+ class ActionFadeBy : ActionInterval
{
- delta = tgtDelta;
- }
+ protected float delta;
- public override Action clone()
- {
- return new ActionFadeBy(delta, duration);
- }
+ public ActionFadeBy(float tgtDelta, float tgtDuration)
+ : base(tgtDuration)
+ {
+ delta = tgtDelta;
+ }
- public override Action reverse()
- {
- return new ActionFadeBy(-delta, duration);
- }
+ ///
+ /// Returns a copy of the action.
+ ///
+ public override ActionInstant clone()
+ {
+ return new ActionFadeBy(delta, duration);
+ }
- public override void stepInterval(float dt)
- {
- float d = dt / duration;
- Color tgtColor = renderer.material.color;
- tgtColor[3] += delta * d;
- renderer.material.color = tgtColor;
+ ///
+ /// Returns the reversed version of the action, if it is possible.
+ ///
+ public override ActionInstant reverse()
+ {
+ return new ActionFadeBy(-delta, duration);
+ }
+
+ ///
+ /// This method is called every frame update.
+ ///
+ public override void stepInterval(float dt)
+ {
+ float d = dt / duration;
+ Color tgtColor = renderer.material.color;
+ tgtColor[3] += delta * d;
+ renderer.material.color = tgtColor;
+ }
}
}
\ No newline at end of file
diff --git a/src/ActionsInterval/ActionFadeIn.cs b/src/ActionsInterval/ActionFadeIn.cs
index ed80f4b..8ec09d4 100644
--- a/src/ActionsInterval/ActionFadeIn.cs
+++ b/src/ActionsInterval/ActionFadeIn.cs
@@ -2,21 +2,33 @@
using System.Collections.Generic;
using UnityEngine;
-class ActionFadeIn : ActionFadeTo
+namespace coa4u
{
-
- public ActionFadeIn(float tgtDuration)
- : base(1, tgtDuration)
+ ///
+ /// Fades in the target. The tartet shaders should support transparency in order to use this action.
+ ///
+ class ActionFadeIn : ActionFadeTo
{
- }
- public override Action clone()
- {
- return new ActionFadeIn(duration);
- }
+ public ActionFadeIn(float tgtDuration)
+ : base(1, tgtDuration)
+ {
+ }
- public override Action reverse()
- {
- return new ActionFadeIn(duration);
+ ///
+ /// Returns a copy of the action.
+ ///
+ public override ActionInstant clone()
+ {
+ return new ActionFadeIn(duration);
+ }
+
+ ///
+ /// Returns the reversed version of the action, if it is possible.
+ ///
+ public override ActionInstant reverse()
+ {
+ return new ActionFadeOut(duration);
+ }
}
}
\ No newline at end of file
diff --git a/src/ActionsInterval/ActionFadeOut.cs b/src/ActionsInterval/ActionFadeOut.cs
index dd82570..5b3adcd 100644
--- a/src/ActionsInterval/ActionFadeOut.cs
+++ b/src/ActionsInterval/ActionFadeOut.cs
@@ -2,21 +2,33 @@
using System.Collections.Generic;
using UnityEngine;
-class ActionFadeOut : ActionFadeTo
+namespace coa4u
{
-
- public ActionFadeOut(float tgtDuration)
- : base(0, tgtDuration)
+ ///
+ /// Fades out the target. The tartet shaders should support transparency in order to use this action.
+ ///
+ class ActionFadeOut : ActionFadeTo
{
- }
- public override Action clone()
- {
- return new ActionFadeOut(duration);
- }
+ public ActionFadeOut(float tgtDuration)
+ : base(0, tgtDuration)
+ {
+ }
- public override Action reverse()
- {
- return new ActionFadeOut(duration);
+ ///
+ /// Returns a copy of the action.
+ ///
+ public override ActionInstant clone()
+ {
+ return new ActionFadeOut(duration);
+ }
+
+ ///
+ /// Returns the reversed version of the action, if it is possible.
+ ///
+ public override ActionInstant reverse()
+ {
+ return new ActionFadeIn(duration);
+ }
}
}
\ No newline at end of file
diff --git a/src/ActionsInterval/ActionFadeTo.cs b/src/ActionsInterval/ActionFadeTo.cs
index ba9b84b..320f70b 100644
--- a/src/ActionsInterval/ActionFadeTo.cs
+++ b/src/ActionsInterval/ActionFadeTo.cs
@@ -2,33 +2,48 @@
using System.Collections.Generic;
using UnityEngine;
-class ActionFadeTo : ActionInterval
+namespace coa4u
{
- protected float value;
- protected float delta;
-
- public ActionFadeTo(float tgtValue, float tgtDuration)
- : base(tgtDuration)
+ ///
+ /// Fades the target to the given alpha value. The tartet shaders should support transparency in order to use this action.
+ ///
+ class ActionFadeTo : ActionInterval
{
- value = tgtValue;
- }
+ protected float value;
+ protected float delta;
- public override Action clone()
- {
- return new ActionFadeTo(value, duration);
- }
+ public ActionFadeTo(float tgtValue, float tgtDuration)
+ : base(tgtDuration)
+ {
+ value = tgtValue;
+ }
- public override void start()
- {
- base.start();
- delta = value - renderer.material.color.a;
- }
+ ///
+ /// Returns a copy of the action.
+ ///
+ public override ActionInstant clone()
+ {
+ return new ActionFadeTo(value, duration);
+ }
- public override void stepInterval(float dt)
- {
- float d = dt / duration;
- Color tgtColor = renderer.material.color;
- tgtColor[3] += delta * d;
- renderer.material.color = tgtColor;
+ ///
+ /// This method is called at the action start.
+ ///
+ public override void start()
+ {
+ base.start();
+ delta = value - renderer.material.color.a;
+ }
+
+ ///
+ /// This method is called every frame update.
+ ///
+ public override void stepInterval(float dt)
+ {
+ float d = dt / duration;
+ Color tgtColor = renderer.material.color;
+ tgtColor[3] += delta * d;
+ renderer.material.color = tgtColor;
+ }
}
}
\ No newline at end of file
diff --git a/src/ActionsInterval/ActionJumpBy.cs b/src/ActionsInterval/ActionJumpBy.cs
index 1264723..ce7b03d 100644
--- a/src/ActionsInterval/ActionJumpBy.cs
+++ b/src/ActionsInterval/ActionJumpBy.cs
@@ -2,48 +2,51 @@
using System.Collections.Generic;
using UnityEngine;
-class ActionJumpBy : ActionSequence
+namespace coa4u
{
- protected Vector3 point;
- float height;
- int jumps;
-
- public ActionJumpBy(Vector3 tgtPoint, float tgtHeight, int tgtJumps, float tgtDuration)
- : base(new Action[tgtJumps])
+ class ActionJumpBy : ActionSequence
{
- point = tgtPoint;
- jumps = tgtJumps;
- height = tgtHeight;
- duration = tgtDuration;
- }
+ protected Vector3 point;
+ float height;
+ int jumps;
- public ActionJumpBy(Vector2 tgtPoint, float tgtHeight, int tgtJumps, float tgtDuration)
- : this((Vector3)tgtPoint, tgtHeight, tgtJumps, tgtDuration)
- {
- is2d = true;
- }
+ public ActionJumpBy(Vector3 tgtPoint, float tgtHeight, int tgtJumps, float tgtDuration)
+ : base(new ActionInstant[tgtJumps])
+ {
+ point = tgtPoint;
+ jumps = tgtJumps;
+ height = tgtHeight;
+ duration = tgtDuration;
+ }
- public override Action clone()
- {
- return new ActionJumpBy(point, height, jumps, duration);
- }
+ public ActionJumpBy(Vector2 tgtPoint, float tgtHeight, int tgtJumps, float tgtDuration)
+ : this((Vector3)tgtPoint, tgtHeight, tgtJumps, tgtDuration)
+ {
+ is2d = true;
+ }
- public override Action reverse()
- {
- return new ActionJumpBy(-point, height, jumps, duration);
- }
+ public override ActionInstant clone()
+ {
+ return new ActionJumpBy(point, height, jumps, duration);
+ }
- public override void start()
- {
- float coeff = 1F / jumps;
- Vector3 end = point * coeff;
- Vector3 cp1 = Vector3.up * height;
- Vector3 cp2 = end + cp1;
- ActionBezierRel singleJump = new ActionBezierRel(cp1, cp2, end, duration * coeff);
- for (int i = 0; i < jumps; i++)
+ public override ActionInstant reverse()
+ {
+ return new ActionJumpBy(-point, height, jumps, duration);
+ }
+
+ public override void start()
{
- actions[i] = singleJump;
+ float coeff = 1F / jumps;
+ Vector3 end = point * coeff;
+ Vector3 cp1 = Vector3.up * height;
+ Vector3 cp2 = end + cp1;
+ ActionBezierRel singleJump = new ActionBezierRel(cp1, cp2, end, duration * coeff);
+ for (int i = 0; i < jumps; i++)
+ {
+ actions[i] = singleJump;
+ }
+ base.start();
}
- base.start();
}
}
\ No newline at end of file
diff --git a/src/ActionsInterval/ActionJumpTo.cs b/src/ActionsInterval/ActionJumpTo.cs
index 97892ba..049f732 100644
--- a/src/ActionsInterval/ActionJumpTo.cs
+++ b/src/ActionsInterval/ActionJumpTo.cs
@@ -2,46 +2,49 @@
using System.Collections.Generic;
using UnityEngine;
-class ActionJumpTo : ActionSequence
+namespace coa4u
{
- protected Vector3 point;
- float height;
- int jumps;
-
- public ActionJumpTo(Vector3 tgtPoint, float tgtHeight, int tgtJumps, float tgtDuration)
- : base(new Action[tgtJumps])
+ class ActionJumpTo : ActionSequence
{
- point = tgtPoint;
- jumps = tgtJumps;
- height = tgtHeight;
- duration = tgtDuration;
- }
+ protected Vector3 point;
+ float height;
+ int jumps;
- public ActionJumpTo(Vector2 tgtPoint, float tgtHeight, int tgtJumps, float tgtDuration)
- : this((Vector3)tgtPoint, tgtHeight, tgtJumps, tgtDuration)
- {
- is2d = true;
- }
+ public ActionJumpTo(Vector3 tgtPoint, float tgtHeight, int tgtJumps, float tgtDuration)
+ : base(new ActionInstant[tgtJumps])
+ {
+ point = tgtPoint;
+ jumps = tgtJumps;
+ height = tgtHeight;
+ duration = tgtDuration;
+ }
- public override Action clone()
- {
- return new ActionJumpTo(point, height, jumps, duration);
- }
+ public ActionJumpTo(Vector2 tgtPoint, float tgtHeight, int tgtJumps, float tgtDuration)
+ : this((Vector3)tgtPoint, tgtHeight, tgtJumps, tgtDuration)
+ {
+ is2d = true;
+ }
- public override void start()
- {
- float coeff = 1F / jumps;
- if (is2d)
- point.z = transform.position.z;
- Vector3 start = target.gameObject.transform.position;
- Vector3 end = (point - start) * coeff;
- Vector3 cp1 = Vector3.up * height;
- Vector3 cp2 = end + cp1;
- ActionBezierRel singleJump = new ActionBezierRel(cp1, cp2, end, duration * coeff);
- for (int i = 0; i < jumps; i++)
+ public override ActionInstant clone()
+ {
+ return new ActionJumpTo(point, height, jumps, duration);
+ }
+
+ public override void start()
{
- actions[i] = singleJump;
+ float coeff = 1F / jumps;
+ if (is2d)
+ point.z = transform.position.z;
+ Vector3 start = target.gameObject.transform.position;
+ Vector3 end = (point - start) * coeff;
+ Vector3 cp1 = Vector3.up * height;
+ Vector3 cp2 = end + cp1;
+ ActionBezierRel singleJump = new ActionBezierRel(cp1, cp2, end, duration * coeff);
+ for (int i = 0; i < jumps; i++)
+ {
+ actions[i] = singleJump;
+ }
+ base.start();
}
- base.start();
}
}
\ No newline at end of file
diff --git a/src/ActionsInterval/ActionMoveBy.cs b/src/ActionsInterval/ActionMoveBy.cs
index 43f5130..ae6a682 100644
--- a/src/ActionsInterval/ActionMoveBy.cs
+++ b/src/ActionsInterval/ActionMoveBy.cs
@@ -2,36 +2,39 @@
using System.Collections.Generic;
using UnityEngine;
-class ActionMoveBy : ActionInterval
+namespace coa4u
{
- protected Vector3 delta;
-
- public ActionMoveBy(Vector3 tgtDelta, float tgtDuration)
- : base(tgtDuration)
+ class ActionMoveBy : ActionInterval
{
- delta = tgtDelta;
- }
+ protected Vector3 delta;
- public ActionMoveBy(Vector2 tgtValue, float tgtDuration)
- : this((Vector3) tgtValue, tgtDuration)
- {
- is2d = true;
- }
+ public ActionMoveBy(Vector3 tgtDelta, float tgtDuration)
+ : base(tgtDuration)
+ {
+ delta = tgtDelta;
+ }
- public override Action clone()
- {
- return new ActionMoveBy(delta, duration);
- }
+ public ActionMoveBy(Vector2 tgtValue, float tgtDuration)
+ : this((Vector3)tgtValue, tgtDuration)
+ {
+ is2d = true;
+ }
- public override Action reverse()
- {
- return new ActionMoveBy(delta * -1F, duration);
- }
+ public override ActionInstant clone()
+ {
+ return new ActionMoveBy(delta, duration);
+ }
- public override void stepInterval(float dt)
- {
- float d = dt / duration;
- Vector3 tgt = delta * d;
- transform.Translate(tgt, Space.World);
+ public override ActionInstant reverse()
+ {
+ return new ActionMoveBy(delta * -1F, duration);
+ }
+
+ public override void stepInterval(float dt)
+ {
+ float d = dt / duration;
+ Vector3 tgt = delta * d;
+ transform.Translate(tgt, Space.World);
+ }
}
}
\ No newline at end of file
diff --git a/src/ActionsInterval/ActionMoveTo.cs b/src/ActionsInterval/ActionMoveTo.cs
index 656fb74..dfcfd22 100644
--- a/src/ActionsInterval/ActionMoveTo.cs
+++ b/src/ActionsInterval/ActionMoveTo.cs
@@ -2,40 +2,43 @@
using System.Collections.Generic;
using UnityEngine;
-class ActionMoveTo : ActionInterval
+namespace coa4u
{
- protected Vector3 value;
- protected Vector3 path;
-
- public ActionMoveTo(Vector3 tgtValue, float tgtDuration)
- : base(tgtDuration)
+ class ActionMoveTo : ActionInterval
{
- value = tgtValue;
- }
+ protected Vector3 value;
+ protected Vector3 path;
- public ActionMoveTo(Vector2 tgtValue, float tgtDuration)
- : this((Vector3) tgtValue, tgtDuration)
- {
- is2d = true;
- }
+ public ActionMoveTo(Vector3 tgtValue, float tgtDuration)
+ : base(tgtDuration)
+ {
+ value = tgtValue;
+ }
- public override Action clone()
- {
- return new ActionMoveBy(value, duration);
- }
+ public ActionMoveTo(Vector2 tgtValue, float tgtDuration)
+ : this((Vector3)tgtValue, tgtDuration)
+ {
+ is2d = true;
+ }
- public override void start()
- {
- base.start();
- if (is2d)
- value.z = transform.position.z;
- path = value - transform.position;
- }
+ public override ActionInstant clone()
+ {
+ return new ActionMoveBy(value, duration);
+ }
- public override void stepInterval(float dt)
- {
- float d = dt / duration;
- Vector3 tgt = path * d;
- transform.Translate(tgt, Space.World);
+ public override void start()
+ {
+ base.start();
+ if (is2d)
+ value.z = transform.position.z;
+ path = value - transform.position;
+ }
+
+ public override void stepInterval(float dt)
+ {
+ float d = dt / duration;
+ Vector3 tgt = path * d;
+ transform.Translate(tgt, Space.World);
+ }
}
}
\ No newline at end of file
diff --git a/src/ActionsInterval/ActionRotateBy.cs b/src/ActionsInterval/ActionRotateBy.cs
index 316bb24..acbabc3 100644
--- a/src/ActionsInterval/ActionRotateBy.cs
+++ b/src/ActionsInterval/ActionRotateBy.cs
@@ -2,36 +2,39 @@
using System.Collections.Generic;
using UnityEngine;
-class ActionRotateBy : ActionInterval
+namespace coa4u
{
- protected Vector3 delta;
-
- public ActionRotateBy(Vector3 tgtDelta, float tgtDuration)
- : base(tgtDuration)
+ class ActionRotateBy : ActionInterval
{
- delta = tgtDelta;
- }
+ protected Vector3 delta;
- public ActionRotateBy(float angle, float tgtDuration)
- : this(new Vector3(0, 0, angle), tgtDuration)
- {
- is2d = true;
- }
+ public ActionRotateBy(Vector3 tgtDelta, float tgtDuration)
+ : base(tgtDuration)
+ {
+ delta = tgtDelta;
+ }
- public override Action clone()
- {
- return new ActionRotateBy(delta, duration);
- }
+ public ActionRotateBy(float angle, float tgtDuration)
+ : this(new Vector3(0, 0, angle), tgtDuration)
+ {
+ is2d = true;
+ }
- public override Action reverse()
- {
- return new ActionRotateBy(delta * -1F, duration);
- }
+ public override ActionInstant clone()
+ {
+ return new ActionRotateBy(delta, duration);
+ }
- public override void stepInterval(float dt)
- {
- float d = dt / duration;
- Vector3 tgt = delta * d;
- transform.rotation = Quaternion.Euler(transform.rotation.eulerAngles + tgt);
+ public override ActionInstant reverse()
+ {
+ return new ActionRotateBy(delta * -1F, duration);
+ }
+
+ public override void stepInterval(float dt)
+ {
+ float d = dt / duration;
+ Vector3 tgt = delta * d;
+ transform.rotation = Quaternion.Euler(transform.rotation.eulerAngles + tgt);
+ }
}
}
\ No newline at end of file
diff --git a/src/ActionsInterval/ActionRotateTo.cs b/src/ActionsInterval/ActionRotateTo.cs
index 7713ee4..bfd92a3 100644
--- a/src/ActionsInterval/ActionRotateTo.cs
+++ b/src/ActionsInterval/ActionRotateTo.cs
@@ -2,46 +2,49 @@
using System.Collections.Generic;
using UnityEngine;
-class ActionRotateTo : ActionInterval
+namespace coa4u
{
- protected Vector3 value;
- protected Vector3 path;
-
- public ActionRotateTo(Vector3 tgtValue, float tgtDuration)
- : base(tgtDuration)
+ class ActionRotateTo : ActionInterval
{
- value = tgtValue;
- }
+ protected Vector3 value;
+ protected Vector3 path;
- public ActionRotateTo(float angle, float tgtDuration)
- : this(new Vector3(0, 0, angle), tgtDuration)
- {
- is2d = true;
- }
+ public ActionRotateTo(Vector3 tgtValue, float tgtDuration)
+ : base(tgtDuration)
+ {
+ value = tgtValue;
+ }
- public override Action clone()
- {
- return new ActionRotateTo(value, duration);
- }
+ public ActionRotateTo(float angle, float tgtDuration)
+ : this(new Vector3(0, 0, angle), tgtDuration)
+ {
+ is2d = true;
+ }
- public override void start()
- {
- base.start();
- path = new Vector3();
- for (int i = 0; i < 3; i++)
+ public override ActionInstant clone()
{
- float t = value[i];
- float f = transform.rotation.eulerAngles[i];
- if (Math.Abs(t - f) < Math.Abs(t + 360 - f))
- path[i] = t - f;
- else
- path[i] = t + 360 - f;
+ return new ActionRotateTo(value, duration);
+ }
+
+ public override void start()
+ {
+ base.start();
+ path = new Vector3();
+ for (int i = 0; i < 3; i++)
+ {
+ float t = value[i];
+ float f = transform.rotation.eulerAngles[i];
+ if (Math.Abs(t - f) < Math.Abs(t + 360 - f))
+ path[i] = t - f;
+ else
+ path[i] = t + 360 - f;
+ }
+ }
+ public override void stepInterval(float dt)
+ {
+ float d = dt / duration;
+ Vector3 tgt = path * d;
+ transform.rotation = Quaternion.Euler(transform.rotation.eulerAngles + tgt);
}
- }
- public override void stepInterval(float dt)
- {
- float d = dt / duration;
- Vector3 tgt = path * d;
- transform.rotation = Quaternion.Euler(transform.rotation.eulerAngles + tgt);
}
}
\ No newline at end of file
diff --git a/src/ActionsInterval/ActionScaleBy.cs b/src/ActionsInterval/ActionScaleBy.cs
index 63d9cad..ea4d5eb 100644
--- a/src/ActionsInterval/ActionScaleBy.cs
+++ b/src/ActionsInterval/ActionScaleBy.cs
@@ -2,52 +2,55 @@
using System.Collections.Generic;
using UnityEngine;
-class ActionScaleBy : ActionInterval
+namespace coa4u
{
- protected Vector3 delta;
- protected Vector3 path;
-
- public ActionScaleBy(Vector3 tgtDelta, float tgtDuration)
- : base(tgtDuration)
- {
- delta = tgtDelta;
- }
-
- public ActionScaleBy(Vector2 tgtValue, float tgtDuration)
- : this((Vector3)tgtValue, tgtDuration)
- {
- is2d = true;
- }
-
- public override Action clone()
- {
- return new ActionScaleBy(delta, duration);
- }
-
- public override Action reverse()
- {
- return new ActionScaleBy(delta * -1F, duration);
- }
-
- public override void start()
- {
- base.start();
- Vector3 scale = transform.localScale;
- scale.x *= delta.x;
- scale.y *= delta.y;
- scale.z *= delta.z;
- path = scale - transform.localScale;
- }
-
- public override void stepInterval(float dt)
- {
- float d = dt / duration;
- Vector3 tgt = path * d;
- transform.localScale += tgt;
- }
-
- public override void stop()
+ class ActionScaleBy : ActionInterval
{
- base.stop();
+ protected Vector3 delta;
+ protected Vector3 path;
+
+ public ActionScaleBy(Vector3 tgtDelta, float tgtDuration)
+ : base(tgtDuration)
+ {
+ delta = tgtDelta;
+ }
+
+ public ActionScaleBy(Vector2 tgtValue, float tgtDuration)
+ : this((Vector3)tgtValue, tgtDuration)
+ {
+ is2d = true;
+ }
+
+ public override ActionInstant clone()
+ {
+ return new ActionScaleBy(delta, duration);
+ }
+
+ public override ActionInstant reverse()
+ {
+ return new ActionScaleBy(delta * -1F, duration);
+ }
+
+ public override void start()
+ {
+ base.start();
+ Vector3 scale = transform.localScale;
+ scale.x *= delta.x;
+ scale.y *= delta.y;
+ scale.z *= delta.z;
+ path = scale - transform.localScale;
+ }
+
+ public override void stepInterval(float dt)
+ {
+ float d = dt / duration;
+ Vector3 tgt = path * d;
+ transform.localScale += tgt;
+ }
+
+ public override void stop()
+ {
+ base.stop();
+ }
}
}
\ No newline at end of file
diff --git a/src/ActionsInterval/ActionScaleTo.cs b/src/ActionsInterval/ActionScaleTo.cs
index 19ba880..b80a11f 100644
--- a/src/ActionsInterval/ActionScaleTo.cs
+++ b/src/ActionsInterval/ActionScaleTo.cs
@@ -2,40 +2,43 @@
using System.Collections.Generic;
using UnityEngine;
-class ActionScaleTo : ActionInterval
+namespace coa4u
{
- protected Vector3 value;
- protected Vector3 path;
-
- public ActionScaleTo(Vector3 tgtValue, float tgtDuration)
- : base(tgtDuration)
+ class ActionScaleTo : ActionInterval
{
- value = tgtValue;
- }
+ protected Vector3 value;
+ protected Vector3 path;
- public ActionScaleTo(Vector2 tgtValue, float tgtDuration)
- : this((Vector3) tgtValue, tgtDuration)
- {
- is2d = true;
- }
+ public ActionScaleTo(Vector3 tgtValue, float tgtDuration)
+ : base(tgtDuration)
+ {
+ value = tgtValue;
+ }
- public override Action clone()
- {
- return new ActionScaleTo(value, duration);
- }
+ public ActionScaleTo(Vector2 tgtValue, float tgtDuration)
+ : this((Vector3)tgtValue, tgtDuration)
+ {
+ is2d = true;
+ }
- public override void start()
- {
- base.start();
- if (is2d)
- value.z = transform.localScale.z;
- path = value - transform.localScale;
- }
+ public override ActionInstant clone()
+ {
+ return new ActionScaleTo(value, duration);
+ }
- public override void stepInterval(float dt)
- {
- float d = dt / duration;
- Vector3 tgt = path * d;
- transform.localScale += tgt;
+ public override void start()
+ {
+ base.start();
+ if (is2d)
+ value.z = transform.localScale.z;
+ path = value - transform.localScale;
+ }
+
+ public override void stepInterval(float dt)
+ {
+ float d = dt / duration;
+ Vector3 tgt = path * d;
+ transform.localScale += tgt;
+ }
}
}
\ No newline at end of file
diff --git a/src/ActionsInterval/ActionSkewBy.cs b/src/ActionsInterval/ActionSkewBy.cs
index 8716dec..2dd6e8d 100644
--- a/src/ActionsInterval/ActionSkewBy.cs
+++ b/src/ActionsInterval/ActionSkewBy.cs
@@ -2,44 +2,47 @@
using System.Collections.Generic;
using UnityEngine;
-class ActionSkewBy : ActionInterval
+namespace coa4u
{
- protected Vector3 skewAngles1;
- protected Vector3 skewAngles2;
- protected Mesh mesh;
-
- public ActionSkewBy(Vector3 tgtAngles1, Vector3 tgtAngles2, float tgtDuration)
- : base(tgtDuration)
+ class ActionSkewBy : ActionInterval
{
- skewAngles1 = tgtAngles1;
- skewAngles2 = tgtAngles2;
- }
+ protected Vector3 skewAngles1;
+ protected Vector3 skewAngles2;
+ protected Mesh mesh;
- public override Action clone()
- {
- return new ActionSkewBy(skewAngles1, skewAngles2, duration);
- }
+ public ActionSkewBy(Vector3 tgtAngles1, Vector3 tgtAngles2, float tgtDuration)
+ : base(tgtDuration)
+ {
+ skewAngles1 = tgtAngles1;
+ skewAngles2 = tgtAngles2;
+ }
- public override Action reverse()
- {
- return new ActionSkewBy(-skewAngles1, -skewAngles2, duration);
- }
+ public override ActionInstant clone()
+ {
+ return new ActionSkewBy(skewAngles1, skewAngles2, duration);
+ }
- public override void start()
- {
- base.start();
- if (!(target is MeshActor))
+ public override ActionInstant reverse()
{
- throw new Exception("You should use MeshActor class instead of Actor, if you want to skew your object.");
+ return new ActionSkewBy(-skewAngles1, -skewAngles2, duration);
}
- }
- public override void stepInterval(float dt)
- {
- float d = dt / duration;
- Vector3 tgt = skewAngles1 * d;
- ((MeshActor)target).skewAngles1 += tgt;
- tgt = skewAngles2 * d;
- ((MeshActor)target).skewAngles2 += tgt;
+ public override void start()
+ {
+ base.start();
+ if (!(target is Actor))
+ {
+ throw new Exception("You should use Actor class instead of Actor, if you want to skew your object.");
+ }
+ }
+
+ public override void stepInterval(float dt)
+ {
+ float d = dt / duration;
+ Vector3 tgt = skewAngles1 * d;
+ ((Actor)target).skewAngles1 += tgt;
+ tgt = skewAngles2 * d;
+ ((Actor)target).skewAngles2 += tgt;
+ }
}
}
\ No newline at end of file
diff --git a/src/ActionsInterval/ActionTintBy.cs b/src/ActionsInterval/ActionTintBy.cs
index 2ad5824..954e8ab 100644
--- a/src/ActionsInterval/ActionTintBy.cs
+++ b/src/ActionsInterval/ActionTintBy.cs
@@ -2,41 +2,44 @@
using System.Collections.Generic;
using UnityEngine;
-class ActionTintBy : ActionInterval
+namespace coa4u
{
- protected Vector4 color;
- protected const float coeff = 1F / 255F;
-
- public ActionTintBy(Vector4 tgtColor, float tgtDuration)
- : base(tgtDuration)
+ class ActionTintBy : ActionInterval
{
- color = tgtColor * coeff;
- }
+ protected Vector4 color;
+ protected const float coeff = 1F / 255F;
- public ActionTintBy(Vector3 tgtColor, float tgtDuration)
- : this(new Vector4(tgtColor.x, tgtColor.y, tgtColor.z), tgtDuration)
- {
- }
+ public ActionTintBy(Vector4 tgtColor, float tgtDuration)
+ : base(tgtDuration)
+ {
+ color = tgtColor * coeff;
+ }
- public override Action clone()
- {
- return new ActionTintBy(color / coeff, duration);
- }
+ public ActionTintBy(Vector3 tgtColor, float tgtDuration)
+ : this(new Vector4(tgtColor.x, tgtColor.y, tgtColor.z), tgtDuration)
+ {
+ }
- public override Action reverse()
- {
- return new ActionTintBy(-color / coeff, duration);
- }
+ public override ActionInstant clone()
+ {
+ return new ActionTintBy(color / coeff, duration);
+ }
- public override void stepInterval(float dt)
- {
- float d = dt / duration;
- Vector4 tgt = color * d;
- Color tgtColor = renderer.material.color;
- tgtColor[0] += tgt[0];
- tgtColor[1] += tgt[1];
- tgtColor[2] += tgt[2];
- tgtColor[3] += tgt[3];
- renderer.material.color = tgtColor;
+ public override ActionInstant reverse()
+ {
+ return new ActionTintBy(-color / coeff, duration);
+ }
+
+ public override void stepInterval(float dt)
+ {
+ float d = dt / duration;
+ Vector4 tgt = color * d;
+ Color tgtColor = renderer.material.color;
+ tgtColor[0] += tgt[0];
+ tgtColor[1] += tgt[1];
+ tgtColor[2] += tgt[2];
+ tgtColor[3] += tgt[3];
+ renderer.material.color = tgtColor;
+ }
}
}
\ No newline at end of file
diff --git a/src/ActionsInterval/ActionTintTo.cs b/src/ActionsInterval/ActionTintTo.cs
index 61a1618..c7cf1ad 100644
--- a/src/ActionsInterval/ActionTintTo.cs
+++ b/src/ActionsInterval/ActionTintTo.cs
@@ -2,48 +2,51 @@
using System.Collections.Generic;
using UnityEngine;
-class ActionTintTo : ActionInterval
+namespace coa4u
{
- protected Vector4 color;
- protected Vector4 path;
- protected const float coeff = 1F / 255F;
-
- public ActionTintTo(Vector4 tgtColor, float tgtDuration)
- : base(tgtDuration)
+ class ActionTintTo : ActionInterval
{
- color = tgtColor * coeff;
- path = Vector4.zero;
- }
+ protected Vector4 color;
+ protected Vector4 path;
+ protected const float coeff = 1F / 255F;
- public ActionTintTo(Vector3 tgtColor, float tgtDuration)
- : this(new Vector4(tgtColor.x, tgtColor.y, tgtColor.z), tgtDuration)
- {
- }
+ public ActionTintTo(Vector4 tgtColor, float tgtDuration)
+ : base(tgtDuration)
+ {
+ color = tgtColor * coeff;
+ path = Vector4.zero;
+ }
- public override Action clone()
- {
- return new ActionTintTo(color / coeff, duration);
- }
+ public ActionTintTo(Vector3 tgtColor, float tgtDuration)
+ : this(new Vector4(tgtColor.x, tgtColor.y, tgtColor.z), tgtDuration)
+ {
+ }
- public override void start()
- {
- base.start();
- Color tgtColor = 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 ActionInstant clone()
+ {
+ return new ActionTintTo(color / coeff, duration);
+ }
- public override void stepInterval(float dt)
- {
- float d = dt / duration;
- Vector4 tgt = path * d;
- Color tgtColor = renderer.material.color;
- tgtColor[0] += tgt[0];
- tgtColor[1] += tgt[1];
- tgtColor[2] += tgt[2];
- tgtColor[3] += tgt[3];
- renderer.material.color = tgtColor;
+ public override void start()
+ {
+ base.start();
+ Color tgtColor = 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 = renderer.material.color;
+ tgtColor[0] += tgt[0];
+ tgtColor[1] += tgt[1];
+ tgtColor[2] += tgt[2];
+ tgtColor[3] += tgt[3];
+ renderer.material.color = tgtColor;
+ }
}
}
\ No newline at end of file
diff --git a/src/CoreClasses/MethodHolder.cs b/src/CoreClasses/MethodHolder.cs
new file mode 100644
index 0000000..0c48716
--- /dev/null
+++ b/src/CoreClasses/MethodHolder.cs
@@ -0,0 +1,53 @@
+using System;
+using System.Collections.Generic;
+using UnityEngine;
+
+namespace coa4u
+{
+ public class MethodHolder
+ {
+ protected Action method;
+ protected string methodName;
+
+ public MethodHolder()
+ {
+ }
+
+ public MethodHolder(Action tgtMethod)
+ {
+ method = tgtMethod;
+ methodName = tgtMethod.Method.Name;
+ }
+
+ public virtual void run(object param = null)
+ {
+ if (method != null)
+ method.Invoke();
+ }
+
+ public string name
+ {
+ get
+ {
+ return methodName;
+ }
+ }
+ }
+
+ public class MethodHolder : MethodHolder
+ {
+ protected Action methodParam;
+
+ public MethodHolder(Action tgtMethod)
+ {
+ methodParam = tgtMethod;
+ methodName = tgtMethod.Method.Name;
+ }
+
+ public override void run(object param)
+ {
+ if (methodParam != null)
+ methodParam.Invoke((T)param);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/UnityComponents/Actor.cs b/src/UnityComponents/Actor.cs
index 0834335..612bccd 100644
--- a/src/UnityComponents/Actor.cs
+++ b/src/UnityComponents/Actor.cs
@@ -1,42 +1,126 @@
-using UnityEngine;
+using System;
+using UnityEngine;
using System.Collections;
+using System.Collections.Generic;
+using coa4u;
+///
+/// The default Actor class for the Action system.
+///
public class Actor : MonoBehaviour
{
- protected Action action;
+ protected Dictionary methodsCache = new Dictionary();
+ protected ActionInstant action;
private bool paused = false;
+ protected Vector3 angles1prev = Vector3.zero;
+ protected Vector3 angles2prev = Vector3.zero;
+ protected const float coeff = Mathf.PI / 180;
+ protected Vector3[] initialState;
+ public Transform transformCached;
+ public Renderer rendererCached;
+ public Mesh meshCached;
+ public Vector3 skewAngles1;
+ public Vector3 skewAngles2;
+ ///
+ /// This method is called when the script instance is being loaded.
+ ///
+ protected void Awake()
+ {
+ transformCached = gameObject.transform;
+ rendererCached = gameObject.renderer;
+ meshCached = gameObject.GetComponent().mesh;
+ initialState = meshCached.vertices;
+ }
+
+ ///
+ /// This method is called at every frame update.
+ ///
protected void Update()
{
if (paused || action == null)
return;
- if (action.isRunning())
+ if (action.running)
action.step(Time.deltaTime);
+ if (skewAngles1 != angles1prev || skewAngles2 != angles2prev)
+ updateSkew();
+ }
+
+ ///
+ /// Updates the skew for the mesh.
+ ///
+ void updateSkew()
+ {
+ Matrix4x4 m = Matrix4x4.zero;
+ m[0, 0] = 1;
+ m[1, 1] = 1;
+ m[2, 2] = 1;
+ m[3, 3] = 1;
+ m[0, 1] = Mathf.Tan(skewAngles1.x * coeff); // skewing in xy
+ m[0, 2] = Mathf.Tan(skewAngles2.x * coeff); // skewing in xz
+ m[1, 0] = Mathf.Tan(skewAngles1.y * coeff); // skewing in yx
+ m[1, 2] = Mathf.Tan(skewAngles2.y * coeff); // skewing in yz
+ m[2, 0] = Mathf.Tan(skewAngles1.z * coeff); // skewing in zx
+ m[2, 1] = Mathf.Tan(skewAngles2.z * coeff); // skewing in zy
+
+ Vector3[] verts = new Vector3[initialState.Length];
+ int i = 0;
+ while (i < verts.Length)
+ {
+ verts[i] = m.MultiplyPoint3x4(initialState[i]);
+ i++;
+ }
+
+ meshCached.vertices = verts;
+ angles1prev = skewAngles1;
+ angles2prev = skewAngles2;
}
- public void AttachAction(Action tgtAction)
+ ///
+ /// Attaches and starts the action.
+ ///
+ public void AttachAction(ActionInstant tgtAction)
{
+ if (action != null)
+ {
+ action.stop();
+ }
action = tgtAction;
action.setActor(this);
action.start();
}
+ ///
+ /// Stops all running actions for this actor.
+ ///
public void StopAction()
{
- action.stop();
+ if (action == null)
+ return;
+ if (action.running)
+ action.stop();
action = null;
}
+ ///
+ /// Pauses actions for this actor.
+ ///
public void PauseAction()
{
paused = true;
}
+ ///
+ /// Unpauses actions for this actor.
+ ///
public void UnpauseAction()
{
paused = false;
}
+ ///
+ /// Sets the timescale for current action.
+ ///
public void SetTimeScale(float ts)
{
if (action is ActionInterval)
@@ -44,4 +128,40 @@ public class Actor : MonoBehaviour
((ActionInterval)action).setTimeScale(ts);
}
}
+
+ ///
+ /// Adds method to cache to speed-up
+ ///
+ public void AddMethodToCache(MethodHolder method)
+ {
+ methodsCache.Add(method.name, method);
+ }
+
+ public void RemoveMethodFromCache(string key)
+ {
+ if (methodsCache.ContainsKey(key))
+ {
+ methodsCache.Remove(key);
+ }
+ else
+ {
+ throw new Exception("Method " + key + " not found in cache.");
+ }
+ }
+
+
+ public void ReceiveMessage(string key, object param = null, SendMessageOptions options = SendMessageOptions.DontRequireReceiver)
+ {
+ if (methodsCache.ContainsKey(key))
+ {
+ if (param == null)
+ methodsCache[key].run();
+ else
+ methodsCache[key].run(param);
+ }
+ else
+ {
+ gameObject.SendMessage(key, param, options);
+ }
+ }
}
diff --git a/src/UnityComponents/ActorSampleActions.cs b/src/UnityComponents/ActorSampleActions.cs
index 980f728..560b518 100644
--- a/src/UnityComponents/ActorSampleActions.cs
+++ b/src/UnityComponents/ActorSampleActions.cs
@@ -1,14 +1,15 @@
using UnityEngine;
using System.Collections;
+using coa4u;
-public class ActorSampleActions : MeshActor
+public class ActorSampleActions : Actor
{
public void Start()
{
- Action seq = new ActionRepeat (new ActionSequence(new Action[]
+ ActionInstant seq = new ActionRepeat (new ActionSequence(new ActionInstant[]
{
new ActionFadeIn(2),
- new ActionParallel(new Action[] {
+ new ActionParallel(new ActionInstant[] {
new ActionMoveBy(new Vector3(10, 10, 0), 1),
new ActionRotateBy(new Vector3(90, 90, 0), 1),
new ActionTintBy(new Vector4(-50, 50, -150), 1)
@@ -32,9 +33,23 @@ public class ActorSampleActions : MeshActor
new ActionScaleTo(new Vector3(2, 2, 2), 1),
new ActionRotateTo(new Vector3(0, 0, 0), 1),
new ActionFadeOut(2),
- new ActionSetTint(new Vector4(67, 105, 181))
+ new ActionSetTint(new Vector4(67, 105, 181)),
+ new ActionSendMessage("msgHello"),
+ new ActionSendMessage("msgHelloTo", "world"),
}), 5);
- SetTimeScale(2);
this.AttachAction(seq);
+
+ AddMethodToCache(new MethodHolder(msgHello));
+ AddMethodToCache(new MethodHolder(msgHelloTo));
+ }
+
+ void msgHello()
+ {
+ Debug.Log("Hello!");
+ }
+
+ void msgHelloTo(string who)
+ {
+ Debug.Log("Hello " + who.ToString() + "!");
}
}
diff --git a/src/UnityComponents/MeshActor.cs b/src/UnityComponents/MeshActor.cs
deleted file mode 100644
index 173bbe6..0000000
--- a/src/UnityComponents/MeshActor.cs
+++ /dev/null
@@ -1,54 +0,0 @@
-using UnityEngine;
-using System.Collections;
-
-[System.Serializable]
-public class MeshActor : Actor
-{
- public Vector3 skewAngles1;
- public Vector3 skewAngles2;
- protected Vector3 angles1prev = Vector3.zero;
- protected Vector3 angles2prev = Vector3.zero;
- protected const float coeff = Mathf.PI/180;
- protected Mesh mesh;
- protected Vector3[] initialState;
-
- void Awake()
- {
- mesh = gameObject.GetComponent().mesh;
- initialState = mesh.vertices;
- }
-
- protected void Update()
- {
- base.Update();
- if (skewAngles1 != angles1prev || skewAngles2 != angles2prev)
- updateMesh();
- }
-
- protected void updateMesh()
- {
- Matrix4x4 m = Matrix4x4.zero;
- m[0, 0] = 1;
- m[1, 1] = 1;
- m[2, 2] = 1;
- m[3, 3] = 1;
- m[0, 1] = Mathf.Tan(skewAngles1.x * coeff); // skewing in xy
- m[0, 2] = Mathf.Tan(skewAngles2.x * coeff); // skewing in xz
- m[1, 0] = Mathf.Tan(skewAngles1.y * coeff); // skewing in yx
- m[1, 2] = Mathf.Tan(skewAngles2.y * coeff); // skewing in yz
- m[2, 0] = Mathf.Tan(skewAngles1.z * coeff); // skewing in zx
- m[2, 1] = Mathf.Tan(skewAngles2.z * coeff); // skewing in zy
-
- Vector3[] verts = new Vector3[initialState.Length];
- int i = 0;
- while (i < verts.Length)
- {
- verts[i] = m.MultiplyPoint3x4(initialState[i]);
- i++;
- }
-
- mesh.vertices = verts;
- angles1prev = skewAngles1;
- angles2prev = skewAngles2;
- }
-}