Unity --- OnValidate 和 ExecuteInEditMode

 1 using UnityEngine;
 2 
 3 [ExecuteInEditMode]  //添加脚本、启动、Stop的时候执行Awake()  Start()
 4 public class test : MonoBehaviour
 5 {
 6     [SerializeField]
 7     int val;
 8     void Awake()
 9     {
10         Debug.Log("Awake()");
11     }
12 
13     void Start()
14     {
15         Debug.Log("Start()");
16     }
17  
18 #if UNITY_EDITOR
19     //启动的时候执行两次,Stop的时候执行一次,组件数值改变的时候执行一次
20     void OnValidate()
21     {
22         Debug.Log("OnValidate()");
23     }
24 #endif
25 
26 }
原文地址:https://www.cnblogs.com/luguoshuai/p/10611190.html