Exemple #1
0
        public void CreateEasyAISystem()
        {
            if (SelectedObject != null)
            {
                if (!SelectedObject.GetComponent <EasyAIFSM>())
                {
                    coreSystem = SelectedObject.AddComponent <EasyAIFSM> ();
                    coreSystem.Init();

                    Node node = ScriptableObject.CreateInstance <StartAINode>();
                    node.self = coreSystem.gameObject;
                    node.Init();
                    node.rect.x = 100f;
                    node.rect.y = 100f;
                    coreSystem.nodes.Add(node);
                }
                else
                {
                    coreSystem = SelectedObject.GetComponent <EasyAIFSM>();
                }
            }
            else
            {
                //	SelectedObject = new GameObject ("Easy AI Agent");
                //	coreSystem = SelectedObject.AddComponent<CoreSystem> ();
                //	coreSystem.Init ();
                //
            }
        }
Exemple #2
0
        void OnEnable()
        {
            SelectedObject = Selection.activeGameObject;
            coreSystem     = null;

            CreateEasyAISystem();
            EditorApplication.update += Update;
        }
Exemple #3
0
        // OnGUI is called for rendering and handling GUI events
        void OnGUI()
        {
            if (customMenu == null)
            {
                Init();
            }

            if (!initialized)
            {
                Init();
            }
            // Input Events
            Event currentEvent = Event.current;

            // Zoom Operations
            if (coreSystem == null || zoomFactor == 0)
            {
                // If coreSystem.zoomfactor is not available
                zoomFactor = 1f;
            }
            else
            {
                // Get zoomfactor from serialized variable
                zoomFactor = coreSystem.zoomFactor;
            }


            SelectedObject = Selection.activeGameObject;

            if (SelectedObject != null)
            {
                if (SelectedObject.GetComponent <EasyAIFSM>())
                {
                    coreSystem = SelectedObject.GetComponent <EasyAIFSM>();
                }
            }
            // Side Window
            if (sideWindow != null && coreSystem != null)
            {
                sideWindow.Draw(position, coreSystem);
            }

            // User Input
            if (!customMenu.visible)
            {
                InputEvents(currentEvent);
            }

            // Begin scaled GUI Area
            Begin(zoomFactor, new Rect(0f, 11.5f, position.width - (sideWindow.opened ? 220f : 25f), position.height));


            // Background
            if (currentEvent.type == EventType.Repaint)
            {
                DrawBackground();
            }



            // Nodes
            if (coreSystem != null)
            {
                if (coreSystem.nodes != null)
                {
                    if (coreSystem.nodes.Count > 0 && sc == UnityEngine.SceneManagement.SceneManager.GetActiveScene())
                    {
                        // Draw Curves between Connection Knobs

                        DrawCurves();

                        BeginWindows();
                        for (int i = 0; i < coreSystem.nodes.Count; i++)
                        {
                            //// Draw Connection Knobs only
                            coreSystem.nodes[i].DrawConnectors();
                            if (coreSystem.nodes[i].isRunning && flagIsRunning)
                            {
                                GUI.color = Color.green;
                            }
                            else
                            {
                                GUI.color = Color.white;
                            }
                            coreSystem.nodes[i].rect = GUI.Window(i, coreSystem.nodes[i].rect, DrawNodeWindow, "", EditorStyles.helpBox);                // customSkin.GetStyle("Eventwindow")
                        }

                        EndWindows();
                    }
                }
            }
            else
            {
                //// If savePoint doesn't exist, there is no Tutorial System Object in the Scene
                //GameObject temp = GameObject.Find("DialogueSystem");
                //if (temp != null) {
                //	coreSystem = temp.GetComponent<CoreSystem>();

                //}
            }

            if (wantsMouseMove)
            {
                EditorGUI.EndDisabledGroup();
            }
            // End Scaled Area
            ZoomAreaEnd();


            // Context Menu
            customMenu.Draw(currentEvent);


            if (currentEvent.type == EventType.Repaint)
            {
                sc = UnityEngine.SceneManagement.SceneManager.GetActiveScene();

                Repaint();
            }
        }
