2D support

This commit is contained in:
2014-06-19 23:03:18 +04:00
parent 1d69dfd8f3
commit 06e25ca6c7
16 changed files with 121 additions and 23 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -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;
}

View File

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

View File

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

View File

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

View File

@@ -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();
}
}