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 }

 

posted @ 2019-03-27 21:55  小·糊涂仙  阅读(2703)  评论(0编辑  收藏  举报