//在平台上创建英雄 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("错误:在模拟服务器上找不到持有的英雄信息"); }
//交换平台上的英雄 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 OnSceneLevelFightCallBack(object[] p) { RoleCtrl ctrl = (RoleCtrl)p[0]; Vector3 scenePos = (Vector3)p[1]; HeroPlatform platform = GameSceneCtrl.Instance.GetHeroPlatformByScreenPos(scenePos); //依然在平台内 if (platform != null) { SetGameObjectLayer(ctrl.gameObject, "Role", 0); ctrl.transform.SetParent(null); if (platform.RoleId != 0) { //替换 GameSceneCtrl.Instance.SwapHeroOnPlatfrom(ctrl.CurRoleInfo.RoleId, platform.RoleId); } else { //刷新 GameSceneCtrl.Instance.RefreshHeroPlatform(ctrl.CurRoleInfo.RoleId, platform); } } else { //在UI内 RectTransform rect = ((UIGameSceneView)UISceneCtrl.Instance.CurrentUIScene).HeroGridRect; bool inHeroGrid = RectTransformUtility.RectangleContainsScreenPoint(rect, scenePos, UISceneCtrl.Instance.CurrentUIScene.UICamera); if (inHeroGrid) { //移除这个战斗英雄 SimulatedDatabase.Instance.RemoveFightHero(ctrl.CurRoleInfo.RoleId); GameObject.DestroyImmediate(ctrl.gameObject); UpdateAllHeroInfo(); } else { //复原 SetGameObjectLayer(ctrl.gameObject, "Role", 0); ctrl.transform.SetParent(null); ctrl.StandOnPlatfrom(); } } }