示例#1
0
    public Sequence Initialize(List<BTObject> taskSequence)
    {
        this.TaskSequence = taskSequence;
        this.TaskSequence = this.TaskSequence.OrderByDescending( x => x.Priority ).ToList();

        this.currentTask = this.TaskSequence[0];

        return this;
    }
示例#2
0
    public Selector Initialize(List<BTObject> taskSelectors)
    {
        this.TaskSelectors = taskSelectors;
        this.TaskSelectors = this.TaskSelectors.OrderByDescending( x => x.Priority ).ToList();

        this.currentTask = this.TaskSelectors[0];

        return this;
    }
示例#3
0
    static public BehaviourState ActionHasAppeared(MonoBehaviour mb)
    {
        BTObject btObject = ( BTObject )mb;

        btObject.count = 0;

        Debug.Log("has appeared");
        return(BehaviourState.succeeded);
    }
    public Sequence Initialize(List<BTObject> taskSequence)
    {
        if (taskSequence == null)
            throw new System.ArgumentNullException("taskSequence", "Cannot supply null taskSequence to Sequence class");

        this.TaskSequence = taskSequence;
        this.TaskSequence = TaskSequence.OrderByDescending( x => x.Priority ).ToList();

        this.currentTask = this.TaskSequence[0];

        return this;
    }
    public Selector Initialize(List<BTObject> taskSelectors)
    {
        if (taskSelectors == null)
            throw new System.ArgumentNullException("taskSelectors", "Cannot supply taskSelectors as null to Selector Initialize");

        this.TaskSelectors = taskSelectors;
        this.TaskSelectors = TaskSelectors.OrderByDescending( x => x.Priority ).ToList();

        this.currentTask = this.TaskSelectors[0];

        return this;
    }
示例#6
0
    public void Awake()
    {
        btTree       = new BehaviourTree();
        baseNodeData = btTree.buildTree(btTreeData, typeof(BTObject));

        btObjectList = new BTObject[count];

        for (int i = 0; i < count; ++i)
        {
            GameObject go = ( GameObject )Instantiate(testObject, Vector3.zero, Quaternion.identity);
            btObjectList[i] = go.GetComponent <BTObject>();
            btObjectList[i].init(btTree, baseNodeData);
        }
    }
示例#7
0
    public override void StartObject()
    {
        if (this.TaskSequence == null || this.TaskSequence.Count <= 0) {
            Debug.LogWarning("Sequence has no Task Sequence list set");
            this.CurrentState = TaskState.TASK_CANCELLED;
        }
        else {
            if (this.CurrentState == TaskState.TASK_WAITING) {
                this.CurrentState = TaskState.TASK_RUNNING;
                this.currentTask = this.TaskSequence[0];
                this.currentTask.StartObject();

                if (this.Counter > 1 && !this.Looping)
                    this.Looping = true;
            }
        }
    }
示例#8
0
    static public BehaviourState ActionIsReadyToGo(MonoBehaviour mb)
    {
        BTObject btObject = ( BTObject )mb;

        if (btObject.count < 100)
        {
            if (btObject.count == 0)
            {
                Debug.Log("is waiting");
            }

            ++btObject.count;
            return(BehaviourState.running);
        }

        Debug.Log("is ready to go");
        return(BehaviourState.succeeded);
    }
示例#9
0
 public void SetId(BTObject btObject)
 {
     this.id = btObject.id;
 }
示例#10
0
 public void SetObjectId(BTObject btObject)
 {
     btObject.id = this.id;
 }
示例#11
0
    private void Update()
    {
        if (this.CurrentState == TaskState.TASK_RUNNING) {
            if (this.currentTask.CurrentState == TaskState.TASK_DONE) {
                this.currentTask = getNextTask();

                if (this.currentTask == null) {
                    this.CurrentState = TaskState.TASK_DONE;
                }
                else {
                    this.currentTask.StartObject();
                }
            }
            else if (this.currentTask.CurrentState == Task.TaskState.TASK_ABORTED || this.currentTask.CurrentState == Task.TaskState.TASK_CANCELLED) {
                this.CurrentState = this.currentTask.CurrentState;
            }
        }
        else if (this.CurrentState != TaskState.TASK_WAITING) {
            if (!this.bDoneRunning) {
                if (this.Looping) {
                    if (this.Counter <= 1 || this.counterCount < this.Counter) {
                        this.counterCount++;
                        this.CurrentState = TaskState.TASK_WAITING;

                        foreach (BTObject task in this.TaskSequence) {
                            task.bDoneRunning = false;
                            task.CurrentState = TaskState.TASK_WAITING;
                        }
                    }
                    else {
                        this.Looping = false;
                        this.bDoneRunning = true;
                    }
                }
                else
                    this.bDoneRunning = true;
            }
        }
    }
    public override void StartObject()
    {
        if (this.TaskSelectors == null || this.TaskSelectors.Count <= 0) {
            Debug.LogWarning("Selector has no Task Selector list set");
            this.CurrentState = TaskState.TASK_CANCELLED;
        }
        else {
            if (this.CurrentState == TaskState.TASK_WAITING) {
                this.CurrentState = TaskState.TASK_RUNNING;
                this.currentTask = this.TaskSelectors[0];
                this.currentTask.StartObject();

                if (this.Counter > 1 && !this.Looping)
                    this.Looping = true;

                if (BTName == "BTObject")
                    BTName = "Selector";

                if (bPaused)
                    bPaused = false;
            }
        }
    }