2021-04-08 20:09:59 +08:00
|
|
|
|
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;
|
|
|
|
|
|
2021-04-20 00:25:04 +08:00
|
|
|
|
#if UNITY
|
2021-04-08 20:09:59 +08:00
|
|
|
|
private static float xDis = -0.08f * Screen.width;
|
|
|
|
|
private static float yDis = xDis * Mathf.Tan(150 * Mathf.PI / 180);
|
2021-04-20 00:25:04 +08:00
|
|
|
|
#else
|
|
|
|
|
private static float xDis = -0.08f * 28;
|
|
|
|
|
private static float yDis = xDis * Mathf.Tan(150 * Mathf.PI / 180);
|
|
|
|
|
#endif
|
2021-04-08 20:09:59 +08:00
|
|
|
|
public static Vector3 GetMonsterPos(int index)
|
|
|
|
|
{
|
2021-04-20 00:25:04 +08:00
|
|
|
|
#if UNITY
|
2021-04-11 19:50:39 +08:00
|
|
|
|
Vector3 pos = GetMonsterPos()[index];
|
2021-04-08 20:09:59 +08:00
|
|
|
|
pos = Camera.main.ScreenToWorldPoint(pos);
|
|
|
|
|
return pos;
|
2021-04-20 00:25:04 +08:00
|
|
|
|
#else
|
|
|
|
|
return Vector3.zero;
|
|
|
|
|
#endif
|
2021-04-08 20:09:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static Vector3[] GetMonsterPos()
|
|
|
|
|
{
|
|
|
|
|
if (MonsterPosArr == null)
|
|
|
|
|
MonsterPosArr = new Vector3[10];
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return MonsterPosArr;
|
|
|
|
|
}
|
2021-04-20 00:25:04 +08:00
|
|
|
|
#if UNITY
|
2021-04-08 20:09:59 +08:00
|
|
|
|
Vector3 posBase = new Vector3(MonsterBasePos.x * Screen.width, MonsterBasePos.y * Screen.height, PlayerPos_Z);
|
2021-04-20 00:25:04 +08:00
|
|
|
|
#else
|
|
|
|
|
Vector3 posBase= Vector3.zero;
|
|
|
|
|
#endif
|
2021-04-08 20:09:59 +08:00
|
|
|
|
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];
|
2021-04-20 00:25:04 +08:00
|
|
|
|
#if UNITY
|
2021-04-08 20:09:59 +08:00
|
|
|
|
Vector3 posBase = new Vector3(PlayerBasePos.x * Screen.width, PlayerBasePos.y * Screen.height, PlayerPos_Z);
|
2021-04-20 00:25:04 +08:00
|
|
|
|
#else
|
|
|
|
|
Vector3 posBase= Vector3.zero;
|
|
|
|
|
#endif
|
2021-04-08 20:09:59 +08:00
|
|
|
|
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];
|
2021-04-20 00:25:04 +08:00
|
|
|
|
#if UNITY
|
2021-04-08 20:09:59 +08:00
|
|
|
|
Vector3 posBase = new Vector3(EnermyPlayerBasePos.x * Screen.width, EnermyPlayerBasePos.y * Screen.height, PlayerPos_Z);
|
2021-04-20 00:25:04 +08:00
|
|
|
|
#else
|
|
|
|
|
Vector3 posBase= Vector3.zero;
|
|
|
|
|
#endif
|
2021-04-08 20:09:59 +08:00
|
|
|
|
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)
|
|
|
|
|
{
|
2021-04-20 00:25:04 +08:00
|
|
|
|
#if UNITY
|
2021-04-08 20:09:59 +08:00
|
|
|
|
Vector3 pos;
|
|
|
|
|
pos = GetPlayerPos()[index];
|
|
|
|
|
pos = Camera.main.ScreenToWorldPoint(pos);
|
|
|
|
|
return pos;
|
2021-04-20 00:25:04 +08:00
|
|
|
|
#else
|
|
|
|
|
return Vector3.zero;
|
|
|
|
|
#endif
|
2021-04-08 20:09:59 +08:00
|
|
|
|
}
|
2021-04-20 00:25:04 +08:00
|
|
|
|
public static void BackPos(Scene zoneScene)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
//!将玩家归位
|
2021-04-20 00:25:04 +08:00
|
|
|
|
Team team =zoneScene.GetComponent<TeamComponent>().Get(zoneScene.GetComponent<GlobalVariable>().LeaderId);
|
2021-04-08 20:09:59 +08:00
|
|
|
|
int index = 0;
|
2021-04-11 19:50:39 +08:00
|
|
|
|
foreach (Unit unit in team.GetAll())
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Game.EventSystem.Publish_Sync(new ET.EventType.HideHpBar
|
|
|
|
|
{
|
|
|
|
|
zoneScene = unit.ZoneScene(),
|
|
|
|
|
unit = unit,
|
|
|
|
|
});
|
2021-04-20 00:25:04 +08:00
|
|
|
|
Vector4 posAndYAngle = zoneScene.GetComponent<GlobalVariable>().PlayerPosList_BeforeBattle[index++];
|
2021-04-08 20:09:59 +08:00
|
|
|
|
unit.Position = new UnityEngine.Vector3(posAndYAngle.x, posAndYAngle.y, posAndYAngle.z);
|
|
|
|
|
unit.YAngle = (int)posAndYAngle.w;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Log.Error(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-04-20 00:25:04 +08:00
|
|
|
|
zoneScene.GetComponent<UnitComponent>().MyUnit.IsFight = false;
|
|
|
|
|
Team enermyTeam =zoneScene.GetComponent<TeamComponent>().GetEnermyTeam();
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (enermyTeam)
|
|
|
|
|
{
|
|
|
|
|
index = 0;
|
2021-04-11 19:50:39 +08:00
|
|
|
|
foreach (Unit unit in enermyTeam.GetAll())
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Game.EventSystem.Publish_Sync(new ET.EventType.HideHpBar
|
|
|
|
|
{
|
|
|
|
|
zoneScene = unit.ZoneScene(),
|
|
|
|
|
unit = unit,
|
|
|
|
|
});
|
2021-04-20 00:25:04 +08:00
|
|
|
|
Vector4 posAndYAngle = zoneScene.GetComponent<GlobalVariable>().EnermyPlayerPosList_BeforeBattle[index++];
|
2021-04-08 20:09:59 +08:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-04-20 00:25:04 +08:00
|
|
|
|
public static void CheckSceneError(Scene zoneScene, int sceneId, string info)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
2021-04-20 00:25:04 +08:00
|
|
|
|
if (zoneScene.GetComponent<GlobalVariable>().MapId / 100 != sceneId)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
2021-04-20 00:25:04 +08:00
|
|
|
|
zoneScene.GetComponent<SessionComponent>().Session.Send(new C2M_CheckSceneError { Info = $"玩家所在场景为{zoneScene.GetComponent<GlobalVariable>().MapId / 100},检查场景为{sceneId},info = {info}" });
|
2021-04-08 20:09:59 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-04-20 00:25:04 +08:00
|
|
|
|
public static void CheckSceneError(Scene zoneScene,string info, params int[] sceneIds)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
bool isError = true;
|
2021-04-11 19:50:39 +08:00
|
|
|
|
foreach (int sceneId in sceneIds)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
2021-04-20 00:25:04 +08:00
|
|
|
|
if (zoneScene.GetComponent<GlobalVariable>().MapId / 100 == sceneId)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
isError = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (isError)
|
|
|
|
|
{
|
|
|
|
|
string str = null;
|
2021-04-11 19:50:39 +08:00
|
|
|
|
foreach (int sceneId in sceneIds)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
str += $"||{sceneId}";
|
|
|
|
|
}
|
2021-04-20 00:25:04 +08:00
|
|
|
|
zoneScene.GetComponent<SessionComponent>().Session.Send(new C2M_CheckSceneError { Info = $"玩家所在场景为{zoneScene.GetComponent<GlobalVariable>().MapId / 100},检查场景为{str},info = {info}" });
|
2021-04-08 20:09:59 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public static Vector3 GetEnermyPlayerPos(int index)
|
|
|
|
|
{
|
2021-04-20 00:25:04 +08:00
|
|
|
|
#if UNITY
|
2021-04-08 20:09:59 +08:00
|
|
|
|
Vector3 pos;
|
|
|
|
|
pos = GetEnermyPlayerPos()[index];
|
|
|
|
|
pos = Camera.main.ScreenToWorldPoint(pos);
|
|
|
|
|
return pos;
|
2021-04-20 00:25:04 +08:00
|
|
|
|
#else
|
|
|
|
|
return Vector3.zero;
|
|
|
|
|
#endif
|
2021-04-08 20:09:59 +08:00
|
|
|
|
}
|
|
|
|
|
public static Vector2 WorldToScreen(Vector3 worldPos)
|
|
|
|
|
{
|
2021-04-20 00:25:04 +08:00
|
|
|
|
#if UNITY
|
2021-04-08 20:09:59 +08:00
|
|
|
|
Vector3 screenPos = Camera.main.WorldToScreenPoint(worldPos);
|
|
|
|
|
//!原点位置转换
|
|
|
|
|
screenPos.y = Screen.height - screenPos.y;
|
|
|
|
|
return GRoot.inst.GlobalToLocal(screenPos);
|
2021-04-20 00:25:04 +08:00
|
|
|
|
#else
|
|
|
|
|
return Vector2.zero;
|
|
|
|
|
#endif
|
2021-04-08 20:09:59 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|