[UnityEditor.Callbacks.DidReloadScripts()]

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

示例

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

标签: Unity3d

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号