瀏覽代碼

2D support

master
父節點
當前提交
06e25ca6c7
共有 16 個檔案被更改,包括 121 行新增23 行删除
  1. +1
    -2
      README.md
  2. +1
    -0
      src/ActionsBase/Action.cs
  3. +12
    -4
      src/ActionsInstant/ActionSetPlace.cs
  4. +6
    -0
      src/ActionsInstant/ActionSetRotation.cs
  5. +19
    -0
      src/ActionsInterval/ActionBezierAbs.cs
  6. +6
    -0
      src/ActionsInterval/ActionBezierRel.cs
  7. +21
    -4
      src/ActionsInterval/ActionBlink.cs
  8. +6
    -0
      src/ActionsInterval/ActionJumpBy.cs
  9. +8
    -0
      src/ActionsInterval/ActionJumpTo.cs
  10. +6
    -0
      src/ActionsInterval/ActionMoveBy.cs
  11. +7
    -0
      src/ActionsInterval/ActionMoveTo.cs
  12. +6
    -0
      src/ActionsInterval/ActionRotateBy.cs
  13. +6
    -0
      src/ActionsInterval/ActionRotateTo.cs
  14. +6
    -0
      src/ActionsInterval/ActionScaleBy.cs
  15. +8
    -5
      src/ActionsInterval/ActionScaleTo.cs
  16. +2
    -8
      src/Examples/SampleActions.cs

+ 1
- 2
README.md 查看文件

@@ -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.

### Included actions (ready and WIP)
All actions are designed to word in 3D scene (i.e. using Vector3 for movement, rotation and scaling).
You can use it in 2D with apropriate vectors, but i'm going to add support for 2D actions soon.
All actions are capable to work both in 3D (use Vector3) and 2D (use Vector2) scenes.

Base actions
- [x] Sequence


+ 1
- 0
src/ActionsBase/Action.cs 查看文件

@@ -8,6 +8,7 @@ public class Action
public float duration = 0;
protected Transform transform;
protected Renderer renderer;
protected bool is2d = false;

public Action()
{


+ 12
- 4
src/ActionsInstant/ActionSetPlace.cs 查看文件

@@ -4,22 +4,30 @@ using UnityEngine;

class ActionSetPlace : Action
{
protected Vector3 place;
protected Vector3 value;

public ActionSetPlace(Vector3 tgtPlace)
: base()
{
place = tgtPlace;
value = tgtPlace;
}

public ActionSetPlace(Vector2 tgtPlace)
: this((Vector3) tgtPlace)
{
is2d = true;
}

public override Action clone()
{
return new ActionSetPlace(place);
return new ActionSetPlace(value);
}

public override void start()
{
base.start();
transform.position = place;
if (is2d)
value.z = transform.position.z;
transform.position = value;
}
}

+ 6
- 0
src/ActionsInstant/ActionSetRotation.cs 查看文件

@@ -12,6 +12,12 @@ class ActionSetRotation : Action
value = tgtValue;
}

public ActionSetRotation(float angle)
: this(new Vector3(0, 0, angle))
{
is2d = true;
}

public override Action clone()
{
return new ActionSetRotation(value);


+ 19
- 0
src/ActionsInterval/ActionBezierAbs.cs 查看文件

@@ -18,6 +18,12 @@ class ActionBezierAbs : ActionInterval
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()
{
return new ActionBezierAbs(startPoint, startControlPoint, endControlPoint, endPoint, duration);
@@ -28,6 +34,19 @@ class ActionBezierAbs : ActionInterval
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)
{
float t = timer / duration;


+ 6
- 0
src/ActionsInterval/ActionBezierRel.cs 查看文件

@@ -20,6 +20,12 @@ class ActionBezierRel : ActionInterval
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()
{
return new ActionBezierRel(startControlPoint, endControlPoint, endPoint, duration);


+ 21
- 4
src/ActionsInterval/ActionBlink.cs 查看文件

@@ -7,11 +7,14 @@ class ActionBlink : ActionRepeat
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, tgtBlinks)
: base(null, 0)
{
duration = tgtDuration;
durationMin = tgtDuration;
durationMax = tgtDuration;
count = (tgtBlinks) * 2;
blinkSeq = new Action[]
{
@@ -21,13 +24,27 @@ class ActionBlink : ActionRepeat
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()
{
return new ActionBlink(count / 2 - 1, duration);
return new ActionBlink(count / 2 - 1, durationMin, durationMax);
}

public override Action reverse()
{
return new ActionBlink(count / 2 - 1, duration);
return new ActionBlink(count / 2 - 1, durationMin, durationMax);
}
}

+ 6
- 0
src/ActionsInterval/ActionJumpBy.cs 查看文件

@@ -17,6 +17,12 @@ class ActionJumpBy : ActionSequence
duration = tgtDuration;
}

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);


+ 8
- 0
src/ActionsInterval/ActionJumpTo.cs 查看文件

@@ -17,6 +17,12 @@ class ActionJumpTo : ActionSequence
duration = tgtDuration;
}

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);
@@ -25,6 +31,8 @@ class ActionJumpTo : ActionSequence
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;


