编辑器是否处于播放模式。
如果编辑器处于播放模式,则返回 true。设置 isPlaying 会延迟结果,直到此帧的所有脚本代码都完成为止。如果编辑器已暂停,则此值也返回 true。
其他资源:isPaused,isPlayingOrWillChangePlaymode。
using UnityEngine; using UnityEditor;
// The following is a simple example where EditorApplication.isPlaying is watched to // report whether the Editor is in Play mode.
public class EditorPlaying : EditorWindow { [MenuItem("Examples/EditorApplication.isPlaying demo")] static void Init() { EditorWindow window = GetWindow(typeof(EditorPlaying)); window.position = new Rect(100, 100, 150, 50); window.Show(); }
void OnGUI() { if (EditorApplication.isPlaying) { EditorGUILayout.LabelField("Playing"); } else { EditorGUILayout.LabelField("Not playing"); } } }