| | |
| | | public Button m_Map;
|
| | | public Button m_Daily;
|
| | | public Button m_BackPack;
|
| | | public Image m_MapImage;
|
| | | public Image m_MapHero;
|
| | | public Text m_MapName;
|
| | |
|
| | | LocalMap mapMatrix;
|
| | | Vector3 heroPrePosition = new Vector3(-999, -8888, 0);
|
| | | int dataMapId = 0;
|
| | | int lineId = 0;
|
| | | MapModel model { get { return ModelCenter.Instance.GetModel<MapModel>(); } }
|
| | |
|
| | | public void Init()
|
| | | {
|
| | |
| | | WindowCenter.Instance.Close<MainInterfaceWin>();
|
| | | }
|
| | |
|
| | |
|
| | | public void Update()
|
| | | {
|
| | | // 更新地图
|
| | | int curMapID = model.wannaLookLocalMap == 0 ? MapUtility.GetDataMapId() : model.wannaLookLocalMap;
|
| | | if (curMapID != 0 && curMapID != dataMapId)
|
| | | {
|
| | | dataMapId = curMapID;
|
| | | lineId = MapUtility.GetDataMapId() == dataMapId ? PlayerDatas.Instance.baseData.dungeonLineId : 0;
|
| | | var mapResConfig = MapResourcesConfig.GetConfig(this.dataMapId, this.lineId);
|
| | | var mapWidth = mapResConfig.MapScale.x;
|
| | | var mapHeight = mapResConfig.MapScale.y;
|
| | | var uiMapWidth = mapWidth * mapResConfig.MapShowScale;
|
| | | var uiMapHeight = mapHeight * mapResConfig.MapShowScale;
|
| | |
|
| | | this.mapMatrix = new LocalMap(this.dataMapId, mapWidth, mapHeight, uiMapWidth, uiMapHeight);
|
| | |
|
| | | m_MapImage.SetSprite(mapResConfig.BigMap);
|
| | | m_MapImage.SetNativeSize();
|
| | | var hPos = mapMatrix.WorldToLocalPosition(PlayerDatas.Instance.hero.Pos);
|
| | | heroPrePosition = hPos;
|
| | | m_MapName.text = mapResConfig.Name;
|
| | | }
|
| | |
|
| | | //更新坐标
|
| | | if (dataMapId == PlayerDatas.Instance.baseData.MapID && PlayerDatas.Instance.hero.IsRun())
|
| | | {
|
| | | var heroPos = mapMatrix.WorldToLocalPosition(PlayerDatas.Instance.hero.Pos);
|
| | | if (Vector3.Distance(heroPrePosition, heroPos) > 1f)
|
| | | {
|
| | | heroPrePosition = heroPos;
|
| | | |
| | | var _eular = PlayerDatas.Instance.hero.Root.eulerAngles; |
| | | var _mapHeroEular = m_MapHero.transform.eulerAngles; |
| | | _mapHeroEular.z = -_eular.y; |
| | | m_MapHero.transform.eulerAngles = _mapHeroEular;
|
| | | }
|
| | | }
|
| | | if (m_MapImage.transform.localPosition != heroPrePosition)
|
| | | m_MapImage.transform.localPosition = heroPrePosition;
|
| | |
|
| | |
|
| | | }
|
| | |
|
| | |
|
| | | public struct LocalMap
|
| | | {
|
| | | public int mapId;
|
| | | public float worldMapWidth;
|
| | | public float worldMapHeight;
|
| | | public float localMapWidth;
|
| | | public float localMapHeight;
|
| | |
|
| | | public LocalMap(int mapId, float mWidth, float mHeigth, float mSpriteWidth, float mSpriteHeight)
|
| | | {
|
| | | this.mapId = mapId;
|
| | | worldMapWidth = mWidth;
|
| | | worldMapHeight = mHeigth;
|
| | | localMapWidth = mSpriteWidth;
|
| | | localMapHeight = mSpriteHeight;
|
| | | }
|
| | |
|
| | | public Vector3 WorldToLocalPosition(Vector3 _worldPosition)
|
| | | {
|
| | | var x = ((worldMapWidth * 0.5f - _worldPosition.x) / worldMapWidth) * localMapWidth;
|
| | | var y = ((worldMapHeight * 0.5f - _worldPosition.z) / worldMapHeight) * localMapHeight;
|
| | | return new Vector3(x, y, 0);
|
| | | }
|
| | |
|
| | | }
|
| | | }
|
| | |
|
| | | }
|