using ET; using FairyGUI; using System; using System.Collections.Generic; using System.Linq; using System.Text; using UnityEngine; namespace ET { public class PosHelper { public const int PlayerPos_Z = 50; public const int NPCPos_Z = 80; private readonly static Vector2 MonsterBasePos = new Vector2(0.48f, 0.1f); private readonly static Vector2 PlayerBasePos = new Vector2(0.80f, 0.25f); private readonly static Vector2 EnermyPlayerBasePos = new Vector2(0.3f, 0.25f); private static Vector3[] MonsterPosArr; private static Vector3[] PlayerPosArr; private static Vector3[] EnermyPlayerPosArr; #if UNITY private static float xDis = -0.08f * Screen.width; private static float yDis = xDis * Mathf.Tan(150 * Mathf.PI / 180); #else private static float xDis = -0.08f * 28; private static float yDis = xDis * Mathf.Tan(150 * Mathf.PI / 180); #endif public static Vector3 GetMonsterPos(int index) { #if UNITY Vector3 pos = GetMonsterPos()[index]; pos = Camera.main.ScreenToWorldPoint(pos); return pos; #else return Vector3.zero; #endif } private static Vector3[] GetMonsterPos() { if (MonsterPosArr == null) MonsterPosArr = new Vector3[10]; else { return MonsterPosArr; } #if UNITY Vector3 posBase = new Vector3(MonsterBasePos.x * Screen.width, MonsterBasePos.y * Screen.height, PlayerPos_Z); #else Vector3 posBase= Vector3.zero; #endif int i = 0; MonsterPosArr[i++] = posBase + new Vector3(xDis * 3, yDis * 1, 0); MonsterPosArr[i++] = posBase + new Vector3(xDis * 4, yDis * 2, 0); MonsterPosArr[i++] = posBase + new Vector3(xDis * 5, yDis * 3, 0); MonsterPosArr[i++] = posBase + new Vector3(xDis * 2, yDis * 0, 0); MonsterPosArr[i++] = posBase + new Vector3(xDis * 5, yDis * 1, 0); MonsterPosArr[i++] = posBase + new Vector3(xDis * 4, yDis * 0, 0); MonsterPosArr[i++] = posBase + new Vector3(xDis * 1, yDis * 1, 0); MonsterPosArr[i++] = posBase + new Vector3(xDis * 2, yDis * 2, 0); MonsterPosArr[i++] = posBase + new Vector3(xDis * 3, yDis * 3, 0); MonsterPosArr[i++] = posBase + new Vector3(xDis * 0, yDis * 0, 0); return MonsterPosArr; } private static Vector3[] GetPlayerPos() { if (PlayerPosArr == null) { PlayerPosArr = new Vector3[5]; #if UNITY Vector3 posBase = new Vector3(PlayerBasePos.x * Screen.width, PlayerBasePos.y * Screen.height, PlayerPos_Z); #else Vector3 posBase= Vector3.zero; #endif int i = 0; PlayerPosArr[i++] = posBase + new Vector3(xDis * 0, yDis * 0, 0); PlayerPosArr[i++] = posBase + new Vector3(xDis * 1, yDis * 1, 0); PlayerPosArr[i++] = posBase + new Vector3(xDis * -1, yDis * -1, 0); PlayerPosArr[i++] = posBase + new Vector3(xDis * 2, yDis * 2, 0); PlayerPosArr[i++] = posBase + new Vector3(xDis * -2, yDis * -2, 0); } return PlayerPosArr; } private static Vector3[] GetEnermyPlayerPos() { if (EnermyPlayerPosArr == null) { EnermyPlayerPosArr = new Vector3[5]; #if UNITY Vector3 posBase = new Vector3(EnermyPlayerBasePos.x * Screen.width, EnermyPlayerBasePos.y * Screen.height, PlayerPos_Z); #else Vector3 posBase= Vector3.zero; #endif int i = 0; EnermyPlayerPosArr[i++] = posBase + new Vector3(xDis * 0, yDis * 0, 0); EnermyPlayerPosArr[i++] = posBase + new Vector3(xDis * 1, yDis * 1, 0); EnermyPlayerPosArr[i++] = posBase + new Vector3(xDis * -1, yDis * -1, 0); EnermyPlayerPosArr[i++] = posBase + new Vector3(xDis * 2, yDis * 2, 0); EnermyPlayerPosArr[i++] = posBase + new Vector3(xDis * -2, yDis * -2, 0); } return EnermyPlayerPosArr; } public static Vector3 GetPlayerPos(int index) { #if UNITY Vector3 pos; pos = GetPlayerPos()[index]; pos = Camera.main.ScreenToWorldPoint(pos); return pos; #else return Vector3.zero; #endif } public static void BackPos(Scene zoneScene) { try { //!将玩家归位 Team team =zoneScene.GetComponent().Get(zoneScene.GetComponent().LeaderId); int index = 0; foreach (Unit unit in team.GetAll()) { try { Game.EventSystem.Publish_Sync(new ET.EventType.HideHpBar { zoneScene = unit.ZoneScene(), unit = unit, }); Vector4 posAndYAngle = zoneScene.GetComponent().PlayerPosList_BeforeBattle[index++]; unit.Position = new UnityEngine.Vector3(posAndYAngle.x, posAndYAngle.y, posAndYAngle.z); unit.YAngle = (int)posAndYAngle.w; } catch (Exception e) { Log.Error(e); } } zoneScene.GetComponent().MyUnit.IsFight = false; Team enermyTeam =zoneScene.GetComponent().GetEnermyTeam(); if (enermyTeam) { index = 0; foreach (Unit unit in enermyTeam.GetAll()) { try { Game.EventSystem.Publish_Sync(new ET.EventType.HideHpBar { zoneScene = unit.ZoneScene(), unit = unit, }); Vector4 posAndYAngle = zoneScene.GetComponent().EnermyPlayerPosList_BeforeBattle[index++]; unit.Position = new UnityEngine.Vector3(posAndYAngle.x, posAndYAngle.y, posAndYAngle.z); unit.YAngle = (int)posAndYAngle.w; } catch (Exception e) { Log.Error(e); } } } } catch (Exception e) { Log.Error(e); } } public static void CheckSceneError(Scene zoneScene, int sceneId, string info) { if (zoneScene.GetComponent().MapId / 100 != sceneId) { zoneScene.GetComponent().Session.Send(new C2M_CheckSceneError { Info = $"玩家所在场景为{zoneScene.GetComponent().MapId / 100},检查场景为{sceneId},info = {info}" }); } } public static void CheckSceneError(Scene zoneScene,string info, params int[] sceneIds) { bool isError = true; foreach (int sceneId in sceneIds) { if (zoneScene.GetComponent().MapId / 100 == sceneId) { isError = false; } } if (isError) { string str = null; foreach (int sceneId in sceneIds) { str += $"||{sceneId}"; } zoneScene.GetComponent().Session.Send(new C2M_CheckSceneError { Info = $"玩家所在场景为{zoneScene.GetComponent().MapId / 100},检查场景为{str},info = {info}" }); } } public static Vector3 GetEnermyPlayerPos(int index) { #if UNITY Vector3 pos; pos = GetEnermyPlayerPos()[index]; pos = Camera.main.ScreenToWorldPoint(pos); return pos; #else return Vector3.zero; #endif } public static Vector2 WorldToScreen(Vector3 worldPos) { #if UNITY Vector3 screenPos = Camera.main.WorldToScreenPoint(worldPos); //!原点位置转换 screenPos.y = Screen.height - screenPos.y; return GRoot.inst.GlobalToLocal(screenPos); #else return Vector2.zero; #endif } } }