minor fixes in ActionTintBy.cs
new actions: ActionFadeBy.cs ActionTintTo.cs
This commit is contained in:
37
src/ActionsInterval/ActionFadeBy.cs
Normal file
37
src/ActionsInterval/ActionFadeBy.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
49
src/ActionsInterval/ActionTintTo.cs
Normal file
49
src/ActionsInterval/ActionTintTo.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user