예제 #1
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);
            }
        }
예제 #2
0
        void CheckAllFiles(GUICallback callback = null)
        {
            // The shared context for all script analysis.
            var analysisContext = new Yarn.Analysis.Context();

            // We shouldn't try to perform program analysis if
            // any of the files fails to compile, because that
            // analysis would be performed on incomplete data.
            bool shouldPerformAnalysis = true;

            // How many files have we finished checking?
            int complete = 0;

            // Let's get started!

            // First, ensure that we're looking at all of the scripts.
            UpdateYarnScriptList();

            // Next, compile each one.
            foreach (var result in checkResults)
            {
                // Attempt to compile the file. Record any compiler messages.
                CheckerResult.State state;

                var messages = ValidateFile(result.script, analysisContext, out state);

                result.state    = state;
                result.messages = messages;

                // Don't perform whole-program analysis if any file failed to compile
                if (result.state != CheckerResult.State.Passed)
                {
                    shouldPerformAnalysis = false;
                }

                // We're done with it; if we have a callback to call after
                // each file is validated, do so.
                complete++;

                if (callback != null)
                {
                    callback(complete, checkResults.Count);
                }
            }

            var results = new List <Yarn.Analysis.Diagnosis>();

            if (shouldPerformAnalysis)
            {
                var scriptAnalyses = analysisContext.FinishAnalysis();
                results.AddRange(scriptAnalyses);
            }


            var environmentAnalyses = AnalyseEnvironment();

            results.AddRange(environmentAnalyses);

            diagnoses = results;
        }
예제 #3
0
 /// </summary>
 /// Register OnGUI node in editor mode.
 /// </summary>
 void RegisterEditorOnGUI()
 {
     if (!EditorApplication.isPlayingOrWillChangePlaymode)
     {
         if (m_ActionState.onGUINode != null && ((m_ActionState.isRoot && BehaviourWindow.activeState == null) || m_ActionState == BehaviourWindow.activeState))
         {
             GUICallback.ResetCallbacks();
             GUICallback.onGUI += m_ActionState.onGUINode.EditorOnTick;
         }
     }
 }
예제 #4
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;
     }
 }
예제 #5
0
    /// <summary>
    /// Creates the GUI dialog to show
    /// </summary>
    /// <param name='callback'>
    /// Callback. when intialize is over
    /// </param>
    /// <param name='style'>
    /// Style.
    /// </param>
    /// <param name='_dele'>
    /// _dele function callback when dialog confirm button is clicked
    /// </param>
    public void CreateGUIDialog(GUICallback <GUIDialog> callback, EDialogStyle style, GUIDialog.ConfirmDelegate _dele = null)
    {
        CreateWindow <GUIDialog>(delegate(GUIDialog gui){
            gui.InitializeGUI(style);
            gui.SetConfirmBtnDelegate(_dele);

            if (callback != null)
            {
                callback(gui);
            }
        });
    }
예제 #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;
        }
예제 #7
0
        /// <summary>
        /// A Unity callback called when the object goes out of scope.
        /// </summary>
        private void OnDisable()
        {
            BehaviourWindow.activeNodeChanged -= this.ActiveNodeChanged;

            // Unregister the callback for visual debugging
            ActionNode.onNodeTick -= OnNodeTick;

            // Register Update
            if (Application.isPlaying)
            {
                EditorApplication.update -= this.Update;
            }
            else
            {
                GUICallback.ResetCallbacks();
            }
        }
예제 #8
0
    /// <summary>
    /// Creates the window.
    /// </summary>
    /// <returns>
    /// return true if the window create otherwise false because creating or created
    /// </returns>
    /// <param name='callback'>
    /// If set to <c>true</c> callback.
    /// </param>
    /// <typeparam name='T'>
    /// the window type (GUIWindow's child class)
    /// </typeparam>
    public bool CreateWindow <T>(GUICallback <T> callback) where T : GUIWindow
    {
        if (_mTempWindowList.IndexOf(typeof(T)) != -1)
        {
            return(false);
        }

        T ui = GetGUIWindow <T>();

        if (null != ui)
        {
            if (null != callback)
            {
                callback(ui);
            }

            return(false);
        }
        _mTempWindowList.Add(typeof(T));

        CreateGUIWindow <T>
            (typeof(T).Name, false,
            delegate(T gui)
        {
            _mTempWindowList.Remove(typeof(T));

            gui.InitializeGUI();

            if (null != callback)
            {
                callback(gui);
            }
        }
            );

        return(true);
    }
예제 #9
0
 public ModalDialogue(string question, GUICallback yesCallback, GUICallback noCallback)
 {
     this.Question = question;
     this.YesCallback = yesCallback;
     this.NoCallback = noCallback;
 }
 public ModalDialogue(string question, GUICallback yesCallback, GUICallback noCallback)
 {
     this.Question    = question;
     this.YesCallback = yesCallback;
     this.NoCallback  = noCallback;
 }
