public void Init(int id, int lv) { EnemyData.RootObject data = EnemyData.GetData(id); Info.Init(id, lv); _originalPosition = transform.position; Sprite.sprite = Resources.Load <Sprite>("Image/Character/Small/" + data.Image); if (data.Animator != string.Empty) { Animator.runtimeAnimatorController = Resources.Load <RuntimeAnimatorController>("Animator/" + data.Animator); } AI = GetComponent(Type.GetType(data.AI)) as AI; if (AI == null) { gameObject.AddComponent(Type.GetType(data.AI)); AI = GetComponent(Type.GetType(data.AI)) as AI; } AI.Init(this, data.SkillList); BattleController.Instance.TurnEndHandler += CheckBattleStatus; }
private List <BattleCharacter> _playerList = new List <BattleCharacter>(); //戰鬥結束時需要的友方資料 public void Init(int battlefieldId, BattleGroupData.RootObject battleGroupData, Action winCallback, Action loseCallback) { BattlefieldGenerator.Instance.Generate(battlefieldId, battleGroupData.EnemyList.Count); Turn = 1; _power = TeamManager.Instance.Power; _exp = battleGroupData.Exp; _winCallback = winCallback; _loseCallback = loseCallback; CharacterList.Clear(); BattleCharacter character; TeamMember member; List <TeamMember> memberList = TeamManager.Instance.GetAttendList(); for (int i = 0; i < memberList.Count; i++) { member = memberList[i]; character = ResourceManager.Instance.Spawn("BattleCharacter/BattleCharacter", ResourceManager.Type.Other).GetComponent <BattleCharacter>(); character.name = member.Data.Animator; character.Init(member, TeamManager.Instance.Lv); CharacterList.Add(character); _playerList.Add(character); character.SetPosition((Vector2)(member.Formation + BattleFieldManager.Instance.Center)); if (character.LiveState == BattleCharacter.LiveStateEnum.Dead) { character.Sprite.color = Color.clear; } } EnemyData.RootObject data; List <int> itemList = new List <int>(); //單隻怪的掉落物 List <KeyValuePair <int, int> > enemyList = battleGroupData.GetEnemy(); for (int i = 0; i < enemyList.Count; i++) { data = EnemyData.GetData(enemyList[i].Key); itemList = data.GetDropItemList(); for (int j = 0; j < itemList.Count; j++) { _dropItemList.Add(itemList[j]); } character = ResourceManager.Instance.Spawn("BattleCharacter/BattleCharacter", ResourceManager.Type.Other).GetComponent <BattleCharacter>(); character.Init(enemyList[i].Key, enemyList[i].Value); CharacterList.Add(character); character.SetPosition(BattleFieldManager.Instance.EnemyPositionList[i]); } int itemId; ItemData.RootObject itemData; SkillData.RootObject skillData; Skill skill; List <Item> medicineList = ItemManager.Instance.GetItemListByType(ItemManager.Type.Bag, ItemData.TypeEnum.Medicine); if (medicineList != null) { foreach (Item item in medicineList) { itemId = item.ID; itemData = ItemData.GetData(itemId); skillData = SkillData.GetData(itemData.Skill); skill = SkillFactory.GetNewSkill(skillData, null, 1); skill.ItemID = itemId; ItemSkillList.Add(skill); } } Camera.main.transform.position = new Vector3(BattleFieldManager.Instance.Center.x, BattleFieldManager.Instance.Center.y, Camera.main.transform.position.z); AudioSystem.Instance.Play("Battle", true); ChangeSceneUI.Instance.EndClock(() => { BattleUI.Open(); BattleUI.Instance.Init(_power, CharacterList, battleGroupData.CanEscape); ChangeState <TurnStartState>(); }); }