private void GUI_tokens(BTLGUILine line) { GUIStyle style = BTLSyntaxHighlight.style_label; for (int i = 0; i < line.tokens.Count; ++i) { BTNode node = null; if (i < line.btnodes.Count) { node = line.btnodes[i]; } var token = line.tokens[i]; style = BTLSyntaxHighlight.GetTokenStyle(token); if (bt.program == null || bt.program.codemaps == null) { style = BTLSyntaxHighlight.style_comment; } if (bt.exceptions.Length > 0) { style = BTLSyntaxHighlight.style_comment; } if (line.hasErrors) { style = BTLSyntaxHighlight.style_failed; } GUI_token(style, node, token); }// for tokens }
private void GUI_tokens_live(BTLGUILine line) { GUIStyle style = BTLSyntaxHighlight.style_label; for (int i = 0; i < line.tokens.Count; ++i) { BTNode node = null; if (i < line.btnodes.Count) { node = line.btnodes[i]; } var token = line.tokens[i]; style = BTLSyntaxHighlight.GetTokenStyle(token); if (node != null) { var nodeStyle = GetNodeStyle(node); if (nodeStyle != null) { style = nodeStyle; } } if (bt.exceptions.Length > 0) { style = BTLSyntaxHighlight.style_comment; } if (line.hasErrors) { style = BTLSyntaxHighlight.style_failed; } GUI_token(style, node, token); // debug info bool isLastNodeToken = node != null && (i + 1 >= line.btnodes.Count || node != line.btnodes[i + 1]); if (isLastNodeToken && node.debugInfo != null && node.debugInfo != "") { GUILayout.Label(string.Format("[{0}]", node.debugInfo.Replace("\t", " ")), BTLSyntaxHighlight.style_comment); } }// for tokens }
public void OnEnable() { Undo.undoRedoPerformed += UndoRedoPerformed; SourceDisplay.refreshAllBehaviourTreeEditors = RefreshAll; if (!instances.Contains(this)) { instances.Add(this); } BTLSyntaxHighlight.InitializeColors(); bt = (BehaviourTree)target; if (bt != null && bt.scripts != null) { size = bt.scripts.Length; } else if (bt.scripts == null && bt.program == null) { bt.scripts = new TextAsset[size]; } if (bt != null && bt.scripts == null && bt.program != null) {// When 'BehaviourTree.Compile(...)' has been used. size = bt.btSources.Length; } if (bt != null && bt.program == null) { bt.Compile(); } if (bt != null) { bt._isInspected = true; } InitSourceInfos(); bt.OnTicked += this.Repaint; }
public override void OnInspectorGUI() { BTLSyntaxHighlight.InitializeStyles(); CheckComponentChanges(); EditorGUILayout.BeginVertical(); if (bt != null && bt.exceptions.Length > 0 && Application.isPlaying) { GUILayout.BeginHorizontal(); var style = BTLSyntaxHighlight.style_failed; GUILayout.Label("This program contains errors. Please check console for details.", style); GUILayout.EndHorizontal(); } EditorGUI.BeginChangeCheck(); EditorGUILayout.BeginHorizontal(); bt.tickOn = (BehaviourTree.UpdateOrder)EditorGUILayout.EnumPopup("Tick On:", bt.tickOn); bt.autoReset = GUILayout.Toggle(bt.autoReset, "Repeat Root"); EditorGUILayout.EndHorizontal(); DisplayStatus(); var newSize = EditorGUILayout.IntField("Count", size); if (EditorGUI.EndChangeCheck()) { RecordUndo(); if (size != newSize) { size = newSize; if (size < 0) { size = 0; } // Resize the TextAsset array TextAsset[] old = new TextAsset[bt.scripts.Length]; bt.scripts.CopyTo(old, 0); bt.scripts = new TextAsset[size]; for (int i = 0; i < size; ++i) { bt.scripts[i] = i < old.Length ? old[i] : null; } bt.Apply(); bt.Compile(); Clear_guiBTScripts(); InitSourceInfos(); Refresh(); } } EditorGUILayout.EndVertical(); if (bt.scripts != null || bt.btSources.Length > 0) { for (int i = 0; i < size; ++i) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.BeginHorizontal(GUILayout.MaxWidth(1.0f)); var isFoldout = EditorGUILayout.Foldout(bt.sourceInfos[i].isFoldout, ""); if (isFoldout != bt.sourceInfos[i].isFoldout) { RecordUndo(); bt.sourceInfos[i].isFoldout = isFoldout; } EditorGUILayout.EndHorizontal(); string label = null; #if !PANDA_BT_FREE if (guiBTScripts != null) { label = string.Format("BT Script {0}{1}", i, guiBTScripts[i].isModified ? "*" : ""); } else { label = string.Format("BT Script {0}", i); } #else label = string.Format("BT Script {0}", i); #endif GUILayout.Label(label, GUILayout.MaxWidth(100.0f)); if (bt.scripts != null) { var newScript = EditorGUILayout.ObjectField(bt.scripts[i], typeof(TextAsset), allowSceneObjects: false) as TextAsset; if (bt.scripts[i] != newScript) { RecordUndo(); bt.scripts[i] = newScript; if (sourceInfos != null && i < sourceInfos.Count) { sourceInfos[i] = null; } Clear_guiBTScripts(); bt.Apply(); bt.Compile(); InitSourceInfos(); Refresh(); } } else { GUILayout.Label("[compiled from string]"); } #if !PANDA_BT_FREE if (guiBTScripts != null) { GUI.enabled = guiBTScripts[i].isModified; switch (GUILayout.Toolbar(-1, new string[] { "Revert", "Apply" })) { case 0: guiBTScripts[i].Revert(); bt.Compile(); break; case 1: guiBTScripts[i].SaveToFile(); break; } GUI.enabled = true; } #endif EditorGUILayout.EndHorizontal(); DisplayBTScript(i); } } }