2020-09-28 20:35:40 +08:00
|
|
|
|
using UnityEngine;
|
2020-08-20 03:42:16 +08:00
|
|
|
|
|
|
|
|
|
namespace Coffee.UIExtensions
|
|
|
|
|
{
|
|
|
|
|
[System.Serializable]
|
|
|
|
|
public class AnimatableProperty : ISerializationCallbackReceiver
|
|
|
|
|
{
|
|
|
|
|
public enum ShaderPropertyType
|
|
|
|
|
{
|
|
|
|
|
Color,
|
|
|
|
|
Vector,
|
|
|
|
|
Float,
|
|
|
|
|
Range,
|
|
|
|
|
Texture,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[SerializeField] string m_Name = "";
|
|
|
|
|
[SerializeField] ShaderPropertyType m_Type = ShaderPropertyType.Vector;
|
|
|
|
|
public int id { get; private set; }
|
|
|
|
|
|
|
|
|
|
public ShaderPropertyType type
|
|
|
|
|
{
|
|
|
|
|
get { return m_Type; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void UpdateMaterialProperties(Material material, MaterialPropertyBlock mpb)
|
|
|
|
|
{
|
2020-08-29 02:55:46 +08:00
|
|
|
|
if (!material.HasProperty(id)) return;
|
|
|
|
|
|
2020-08-20 03:42:16 +08:00
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
case ShaderPropertyType.Color:
|
2020-08-29 02:55:46 +08:00
|
|
|
|
var color = mpb.GetColor(id);
|
|
|
|
|
if (color != default(Color))
|
|
|
|
|
material.SetColor(id, color);
|
2020-08-20 03:42:16 +08:00
|
|
|
|
break;
|
|
|
|
|
case ShaderPropertyType.Vector:
|
2020-08-29 02:55:46 +08:00
|
|
|
|
var vector = mpb.GetVector(id);
|
|
|
|
|
if (vector != default(Vector4))
|
|
|
|
|
material.SetVector(id, vector);
|
2020-08-20 03:42:16 +08:00
|
|
|
|
break;
|
|
|
|
|
case ShaderPropertyType.Float:
|
|
|
|
|
case ShaderPropertyType.Range:
|
2020-08-29 02:55:46 +08:00
|
|
|
|
var value = mpb.GetFloat(id);
|
|
|
|
|
if (value != default(float))
|
|
|
|
|
material.SetFloat(id, value);
|
2020-08-20 03:42:16 +08:00
|
|
|
|
break;
|
|
|
|
|
case ShaderPropertyType.Texture:
|
2020-08-29 02:55:46 +08:00
|
|
|
|
var tex = mpb.GetTexture(id);
|
|
|
|
|
if (tex != default(Texture))
|
|
|
|
|
material.SetTexture(id, tex);
|
2020-08-20 03:42:16 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnBeforeSerialize()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnAfterDeserialize()
|
|
|
|
|
{
|
|
|
|
|
id = Shader.PropertyToID(m_Name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|