/// <summary>
    /// Tests a set of conditions to ensure that the behavior tree is functional
    /// </summary>
    /// <returns></returns>
    private bool ValidateAndSetRootNode()
    {
        if (runtimeTree == null)
        {
            Debug.LogWarning("runtimeTree is null - Behaviour tree will not run - Add a Behaviour Tree to the RuntimeBehaviourTree Script");
            return(false);
        }

        List <BTRoot> rootNodeList = new List <BTRoot>();

        foreach (Node _node in runtimeTree.nodes)
        {
            BTRoot root = _node as BTRoot;
            if (root != null)
            {
                rootNodeList.Add(root);
            }
        }

        if (rootNodeList.Count != 1)
        {
            Debug.LogWarning("There is no root node or more than 1 root node in this behaviourTree - BehaviourTree will not run - Make sure there is exactly 1 BTRoot node in your graph");
            return(false);
        }
        else
        {
            rootNode = rootNodeList[0];
        }

        return(true);
    }
Exemple #2
0
    protected override void Start()
    {
        base.Start();
        skillReaderList.Add(new SkillReader(SkillManager.FindSkill("FrogGeneralAttack")));
        BT BTAttack = BT.Sequence
                      (
            BT.Call(GeneralAttack)
                      );
        BT BTPatrol = BT.Sequence
                      (
            BT.Success(BT.Call(RandomWayPoint)),
            BT.Success(BT.Call(FindAroundEnemy)),
            BT.Condition(() => { return(!isFoundEnemy); }, BT.Call(Move))
                      );

        AI = BT.Root
             (
            BT.Sequence
            (
                BT.Success(BT.Call(FindAroundEnemy)),
                BT.Selector
                (
                    BT.Condition(() => { return(isFoundEnemy); }, BTAttack),
                    BT.Probability(0.3f * Time.fixedDeltaTime, BTPatrol)
                )
            )
             );
        moveMaxDelay = new Delay();
    }
Exemple #3
0
    /// <summary>
    /// Checks if the connected behavior tree is valid and has a root node
    /// </summary>
    /// <returns></returns>
    private bool ValidateAndSetRootNode()
    {
        if (subTree == null)
        {
            Debug.LogWarning("subTree is null - tree will not run");
            return(false);
        }

        List <BTRoot> rootNodeList = new List <BTRoot>();

        foreach (Node _node in subTree.nodes)
        {
            BTRoot root = _node as BTRoot;
            if (root != null)
            {
                rootNodeList.Add(root);
            }
        }

        if (rootNodeList.Count != 1)
        {
            Debug.LogWarning("There is no root node or more than 1 root node in this subTree - subtree will not run - Make sure there is exactly 1BTRoot node in your graph");
            return(false);
        }
        else
        {
            subTreeRoot = rootNodeList[0];
        }

        return(true);
    }
        public void AddBtRoot(string Id)
        {
            BTRoot bt = new BTRoot();

            bt.Id = Id;
            m_BTRoots.Add(bt);
        }
    void Start()
    {
        attackTimer = unitData.fireRate - 1;

        rootAI = new BTRoot(new List <BTNode>()
        {
            CombatSequence(),
        });
    }
Exemple #6
0
 public void Tick(string config, ref BTInput input)
 {
     if (string.IsNullOrEmpty(config))
     {
         return;
     }
     if (mBattleLogicDic.ContainsKey(config) == false)
     {
         BTRoot root = new BTRoot();
         AIConfig.ReadXML(config, root);
         mBattleLogicDic.Add(config, root);
     }
     mBattleLogicDic[config].Tick(ref input);
 }
Exemple #7
0
 public static void ReadXML(string name, BTRoot root)
 {
     /*string assetBundleName = string.Format("assets/assetbundle/config/character/ai/{0}.xml", name.ToLower());
      * AssetCache.LoadAssetAsync<TextAsset>(assetBundleName, assetBundleName, (asset) =>
      * {
      *  if (asset != null)
      *  {
      *
      *      TextAsset text = asset.GetAsset() as TextAsset;
      *
      *      if (text!=null)
      *      {
      *          root.InitXML(text.bytes);
      *      }
      *  }
      * });
      */
 }
Exemple #8
0
        private void InitTextMesh(BTRoot root)
        {
            if (root.GetComponent <TextMeshPro>())
            {
                return;
            }

            var text = root.gameObject.AddComponent <TextMeshPro>();
            var rect = root.GetComponent <RectTransform>();

            rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 2.2f);
            rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 1f);

            text.enableAutoSizing = true;
            text.fontSizeMin      = 0;
            text.fontSizeMax      = 5;
            text.fontStyle        = FontStyles.Bold;
            text.lineSpacing      = -2f;
            text.alignment        = TextAlignmentOptions.Midline;
        }
Exemple #9
0
 public BTActionNode(BTRoot ai, BTNodeData config) : base(ai, config)
 {
 }
Exemple #10
0
 protected void PopulateBtNodes(List <BTNode> btNodes)
 {
     rootAI = new BTRoot(btNodes);
 }