GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • Chat2DB
  • 我的博客
  • 我的园子
  • 账号设置
  • 会员中心
  • 注册

This view

  • Original page
  • New address

GeezerVison is showing www.cnblogs.com — Unity 侦听进入播放模式、Unity加载时初始化编辑器类 - kingBook - 博客园

kingBook

导航

  • 新随笔
  • 管理

Unity 侦听进入播放模式、Unity加载时初始化编辑器类

"Editor"文件夹下的PlayModeStateChangedHandler.cs

using UnityEngine;
using UnityEditor;
//允许在 Unity 加载时初始化编辑器类,无需用户操作。
[InitializeOnLoadAttribute]
public static class PlayModeStateChangedHandler{
	
	//初始化类时,注册事件处理函数
	static PlayModeStateChangedHandler(){
		EditorApplication.playModeStateChanged+=OnPlayerModeStateChanged;
	}

	private static void OnPlayerModeStateChanged(PlayModeStateChange playModeState){
		Debug.LogFormat("state:{0} will:{1} isPlaying:{2}",playModeState,EditorApplication.isPlayingOrWillChangePlaymode,EditorApplication.isPlaying);
	}
	//当点"Play"按钮进入播放模式时
	//输出:
	//state:ExitingEditMode will:True isPlaying:False
	//state:EnteredPlayMode will:True isPlaying:True
}

posted on 2020-01-07 12:14  kingBook  阅读(837)  评论(0)    收藏  举报

刷新页面返回顶部
You are visitor 01402605 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.