之前美术同学在做UI界面的动画
效果的时候遇到了 材质参数不可key动画的问题,我就简单帮忙写了小脚本~ 做个小记录
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[ExecuteInEditMode]
public class AniUImove : MonoBehaviour
{
public Material[] materials;
[SerializeField]
private float m_Offsetx;
[SerializeField]
private float m_Offsety;
private float m_TempOffsetx;
private float m_TempOffsety;
private void Start()
{
Renderer renderer = gameObject.GetComponentInChildren<Renderer>(true);
if (renderer != null)
materials = renderer.sharedMaterials;
}
void Update()
{
if (m_TempOffsetx != m_Offsetx || m_TempOffsety != m_Offsety)
{
if (materials != null && materials.Length > 0)
{
for (int i = 0; i < materials.Length; i++)
{
Material mat = materials[i];
mat.SetTextureOffset("_MainTex", new Vector2(m_Offsetx, m_Offsety));
}
}
m_TempOffsetx = m_Offsetx;
m_TempOffsety = m_Offsety;
}
}
}