2D support
This commit is contained in:
@@ -16,8 +16,7 @@ See the examples folder, there's a sample script there.
|
|||||||
You can also subclass the Actor and add all the actions you want to the Start() method.
|
You can also subclass the Actor and add all the actions you want to the Start() method.
|
||||||
|
|
||||||
### Included actions (ready and WIP)
|
### Included actions (ready and WIP)
|
||||||
All actions are designed to word in 3D scene (i.e. using Vector3 for movement, rotation and scaling).
|
All actions are capable to work both in 3D (use Vector3) and 2D (use Vector2) scenes.
|
||||||
You can use it in 2D with apropriate vectors, but i'm going to add support for 2D actions soon.
|
|
||||||
|
|
||||||
Base actions
|
Base actions
|
||||||
- [x] Sequence
|
- [x] Sequence
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ public class Action
|
|||||||
public float duration = 0;
|
public float duration = 0;
|
||||||
protected Transform transform;
|
protected Transform transform;
|
||||||
protected Renderer renderer;
|
protected Renderer renderer;
|
||||||
|
protected bool is2d = false;
|
||||||
|
|
||||||
public Action()
|
public Action()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,22 +4,30 @@ using UnityEngine;
|
|||||||
|
|
||||||
class ActionSetPlace : Action
|
class ActionSetPlace : Action
|
||||||
{
|
{
|
||||||
protected Vector3 place;
|
protected Vector3 value;
|
||||||
|
|
||||||
public ActionSetPlace(Vector3 tgtPlace)
|
public ActionSetPlace(Vector3 tgtPlace)
|
||||||
: base()
|
: base()
|
||||||
{
|
{
|
||||||
place = tgtPlace;
|
value = tgtPlace;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ActionSetPlace(Vector2 tgtPlace)
|
||||||
|
: this((Vector3) tgtPlace)
|
||||||
|
{
|
||||||
|
is2d = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Action clone()
|
public override Action clone()
|
||||||
{
|
{
|
||||||
return new ActionSetPlace(place);
|
return new ActionSetPlace(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void start()
|
public override void start()
|
||||||
{
|
{
|
||||||
base.start();
|
base.start();
|
||||||
transform.position = place;
|
if (is2d)
|
||||||
|
value.z = transform.position.z;
|
||||||
|
transform.position = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -12,6 +12,12 @@ class ActionSetRotation : Action
|
|||||||
value = tgtValue;
|
value = tgtValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ActionSetRotation(float angle)
|
||||||
|
: this(new Vector3(0, 0, angle))
|
||||||
|
{
|
||||||
|
is2d = true;
|
||||||
|
}
|
||||||
|
|
||||||
public override Action clone()
|
public override Action clone()
|
||||||
{
|
{
|
||||||
return new ActionSetRotation(value);
|
return new ActionSetRotation(value);
|
||||||
|
|||||||
@@ -18,6 +18,12 @@ class ActionBezierAbs : ActionInterval
|
|||||||
endControlPoint = tgtECP;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
public override Action clone()
|
public override Action clone()
|
||||||
{
|
{
|
||||||
return new ActionBezierAbs(startPoint, startControlPoint, endControlPoint, endPoint, duration);
|
return new ActionBezierAbs(startPoint, startControlPoint, endControlPoint, endPoint, duration);
|
||||||
@@ -28,6 +34,19 @@ class ActionBezierAbs : ActionInterval
|
|||||||
return new ActionBezierAbs(endPoint, endControlPoint, startControlPoint, startPoint, duration);
|
return new ActionBezierAbs(endPoint, endControlPoint, startControlPoint, startPoint, duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public override void stepInterval(float dt)
|
public override void stepInterval(float dt)
|
||||||
{
|
{
|
||||||
float t = timer / duration;
|
float t = timer / duration;
|
||||||
|
|||||||
@@ -20,6 +20,12 @@ class ActionBezierRel : ActionInterval
|
|||||||
cp2 = tgtECP;
|
cp2 = tgtECP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ActionBezierRel(Vector2 tgtSCP, Vector2 tgtECP, Vector2 tgtEnd, float tgtDuration)
|
||||||
|
: this((Vector3)tgtSCP, (Vector3)tgtECP, (Vector3)tgtEnd, tgtDuration)
|
||||||
|
{
|
||||||
|
is2d = true;
|
||||||
|
}
|
||||||
|
|
||||||
public override Action clone()
|
public override Action clone()
|
||||||
{
|
{
|
||||||
return new ActionBezierRel(startControlPoint, endControlPoint, endPoint, duration);
|
return new ActionBezierRel(startControlPoint, endControlPoint, endPoint, duration);
|
||||||
|
|||||||
@@ -7,11 +7,14 @@ class ActionBlink : ActionRepeat
|
|||||||
protected bool randomDelay;
|
protected bool randomDelay;
|
||||||
protected ActionDelay delay = new ActionDelay(0);
|
protected ActionDelay delay = new ActionDelay(0);
|
||||||
protected Action[] blinkSeq;
|
protected Action[] blinkSeq;
|
||||||
|
protected float durationMin;
|
||||||
|
protected float durationMax;
|
||||||
|
|
||||||
public ActionBlink(int tgtBlinks, float tgtDuration)
|
public ActionBlink(int tgtBlinks, float tgtDuration)
|
||||||
: base(null, tgtBlinks)
|
: base(null, 0)
|
||||||
{
|
{
|
||||||
duration = tgtDuration;
|
durationMin = tgtDuration;
|
||||||
|
durationMax = tgtDuration;
|
||||||
count = (tgtBlinks) * 2;
|
count = (tgtBlinks) * 2;
|
||||||
blinkSeq = new Action[]
|
blinkSeq = new Action[]
|
||||||
{
|
{
|
||||||
@@ -21,13 +24,27 @@ class ActionBlink : ActionRepeat
|
|||||||
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[]
|
||||||
|
{
|
||||||
|
new ActionToggleVisibility(),
|
||||||
|
new ActionDelay(tgtDurationMin / tgtBlinks, tgtDurationMax / tgtBlinks)
|
||||||
|
};
|
||||||
|
action = new ActionSequence(blinkSeq);
|
||||||
|
}
|
||||||
|
|
||||||
public override Action clone()
|
public override Action clone()
|
||||||
{
|
{
|
||||||
return new ActionBlink(count / 2 - 1, duration);
|
return new ActionBlink(count / 2 - 1, durationMin, durationMax);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Action reverse()
|
public override Action reverse()
|
||||||
{
|
{
|
||||||
return new ActionBlink(count / 2 - 1, duration);
|
return new ActionBlink(count / 2 - 1, durationMin, durationMax);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -17,6 +17,12 @@ class ActionJumpBy : ActionSequence
|
|||||||
duration = tgtDuration;
|
duration = tgtDuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ActionJumpBy(Vector2 tgtPoint, float tgtHeight, int tgtJumps, float tgtDuration)
|
||||||
|
: this((Vector3)tgtPoint, tgtHeight, tgtJumps, tgtDuration)
|
||||||
|
{
|
||||||
|
is2d = true;
|
||||||
|
}
|
||||||
|
|
||||||
public override Action clone()
|
public override Action clone()
|
||||||
{
|
{
|
||||||
return new ActionJumpBy(point, height, jumps, duration);
|
return new ActionJumpBy(point, height, jumps, duration);
|
||||||
|
|||||||
@@ -17,6 +17,12 @@ class ActionJumpTo : ActionSequence
|
|||||||
duration = tgtDuration;
|
duration = tgtDuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ActionJumpTo(Vector2 tgtPoint, float tgtHeight, int tgtJumps, float tgtDuration)
|
||||||
|
: this((Vector3)tgtPoint, tgtHeight, tgtJumps, tgtDuration)
|
||||||
|
{
|
||||||
|
is2d = true;
|
||||||
|
}
|
||||||
|
|
||||||
public override Action clone()
|
public override Action clone()
|
||||||
{
|
{
|
||||||
return new ActionJumpTo(point, height, jumps, duration);
|
return new ActionJumpTo(point, height, jumps, duration);
|
||||||
@@ -25,6 +31,8 @@ class ActionJumpTo : ActionSequence
|
|||||||
public override void start()
|
public override void start()
|
||||||
{
|
{
|
||||||
float coeff = 1F / jumps;
|
float coeff = 1F / jumps;
|
||||||
|
if (is2d)
|
||||||
|
point.z = transform.position.z;
|
||||||
Vector3 start = target.gameObject.transform.position;
|
Vector3 start = target.gameObject.transform.position;
|
||||||
Vector3 end = (point - start) * coeff;
|
Vector3 end = (point - start) * coeff;
|
||||||
Vector3 cp1 = Vector3.up * height;
|
Vector3 cp1 = Vector3.up * height;
|
||||||
|
|||||||
@@ -12,6 +12,12 @@ class ActionMoveBy : ActionInterval
|
|||||||
delta = tgtDelta;
|
delta = tgtDelta;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ActionMoveBy(Vector2 tgtValue, float tgtDuration)
|
||||||
|
: this((Vector3) tgtValue, tgtDuration)
|
||||||
|
{
|
||||||
|
is2d = true;
|
||||||
|
}
|
||||||
|
|
||||||
public override Action clone()
|
public override Action clone()
|
||||||
{
|
{
|
||||||
return new ActionMoveBy(delta, duration);
|
return new ActionMoveBy(delta, duration);
|
||||||
|
|||||||
@@ -13,6 +13,11 @@ class ActionMoveTo : ActionInterval
|
|||||||
value = tgtValue;
|
value = tgtValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ActionMoveTo(Vector2 tgtValue, float tgtDuration)
|
||||||
|
: this((Vector3) tgtValue, tgtDuration)
|
||||||
|
{
|
||||||
|
is2d = true;
|
||||||
|
}
|
||||||
|
|
||||||
public override Action clone()
|
public override Action clone()
|
||||||
{
|
{
|
||||||
@@ -22,6 +27,8 @@ class ActionMoveTo : ActionInterval
|
|||||||
public override void start()
|
public override void start()
|
||||||
{
|
{
|
||||||
base.start();
|
base.start();
|
||||||
|
if (is2d)
|
||||||
|
value.z = transform.position.z;
|
||||||
path = value - transform.position;
|
path = value - transform.position;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,12 @@ class ActionRotateBy : ActionInterval
|
|||||||
delta = tgtDelta;
|
delta = tgtDelta;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ActionRotateBy(float angle, float tgtDuration)
|
||||||
|
: this(new Vector3(0, 0, angle), tgtDuration)
|
||||||
|
{
|
||||||
|
is2d = true;
|
||||||
|
}
|
||||||
|
|
||||||
public override Action clone()
|
public override Action clone()
|
||||||
{
|
{
|
||||||
return new ActionRotateBy(delta, duration);
|
return new ActionRotateBy(delta, duration);
|
||||||
|
|||||||
@@ -13,6 +13,12 @@ class ActionRotateTo : ActionInterval
|
|||||||
value = tgtValue;
|
value = tgtValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ActionRotateTo(float angle, float tgtDuration)
|
||||||
|
: this(new Vector3(0, 0, angle), tgtDuration)
|
||||||
|
{
|
||||||
|
is2d = true;
|
||||||
|
}
|
||||||
|
|
||||||
public override Action clone()
|
public override Action clone()
|
||||||
{
|
{
|
||||||
return new ActionRotateTo(value, duration);
|
return new ActionRotateTo(value, duration);
|
||||||
|
|||||||
@@ -13,6 +13,12 @@ class ActionScaleBy : ActionInterval
|
|||||||
delta = tgtDelta;
|
delta = tgtDelta;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ActionScaleBy(Vector2 tgtValue, float tgtDuration)
|
||||||
|
: this((Vector3)tgtValue, tgtDuration)
|
||||||
|
{
|
||||||
|
is2d = true;
|
||||||
|
}
|
||||||
|
|
||||||
public override Action clone()
|
public override Action clone()
|
||||||
{
|
{
|
||||||
return new ActionScaleBy(delta, duration);
|
return new ActionScaleBy(delta, duration);
|
||||||
|
|||||||
@@ -13,6 +13,12 @@ class ActionScaleTo : ActionInterval
|
|||||||
value = tgtValue;
|
value = tgtValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ActionScaleTo(Vector2 tgtValue, float tgtDuration)
|
||||||
|
: this((Vector3) tgtValue, tgtDuration)
|
||||||
|
{
|
||||||
|
is2d = true;
|
||||||
|
}
|
||||||
|
|
||||||
public override Action clone()
|
public override Action clone()
|
||||||
{
|
{
|
||||||
return new ActionScaleTo(value, duration);
|
return new ActionScaleTo(value, duration);
|
||||||
@@ -21,6 +27,8 @@ class ActionScaleTo : ActionInterval
|
|||||||
public override void start()
|
public override void start()
|
||||||
{
|
{
|
||||||
base.start();
|
base.start();
|
||||||
|
if (is2d)
|
||||||
|
value.z = transform.localScale.z;
|
||||||
path = value - transform.localScale;
|
path = value - transform.localScale;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,9 +38,4 @@ class ActionScaleTo : ActionInterval
|
|||||||
Vector3 tgt = path * d;
|
Vector3 tgt = path * d;
|
||||||
transform.localScale += tgt;
|
transform.localScale += tgt;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void stop()
|
|
||||||
{
|
|
||||||
base.stop();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -16,21 +16,15 @@ public class SampleActions : MonoBehaviour
|
|||||||
new ActionScaleBy(new Vector3(2, 2, 1), 1),
|
new ActionScaleBy(new Vector3(2, 2, 1), 1),
|
||||||
new ActionScaleBy(new Vector3(0.5F, 0.5F, 2), 1),
|
new ActionScaleBy(new Vector3(0.5F, 0.5F, 2), 1),
|
||||||
new ActionDelay(1),
|
new ActionDelay(1),
|
||||||
new ActionRepeat(new ActionSequence(new Action[] {
|
new ActionBlink(5, 0.1F, 0.4F),
|
||||||
new ActionHide(),
|
|
||||||
new ActionDelay(0F, 0.2F),
|
|
||||||
new ActionShow(),
|
|
||||||
new ActionDelay(0F, 0.2F),
|
|
||||||
}), 5),
|
|
||||||
new ActionDelay(1),
|
new ActionDelay(1),
|
||||||
new ActionJumpBy(new Vector3(-10, 0, 0), 1, 4, 1),
|
new ActionJumpBy(new Vector3(-10, 0, 0), 1, 4, 1),
|
||||||
new ActionJumpTo(new Vector3(10, 10, 10), 1, 3, 1),
|
new ActionJumpTo(new Vector3(10, 10, 10), 1, 3, 1),
|
||||||
new ActionJumpBy(new Vector3(-10, 0, 0), 1, 2, 1),
|
new ActionJumpBy(new Vector3(-10, 0, 0), 1, 2, 1),
|
||||||
new ActionDelay(0.5F),
|
new ActionDelay(0.5F),
|
||||||
new ActionBezierRel(new Vector3 (5, 0, 0), new Vector3(5, -10, 0), new Vector3 (0, -10, 0), 2),
|
new ActionBezierRel(new Vector2 (5, 0), new Vector2(5, -10), new Vector2 (0, -10), 2),
|
||||||
new ActionScaleTo(new Vector3(2, 2, 2), 1),
|
new ActionScaleTo(new Vector3(2, 2, 2), 1),
|
||||||
new ActionRotateTo(new Vector3(0, 0, 0), 1),
|
new ActionRotateTo(new Vector3(0, 0, 0), 1),
|
||||||
new ActionBlink(2, 1),
|
|
||||||
new ActionFadeOut(2),
|
new ActionFadeOut(2),
|
||||||
new ActionSetTint(new Vector4(67, 105, 181))
|
new ActionSetTint(new Vector4(67, 105, 181))
|
||||||
}), 5);
|
}), 5);
|
||||||
|
|||||||
Reference in New Issue
Block a user