71 lines
2.0 KiB
C#
71 lines
2.0 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using WI;
|
|
|
|
namespace CHN
|
|
{
|
|
public class Panel_MiniMap : PanelBase
|
|
{
|
|
OrbitalControllerTarget target;
|
|
|
|
Image MiniMapScreen;
|
|
RectTransform Image_MiniMapIcon;
|
|
TextMeshProUGUI Text_MiniMapFloor;
|
|
|
|
Vector2 worldMin = new Vector2(-40.25f, -32.0f);
|
|
Vector2 worldMax = new Vector2(57.25f, 31.0f);
|
|
|
|
[SerializeField]
|
|
Sprite[] miniMapImages;
|
|
|
|
public override void AfterAwake()
|
|
{
|
|
target = FindSingle<OrbitalControllerTarget>();
|
|
SetActive(false);
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
UpdateMiniMapIcon();
|
|
}
|
|
|
|
public void ChangeMiniMapFloor(int floorValue)
|
|
{
|
|
int floor = floorValue + 1;
|
|
Text_MiniMapFloor.text = floor.ToString() + "F";
|
|
|
|
MiniMapScreen.sprite = miniMapImages[floorValue];
|
|
}
|
|
|
|
void UpdateMiniMapIcon()
|
|
{
|
|
Vector2 worldPos = new Vector2(target.transform.position.x, target.transform.position.z);
|
|
Vector2 normalizedPos = (worldPos - worldMin) / (worldMax - worldMin);
|
|
|
|
RectTransform miniMapRect = MiniMapScreen.GetComponent<RectTransform>();
|
|
Vector2 miniMapSize = miniMapRect.rect.size;
|
|
Vector2 iconPos = new Vector2(
|
|
(normalizedPos.x * miniMapSize.x) - (miniMapSize.x * 0.5f),
|
|
(normalizedPos.y * miniMapSize.y) - (miniMapSize.y * 0.5f)
|
|
);
|
|
|
|
Image_MiniMapIcon.anchoredPosition = iconPos;
|
|
|
|
float cameraRotateY = Camera.main.transform.eulerAngles.y;
|
|
Image_MiniMapIcon.localEulerAngles = new Vector3(0, 0, -cameraRotateY);
|
|
}
|
|
|
|
public void SetActive()
|
|
{
|
|
var isActive = gameObject.activeSelf;
|
|
var active = isActive ? false : true;
|
|
|
|
gameObject.SetActive(active);
|
|
}
|
|
}
|
|
}
|
|
|