Moved all actions to coa4u namespace.
Added methods caching for quick message processing. Integrated MeshActor into Actor. new Actions: ActionStop.cs ActionSetDirection.cs
This commit is contained in:
@@ -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.
|
||||
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
}
|
||||
|
||||
public virtual Action clone()
|
||||
{
|
||||
return new Action();
|
||||
}
|
||||
|
||||
public virtual bool isRunning()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method is called at the action start. Usable for instant and interval actions.
|
||||
/// Basic action class for subclassing. To inherit interval actions, consider using the ActionInterval as the base class.
|
||||
/// </summary>
|
||||
public virtual Action reverse()
|
||||
public class ActionInstant
|
||||
{
|
||||
throw new Exception("Can reverse only the reversable interval actions");
|
||||
}
|
||||
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;
|
||||
|
||||
/// <summary>
|
||||
/// This method is called at the action start. Usable for instant and interval actions.
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method is called at every frame update. Not usable for instant actions.
|
||||
/// </summary>
|
||||
public virtual void step(float dt)
|
||||
{
|
||||
if (target == null)
|
||||
throw new Exception("Can update the action only after it's atached to the actor");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method is called after the interval action is stopped. Not usable for instant actions.
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
|
||||
public virtual float dtr
|
||||
{
|
||||
get
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected set
|
||||
public ActionInstant()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a copy of the action.
|
||||
/// </summary>
|
||||
public virtual ActionInstant clone()
|
||||
{
|
||||
return new ActionInstant();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the reversed version of the action, if it is possible.
|
||||
/// </summary>
|
||||
public virtual ActionInstant reverse()
|
||||
{
|
||||
throw new Exception("Can reverse only the reversable interval actions");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method is called at the action start. Usable for instant and interval actions.
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method is called at every frame update. Not usable for instant actions.
|
||||
/// </summary>
|
||||
public virtual void step(float dt)
|
||||
{
|
||||
if (target == null)
|
||||
throw new Exception("Can update the action only after it's atached to the actor");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method is called after the interval action is stopped. Not usable for instant actions.
|
||||
/// </summary>
|
||||
public virtual void stop()
|
||||
{
|
||||
if (target == null)
|
||||
throw new Exception("Can stop the action only after it's atached to the actor");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method sets the actor for the action.
|
||||
/// </summary>
|
||||
public void setActor(Actor actor)
|
||||
{
|
||||
target = actor;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Readonly property. Shows the remaining time of the action.
|
||||
/// </summary>
|
||||
public float duration
|
||||
{
|
||||
get
|
||||
{
|
||||
return durationValue;
|
||||
}
|
||||
|
||||
protected set
|
||||
{
|
||||
durationValue = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Readonly property. Shows if the action is running or not.
|
||||
/// </summary>
|
||||
public bool running
|
||||
{
|
||||
get
|
||||
{
|
||||
return isRunning;
|
||||
}
|
||||
|
||||
protected set
|
||||
{
|
||||
isRunning = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Readonly property. Contains the remaining tick time after action finished.
|
||||
/// </summary>
|
||||
public float dtr
|
||||
{
|
||||
get
|
||||
{
|
||||
return dtrValue;
|
||||
}
|
||||
|
||||
protected set
|
||||
{
|
||||
dtrValue = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Step method for interval actions. Don't override this method, when inheriting, put your code in stepInterval instead.
|
||||
/// Interval action class for subclassing.
|
||||
/// </summary>
|
||||
public override void step(float dt)
|
||||
public class ActionInterval : ActionInstant
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
protected float timer;
|
||||
protected float timeScale;
|
||||
private float dtrdata;
|
||||
|
||||
/// <summary>
|
||||
/// Step method for interval actions. Put your code here.
|
||||
/// </summary>
|
||||
public virtual void stepInterval(float dt)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Property to get the remaining tick time after the action has ended.
|
||||
/// </summary>
|
||||
public override float dtr
|
||||
{
|
||||
get
|
||||
public ActionInterval(float tgtDuration)
|
||||
: base()
|
||||
{
|
||||
return dtrdata;
|
||||
duration = tgtDuration;
|
||||
timeScale = 1F;
|
||||
dtr = 0;
|
||||
}
|
||||
|
||||
protected set
|
||||
/// <summary>
|
||||
/// Returns a copy of the action.
|
||||
/// </summary>
|
||||
public override ActionInstant clone()
|
||||
{
|
||||
dtrdata = value;
|
||||
return new ActionInterval(duration);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Immediately changes the time scale for this action and all nested ones.
|
||||
/// </summary>
|
||||
public void setTimeScale(float ts)
|
||||
{
|
||||
timeScale = ts;
|
||||
/// <summary>
|
||||
/// Returns the reversed version of the action, if it is possible.
|
||||
/// </summary>
|
||||
public override ActionInstant reverse()
|
||||
{
|
||||
throw new Exception("Can reverse only the reversable interval actions");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method is called at the action start.
|
||||
/// </summary>
|
||||
public override void start()
|
||||
{
|
||||
base.start();
|
||||
running = true;
|
||||
timer = 0F;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method is called after the interval action is stopped.
|
||||
/// </summary>
|
||||
public override void stop()
|
||||
{
|
||||
base.stop();
|
||||
running = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method is called every frame update. Don't override this method, when inheriting, put your code in stepInterval instead.
|
||||
/// </summary>
|
||||
public override void step(float dt)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method is called every frame update. Put your code here.
|
||||
/// </summary>
|
||||
public virtual void stepInterval(float dt)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Immediately changes the time scale for this action and all nested ones.
|
||||
/// </summary>
|
||||
public void setTimeScale(float ts)
|
||||
{
|
||||
timeScale = ts;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
/// <summary>
|
||||
/// Runs several actions at the same time.
|
||||
/// </summary>
|
||||
public class ActionParallel : ActionInterval
|
||||
{
|
||||
actions = new Action[] {action1, action2};
|
||||
}
|
||||
protected ActionInstant[] actions;
|
||||
|
||||
public ActionParallel(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 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();
|
||||
}
|
||||
return new ActionSequence(aList);
|
||||
}
|
||||
actions = actionsList;
|
||||
|
||||
public override void start()
|
||||
{
|
||||
base.start();
|
||||
for (int i = 0; i < actions.Length; i++)
|
||||
{
|
||||
actions[i].setActor(target);
|
||||
actions[i].start();
|
||||
}
|
||||
}
|
||||
|
||||
public override void step(float dt)
|
||||
{
|
||||
dt *= timeScale;
|
||||
for (int i = 0; i < actions.Length; i++)
|
||||
/// <summary>
|
||||
/// Returns a copy of the action.
|
||||
/// </summary>
|
||||
public override ActionInstant clone()
|
||||
{
|
||||
if (actions[i].isRunning())
|
||||
actions[i].step(dt);
|
||||
}
|
||||
bool canStopNow = true;
|
||||
float dtrdata = 0;
|
||||
for (int i = 0; i < actions.Length; i++)
|
||||
{
|
||||
if (actions[i].isRunning())
|
||||
ActionInstant[] aList = new ActionInstant[actions.Length];
|
||||
for (int i = 0; i < actions.Length; i++)
|
||||
{
|
||||
canStopNow = false;
|
||||
dtrdata = Math.Max(actions[i].dtr, dtrdata);
|
||||
aList[i] = actions[i].clone();
|
||||
}
|
||||
return new ActionSequence(aList);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the reversed version of the action, if it is possible.
|
||||
/// </summary>
|
||||
public override ActionInstant reverse()
|
||||
{
|
||||
ActionInstant[] aList = new ActionInstant[actions.Length];
|
||||
for (int i = 0; i < actions.Length; i++)
|
||||
{
|
||||
aList[i] = actions[i].reverse();
|
||||
}
|
||||
return new ActionSequence(aList);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method is called at the action start.
|
||||
/// </summary>
|
||||
public override void start()
|
||||
{
|
||||
base.start();
|
||||
for (int i = 0; i < actions.Length; i++)
|
||||
{
|
||||
actions[i].setActor(target);
|
||||
actions[i].start();
|
||||
}
|
||||
}
|
||||
if (canStopNow)
|
||||
{
|
||||
stop();
|
||||
dtr = dtrdata;
|
||||
}
|
||||
}
|
||||
|
||||
public override void stop()
|
||||
{
|
||||
base.stop();
|
||||
for (int i = 0; i < actions.Length; i++)
|
||||
/// <summary>
|
||||
/// This method is called every frame update.
|
||||
/// </summary>
|
||||
public override void step(float dt)
|
||||
{
|
||||
actions[i].stop();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method is called after the interval action is stopped.
|
||||
/// </summary>
|
||||
public override void stop()
|
||||
{
|
||||
base.stop();
|
||||
for (int i = 0; i < actions.Length; i++)
|
||||
{
|
||||
actions[i].stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,68 +2,89 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
class ActionRandom : ActionInterval
|
||||
namespace coa4u
|
||||
{
|
||||
|
||||
protected Action[] actions;
|
||||
protected int index;
|
||||
|
||||
public ActionRandom(Action action1, Action action2)
|
||||
: base(0)
|
||||
/// <summary>
|
||||
/// Runs one random action from the given list.
|
||||
/// </summary>
|
||||
class ActionRandom : ActionInterval
|
||||
{
|
||||
actions = new Action[] {action1, action2};
|
||||
}
|
||||
|
||||
public ActionRandom(Action[] actionsList)
|
||||
: base(0)
|
||||
{
|
||||
actions = actionsList;
|
||||
protected ActionInstant[] actions;
|
||||
protected int index;
|
||||
|
||||
}
|
||||
|
||||
public override Action clone()
|
||||
{
|
||||
Action[] aList = new Action[actions.Length];
|
||||
for (int i = 0; i < actions.Length; i++)
|
||||
public ActionRandom(ActionInstant action1, ActionInstant action2)
|
||||
: base(0)
|
||||
{
|
||||
aList[i] = actions[i].clone();
|
||||
actions = new ActionInstant[] { action1, action2 };
|
||||
}
|
||||
return new ActionRandom(aList);
|
||||
}
|
||||
|
||||
public override Action reverse()
|
||||
{
|
||||
Action[] aList = new Action[actions.Length];
|
||||
for (int i = 0; i < actions.Length; i++)
|
||||
public ActionRandom(ActionInstant[] actionsList)
|
||||
: base(0)
|
||||
{
|
||||
aList[i] = actions[i].reverse();
|
||||
actions = actionsList;
|
||||
|
||||
}
|
||||
return new ActionRandom(aList);
|
||||
}
|
||||
|
||||
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())
|
||||
/// <summary>
|
||||
/// Returns a copy of the action.
|
||||
/// </summary>
|
||||
public override ActionInstant clone()
|
||||
{
|
||||
stop();
|
||||
dtr = actions[index].dtr;
|
||||
ActionInstant[] aList = new ActionInstant[actions.Length];
|
||||
for (int i = 0; i < actions.Length; i++)
|
||||
{
|
||||
aList[i] = actions[i].clone();
|
||||
}
|
||||
return new ActionRandom(aList);
|
||||
}
|
||||
}
|
||||
|
||||
public override void stop()
|
||||
{
|
||||
base.stop();
|
||||
actions[index].stop();
|
||||
/// <summary>
|
||||
/// Returns the reversed version of the action, if it is possible.
|
||||
/// </summary>
|
||||
public override ActionInstant reverse()
|
||||
{
|
||||
ActionInstant[] aList = new ActionInstant[actions.Length];
|
||||
for (int i = 0; i < actions.Length; i++)
|
||||
{
|
||||
aList[i] = actions[i].reverse();
|
||||
}
|
||||
return new ActionRandom(aList);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method is called at the action start.
|
||||
/// </summary>
|
||||
public override void start()
|
||||
{
|
||||
base.start();
|
||||
index = UnityEngine.Random.Range(0, actions.Length);
|
||||
actions[index].setActor(target);
|
||||
actions[index].start();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method is called every frame update.
|
||||
/// </summary>
|
||||
public override void step(float dt)
|
||||
{
|
||||
dt *= timeScale;
|
||||
if (actions[index].running)
|
||||
actions[index].step(dt);
|
||||
if (!actions[index].running)
|
||||
{
|
||||
stop();
|
||||
dtr = actions[index].dtr;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method is called after the interval action is stopped.
|
||||
/// </summary>
|
||||
public override void stop()
|
||||
{
|
||||
base.stop();
|
||||
actions[index].stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
/// <summary>
|
||||
/// Runs the given action the several times. Also can repeat the action forever.
|
||||
/// </summary>
|
||||
class ActionRepeat : ActionInterval
|
||||
{
|
||||
action = tgtAction;
|
||||
count = tgtCount;
|
||||
counter = 0;
|
||||
forever = false;
|
||||
}
|
||||
protected ActionInterval action;
|
||||
protected int count;
|
||||
protected int counter;
|
||||
protected bool forever;
|
||||
|
||||
public ActionRepeat(ActionInterval tgtAction)
|
||||
: base(0)
|
||||
{
|
||||
action = tgtAction;
|
||||
count = 0;
|
||||
counter = 0;
|
||||
forever = true;
|
||||
}
|
||||
|
||||
public override Action clone()
|
||||
{
|
||||
return new ActionRepeat((ActionInterval) action.clone(), count);
|
||||
}
|
||||
|
||||
public override Action reverse()
|
||||
{
|
||||
return new ActionRepeat((ActionInterval) action.reverse(), count);
|
||||
}
|
||||
|
||||
public override void start()
|
||||
{
|
||||
base.start();
|
||||
action.setActor(target);
|
||||
action.start();
|
||||
counter = 0;
|
||||
}
|
||||
|
||||
public override void step(float dt)
|
||||
{
|
||||
dt *= timeScale;
|
||||
if (action.isRunning())
|
||||
public ActionRepeat(ActionInterval tgtAction, int tgtCount)
|
||||
: base(0)
|
||||
{
|
||||
action.step(dt);
|
||||
action = tgtAction;
|
||||
count = tgtCount;
|
||||
counter = 0;
|
||||
forever = false;
|
||||
}
|
||||
if (!action.isRunning() && (forever || counter < count - 1))
|
||||
|
||||
public ActionRepeat(ActionInterval tgtAction)
|
||||
: base(0)
|
||||
{
|
||||
float dtrdata = action.dtr;
|
||||
action = tgtAction;
|
||||
count = 0;
|
||||
counter = 0;
|
||||
forever = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a copy of the action.
|
||||
/// </summary>
|
||||
public override ActionInstant clone()
|
||||
{
|
||||
return new ActionRepeat((ActionInterval)action.clone(), count);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the reversed version of the action, if it is possible.
|
||||
/// </summary>
|
||||
public override ActionInstant reverse()
|
||||
{
|
||||
return new ActionRepeat((ActionInterval)action.reverse(), count);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method is called at the action start.
|
||||
/// </summary>
|
||||
public override void start()
|
||||
{
|
||||
base.start();
|
||||
action.setActor(target);
|
||||
action.start();
|
||||
if (dtrdata > 0)
|
||||
action.step(dtrdata);
|
||||
counter += 1;
|
||||
counter = 0;
|
||||
}
|
||||
else if (!action.isRunning() && counter >= count - 1)
|
||||
|
||||
/// <summary>
|
||||
/// This method is called every frame update.
|
||||
/// </summary>
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
/// <summary>
|
||||
/// Runs several actions in a sequence.
|
||||
/// </summary>
|
||||
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();
|
||||
}
|
||||
return new ActionSequence(aList);
|
||||
}
|
||||
actions = actionsList;
|
||||
|
||||
public override void start()
|
||||
{
|
||||
base.start();
|
||||
index = 0;
|
||||
actions[0].setActor(target);
|
||||
actions[0].start();
|
||||
while (!actions[index].isRunning() && index < actions.Length)
|
||||
{
|
||||
index += 1;
|
||||
actions[index].setActor(target);
|
||||
actions[index].start();
|
||||
}
|
||||
}
|
||||
|
||||
public override void step(float dt)
|
||||
{
|
||||
dt *= timeScale;
|
||||
float dtrdata = 0;
|
||||
if (actions[index].isRunning())
|
||||
/// <summary>
|
||||
/// Returns a copy of the action.
|
||||
/// </summary>
|
||||
public override ActionInstant clone()
|
||||
{
|
||||
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[i] = actions[i].clone();
|
||||
}
|
||||
return new ActionSequence(aList);
|
||||
}
|
||||
while (!actions[index].isRunning() && index < actions.Length - 1)
|
||||
{
|
||||
index += 1;
|
||||
actions[index].setActor(target);
|
||||
actions[index].start();
|
||||
if (actions[index].isRunning() && dtrdata > 0)
|
||||
actions[index].step(dtrdata);
|
||||
}
|
||||
if (!actions[index].isRunning())
|
||||
{
|
||||
stop();
|
||||
dtr = dtrdata;
|
||||
}
|
||||
}
|
||||
|
||||
public override void stop()
|
||||
{
|
||||
base.stop();
|
||||
for (int i = 0; i < actions.Length; i++)
|
||||
/// <summary>
|
||||
/// Returns the reversed version of the action, if it is possible.
|
||||
/// </summary>
|
||||
public override ActionInstant reverse()
|
||||
{
|
||||
actions[i].stop();
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method is called at the action start.
|
||||
/// </summary>
|
||||
public override void start()
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method is called every frame update.
|
||||
/// </summary>
|
||||
public override void step(float dt)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method is called after the interval action is stopped.
|
||||
/// </summary>
|
||||
public override void stop()
|
||||
{
|
||||
base.stop();
|
||||
for (int i = 0; i < actions.Length; i++)
|
||||
{
|
||||
actions[i].stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
34
src/ActionsBase/ActionStop.cs
Normal file
34
src/ActionsBase/ActionStop.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace coa4u
|
||||
{
|
||||
/// <summary>
|
||||
/// This action stops all actions for the current target.
|
||||
/// </summary>
|
||||
class ActionStop : ActionInstant
|
||||
{
|
||||
public ActionStop()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a copy of the action.
|
||||
/// </summary>
|
||||
public override ActionInstant clone()
|
||||
{
|
||||
return new ActionStop();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method is called at the action start.
|
||||
/// </summary>
|
||||
public override void start()
|
||||
{
|
||||
base.start();
|
||||
target.StopAction();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,22 +2,42 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
class ActionHide : Action
|
||||
namespace coa4u
|
||||
{
|
||||
|
||||
public ActionHide()
|
||||
: base()
|
||||
/// <summary>
|
||||
/// Instantly hides the target. This action does not require the transparency support in shaders.
|
||||
/// </summary>
|
||||
class ActionHide : ActionInstant
|
||||
{
|
||||
}
|
||||
|
||||
public override Action clone()
|
||||
{
|
||||
return new ActionHide();
|
||||
}
|
||||
public ActionHide()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
public override void start()
|
||||
{
|
||||
base.start();
|
||||
renderer.enabled = false;
|
||||
/// <summary>
|
||||
/// Returns a copy of the action.
|
||||
/// </summary>
|
||||
public override ActionInstant clone()
|
||||
{
|
||||
return new ActionHide();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the reversed version of the action, if it is possible.
|
||||
/// </summary>
|
||||
public override ActionInstant reverse()
|
||||
{
|
||||
return new ActionShow();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method is called at the action start.
|
||||
/// </summary>
|
||||
public override void start()
|
||||
{
|
||||
base.start();
|
||||
renderer.enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,19 +2,44 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
class ActionLog : Action
|
||||
namespace coa4u
|
||||
{
|
||||
string message;
|
||||
|
||||
public ActionLog(string tgtMessage)
|
||||
: base()
|
||||
/// <summary>
|
||||
/// Prints a message in Unity debug console.
|
||||
/// </summary>
|
||||
class ActionLog : ActionInstant
|
||||
{
|
||||
message = tgtMessage;
|
||||
}
|
||||
string message;
|
||||
|
||||
public override void start()
|
||||
{
|
||||
base.start();
|
||||
Debug.Log(message);
|
||||
public ActionLog(string tgtMessage)
|
||||
: base()
|
||||
{
|
||||
message = tgtMessage;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a copy of the action.
|
||||
/// </summary>
|
||||
public override ActionInstant clone()
|
||||
{
|
||||
return new ActionLog(message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the reversed version of the action, if it is possible.
|
||||
/// </summary>
|
||||
public override ActionInstant reverse()
|
||||
{
|
||||
return new ActionLog(message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method is called at the action start.
|
||||
/// </summary>
|
||||
public override void start()
|
||||
{
|
||||
base.start();
|
||||
Debug.Log(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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()
|
||||
/// <summary>
|
||||
/// 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).
|
||||
/// </summary>
|
||||
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, object tgtParam, SendMessageOptions tgtOptions)
|
||||
: base()
|
||||
{
|
||||
message = tgtMessage;
|
||||
param = tgtParam;
|
||||
options = tgtOptions;
|
||||
}
|
||||
|
||||
public override void start()
|
||||
{
|
||||
base.start();
|
||||
if (param != null)
|
||||
public ActionSendMessage(string tgtMessage)
|
||||
: base()
|
||||
{
|
||||
target.SendMessage(message, param);
|
||||
message = tgtMessage;
|
||||
}
|
||||
else
|
||||
|
||||
public ActionSendMessage(string tgtMessage, object tgtParam)
|
||||
: base()
|
||||
{
|
||||
target.SendMessage(message);
|
||||
message = tgtMessage;
|
||||
param = tgtParam;
|
||||
}
|
||||
|
||||
public ActionSendMessage(string tgtMessage, object tgtParam, SendMessageOptions tgtOptions)
|
||||
: base()
|
||||
{
|
||||
message = tgtMessage;
|
||||
param = tgtParam;
|
||||
options = tgtOptions;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a copy of the action.
|
||||
/// </summary>
|
||||
public override ActionInstant clone()
|
||||
{
|
||||
return new ActionSendMessage(message, param, options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the reversed version of the action, if it is possible.
|
||||
/// </summary>
|
||||
public override ActionInstant reverse()
|
||||
{
|
||||
return new ActionSendMessage(message, param, options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method is called at the action start.
|
||||
/// </summary>
|
||||
public override void start()
|
||||
{
|
||||
base.start();
|
||||
if (param != null)
|
||||
{
|
||||
target.ReceiveMessage(message, param, options);
|
||||
}
|
||||
else
|
||||
{
|
||||
target.ReceiveMessage(message, options);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
58
src/ActionsInstant/ActionSetDirection.cs
Normal file
58
src/ActionsInstant/ActionSetDirection.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace coa4u
|
||||
{
|
||||
/// <summary>
|
||||
/// Instantly rotates the target to face the given point or actor.
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a copy of the action.
|
||||
/// </summary>
|
||||
public override ActionInstant clone()
|
||||
{
|
||||
return new ActionSetDirection(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method is called at the action start.
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,32 +2,44 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
class ActionSetPlace : Action
|
||||
namespace coa4u
|
||||
{
|
||||
protected Vector3 value;
|
||||
|
||||
public ActionSetPlace(Vector3 tgtPlace)
|
||||
: base()
|
||||
/// <summary>
|
||||
/// Instantly moves the target to the given point.
|
||||
/// </summary>
|
||||
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;
|
||||
/// <summary>
|
||||
/// Returns a copy of the action.
|
||||
/// </summary>
|
||||
public override ActionInstant clone()
|
||||
{
|
||||
return new ActionSetPlace(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method is called at the action start.
|
||||
/// </summary>
|
||||
public override void start()
|
||||
{
|
||||
base.start();
|
||||
if (is2d)
|
||||
value.z = transform.position.z;
|
||||
transform.position = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,31 +2,42 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
class ActionSetRotation : Action
|
||||
namespace coa4u
|
||||
{
|
||||
protected Vector3 value;
|
||||
|
||||
public ActionSetRotation(Vector3 tgtValue)
|
||||
: base()
|
||||
/// <summary>
|
||||
/// Instantly rotates the target.
|
||||
/// </summary>
|
||||
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);
|
||||
/// <summary>
|
||||
/// Returns a copy of the action.
|
||||
/// </summary>
|
||||
public override ActionInstant clone()
|
||||
{
|
||||
return new ActionSetRotation(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method is called at the action start.
|
||||
/// </summary>
|
||||
public override void start()
|
||||
{
|
||||
base.start();
|
||||
transform.rotation = Quaternion.Euler(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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()
|
||||
/// <summary>
|
||||
/// Instantly tints the target to the given color.
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a copy of the action.
|
||||
/// </summary>
|
||||
public override ActionInstant clone()
|
||||
{
|
||||
return new ActionSetTint(color * 255F);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method is called at the action start.
|
||||
/// </summary>
|
||||
public override void start()
|
||||
{
|
||||
base.start();
|
||||
renderer.material.color = new Color(color[0], color[1], color[2], color[3]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,22 +2,42 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
class ActionShow : Action
|
||||
namespace coa4u
|
||||
{
|
||||
|
||||
public ActionShow()
|
||||
: base()
|
||||
/// <summary>
|
||||
/// Instantly shows the hidden target. This action does not require the transparency support in shaders.
|
||||
/// </summary>
|
||||
class ActionShow : ActionInstant
|
||||
{
|
||||
}
|
||||
|
||||
public override Action clone()
|
||||
{
|
||||
return new ActionShow();
|
||||
}
|
||||
public ActionShow()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
public override void start()
|
||||
{
|
||||
base.start();
|
||||
renderer.enabled = true;
|
||||
/// <summary>
|
||||
/// Returns a copy of the action.
|
||||
/// </summary>
|
||||
public override ActionInstant clone()
|
||||
{
|
||||
return new ActionShow();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the reversed version of the action, if it is possible.
|
||||
/// </summary>
|
||||
public override ActionInstant reverse()
|
||||
{
|
||||
return new ActionHide();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method is called at the action start.
|
||||
/// </summary>
|
||||
public override void start()
|
||||
{
|
||||
base.start();
|
||||
renderer.enabled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,17 +2,42 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
class ActionToggleVisibility : Action
|
||||
namespace coa4u
|
||||
{
|
||||
|
||||
public ActionToggleVisibility()
|
||||
: base()
|
||||
/// <summary>
|
||||
/// Instantly hides the target or showes it, if it's hidden. This action does not require the transparency support in shaders.
|
||||
/// </summary>
|
||||
class ActionToggleVisibility : ActionInstant
|
||||
{
|
||||
}
|
||||
|
||||
public override void start()
|
||||
{
|
||||
base.start();
|
||||
renderer.enabled = !renderer.enabled;
|
||||
public ActionToggleVisibility()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a copy of the action.
|
||||
/// </summary>
|
||||
public override ActionInstant clone()
|
||||
{
|
||||
return new ActionToggleVisibility();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the reversed version of the action, if it is possible.
|
||||
/// </summary>
|
||||
public override ActionInstant reverse()
|
||||
{
|
||||
return new ActionToggleVisibility();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method is called at the action start.
|
||||
/// </summary>
|
||||
public override void start()
|
||||
{
|
||||
base.start();
|
||||
renderer.enabled = !renderer.enabled;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
/// <summary>
|
||||
/// 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).
|
||||
/// </summary>
|
||||
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 override Action clone()
|
||||
{
|
||||
return new ActionBezierAbs(startPoint, startControlPoint, endControlPoint, endPoint, duration);
|
||||
}
|
||||
|
||||
public override Action reverse()
|
||||
{
|
||||
return new ActionBezierAbs(endPoint, endControlPoint, startControlPoint, startPoint, duration);
|
||||
}
|
||||
|
||||
public override void start()
|
||||
{
|
||||
base.start();
|
||||
float z = transform.position.z;
|
||||
if (is2d)
|
||||
public ActionBezierAbs(Vector3 tgtStart, Vector3 tgtSCP, Vector3 tgtECP, Vector3 tgtEnd, float tgtDuration)
|
||||
: base(tgtDuration)
|
||||
{
|
||||
startPoint.z = z;
|
||||
endPoint.z = z;
|
||||
startControlPoint.z = z;
|
||||
endControlPoint.z = z;
|
||||
startPoint = tgtStart;
|
||||
endPoint = tgtEnd;
|
||||
startControlPoint = tgtSCP;
|
||||
endControlPoint = tgtECP;
|
||||
}
|
||||
|
||||
public ActionBezierAbs(Vector2 tgtStart, Vector2 tgtSCP, Vector2 tgtECP, Vector2 tgtEnd, float tgtDuration)
|
||||
: this((Vector3)tgtStart, (Vector3)tgtSCP, (Vector3)tgtECP, (Vector3)tgtEnd, tgtDuration)
|
||||
{
|
||||
is2d = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a copy of the action.
|
||||
/// </summary>
|
||||
public override ActionInstant clone()
|
||||
{
|
||||
return new ActionBezierAbs(startPoint, startControlPoint, endControlPoint, endPoint, duration);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the reversed version of the action, if it is possible.
|
||||
/// </summary>
|
||||
public override ActionInstant reverse()
|
||||
{
|
||||
return new ActionBezierAbs(endPoint, endControlPoint, startControlPoint, startPoint, duration);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method is called at the action start.
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method is called every frame update.
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
/// <summary>
|
||||
/// Moves the target with a cubic Bezier in relative coordinates.
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
/// <summary>
|
||||
/// Returns a copy of the action.
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
/// <summary>
|
||||
/// Returns the reversed version of the action, if it is possible.
|
||||
/// </summary>
|
||||
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;
|
||||
/// <summary>
|
||||
/// This method is called at the action start.
|
||||
/// </summary>
|
||||
public override void start()
|
||||
{
|
||||
base.start();
|
||||
startPoint = target.transform.position;
|
||||
endPoint = startPoint + ep;
|
||||
startControlPoint = startPoint + cp1;
|
||||
endControlPoint = startControlPoint + cp2;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method is called every frame update.
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
/// <summary>
|
||||
/// Blinks the target.
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
/// <summary>
|
||||
/// Returns a copy of the action.
|
||||
/// </summary>
|
||||
public override ActionInstant clone()
|
||||
{
|
||||
return new ActionBlink(count / 2 - 1, durationMin, durationMax);
|
||||
}
|
||||
|
||||
public override Action reverse()
|
||||
{
|
||||
return new ActionBlink(count / 2 - 1, durationMin, durationMax);
|
||||
/// <summary>
|
||||
/// Returns the reversed version of the action, if it is possible.
|
||||
/// </summary>
|
||||
public override ActionInstant reverse()
|
||||
{
|
||||
return new ActionBlink(count / 2 - 1, durationMin, durationMax);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
/// <summary>
|
||||
/// Delays the action for the given amount of seconds.
|
||||
/// </summary>
|
||||
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 override void start()
|
||||
{
|
||||
base.start();
|
||||
if (durationMax != null)
|
||||
public ActionDelay(float tgtDuration)
|
||||
: base(tgtDuration)
|
||||
{
|
||||
duration = UnityEngine.Random.Range(durationMin, durationMax);
|
||||
durationMin = tgtDuration;
|
||||
durationMax = tgtDuration;
|
||||
}
|
||||
|
||||
public ActionDelay(float tgtDuration, float tgtDurationMax)
|
||||
: base(tgtDuration)
|
||||
{
|
||||
durationMin = tgtDuration;
|
||||
durationMax = tgtDurationMax;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method is called at the action start.
|
||||
/// </summary>
|
||||
public override void start()
|
||||
{
|
||||
base.start();
|
||||
if (durationMax != null)
|
||||
{
|
||||
duration = UnityEngine.Random.Range(durationMin, durationMax);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
/// <summary>
|
||||
/// Fades the target by the given alpha value. The tartet shaders should support transparency in order to use this action.
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
/// <summary>
|
||||
/// Returns a copy of the action.
|
||||
/// </summary>
|
||||
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;
|
||||
/// <summary>
|
||||
/// Returns the reversed version of the action, if it is possible.
|
||||
/// </summary>
|
||||
public override ActionInstant reverse()
|
||||
{
|
||||
return new ActionFadeBy(-delta, duration);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method is called every frame update.
|
||||
/// </summary>
|
||||
public override void stepInterval(float dt)
|
||||
{
|
||||
float d = dt / duration;
|
||||
Color tgtColor = renderer.material.color;
|
||||
tgtColor[3] += delta * d;
|
||||
renderer.material.color = tgtColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,21 +2,33 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
class ActionFadeIn : ActionFadeTo
|
||||
namespace coa4u
|
||||
{
|
||||
|
||||
public ActionFadeIn(float tgtDuration)
|
||||
: base(1, tgtDuration)
|
||||
/// <summary>
|
||||
/// Fades in the target. The tartet shaders should support transparency in order to use this action.
|
||||
/// </summary>
|
||||
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);
|
||||
/// <summary>
|
||||
/// Returns a copy of the action.
|
||||
/// </summary>
|
||||
public override ActionInstant clone()
|
||||
{
|
||||
return new ActionFadeIn(duration);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the reversed version of the action, if it is possible.
|
||||
/// </summary>
|
||||
public override ActionInstant reverse()
|
||||
{
|
||||
return new ActionFadeOut(duration);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,21 +2,33 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
class ActionFadeOut : ActionFadeTo
|
||||
namespace coa4u
|
||||
{
|
||||
|
||||
public ActionFadeOut(float tgtDuration)
|
||||
: base(0, tgtDuration)
|
||||
/// <summary>
|
||||
/// Fades out the target. The tartet shaders should support transparency in order to use this action.
|
||||
/// </summary>
|
||||
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);
|
||||
/// <summary>
|
||||
/// Returns a copy of the action.
|
||||
/// </summary>
|
||||
public override ActionInstant clone()
|
||||
{
|
||||
return new ActionFadeOut(duration);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the reversed version of the action, if it is possible.
|
||||
/// </summary>
|
||||
public override ActionInstant reverse()
|
||||
{
|
||||
return new ActionFadeIn(duration);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
/// <summary>
|
||||
/// Fades the target to the given alpha value. The tartet shaders should support transparency in order to use this action.
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
/// <summary>
|
||||
/// Returns a copy of the action.
|
||||
/// </summary>
|
||||
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;
|
||||
/// <summary>
|
||||
/// This method is called at the action start.
|
||||
/// </summary>
|
||||
public override void start()
|
||||
{
|
||||
base.start();
|
||||
delta = value - renderer.material.color.a;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method is called every frame update.
|
||||
/// </summary>
|
||||
public override void stepInterval(float dt)
|
||||
{
|
||||
float d = dt / duration;
|
||||
Color tgtColor = renderer.material.color;
|
||||
tgtColor[3] += delta * d;
|
||||
renderer.material.color = tgtColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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 override Action clone()
|
||||
{
|
||||
return new ActionJumpBy(point, height, jumps, duration);
|
||||
}
|
||||
|
||||
public override Action reverse()
|
||||
{
|
||||
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 ActionJumpBy(Vector3 tgtPoint, float tgtHeight, int tgtJumps, float tgtDuration)
|
||||
: base(new ActionInstant[tgtJumps])
|
||||
{
|
||||
actions[i] = singleJump;
|
||||
point = tgtPoint;
|
||||
jumps = tgtJumps;
|
||||
height = tgtHeight;
|
||||
duration = tgtDuration;
|
||||
}
|
||||
|
||||
public ActionJumpBy(Vector2 tgtPoint, float tgtHeight, int tgtJumps, float tgtDuration)
|
||||
: this((Vector3)tgtPoint, tgtHeight, tgtJumps, tgtDuration)
|
||||
{
|
||||
is2d = true;
|
||||
}
|
||||
|
||||
public override ActionInstant clone()
|
||||
{
|
||||
return new ActionJumpBy(point, height, jumps, duration);
|
||||
}
|
||||
|
||||
public override ActionInstant reverse()
|
||||
{
|
||||
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++)
|
||||
{
|
||||
actions[i] = singleJump;
|
||||
}
|
||||
base.start();
|
||||
}
|
||||
base.start();
|
||||
}
|
||||
}
|
||||
@@ -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 override Action clone()
|
||||
{
|
||||
return new ActionJumpTo(point, height, jumps, duration);
|
||||
}
|
||||
|
||||
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 ActionJumpTo(Vector3 tgtPoint, float tgtHeight, int tgtJumps, float tgtDuration)
|
||||
: base(new ActionInstant[tgtJumps])
|
||||
{
|
||||
actions[i] = singleJump;
|
||||
point = tgtPoint;
|
||||
jumps = tgtJumps;
|
||||
height = tgtHeight;
|
||||
duration = tgtDuration;
|
||||
}
|
||||
|
||||
public ActionJumpTo(Vector2 tgtPoint, float tgtHeight, int tgtJumps, float tgtDuration)
|
||||
: this((Vector3)tgtPoint, tgtHeight, tgtJumps, tgtDuration)
|
||||
{
|
||||
is2d = true;
|
||||
}
|
||||
|
||||
public override ActionInstant clone()
|
||||
{
|
||||
return new ActionJumpTo(point, height, jumps, duration);
|
||||
}
|
||||
|
||||
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++)
|
||||
{
|
||||
actions[i] = singleJump;
|
||||
}
|
||||
base.start();
|
||||
}
|
||||
base.start();
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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 override Action clone()
|
||||
{
|
||||
return new ActionRotateTo(value, duration);
|
||||
}
|
||||
|
||||
public override void start()
|
||||
{
|
||||
base.start();
|
||||
path = new Vector3();
|
||||
for (int i = 0; i < 3; i++)
|
||||
public ActionRotateTo(Vector3 tgtValue, float tgtDuration)
|
||||
: base(tgtDuration)
|
||||
{
|
||||
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;
|
||||
value = tgtValue;
|
||||
}
|
||||
|
||||
public ActionRotateTo(float angle, float tgtDuration)
|
||||
: this(new Vector3(0, 0, angle), tgtDuration)
|
||||
{
|
||||
is2d = true;
|
||||
}
|
||||
|
||||
public override ActionInstant clone()
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
class ActionScaleBy : ActionInterval
|
||||
{
|
||||
delta = tgtDelta;
|
||||
}
|
||||
protected Vector3 delta;
|
||||
protected Vector3 path;
|
||||
|
||||
public ActionScaleBy(Vector2 tgtValue, float tgtDuration)
|
||||
: this((Vector3)tgtValue, tgtDuration)
|
||||
{
|
||||
is2d = true;
|
||||
}
|
||||
public ActionScaleBy(Vector3 tgtDelta, float tgtDuration)
|
||||
: base(tgtDuration)
|
||||
{
|
||||
delta = tgtDelta;
|
||||
}
|
||||
|
||||
public override Action clone()
|
||||
{
|
||||
return new ActionScaleBy(delta, duration);
|
||||
}
|
||||
public ActionScaleBy(Vector2 tgtValue, float tgtDuration)
|
||||
: this((Vector3)tgtValue, tgtDuration)
|
||||
{
|
||||
is2d = true;
|
||||
}
|
||||
|
||||
public override Action reverse()
|
||||
{
|
||||
return new ActionScaleBy(delta * -1F, duration);
|
||||
}
|
||||
public override ActionInstant clone()
|
||||
{
|
||||
return new ActionScaleBy(delta, 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 ActionInstant reverse()
|
||||
{
|
||||
return new ActionScaleBy(delta * -1F, duration);
|
||||
}
|
||||
|
||||
public override void stepInterval(float dt)
|
||||
{
|
||||
float d = dt / duration;
|
||||
Vector3 tgt = path * d;
|
||||
transform.localScale += tgt;
|
||||
}
|
||||
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 stop()
|
||||
{
|
||||
base.stop();
|
||||
public override void stepInterval(float dt)
|
||||
{
|
||||
float d = dt / duration;
|
||||
Vector3 tgt = path * d;
|
||||
transform.localScale += tgt;
|
||||
}
|
||||
|
||||
public override void stop()
|
||||
{
|
||||
base.stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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 override Action reverse()
|
||||
{
|
||||
return new ActionSkewBy(-skewAngles1, -skewAngles2, duration);
|
||||
}
|
||||
|
||||
public override void start()
|
||||
{
|
||||
base.start();
|
||||
if (!(target is MeshActor))
|
||||
public ActionSkewBy(Vector3 tgtAngles1, Vector3 tgtAngles2, float tgtDuration)
|
||||
: base(tgtDuration)
|
||||
{
|
||||
throw new Exception("You should use MeshActor class instead of Actor, if you want to skew your object.");
|
||||
skewAngles1 = tgtAngles1;
|
||||
skewAngles2 = tgtAngles2;
|
||||
}
|
||||
|
||||
public override ActionInstant clone()
|
||||
{
|
||||
return new ActionSkewBy(skewAngles1, skewAngles2, duration);
|
||||
}
|
||||
|
||||
public override ActionInstant reverse()
|
||||
{
|
||||
return new ActionSkewBy(-skewAngles1, -skewAngles2, duration);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
53
src/CoreClasses/MethodHolder.cs
Normal file
53
src/CoreClasses/MethodHolder.cs
Normal file
@@ -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<T> : MethodHolder
|
||||
{
|
||||
protected Action<T> methodParam;
|
||||
|
||||
public MethodHolder(Action<T> tgtMethod)
|
||||
{
|
||||
methodParam = tgtMethod;
|
||||
methodName = tgtMethod.Method.Name;
|
||||
}
|
||||
|
||||
public override void run(object param)
|
||||
{
|
||||
if (methodParam != null)
|
||||
methodParam.Invoke((T)param);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,42 +1,126 @@
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using coa4u;
|
||||
|
||||
/// <summary>
|
||||
/// The default Actor class for the Action system.
|
||||
/// </summary>
|
||||
public class Actor : MonoBehaviour
|
||||
{
|
||||
protected Action action;
|
||||
protected Dictionary<string, MethodHolder> methodsCache = new Dictionary<string, MethodHolder>();
|
||||
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;
|
||||
|
||||
/// <summary>
|
||||
/// This method is called when the script instance is being loaded.
|
||||
/// </summary>
|
||||
protected void Awake()
|
||||
{
|
||||
transformCached = gameObject.transform;
|
||||
rendererCached = gameObject.renderer;
|
||||
meshCached = gameObject.GetComponent<MeshFilter>().mesh;
|
||||
initialState = meshCached.vertices;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method is called at every frame update.
|
||||
/// </summary>
|
||||
protected void Update()
|
||||
{
|
||||
if (paused || action == null)
|
||||
return;
|
||||
if (action.isRunning())
|
||||
if (action.running)
|
||||
action.step(Time.deltaTime);
|
||||
if (skewAngles1 != angles1prev || skewAngles2 != angles2prev)
|
||||
updateSkew();
|
||||
}
|
||||
|
||||
public void AttachAction(Action tgtAction)
|
||||
/// <summary>
|
||||
/// Updates the skew for the mesh.
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attaches and starts the action.
|
||||
/// </summary>
|
||||
public void AttachAction(ActionInstant tgtAction)
|
||||
{
|
||||
if (action != null)
|
||||
{
|
||||
action.stop();
|
||||
}
|
||||
action = tgtAction;
|
||||
action.setActor(this);
|
||||
action.start();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stops all running actions for this actor.
|
||||
/// </summary>
|
||||
public void StopAction()
|
||||
{
|
||||
action.stop();
|
||||
if (action == null)
|
||||
return;
|
||||
if (action.running)
|
||||
action.stop();
|
||||
action = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pauses actions for this actor.
|
||||
/// </summary>
|
||||
public void PauseAction()
|
||||
{
|
||||
paused = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unpauses actions for this actor.
|
||||
/// </summary>
|
||||
public void UnpauseAction()
|
||||
{
|
||||
paused = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the timescale for current action.
|
||||
/// </summary>
|
||||
public void SetTimeScale(float ts)
|
||||
{
|
||||
if (action is ActionInterval)
|
||||
@@ -44,4 +128,40 @@ public class Actor : MonoBehaviour
|
||||
((ActionInterval)action).setTimeScale(ts);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds method to cache to speed-up
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<string>(msgHelloTo));
|
||||
}
|
||||
|
||||
void msgHello()
|
||||
{
|
||||
Debug.Log("Hello!");
|
||||
}
|
||||
|
||||
void msgHelloTo(string who)
|
||||
{
|
||||
Debug.Log("Hello " + who.ToString() + "!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<MeshFilter>().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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user