static void OnPostprocessAllAssets ( string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths ) { // Recompile all BT when the assets are refreshed. var behaviours = GameObject.FindObjectsOfType <BehaviourTree>(); foreach (var b in behaviours) { b.Apply(); b.Compile(); } GUIBTScript.ParseAll(); SourceDisplay.RefreshAllBehaviourTreeEditors(); }
private void OnGUI_TaskListSelector() { #if UNITY_EDITOR var taskList = GUIBTScript.taskList; UnityEditor.EditorGUI.BeginChangeCheck(); taskIndex = UnityEditor.EditorGUILayout.Popup(taskIndex, taskList, GUILayout.ExpandWidth(false), GUILayout.MaxWidth(80.0f)); if (UnityEditor.EditorGUI.EndChangeCheck()) { if (taskIndex >= GUIBTScript.structuralNodes.Length) { var ti = GUIBTScript.taskImplementations[taskIndex - GUIBTScript.structuralNodes.Length]; this.Promote(ti); } else { var option = taskList[taskIndex]; var lastSlash = option.LastIndexOf('/'); var w = option.Length - lastSlash - 1; var name = option.Substring(lastSlash + 1, w); string label = null; System.Type[] types = null; if (name == "tree") { label = "tree"; types = new System.Type[] { typeof(string) }; } else if (name == "repeat n") { label = "repeat"; types = new System.Type[] { typeof(int) }; } else { label = name; types = new System.Type[0]; } this.Promote(label, types); } GUIBTScript.SetSourcesDirty(); } #endif }
private void GUI_token(GUIStyle style, BTNode node, BTLTokenizer.Token token) { var label = token.content.Replace("\t", " "); if (clickedTask != null && clickedTaskFade < Time.realtimeSinceStartup) { clickedTask = null; } #if UNITY_EDITOR var task = node as BTTask; if (task != null && task.boundState != BoundState.Bound) { style = BTLSyntaxHighlight.style_failed; } if (task != null && task.boundState == BoundState.Bound && token.type == BTLTokenizer.TokenType.Word) { if (GUILayout.Button(label, style) && Event.current.button == 0) { if (clickedTask == task) { GUIBTScript.OpenScript(task.boundObject as MonoBehaviour, task.boundMember); } clickedTask = task; clickedTaskFade = Time.realtimeSinceStartup + 0.5f; } } else { GUILayout.Label(label, style); } #else GUILayout.Label(label, style); #endif }
public static void EmptyLine() { GUIBTScript.EmptyLine(); }
public static bool UncommentValidate() { return(GUIBTScript.UncommentValidate()); }
public static void Uncomment() { GUIBTScript.SelectionUncomment(); }
public static bool OpenValidate() { return(GUIBTScript.OpenTaskValidate()); }
void OnParameterChange() { GUIBTScript.SetSourcesDirty(); }
public static bool PasteValidate() { return(GUIBTScript.PasteValidate()); }
public static void Paste() { GUIBTScript.Paste(forceAboveInsertion: false); }
public static void Cut() { GUIBTScript.Cut(); }
public static void Break_PointSet_ClearAll() { GUIBTScript.BreakPoint_ClearAll(); }
public static void Copy() { GUIBTScript.Copy(); }
public static void Break_PointSet_Fail() { GUIBTScript.BreakPoint_Set_Fail(); }
public static void Break_PointSet_Succeed() { GUIBTScript.BreakPoint_Set_Succeed(); }
public static void Open() { GUIBTScript.OpenTask(); }
public void OnGUI() { var node = this; GUINode._current = this; // Recompute rects when edit state has changed. if (GUIBTScript.isEventSafe) { if (isEdited == false && _isEditedPrev) { SetDirty(); } if (isEdited && _isEditedPrev == false) { GUIBTScript.SelectionClear(); } _isEditedPrev = isEdited; } if (node.nodeType == NodeType.TaskList) { OnGUI_TaskListSelector(); } else { if ((node.isSelected || node == GUIBTScript.cursorNode) && !isRectDirty && !isEdited) { OnGUI_OneBlock(); } else { OnGUI_ColoredNode(); } } // Edit parameter when left mouse click. bool isClicked = Event.current.isMouse && Event.current.type == EventType.MouseDown && Event.current.button == 0; var mpos = Event.current.mousePosition; if (!isRectDirty && !GUIBTScript.isCTRLPressed && isClicked && GUIBTScript.mode == GUIBTScript.Mode.Normal) { bool isParameterClicked = false; for (int i = 0; i < parameters.Count; i++) { var r = parameterRects[i]; var isWithinRect = r.Contains(mpos); parameters[i].isEdited = isWithinRect; if (isWithinRect) { isParameterClicked = true; } } if (this.rect.Contains(mpos) && !isParameterClicked) { bool isDoubleClicked = Time.realtimeSinceStartup - lastClickTime < 0.4f; lastClickTime = Time.realtimeSinceStartup; if (isDoubleClicked && this.nodeType == NodeType.Task && this.label.ToLower() != "tree") { GUIBTScript.OpenScript(this); } } } // On press Enter or Esc stop editing the parameter. if (Event.current.isKey && (Event.current.keyCode == KeyCode.Return || Event.current.keyCode == KeyCode.KeypadEnter || Event.current.keyCode == KeyCode.Escape)) { foreach (var p in parameters) { if (p.isEdited) { p.isEdited = false; } } } // Locate mouse position in rect. if (Event.current.type == EventType.Repaint) { if (rect.Contains(mpos)) { isMouseOver = true; if (GUIBTScript.cursorNode != node) { GUIBTScript.cursorNode = node; //GUIBTScript.current.redraw = true; } float f = 0.3f; var w = rect.width; var wb = w * f; var h = rect.height; var hb = h * f; if (mpos.y < rect.y + hb) { mouseHoverPosition = MouseHoverPosition.Above; } else if (mpos.y > rect.y + h - hb && node.line.children.Count == 0) { mouseHoverPosition = MouseHoverPosition.Below; } else if (mpos.x < rect.x + wb) { mouseHoverPosition = MouseHoverPosition.Left; } else if (mpos.x > rect.x + w - wb) { mouseHoverPosition = MouseHoverPosition.Right; } else if (nodeType == NodeType.Structural && node.line.nodes[0] == node) { mouseHoverPosition = MouseHoverPosition.Center; } } else { isMouseOver = false; } } else if (node != GUIBTScript.cursorNode) { mouseHoverPosition = MouseHoverPosition.None; } }
public static void Duplicate() { GUIBTScript.Duplicate(); }
void OnGUI_OneBlock() { GUINode node = this; var style = new GUIStyle(node.isSelected ? BTLSyntaxHighlight.style_selected : BTLSyntaxHighlight.style_running); //GUIStyle style = new GUIStyle(); bool displayInsert = false; if (!node.isSelected && (GUIBTScript.mode == GUIBTScript.Mode.MouseDrag || GUIBTScript.mode == GUIBTScript.Mode.InsertingNewNode)) { switch (node.mouseHoverPosition) { case MouseHoverPosition.Above: style = BTLSyntaxHighlight.style_insert_above; break; case MouseHoverPosition.Below: style = BTLSyntaxHighlight.style_insert_below; break; case MouseHoverPosition.Center: style = BTLSyntaxHighlight.style_insert_in; break; } displayInsert = true; } var sbLabel = new System.Text.StringBuilder(); if (displayInsert && mouseHoverPosition == MouseHoverPosition.Left) { sbLabel.Append("|"); //GUILayout.Label(BTLSyntaxHighlight.texture_insert_LeftRigth, GUILayout.ExpandWidth(false)); } sbLabel.Append(node.label); bool withParenthesis = parameters.Count > 0 && nodeType != NodeType.Comment; if (withParenthesis) { sbLabel.Append("("); } for (int i = 0; i < node.parameters.Count; i++) { var p = node.parameters[i]; if (nodeType == NodeType.Comment && p.value.Trim() == "") { sbLabel.Append("..."); } else { sbLabel.Append(p.value); if (withParenthesis && i + 1 < node.parameters.Count) { sbLabel.Append(", "); } } } if (withParenthesis) { sbLabel.Append(")"); } if (displayInsert && mouseHoverPosition == MouseHoverPosition.Right) { sbLabel.Append("|"); //GUILayout.Label(BTLSyntaxHighlight.texture_insert_LeftRigth, GUILayout.ExpandWidth(false)); } GUI.SetNextControlName(node.controlName); if (node.nodeType == NodeType.EmptyLine) { GUILayout.Label(node.label, style, GUILayout.ExpandWidth(true)); } else { GUILayout.Label(sbLabel.ToString(), style); } // Selection and drag start if (isMouseOver && Event.current.isMouse && Event.current.type == EventType.MouseDown) { if (GUIBTScript.isCTRLPressed) { if (this.isSelected) { GUIBTScript.SelectionRemove(node); } else { GUIBTScript.SelectionAdd(node); } } else { if (!isSelected) { GUIBTScript.SelectionClear(); } GUIBTScript.SelectionAdd(node); } GUI.FocusControl(node.controlName); } if (isMouseOver && Event.current.isMouse && Event.current.type == EventType.MouseUp && !GUIBTScript.isCTRLPressed && !GUIBTScript.isControlLocked) { GUIBTScript.SelectionClear(); GUIBTScript.SelectionAdd(node); GUI.FocusControl(node.controlName); } }
public static void Delete() { GUIBTScript.Delete(); }
public void OnGUI(bool isComment) { var p = this; var style = isComment? BTLSyntaxHighlight.style_comment: BTLSyntaxHighlight.style_value; if (p.isEdited) { #if UNITY_EDITOR var size = style.CalcSize(new GUIContent(p.value)); if (p._type == typeof(bool)) { var v = p.value.ToLower() == "true" ? 1 : 0; v = UnityEditor.EditorGUILayout.Popup(v, boolOptions, style, GUILayout.ExpandWidth(false), GUILayout.MaxWidth(60.0f)); p.value = v == 1 ? "true" : "false"; } else if (p._type == typeof(int)) { var v = UnityEditor.EditorGUILayout.IntField(int.Parse(p.value), style, GUILayout.ExpandWidth(false), GUILayout.Width(size.x)); p.value = v.ToString(); } else if (p._type == typeof(float)) { var v = UnityEditor.EditorGUILayout.FloatField(float.Parse(p.value), style, GUILayout.ExpandWidth(false), GUILayout.Width(size.x)); p.value = string.Format("{0:0.0#############}", v); } else if (p._type == typeof(string)) { if (isComment) { p.value = UnityEditor.EditorGUILayout.TextField(p.value, style, GUILayout.ExpandWidth(false), GUILayout.MinWidth(10.0f), GUILayout.Width(size.x)); } else { var v = p.value.Trim(); size = style.CalcSize(new GUIContent(v)); v = v.Substring(1, v.Length - 2); GUILayout.Label("\"", style); p.value = '"' + UnityEditor.EditorGUILayout.TextField(v, style, GUILayout.ExpandWidth(false), GUILayout.Width(size.x)) + '"'; GUILayout.Label("\"", style); } } if (p._type == typeof(Panda.EnumParameter)) { if (p._enumType == null) { var ti = GUIBTScript.GetTaskImplementation(GUINode._current); if (ti != null) { p._enumType = ti.parameterTypes[GUINode._currentParameterIndex]; } } if (p._enumType != null) { var enumVals = System.Enum.GetNames(p._enumType); string[] fulls = new string[enumVals.Length]; int v = 0; for (int i = 0; i < enumVals.Length; i++) { var full = p._enumType.FullName.Replace("+", ".") + "." + enumVals[i]; fulls[i] = full; if (full.EndsWith(value.Trim())) { v = i; } } size = style.CalcSize(new GUIContent(fulls[v])); v = UnityEditor.EditorGUILayout.Popup(v, fulls, style, GUILayout.ExpandWidth(false), GUILayout.Width(size.x)); p.value = fulls[v]; } else { GUILayout.Label("????", style); } } #endif } else { var label = isComment && p.value.Trim() == "" ? "..." : p.value; GUILayout.Label(label, style); } }
public static void CreateNode() { GUIBTScript.CreateNode(); }
public static void Comment() { GUIBTScript.SelectionComment(); }
void InitSourceInfos() { sourceInfos.Clear(); foreach (var src in bt.btSources) { sourceInfos.Add(new SourceInfo(src)); } var oldSourInfos = bt.sourceInfos; if (bt.sourceInfos == null || bt.sourceInfos.Length != size) { bt.sourceInfos = new InspectorGuiData[size]; for (int i = 0; i < size; ++i) { if (oldSourInfos != null && i < oldSourInfos.Length && oldSourInfos[i] != null) { bt.sourceInfos[i] = oldSourInfos[i]; } else { bt.sourceInfos[i] = new InspectorGuiData(); } } } sourceDisplays = SourceDisplay.MapGUILines(bt.btSources, bt.program, bt.pandaExceptions); if (sourceDisplays != null) { foreach (var sd in sourceDisplays) { if (sd != null) { sd.bt = bt; } } } if (bt != null && bt.scripts != null) { #if !PANDA_BT_FREE var guiBTScriptsList = new List <GUIBTScript>(); #endif for (int i = 0; i < bt.scripts.Length; i++) { #if !PANDA_BT_FREE var a = bt.scripts[i]; GUIBTScript b = null; if (guiBTScripts != null && i < guiBTScripts.Length && guiBTScripts[i] != null) { b = guiBTScripts[i]; } else { b = new GUIBTScript(bt, a, i); } if (a != null) { b.Parse(); } guiBTScriptsList.Add(b); #endif // Read line collapsed state from sourceInfos if (sourceDisplays != null && i < sourceDisplays.Length && sourceDisplays[i] != null) { var lines = sourceDisplays[i].flattenLines; var list = bt.sourceInfos[i].collapsedLines; foreach (var line in lines) { line.isFoldout = list.Contains(line.lineNumber); } } } #if !PANDA_BT_FREE guiBTScripts = guiBTScriptsList.ToArray(); InitBreakPoints(); bt.Apply(); #else bt.Apply(); #endif } }