Exemple #4
0
        // Callback from Context Menu
        private void ContextCallback(object obj)
        {
            if (obj.ToString() == "Delete Node")
            {
                Node d_node = NodeAtPosition(mousePos);
                if (d_node != null)
                {
                    Undo.RegisterCompleteObjectUndo(coreSystem, "Delete Node");
                    // Break opposite connections of this Nodes Connectors
                    foreach (Connector c in d_node.connectors)
                    {
                        c.BreakOpposite();
                    }

                    coreSystem.nodes.Remove(d_node);

                    Undo.DestroyObjectImmediate(d_node);
                }
            }
            else if (obj.ToString() == "Duplicate Node")
            {
                Node dup_node = NodeAtPosition(mousePos);
                if (dup_node != null)
                {
                    Node node = ScriptableObject.CreateInstance(dup_node.GetType().Name) as Node;
                    node.Init();
                    node.rect.x = mousePos.x + 60f;
                    node.rect.y = mousePos.y;
                    coreSystem.nodes.Add(node);

                    //EditorUtility.CopySerialized(dup_node, node);
                }
            }
            else if (obj.ToString() == "Create GameObject")
            {
                SelectedObject = new GameObject("Easy AI Agent");
                coreSystem     = SelectedObject.AddComponent <EasyAIFSM> ();

                coreSystem.Init();

                Node node = ScriptableObject.CreateInstance <StartAINode>();
                node.self = coreSystem.gameObject;
                node.Init();
                node.rect.x = mousePos.x;
                node.rect.y = mousePos.y;
                coreSystem.nodes.Add(node);
            }

            else
            {
                Type typeData;

                if (nodes.TryGetValue(obj.ToString(), out typeData))         // Returns true.
                {
                    Node node = ScriptableObject.CreateInstance(typeData.Name) as Node;
                    node.self = coreSystem.gameObject;
                    node.Init();
                    node.rect.x = mousePos.x;
                    node.rect.y = mousePos.y;
                    coreSystem.nodes.Add(node);
                }
            }
        }
