/// <summary>
 /// constructor taking a go and position
 /// </summary>
 public MovingTask(TaskList tl, GameObject go, Vector3 position, Quaternion rotation) : base(tl, go)
 {
     Position = position;
     Rotation = rotation;
 }
        public override void OnInspectorGUI()
        {
            // draw base inspector gui
            base.OnInspectorGUI();

            obj = (TaskList)target;

            // to find missing game objects
            if (GUILayout.Button("Find Missing Objects by Name"))
            {
                obj.FindMissingObjectsByName();
            }

            // to recapture associated game object names
            if (GUILayout.Button("Capture Game Objects Names"))
            {
                obj.CaptureGameObjectNames();
            }

            GUILayout.BeginVertical();
            for (int i = 0; i < obj.Tasks.Count; i++)
            {
                GUILayout.BeginHorizontal();

                // toggle show task detail on and off
                string taskName = "Missing!";
                if (obj.Tasks[i].GameObject != null)
                {
                    taskName = obj.Tasks[i].TaskName + " (" + obj.Tasks[i].GameObject.name + ")";
                }

                GUIStyle style = new GUIStyle(EditorStyles.toolbarButton);
                style.alignment = TextAnchor.MiddleLeft;
                bool clicked = GUILayout.Toggle(i == SelectedTaskId, i + 1 + ". " + taskName, style);
                if (clicked != (i == SelectedTaskId))
                {
                    if (clicked)
                    {
                        EditorGUIUtility.PingObject(obj.Tasks[i].GameObject);
                        obj.CurrentTaskId = i;
                        SelectedTaskId    = i;
                        GUI.FocusControl(null);
                    }
                    else
                    {
                        obj.CurrentTaskId = -1;
                        SelectedTaskId    = -1;
                    }
                }

                // to easily reorder tasks up and down
                if (i <= 0)
                {
                    GUI.enabled = false;
                }
                if (GUILayout.Button(i > 0 ? "^" : " ", EditorStyles.toolbarButton, GUILayout.Width(30)))
                {
                    Task temp = obj.Tasks[i];
                    obj.Tasks[i]     = obj.Tasks[i - 1];
                    obj.Tasks[i - 1] = temp;
                }
                GUI.enabled = true;

                // to easily reorder tasks up and down
                if (i >= obj.Tasks.Count - 1)
                {
                    GUI.enabled = false;
                }
                if (GUILayout.Button(i < obj.Tasks.Count - 1 ? "v" : " ", EditorStyles.toolbarButton, GUILayout.Width(30)))
                {
                    Task temp = obj.Tasks[i];
                    obj.Tasks[i]     = obj.Tasks[i + 1];
                    obj.Tasks[i + 1] = temp;
                }
                GUI.enabled = true;

                // remove task from task list
                if (GUILayout.Button("-", EditorStyles.toolbarButton, GUILayout.Width(30)))
                {
                    if (SelectedTaskId != -1)
                    {
                        SelectedTaskId = -1;
                    }
                    obj.Tasks.RemoveAt(i);
                }

                GUILayout.EndHorizontal();

                // display task detail if task is selected
                if (i == SelectedTaskId)
                {
                    DisplayTaskDetail(obj.Tasks[i]);
                }
            }
            GUILayout.EndVertical();

            if (GUI.changed)
            {
                EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene());
            }
        }
Beispiel #3
0
 /// <summary>
 /// constructor taking a go
 /// </summary>
 public ClickingTask(TaskList tl, GameObject go) : base(tl, go)
 {
 }
Beispiel #4
0
 /// <summary>
 /// constructor taking a serializable task
 /// </summary>
 public ClickingTask(TaskList tl, SerializableTask task) : base(tl, task)
 {
 }
        /// <summary>
        /// displaying each node info
        /// </summary>
        public void DisplayNodeInfo(Node node)
        {
            if (node != null)
            {
                // node name and go, lock button, reset button, add task button
                GUILayout.BeginHorizontal();
                GUILayout.Space(indentLevel * 10);
                if (GUILayout.Button(node.Name + " (" + (node.GameObject == null?"Missing!": node.GameObject.name) + ")" + (node.Selected?"*":""), "Button"))
                {
                    EditorGUIUtility.PingObject(node.GameObject);
                    obj.ToggleSelect(node);
                }

                // to lock or unlock node for interaction
                if (GUILayout.Button((node.Locked ? "X" : " "), "Button", GUILayout.Width(20)))
                {
                    if (node.Locked)
                    {
                        node.Locked = false;
                    }
                    else
                    {
                        obj.Release();
                        obj.Deselect(node);
                        node.Locked = true;
                    }
                }

                // to reset this specific node
                if (GUILayout.Button("R", "Button", GUILayout.Width(20)))
                {
                    obj.Reset(node);
                }

                // to add a task related to the game object of this node
                if (GUILayout.Button("Add Task", "Button", GUILayout.Width(100)))
                {
                    GenericMenu genericMenu = new GenericMenu();
                    for (int i = 0; i < MultiPartsObjectEditorUtility.TaskTypes().Length; i++)
                    {
                        genericMenu.AddItem(new GUIContent(MultiPartsObjectEditorUtility.TaskTypes()[i]), false,
                                            (param) =>
                        {
                            int index = (int)param;
                            switch (index)
                            {
                            case 0:
                                {
                                    TaskList tl = obj.TaskList;
                                    tl.Tasks.Add(new MovingTask(tl, node.GameObject, obj.transform.InverseTransformPoint(node.GameObject.transform.position), Quaternion.Inverse(obj.transform.rotation) * node.GameObject.transform.rotation));
                                }
                                break;

                            case 1:
                                {
                                    TaskList tl = obj.TaskList;
                                    tl.Tasks.Add(new ClickingTask(tl, node.GameObject));
                                }
                                break;
                            }
                        }
                                            , i);
                    }
                    genericMenu.ShowAsContext();
                }
                GUILayout.EndHorizontal();


                // node details
                if (node.Selected)
                {
                    GUILayout.BeginHorizontal();
                    GUILayout.Space(indentLevel * 10);
                    GUILayout.BeginVertical(EditorStyles.helpBox);

                    // allows to change the name of the node
                    GUILayout.BeginHorizontal();
                    GUILayout.Label("Name", GUILayout.Width(100));
                    node.Name = GUILayout.TextField(node.Name);
                    GUILayout.EndHorizontal();

                    // allows to change the name of the node
                    GUILayout.BeginHorizontal();
                    GUILayout.Label("Description", GUILayout.Width(100));
                    GUILayout.EndHorizontal();
                    GUILayout.BeginHorizontal();
                    EditorStyles.textField.wordWrap = true;
                    node.Description = EditorGUILayout.TextArea(node.Description, GUILayout.Height(100));
                    GUILayout.EndHorizontal();

                    // allows to change the game object of the node
                    GUILayout.BeginHorizontal();
                    GUILayout.Label("GO", GUILayout.Width(100));
                    node.GameObject = (GameObject)EditorGUILayout.ObjectField(node.GameObject, typeof(GameObject), true);
                    GUILayout.EndHorizontal();

                    // go name
                    GUILayout.BeginHorizontal();
                    GUILayout.Label("GOName", GUILayout.Width(100));
                    node.GOName = GUILayout.TextField(node.GOName);
                    GUILayout.EndHorizontal();

                    GUILayout.EndVertical();
                    GUILayout.EndHorizontal();
                }

                // node childs
                if (node.Childs.Count > 0)
                {
                    indentLevel++;
                    GUILayout.BeginVertical();
                    foreach (var child in node.Childs)
                    {
                        //GUILayout.BeginHorizontal();
                        //GUILayout.Space(20);
                        DisplayNodeInfo(child);
                        //GUILayout.EndHorizontal();
                    }
                    GUILayout.EndVertical();
                    indentLevel--;
                }
            }
        }