鸟语天空
[UnityEditor.Callbacks.DidReloadScripts()]
post by:追风剑情 2018-4-10 14:37

示例

using UnityEngine;
using UnityEditor;
using System.Collections;

public class TestEditor {

    //监听脚本编译完成
    [UnityEditor.Callbacks.DidReloadScripts()]
    static void OnScriptReload()
    {
        Debug.Log("OnScriptReload()");
        //监听播放状态
        EditorApplication.playmodeStateChanged -= OnPlaymodeStateChanged;
        EditorApplication.playmodeStateChanged += OnPlaymodeStateChanged;
    }

    [UnityEditor.Callbacks.DidReloadScripts(1)]
    static void OnScriptReload1()
    {
        Debug.Log("OnScriptReload1() ");
    }

    static void OnPlaymodeStateChanged()
    {
        Debug.Log(string.Format("isPlaying={0}, isPlayingOrWillChangePlaymode={1}",
            UnityEngine.Application.isPlaying, EditorApplication.isPlayingOrWillChangePlaymode));

        if (UnityEngine.Application.isPlaying && EditorApplication.isPlayingOrWillChangePlaymode)
        {
            
        }
    }
}

编译完成并运行

11111.jpg

停止运行

2222.jpg

评论:
发表评论:
昵称

邮件地址 (选填)

个人主页 (选填)

内容