浏览代码

Added ColorAnimationHandlers + Added More types to Generic Binding Rig

/feature-generic-animation-rigs
Thomas ICHÉ 4 年前
当前提交
cd3a0355
共有 5 个文件被更改,包括 144 次插入2 次删除
  1. 25
      Runtime/Ingredients/Rigs/GenericAnimation/GenericBindingRig.cs
  2. 48
      Runtime/Ingredients/Rigs/GenericAnimation/GenericColorAnimationRig.cs
  3. 11
      Runtime/Ingredients/Rigs/GenericAnimation/GenericColorAnimationRig.cs.meta
  4. 51
      Runtime/Ingredients/Rigs/GenericAnimation/Handlers/ColorAnimationHandler.cs
  5. 11
      Runtime/Ingredients/Rigs/GenericAnimation/Handlers/ColorAnimationHandler.cs.meta

25
Runtime/Ingredients/Rigs/GenericAnimation/GenericBindingRig.cs


public class GenericBindingRig : Rig
{
public enum BindingType
{
{
Bool,
Int,
UInt,
Vector3
Vector2,
Vector3,
Vector4,
Quaternion,
Color
}
[SerializeField]
BindingType bindingType = BindingType.Float;

{
switch (bindingType)
{
case BindingType.Bool:
return typeof(bool);
case BindingType.Int:
return typeof(int);
case BindingType.UInt:
return typeof(uint);
case BindingType.Vector2:
return typeof(Vector2);
case BindingType.Vector4:
return typeof(Vector4);
case BindingType.Quaternion:
return typeof(Quaternion);
case BindingType.Color:
return typeof(Color);
default:
throw new NotImplementedException();
}

48
Runtime/Ingredients/Rigs/GenericAnimation/GenericColorAnimationRig.cs


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

11
Runtime/Ingredients/Rigs/GenericAnimation/GenericColorAnimationRig.cs.meta


fileFormatVersion: 2
guid: da33a542fba967a4cbd12450bb0b12da
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

51
Runtime/Ingredients/Rigs/GenericAnimation/Handlers/ColorAnimationHandler.cs


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

11
Runtime/Ingredients/Rigs/GenericAnimation/Handlers/ColorAnimationHandler.cs.meta


fileFormatVersion: 2
guid: 623206cf60ca5ac44a99bceeda298282
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存