Esempio n. 1
0
        /// <summary>
        /// Creates a GUICallback component if it not exists.
        /// </summary>
        void CreateGUICallbackIfNotExist()
        {
            #if UNITY_EDITOR
            if (!Application.isPlaying)
            {
                return;
            }
            #endif

            if (m_GUICallback == null)
            {
                #if UNITY_EDITOR
                if (Application.isEditor)
                {
                    // Delay the GUICallback creation in editor to avoid the Unity GUISkin bug.
                    StartCoroutine(DelayedCreateGUICallback());
                }
                else
                {
                    m_GUICallback       = gameObject.AddComponent <GUICallback>();
                    s_CreateGUICallback = false;
                }
                #else
                m_GUICallback       = gameObject.AddComponent <GUICallback>();
                s_CreateGUICallback = false;
                #endif
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Called only in the editor to create a GUICallback in the next frame.
        /// </summary>
        IEnumerator DelayedCreateGUICallback()
        {
            yield return(null);

            if (m_GUICallback == null)
            {
                m_GUICallback       = gameObject.AddComponent <GUICallback>();
                s_CreateGUICallback = false;
            }
        }
Esempio n. 3
0
 /// <summary>
 /// A Unity callback called when the object is loaded.
 /// </summary>
 void OnEnable()
 {
     // Destroys the new gui callback
     if (s_Instance != null && s_Instance != this)
     {
         #if UNITY_EDITOR
         if (!Application.isPlaying)
         {
             DestroyImmediate(s_Instance.gameObject, true);
         }
         else
         {
             Destroy(s_Instance.gameObject);
         }
         #else
         Destroy(s_Instance.gameObject);
         #endif
     }
     else
     {
         // Set instance
         s_Instance = this;
     }
 }
Esempio n. 4
0
        /// <summary>
        /// Unity callback called when playmode changes. 
        /// Un-/Registered in the OnDisable/OnEnable. 
        /// Updates the m_PlayModeState member and the activeParent.
        /// Creates or destroy the guiCallback.
        /// </summary>
        void OnPlaymodeChange () {

            // Update playmode
            if (EditorApplication.isPlaying)
                m_PlayModeState = !EditorApplication.isPlayingOrWillChangePlaymode ? PlayModeState.SwitchingToEditor : PlayModeState.Playing;
            else
                m_PlayModeState = EditorApplication.isPlayingOrWillChangePlaymode ? PlayModeState.SwitchingToPlaymode : PlayModeState.Editor;

            // if (/*!EditorApplication.isPaused &&*/ (EditorApplication.isPlayingOrWillChangePlaymode && EditorApplication.isPlaying || !EditorApplication.isPlayingOrWillChangePlaymode && !EditorApplication.isPlaying)) {
            if (m_PlayModeState == PlayModeState.Playing || m_PlayModeState == PlayModeState.Editor) {
                var parentID = m_SerializedParentID;
                activeParent = null;
                activeParent = EditorUtility.InstanceIDToObject(parentID) as ParentBehaviour;
                GUIUtility.hotControl = 0;
                GUIUtility.keyboardControl = 0;
            }

            // Create guiCallback?
            if (m_PlayModeState == PlayModeState.SwitchingToEditor && m_GUICallback == null) {
                m_GUICallback = this.CreateGUICallback();
            }
            // Destroy guiCallback?
            else if (m_PlayModeState == PlayModeState.SwitchingToPlaymode && m_GUICallback != null) {
                DestroyImmediate(m_GUICallback.gameObject, true);
            }
        }
Esempio n. 5
0
 /// <summary>
 /// Unity callback called after compilation.
 /// Un-/Registered in the OnDisable/OnEnable. 
 /// Recreates guiCallback if the Unity is in the editor mode.
 /// </summary>
 void OnDelayCall () {
     switch (m_PlayModeState) {
         case PlayModeState.Editor:
             if (m_GUICallback == null)
                 m_GUICallback = this.CreateGUICallback();
             break;
     }
 }
Esempio n. 6
0
        /// <summary>
        /// A Unity callback called when the window is loaded.
        /// </summary>
        void OnEnable () {
            // Set window name
            this.name = Print.GetLogo() + " Behaviour";
            // Update singleton instance
            Instance = this;

            // Update NotVisible value
            BehaviourWindow.s_NotVisible = this.m_NotVisible;

            // Set playmode state
            if (m_PlayModeState == PlayModeState.Unknow) {
                m_PlayModeState = EditorApplication.isPlaying ? PlayModeState.Playing : PlayModeState.Editor;

                // The guiCallback is null and the unity application is not playing or changing playmode?
                if (m_GUICallback == null && !EditorApplication.isPlayingOrWillChangePlaymode) {
                    // Create game object
                    GameObject go = EditorUtility.CreateGameObjectWithHideFlags("GUI Object", HideFlags.HideAndDontSave, new System.Type[] {typeof(GUICallback)});
                    // Get GUICallback component
                    m_GUICallback = go.GetComponent<GUICallback>();
                }
            }

            // Set callbacks
            activeParentChanged += OnParentSelectionChange;
            activeNodeChanged += OnNodeSelectionChange;
            EditorApplication.playmodeStateChanged += OnPlaymodeChange;
            EditorApplication.delayCall += OnDelayCall;
            LoadSceneUtility.onLoadScene += this.OnLoadScene;
            BehaviourMachinePrefs.preferencesChanged += this.Repaint;

            // The minimum size of this window
            base.minSize = new Vector2(200f, 150f);

            // Forces selection update
            activeParent = EditorUtility.InstanceIDToObject(m_SerializedParentID) as ParentBehaviour;
            OnSelectionChange();
            activeNodeID = m_SerializedNodeID;

            // Set guiController
            SetParentGUI();

            // Automatically repaint window whenever the scene has change
            base.autoRepaintOnSceneChange = true;
        }
Esempio n. 7
0
 /// <summary> 
 /// A Unity callback called when the object is loaded.
 /// </summary>
 void OnEnable () {
     // Destroys the new gui callback
     if (s_Instance != null && s_Instance != this) {
         #if UNITY_EDITOR
         if (!Application.isPlaying)
             DestroyImmediate(s_Instance.gameObject, true);
         else
             Destroy(s_Instance.gameObject);
         #else
         Destroy(s_Instance.gameObject);
         #endif
     }
     else {
         // Set instance
         s_Instance = this;
     }
 }
 /// <summary>
 /// Called only in the editor to create a GUICallback in the next frame.
 /// </summary> 
 IEnumerator DelayedCreateGUICallback () {
     yield return null;
     if (m_GUICallback == null) {
     	m_GUICallback = gameObject.AddComponent<GUICallback>();
         s_CreateGUICallback = false;
     }
 }
		/// <summary>
        /// Creates a GUICallback component if it not exists.
        /// </summary> 
		void CreateGUICallbackIfNotExist () {
            #if UNITY_EDITOR
            if (!Application.isPlaying)
                return;
            #endif

            if (m_GUICallback == null) {
                #if UNITY_EDITOR
            	if (Application.isEditor) {
            	   // Delay the GUICallback creation in editor to avoid the Unity GUISkin bug.
            	   StartCoroutine(DelayedCreateGUICallback());
                }
            	else {
                    m_GUICallback = gameObject.AddComponent<GUICallback>();
                    s_CreateGUICallback = false;
                }
                #else
                m_GUICallback = gameObject.AddComponent<GUICallback>();
                s_CreateGUICallback = false;
                #endif
            }
		}