Example #1
0
            /// <summary>
            /// 简单粗暴版RemoveTask,将待删除的节点或子树与parent解除父子关系,重新初始化过taskList、parentIndexList和parentIndexMap
            /// </summary>
            /// <param name="taskIndex"></param>
            /// <returns></returns>
            public bool RemoveTask(int taskIndex)
            {
                if (-1 < taskIndex && taskList.Count > taskIndex)
                {
                    Task task = taskList[taskIndex];

                    int parentIndex = parentIndexMap[taskIndex];

                    // TOTHINK : 析构自己和所有子节点
                    // TODO STH.

                    if (-1 != parentIndex)
                    {
                        ParentTask parentTask = taskList[parentIndex] as ParentTask;
                        parentTask.RemoveChild(task);
                        taskList.Clear();
                        parentIndexList.Clear();
                        parentIndexMap.Clear();
                        InitalBTStructureData(rootTask);
                    }
                    else
                    {
                        // 根结点,整棵树删掉
                        if (taskIndex == 0)
                        {
                            rootTask = null;
                            taskList.Clear();
                            parentIndexList.Clear();
                            parentIndexMap.Clear();
                        }
                        else
                        {
#if UNITY_EDITOR
                            Debug.LogWarning("BehaviorManager.BehaviorTree RemoveTask ERROR : the child has no parent and child is not a roottask.");
#endif
                        }
                    }
                }
                else
                {
                    return(false);
                }
                return(true);
            }