/// <summary> /// 角色控制器初始化 /// </summary> /// <param name="roleType"></param> /// <param name="roleInfo"></param> /// <param name="ai"></param> public void Init(RoleType roleType, RoleInfoBase roleInfo, IRoleAI ai) { CurRoleType = roleType; CurRoleInfo = roleInfo; CurRoleAI = ai; m_IsInit = true; StateMachine = new RoleStateMachine(this.gameObject, true); RoleStateAbstract[] states = GetComponents <RoleStateAbstract>(); for (int i = 0; i < states.Length; i++) { StateMachine.AddState(states[i]); } Attack = new RoleAttack(this); m_Hurt = new RoleHurt(StateMachine, this); m_Hurt.OnHurt = OnHurt; ToIdle(); m_RoleOperationsStatus = new StateMachine <RoleOperationsStatus>(this.gameObject, true, CurRoleInfo.RoleId + ":" + "RoleOperationsStatus"); StateMachineDispatcher.Instance.AddEventListen(CurRoleInfo.RoleId + ":" + "RoleOperationsStatus", OnRoleOperationsStatusCallBack); m_RoleOperationsStatus.ChangeState(RoleOperationsStatus.NoOperations); //初始化血条 InitRoleHeadBar(); }
//显示英雄简介 private void ShowHeroIntro(long roleId) { if (m_HeroIntroView == null) { GameObject go = ResourcesMrg.Instance.Load(ResourcesMrg.ResourceType.UIWindowChild, "HeroIntro"); m_HeroIntroView = go.GetComponent <UIHeroIntroView>(); go.transform.SetParent(UISceneCtrl.Instance.CurrentUIScene.MainCanvans.transform); go.transform.localScale = Vector3.one; go.transform.localPosition = Vector3.zero; } m_HeroIntroView.gameObject.SetActive(true); DataTransfer data = new DataTransfer(); HeroInfo heroInfo = Global.HeroInfoList.Find(x => x.RoleId == roleId); if (heroInfo != null) { if (heroInfo != null) { HeroEntity heroEntity = HeroDBModel.Instance.Get(heroInfo.HeroID); data.SetData <string>("HeroName", heroEntity.Name); data.SetData <string>("HeroDesc", heroEntity.Desc); for (int i = 0; i < heroInfo.SkillList.Count; i++) { SkillEntity skill1Entity = SkillDBModel.Instance.Get(heroInfo.SkillList[i].SkillId); data.SetData <string>("Skill" + (i + 1) + "Name", skill1Entity.SkillName); data.SetData <string>("Skill" + (i + 1) + "Desc", skill1Entity.SkillDesc); } } } else { //敌人 RoleInfoBase monsterInfo = GameSceneCtrl.Instance.MonsterList.Find(x => x.CurRoleInfo.RoleId == roleId).CurRoleInfo; if (monsterInfo != null) { SpriteEntity spriteEntity = SpriteDBModel.Instance.GetList().Find(x => x == ((MonsterInfo)monsterInfo).SpriteEntity); if (spriteEntity == null) { Debug.LogError("错误:找不到精灵实体,请查看是否有没有赋值,或者GameSceneCtrl的MonsterList 移除,添加出错了"); return; } else { data.SetData <string>("HeroName", spriteEntity.Name); data.SetData <string>("HeroDesc", ""); for (int j = 0; j < ((MonsterInfo)monsterInfo).GetSkillList().Count; j++) { SkillEntity skill1Entity = SkillDBModel.Instance.Get(((MonsterInfo)monsterInfo).GetSkillList()[j]); data.SetData <string>("Skill" + (j + 1) + "Name", skill1Entity.SkillName); data.SetData <string>("Skill" + (j + 1) + "Desc", skill1Entity.SkillDesc); } } } else { Debug.Log("错误:没找到英雄信息"); return; } } m_HeroIntroView.SetUI(data); }