Esempio n. 1
0
        public void SetData(IDataBase data, string id)
        {
            JsonMonsterAI jsonMonster = (JsonMonsterAI)data;

            typeID    = jsonMonster.typeID;
            monsterID = id;

            enterMethod   = GetMethod(jsonMonster.enter);
            executeMethod = GetMethod(jsonMonster.excuse);
            exitMethod    = GetMethod(jsonMonster.exit);
        }
Esempio n. 2
0
        public MonsterStateMachine LoadData(string resourcesID)
        {
            //
            MonsterStateMachine monsterStateMachine = new MonsterStateMachine();

            // 取得 json資料
            TextAsset text = Resources.Load <TextAsset>(
                string.Format("1.MonsterAI/1.1.Json/{0}", resourcesID));

            // json資料轉換
            JsonDataList jsonData = JsonUtility.FromJson <JsonDataList>(text.text);

            // 狀態條件
            for (int i = jsonData.dataBases.Count - 1; i > -1; i--)
            {
                if (typeof(JsonCondition).IsInstanceOfType(jsonData.dataBases[i]))
                {
                    JsonCondition json = (JsonCondition)jsonData.dataBases[i];

                    Type type = Type.GetType(json.createType);
                    var  ob   = Activator.CreateInstance(type);

                    IStateCondition condition = (IStateCondition)ob;
                    condition.SetData(json);
                    condition.SetMonsterID = monsterID;

                    monsterStateMachine.SetCondition(condition);

                    jsonData.dataBases.RemoveAt(i);
                }
            }

            // 狀態
            for (int i = 0; i < jsonData.dataBases.Count; i++)
            {
                //
                if (typeof(JsonMonsterAI).IsInstanceOfType(jsonData.dataBases[i]))
                {
                    JsonMonsterAI json = (JsonMonsterAI)jsonData.dataBases[i];

                    Type             type         = Type.GetType(json.createType);
                    MonsterStateBase monsterState = (MonsterStateBase)Activator.CreateInstance(type);

                    monsterState.SetData(json, monsterID);

                    monsterStateMachine.SetState(json, monsterState);
                }
            }

            monsterStateMachine.StartAI();

            return(monsterStateMachine);
        }
 /// <summary>
 /// 添加狀態
 /// </summary>
 public void SetState(JsonMonsterAI jsonMonster, MonsterStateBase monsterState)
 {
     monsterStates.Add(monsterState.GetID, monsterState);
 }