浏览代码
Added ColorAnimationHandlers + Added More types to Generic Binding Rig
/feature-generic-animation-rigs
Added ColorAnimationHandlers + Added More types to Generic Binding Rig
/feature-generic-animation-rigs
Thomas ICHÉ
4 年前
当前提交
cd3a0355
共有 5 个文件被更改,包括 144 次插入 和 2 次删除
-
25Runtime/Ingredients/Rigs/GenericAnimation/GenericBindingRig.cs
-
48Runtime/Ingredients/Rigs/GenericAnimation/GenericColorAnimationRig.cs
-
11Runtime/Ingredients/Rigs/GenericAnimation/GenericColorAnimationRig.cs.meta
-
51Runtime/Ingredients/Rigs/GenericAnimation/Handlers/ColorAnimationHandler.cs
-
11Runtime/Ingredients/Rigs/GenericAnimation/Handlers/ColorAnimationHandler.cs.meta
|
|||
using NaughtyAttributes; |
|||
using System; |
|||
using UnityEngine; |
|||
|
|||
namespace GameplayIngredients.Rigs |
|||
{ |
|||
public class GenericColorAnimationRig : GenericAnimationRig |
|||
{ |
|||
[Header("Base Value")] |
|||
[SerializeField] |
|||
bool useStoredValueAsBase = true; |
|||
[SerializeField, DisableIf("useStoredValueAsBase")] |
|||
Color baseValue = Color.white; |
|||
|
|||
[Header("Animation")] |
|||
[SerializeReference, HandlerType(typeof(Color))] |
|||
public ColorAnimationHandler animationHandler = new ColorGradientAnimationHandler(); |
|||
|
|||
public override Type animatedType => typeof(Color); |
|||
|
|||
private void Awake() |
|||
{ |
|||
if (useStoredValueAsBase) |
|||
baseValue = (Color)property.GetValue(); |
|||
} |
|||
|
|||
protected override void OnEnable() |
|||
{ |
|||
base.OnEnable(); |
|||
animationHandler?.OnStart(baseValue); |
|||
} |
|||
|
|||
protected override object UpdateAndGetValue(float deltaTime) |
|||
{ |
|||
if (animationHandler != null) |
|||
{ |
|||
return animationHandler.OnUpdate(deltaTime); |
|||
} |
|||
else |
|||
{ |
|||
Debug.LogWarning("Float Animation Rig has no Animation Handler", this); |
|||
return baseValue; |
|||
} |
|||
|
|||
} |
|||
} |
|||
} |
|||
|
|
|||
fileFormatVersion: 2 |
|||
guid: da33a542fba967a4cbd12450bb0b12da |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using UnityEngine; |
|||
|
|||
namespace GameplayIngredients.Rigs |
|||
{ |
|||
[Serializable] |
|||
public abstract class ColorAnimationHandler : AnimationHandler<Color> { } |
|||
|
|||
[Serializable, AnimationHandler("Color Gradient", typeof(Color))] |
|||
public class ColorGradientAnimationHandler : ColorAnimationHandler |
|||
{ |
|||
static Gradient defaultGradient { |
|||
get |
|||
{ |
|||
var c = new Gradient(); |
|||
c.SetKeys(new GradientColorKey[] |
|||
{ |
|||
new GradientColorKey(Color.red, .0f), |
|||
new GradientColorKey(Color.yellow, .16666f), |
|||
new GradientColorKey(Color.green, .33333f), |
|||
new GradientColorKey(Color.cyan, .5f), |
|||
new GradientColorKey(Color.blue, .6666666f), |
|||
new GradientColorKey(Color.magenta, .833333f), |
|||
new GradientColorKey(Color.red, .1f) |
|||
}, |
|||
new GradientAlphaKey[] { new GradientAlphaKey(1, 0), new GradientAlphaKey(1, 1) }); |
|||
return c; |
|||
} |
|||
} |
|||
|
|||
[SerializeField] |
|||
Gradient gradient = defaultGradient; |
|||
[SerializeField] |
|||
float blendSourceColor = 0f; |
|||
|
|||
Color m_Base; |
|||
float m_Time; |
|||
|
|||
public override void OnStart(Color defaultValue) |
|||
{ |
|||
m_Base = defaultValue; |
|||
m_Time = 0; |
|||
} |
|||
|
|||
public override Color OnUpdate(float deltaTime) |
|||
{ |
|||
m_Time += deltaTime; |
|||
return Color.Lerp(gradient.Evaluate(m_Time), m_Base, blendSourceColor); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 623206cf60ca5ac44a99bceeda298282 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue