public void ShowDefinedBBVariablesGUI() { var varInfo = new Dictionary <string, BBVarInfo>(); foreach (KeyValuePair <BBVariable, object> pair in GetDefinedBBVariables()) { if (!varInfo.ContainsKey(pair.Key.dataName)) { varInfo[pair.Key.dataName] = new BBVarInfo(); } varInfo[pair.Key.dataName].type = pair.Key.varType; varInfo[pair.Key.dataName].dynamic = pair.Key.isDynamic; varInfo[pair.Key.dataName].count++; varInfo[pair.Key.dataName].objects.Add(pair.Value); } EditorUtils.BoldSeparator(); EditorUtils.CoolLabel("Defined Parameters"); EditorUtils.Separator(); GUILayout.BeginHorizontal(); GUILayout.BeginVertical(GUILayout.MaxWidth(100), GUILayout.ExpandWidth(true)); GUI.color = Color.yellow; GUILayout.Label("Name"); GUI.color = Color.white; foreach (KeyValuePair <string, BBVarInfo> pair in varInfo) { GUILayout.Label(string.Format(pair.Value.dynamic? "<i>{0}</i>" : "{0}", pair.Key)); } GUILayout.EndVertical(); GUILayout.BeginVertical(GUILayout.MaxWidth(100), GUILayout.ExpandWidth(true)); GUI.color = Color.yellow; GUILayout.Label("Type"); GUI.color = Color.white; foreach (KeyValuePair <string, BBVarInfo> pair in varInfo) { GUILayout.Label(EditorUtils.TypeName(pair.Value.type)); } GUILayout.EndVertical(); GUILayout.BeginVertical(GUILayout.MaxWidth(100), GUILayout.ExpandWidth(true)); GUI.color = Color.yellow; GUILayout.Label("Occurencies"); GUI.color = Color.white; foreach (KeyValuePair <string, BBVarInfo> pair in varInfo) { GUILayout.Label(pair.Value.count.ToString()); } GUILayout.EndVertical(); GUILayout.EndHorizontal(); }
public void ShowListGUI() { if (this == null) { return; } EditorUtils.TaskSelectionButton(gameObject, typeof(ConditionTask), delegate(Task c){ AddCondition((ConditionTask)c); }); ValidateList(); if (conditions.Count == 0) { EditorGUILayout.HelpBox("No Conditions", MessageType.None); return; } EditorUtils.ReorderableList(conditions, delegate(int i){ var o = conditions[i]; var condition = conditions[i] as ConditionTask; GUI.color = new Color(1, 1, 1, 0.25f); GUILayout.BeginHorizontal("box"); if (condition != null) { GUI.color = condition.isActive? new Color(1, 1, 1, 0.8f) : new Color(1, 1, 1, 0.25f); Undo.RecordObject(condition, "Mute"); condition.isActive = EditorGUILayout.Toggle(condition.isActive, GUILayout.Width(18)); GUI.backgroundColor = condition == currentViewCondition? Color.grey : Color.white; if (GUILayout.Button(EditorUtils.viewIcon, GUILayout.Width(25), GUILayout.Height(18))) { currentViewCondition = condition == currentViewCondition? null : condition; } EditorGUIUtility.AddCursorRect(GUILayoutUtility.GetLastRect(), MouseCursor.Link); GUI.backgroundColor = Color.white; GUILayout.Label(condition.summaryInfo); } else { GUILayout.Label(MissingTaskText(o)); GUI.color = Color.white; } if (GUILayout.Button("X", GUILayout.MaxWidth(20))) { Undo.RecordObject(this, "List Remove Task"); conditions.RemoveAt(i); Undo.DestroyObjectImmediate(o); } EditorGUIUtility.AddCursorRect(GUILayoutUtility.GetLastRect(), MouseCursor.Link); GUILayout.EndHorizontal(); GUI.color = Color.white; }); EditorUtils.Separator(); if (conditions.Count > 1) { GUI.backgroundColor = new Color(0.5f, 0.5f, 0.5f); if (GUILayout.Button(allSuccessRequired? "ALL True Required":"ANY True Suffice")) { allSuccessRequired = !allSuccessRequired; } GUI.backgroundColor = Color.white; } }
//Draw the window void DrawNodeWindow() { if (isHidden) { return; } if (childrenCollapsed) { var r = new Rect(nodeRect.x, nodeRect.yMax + 10, nodeRect.width, 20); EditorGUIUtility.AddCursorRect(r, MouseCursor.Link); if (GUI.Button(r, "COLLAPSED", "box")) { childrenCollapsed = false; } } GUI.color = isActive? Color.white : new Color(0.9f, 0.9f, 0.9f, 0.8f); GUI.color = Graph.currentSelection == this? new Color(0.9f, 0.9f, 1) : GUI.color; GUI.color = Application.isPlaying? new Color(0.9f, 0.9f, 0.9f) : GUI.color; nodeRect = GUILayout.Window(ID, nodeRect, NodeWindowGUI, string.Empty, "window"); GUI.Box(nodeRect, "", "windowShadow"); GUI.color = new Color(1, 1, 1, 0.5f); GUI.Box(new Rect(nodeRect.x + 6, nodeRect.y + 6, nodeRect.width, nodeRect.height), "", "windowShadow"); if (Application.isPlaying && status != Status.Resting) { if (status == Status.Success) { GUI.color = successColor; } else if (status == Status.Running) { GUI.color = runningColor; } else if (status == Status.Failure) { GUI.color = failureColor; } else if (status == Status.Error) { GUI.color = Color.red; } GUI.Box(nodeRect, "", "windowHighlight"); } else { if (isSelected) { GUI.color = restingColor; GUI.Box(nodeRect, "", "windowHighlight"); } } if (isSelected && GUIUtility.keyboardControl == 0 && Event.current.keyCode == KeyCode.Delete && Event.current.type == EventType.KeyUp) { Graph.PostGUI += delegate { graph.RemoveNode(this); } } ; GUI.color = Color.white; EditorGUIUtility.AddCursorRect(nodeRect, MouseCursor.Link); /* * var assignable = this as ITaskAssignable; * if (assignable && assignable.task != null && assignable.task.agentIsOverride){ * var overrideRect = new Rect(nodeRect.x, nodeRect.y-18, nodeRect.width, 18); * GUI.Box(overrideRect, assignable.task.agentInfo); * } */ } //removes the text color that some nodes add with html tags string StripNameColor(string name) { if (string.IsNullOrEmpty(name)) { return(name); } if (name.StartsWith("<") && name.EndsWith(">")) { name = name.Replace(name.Substring(0, name.IndexOf(">") + 1), ""); name = name.Replace(name.Substring(name.IndexOf("<"), name.LastIndexOf(">") + 1 - name.IndexOf("<")), ""); } return(name); } //This is the callback function of the GUILayout.window. Everything here is INSIDE the node Window. void NodeWindowGUI(int ID) { ////TITLE/// if (inIconMode) { GUI.color = EditorGUIUtility.isProSkin? Color.white : new Color(0f, 0f, 0f, 0.7f); GUI.backgroundColor = new Color(0, 0, 0, 0); GUILayout.Box(icon); GUI.backgroundColor = Color.white; GUI.color = Color.white; } else { var stripedTitle = StripNameColor(nodeName); if (!string.IsNullOrEmpty(stripedTitle)) { var title = nodeName; var defaultColor = "<color=#eed9a7>"; if (!EditorGUIUtility.isProSkin) { title = StripNameColor(title); defaultColor = "<color=#222222>"; } GUILayout.Label("<b><size=12>" + defaultColor + title + "</color></size></b>", centerLabel); } } /// var e = Event.current; /* * var scaleNodeRect= new Rect(nodeRect.width-10,nodeRect.height-10, 8, 8); * GUI.Box(scaleNodeRect, "", "nodeScaleBtn"); * * ////CONTROLS//// * if (Graph.allowClick && e.button == 0 && e.type == EventType.MouseDown && scaleNodeRect.Contains(e.mousePosition)){ * inResizeMode = true; * e.Use(); * } */ if (Graph.allowClick && e.button != 2 && e.type == EventType.MouseDown) { Graph.currentSelection = this; nodeIsPressed = true; if (e.button == 0 && e.clickCount == 2) { if (this is INestedNode && (this as INestedNode).nestedGraph != null) { graph.nestedGraphView = (this as INestedNode).nestedGraph; nodeIsPressed = false; } else { AssetDatabase.OpenAsset(MonoScript.FromMonoBehaviour(this)); } e.Use(); } if (e.control) { Graph.PostGUI += delegate { graph.primeNode = this; }; e.Use(); } OnNodePicked(); } if (e.type == EventType.MouseUp) { inResizeMode = false; nodeIsPressed = false; if (this is IAutoSortable) { Graph.PostGUI += delegate { SortConnectionsByPositionX(); } } ; OnNodeReleased(); } /// ////STATUS MARK ICONS//// if (Application.isPlaying) { var markRect = new Rect(5, 5, 15, 15); if (status == Status.Success) { GUI.color = successColor; GUI.Box(markRect, "", new GUIStyle("checkMark")); } else if (status == Status.Running) { GUI.Box(markRect, "", new GUIStyle("clockMark")); } else if (status == Status.Failure) { GUI.color = failureColor; GUI.Box(markRect, "", new GUIStyle("xMark")); } } /// ////NODE GUI//// GUI.color = Color.white; GUI.skin = null; GUI.skin.label.richText = true; GUI.skin.label.alignment = TextAnchor.MiddleCenter; GUILayout.BeginVertical(); OnNodeGUI(); if (this is ITaskAssignable) { var assignable = this as ITaskAssignable; var missing = MissingTask(assignable.serializedTask); if (missing != null) { GUILayout.Label(missing); } else { var task = (this as ITaskAssignable).task; if (task != null) { GUILayout.Label(NCPrefs.showTaskSummary? task.summaryInfo : string.Format("<b>{0}</b>", task.name)); } else { GUILayout.Label("No Task"); } } } GUILayout.EndVertical(); GUI.skin.label.alignment = TextAnchor.UpperLeft; ////CONTEXT MENU//// if (Graph.allowClick && e.button == 1 && e.type == EventType.MouseUp) { if (Graph.multiSelection.Count > 0) { var menu = new GenericMenu(); menu.AddItem(new GUIContent("Delete Selected Nodes"), false, delegate { foreach (Node node in Graph.multiSelection) { graph.RemoveNode(node); } }); menu.ShowAsContext(); e.Use(); return; } else { var menu = new GenericMenu(); if (graph.primeNode != this && allowAsPrime) { menu.AddItem(new GUIContent("Make Start (CTRL+Click)"), false, delegate { graph.primeNode = this; }); } if (this is INestedNode) { menu.AddItem(new GUIContent("Edit Nested (Double Click)"), false, delegate { graph.nestedGraphView = (this as INestedNode).nestedGraph; }); } menu.AddItem(new GUIContent("Duplicate (CTRL+D)"), false, delegate { Duplicate(); }); if (inConnections.Count > 0) { menu.AddItem(new GUIContent(isActive? "Disable" : "Enable"), false, delegate { SetActive(!isActive); }); } if (this is IAutoSortable && outConnections.Count > 0) { menu.AddItem(new GUIContent(childrenCollapsed? "Expand Children" : "Collapse Children"), false, delegate { childrenCollapsed = !childrenCollapsed; }); } if (this is ITaskAssignable) { var assignable = this as ITaskAssignable; if (assignable.task != null) { menu.AddItem(new GUIContent("Copy Assigned Task"), false, delegate { Task.copiedTask = assignable.task; }); } else { menu.AddDisabledItem(new GUIContent("Copy Assigned Task")); } if (Task.copiedTask != null) { menu.AddItem(new GUIContent("Paste Assign Task"), false, delegate { try { var current = assignable.task; assignable.task = Task.copiedTask; assignable.task = current; } catch { Debug.LogWarning(string.Format("Copied Task '{0}'' is incompatible type for target node '{1}'", Task.copiedTask.name, this.name)); return; } if (assignable.task == Task.copiedTask) { return; } if (assignable.task != null) { if (EditorUtility.DisplayDialog("Paste Task", string.Format("Node already has a Task assigned '{0}'. Replace assigned task with pasted task '{1}'?", assignable.task.name, Task.copiedTask.name), "YES", "NO")) { Undo.DestroyObjectImmediate(assignable.task); } else { return; } } assignable.task = Task.copiedTask.CopyTo(gameObject); }); } else { menu.AddDisabledItem(new GUIContent("Paste Assigned Task")); } } OnContextMenu(menu); menu.AddSeparator("/"); menu.AddItem(new GUIContent("Delete (DEL)"), false, delegate { graph.RemoveNode(this); }); menu.ShowAsContext(); e.Use(); } } /// ////LAST (BUT NOT LEAST)/// if (inResizeMode) { nodeRect.width = Mathf.Max(e.mousePosition.x + 10, minSize.x); nodeRect.height = Mathf.Max(e.mousePosition.y + 10, minSize.y); } else if (Graph.allowClick && e.button != 2) { if (e.type == EventType.MouseDrag) { foreach (Node node in Graph.multiSelection) { if (node != null) { Undo.RecordObject(node, "Move"); node.nodeRect.center += e.delta; } } } Undo.RecordObject(this, "Move"); if (NCPrefs.doSnap && !e.shift && Graph.multiSelection.Count == 0 && nodeIsPressed) { nodeRect.x = Mathf.Round(nodeRect.x / 15) * 15; nodeRect.y = Mathf.Round(nodeRect.y / 15) * 15; } if (this is IAutoSortable && (e.shift || childrenCollapsed) && e.type == EventType.MouseDrag && nodeIsPressed) { RecursivePanNode(e.delta); } GUI.DragWindow(); } } //The comments of the node sitting next or bottom of it void DrawNodeComments() { if (!string.IsNullOrEmpty(nodeComment) && graph && graph.showComments) { var commentsRect = new Rect(); var size = new GUIStyle("textArea").CalcSize(new GUIContent(nodeComment)); if (outConnections.Count == 0) { size.y = new GUIStyle("textArea").CalcHeight(new GUIContent(nodeComment), nodeRect.width); commentsRect = new Rect(nodeRect.x, nodeRect.yMax + 5, nodeRect.width, size.y); } else { commentsRect = new Rect(nodeRect.xMax + 5, nodeRect.yMin, Mathf.Min(size.x, nodeRect.width), nodeRect.height); } GUI.color = new Color(1, 1, 1, 0.6f); GUI.backgroundColor = new Color(1f, 1f, 1f, 0.2f); GUI.Box(commentsRect, nodeComment, "textArea"); GUI.backgroundColor = Color.white; GUI.color = Color.white; } } //Shows the tag label on the left of the node if it is tagged void DrawNodeTag() { if (!string.IsNullOrEmpty(tag)) { var size = new GUIStyle("label").CalcSize(new GUIContent(tag)); var tagRect = new Rect(nodeRect.x - size.x - 10, nodeRect.y, size.x, size.y); GUI.Label(tagRect, tag); tagRect.width = 12; tagRect.height = 12; tagRect.y += tagRect.height + 5; tagRect.x = nodeRect.x - 22; GUI.DrawTexture(tagRect, EditorUtils.tagIcon); } } //Function to pan the node recursively void RecursivePanNode(Vector2 delta) { nodeRect.center += delta; for (int i = 0; i < outConnections.Count; i++) { var node = outConnections[i].targetNode; if (node.ID > this.ID) { node.RecursivePanNode(delta); } } } //The inspector of the node shown in the editor panel or else. public void ShowNodeInspectorGUI() { Undo.RecordObject(this, "Node Inspector"); if (NCPrefs.showNodeInfo) { GUI.backgroundColor = new Color(0.8f, 0.8f, 1); EditorGUILayout.HelpBox(nodeDescription, MessageType.None); GUI.backgroundColor = Color.white; } GUILayout.BeginHorizontal(); if (!inIconMode && allowAsPrime) { customName = EditorGUILayout.TextField(customName); EditorUtils.TextFieldComment(customName, "Name..."); } tag = EditorGUILayout.TextField(tag); EditorUtils.TextFieldComment(tag, "Tag..."); GUILayout.EndHorizontal(); nodeComment = EditorGUILayout.TextField(nodeComment); EditorUtils.TextFieldComment(nodeComment); EditorUtils.Separator(); OnNodeInspectorGUI(); TaskAssignableGUI(); if (GUI.changed) { EditorUtility.SetDirty(this); } } void TaskAssignableGUI() { if (this is ITaskAssignable) { System.Type taskType = null; foreach (System.Type iType in this.GetType().GetInterfaces()) { if (iType.IsGenericType && iType.GetGenericTypeDefinition() == typeof(ITaskAssignable <>)) { taskType = iType.GetGenericArguments()[0]; break; } } if (taskType != null) { var assignable = this as ITaskAssignable; string missing = MissingTask(assignable.serializedTask); if (missing != null) { GUILayout.Label("Missing: " + missing); if (GUILayout.Button("Remove Missing")) { DestroyImmediate(assignable.serializedTask, true); assignable.task = null; } return; } if (assignable.task == null) { EditorUtils.TaskSelectionButton(gameObject, taskType, delegate(Task t){ assignable.task = t; }); } else { assignable.task.ShowInspectorGUI(); } } } } string MissingTask(Object o) { if (!Equals(o, null) && o.GetType() == typeof(Object) && o.ToString() != "null") { var s = o.ToString(); s = s.Replace(gameObject.name + " ", ""); return(string.Format("<color=#ff6457>* {0} *</color>", s)); } return(null); }