public static void RefreshAllBehaviourTreeEditors() { if (SourceDisplay.refreshAllBehaviourTreeEditors != null) { SourceDisplay.refreshAllBehaviourTreeEditors(); } }
private void RenderLines(SourceDisplay sourceDisplay) { var stack = new Stack <BTLGUILine>(); var lines = sourceDisplay.lines; var orphans = sourceDisplay.orphans; for (int i = lines.Length - 1; i >= 0; i--) { stack.Push(lines[i]); } int orphanIdx = 0; int lastRenderedLine = 0; GUILayout.BeginVertical(); while (stack.Count > 0) { var line = stack.Pop(); while (orphanIdx < orphans.Length && lastRenderedLine < orphans[orphanIdx].lineNumber && orphans[orphanIdx].lineNumber < line.lineNumber) { RenderLine(orphans[orphanIdx]); if (!orphans[orphanIdx].isFoldout) { foreach (var c in orphans[orphanIdx].children) { RenderLine(c); } } ++orphanIdx; } RenderLine(line); lastRenderedLine = line.lineNumber; if (!line.isFoldout) { for (int i = line.children.Count - 1; i >= 0; i--) { stack.Push(line.children[i]); } } else { while (orphanIdx < orphans.Length && lastRenderedLine < orphans[orphanIdx].lineNumber && orphans[orphanIdx].lineNumber < line.lineNumberEnd) { ++orphanIdx; } } } GUILayout.EndVertical(); }
private void DisplayBTScript(int i) { GUIBTScript.isMouseHoverLineNumbers = false; bool isSourceAvailable = false; if (bt.scripts != null && i < bt.scripts.Length && bt.scripts[i] != null) { isSourceAvailable = true; } else if (bt.sourceInfos != null && i < bt.sourceInfos.Length && bt.sourceInfos[i] != null && bt.sourceInfos[i].btScript != null && bt.sourceInfos[i].btScript.Trim() != "") { isSourceAvailable = true; } if (isSourceAvailable && bt.sourceInfos[i].isFoldout) { #if !PANDA_BT_FREE if (!EditorApplication.isPlaying) { guiBTScripts[i].OnGUI(); } else { #endif SourceDisplay sourceDisplay = null; if (sourceDisplays != null && i < sourceDisplays.Length) { sourceDisplay = sourceDisplays[i]; } if (sourceDisplay != null) { sourceDisplay.DisplayCode(); } else { GUILayout.Label("Error parsing script. See console for details.", BTLSyntaxHighlight.style_failed); } #if !PANDA_BT_FREE } #endif } else if (bt.scripts != null && bt.scripts[i] != null && !bt.sourceInfos[i].isFoldout) { if (bt.sourceInfos[i].breakPoints.Count > 0) { bt.sourceInfos[i].breakPoints.Clear(); #if !PANDA_BT_FREE InitBreakPoints(); #endif } } }
void DebugBreak() { var node = BTNode.currentNode; _isBreakPointActive = node != null && ( node.previousStatus == Status.Ready && node.status != Status.Ready && breakPointStatus == Status.Running || node.status == Status.Succeeded && breakPointStatus == Status.Succeeded || node.status == Status.Failed && breakPointStatus == Status.Failed ); if (_isBreakPointActive) { SourceDisplay.RefreshAllBehaviourTreeEditors(); Debug.Break(); } }
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(); }
public void DisplayCode() { #if UNITY_EDITOR isPaused = UnityEditor.EditorApplication.isPaused; isPlaying = UnityEditor.EditorApplication.isPlaying; #endif SourceDisplay sourceDisplay = this; if (sourceDisplay != null) { SourceDisplay.current = sourceDisplay; SourceDisplay.currentSourceIndex = this.scriptIndex; switch (GUILayout.Toolbar(-1, new string[] { "-", "+" }, GUILayout.ExpandWidth(false))) { case 0: sourceDisplay.SetIsFoldoutAll(true); break; case 1: sourceDisplay.SetIsFoldoutAll(false); break; } RenderLines(sourceDisplay); } }
public static SourceDisplay Analyse(BTLTokenizer.Token[] tokens, int sourceIndex) { if (tokens == null) { return(null); } SourceDisplay sourceDisplay = new SourceDisplay(sourceIndex); int lineNumber = 1; var lines = new List <BTLGUILine>(); var orphans = new List <BTLGUILine>(); var parentStack = new Stack <BTLGUILine>(); BTLGUILine current = new BTLGUILine(); current.lineNumber = lineNumber; foreach (var t in tokens) { bool isComment = current.tokens.Count > 0 && current.tokens[0].type == BTLTokenizer.TokenType.Comment; if (t.type == BTLTokenizer.TokenType.EOL && current.tokens.Count == 0) {// Empty line orphans.Add(current); ++lineNumber; current = new BTLGUILine(); current.indent = 0; current.lineNumber = lineNumber; } else if (t.type == BTLTokenizer.TokenType.EOL && isComment) {// End of comments ++lineNumber; orphans.Add(current); current = new BTLGUILine(); current.indent = 0; current.lineNumber = lineNumber; } else if (t.type == BTLTokenizer.TokenType.EOL && !isComment) {// End of line containing nodes ++lineNumber; ParentOrAddToLines(lines, parentStack, current); if (current.tokens.Count > 0) { parentStack.Push(current); } current = new BTLGUILine(); current.indent = 0; current.lineNumber = lineNumber; } else if (t.type == BTLTokenizer.TokenType.Indent && current.tokens.Count == 0) { current.indent++; } else if (t.type == BTLTokenizer.TokenType.Comment) { var commentLines = t.content.Split('\n'); if (commentLines.Length > 0) { current.tokens.Add(GenerateCommentToken(commentLines[0], current.lineNumber)); for (int i = 1; i < commentLines.Length; ++i) { ++lineNumber; var commentline = commentLines[i]; var commentGUILine = GenerateCommentLineGui(commentline, current.indent, lineNumber); current.children.Add(commentGUILine); } } } else { current.tokens.Add(t); } } ParentOrAddToLines(lines, parentStack, current); sourceDisplay.lines = lines.ToArray(); sourceDisplay.orphans = orphans.ToArray(); ProcessFoldable(sourceDisplay.lines); ProcessFoldable(sourceDisplay.orphans); return(sourceDisplay); }
public static SourceDisplay[] MapGUILines(BTSource[] btlSources, BTProgram program, PandaScriptException[] pandaExceptions) { if (btlSources == null || program == null) { return(null); } var sourceDisplays = new SourceDisplay[btlSources.Length]; for (int i = 0; i < btlSources.Length; i++) { if (btlSources[i] == null) { continue; } SourceDisplay sourceDisplay = null; var tokens = BTLAssetManager.GetBTLTokens(btlSources, btlSources[i]); sourceDisplay = BTLGUILine.Analyse(tokens, i); sourceDisplays[i] = sourceDisplay; CodeMap codemap = null; if (program.codemaps != null && i < program.codemaps.Length) { codemap = program.codemaps[i]; } if (codemap != null) { BTLGUILine.MapNodes(sourceDisplay.lines, codemap); var lines = sourceDisplay.flattenLines; foreach (var line in lines) { foreach (var n in line.btnodes) { var task = n as BTTask; if (task != null && task.boundState != BoundState.Bound) { line.hasErrors = true; } } } } if (sourceDisplay != null) { var lines = sourceDisplay.flattenLines; foreach (var line in lines) { foreach (var pandaException in pandaExceptions) { if (pandaException != null) { if (pandaException.filePath == btlSources[i].url && line.lineNumber == pandaException.lineNumber) { line.hasErrors = true; } } } } } } return(sourceDisplays); }
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 } }