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 }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM