Пример #1
0
    /// <summary>
    /// 初始化
    /// </summary>
    public virtual void Init()
    {
        if (backpack == null)
        {
            backpack = gameObject.AddComponent <BackpackComponent>() as BackpackComponent;
        }
        if (backpack.tool == null)
        {
            //加载工具
            GameObject prefab = Resources.Load <GameObject>(backpack.toolType);
            //实例化
            GameObject tool = Instantiate(prefab, transform.position, transform.rotation) as GameObject;
            backpack.tool = tool;
            // attach the tool
            //附上工具
            tool.transform.parent = transform;
        }

        if (Brain == null)
        {
            Brain = gameObject.GetComponent <Brain>();
        }
        Brain.Init();

        //init world data 初始化世界数据
        worldData.Add("hasOre", (backpack.numOre > 0));
        worldData.Add("hasLogs", (backpack.numLogs > 0));
        worldData.Add("hasFirewood", (backpack.numFirewood > 0));
        worldData.Add("hasTool", (backpack.tool != null));
        worldData.Add("hasMeat", (backpack.numMeat > 0));

        //init blackboard 初始化黑板
        bb.AddData("backpack", backpack);
        bb.AddData("brain", Brain);
        bb.AddData("ironRock", FindObjectsOfType(typeof(IronRockComponent)));
        bb.AddData("appleTree", FindObjectsOfType(typeof(AppleTreeComponet)));
        bb.AddData("forge", FindObjectsOfType(typeof(ForgeComponent)));
        bb.AddData("tree", FindObjectsOfType(typeof(TreeComponent)));
        bb.AddData("wolfDen", FindObjectsOfType(typeof(WolfDen)));
        bb.AddData("choppingBlock", FindObjectsOfType(typeof(ChoppingBlockComponent)));
        bb.AddData("supplyPiles", FindObjectsOfType(typeof(SupplyPileComponent)));
        bb.AddData("camp", FindObjectsOfType(typeof(CampComponent)));
    }
Пример #2
0
    /// <summary>
    /// 初始化
    /// </summary>
    public virtual void Init()
    {
        if (backpack == null)
        {
            backpack = gameObject.AddComponent <Backpack>() as Backpack;
        }
        if (backpack.tool == null)
        {
            //加载工具
            GameObject prefab = Resources.Load <GameObject>(backpack.toolType);
            //实例化
            GameObject tool = Instantiate(prefab, transform.position, transform.rotation) as GameObject;
            backpack.tool = tool;
            // attach the tool
            //附上工具
            tool.transform.parent = transform;
        }

        if (State == null)
        {
            State = gameObject.GetComponent <CharacterStatus>();
        }
        State.Init();

        //init world data 初始化世界数据
        worldData.Add("hasTool", (backpack.tool != null));
        worldData.Add("hasTree", (backpack.woodNum > 0));
        worldData.Add("hasMining", (backpack.stoneNum > 0));
        //init blackboard 初始化黑板
        bb.AddData("backpack", backpack);
        bb.AddData("state", State);
        bb.AddData("Warehouse", FindObjectsOfType(typeof(Warehouse)));
        bb.AddData("Tree", FindObjectsOfType(typeof(Trees)));
        bb.AddData("ChopFirewoodPoint", FindObjectsOfType(typeof(ChopFirewoodPoint)));
        bb.AddData("Mining", FindObjectsOfType(typeof(Mining)));
        bb.AddData("Forge", FindObjectsOfType(typeof(ForgeComponent)));
    }
Пример #3
0
 void Start()
 {
     StartCoroutine(GenerateAi());
     //添加仓库
     bb.AddData("Warehouse", FindObjectsOfType(typeof(Warehouse)));
 }