第一章方式:
函数前面 + [ContextMenu("Play")] ,Inspector面板右键调用
第二种方式:
OnValidate() ,值改变自动执行
using UnityEngine;
using System.Linq;public class NightController : MonoBehaviour
{public float m_fEmissionInstensity = 0;public Material[] m_NightMats;// Start is called before the first frame updatevoid OnValidate(){m_NightMats.ToList().ForEach(_ =>{_.SetFloat("_Emission_Intensity", m_fEmissionInstensity);});}[ContextMenu("Play")]void Play(){m_NightMats.ToList().ForEach(_ =>{_.SetFloat("_Emission_Intensity", m_fEmissionInstensity);});}
}