110 lines
3.2 KiB
C#
110 lines
3.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using WI;
|
|
|
|
namespace Samkwang
|
|
{
|
|
public class Panel_MiniMap : MonoBehaviour
|
|
{
|
|
GameObject target;
|
|
|
|
private Image MiniMapScreen;
|
|
private RectTransform Image_MiniMapIcon;
|
|
private Button Button_Close;
|
|
private bool isTourMode;
|
|
|
|
public Vector2 worldPos;
|
|
|
|
public Vector2 worldSize;
|
|
public Vector2 worldMin;
|
|
public Vector2 worldMax;
|
|
public float offset;
|
|
|
|
public Action onClickCloseButton;
|
|
|
|
//[SerializeField]
|
|
//Sprite[] miniMapImages;
|
|
|
|
public void Init()
|
|
{
|
|
var imageDict = transform.GetChildComponentsByName<Image>();
|
|
var rectDict = transform.GetChildComponentsByName<RectTransform>();
|
|
var buttonDict = transform.GetChildComponentsByName<Button>();
|
|
target = FindAnyObjectByType<OrbitalControllerTarget>().gameObject;
|
|
|
|
MiniMapScreen = imageDict.GetOrNull(nameof(MiniMapScreen));
|
|
Image_MiniMapIcon = rectDict.GetOrNull(nameof(Image_MiniMapIcon));
|
|
Button_Close = buttonDict.GetOrNull(nameof(Button_Close));
|
|
|
|
worldMin = worldPos - 0.5f * worldSize;
|
|
worldMax = worldMin + worldSize;
|
|
|
|
Button_Close.onClick.AddListener(OnClickCloseButton);
|
|
gameObject.SetActive(false);
|
|
}
|
|
private void OnClickCloseButton()
|
|
{
|
|
gameObject.SetActive(false);
|
|
onClickCloseButton?.Invoke();
|
|
}
|
|
public void ChangedTarget()
|
|
{
|
|
if (!isTourMode)
|
|
{
|
|
target = Camera.main.gameObject;
|
|
isTourMode = true;
|
|
}
|
|
else
|
|
{
|
|
SetOriginTarget();
|
|
}
|
|
}
|
|
public void SetOriginTarget()
|
|
{
|
|
target = FindAnyObjectByType<OrbitalControllerTarget>().gameObject;
|
|
isTourMode = false;
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
UpdateMiniMapIcon();
|
|
}
|
|
|
|
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.y * miniMapSize.y) - (miniMapSize.y * 0.5f),
|
|
-((normalizedPos.x * miniMapSize.x) - (miniMapSize.x * 0.5f))
|
|
);
|
|
|
|
Image_MiniMapIcon.anchoredPosition = iconPos;
|
|
|
|
float cameraRotateY = Camera.main.transform.eulerAngles.y;
|
|
Image_MiniMapIcon.localEulerAngles = new Vector3(0, 0, -cameraRotateY + offset);
|
|
}
|
|
|
|
public void SetActive()
|
|
{
|
|
var isActive = gameObject.activeSelf;
|
|
var active = isActive ? false : true;
|
|
|
|
gameObject.SetActive(active);
|
|
}
|
|
|
|
//public void ChangeMiniMapFloor(bool isActive)
|
|
//{
|
|
// var sprite = isActive ? miniMapImages[0] : miniMapImages[1];
|
|
// MiniMapScreen.sprite = sprite;
|
|
//}
|
|
}
|
|
}
|
|
|