private static void DrawNode(Node node, bool selected, Texture2D iconImage, int boxColor) { float sharedHeight = node.position.yMin + 15; DrawDecorators(node, ref sharedHeight); Rect insideMainNode = node.position; insideMainNode.xMin += 7; insideMainNode.xMax -= 7; insideMainNode.yMin = sharedHeight; insideMainNode.yMax = sharedHeight + 32 + GetCommentHeight(node.comment); GUIStyle insideMainNodeStyle = BehaviorTreeEditorStyles.GetNodeStyle(boxColor, false); GUI.Box(insideMainNode, "", insideMainNodeStyle); int?myIndex = BehaviorTreeEditorUtility.GetMyIndex(node); if (myIndex != null) { float circleIconWidth = circleIcon.width * 1.1f; float circleIconHeight = circleIcon.height * 1.1f; Rect indexRect = new Rect(insideMainNode.xMax - circleIconWidth / 2f + 12, insideMainNode.yMin - circleIconHeight / 2f, circleIconWidth, circleIconHeight); GUI.DrawTexture(indexRect, circleIcon); indexRect.xMin -= 2; indexRect.yMin -= 2; GUI.Label(indexRect, "<color=white>" + (myIndex + 1).ToString() + "</color>", BehaviorTreeEditorStyles.nodeIndexLabel); } Rect iconRect = node.position; iconRect.x = node.position.xMin + 7; iconRect.y = sharedHeight - 1; GUI.Label(iconRect, iconImage); Rect nameRect = node.position; nameRect.x = node.position.xMin + 42; nameRect.y = sharedHeight + 5; GUI.Label(nameRect, "<color=white>" + node.Name + "</color>", BehaviorTreeEditorStyles.nodeBoxNameNormalStyle); GUIContent commentContent = new GUIContent(node.comment); Rect commentRect = node.position; commentRect.x = node.position.xMin + 7; commentRect.y = sharedHeight + 30; commentRect.width = BehaviorTreeEditorStyles.nodeBoxCommentStyle.CalcSize(commentContent).x + 10; GUI.Label(commentRect, "<color=white>" + node.comment + "</color>", BehaviorTreeEditorStyles.nodeBoxCommentStyle); sharedHeight += insideMainNode.yMax - insideMainNode.yMin + 5; DrawServices(node, sharedHeight); }
private static void DrawDecorators(Node node, ref float height) { for (int i = 0; i < node.decorators.Length; i++) { Decorator decorator = node.decorators[i]; Rect decoratorRect = node.position; decoratorRect.xMin += 7; decoratorRect.xMax -= 7; decoratorRect.yMin = height; decoratorRect.yMax = height + 32 + GetCommentHeight(decorator.comment); GUIStyle decoratorStyle = BehaviorTreeEditorStyles.GetNodeStyle((int)NodeColor.Blue, BehaviorTreeEditor.CompareSelectedDecorators(decorator)); if (EditorApplication.isPlaying) { decoratorStyle = BehaviorTreeEditorStyles.GetNodeStyle(BehaviorTreeEditor.CheckThisDecoratorClosed(decorator) ? (int)NodeColor.Red : (int)NodeColor.Blue, BehaviorTreeEditor.CompareSelectedDecorators(decorator)); } GUI.Box(decoratorRect, "", decoratorStyle); Rect decoratorIconRect = node.position; decoratorIconRect.x = node.position.xMin + 7; decoratorIconRect.y = height - 1; GUI.Label(decoratorIconRect, decoratorIcon); Rect decoratorNameRect = node.position; decoratorNameRect.x = node.position.xMin + 42; decoratorNameRect.y = height + 5; GUI.Label(decoratorNameRect, "<color=white>" + decorator.Name + "</color>", BehaviorTreeEditorStyles.nodeBoxNameNormalStyle); GUIContent decoratorCommentContent = new GUIContent(decorator.comment); Rect decoratorCommentRect = node.position; decoratorCommentRect.x = node.position.xMin + 7; decoratorCommentRect.y = height + 30; decoratorCommentRect.width = BehaviorTreeEditorStyles.nodeBoxCommentStyle.CalcSize(decoratorCommentContent).x + 10; GUI.Label(decoratorCommentRect, "<color=white>" + decorator.comment + "</color>", BehaviorTreeEditorStyles.nodeBoxCommentStyle); height += decoratorRect.yMax - decoratorRect.yMin + 5; } }
private static void DrawServices(Node node, float height) { if (node is Composite) { Composite composite = node as Composite; for (int i = 0; i < composite.services.Length; i++) { Service service = composite.services[i]; Rect serviceRect = node.position; serviceRect.xMin += 7 + 13; serviceRect.xMax -= 7; serviceRect.yMin = height; serviceRect.yMax = height + 32 + GetCommentHeight(service.comment); GUIStyle serviceStyle = BehaviorTreeEditorStyles.GetNodeStyle((int)NodeColor.Aqua, BehaviorTreeEditor.CompareSelectedServices(service)); GUI.Box(serviceRect, "", serviceStyle); Rect serviceIconRect = node.position; serviceIconRect.x = node.position.xMin + 7 + 13; serviceIconRect.y = height - 1; GUI.Label(serviceIconRect, serviceIcon); Rect serviceNameRect = node.position; serviceNameRect.x = node.position.xMin + 42 + 13; serviceNameRect.y = height + 5; GUI.Label(serviceNameRect, "<color=white>" + service.Name + "</color>", BehaviorTreeEditorStyles.nodeBoxNameNormalStyle); GUIContent serviceCommentContent = new GUIContent(service.comment); Rect serviceCommentRect = node.position; serviceCommentRect.x = node.position.xMin + 7 + 13; serviceCommentRect.y = height + 30; serviceCommentRect.width = BehaviorTreeEditorStyles.nodeBoxCommentStyle.CalcSize(serviceCommentContent).x + 10; GUI.Label(serviceCommentRect, "<color=white>" + service.comment + "</color>", BehaviorTreeEditorStyles.nodeBoxCommentStyle); } } }
private void DoNode(Node node) { GUIStyle style = BehaviorTreeEditorStyles.GetNodeStyle((int)NodeColor.Grey, _selection.Contains(node)); if (EditorApplication.isPlaying && CompareLockedNodes(node)) { style = BehaviorTreeEditorStyles.GetNodeStyle((int)NodeColor.Yellow, _selection.Contains(node)); } node.position.width = NodeDrawer.GetMaxWidthContents(node); node.position.height = NodeDrawer.GetMaxHeightContents(node); GUI.Box(node.position, "", style); NodeDrawer.DrawNode(node, _selection.Contains(node)); if (node.hasTopSelector) { Rect rect = node.position; rect.x += 20; rect.width = rect.width - 40; rect.height = 10; GUIStyle topSelectorStyle = BehaviorTreeEditorStyles.GetSelectorStyle(false); if (GUI.Button(rect, "", topSelectorStyle) && !EditorApplication.isPlayingOrWillChangePlaymode) { if (_fromNode == null) { _fromNode = node; _isTopSelect = true; if (node.parentNode != null) { node.parentNode.childNodes = ArrayUtility.Remove <Node>(node.parentNode.childNodes, node); node.parentNode = null; } } else { if (!_isTopSelect && !ArrayUtility.Contains(_fromNode.childNodes, node)) { AddTransition(_fromNode, node); } _fromNode = null; } GUIUtility.hotControl = 0; GUIUtility.keyboardControl = 0; _selection.Clear(); _selection.Add(node); UpdateUnitySelection(); } } if (node.hasBotSelector) { Rect rect = node.position; rect.x += 20; rect.y += rect.height - 14; rect.width = rect.width - 40; rect.height = 10; GUIStyle botSelectorStyle = BehaviorTreeEditorStyles.GetSelectorStyle(false); if (GUI.Button(rect, "", botSelectorStyle) && !EditorApplication.isPlayingOrWillChangePlaymode) { if (_fromNode == null) { _fromNode = node; _isTopSelect = false; } else { if (_isTopSelect && !ArrayUtility.Contains(node.childNodes, _fromNode)) { AddTransition(node, _fromNode); } _fromNode = null; } GUIUtility.hotControl = 0; GUIUtility.keyboardControl = 0; _selection.Clear(); _selection.Add(node); UpdateUnitySelection(); } } }