private static Node CreateTaskLayoutInfos(BehaviorTreeState tree, uint taskId) { var task = (TaskState)tree.Repository.States[TaskState.GetId(taskId)]; var node = new Node() { Task = task }; node.LaneWidth = EditorConfiguration.NodeSize.x + EditorConfiguration.TaskNodeMinSpace.x / 2; if (!node.Task.IsCollapsed) { if (node.Task.Desc is DecoratorTaskDescWrapper) { var childTaskId = ((DecoratorTaskDescWrapper)node.Task.Desc).ChildTaskId; if (childTaskId > 0) { var childTaskInfo = CreateTaskLayoutInfos(tree, childTaskId); node.Children = new[] { childTaskInfo }; node.LaneWidth = childTaskInfo.LaneWidth; } } else if (node.Task.Desc is CompositeTaskDescWrapper) { var childTaskIds = ((CompositeTaskDescWrapper)node.Task.Desc).ChildTaskIds; if (childTaskIds.Count > 0) { node.Children = (childTaskIds.Select(childTaskId => CreateTaskLayoutInfos(tree, childTaskId))).ToArray(); node.LaneWidth = node.Children.Sum(i => i.LaneWidth); } } } return(node); }
public DecoratorTaskNode(EditorDomain domain, EditorComponent parent, TaskState task) : base(domain, parent, task) { }
private void OnCreateTaskCommand(CreateTaskCommand command) { var parent = Repository.States[command.Id]; var parentTaskId = 0u; if (parent is BehaviorTreeState) { var tree = (BehaviorTreeState)parent; if (tree.RootTaskId > 0) { parent.ApplyEvent(new TaskNotCreatedEvent(command.Id) { Reason = "Behavior tree already has root task" }); return; } } else if (parent is TaskState) { var task = (TaskState)parent; if (task.Desc is LeafTaskDescWrapper) { parent.ApplyEvent(new TaskNotCreatedEvent(command.Id) { Reason = "Leaf task cannot have child task" }); return; } else if (task.Desc is DecoratorTaskDescWrapper) { var desc = (DecoratorTaskDescWrapper)task.Desc; if (desc.ChildTaskId != 0) { parent.ApplyEvent(new TaskNotCreatedEvent(command.Id) { Reason = "Decorator task can only has one child task" }); return; } } parentTaskId = task.Desc.Id; } else { throw new NotSupportedException(command.Id); } { var tree = (BehaviorTreeState)Repository.States[BehaviorTreeState.GetId()]; TaskDescWrapper taskDescWrapper; if (typeof(ILeafTaskDesc).IsAssignableFrom(command.TaskType)) { taskDescWrapper = new LeafTaskDescWrapper(); } else if (typeof(IDecoratorTaskDesc).IsAssignableFrom(command.TaskType)) { taskDescWrapper = new DecoratorTaskDescWrapper(); } else if (typeof(ICompositeTaskDesc).IsAssignableFrom(command.TaskType)) { taskDescWrapper = new CompositeTaskDescWrapper(); } else { throw new NotSupportedException(command.TaskType.ToString()); } taskDescWrapper.Id = tree.NextTaskId; taskDescWrapper.CustomDesc = (ITaskDesc)Activator.CreateInstance(command.TaskType); var taskState = new TaskState(Domain, TaskState.GetId(tree.NextTaskId)); taskState.ParentTaskId = parentTaskId; taskState.Desc = taskDescWrapper; parent.ApplyEvent(new TaskCreatedEvent(command.Id) { NewTask = taskState }); } }
public CompositeTaskNode(EditorDomain domain, EditorComponent parent, TaskState task) : base(domain, parent, task) { }
private void CreateChildTaskNode(uint taskId) { var task = (TaskState)Repository.States[TaskState.GetId(taskId)]; RootView.Children.Add(Create(RootView, task)); }