Exemple #5
0
        /// <summary>
        /// Basic Draw routine. Called in OnGUI in TutorialEditor
        /// </summary>
        /// <param name="position">Absolute position</param>
        public void Draw(Rect position, EasyAIFSM coreSystem)
        {
            float width = opened ? 220f : 25f;

            rect        = new Rect(position.width - width, 0f, width, position.height);
            stackHeight = 0f;

            GUI.BeginGroup(rect, sideWindowStyle);

            // Open- / Close Button
            if (GUI.Button(new Rect(opened ? 10f:5f, stackHeight += 5f, opened ? 190f : 15f, 20f),
                           new GUIContent(opened ? ">> Close >>" : "<", opened ? "Close Sidewindow" : "Open Sidewindow")))
            {
                opened = !opened;
            }

            // Elements on opened SideWindow
            if (opened)
            {
                stackHeight = 20f;
                if (GUI.Button(new Rect(10f, stackHeight += 25f, 190f, 20f),
                               "New Canvas"))
                {
                    NodeEditorWindow.self.CreateEasyAISystem();
                }
                if (GUI.Button(new Rect(10f, stackHeight += 35f, 190f, 20f),
                               "Clear Canvas"))
                {
                    coreSystem.nodes.Clear();
                    coreSystem.fsmVariables.Clear();
                    Node node = ScriptableObject.CreateInstance <StartAINode>();
                    node.self = coreSystem.gameObject;
                    node.Init();
                    node.rect.x = 100f;
                    node.rect.y = 100f;

                    coreSystem.nodes.Add(node);
                }
                if (GUI.Button(new Rect(10f, stackHeight += 35f, 190f, 20f),
                               "Welcome Window"))
                {
                    WelcomeWindow.ShowWindow();
                }

                //GUI.Label(new Rect(5f, stackHeight += 40f, 120f, 20f),
                //	"Variables: ");
                GUI.BeginGroup(new Rect(5f, stackHeight += 40, 210f, 1500f));         // 190


                GUILayout.BeginVertical("box");

                GUILayout.Label("Variables: ", GUILayout.Height(20), GUILayout.Width(80));



                GUILayout.BeginHorizontal();
                if (GUILayout.Button("Add", GUILayout.Height(15), GUILayout.Width(35)) && _choiceIndex != 0 && !string.IsNullOrEmpty(varName))
                {
                    foreach (var item in coreSystem.fsmVariables)
                    {
                        if (item.Name == varName)
                        {
                            EditorGUIUtility.ExitGUI();
                        }
                    }


                    switch (_choiceIndex)
                    {
                    // String
                    case 1:
                        FsmString item = "";
                        item.Name = varName;
                        coreSystem.fsmVariables.Add(item);
                        break;

                    // Bool
                    case 2:
                        FsmBool item2 = false;
                        item2.Name = varName;
                        coreSystem.fsmVariables.Add(item2);
                        break;

                    // Color
                    case 3:
                        FsmColor item3 = Color.white;
                        item3.Name = varName;
                        coreSystem.fsmVariables.Add(item3);
                        break;

                    // Float
                    case 4:
                        FsmFloat item4 = 0f;
                        item4.Name = varName;
                        coreSystem.fsmVariables.Add(item4);
                        break;

                    // GameObject
                    case 5:
                        FsmGameObject item5 = ScriptableObject.CreateInstance <FsmGameObject>();
                        item5.Name = varName;
                        coreSystem.fsmVariables.Add(item5);
                        break;

                    // Object
                    case 6:
                        FsmObject item6 = ScriptableObject.CreateInstance <FsmObject>();

                        item6.Name = varName;
                        coreSystem.fsmVariables.Add(item6);
                        break;

                    // Int
                    case 7:
                        FsmInt item7 = 0;
                        item7.Name = varName;
                        coreSystem.fsmVariables.Add(item7);
                        break;

                    // Vector 2
                    case 8:
                        FsmVector2 item8 = Vector2.zero;
                        item8.Name = varName;
                        coreSystem.fsmVariables.Add(item8);
                        break;

                    // Vector3
                    case 9:
                        FsmVector3 item9 = Vector3.zero;
                        item9.Name = varName;
                        coreSystem.fsmVariables.Add(item9);
                        break;

                    default:
                        break;
                    }
                    varName = "";
                }
                varName = GUILayout.TextField(varName, GUILayout.Width(80));

                _choiceIndex = EditorGUILayout.Popup(_choiceIndex, DisplayNames, GUILayout.Height(10), GUILayout.Width(60));


                GUILayout.EndHorizontal();
                GUILayout.EndVertical();
                GUILayout.BeginVertical();
                GUILayout.Space(8f);


                // scrolll variables
                scrollPos = EditorGUILayout.BeginScrollView(scrollPos, GUIStyle.none, GUI.skin.verticalScrollbar, GUILayout.Width(210), GUILayout.Height(400));



                for (int i = 0; i < coreSystem.fsmVariables.Count; i++)
                {
                    GUILayout.BeginVertical("box");
                    GUILayout.BeginHorizontal();

                    GUILayout.Label(coreSystem.fsmVariables[i].Name, GUILayout.Width(60));
                    GUILayout.Label(SerializedVariable.GetTypeName(coreSystem.fsmVariables[i].VariableType), GUILayout.Width(75));

                    GUILayout.Space(15f);
                    if (GUILayout.Button("X", GUILayout.Height(15), GUILayout.Width(20)))
                    {
                        coreSystem.fsmVariables.RemoveAt(i);


                        EditorGUIUtility.ExitGUI();
                    }
                    GUILayout.EndHorizontal();
                    GUILayout.BeginVertical();

                    if (coreSystem.fsmVariables[i].VariableType == typeof(GameObject))
                    {
                        GameObject temp = coreSystem.fsmVariables[i].GetValue() as GameObject;

                        temp = EditorGUILayout.ObjectField("", temp, typeof(GameObject), true, GUILayout.Width(160)) as GameObject;
                        if (temp != null)
                        {
                            var _name = coreSystem.fsmVariables[i].Name;
                            coreSystem.fsmVariables [i]     = (FsmGameObject)temp;                         //temp as FsmGameObject;
                            coreSystem.fsmVariables[i].Name = _name;
                        }
                    }
                    else if (coreSystem.fsmVariables[i].VariableType == typeof(string))
                    {
                        string temp = coreSystem.fsmVariables[i].GetValue() as string;

                        temp = EditorGUILayout.TextField("", temp, GUILayout.Width(160));

                        if (temp != null)
                        {
                            var _name = coreSystem.fsmVariables[i].Name;
                            coreSystem.fsmVariables[i]      = (FsmString)temp;
                            coreSystem.fsmVariables[i].Name = _name;
                        }
                    }
                    else if (coreSystem.fsmVariables[i].VariableType == typeof(int))
                    {
                        int temp = (int)coreSystem.fsmVariables[i].GetValue();

                        temp = EditorGUILayout.IntField("", temp, GUILayout.Width(160));


                        var _name = coreSystem.fsmVariables[i].Name;
                        coreSystem.fsmVariables[i]      = (FsmInt)temp;
                        coreSystem.fsmVariables[i].Name = _name;
                    }
                    else if (coreSystem.fsmVariables[i].VariableType == typeof(float))
                    {
                        float temp = (float)coreSystem.fsmVariables[i].GetValue();

                        temp = EditorGUILayout.FloatField("", temp, GUILayout.Width(160));


                        var _name = coreSystem.fsmVariables[i].Name;
                        coreSystem.fsmVariables[i]      = (FsmFloat)temp;
                        coreSystem.fsmVariables[i].Name = _name;
                    }
                    else if (coreSystem.fsmVariables[i].VariableType == typeof(bool))
                    {
                        bool temp = (bool)coreSystem.fsmVariables[i].GetValue();
                        EditorGUILayout.BeginHorizontal();
                        GUILayout.Space(80f);
                        temp = EditorGUILayout.Toggle("", temp, GUILayout.Width(80));


                        var _name = coreSystem.fsmVariables[i].Name;
                        coreSystem.fsmVariables[i]      = (FsmBool)temp;
                        coreSystem.fsmVariables[i].Name = _name;

                        EditorGUILayout.EndHorizontal();
                    }
                    else if (coreSystem.fsmVariables[i].VariableType == typeof(Vector2))
                    {
                        Vector2 temp = (Vector2)coreSystem.fsmVariables[i].GetValue();

                        temp = EditorGUILayout.Vector2Field("", temp, GUILayout.Width(160));


                        var _name = coreSystem.fsmVariables[i].Name;
                        coreSystem.fsmVariables[i]      = (FsmVector2)temp;
                        coreSystem.fsmVariables[i].Name = _name;
                    }
                    else if (coreSystem.fsmVariables[i].VariableType == typeof(Vector3))
                    {
                        Vector3 temp = (Vector3)coreSystem.fsmVariables[i].GetValue();

                        temp = EditorGUILayout.Vector3Field("", temp, GUILayout.Width(160));


                        var _name = coreSystem.fsmVariables[i].Name;
                        coreSystem.fsmVariables[i]      = (FsmVector3)temp;
                        coreSystem.fsmVariables[i].Name = _name;
                    }
                    else if (coreSystem.fsmVariables[i].VariableType == typeof(Color))
                    {
                        Color temp = (Color)coreSystem.fsmVariables[i].GetValue();

                        temp = EditorGUILayout.ColorField(temp, GUILayout.Width(160));


                        var _name = coreSystem.fsmVariables[i].Name;
                        coreSystem.fsmVariables[i]      = (FsmColor)temp;
                        coreSystem.fsmVariables[i].Name = _name;
                    }
                    else if (coreSystem.fsmVariables[i].VariableType == typeof(Object))
                    {
                        Object temp = (Object)coreSystem.fsmVariables[i].GetValue();

                        temp = EditorGUILayout.ObjectField("", temp, typeof(Object), true, GUILayout.Width(160));

                        if (temp != null)
                        {
                            var _name = coreSystem.fsmVariables[i].Name;
                            coreSystem.fsmVariables[i]      = (FsmObject)temp;
                            coreSystem.fsmVariables[i].Name = _name;
                        }
                    }



                    //GUILayout.Label(coreSystem.fsmVariables[i].GetValue().ToString(),GUILayout.Width(220));

                    GUILayout.EndVertical();
                    GUILayout.Space(5f);
                    GUILayout.EndVertical();
                }

                EditorGUILayout.EndScrollView();

                GUILayout.EndVertical();

                GUI.EndGroup();

                //if (GUI.Button (new Rect(5f, stackHeight += 25f, 60f, 20f),"Add New")) {



                //}



                //	// If TutorialSystem Gameobject was not yet created
                //if (!TutorialEditor.tutSystemCreated) {
                //		// New Tutorial Button
                //	if (GUI.Button (new Rect(5f, stackHeight += 25f, 190f, 20f),
                //		"New Tutorial", TutorialEditor.customSkin.button)) {
                //		TutorialEditor.CreateTutorialSystem ();
                //		}

                //	AboutButton();
                //	// If TutorialSystem was already created
                //} else {
                //		// Delete everything from TutorialDesigner Canvas
                //	if (GUI.Button(new Rect(5f, stackHeight += 25f, 190f, 20f),
                //		"Clear Workspace", TutorialEditor.customSkin.button)) {
                //		Undo.RegisterCompleteObjectUndo (TutorialEditor.savePoint, "Clear Workspace");
                //		foreach (Node n in TutorialEditor.savePoint.nodes) {
                //			n.Remove ();
                //		}
                //		TutorialEditor.savePoint.nodes.Clear ();
                //		TutorialEditor.savePoint.startNode = null;
                //		}

                //		// Hide all Dialogue Gameobjects in current scene
                //	if (GUI.Button(new Rect(5f, stackHeight += 25f, 190f, 20f),
                //		"Hide Dialogues", TutorialEditor.customSkin.button)) {
                //		TutorialEditor.savePoint.HideAllDialogues();
                //		}

                //	AboutButton();

                //		// Basic Zooming in the EditorWindow
                //	float zoomChange = 0f;
                //	GUI.Label(new Rect(5f, stackHeight += 30f, 120f, 20f),
                //		"Zoom : " + TutorialEditor.zoomFactor, labelBold);
                //	if (GUI.Button (new Rect(125f, stackHeight, 30f, 20f),
                //		"+", TutorialEditor.customSkin.button)) {
                //		zoomChange = 0.2f;
                //		}
                //	if (GUI.Button (new Rect(160f, stackHeight, 30f, 20f),
                //		"-", TutorialEditor.customSkin.button)) {
                //		zoomChange = -0.2f;
                //		}

                //		// If user changed zoomFactor
                //	if (zoomChange != 0) {
                //		TutorialEditor.zoomFactor = Mathf.Clamp (TutorialEditor.zoomFactor + zoomChange, 0.2f, 1f);
                //			// Store here for Serialization
                //		TutorialEditor.savePoint.zoomFactor = TutorialEditor.zoomFactor;
                //	}

                //		// Display StartNode if available
                //	Node startNode =  TutorialEditor.savePoint.startNode;
                //	string start = "missing";
                //	if (startNode != null) {
                //		bool isItStep = ((TutorialEditor.savePoint.startNode.nodeType & 1) == 1);
                //		start = (isItStep ? "Step - " : "Event - ") + startNode.description;
                //	}

                //GUI.Label(new Rect(5f, stackHeight += 30f, 120f, 20f),
                //	"Startnode: ");
                //GUI.Label(new Rect(5f, stackHeight += 18f, 190f, 52f),
                //	"start");

                //GUI.BeginGroup(new Rect(5f, stackHeight += 60, 190f, 230f));
                //int groupStack = 0;

                //	// Tutorial Monitor
                //GUI.Label (new Rect(10f, groupStack, 180f, 20f), "Tutorial Monitor");
                //GUI.Label (new Rect(10f, groupStack += 20, 180f, 18f), "--- Default Path ---");
                //GUI.Label (new Rect(10f, groupStack += 18, 180f, 0f), "-> " + currentNode);
                //GUI.Label (new Rect(10f, groupStack += 80, 180f, 18f), "--- Global ---");
                //GUI.Label (new Rect(10f, groupStack += 18, 180f, 0f), "-> " + globalNode);

                //GUI.EndGroup();
            }
            GUI.EndGroup();
        }