minor fixes in ActionTintBy.cs

new actions:
ActionFadeBy.cs
ActionTintTo.cs
This commit is contained in:
2014-06-17 01:52:31 +04:00
committed by Ivan "KaiSD" Korystin
parent 41e0072a15
commit 0b4d17f8df
5 changed files with 107 additions and 11 deletions

View File

@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using UnityEngine;
class ActionFadeBy : ActionInterval
{
public float delta;
public ActionFadeBy(float tgtDelta, float tgtDuration)
: base(tgtDuration)
{
delta = tgtDelta;
}
public override Action clone()
{
return new ActionFadeBy(delta, duration);
}
public override Action reverse()
{
return new ActionFadeBy(-delta, duration);
}
public override void start()
{
base.start();
}
public override void stepInterval(float dt)
{
float d = dt / duration;
Color tgtColor = target.gameObject.renderer.material.color;
tgtColor[3] += delta * d;
target.gameObject.renderer.material.color = tgtColor;
}
}

View File

@@ -13,6 +13,11 @@ class ActionTintBy : ActionInterval
color = tgtColor * coeff;
}
public ActionTintBy(Vector3 tgtColor, float tgtDuration)
: this(new Vector4(tgtColor.x, tgtColor.y, tgtColor.z), tgtDuration)
{
}
public override Action clone()
{
return new ActionTintBy(color / coeff, duration);

View File

@@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using UnityEngine;
class ActionTintTo : ActionInterval
{
public Vector4 color;
public Vector4 path;
protected const float coeff = 1F / 255F;
public ActionTintTo(Vector4 tgtColor, float tgtDuration)
: base(tgtDuration)
{
color = tgtColor * coeff;
path = Vector4.zero;
}
public ActionTintTo(Vector3 tgtColor, float tgtDuration)
: this(new Vector4(tgtColor.x, tgtColor.y, tgtColor.z), tgtDuration)
{
}
public override Action clone()
{
return new ActionTintTo(color / coeff, duration);
}
public override void start()
{
base.start();
Color tgtColor = target.gameObject.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];
}
public override void stepInterval(float dt)
{
float d = dt / duration;
Vector4 tgt = path * 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;
}
}

View File

@@ -7,14 +7,16 @@ public class SampleActions : MonoBehaviour
{
Action seq = new ActionRepeat (new ActionSequence(new Action[]
{
new ActionTintBy(new Vector4(-50,50,-50,-50),1),
new ActionParallel(new Action[] {
new ActionMoveBy(new Vector3(10, 0, 0), 1),
new ActionMoveBy(new Vector3(0, 10, 0), 1),
// new ActionRotateBy(new Vector3(90, 0, 0), 1)
new ActionRotateBy(new Vector3(90, 0, 0), 1),
new ActionTintBy(new Vector4(-50, 50, -150, 0), 1)
}),
new ActionScaleBy(new Vector3(2, 2, 1), 1),
new ActionScaleBy(new Vector3(0.5F, 0.5F, 2), 1),
new ActionFadeBy(-1F, 2),
new ActionFadeBy(1F, 2),
new ActionDelay(1),
new ActionRepeat(new ActionSequence(new Action[] {
new ActionHide(),
@@ -28,7 +30,7 @@ public class SampleActions : MonoBehaviour
new ActionMoveTo(new Vector3(0, 0, 10), 1),
new ActionScaleTo(new Vector3(2, 2, 2), 1),
new ActionRotateTo(new Vector3(0, 0, 0), 1),
new ActionTintBy(new Vector4(50,-50,50,50),3)
new ActionTintTo(new Vector4(67, 105, 181, 255),3)
}), 5);
gameObject.SendMessage("AttachAction", seq);
}