//在平台上创建英雄 public void CreateHero(long roleId, Vector2 screenPos) { HeroInfo info = Global.HeroInfoList.Find(x => x.RoleId == roleId); if (info != null) { HeroEntity heroEntity = HeroDBModel.Instance.Get(info.HeroID); GameObject go = RoleMgr.Instance.LoadRole(RoleType.Hero, heroEntity.PrefabName); RoleCtrl ctrl = go.GetComponent <RoleCtrl>(); ctrl.Init(RoleType.Hero, info, null); HeroPlatform platform = GetHeroPlatformByScreenPos(screenPos); platform.RefreshRoleId(ctrl.CurRoleInfo.RoleId); ctrl.RefreshPlatfrom(platform); ctrl.StandOnPlatfrom(); go.transform.position = platform.transform.TransformPoint(platform.StandPos); bool inFoward = ForwardHeroPlatformList.Contains(platform); if (inFoward) { AddHero(ctrl, true); } else { AddHero(ctrl, false); } ctrl.OnRoleDestory += OnRoleDestoryCallBack; ctrl.OnRoleDie += OnRoleDieCallBack; return; } Debug.Log("错误:在模拟服务器上找不到持有的英雄信息"); }
private void OnRoleDieCallBack(RoleCtrl ctrlTemp) { if (ctrlTemp.CurRoleType == RoleType.Hero) { HeroPlatform platform = GetHeroPlatform(ctrlTemp.CurRoleInfo.RoleId); platform.RefreshRoleId(0); RemoveHero(ctrlTemp); if (HeroList.Count <= 0) { m_LevelProcedure.ChangeState(LevelProcedure.Fail); } } else { if (MonsterList.Contains(ctrlTemp)) { MonsterList.Remove(ctrlTemp); if (MonsterList.Count <= 0) { m_LevelProcedure.ChangeState(LevelProcedure.Win); } } else { Debug.LogError("错误;角色被已经被移除了"); } } ctrlTemp.OnRoleDie -= OnRoleDieCallBack; }
//交换平台上的英雄 public void SwapHeroOnPlatfrom(long sourceRoleId, long targetRoleId) { RoleCtrl sourcrRole = GetHero(sourceRoleId); RoleCtrl targetRole = GetHero(targetRoleId); HeroPlatform sourcrePlatform = GetHeroPlatform(sourceRoleId); HeroPlatform targetPlatform = GetHeroPlatform(targetRoleId); if (sourcrRole == null || targetRole == null || sourcrePlatform == null || targetPlatform == null) { Debug.LogError("错误"); return; } ReplaceHero(sourcrRole, targetPlatform); ReplaceHero(targetRole, sourcrePlatform); sourcrePlatform.RefreshRoleId(targetRole.CurRoleInfo.RoleId); targetPlatform.RefreshRoleId(sourcrRole.CurRoleInfo.RoleId); sourcrRole.RefreshPlatfrom(targetPlatform); sourcrRole.StandOnPlatfrom(); targetRole.RefreshPlatfrom(sourcrePlatform); targetRole.StandOnPlatfrom(); }
//刷新英雄平台 public void RefreshHeroPlatform(long roleId, HeroPlatform platfrom) { RoleCtrl role = GetHero(roleId); HeroPlatform sourcePlatform = GetHeroPlatform(roleId); ReplaceHero(role, platfrom); sourcePlatform.RefreshRoleId(0); platfrom.RefreshRoleId(role.CurRoleInfo.RoleId); role.RefreshPlatfrom(platfrom); role.StandOnPlatfrom(); }
private void OnRoleDestoryCallBack(Transform obj) { if (m_LevelProcedure.CurState == LevelProcedure.HeroEditor) { RoleCtrl roleCtrl = obj.GetComponent <RoleCtrl>(); if (roleCtrl.CurRoleType == RoleType.Hero) { HeroPlatform platform = GetHeroPlatform(roleCtrl.CurRoleInfo.RoleId); platform.RefreshRoleId(0); RemoveHero(roleCtrl); } } }