本项目演示如何创建自己的顶点动画着色器。场景不使用任何纹理或动画资源,所有内容都使用Shader Graph进行着色和动画处理。
您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 

51 行
1.3 KiB

using UnityEngine;
using System.Collections;
namespace TMPro.Examples
{
public class ShaderPropAnimator : MonoBehaviour
{
private Renderer m_Renderer;
private Material m_Material;
public AnimationCurve GlowCurve;
public float m_frame;
void Awake()
{
// Cache a reference to object's renderer
m_Renderer = GetComponent<Renderer>();
// Cache a reference to object's material and create an instance by doing so.
m_Material = m_Renderer.material;
}
void Start()
{
StartCoroutine(AnimateProperties());
}
IEnumerator AnimateProperties()
{
//float lightAngle;
float glowPower;
m_frame = Random.Range(0f, 1f);
while (true)
{
//lightAngle = (m_Material.GetFloat(ShaderPropertyIDs.ID_LightAngle) + Time.deltaTime) % 6.2831853f;
//m_Material.SetFloat(ShaderPropertyIDs.ID_LightAngle, lightAngle);
glowPower = GlowCurve.Evaluate(m_frame);
m_Material.SetFloat(ShaderUtilities.ID_GlowPower, glowPower);
m_frame += Time.deltaTime * Random.Range(0.2f, 0.3f);
yield return new WaitForEndOfFrame();
}
}
}
}