323 lines
10 KiB
C#
323 lines
10 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using System.Collections;
|
|
using Games.LogicObj;
|
|
using System.Collections.Generic;
|
|
using GCGame.Table;
|
|
using Games.GlobeDefine;
|
|
using Games.Scene;
|
|
using Module.Log;
|
|
public class Radar : MonoBehaviour
|
|
{
|
|
public static bool ShowRadar = false;
|
|
|
|
public float UPDATE_DELAY = 0.5f; // 更新延迟
|
|
public Text LabelChannel; // 当前频道
|
|
public Text LabelPos; // 位置信息Label
|
|
public Text m_LabelSceneName;
|
|
public RawImage MapClip;
|
|
public RectTransform MapClipRect;
|
|
public GameObject ObjArrow; // 主角箭头
|
|
private MapInterface m_mapInterface = new MapInterface();
|
|
|
|
public GameObject m_pointNpc;
|
|
public GameObject m_pointFriend;
|
|
public GameObject m_pointEnimy;
|
|
public GameObject m_pointOther;
|
|
public GameObject m_pointTeam;
|
|
public GameObject m_SceneNameTip;
|
|
public Text sceneIcon; //当前场景的描述Icon
|
|
private int m_CurrentSceneID = -1;
|
|
void Awake()
|
|
{
|
|
Games.Events.EventDispatcher.Instance.Add(Games.Events.EventId.UpdateUpRightSceneLineInfo, UpdateSceneLineInfo);
|
|
Games.Events.EventDispatcher.Instance.Add(Games.Events.EventId.OnSceneMapFixLoadOver, InitNpcInfo);
|
|
InitMap();
|
|
}
|
|
|
|
public void UpdateSceneLineInfo(object args)
|
|
{
|
|
InitMap();
|
|
}
|
|
|
|
void InitMap()
|
|
{
|
|
Tab_SceneClass curTabScene = TableManager.GetSceneClassByID(GameManager.gameManager.RunningScene, 0);
|
|
if (curTabScene == null || curTabScene.Type == -1)
|
|
return;
|
|
if ((curTabScene.Type == 2 || curTabScene.Type == 3))
|
|
{
|
|
LabelChannel.text = "";
|
|
}
|
|
|
|
if (LabelChannel != null)
|
|
{
|
|
if ((curTabScene.Type == 2 || curTabScene.Type == 3))
|
|
{
|
|
LabelChannel.text = "";
|
|
}
|
|
else
|
|
{
|
|
LabelChannel.text = StrDictionary.GetClientDictionaryString("{#1177}", SceneData.SceneInst + 1);
|
|
}
|
|
}
|
|
if (m_CurrentSceneID == GameManager.gameManager.m_RunningScene && SceneData.sceneGuildGuid == Games.GlobeDefine.GlobeVar.INVALID_GUID)
|
|
{
|
|
return;
|
|
}
|
|
m_CurrentSceneID = GameManager.gameManager.m_RunningScene;
|
|
|
|
CancleScenInfo();
|
|
if (m_mapInterface == null)
|
|
m_mapInterface = new MapInterface();
|
|
m_mapInterface.Init(MapClip.rectTransform, m_pointFriend, m_pointEnimy, m_pointOther, m_pointTeam);
|
|
InitSceneInfo();
|
|
if (SceneMapFix.Instance() != null)
|
|
{
|
|
SceneMapFix.Instance().Start();
|
|
}
|
|
}
|
|
// 初始不更新
|
|
private float _nextUpdateTime = float.PositiveInfinity;
|
|
private void Update()
|
|
{
|
|
if (Time.unscaledTime > _nextUpdateTime)
|
|
{
|
|
_nextUpdateTime = Time.unscaledTime + UPDATE_DELAY;
|
|
UpdateMap();
|
|
}
|
|
}
|
|
|
|
void Start()
|
|
{
|
|
if (null == SceneMapFix.Instance())
|
|
{
|
|
ResourceManager.InstantiateResource("Prefab/Logic/SceneMapFix", "SceneMapFix");
|
|
}
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
ShowRadar = true;
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
ShowRadar = false;
|
|
}
|
|
|
|
void OnDestroy()
|
|
{
|
|
Games.Events.EventDispatcher.Instance.Remove(Games.Events.EventId.UpdateUpRightSceneLineInfo, UpdateSceneLineInfo);
|
|
Games.Events.EventDispatcher.Instance.Remove(Games.Events.EventId.OnSceneMapFixLoadOver, InitNpcInfo);
|
|
}
|
|
|
|
public void CancleScenInfo()
|
|
{
|
|
CancelInvoke();
|
|
if (m_mapInterface != null)
|
|
m_mapInterface.ClearStaticPoint();
|
|
}
|
|
|
|
public void InitSceneInfo()
|
|
{
|
|
Tab_SceneClass curScene = TableManager.GetSceneClassByID(GameManager.gameManager.RunningScene, 0);
|
|
if (null == curScene)
|
|
{
|
|
|
|
LogModule.ErrorLog("load scene map table fail :" + GameManager.gameManager.RunningScene);
|
|
return;
|
|
}
|
|
if (GameManager.gameManager.RunningScene == (int)GameDefine_Globe.SCENE_DEFINE.SCENE_GUANNING)
|
|
{
|
|
LabelChannel.text = "";
|
|
}
|
|
else
|
|
{
|
|
LabelChannel.text = StrDictionary.GetClientDictionaryString("{#1177}", SceneData.SceneInst + 1);
|
|
}
|
|
Tab_SceneClass curTabScene = TableManager.GetSceneClassByID(GameManager.gameManager.RunningScene, 0);
|
|
if (null != curTabScene && (curTabScene.Type == 2 || curTabScene.Type == 3))
|
|
{
|
|
LabelChannel.text = "";
|
|
}
|
|
if (MapClip != null && string.IsNullOrEmpty(curScene.SceneMapTexture) == false)
|
|
{
|
|
m_mapInterface.SetMapImage(curScene.SceneMapTexture, MapClip);
|
|
}
|
|
|
|
InitSceneNameIcon(curScene.Name);
|
|
InitSceneNmaeTip(curScene.Name);
|
|
// 开始更新地图
|
|
_nextUpdateTime = 0f;
|
|
}
|
|
|
|
public void InitSceneNameIcon(string resName)
|
|
{
|
|
//设置场景描述Icon
|
|
if (resName != "-1")
|
|
{
|
|
m_SceneNameTip.gameObject.SetActive(true);
|
|
sceneIcon.gameObject.SetActive(true); //显示地图Icon
|
|
//LoadAssetBundle.Instance.SetImageSprite(sceneIcon, resName);
|
|
sceneIcon.text = resName;
|
|
sceneIcon.SetNativeSize();
|
|
Invoke("HideSceneNameTip", 4.0f);
|
|
}
|
|
else
|
|
{
|
|
if (m_SceneNameTip.gameObject.activeInHierarchy)
|
|
{
|
|
m_SceneNameTip.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void InitSceneNmaeTip(string name)
|
|
{
|
|
if (SceneData.sceneGuildGuid != Games.GlobeDefine.GlobeVar.INVALID_GUID)
|
|
{
|
|
if (SceneData.sceneGuildGuid == GameManager.gameManager.PlayerDataPool.GuildInfo.GuildGuid)
|
|
{
|
|
m_LabelSceneName.text = GameManager.gameManager.PlayerDataPool.GuildInfo.GuildName;
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
if (SceneData.sceneGuildName != "")
|
|
{
|
|
m_LabelSceneName.text = SceneData.sceneGuildName;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
m_LabelSceneName.text = name;
|
|
}
|
|
|
|
public void HideSceneNameTip()
|
|
{
|
|
m_SceneNameTip.gameObject.SetActive(false);
|
|
}
|
|
|
|
|
|
public void ShowSceneMap()
|
|
{
|
|
if (FirstShowScene.Instance() != null)
|
|
{
|
|
return;
|
|
}
|
|
if (MainUILogic.Instance() != null && SceneMapFix.Instance() != null)
|
|
{
|
|
UIManager.ShowUI(UIInfo.SceneMapRoot);
|
|
}
|
|
}
|
|
|
|
public void OnChangeChannelClick()
|
|
{
|
|
if (FirstShowScene.Instance() != null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Tab_SceneClass curTabScene = TableManager.GetSceneClassByID(GameManager.gameManager.RunningScene, 0);
|
|
if (null == curTabScene)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (curTabScene.Type == 2 || curTabScene.Type == 3)
|
|
{
|
|
// 副本不允许切线
|
|
return;
|
|
}
|
|
|
|
CG_REQ_SCENE_SUB_LINE ask = (CG_REQ_SCENE_SUB_LINE)PacketDistributed.CreatePacket(MessageID.PACKET_CG_REQ_SCENE_SUB_LINE);
|
|
ask.NoParam = 1;
|
|
ask.SendPacket();
|
|
//UIManager.ShowUI(UIInfo.ChannelChange);
|
|
}
|
|
|
|
public void InitNpcInfo(object args)
|
|
{
|
|
var curTabSceneNPCDic = TableManager.GetSceneNpc().Values;
|
|
foreach (var curPair in curTabSceneNPCDic)
|
|
{
|
|
if (curPair.SceneID == GameManager.gameManager.RunningScene)
|
|
{
|
|
Tab_RoleBaseAttr curRoleBase = TableManager.GetRoleBaseAttrByID(curPair.DataID, 0);
|
|
if (curRoleBase != null)
|
|
{
|
|
if (curRoleBase.Camp == 1 && curRoleBase.IsShowInMap == 1)
|
|
{
|
|
var data = new MapInterface.PointInfoData
|
|
{
|
|
m_name = curRoleBase.Name,
|
|
m_pos = ActiveScene.GetTerrainPosition(
|
|
new Vector2(curPair.PosX, curPair.PosZ)
|
|
.InsertY())
|
|
};
|
|
CreateNPCPoint(data);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public void CreateNPCPoint(MapInterface.PointInfoData pointData)
|
|
{
|
|
if (m_mapInterface == null)
|
|
return;
|
|
pointData.m_cloneObj = m_pointNpc;
|
|
m_mapInterface.ClonePoint(pointData);
|
|
}
|
|
|
|
void UpdateMap()
|
|
{
|
|
var mainPlayer = ObjManager.Instance.MainPlayer;
|
|
if (mainPlayer != null)
|
|
{
|
|
//if (sceneIcon.isActiveAndEnabled)
|
|
//{
|
|
// sceneIcon.SetNativeSize();
|
|
//}
|
|
var mainPlayerMapPos = m_mapInterface.ScenePosToMapPosVec3(mainPlayer.transform.position);
|
|
var rect = MapClip.gameObject.GetComponent<RectTransform>();
|
|
if (rect != null)
|
|
{
|
|
var addx = MapClipRect.sizeDelta.x / 2 - (rect.sizeDelta.x / 2 - Mathf.Abs(mainPlayerMapPos.x));
|
|
var addy = MapClipRect.sizeDelta.y / 2 - (rect.sizeDelta.y / 2 - Mathf.Abs(mainPlayerMapPos.y));
|
|
var newx = mainPlayerMapPos.x;
|
|
var newy = mainPlayerMapPos.y;
|
|
if (addx > 0)
|
|
newx = mainPlayerMapPos.x / Mathf.Abs(mainPlayerMapPos.x) * (Mathf.Abs(mainPlayerMapPos.x) - addx);
|
|
if (addy > 0)
|
|
newy = mainPlayerMapPos.y / Mathf.Abs(mainPlayerMapPos.y) * (Mathf.Abs(mainPlayerMapPos.y) - addy);
|
|
|
|
rect.localPosition = new Vector3(0 - newx, 0 - newy, mainPlayerMapPos.z);
|
|
|
|
Vector3 arrowPos = Vector3.zero;
|
|
if (addx > 0)
|
|
arrowPos.x = mainPlayerMapPos.x / Mathf.Abs(mainPlayerMapPos.x) * addx;
|
|
if (addy > 0)
|
|
arrowPos.y = mainPlayerMapPos.y / Mathf.Abs(mainPlayerMapPos.y) * addy;
|
|
RectTransform arrowRect = ObjArrow.GetComponent<RectTransform>();
|
|
if (arrowRect != null)
|
|
{
|
|
arrowRect.localPosition = arrowPos;
|
|
}
|
|
}
|
|
|
|
if (null != LabelPos)
|
|
{
|
|
LabelPos.text = ((int)mainPlayer.transform.position.x).ToString() + ", " +
|
|
((int)mainPlayer.transform.position.z).ToString();
|
|
}
|
|
|
|
if (m_mapInterface != null)
|
|
{
|
|
m_mapInterface.UpdateMap();
|
|
}
|
|
}
|
|
}
|
|
} |