+ 6
- 0
src/ActionsInterval/ActionMoveBy.cs 查看文件

@@ -12,6 +12,12 @@ class ActionMoveBy : ActionInterval
delta = tgtDelta;
}

public ActionMoveBy(Vector2 tgtValue, float tgtDuration)
: this((Vector3) tgtValue, tgtDuration)
{
is2d = true;
}

public override Action clone()
{
return new ActionMoveBy(delta, duration);


+ 7
- 0
src/ActionsInterval/ActionMoveTo.cs 查看文件

@@ -13,6 +13,11 @@ class ActionMoveTo : ActionInterval
value = tgtValue;
}

public ActionMoveTo(Vector2 tgtValue, float tgtDuration)
: this((Vector3) tgtValue, tgtDuration)
{
is2d = true;
}

public override Action clone()
{
@@ -22,6 +27,8 @@ class ActionMoveTo : ActionInterval
public override void start()
{
base.start();
if (is2d)
value.z = transform.position.z;
path = value - transform.position;
}



+ 6
- 0
src/ActionsInterval/ActionRotateBy.cs 查看文件

@@ -12,6 +12,12 @@ class ActionRotateBy : ActionInterval
delta = tgtDelta;
}

public ActionRotateBy(float angle, float tgtDuration)
: this(new Vector3(0, 0, angle), tgtDuration)
{
is2d = true;
}

public override Action clone()
{
return new ActionRotateBy(delta, duration);


+ 6
- 0
src/ActionsInterval/ActionRotateTo.cs 查看文件

@@ -13,6 +13,12 @@ class ActionRotateTo : ActionInterval
value = tgtValue;
}

public ActionRotateTo(float angle, float tgtDuration)
: this(new Vector3(0, 0, angle), tgtDuration)
{
is2d = true;
}

public override Action clone()
{
return new ActionRotateTo(value, duration);


+ 6
- 0
src/ActionsInterval/ActionScaleBy.cs 查看文件

@@ -13,6 +13,12 @@ class ActionScaleBy : ActionInterval
delta = tgtDelta;
}

public ActionScaleBy(Vector2 tgtValue, float tgtDuration)
: this((Vector3)tgtValue, tgtDuration)
{
is2d = true;
}

public override Action clone()
{
return new ActionScaleBy(delta, duration);


+ 8
- 5
src/ActionsInterval/ActionScaleTo.cs 查看文件

@@ -13,6 +13,12 @@ class ActionScaleTo : ActionInterval
value = tgtValue;
}

public ActionScaleTo(Vector2 tgtValue, float tgtDuration)
: this((Vector3) tgtValue, tgtDuration)
{
is2d = true;
}

public override Action clone()
{
return new ActionScaleTo(value, duration);
@@ -21,6 +27,8 @@ class ActionScaleTo : ActionInterval
public override void start()
{
base.start();
if (is2d)
value.z = transform.localScale.z;
path = value - transform.localScale;
}

@@ -30,9 +38,4 @@ class ActionScaleTo : ActionInterval
Vector3 tgt = path * d;
transform.localScale += tgt;
}

public override void stop()
{
base.stop();
}
}

+ 2
- 8
src/Examples/SampleActions.cs 查看文件

@@ -16,21 +16,15 @@ public class SampleActions : MonoBehaviour
new ActionScaleBy(new Vector3(2, 2, 1), 1),
new ActionScaleBy(new Vector3(0.5F, 0.5F, 2), 1),
new ActionDelay(1),
new ActionRepeat(new ActionSequence(new Action[] {
new ActionHide(),
new ActionDelay(0F, 0.2F),
new ActionShow(),
new ActionDelay(0F, 0.2F),
}), 5),
new ActionBlink(5, 0.1F, 0.4F),
new ActionDelay(1),
new ActionJumpBy(new Vector3(-10, 0, 0), 1, 4, 1),
new ActionJumpTo(new Vector3(10, 10, 10), 1, 3, 1),
new ActionJumpBy(new Vector3(-10, 0, 0), 1, 2, 1),
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 ActionRotateTo(new Vector3(0, 0, 0), 1),
new ActionBlink(2, 1),
new ActionFadeOut(2),
new ActionSetTint(new Vector4(67, 105, 181))
}), 5);