• 注册
欢迎加入behaviac Q&A网站。behaviac是腾讯开源组件https://github.com/TencentOpen/behaviac 官方网站:http://www.behaviac.com/,提供各种文档和教程及手册 为了您及时的获得您最新问题的评论或者回答,请提供并验证您的邮箱

string agentType = behaviorNode.Attribute("agenttype").Replace("::", ".");

0 喜欢 0 不喜欢
86 浏览
using System;
using System.Collections.Generic;
using System.Text;
using UnityEngine;
[behaviac.TypeMetaInfo()]
class users : behaviac.Agent
{
    [behaviac.MemberMetaInfo()]
    public string name = "张三";

    [behaviac.MethodMetaInfo()]
    public void show()
    {
        print("攻击");
    }
    public string behaviorTree = "firstBehav";
    protected bool btloadResult = false;
    public void loadTree()
    {

        //behaviac.Agent.RegisterInstanceName<users>("usersEntity");
        if (behaviorTree.Length > 0)
        {
            btloadResult = btload(behaviorTree, true);
            if (btloadResult)
                btsetcurrent(behaviorTree);
            else
                Debug.LogError("Behavior tree data load failed! " + behaviorTree);
        }
    }
}
 

 

 

using UnityEngine;
using System.Collections;

[behaviac.TypeMetaInfo("loadBehaviac", "loadBehaviac -> Agent")]
[AddComponentMenu("BattleCity/GameLevelCommon")]
public class loadBehaviac : behaviac.Agent
{
    public string behaviorTree = "firstBehav";
    protected bool btloadResult = false;
    private users oop;
    void Awake()
    {
        oop = this.GetComponent<users>();
    }

    void Update()
    {
        btexec();
    }
    void Start()
    {
        oop.name = "张三";

        oop.loadTree();  //加载行为树时,报错
    }
}
 

跟踪代码,

  string agentType = behaviorNode.Attribute("agenttype").Replace("::", ".");  报错

  behaviorNode.Attribute("agenttype")为null

behaviorNode  值如下:

  "<Behavior Version=\"5\">\r\n
<Node Class=\"Behaviac.Design.Nodes.Behavior\"\r\nAgentType=\"users\"\r\nDomains=\"\"\r\nEnable=\"true\"\r\nHasOwnPrefabData=\"false\"\r\nId=\"-1\"\r\nPrefabName=\"\"\r\nPrefabNodeId=\"-1\">\r\n<Comment Background=\"NoColor\"\r\nText=\"\"/>\r\n<DescriptorRefs value=\"0:\"/>\r\n<Connector Identifier=\"GenericChildren\">\r\n<Node Class=\"PluginBehaviac.Nodes.Sequence\"\r\nEnable=\"true\"\r\nHasOwnPrefabData=\"false\"\r\nId=\"0\"\r\nPrefabName=\"\"\r\nPrefabNodeId=\"-1\">\r\n<Comment Background=\"NoColor\"\r\nText=\"\"/>\r\n<Connector Identifier=\"GenericChildren\">\r\n<Node Class=\"PluginBehaviac.Nodes.Condition\"\r\nEnable=\"true\"\r\nHasOwnPrefabData=\"false\"\r\nId=\"1\"\r\nOperator=\"Equal\"\r\nOpl=\"string Self.users::name\"\r\nOpr=\"const string &quot;张三&quot;\"\r\nPrefabName=\"\"\r\nPrefabNodeId=\"-1\">\r\n<Comment Background=\"NoColor\"\r\nText=\"\"/>\r\n</Node>\r\n<Node Class=\"PluginBehaviac.Nodes.Action\"\r\nEnable=\"true\"\r\nHasOwnPrefabData=\"false\"\r\nId=\"2\"\r\nMethod=\"Self.users::show()\"\r\nPrefabName=\"\"\r\nPrefabNodeId=\"-1\"\r\nResultFunctor=\"&quot;&quot;\"\r\nResultOption=\"BT_SUCCESS\">\r\n<Comment Background=\"NoColor\"\r\nText=\"\"/>\r\n</Node>\r\n</Connector>\r\n</Node>\r\n</Connector>\r\n</Node>\r\n</Behavior>\r\n"
最新提问 6月 23, 2016 用户: qq_576a6645d6e2a (410 分)
标签修改 6月 24, 2016 用户:jonygli

1个回答

0 喜欢 0 不喜欢

需要指定cs格式,缺省用的是xml格式:

请参考:http://www.behaviac.com/language/zh/tutorial4_3_export_cs/

behaviac.Workspace.Instance.FileFormat = behaviac.Workspace.EFileFormat.EF
最新回答 6月 24, 2016 用户: jonygli (58,410 分)
...