using UnityEngine; using System.Collections.Generic; namespace Lean.Transition.Method { /// This component allows you to transition the specified Material's vector to the target value. [HelpURL(LeanTransition.HelpUrlPrefix + "LeanMaterialVector")] [AddComponentMenu(LeanTransition.MethodsMenuPrefix + "Material/Material vector" + LeanTransition.MethodsMenuSuffix + "(LeanMaterialVector)")] public class LeanMaterialVector : LeanMethodWithStateAndTarget { public override System.Type GetTargetType() { return typeof(Material); } public override void Register() { PreviousState = Register(GetAliasedTarget(Data.Target), Data.Property, Data.Value, Data.Duration, Data.Ease); } public static LeanState Register(Material target, string property, Vector4 value, float duration, LeanEase ease = LeanEase.Smooth) { var state = LeanTransition.SpawnWithTarget(State.Pool, target); state.Property = property; state.Value = value; state.Ease = ease; return LeanTransition.Register(state, duration); } [System.Serializable] public class State : LeanStateWithTarget { [Tooltip("The name of the vector property in the shader.")] public string Property; [Tooltip("The value we will transition to.")] public Vector4 Value; [Tooltip("The ease method that will be used for the transition.")] public LeanEase Ease = LeanEase.Smooth; [System.NonSerialized] private Vector4 oldValue; public override int CanFill { get { return Target != null && Target.GetVector(Property) != Value ? 1 : 0; } } public override void FillWithTarget() { Value = Target.GetVector(Property); } public override void BeginWithTarget() { oldValue = Target.GetVector(Property); } public override void UpdateWithTarget(float progress) { Target.SetVector(Property, Vector4.LerpUnclamped(oldValue, Value, Smooth(Ease, progress))); } public static Stack Pool = new Stack(); public override void Despawn() { Pool.Push(this); } } public State Data; } } namespace Lean.Transition { public static partial class LeanExtensions { public static Material vectorTransition(this Material target, string property, Vector4 value, float duration, LeanEase ease = LeanEase.Smooth) { Method.LeanMaterialVector.Register(target, property, value, duration, ease); return target; } } }