Пример #1
0
    void Start()
    {
        agent = GetComponent <NavMeshAgent>();


        var bb = UBTContext.Instance.GetGlobalBlackboard("DefaultBB");
        //bb.Set<Transform>("target", target);

        var idleSeq = new Sequence().OpenBranch(
            new Log("idle")
            );

        var chaseSelector = new Selector().OpenBranch(
            new Condition(() => (target.position - transform.position).sqrMagnitude >= .1f * .1f).Decorate(new MoveTo(agent, "target")),
            new Log("wait")
            );

        var seekCondition = new BlackboardCondition <Transform>("target", Operator.IS_NOT_SET, null, ObserverAborts.BOTH).Decorate(idleSeq);

        var selector = new Selector().OpenBranch(
            seekCondition,
            chaseSelector
            );

        var service = new DefaultService(UpdateStatus).Decorate(selector);

        m_Root = new Root(bb).Decorate(service);

#if UNITY_EDITOR
        UBTDebugger debugger = gameObject.AddComponent <UBTDebugger>();
        debugger.behaviorTree = m_Root;
#endif
        //m_Root.RepeatRoot = false;
        m_Root.Start();
    }
Пример #2
0
 public override Decorator CreateDecoratorNode(long unitId, NP_RuntimeTree runtimeTree, Node node)
 {
     this.m_BlackboardConditionNode = new BlackboardCondition(this.NPBalckBoardRelationData.BBKey,
                                                              this.Ope,
                                                              this.NPBalckBoardRelationData.NP_BBValue, this.Stop, node);
     //此处的value参数可以随便设,因为我们在游戏中这个value是需要动态改变的
     return(this.m_BlackboardConditionNode);
 }
    void Start()
    {
        var bb  = UBTContext.Instance.GetGlobalBlackboard("DefaultBB");
        var sut = new BlackboardCondition <TestType>("Key1", Operator.IS_SET).Decorate(new Log("yahaha"));

        m_Root = new Root(bb).Decorate(sut);

#if UNITY_EDITOR
        UBTDebugger debugger = gameObject.AddComponent <UBTDebugger>();
        debugger.behaviorTree = m_Root;
#endif
        //m_Root.RepeatRoot = false;
        m_Root.Start();
    }
    void Start()
    {
        var bb = UBTContext.Instance.GetGlobalBlackboard("DefaultBB");

        bb.Set("energy", 10);
        bb.Set("sleep", false);

        var working = new Sequence().OpenBranch(
            new Wait(1f),
            new Actions(() => bb.Get <int>("energy").Value--),
            new Log("working")
            );

        var eating = new Sequence().OpenBranch(
            new Wait(1f),
            new Actions(() => bb.Get <int>("energy").Value++),
            new Log("eating")
            );

        var sleep = new Sequence().OpenBranch(
            new Wait(1f),
            new Log("sleep")
            );

        var sleepCondition  = new BlackboardCondition <bool>("sleep", Operator.IS_EQUAL, true, ObserverAborts.BOTH).Decorate(sleep);
        var eatingCondition = new BlackboardCondition <int>("energy", Operator.IS_SMALLER, 5, ObserverAborts.BOTH).Decorate(eating);

        var selector = new Selector().OpenBranch(
            sleepCondition,
            eatingCondition,
            working
            );

        var service = new DefaultService(UpdateStatus).Decorate(selector);

        m_Root = new Root(bb).Decorate(service);

#if UNITY_EDITOR
        UBTDebugger debugger = gameObject.AddComponent <UBTDebugger>();
        debugger.behaviorTree = m_Root;
#endif
        //m_Root.RepeatRoot = false;
        m_Root.Start();
    }