private void DoTransition(Node node) { // This code is borrowed from ICode(https://www.assetstore.unity3d.com/en/#!/content/13761) Node[] childNodes = node.childNodes; if (node.childNodes != null) { for (int i = 0; i < childNodes.Length; i++) { Node child = childNodes[i]; child.position.width = NodeDrawer.GetMaxWidthContents(child); child.position.height = NodeDrawer.GetMaxHeightContents(child); if (EditorApplication.isPlaying) { if (CompareLockedNodes(child)) { DrawConnection(node.position.center, new Vector3(child.position.center.x, child.position.yMin - 7), Color.cyan, 1, false, true); } else { DrawConnection(node.position.center, new Vector3(child.position.center.x, child.position.yMin - 7), Color.gray, 1, false, false, 1); } } else { DrawConnection(node.position.center, new Vector3(child.position.center.x, child.position.yMin - 7), Color.white, 1, false, false, 1); } } } }
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(); } } }