示例#1
0
	public void OnBehaviorTreeChanged()
	{
		if (_currentNode.Value.IsAlive)
		{
			_rootNode = new BehaviorNodeDrawer(this, null, _currentNode.Value.Target, 60f, 10f);
			RecalculateScrollHeight();
		}
		else
		{
			_rootNode = null;
		}

		
	}
示例#2
0
	public BehaviorNodeDrawer(BehaviorTreeWindow behaviorTreeWindow, BehaviorNodeDrawer parentNode, INode nodeToDraw, float xPos, float yPos)
	{
		this._originalPos = new Vector2(xPos, yPos);
		this._behaviorTreeWindow = behaviorTreeWindow;
		this._parentNode = parentNode;
		
		var regionDecoratorNode = nodeToDraw as EditorRegionDecoratorNode;
		if (regionDecoratorNode != null)
		{
			_groupDrawer = new BehaviorGroupDrawer(behaviorTreeWindow, this, regionDecoratorNode, this);
			nodeToDraw = regionDecoratorNode.getChildNode();
		}

		_windowRect = new Rect(xPos, yPos, MIN_WIDTH, MIN_HEIGHT + nodeToDraw.GetGUIPropertyHeight());					
		_nodeToDraw = nodeToDraw;

		var leafNode = nodeToDraw as ILeafNode;
		if (leafNode != null)
		{
			type = VisualNodeType.LeafNode;
			_childrenNodes = new BehaviorNodeDrawer[0];
		}

		var decoratorNode = nodeToDraw as IDecoratorNode;
		if (decoratorNode != null)
		{
			type = VisualNodeType.DecoratorNode;

			_childrenNodes = new BehaviorNodeDrawer[1]
			{
				new BehaviorNodeDrawer(behaviorTreeWindow, this, decoratorNode.getChildNode(), _windowRect.x + INITIAL_HORIZONTAL_SPACING + MIN_WIDTH, _windowRect.y)
			};
		}

		var compositeNode = nodeToDraw as ICompositeNode;
		if (compositeNode != null)
		{
			type = VisualNodeType.CompositeNode;

			var compositeChilds = compositeNode.getChildNodes();

			_childrenNodes = new BehaviorNodeDrawer[compositeChilds.Length];

			for (int i = 0; i < compositeChilds.Length; i++)
			{
				_childrenNodes[i] = new BehaviorNodeDrawer(behaviorTreeWindow, this, compositeChilds[i], _windowRect.x + INITIAL_HORIZONTAL_SPACING + MIN_WIDTH, _windowRect.y);
			}
		}

		if (_groupDrawer != null)
			_groupDrawer.Init();

		var aggregatedHeight = 0f;

		for (int i = 0; i < _childrenNodes.Length; i++)
		{
			_childrenNodes[i].MoveVertical(aggregatedHeight);

			aggregatedHeight += _childrenNodes[i].GetCombinedHeight();
		}

		_windowTitle = _nodeToDraw.GetType().Name.Replace("Node", "").Replace("Decorator", "").Replace("Composite", "");
	}
示例#3
0
	public BehaviorGroupDrawer(BehaviorTreeWindow behaviorTreeWindow, BehaviorNodeDrawer parentNode, EditorRegionDecoratorNode childNode, BehaviorNodeDrawer childNodeDrawer)
	{
		this._behaviorTreeWindow = behaviorTreeWindow;

		_parentNode = parentNode;
		_childNode = childNode;
		_childNodeDrawer = childNodeDrawer;

		_label = childNode.label;

		_isExpanded = childNode.startExpanded;
	}
示例#4
0
	private void DrawToolsWindow(int id)
	{
		GUILayout.Label("Base Settings", EditorStyles.boldLabel);

		if (GUILayout.Button("Reset Tree"))
		{
			_rootNode = null;
			
			_currentNode = new KeyValuePair<string, WeakReferenceT<INode>>("", new WeakReferenceT<INode>(null));
			_currentContext = new WeakReferenceT<BehaviorContext>(null);

			if (_contextDrawer != null)
			{
				_contextDrawer.behaviorContext = _currentContext;
			}
		}

		if (_currentContext.Target != null)
		{
			if (GUILayout.Button("Reset uses"))
			{
				var state = _currentContext.Target.state;

				foreach (var baseNodeState in state.Values)
				{
					baseNodeState.timesFailure = 0;
					baseNodeState.timesRunning = 0;
					baseNodeState.timesSuccess = 0;
				}
			}
		}

		GUI.DragWindow();
	}