예제 #11
0
        /// <summary>
        /// Unity callback to draw a custom inspector.
        /// </summary>
        public override void OnInspectorGUI()
        {
            // Create styles?
            if (s_Styles == null)
            {
                s_Styles = new InternalActionStateEditor.Styles();
            }

            // Workaround to update nodes
            if (Event.current.type == EventType.ValidateCommand && Event.current.commandName == "UndoRedoPerformed")
            {
                GUIUtility.hotControl      = 0;
                GUIUtility.keyboardControl = 0;
                m_ActionState.LoadNodes();
                UpdateActiveNode();
                return;
            }

            // Reload nodes?
            if (m_ActionState.isDirty)
            {
                m_ActionState.LoadNodes();
                UpdateActiveNode();
            }

            // Register OnGUI node?
            if (!Application.isPlaying && m_ActionState.onGUINode != null && !GUICallback.HasCallbacks())
            {
                this.RegisterEditorOnGUI();
            }

            #if UNITY_4_0_0 || UNITY_4_1 || UNITY_4_2
            EditorGUIUtility.LookLikeInspector();
            #endif

            // Draw default inspector
            DrawDefaultInspector();

            // Shows the node editor?
            bool showNodeEditor = m_ActionState.parent == null || BehaviourWindow.activeState == m_ActionState;

            // Draw Action List
            if (m_NodeList == null)
            {
                // m_NodeList = new ReorderableList(this.serializedObject, this.serializedObject.FindProperty("m_UpdateActions"));
                m_NodeList = new ReorderableList(m_ActionState.GetNodes(), typeof(ActionNode));
                m_NodeList.drawHeaderCallback  += delegate(Rect rect) { EditorGUI.LabelField(rect, "Nodes"); };
                m_NodeList.drawElementCallback += DrawNode;
                m_NodeList.onAddCallback       += this.OnAddNode;
                m_NodeList.onRemoveCallback    += this.OnRemoveSelectedNode;
                m_NodeList.onSelectCallback    += this.OnSelectNode;
                m_NodeList.onReorderCallback   += this.OnReorderNode;

                // Select the active node
                UpdateActiveNode();

                #if !UNITY_4_0_0 && !UNITY_4_1 && !UNITY_4_2 && !UNITY_4_3
                m_NodeList.list = m_ActionState.GetNodes();
                m_NodeList.DoLayoutList();
                #else
                this.Repaint();
                #endif
            }
            else if (showNodeEditor)
            {
                m_NodeList.list = m_ActionState.GetNodes();
                m_NodeList.DoLayoutList();
            }

            if (showNodeEditor)
            {
                GUILayout.Space(6f);

                #if UNITY_4_0_0 || UNITY_4_1 || UNITY_4_2
                EditorGUIUtility.LookLikeControls();
                #endif

                // Get the active node
                ActionNode activeNode = m_ActionState.isRoot ? this.GetActiveNode() : BehaviourWindow.activeNode;

                // Draw node properties
                if (m_NodeEditor != null)
                {
                    // Is there an active node?
                    if (activeNode != null && activeNode.owner as InternalActionState == m_ActionState)
                    {
                        // It's an Update node
                        var oldGUIEnabled = GUI.enabled;
                        GUI.enabled = !(activeNode is Update);
                        m_NodeEditor.DrawNode(activeNode);
                        GUI.enabled = oldGUIEnabled;
                        GUILayout.Space(4f);
                    }
                }


                // Copy/Paste/Cut/Duplicate/Delete keyboard shortcuts
                Event current = Event.current;
                if (current.type == EventType.ValidateCommand)
                {
                    // Use event to call event ExecuteCommand
                    if (current.commandName == "Paste")
                    {
                        ActionNode[] nodesToPaste = ActionStateUtility.GetActionsAndConditions(BehaviourTreeUtility.nodeToPaste != null ? new ActionNode[] { BehaviourTreeUtility.nodeToPaste } : new ActionNode[0]);
                        if (nodesToPaste.Length > 0)
                        {
                            current.Use();
                        }
                    }
                    if (activeNode != null)
                    {
                        if (current.commandName == "Copy")
                        {
                            current.Use();
                        }
                        else if (current.commandName == "Duplicate")
                        {
                            current.Use();
                        }
                        else if (current.commandName == "Delete")
                        {
                            current.Use();
                        }
                        else if (current.commandName == "Cut")
                        {
                            current.Use();
                        }
                    }
                }
                else if (Event.current.type == EventType.ExecuteCommand)
                {
                    if (current.commandName == "Paste")
                    {
                        ActionNode[] nodesToPaste = ActionStateUtility.GetActionsAndConditions(BehaviourTreeUtility.nodeToPaste != null ? new ActionNode[] { BehaviourTreeUtility.nodeToPaste } : new ActionNode[0]);
                        ActionStateUtility.PasteNodes(m_ActionState, nodesToPaste);
                    }
                    else if (current.commandName == "Copy")
                    {
                        BehaviourTreeUtility.nodeToPaste = activeNode;
                    }
                    else if (current.commandName == "Duplicate")
                    {
                        ActionStateUtility.PasteNodes(m_ActionState, new ActionNode[] { activeNode });
                    }
                    else if (current.commandName == "Delete")
                    {
                        this.OnDestroyNode(activeNode);
                    }
                    else if (current.commandName == "Cut")
                    {
                        BehaviourTreeUtility.nodeToPaste = activeNode;
                        this.OnDestroyNode(activeNode);
                    }
                }
            }
        }