Renamed some methods to comply with the C# naming convention.master
@@ -37,7 +37,7 @@ namespace coa4u | |||
/// <summary> | |||
/// Returns a copy of the action. | |||
/// </summary> | |||
public virtual ActionInstant clone() | |||
public virtual ActionInstant Clone() | |||
{ | |||
return new ActionInstant(); | |||
} | |||
@@ -45,7 +45,7 @@ namespace coa4u | |||
/// <summary> | |||
/// Returns the reversed version of the action, if it is possible. | |||
/// </summary> | |||
public virtual ActionInstant reverse() | |||
public virtual ActionInstant Reverse() | |||
{ | |||
throw new Exception("Can reverse only the reversable interval actions"); | |||
} | |||
@@ -53,7 +53,7 @@ namespace coa4u | |||
/// <summary> | |||
/// This method is called at the action start. Usable for instant and interval actions. | |||
/// </summary> | |||
public virtual void start() | |||
public virtual void Start() | |||
{ | |||
if (target == null) | |||
throw new Exception("Can start the action only after it's atached to the actor"); | |||
@@ -64,7 +64,7 @@ namespace coa4u | |||
/// <summary> | |||
/// This method is called at every frame update. Not usable for instant actions. | |||
/// </summary> | |||
public virtual void step(float dt) | |||
public virtual void StepTimer(float dt) | |||
{ | |||
if (target == null) | |||
throw new Exception("Can update the action only after it's atached to the actor"); | |||
@@ -73,7 +73,7 @@ namespace coa4u | |||
/// <summary> | |||
/// This method is called after the interval action is stopped. Not usable for instant actions. | |||
/// </summary> | |||
public virtual void stop() | |||
public virtual void Stop() | |||
{ | |||
if (target == null) | |||
throw new Exception("Can stop the action only after it's atached to the actor"); | |||
@@ -82,7 +82,7 @@ namespace coa4u | |||
/// <summary> | |||
/// This method sets the actor for the action. | |||
/// </summary> | |||
public void setActor(Actor actor) | |||
public void SetActor(Actor actor) | |||
{ | |||
target = actor; | |||
} | |||
@@ -90,7 +90,7 @@ namespace coa4u | |||
/// <summary> | |||
/// This method modifies the given vector to keep the locked axises untouched. | |||
/// </summary> | |||
protected void lockAxises(ref Vector3 point) | |||
protected void LockAxises(ref Vector3 point) | |||
{ | |||
{ | |||
if (target == null) | |||
@@ -13,10 +13,10 @@ namespace coa4u | |||
protected float timeScale; | |||
private float dtrdata; | |||
public ActionInterval(float tgtDuration) | |||
public ActionInterval(float targetDuration) | |||
: base() | |||
{ | |||
duration = tgtDuration; | |||
duration = targetDuration; | |||
timeScale = 1F; | |||
dtr = 0; | |||
} | |||
@@ -24,7 +24,7 @@ namespace coa4u | |||
/// <summary> | |||
/// Returns a copy of the action. | |||
/// </summary> | |||
public override ActionInstant clone() | |||
public override ActionInstant Clone() | |||
{ | |||
return new ActionInterval(duration); | |||
} | |||
@@ -32,7 +32,7 @@ namespace coa4u | |||
/// <summary> | |||
/// Returns the reversed version of the action, if it is possible. | |||
/// </summary> | |||
public override ActionInstant reverse() | |||
public override ActionInstant Reverse() | |||
{ | |||
throw new Exception("Can reverse only the reversable interval actions"); | |||
} | |||
@@ -40,9 +40,9 @@ namespace coa4u | |||
/// <summary> | |||
/// This method is called at the action start. | |||
/// </summary> | |||
public override void start() | |||
public override void Start() | |||
{ | |||
base.start(); | |||
base.Start(); | |||
running = true; | |||
timer = 0F; | |||
} | |||
@@ -50,19 +50,19 @@ namespace coa4u | |||
/// <summary> | |||
/// This method is called after the interval action is stopped. | |||
/// </summary> | |||
public override void stop() | |||
public override void Stop() | |||
{ | |||
base.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. | |||
/// This method is called every frame update. Don't override this method, when inheriting, put your code in Step() instead. | |||
/// </summary> | |||
public override void step(float dt) | |||
public override void StepTimer(float dt) | |||
{ | |||
dt *= timeScale; | |||
base.step(dt); | |||
base.StepTimer(dt); | |||
if (timer + dt > duration) | |||
{ | |||
float odt = dt; | |||
@@ -73,10 +73,10 @@ namespace coa4u | |||
{ | |||
timer += dt; | |||
} | |||
stepInterval(dt); | |||
Step(dt); | |||
if (timer > duration) | |||
{ | |||
stop(); | |||
Stop(); | |||
dtr = timer - duration; | |||
} | |||
} | |||
@@ -84,14 +84,14 @@ namespace coa4u | |||
/// <summary> | |||
/// This method is called every frame update. Put your code here. | |||
/// </summary> | |||
public virtual void stepInterval(float dt) | |||
public virtual void Step(float dt) | |||
{ | |||
} | |||
/// <summary> | |||
/// Immediately changes the time scale for this action and all nested ones. | |||
/// </summary> | |||
public void setTimeScale(float ts) | |||
public void SetTimeScale(float ts) | |||
{ | |||
timeScale = ts; | |||
} | |||
@@ -24,55 +24,43 @@ namespace coa4u | |||
} | |||
/// <summary> | |||
/// Returns a copy of the action. | |||
/// </summary> | |||
public override ActionInstant clone() | |||
public override ActionInstant Clone() | |||
{ | |||
ActionInstant[] aList = new ActionInstant[actions.Length]; | |||
for (int i = 0; i < actions.Length; i++) | |||
{ | |||
aList[i] = actions[i].clone(); | |||
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() | |||
public override ActionInstant Reverse() | |||
{ | |||
ActionInstant[] aList = new ActionInstant[actions.Length]; | |||
for (int i = 0; i < actions.Length; i++) | |||
{ | |||
aList[i] = actions[i].reverse(); | |||
aList[i] = actions[i].Reverse(); | |||
} | |||
return new ActionSequence(aList); | |||
} | |||
/// <summary> | |||
/// This method is called at the action start. | |||
/// </summary> | |||
public override void start() | |||
public override void Start() | |||
{ | |||
base.start(); | |||
base.Start(); | |||
for (int i = 0; i < actions.Length; i++) | |||
{ | |||
actions[i].setActor(target); | |||
actions[i].start(); | |||
actions[i].SetActor(target); | |||
actions[i].Start(); | |||
} | |||
} | |||
/// <summary> | |||
/// This method is called every frame update. | |||
/// </summary> | |||
public override void step(float dt) | |||
public override void StepTimer(float dt) | |||
{ | |||
dt *= timeScale; | |||
for (int i = 0; i < actions.Length; i++) | |||
{ | |||
if (actions[i].running) | |||
actions[i].step(dt); | |||
actions[i].StepTimer(dt); | |||
} | |||
bool canStopNow = true; | |||
float dtrdata = 0; | |||
@@ -86,7 +74,7 @@ namespace coa4u | |||
} | |||
if (canStopNow) | |||
{ | |||
stop(); | |||
Stop(); | |||
dtr = dtrdata; | |||
} | |||
} | |||
@@ -94,12 +82,12 @@ namespace coa4u | |||
/// <summary> | |||
/// This method is called after the interval action is stopped. | |||
/// </summary> | |||
public override void stop() | |||
public override void Stop() | |||
{ | |||
base.stop(); | |||
base.Stop(); | |||
for (int i = 0; i < actions.Length; i++) | |||
{ | |||
actions[i].stop(); | |||
actions[i].Stop(); | |||
} | |||
} | |||
} |
@@ -26,54 +26,42 @@ namespace coa4u | |||
} | |||
/// <summary> | |||
/// Returns a copy of the action. | |||
/// </summary> | |||
public override ActionInstant clone() | |||
public override ActionInstant Clone() | |||
{ | |||
ActionInstant[] aList = new ActionInstant[actions.Length]; | |||
for (int i = 0; i < actions.Length; i++) | |||
{ | |||
aList[i] = actions[i].clone(); | |||
aList[i] = actions[i].Clone(); | |||
} | |||
return new ActionRandom(aList); | |||
} | |||
/// <summary> | |||
/// Returns the reversed version of the action, if it is possible. | |||
/// </summary> | |||
public override ActionInstant reverse() | |||
public override ActionInstant Reverse() | |||
{ | |||
ActionInstant[] aList = new ActionInstant[actions.Length]; | |||
for (int i = 0; i < actions.Length; i++) | |||
{ | |||
aList[i] = actions[i].reverse(); | |||
aList[i] = actions[i].Reverse(); | |||
} | |||
return new ActionRandom(aList); | |||
} | |||
/// <summary> | |||
/// This method is called at the action start. | |||
/// </summary> | |||
public override void start() | |||
public override void Start() | |||
{ | |||
base.start(); | |||
base.Start(); | |||
index = UnityEngine.Random.Range(0, actions.Length); | |||
actions[index].setActor(target); | |||
actions[index].start(); | |||
actions[index].SetActor(target); | |||
actions[index].Start(); | |||
} | |||
/// <summary> | |||
/// This method is called every frame update. | |||
/// </summary> | |||
public override void step(float dt) | |||
public override void StepTimer(float dt) | |||
{ | |||
dt *= timeScale; | |||
if (actions[index].running) | |||
actions[index].step(dt); | |||
actions[index].StepTimer(dt); | |||
if (!actions[index].running) | |||
{ | |||
stop(); | |||
Stop(); | |||
dtr = actions[index].dtr; | |||
} | |||
} | |||
@@ -81,10 +69,10 @@ namespace coa4u | |||
/// <summary> | |||
/// This method is called after the interval action is stopped. | |||
/// </summary> | |||
public override void stop() | |||
public override void Stop() | |||
{ | |||
base.stop(); | |||
actions[index].stop(); | |||
base.Stop(); | |||
actions[index].Stop(); | |||
} | |||
} | |||
} |
@@ -14,73 +14,61 @@ namespace coa4u | |||
protected int counter; | |||
protected bool forever; | |||
public ActionRepeat(ActionInterval tgtAction, int tgtCount) | |||
public ActionRepeat(ActionInterval targetAction, int targetCount) | |||
: base(0) | |||
{ | |||
action = tgtAction; | |||
count = tgtCount; | |||
action = targetAction; | |||
count = targetCount; | |||
counter = 0; | |||
forever = false; | |||
} | |||
public ActionRepeat(ActionInterval tgtAction) | |||
public ActionRepeat(ActionInterval targetAction) | |||
: base(0) | |||
{ | |||
action = tgtAction; | |||
action = targetAction; | |||
count = 0; | |||
counter = 0; | |||
forever = true; | |||
} | |||
/// <summary> | |||
/// Returns a copy of the action. | |||
/// </summary> | |||
public override ActionInstant clone() | |||
public override ActionInstant Clone() | |||
{ | |||
return new ActionRepeat((ActionInterval)action.clone(), count); | |||
return new ActionRepeat((ActionInterval)action.Clone(), count); | |||
} | |||
/// <summary> | |||
/// Returns the reversed version of the action, if it is possible. | |||
/// </summary> | |||
public override ActionInstant reverse() | |||
public override ActionInstant Reverse() | |||
{ | |||
return new ActionRepeat((ActionInterval)action.reverse(), count); | |||
return new ActionRepeat((ActionInterval)action.Reverse(), count); | |||
} | |||
/// <summary> | |||
/// This method is called at the action start. | |||
/// </summary> | |||
public override void start() | |||
public override void Start() | |||
{ | |||
base.start(); | |||
action.setActor(target); | |||
action.start(); | |||
base.Start(); | |||
action.SetActor(target); | |||
action.Start(); | |||
counter = 0; | |||
} | |||
/// <summary> | |||
/// This method is called every frame update. | |||
/// </summary> | |||
public override void step(float dt) | |||
public override void StepTimer(float dt) | |||
{ | |||
dt *= timeScale; | |||
if (action.running) | |||
{ | |||
action.step(dt); | |||
action.StepTimer(dt); | |||
} | |||
if (!action.running && (forever || counter < count - 1)) | |||
{ | |||
float dtrdata = action.dtr; | |||
action.start(); | |||
action.Start(); | |||
if (dtrdata > 0) | |||
action.step(dtrdata); | |||
action.StepTimer(dtrdata); | |||
counter += 1; | |||
} | |||
else if (!action.running && counter >= count - 1) | |||
{ | |||
dtr = action.dtr; | |||
stop(); | |||
Stop(); | |||
} | |||
} | |||
} |
@@ -25,73 +25,61 @@ namespace coa4u | |||
} | |||
/// <summary> | |||
/// Returns a copy of the action. | |||
/// </summary> | |||
public override ActionInstant clone() | |||
public override ActionInstant Clone() | |||
{ | |||
ActionInstant[] aList = new ActionInstant[actions.Length]; | |||
for (int i = 0; i < actions.Length; i++) | |||
{ | |||
aList[i] = actions[i].clone(); | |||
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() | |||
public override ActionInstant Reverse() | |||
{ | |||
ActionInstant[] aList = new ActionInstant[actions.Length]; | |||
for (int i = 0; i < actions.Length; i++) | |||
{ | |||
aList[actions.Length - 1 - i] = actions[i].reverse(); | |||
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() | |||
public override void Start() | |||
{ | |||
base.start(); | |||
base.Start(); | |||
index = 0; | |||
actions[0].setActor(target); | |||
actions[0].start(); | |||
actions[0].SetActor(target); | |||
actions[0].Start(); | |||
while (!actions[index].running && index < actions.Length) | |||
{ | |||
index += 1; | |||
actions[index].setActor(target); | |||
actions[index].start(); | |||
actions[index].SetActor(target); | |||
actions[index].Start(); | |||
} | |||
} | |||
/// <summary> | |||
/// This method is called every frame update. | |||
/// </summary> | |||
public override void step(float dt) | |||
public override void StepTimer(float dt) | |||
{ | |||
dt *= timeScale; | |||
float dtrdata = 0; | |||
if (actions[index].running) | |||
{ | |||
actions[index].step(dt); | |||
actions[index].StepTimer(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(); | |||
actions[index].SetActor(target); | |||
actions[index].Start(); | |||
if (actions[index].running && dtrdata > 0) | |||
actions[index].step(dtrdata); | |||
actions[index].StepTimer(dtrdata); | |||
} | |||
if (!actions[index].running) | |||
{ | |||
stop(); | |||
Stop(); | |||
dtr = dtrdata; | |||
} | |||
} | |||
@@ -99,12 +87,12 @@ namespace coa4u | |||
/// <summary> | |||
/// This method is called after the interval action is stopped. | |||
/// </summary> | |||
public override void stop() | |||
public override void Stop() | |||
{ | |||
base.stop(); | |||
base.Stop(); | |||
for (int i = 0; i < actions.Length; i++) | |||
{ | |||
actions[i].stop(); | |||
actions[i].Stop(); | |||
} | |||
} | |||
} |
@@ -14,20 +14,14 @@ namespace coa4u | |||
{ | |||
} | |||
/// <summary> | |||
/// Returns a copy of the action. | |||
/// </summary> | |||
public override ActionInstant clone() | |||
public override ActionInstant Clone() | |||
{ | |||
return new ActionStop(); | |||
} | |||
/// <summary> | |||
/// This method is called at the action start. | |||
/// </summary> | |||
public override void start() | |||
public override void Start() | |||
{ | |||
base.start(); | |||
base.Start(); | |||
target.StopAction(); | |||
} | |||
} |
@@ -15,28 +15,19 @@ namespace coa4u | |||
{ | |||
} | |||
/// <summary> | |||
/// Returns a copy of the action. | |||
/// </summary> | |||
public override ActionInstant clone() | |||
public override ActionInstant Clone() | |||
{ | |||
return new ActionHide(); | |||
} | |||
/// <summary> | |||
/// Returns the reversed version of the action, if it is possible. | |||
/// </summary> | |||
public override ActionInstant reverse() | |||
public override ActionInstant Reverse() | |||
{ | |||
return new ActionShow(); | |||
} | |||
/// <summary> | |||
/// This method is called at the action start. | |||
/// </summary> | |||
public override void start() | |||
public override void Start() | |||
{ | |||
base.start(); | |||
base.Start(); | |||
renderer.enabled = false; | |||
} | |||
} |
@@ -11,16 +11,13 @@ namespace coa4u | |||
{ | |||
string message; | |||
public ActionLog(string tgtMessage) | |||
public ActionLog(string targetMessage) | |||
: base() | |||
{ | |||
message = tgtMessage; | |||
message = targetMessage; | |||
} | |||
/// <summary> | |||
/// Returns a copy of the action. | |||
/// </summary> | |||
public override ActionInstant clone() | |||
public override ActionInstant Clone() | |||
{ | |||
return new ActionLog(message); | |||
} | |||
@@ -28,17 +25,14 @@ namespace coa4u | |||
/// <summary> | |||
/// Returns the reversed version of the action, if it is possible. | |||
/// </summary> | |||
public override ActionInstant reverse() | |||
public override ActionInstant Reverse() | |||
{ | |||
return new ActionLog(message); | |||
} | |||
/// <summary> | |||
/// This method is called at the action start. | |||
/// </summary> | |||
public override void start() | |||
public override void Start() | |||
{ | |||
base.start(); | |||
base.Start(); | |||
Debug.Log(message); | |||
} | |||
} |
@@ -15,49 +15,40 @@ namespace coa4u | |||
protected object param; | |||
protected SendMessageOptions options = SendMessageOptions.DontRequireReceiver; | |||
public ActionSendMessage(string tgtMessage) | |||
public ActionSendMessage(string targetMessage) | |||
: base() | |||
{ | |||
message = tgtMessage; | |||
message = targetMessage; | |||
} | |||
public ActionSendMessage(string tgtMessage, object tgtParam) | |||
public ActionSendMessage(string targetMessage, object targetParam) | |||
: base() | |||
{ | |||
message = tgtMessage; | |||
param = tgtParam; | |||
message = targetMessage; | |||
param = targetParam; | |||
} | |||
public ActionSendMessage(string tgtMessage, object tgtParam, SendMessageOptions tgtOptions) | |||
public ActionSendMessage(string targetMessage, object targetParam, SendMessageOptions targetOptions) | |||
: base() | |||
{ | |||
message = tgtMessage; | |||
param = tgtParam; | |||
options = tgtOptions; | |||
message = targetMessage; | |||
param = targetParam; | |||
options = targetOptions; | |||
} | |||
/// <summary> | |||
/// Returns a copy of the action. | |||
/// </summary> | |||
public override ActionInstant clone() | |||
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() | |||
public override ActionInstant Reverse() | |||
{ | |||
return new ActionSendMessage(message, param, options); | |||
} | |||
/// <summary> | |||
/// This method is called at the action start. | |||
/// </summary> | |||
public override void start() | |||
public override void Start() | |||
{ | |||
base.start(); | |||
base.Start(); | |||
if (param != null) | |||
{ | |||
target.ReceiveMessage(message, param, options); | |||
@@ -12,38 +12,32 @@ namespace coa4u | |||
protected Vector3 value; | |||
protected Actor other; | |||
public ActionSetDirection(Vector3 tgtValue) | |||
public ActionSetDirection(Vector3 targetValue) | |||
: base() | |||
{ | |||
value = tgtValue; | |||
value = targetValue; | |||
} | |||
public ActionSetDirection(Vector2 tgtValue) | |||
: this((Vector3)tgtValue) | |||
public ActionSetDirection(Vector2 targetValue) | |||
: this((Vector3)targetValue) | |||
{ | |||
locks = Axises.z; | |||
} | |||
public ActionSetDirection(Actor tgtActor) | |||
public ActionSetDirection(Actor targetActor) | |||
: base() | |||
{ | |||
other = tgtActor; | |||
other = targetActor; | |||
} | |||
/// <summary> | |||
/// Returns a copy of the action. | |||
/// </summary> | |||
public override ActionInstant clone() | |||
public override ActionInstant Clone() | |||
{ | |||
return new ActionSetDirection(value); | |||
} | |||
/// <summary> | |||
/// This method is called at the action start. | |||
/// </summary> | |||
public override void start() | |||
public override void Start() | |||
{ | |||
base.start(); | |||
base.Start(); | |||
if (other != null) | |||
{ | |||
value = other.transform.position; | |||
@@ -11,34 +11,28 @@ namespace coa4u | |||
{ | |||
protected Vector3 value; | |||
public ActionSetPlace(Vector3 tgtPlace) | |||
public ActionSetPlace(Vector3 targetPlace) | |||
: base() | |||
{ | |||
value = tgtPlace; | |||
value = targetPlace; | |||
} | |||
public ActionSetPlace(Vector2 tgtPlace) | |||
: this((Vector3)tgtPlace) | |||
public ActionSetPlace(Vector2 targetPlace) | |||
: this((Vector3)targetPlace) | |||
{ | |||
locks = Axises.z; | |||
} | |||
/// <summary> | |||
/// Returns a copy of the action. | |||
/// </summary> | |||
public override ActionInstant clone() | |||
public override ActionInstant Clone() | |||
{ | |||
return new ActionSetPlace(value); | |||
} | |||
/// <summary> | |||
/// This method is called at the action start. | |||
/// </summary> | |||
public override void start() | |||
public override void Start() | |||
{ | |||
base.start(); | |||
base.Start(); | |||
if (locks != Axises.none) | |||
lockAxises(ref value); | |||
LockAxises(ref value); | |||
transform.position = value; | |||
} | |||
} |
@@ -11,10 +11,10 @@ namespace coa4u | |||
{ | |||
protected Vector3 value; | |||
public ActionSetRotation(Vector3 tgtValue) | |||
public ActionSetRotation(Vector3 targetValue) | |||
: base() | |||
{ | |||
value = tgtValue; | |||
value = targetValue; | |||
} | |||
public ActionSetRotation(float angle) | |||
@@ -23,22 +23,16 @@ namespace coa4u | |||
locks = Axises.xy; | |||
} | |||
/// <summary> | |||
/// Returns a copy of the action. | |||
/// </summary> | |||
public override ActionInstant clone() | |||
public override ActionInstant Clone() | |||
{ | |||
return new ActionSetRotation(value); | |||
} | |||
/// <summary> | |||
/// This method is called at the action start. | |||
/// </summary> | |||
public override void start() | |||
public override void Start() | |||
{ | |||
base.start(); | |||
base.Start(); | |||
if (locks != Axises.none) | |||
lockAxises(ref value); | |||
LockAxises(ref value); | |||
transform.rotation = Quaternion.Euler(value); | |||
} | |||
} |
@@ -12,26 +12,20 @@ namespace coa4u | |||
public Vector4 color; | |||
protected const float coeff = 1F / 255F; | |||
public ActionSetTint(Vector4 tgtColor) | |||
public ActionSetTint(Vector4 targetColor) | |||
: base() | |||
{ | |||
color = tgtColor * coeff; | |||
color = targetColor * coeff; | |||
} | |||
/// <summary> | |||
/// Returns a copy of the action. | |||
/// </summary> | |||
public override ActionInstant clone() | |||
public override ActionInstant Clone() | |||
{ | |||
return new ActionSetTint(color * 255F); | |||
} | |||
/// <summary> | |||
/// This method is called at the action start. | |||
/// </summary> | |||
public override void start() | |||
public override void Start() | |||
{ | |||
base.start(); | |||
base.Start(); | |||
renderer.material.color = new Color(color[0], color[1], color[2], color[3]); | |||
} | |||
} |
@@ -15,28 +15,19 @@ namespace coa4u | |||
{ | |||
} | |||
/// <summary> | |||
/// Returns a copy of the action. | |||
/// </summary> | |||
public override ActionInstant clone() | |||
public override ActionInstant Clone() | |||
{ | |||
return new ActionShow(); | |||
} | |||
/// <summary> | |||
/// Returns the reversed version of the action, if it is possible. | |||
/// </summary> | |||
public override ActionInstant reverse() | |||
public override ActionInstant Reverse() | |||
{ | |||
return new ActionHide(); | |||
} | |||
/// <summary> | |||
/// This method is called at the action start. | |||
/// </summary> | |||
public override void start() | |||
public override void Start() | |||
{ | |||
base.start(); | |||
base.Start(); | |||
renderer.enabled = true; | |||
} | |||
} |
@@ -15,28 +15,19 @@ namespace coa4u | |||
{ | |||
} | |||
/// <summary> | |||
/// Returns a copy of the action. | |||
/// </summary> | |||
public override ActionInstant clone() | |||
public override ActionInstant Clone() | |||
{ | |||
return new ActionToggleVisibility(); | |||
} | |||
/// <summary> | |||
/// Returns the reversed version of the action, if it is possible. | |||
/// </summary> | |||
public override ActionInstant reverse() | |||
public override ActionInstant Reverse() | |||
{ | |||
return new ActionToggleVisibility(); | |||
} | |||
/// <summary> | |||
/// This method is called at the action start. | |||
/// </summary> | |||
public override void start() | |||
public override void Start() | |||
{ | |||
base.start(); | |||
base.Start(); | |||
renderer.enabled = !renderer.enabled; | |||
} | |||
} |
@@ -14,57 +14,45 @@ namespace coa4u | |||
protected Vector3 startControlPoint; | |||
protected Vector3 endControlPoint; | |||
public ActionBezierAbs(Vector3 tgtStart, Vector3 tgtSCP, Vector3 tgtECP, Vector3 tgtEnd, float tgtDuration) | |||
: base(tgtDuration) | |||
public ActionBezierAbs(Vector3 targetStart, Vector3 targetSCP, Vector3 targetECP, Vector3 targetEnd, float targetDuration) | |||
: base(targetDuration) | |||
{ | |||
startPoint = tgtStart; | |||
endPoint = tgtEnd; | |||
startControlPoint = tgtSCP; | |||
endControlPoint = tgtECP; | |||
startPoint = targetStart; | |||
endPoint = targetEnd; | |||
startControlPoint = targetSCP; | |||
endControlPoint = targetECP; | |||
} | |||
public ActionBezierAbs(Vector2 tgtStart, Vector2 tgtSCP, Vector2 tgtECP, Vector2 tgtEnd, float tgtDuration) | |||
: this((Vector3)tgtStart, (Vector3)tgtSCP, (Vector3)tgtECP, (Vector3)tgtEnd, tgtDuration) | |||
public ActionBezierAbs(Vector2 targetStart, Vector2 targetSCP, Vector2 targetECP, Vector2 targetEnd, float targetDuration) | |||
: this((Vector3)targetStart, (Vector3)targetSCP, (Vector3)targetECP, (Vector3)targetEnd, targetDuration) | |||
{ | |||
locks = Axises.z; | |||
} | |||
/// <summary> | |||
/// Returns a copy of the action. | |||
/// </summary> | |||
public override ActionInstant clone() | |||
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() | |||
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() | |||
public override void Start() | |||
{ | |||
base.start(); | |||
base.Start(); | |||
float z = transform.position.z; | |||
if (locks != Axises.none) | |||
{ | |||
lockAxises(ref startPoint); | |||
lockAxises(ref endPoint); | |||
lockAxises(ref startControlPoint); | |||
lockAxises(ref endControlPoint); | |||
LockAxises(ref startPoint); | |||
LockAxises(ref endPoint); | |||
LockAxises(ref startControlPoint); | |||
LockAxises(ref endControlPoint); | |||
} | |||
} | |||
/// <summary> | |||
/// This method is called every frame update. | |||
/// </summary> | |||
public override void stepInterval(float dt) | |||
public override void Step(float dt) | |||
{ | |||
float t = timer / duration; | |||
Vector3 newPosition = (((-startPoint | |||
@@ -17,51 +17,39 @@ namespace coa4u | |||
protected Vector3 startControlPoint; | |||
protected Vector3 endControlPoint; | |||
public ActionBezierRel(Vector3 tgtSCP, Vector3 tgtECP, Vector3 tgtEnd, float tgtDuration) | |||
: base(tgtDuration) | |||
public ActionBezierRel(Vector3 targetSCP, Vector3 targetECP, Vector3 targetEnd, float targetDuration) | |||
: base(targetDuration) | |||
{ | |||
ep = tgtEnd; | |||
cp1 = tgtSCP; | |||
cp2 = tgtECP; | |||
ep = targetEnd; | |||
cp1 = targetSCP; | |||
cp2 = targetECP; | |||
} | |||
public ActionBezierRel(Vector2 tgtSCP, Vector2 tgtECP, Vector2 tgtEnd, float tgtDuration) | |||
: this((Vector3)tgtSCP, (Vector3)tgtECP, (Vector3)tgtEnd, tgtDuration) | |||
public ActionBezierRel(Vector2 targetSCP, Vector2 targetECP, Vector2 targetEnd, float targetDuration) | |||
: this((Vector3)targetSCP, (Vector3)targetECP, (Vector3)targetEnd, targetDuration) | |||
{ | |||
} | |||
/// <summary> | |||
/// Returns a copy of the action. | |||
/// </summary> | |||
public override ActionInstant clone() | |||
public override ActionInstant Clone() | |||
{ | |||
return new ActionBezierRel(startControlPoint, endControlPoint, endPoint, duration); | |||
} | |||
/// <summary> | |||
/// Returns the reversed version of the action, if it is possible. | |||
/// </summary> | |||
public override ActionInstant reverse() | |||
public override ActionInstant Reverse() | |||
{ | |||
return new ActionBezierRel(-startControlPoint, -endControlPoint, -endPoint, duration); | |||
} | |||
/// <summary> | |||
/// This method is called at the action start. | |||
/// </summary> | |||
public override void start() | |||
public override void Start() | |||
{ | |||
base.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) | |||
public override void Step(float dt) | |||
{ | |||
float t = timer / duration; | |||
Vector3 newPosition = (((-startPoint | |||
@@ -15,46 +15,40 @@ namespace coa4u | |||
protected float durationMin; | |||
protected float durationMax; | |||
public ActionBlink(int tgtBlinks, float tgtDuration) | |||
public ActionBlink(int targetBlinks, float targetDuration) | |||
: base(null, 0) | |||
{ | |||
durationMin = tgtDuration; | |||
durationMax = tgtDuration; | |||
count = (tgtBlinks) * 2; | |||
durationMin = targetDuration; | |||
durationMax = targetDuration; | |||
count = (targetBlinks) * 2; | |||
blinkSeq = new ActionInstant[] | |||
{ | |||
new ActionToggleVisibility(), | |||
new ActionDelay(tgtDuration / tgtBlinks) | |||
new ActionDelay(targetDuration / targetBlinks) | |||
}; | |||
action = new ActionSequence(blinkSeq); | |||
} | |||
public ActionBlink(int tgtBlinks, float tgtDurationMin, float tgtDurationMax) | |||
public ActionBlink(int targetBlinks, float targetDurationMin, float targetDurationMax) | |||
: base(null, 0) | |||
{ | |||
durationMin = tgtDurationMin; | |||
durationMax = tgtDurationMax; | |||
count = (tgtBlinks) * 2; | |||
durationMin = targetDurationMin; | |||
durationMax = targetDurationMax; | |||
count = (targetBlinks) * 2; | |||
blinkSeq = new ActionInstant[] | |||
{ | |||
new ActionToggleVisibility(), | |||
new ActionDelay(tgtDurationMin / tgtBlinks, tgtDurationMax / tgtBlinks) | |||
new ActionDelay(targetDurationMin / targetBlinks, targetDurationMax / targetBlinks) | |||
}; | |||
action = new ActionSequence(blinkSeq); | |||
} | |||
/// <summary> | |||
/// Returns a copy of the action. | |||
/// </summary> | |||
public override ActionInstant clone() | |||
public override ActionInstant Clone() | |||
{ | |||
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() | |||
public override ActionInstant Reverse() | |||
{ | |||
return new ActionBlink(count / 2 - 1, durationMin, durationMax); | |||
} | |||
@@ -12,26 +12,23 @@ namespace coa4u | |||
protected float durationMin; | |||
protected float durationMax; | |||
public ActionDelay(float tgtDuration) | |||
: base(tgtDuration) | |||
public ActionDelay(float targetDuration) | |||
: base(targetDuration) | |||
{ | |||
durationMin = tgtDuration; | |||
durationMax = tgtDuration; | |||
durationMin = targetDuration; | |||
durationMax = targetDuration; | |||
} | |||
public ActionDelay(float tgtDuration, float tgtDurationMax) | |||
: base(tgtDuration) | |||
public ActionDelay(float targetDuration, float targetDurationMax) | |||
: base(targetDuration) | |||
{ | |||
durationMin = tgtDuration; | |||
durationMax = tgtDurationMax; | |||
durationMin = targetDuration; | |||
durationMax = targetDurationMax; | |||
} | |||
/// <summary> | |||
/// This method is called at the action start. | |||
/// </summary> | |||
public override void start() | |||
public override void Start() | |||
{ | |||
base.start(); | |||
base.Start(); | |||
if (durationMax != null) | |||
{ | |||
duration = UnityEngine.Random.Range(durationMin, durationMax); | |||
@@ -11,37 +11,28 @@ namespace coa4u | |||
{ | |||
protected float delta; | |||
public ActionFadeBy(float tgtDelta, float tgtDuration) | |||
: base(tgtDuration) | |||
public ActionFadeBy(float targetDelta, float targetDuration) | |||
: base(targetDuration) | |||
{ | |||
delta = tgtDelta; | |||
delta = targetDelta; | |||
} | |||
/// <summary> | |||
/// Returns a copy of the action. | |||
/// </summary> | |||
public override ActionInstant clone() | |||
public override ActionInstant Clone() | |||
{ | |||
return new ActionFadeBy(delta, duration); | |||
} | |||
/// <summary> | |||
/// Returns the reversed version of the action, if it is possible. | |||
/// </summary> | |||
public override ActionInstant reverse() | |||
public override ActionInstant Reverse() | |||
{ | |||
return new ActionFadeBy(-delta, duration); | |||
} | |||
/// <summary> | |||
/// This method is called every frame update. | |||
/// </summary> | |||
public override void stepInterval(float dt) | |||
public override void Step(float dt) | |||
{ | |||
float d = dt / duration; | |||
Color tgtColor = renderer.material.color; | |||
tgtColor[3] += delta * d; | |||
renderer.material.color = tgtColor; | |||
Color targetColor = renderer.material.color; | |||
targetColor[3] += delta * d; | |||
renderer.material.color = targetColor; | |||
} | |||
} | |||
} |
@@ -10,23 +10,17 @@ namespace coa4u | |||
class ActionFadeIn : ActionFadeTo | |||
{ | |||
public ActionFadeIn(float tgtDuration) | |||
: base(1, tgtDuration) | |||
public ActionFadeIn(float targetDuration) | |||
: base(1, targetDuration) | |||
{ | |||
} | |||
/// <summary> | |||
/// Returns a copy of the action. | |||
/// </summary> | |||
public override ActionInstant clone() | |||
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() | |||
public override ActionInstant Reverse() | |||
{ | |||
return new ActionFadeOut(duration); | |||
} | |||
@@ -10,23 +10,17 @@ namespace coa4u | |||
class ActionFadeOut : ActionFadeTo | |||
{ | |||
public ActionFadeOut(float tgtDuration) | |||
: base(0, tgtDuration) | |||
public ActionFadeOut(float targetDuration) | |||
: base(0, targetDuration) | |||
{ | |||
} | |||
/// <summary> | |||
/// Returns a copy of the action. | |||
/// </summary> | |||
public override ActionInstant clone() | |||
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() | |||
public override ActionInstant Reverse() | |||
{ | |||
return new ActionFadeIn(duration); | |||
} | |||
@@ -12,38 +12,29 @@ namespace coa4u | |||
protected float value; | |||
protected float delta; | |||
public ActionFadeTo(float tgtValue, float tgtDuration) | |||
: base(tgtDuration) | |||
public ActionFadeTo(float targetValue, float targetDuration) | |||
: base(targetDuration) | |||
{ | |||
value = tgtValue; | |||
value = targetValue; | |||
} | |||
/// <summary> | |||
/// Returns a copy of the action. | |||
/// </summary> | |||
public override ActionInstant clone() | |||
public override ActionInstant Clone() | |||
{ | |||
return new ActionFadeTo(value, duration); | |||
} | |||
/// <summary> | |||
/// This method is called at the action start. | |||
/// </summary> | |||
public override void start() | |||
public override void Start() | |||
{ | |||
base.start(); | |||
base.Start(); | |||
delta = value - renderer.material.color.a; | |||
} | |||
/// <summary> | |||
/// This method is called every frame update. | |||
/// </summary> | |||
public override void stepInterval(float dt) | |||
public override void Step(float dt) | |||
{ | |||
float d = dt / duration; | |||
Color tgtColor = renderer.material.color; | |||
tgtColor[3] += delta * d; | |||
renderer.material.color = tgtColor; | |||
Color targetColor = renderer.material.color; | |||
targetColor[3] += delta * d; | |||
renderer.material.color = targetColor; | |||
} | |||
} | |||
} |
@@ -4,37 +4,40 @@ using UnityEngine; | |||
namespace coa4u | |||
{ | |||
/// <summary> | |||
/// Jumps given number of times in the given direction for the given amount of seconds. | |||
/// </summary> | |||
class ActionJumpBy : ActionSequence | |||
{ | |||
protected Vector3 point; | |||
float height; | |||
int jumps; | |||
public ActionJumpBy(Vector3 tgtPoint, float tgtHeight, int tgtJumps, float tgtDuration) | |||
: base(new ActionInstant[tgtJumps]) | |||
public ActionJumpBy(Vector3 targetPoint, float targetHeight, int targetJumps, float targetDuration) | |||
: base(new ActionInstant[targetJumps]) | |||
{ | |||
point = tgtPoint; | |||
jumps = tgtJumps; | |||
height = tgtHeight; | |||
duration = tgtDuration; | |||
point = targetPoint; | |||
jumps = targetJumps; | |||
height = targetHeight; | |||
duration = targetDuration; | |||
} | |||
public ActionJumpBy(Vector2 tgtPoint, float tgtHeight, int tgtJumps, float tgtDuration) | |||
: this((Vector3)tgtPoint, tgtHeight, tgtJumps, tgtDuration) | |||
public ActionJumpBy(Vector2 targetPoint, float targetHeight, int targetJumps, float targetDuration) | |||
: this((Vector3)targetPoint, targetHeight, targetJumps, targetDuration) | |||
{ | |||
} | |||
public override ActionInstant clone() | |||
public override ActionInstant Clone() | |||
{ | |||
return new ActionJumpBy(point, height, jumps, duration); | |||
} | |||
public override ActionInstant reverse() | |||
public override ActionInstant Reverse() | |||
{ | |||
return new ActionJumpBy(-point, height, jumps, duration); | |||
} | |||
public override void start() | |||
public override void Start() | |||
{ | |||
float coeff = 1F / jumps; | |||
Vector3 end = point * coeff; | |||
@@ -45,7 +48,7 @@ namespace coa4u | |||
{ | |||
actions[i] = singleJump; | |||
} | |||
base.start(); | |||
base.Start(); | |||
} | |||
} | |||
} |
@@ -4,37 +4,40 @@ using UnityEngine; | |||
namespace coa4u | |||
{ | |||
/// <summary> | |||
/// Jumps to the given point for the given amount of seconds in the given amounts of jumps. | |||
/// </summary> | |||
class ActionJumpTo : ActionSequence | |||
{ | |||
protected Vector3 point; | |||
float height; | |||
int jumps; | |||
public ActionJumpTo(Vector3 tgtPoint, float tgtHeight, int tgtJumps, float tgtDuration) | |||
: base(new ActionInstant[tgtJumps]) | |||
public ActionJumpTo(Vector3 targetPoint, float targetHeight, int targetJumps, float targetDuration) | |||
: base(new ActionInstant[targetJumps]) | |||
{ | |||
point = tgtPoint; | |||
jumps = tgtJumps; | |||
height = tgtHeight; | |||
duration = tgtDuration; | |||
point = targetPoint; | |||
jumps = targetJumps; | |||
height = targetHeight; | |||
duration = targetDuration; | |||
} | |||
public ActionJumpTo(Vector2 tgtPoint, float tgtHeight, int tgtJumps, float tgtDuration) | |||
: this((Vector3)tgtPoint, tgtHeight, tgtJumps, tgtDuration) | |||
public ActionJumpTo(Vector2 targetPoint, float targetHeight, int targetJumps, float targetDuration) | |||
: this((Vector3)targetPoint, targetHeight, targetJumps, targetDuration) | |||
{ | |||
locks = Axises.z; | |||
} | |||
public override ActionInstant clone() | |||
public override ActionInstant Clone() | |||
{ | |||
return new ActionJumpTo(point, height, jumps, duration); | |||
} | |||
public override void start() | |||
public override void Start() | |||
{ | |||
float coeff = 1F / jumps; | |||
if (locks != Axises.none) | |||
lockAxises(ref point); | |||
LockAxises(ref point); | |||
Vector3 start = target.gameObject.transform.position; | |||
Vector3 end = (point - start) * coeff; | |||
Vector3 cp1 = Vector3.up * height; | |||
@@ -44,7 +47,7 @@ namespace coa4u | |||
{ | |||
actions[i] = singleJump; | |||
} | |||
base.start(); | |||
base.Start(); | |||
} | |||
} | |||
} |
@@ -4,36 +4,55 @@ using UnityEngine; | |||
namespace coa4u | |||
{ | |||
/// <summary> | |||
/// Moves in the given direction for the given amount of seconds. | |||
/// </summary> | |||
class ActionMoveBy : ActionInterval | |||
{ | |||
protected Vector3 delta; | |||
protected Vector3 referencePoint; | |||
public ActionMoveBy(Vector3 tgtDelta, float tgtDuration) | |||
: base(tgtDuration) | |||
public ActionMoveBy(Vector3 targetDelta, float targetDuration) | |||
: base(targetDuration) | |||
{ | |||
delta = tgtDelta; | |||
delta = targetDelta; | |||
} | |||
public ActionMoveBy(Vector2 tgtValue, float tgtDuration) | |||
: this((Vector3)tgtValue, tgtDuration) | |||
public ActionMoveBy(Vector2 targetValue, float targetDuration) | |||
: this((Vector3)targetValue, targetDuration) | |||
{ | |||
} | |||
public override ActionInstant clone() | |||
public ActionMoveBy(ref Vector3 refPoint, float targetDuration) | |||
: this(Vector3.zero, targetDuration) | |||
{ | |||
referencePoint = refPoint; | |||
} | |||
public override ActionInstant Clone() | |||
{ | |||
return new ActionMoveBy(delta, duration); | |||
} | |||
public override ActionInstant reverse() | |||
public override ActionInstant Reverse() | |||
{ | |||
return new ActionMoveBy(delta * -1F, duration); | |||
} | |||
public override void stepInterval(float dt) | |||
public override void Start() | |||
{ | |||
base.Start(); | |||
if (referencePoint != null) | |||
{ | |||
delta = referencePoint; | |||
} | |||
} | |||
public override void Step(float dt) | |||
{ | |||
float d = dt / duration; | |||
Vector3 tgt = delta * d; | |||
transform.Translate(tgt, Space.World); | |||
Vector3 target = delta * d; | |||
transform.Translate(target, Space.World); | |||
} | |||
} | |||
} |
@@ -4,41 +4,44 @@ using UnityEngine; | |||
namespace coa4u | |||
{ | |||
/// <summary> | |||
/// Moves to the given point for the given amount of seconds. | |||
/// </summary> | |||
class ActionMoveTo : ActionInterval | |||
{ | |||
protected Vector3 value; | |||
protected Vector3 path; | |||
public ActionMoveTo(Vector3 tgtValue, float tgtDuration) | |||
: base(tgtDuration) | |||
public ActionMoveTo(Vector3 targetValue, float targetDuration) | |||
: base(targetDuration) | |||
{ | |||
value = tgtValue; | |||
value = targetValue; | |||
} | |||
public ActionMoveTo(Vector2 tgtValue, float tgtDuration) | |||
: this((Vector3)tgtValue, tgtDuration) | |||
public ActionMoveTo(Vector2 targetValue, float targetDuration) | |||
: this((Vector3)targetValue, targetDuration) | |||
{ | |||
locks = Axises.z; | |||
} | |||
public override ActionInstant clone() | |||
public override ActionInstant Clone() | |||
{ | |||
return new ActionMoveBy(value, duration); | |||
} | |||
public override void start() | |||
public override void Start() | |||
{ | |||
base.start(); | |||
base.Start(); | |||
if (locks != Axises.none) | |||
lockAxises(ref value); | |||
LockAxises(ref value); | |||
path = value - transform.position; | |||
} | |||
public override void stepInterval(float dt) | |||
public override void Step(float dt) | |||
{ | |||
float d = dt / duration; | |||
Vector3 tgt = path * d; | |||
transform.Translate(tgt, Space.World); | |||
Vector3 target = path * d; | |||
transform.Translate(target, Space.World); | |||
} | |||
} | |||
} |
@@ -4,36 +4,39 @@ using UnityEngine; | |||
namespace coa4u | |||
{ | |||
/// <summary> | |||
/// Rotates by the given euler angles. | |||
/// </summary> | |||
class ActionRotateBy : ActionInterval | |||
{ | |||
protected Vector3 delta; | |||
public ActionRotateBy(Vector3 tgtDelta, float tgtDuration) | |||
: base(tgtDuration) | |||
public ActionRotateBy(Vector3 targetDelta, float targetDuration) | |||
: base(targetDuration) | |||
{ | |||
delta = tgtDelta; | |||
delta = targetDelta; | |||
} | |||
public ActionRotateBy(float angle, float tgtDuration) | |||
: this(new Vector3(0, 0, angle), tgtDuration) | |||
public ActionRotateBy(float angle, float targetDuration) | |||
: this(new Vector3(0, 0, angle), targetDuration) | |||
{ | |||
} | |||
public override ActionInstant clone() | |||
public override ActionInstant Clone() | |||
{ | |||
return new ActionRotateBy(delta, duration); | |||
} | |||
public override ActionInstant reverse() | |||
public override ActionInstant Reverse() | |||
{ | |||
return new ActionRotateBy(delta * -1F, duration); | |||
} | |||
public override void stepInterval(float dt) | |||
public override void Step(float dt) | |||
{ | |||
float d = dt / duration; | |||
Vector3 tgt = delta * d; | |||
transform.rotation = Quaternion.Euler(transform.rotation.eulerAngles + tgt); | |||
Vector3 target = delta * d; | |||
transform.rotation = Quaternion.Euler(transform.rotation.eulerAngles + target); | |||
} | |||
} | |||
} |
@@ -4,31 +4,34 @@ using UnityEngine; | |||
namespace coa4u | |||
{ | |||
/// <summary> | |||
/// Rotates to the given euler angles. | |||
/// </summary> | |||
class ActionRotateTo : ActionInterval | |||
{ | |||
protected Vector3 value; | |||
protected Vector3 path; | |||
public ActionRotateTo(Vector3 tgtValue, float tgtDuration) | |||
: base(tgtDuration) | |||
public ActionRotateTo(Vector3 targetValue, float targetDuration) | |||
: base(targetDuration) | |||
{ | |||
value = tgtValue; | |||
value = targetValue; | |||
} | |||
public ActionRotateTo(float angle, float tgtDuration) | |||
: this(new Vector3(0, 0, angle), tgtDuration) | |||
public ActionRotateTo(float angle, float targetDuration) | |||
: this(new Vector3(0, 0, angle), targetDuration) | |||
{ | |||
locks = Axises.xy; | |||
} | |||
public override ActionInstant clone() | |||
public override ActionInstant Clone() | |||
{ | |||
return new ActionRotateTo(value, duration); | |||
} | |||
public override void start() | |||
public override void Start() | |||
{ | |||
base.start(); | |||
base.Start(); | |||
path = new Vector3(); | |||
for (int i = 0; i < 3; i++) | |||
{ | |||
@@ -40,13 +43,13 @@ namespace coa4u | |||
path[i] = t + 360 - f; | |||
} | |||
if (locks != Axises.none) | |||
lockAxises(ref path); | |||
LockAxises(ref path); | |||
} | |||
public override void stepInterval(float dt) | |||
public override void Step(float dt) | |||
{ | |||
float d = dt / duration; | |||
Vector3 tgt = path * d; | |||
transform.rotation = Quaternion.Euler(transform.rotation.eulerAngles + tgt); | |||
Vector3 target = path * d; | |||
transform.rotation = Quaternion.Euler(transform.rotation.eulerAngles + target); | |||
} | |||
} | |||
} |
@@ -4,35 +4,38 @@ using UnityEngine; | |||
namespace coa4u | |||
{ | |||
/// <summary> | |||
/// Scales the object by the given multiplier. | |||
/// </summary> | |||
class ActionScaleBy : ActionInterval | |||
{ | |||
protected Vector3 delta; | |||
protected Vector3 path; | |||
public ActionScaleBy(Vector3 tgtDelta, float tgtDuration) | |||
: base(tgtDuration) | |||
public ActionScaleBy(Vector3 targetDelta, float targetDuration) | |||
: base(targetDuration) | |||
{ | |||
delta = tgtDelta; | |||
delta = targetDelta; | |||
} | |||
public ActionScaleBy(Vector2 tgtValue, float tgtDuration) | |||
: this((Vector3)tgtValue, tgtDuration) | |||
public ActionScaleBy(Vector2 targetValue, float targetDuration) | |||
: this((Vector3)targetValue, targetDuration) | |||
{ | |||
} | |||
public override ActionInstant clone() | |||
public override ActionInstant Clone() | |||
{ | |||
return new ActionScaleBy(delta, duration); | |||
} | |||
public override ActionInstant reverse() | |||
public override ActionInstant Reverse() | |||
{ | |||
return new ActionScaleBy(delta * -1F, duration); | |||
} | |||
public override void start() | |||
public override void Start() | |||
{ | |||
base.start(); | |||
base.Start(); | |||
Vector3 scale = transform.localScale; | |||
scale.x *= delta.x; | |||
scale.y *= delta.y; | |||
@@ -40,16 +43,16 @@ namespace coa4u | |||
path = scale - transform.localScale; | |||
} | |||
public override void stepInterval(float dt) | |||
public override void Step(float dt) | |||
{ | |||
float d = dt / duration; | |||
Vector3 tgt = path * d; | |||
transform.localScale += tgt; | |||
Vector3 target = path * d; | |||
transform.localScale += target; | |||
} | |||
public override void stop() | |||
public override void Stop() | |||
{ | |||
base.stop(); | |||
base.Stop(); | |||
} | |||
} | |||
} |
@@ -4,41 +4,44 @@ using UnityEngine; | |||
namespace coa4u | |||
{ | |||
/// <summary> | |||
/// Rotates to the given value. | |||
/// </summary> | |||
class ActionScaleTo : ActionInterval | |||
{ | |||
protected Vector3 value; | |||
protected Vector3 path; | |||
public ActionScaleTo(Vector3 tgtValue, float tgtDuration) | |||
: base(tgtDuration) | |||
public ActionScaleTo(Vector3 targetValue, float targetDuration) | |||
: base(targetDuration) | |||
{ | |||
value = tgtValue; | |||
value = targetValue; | |||
} | |||
public ActionScaleTo(Vector2 tgtValue, float tgtDuration) | |||
: this((Vector3)tgtValue, tgtDuration) | |||
public ActionScaleTo(Vector2 targetValue, float targetDuration) | |||
: this((Vector3)targetValue, targetDuration) | |||
{ | |||
locks = Axises.z; | |||
} | |||
public override ActionInstant clone() | |||
public override ActionInstant Clone() | |||
{ | |||
return new ActionScaleTo(value, duration); | |||
} | |||
public override void start() | |||
public override void Start() | |||
{ | |||
base.start(); | |||
base.Start(); | |||
if (locks != Axises.none) | |||
lockAxises(ref value); | |||
LockAxises(ref value); | |||
path = value - transform.localScale; | |||
} | |||
public override void stepInterval(float dt) | |||
public override void Step(float dt) | |||
{ | |||
float d = dt / duration; | |||
Vector3 tgt = path * d; | |||
transform.localScale += tgt; | |||
Vector3 target = path * d; | |||
transform.localScale += target; | |||
} | |||
} | |||
} |
@@ -4,45 +4,48 @@ using UnityEngine; | |||
namespace coa4u | |||
{ | |||
/// <summary> | |||
/// Skews the object by the given angles. | |||
/// </summary> | |||
class ActionSkewBy : ActionInterval | |||
{ | |||
protected Vector3 skewAngles1; | |||
protected Vector3 skewAngles2; | |||
protected Mesh mesh; | |||
public ActionSkewBy(Vector3 tgtAngles1, Vector3 tgtAngles2, float tgtDuration) | |||
: base(tgtDuration) | |||
public ActionSkewBy(Vector3 targetAngles1, Vector3 targetAngles2, float targetDuration) | |||
: base(targetDuration) | |||
{ | |||
skewAngles1 = tgtAngles1; | |||
skewAngles2 = tgtAngles2; | |||
skewAngles1 = targetAngles1; | |||
skewAngles2 = targetAngles2; | |||
} | |||
public override ActionInstant clone() | |||
public override ActionInstant Clone() | |||
{ | |||
return new ActionSkewBy(skewAngles1, skewAngles2, duration); | |||
} | |||
public override ActionInstant reverse() | |||
public override ActionInstant Reverse() | |||
{ | |||
return new ActionSkewBy(-skewAngles1, -skewAngles2, duration); | |||
} | |||
public override void start() | |||
public override void Start() | |||
{ | |||
base.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) | |||
public override void Step(float dt) | |||
{ | |||
float d = dt / duration; | |||
Vector3 tgt = skewAngles1 * d; | |||
((Actor)target).skewAngles1 += tgt; | |||
tgt = skewAngles2 * d; | |||
((Actor)target).skewAngles2 += tgt; | |||
Vector3 target = skewAngles1 * d; | |||
((Actor)target).skewAngles1 += target; | |||
target = skewAngles2 * d; | |||
((Actor)target).skewAngles2 += target; | |||
} | |||
} | |||
} |
@@ -4,42 +4,45 @@ using UnityEngine; | |||
namespace coa4u | |||
{ | |||
/// <summary> | |||
/// Tints the target by the given color value. If you're going to change alpha, target shaders should support transparency. | |||
/// </summary> | |||
class ActionTintBy : ActionInterval | |||
{ | |||
protected Vector4 color; | |||
protected const float coeff = 1F / 255F; | |||
public ActionTintBy(Vector4 tgtColor, float tgtDuration) | |||
: base(tgtDuration) | |||
public ActionTintBy(Vector4 targetColor, float targetDuration) | |||
: base(targetDuration) | |||
{ | |||
color = tgtColor * coeff; | |||
color = targetColor * coeff; | |||
} | |||
public ActionTintBy(Vector3 tgtColor, float tgtDuration) | |||
: this(new Vector4(tgtColor.x, tgtColor.y, tgtColor.z), tgtDuration) | |||
public ActionTintBy(Vector3 targetColor, float targetDuration) | |||
: this(new Vector4(targetColor.x, targetColor.y, targetColor.z), targetDuration) | |||
{ | |||
} | |||
public override ActionInstant clone() | |||
public override ActionInstant Clone() | |||
{ | |||
return new ActionTintBy(color / coeff, duration); | |||
} | |||
public override ActionInstant reverse() | |||
public override ActionInstant Reverse() | |||
{ | |||
return new ActionTintBy(-color / coeff, duration); | |||
} | |||
public override void stepInterval(float dt) | |||
public override void Step(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; | |||
Vector4 target = color * d; | |||
Color targetColor = renderer.material.color; | |||
targetColor[0] += target[0]; | |||
targetColor[1] += target[1]; | |||
targetColor[2] += target[2]; | |||
targetColor[3] += target[3]; | |||
renderer.material.color = targetColor; | |||
} | |||
} | |||
} |
@@ -4,49 +4,52 @@ using UnityEngine; | |||
namespace coa4u | |||
{ | |||
/// <summary> | |||
/// Tints the target to the given color value. If you're going to change alpha, target shaders should support transparency. | |||
/// </summary> | |||
class ActionTintTo : ActionInterval | |||
{ | |||
protected Vector4 color; | |||
protected Vector4 path; | |||
protected const float coeff = 1F / 255F; | |||
public ActionTintTo(Vector4 tgtColor, float tgtDuration) | |||
: base(tgtDuration) | |||
public ActionTintTo(Vector4 targetColor, float targetDuration) | |||
: base(targetDuration) | |||
{ | |||
color = tgtColor * coeff; | |||
color = targetColor * coeff; | |||
path = Vector4.zero; | |||
} | |||
public ActionTintTo(Vector3 tgtColor, float tgtDuration) | |||
: this(new Vector4(tgtColor.x, tgtColor.y, tgtColor.z), tgtDuration) | |||
public ActionTintTo(Vector3 targetColor, float targetDuration) | |||
: this(new Vector4(targetColor.x, targetColor.y, targetColor.z), targetDuration) | |||
{ | |||
} | |||
public override ActionInstant clone() | |||
public override ActionInstant Clone() | |||
{ | |||
return new ActionTintTo(color / coeff, duration); | |||
} | |||
public override void start() | |||
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]; | |||
base.Start(); | |||
Color targetColor = renderer.material.color; | |||
path[0] = color[0] - targetColor[0]; | |||
path[1] = color[1] - targetColor[1]; | |||
path[2] = color[2] - targetColor[2]; | |||
path[3] = color[3] - targetColor[3]; | |||
} | |||
public override void stepInterval(float dt) | |||
public override void Step(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; | |||
Vector4 target = path * d; | |||
Color targetColor = renderer.material.color; | |||
targetColor[0] += target[0]; | |||
targetColor[1] += target[1]; | |||
targetColor[2] += target[2]; | |||
targetColor[3] += target[3]; | |||
renderer.material.color = targetColor; | |||
} | |||
} | |||
} |
@@ -4,6 +4,9 @@ using UnityEngine; | |||
namespace coa4u | |||
{ | |||
/// <summary> | |||
/// The holder class for the Methods Caching. Use MethodHolder<T> if your method requires the argument of type T. | |||
/// </summary> | |||
public class MethodHolder | |||
{ | |||
protected Action method; | |||
@@ -13,13 +16,13 @@ namespace coa4u | |||
{ | |||
} | |||
public MethodHolder(Action tgtMethod) | |||
public MethodHolder(Action targetMethod) | |||
{ | |||
method = tgtMethod; | |||
methodName = tgtMethod.Method.Name; | |||
method = targetMethod; | |||
methodName = targetMethod.Method.Name; | |||
} | |||
public virtual void run(object param = null) | |||
public virtual void Run(object param = null) | |||
{ | |||
if (method != null) | |||
method.Invoke(); | |||
@@ -34,17 +37,20 @@ namespace coa4u | |||
} | |||
} | |||
/// <summary> | |||
/// The holder class for the Methods Caching. Use MethodHolder<T> if your method requires the argument of type T. | |||
/// </summary> | |||
public class MethodHolder<T> : MethodHolder | |||
{ | |||
protected Action<T> methodParam; | |||
public MethodHolder(Action<T> tgtMethod) | |||
public MethodHolder(Action<T> targetMethod) | |||
{ | |||
methodParam = tgtMethod; | |||
methodName = tgtMethod.Method.Name; | |||
methodParam = targetMethod; | |||
methodName = targetMethod.Method.Name; | |||
} | |||
public override void run(object param) | |||
public override void Run(object param) | |||
{ | |||
if (methodParam != null) | |||
methodParam.Invoke((T)param); | |||
@@ -51,15 +51,15 @@ public class Actor : MonoBehaviour | |||
if (paused || action == null) | |||
return; | |||
if (action.running) | |||
action.step(Time.deltaTime); | |||
action.StepTimer(Time.deltaTime); | |||
if (skewAngles1 != angles1prev || skewAngles2 != angles2prev) | |||
updateSkew(); | |||
UpdateSkew(); | |||
} | |||
/// <summary> | |||
/// Updates the skew for the mesh. | |||
/// </summary> | |||
void updateSkew() | |||
void UpdateSkew() | |||
{ | |||
if (meshCached == null) | |||
return; | |||
@@ -92,15 +92,15 @@ public class Actor : MonoBehaviour | |||
/// <summary> | |||
/// Attaches and starts the action. | |||
/// </summary> | |||
public void AttachAction(ActionInstant tgtAction) | |||
public void AttachAction(ActionInstant targetAction) | |||
{ | |||
if (action != null) | |||
{ | |||
action.stop(); | |||
action.Stop(); | |||
} | |||
action = tgtAction; | |||
action.setActor(this); | |||
action.start(); | |||
action = targetAction; | |||
action.SetActor(this); | |||
action.Start(); | |||
} | |||
/// <summary> | |||
@@ -111,7 +111,7 @@ public class Actor : MonoBehaviour | |||
if (action == null) | |||
return; | |||
if (action.running) | |||
action.stop(); | |||
action.Stop(); | |||
action = null; | |||
} | |||
@@ -138,7 +138,7 @@ public class Actor : MonoBehaviour | |||
{ | |||
if (action is ActionInterval) | |||
{ | |||
((ActionInterval)action).setTimeScale(ts); | |||
((ActionInterval)action).SetTimeScale(ts); | |||
} | |||
} | |||
@@ -170,15 +170,14 @@ public class Actor : MonoBehaviour | |||
} | |||
} | |||
public void ReceiveMessage(string key, object param = null, SendMessageOptions options = SendMessageOptions.DontRequireReceiver) | |||
{ | |||
if (methodsCache.ContainsKey(key)) | |||
{ | |||
if (param == null) | |||
methodsCache[key].run(); | |||
methodsCache[key].Run(); | |||
else | |||
methodsCache[key].run(param); | |||
methodsCache[key].Run(param); | |||
} | |||
else | |||
{ | |||
@@ -34,21 +34,21 @@ public class ActorSampleActions : Actor | |||
new ActionRotateTo(new Vector3(0, 0, 0), 1), | |||
new ActionFadeOut(2), | |||
new ActionSetTint(new Vector4(67, 105, 181)), | |||
new ActionSendMessage("msgHello"), | |||
new ActionSendMessage("msgHelloTo", "world"), | |||
new ActionSendMessage("MessageHello"), | |||
new ActionSendMessage("MessageHelloTo", "world"), | |||
}), 5); | |||
this.AttachAction(seq); | |||
AddMethodToCache(msgHello); | |||
AddMethodToCache<string>(msgHelloTo); | |||
AddMethodToCache(MessageHello); | |||
AddMethodToCache<string>(MessageHelloTo); | |||
} | |||
void msgHello() | |||
void MessageHello() | |||
{ | |||
Debug.Log("Hello!"); | |||
} | |||
void msgHelloTo(string who) | |||
void MessageHelloTo(string who) | |||
{ | |||
Debug.Log("Hello " + who.ToString() + "!"); | |||
} | |||