Пример #1
0
    void Start()
    {
        Application.runInBackground = true;
        Application.targetFrameRate = 60;
        Instance = this.gameObject.GetComponent <MainEntry>();

        //模块管理初始化
        ModuleManager.Setup();
        //人物
        PlayerManager.Setup();
        //相机
        CameraManager.Setup(GameObject.Find("Main Camera").transform);
        //


        B3Config.Register("CreateRoute", typeof(CreateRoute));
        B3Config.Register("IsCanCreateRoute", typeof(IsCanCreateRoute));
        B3Config.Register("IsCreateRoute", typeof(IsCreateRoute));
        B3Config.Register("MoveToPoint", typeof(MoveToPoint));
        B3Config.Register("RandomDir", typeof(RandomDir));
        B3Config.Register("SelectMyNearestGrid", typeof(SelectMyNearestGrid));
        B3Config.Register("IsDangerous", typeof(IsDangerous));
        B3Config.Register("SelectSafeDir", typeof(SelectSafeDir));

        AIManager.Setup();
        //

        stage = new MainStage();
        stage.Init();
    }
Пример #2
0
    // Use this for initialization
    void Start()
    {
        JsonData data = B3Config.Load("TestBehavior3");

        _tree = new BehaviorTree();
        _tree.Load(data);
    }
Пример #3
0
        /**
         * This method loads a Behavior Tree from a data structure, populating this
         * object with the provided data. Notice that, the data structure must
         * follow the format specified by Behavior3JS. Consult the guide to know
         * more about this format.
         *
         * You probably want to use custom nodes in your BTs, thus, you need to
         * provide the `names` object, in which this method can find the nodes by
         * `names[NODE_NAME]`. This variable can be a namespace or a dictionary,
         * as long as this method can find the node by its name, for example:
         *
         *     //json
         *     ...
         *     'node1': {
         *       'name': MyCustomNode,
         *       'title': ...
         *     }
         *     ...
         *
         *     //code
         *     var bt = new b3.BehaviorTree();
         *     bt.load(data, {'MyCustomNode':MyCustomNode})
         *
         *
         * @method load
         * @param {Object} data The data structure representing a Behavior Tree.
         * @param {Object} [names] A namespace or dict containing custom nodes.
         **/
        public void Load(JsonData data)
        {
            this._id         = (string)data["id"];
            this.title       = (string)data["title"];
            this.description = (string)data["description"];
            string rootID = (string)data["root"];
            IDictionary <string, string> treePropDic = data["properties"] as IDictionary <string, string>;

            foreach (string treePropKey in treePropDic.Keys)
            {
                this.properties.Add(treePropKey, treePropDic[treePropKey]);
            }

            // Create the node list (without connection between them)
            IDictionary <string, string> nodesDic = data["nodes"] as IDictionary <string, string>;

            foreach (string nodeKey in nodesDic.Keys)
            {
                JsonData   nodeData = nodesDic[nodeKey];
                B3Settings settings = new B3Settings();
                settings.Parse(nodeData);
                BaseNode node = Activator.CreateInstance(B3Config.GetClassType(settings.Name), settings) as BaseNode;
                _nodeDic.Add(node.Id, node);
            }
            // Connect the nodes
            _root = _nodeDic[rootID];

            foreach (BaseNode node in _nodeDic.Values)
            {
                if (node.Category == B3.COMPOSITE)
                {
                    int childCount = node.ChildKeys.Count;
                    for (int i = 0; i < childCount; i++)
                    {
                        (node as Composite).AddChild(_nodeDic[node.ChildKeys[i]]);
                    }
                }
                else if (node.Category == B3.DECORATOR)
                {
                    if (node.ChildKeys.Count > 0)
                    {
                        (node as Decorator).SetChild(_nodeDic[node.ChildKeys[0]]);
                    }
                }
            }
        }
Пример #4
0
    public static void Setup()
    {
        B3Config.Setup();

        string aipath = Application.streamingAssetsPath + "/ai.json";


        FileStream   file = new FileStream(aipath, FileMode.Open, FileAccess.Read);
        StreamReader sr   = new StreamReader(file);
        string       str  = sr.ReadToEnd();

        //Debug.WriteLine(str);
        json = B3Config.Parse(str);



        //tree = new BehaviorTree();
        //tree.Load(json);
    }