initial
This commit is contained in:
32
src/ActionsInterval/ActionDelay.cs
Normal file
32
src/ActionsInterval/ActionDelay.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
class ActionDelay : ActionInterval
|
||||
{
|
||||
protected float durationMin;
|
||||
protected float durationMax;
|
||||
|
||||
public ActionDelay(float tgtDuration)
|
||||
: base(tgtDuration)
|
||||
{
|
||||
durationMin = tgtDuration;
|
||||
durationMax = tgtDuration;
|
||||
}
|
||||
|
||||
public ActionDelay(float tgtDuration, float tgtDurationMax)
|
||||
: base(tgtDuration)
|
||||
{
|
||||
durationMin = tgtDuration;
|
||||
durationMax = tgtDurationMax;
|
||||
}
|
||||
|
||||
public override void start()
|
||||
{
|
||||
base.start();
|
||||
if (durationMax != null)
|
||||
{
|
||||
duration = UnityEngine.Random.Range(durationMin, durationMax);
|
||||
}
|
||||
}
|
||||
}
|
||||
31
src/ActionsInterval/ActionMoveBy.cs
Normal file
31
src/ActionsInterval/ActionMoveBy.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
class ActionMoveBy : ActionInterval
|
||||
{
|
||||
protected Vector3 delta;
|
||||
|
||||
public ActionMoveBy(Vector3 tgtDelta, float tgtDuration)
|
||||
: base(tgtDuration)
|
||||
{
|
||||
delta = tgtDelta;
|
||||
}
|
||||
|
||||
public override Action clone()
|
||||
{
|
||||
return new ActionMoveBy(delta, duration);
|
||||
}
|
||||
|
||||
public override Action reverse()
|
||||
{
|
||||
return new ActionMoveBy(delta * -1F, duration);
|
||||
}
|
||||
|
||||
public override void stepInterval(float dt)
|
||||
{
|
||||
float d = dt / duration;
|
||||
Vector3 tgt = delta * d;
|
||||
target.gameObject.transform.Translate(tgt, Space.World);
|
||||
}
|
||||
}
|
||||
34
src/ActionsInterval/ActionMoveTo.cs
Normal file
34
src/ActionsInterval/ActionMoveTo.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
class ActionMoveTo : ActionInterval
|
||||
{
|
||||
protected Vector3 value;
|
||||
protected Vector3 path;
|
||||
|
||||
public ActionMoveTo(Vector3 tgtValue, float tgtDuration)
|
||||
: base(tgtDuration)
|
||||
{
|
||||
value = tgtValue;
|
||||
}
|
||||
|
||||
|
||||
public override Action clone()
|
||||
{
|
||||
return new ActionMoveBy(value, duration);
|
||||
}
|
||||
|
||||
public override void start()
|
||||
{
|
||||
base.start();
|
||||
path = value - target.gameObject.transform.position;
|
||||
}
|
||||
|
||||
public override void stepInterval(float dt)
|
||||
{
|
||||
float d = dt / duration;
|
||||
Vector3 tgt = path * d;
|
||||
target.gameObject.transform.Translate(tgt, Space.World);
|
||||
}
|
||||
}
|
||||
33
src/ActionsInterval/ActionRotateBy.cs
Normal file
33
src/ActionsInterval/ActionRotateBy.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
class ActionRotateBy : ActionInterval
|
||||
{
|
||||
protected Vector3 delta;
|
||||
|
||||
public ActionRotateBy(Vector3 tgtDelta, float tgtDuration)
|
||||
: base(tgtDuration)
|
||||
{
|
||||
delta = tgtDelta;
|
||||
}
|
||||
|
||||
public override Action clone()
|
||||
{
|
||||
return new ActionRotateBy(delta, duration);
|
||||
}
|
||||
|
||||
public override Action reverse()
|
||||
{
|
||||
return new ActionRotateBy(delta * -1F, duration);
|
||||
}
|
||||
|
||||
public override void stepInterval(float dt)
|
||||
{
|
||||
float d = dt / duration;
|
||||
Vector3 tgt = delta * d;
|
||||
target.gameObject.transform.Rotate(Vector3.up, tgt.y);
|
||||
target.gameObject.transform.Rotate(Vector3.right, tgt.x);
|
||||
target.gameObject.transform.Rotate(Vector3.forward, tgt.z);
|
||||
}
|
||||
}
|
||||
43
src/ActionsInterval/ActionRotateTo.cs
Normal file
43
src/ActionsInterval/ActionRotateTo.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
class ActionRotateTo : ActionInterval
|
||||
{
|
||||
protected Vector3 value;
|
||||
protected Vector3 path;
|
||||
|
||||
public ActionRotateTo(Vector3 tgtValue, float tgtDuration)
|
||||
: base(tgtDuration)
|
||||
{
|
||||
value = tgtValue;
|
||||
}
|
||||
|
||||
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++)
|
||||
{
|
||||
float t = value[i];
|
||||
float f = target.gameObject.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;
|
||||
target.gameObject.transform.Rotate(Vector3.up, tgt.y);
|
||||
target.gameObject.transform.Rotate(Vector3.right, tgt.x);
|
||||
target.gameObject.transform.Rotate(Vector3.forward, tgt.z);
|
||||
}
|
||||
}
|
||||
47
src/ActionsInterval/ActionScaleBy.cs
Normal file
47
src/ActionsInterval/ActionScaleBy.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
class ActionScaleBy : ActionInterval
|
||||
{
|
||||
protected Vector3 delta;
|
||||
protected Vector3 path;
|
||||
|
||||
public ActionScaleBy(Vector3 tgtDelta, float tgtDuration)
|
||||
: base(tgtDuration)
|
||||
{
|
||||
delta = tgtDelta;
|
||||
}
|
||||
|
||||
public override Action clone()
|
||||
{
|
||||
return new ActionScaleBy(delta, duration);
|
||||
}
|
||||
|
||||
public override Action reverse()
|
||||
{
|
||||
return new ActionScaleBy(delta * -1F, duration);
|
||||
}
|
||||
|
||||
public override void start()
|
||||
{
|
||||
base.start();
|
||||
Vector3 scale = target.gameObject.transform.localScale;
|
||||
scale.x *= delta.x;
|
||||
scale.y *= delta.y;
|
||||
scale.z *= delta.z;
|
||||
path = scale - target.gameObject.transform.localScale;
|
||||
}
|
||||
|
||||
public override void stepInterval(float dt)
|
||||
{
|
||||
float d = dt / duration;
|
||||
Vector3 tgt = path * d;
|
||||
target.gameObject.transform.localScale += tgt;
|
||||
}
|
||||
|
||||
public override void stop()
|
||||
{
|
||||
base.stop();
|
||||
}
|
||||
}
|
||||
38
src/ActionsInterval/ActionScaleTo.cs
Normal file
38
src/ActionsInterval/ActionScaleTo.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
class ActionScaleTo : ActionInterval
|
||||
{
|
||||
protected Vector3 value;
|
||||
protected Vector3 path;
|
||||
|
||||
public ActionScaleTo(Vector3 tgtValue, float tgtDuration)
|
||||
: base(tgtDuration)
|
||||
{
|
||||
value = tgtValue;
|
||||
}
|
||||
|
||||
public override Action clone()
|
||||
{
|
||||
return new ActionScaleTo(value, duration);
|
||||
}
|
||||
|
||||
public override void start()
|
||||
{
|
||||
base.start();
|
||||
path = value - target.gameObject.transform.localScale;
|
||||
}
|
||||
|
||||
public override void stepInterval(float dt)
|
||||
{
|
||||
float d = dt / duration;
|
||||
Vector3 tgt = path * d;
|
||||
target.gameObject.transform.localScale += tgt;
|
||||
}
|
||||
|
||||
public override void stop()
|
||||
{
|
||||
base.stop();
|
||||
}
|
||||
}
|
||||
37
src/ActionsInterval/ActionTintBy.cs
Normal file
37
src/ActionsInterval/ActionTintBy.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
class ActionTintBy : ActionInterval
|
||||
{
|
||||
public Vector4 color;
|
||||
protected const float coeff = 1F / 255F;
|
||||
|
||||
public ActionTintBy(Vector4 tgtColor, float tgtDuration)
|
||||
: base(tgtDuration)
|
||||
{
|
||||
color = tgtColor * coeff;
|
||||
}
|
||||
|
||||
public override Action clone()
|
||||
{
|
||||
return new ActionTintBy(color / coeff, duration);
|
||||
}
|
||||
|
||||
public override Action reverse()
|
||||
{
|
||||
return new ActionTintBy(-color / coeff, duration);
|
||||
}
|
||||
|
||||
public override void stepInterval(float dt)
|
||||
{
|
||||
float d = dt / duration;
|
||||
Vector4 tgt = color * d;
|
||||
Color tgtColor = target.gameObject.renderer.material.color;
|
||||
tgtColor[0] += tgt[0];
|
||||
tgtColor[1] += tgt[1];
|
||||
tgtColor[2] += tgt[2];
|
||||
tgtColor[3] += tgt[3];
|
||||
target.gameObject.renderer.material.color = tgtColor;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user