[UnityEditor.Callbacks.DidReloadScripts()]

作者:追风剑情 发布于:2018-4-10 14:37 分类:Unity3d

示例

  1. using UnityEngine;
  2. using UnityEditor;
  3. using System.Collections;
  4.  
  5. public class TestEditor {
  6.  
  7. //监听脚本编译完成
  8. [UnityEditor.Callbacks.DidReloadScripts()]
  9. static void OnScriptReload()
  10. {
  11. Debug.Log("OnScriptReload()");
  12. //监听播放状态
  13. EditorApplication.playmodeStateChanged -= OnPlaymodeStateChanged;
  14. EditorApplication.playmodeStateChanged += OnPlaymodeStateChanged;
  15. }
  16.  
  17. [UnityEditor.Callbacks.DidReloadScripts(1)]
  18. static void OnScriptReload1()
  19. {
  20. Debug.Log("OnScriptReload1() ");
  21. }
  22.  
  23. static void OnPlaymodeStateChanged()
  24. {
  25. Debug.Log(string.Format("isPlaying={0}, isPlayingOrWillChangePlaymode={1}",
  26. UnityEngine.Application.isPlaying, EditorApplication.isPlayingOrWillChangePlaymode));
  27.  
  28. if (UnityEngine.Application.isPlaying && EditorApplication.isPlayingOrWillChangePlaymode)
  29. {
  30. }
  31. }
  32. }

编译完成并运行

11111.jpg

停止运行

2222.jpg

标签: Unity3d

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号