2024-12-06 13:20:10 +00:00
|
|
|
using System.Collections.Generic;
|
2024-08-29 09:51:32 +00:00
|
|
|
using DG.Tweening;
|
2024-06-07 17:31:08 +00:00
|
|
|
using Sirenix.OdinInspector;
|
|
|
|
using UnityEngine;
|
2024-12-06 13:20:10 +00:00
|
|
|
using UnityEngine.EventSystems;
|
2024-08-29 09:51:32 +00:00
|
|
|
using UnityEngine.UI;
|
2024-06-07 17:31:08 +00:00
|
|
|
|
|
|
|
namespace BlueWater.Uis
|
|
|
|
{
|
|
|
|
public class TycoonUiManager : Singleton<TycoonUiManager>
|
|
|
|
{
|
|
|
|
// Variables
|
|
|
|
#region Variables
|
2024-06-18 18:16:19 +00:00
|
|
|
|
|
|
|
[field: SerializeField]
|
|
|
|
public Canvas MainCanvas { get; private set; }
|
|
|
|
|
2024-11-07 09:13:54 +00:00
|
|
|
[field: SerializeField]
|
|
|
|
public Canvas WorldCanvas { get; private set; }
|
|
|
|
|
2024-08-29 09:51:32 +00:00
|
|
|
[SerializeField]
|
|
|
|
private Image _fadeImage;
|
2024-12-06 13:20:10 +00:00
|
|
|
|
|
|
|
[Title("테스트")]
|
|
|
|
[SerializeField]
|
|
|
|
private bool _isUiClickTest;
|
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
private GraphicRaycaster _raycaster;
|
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
private EventSystem _eventSystem;
|
2024-06-07 17:31:08 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
// Unity events
|
|
|
|
#region Unity events
|
|
|
|
|
|
|
|
protected override void OnAwake()
|
|
|
|
{
|
|
|
|
InitializeComponents();
|
|
|
|
}
|
|
|
|
|
2024-07-22 00:42:29 +00:00
|
|
|
private void Start()
|
2024-06-07 17:31:08 +00:00
|
|
|
{
|
2024-10-10 09:32:18 +00:00
|
|
|
EventManager.OnFadeInOut += FadeInOut;
|
2024-06-07 17:31:08 +00:00
|
|
|
}
|
2024-12-06 13:20:10 +00:00
|
|
|
|
|
|
|
private void Update()
|
|
|
|
{
|
|
|
|
if (!_isUiClickTest) return;
|
|
|
|
|
|
|
|
if (Input.GetMouseButtonDown(0))
|
|
|
|
{
|
|
|
|
// 1. UI Raycast
|
|
|
|
PointerEventData pointerData = new PointerEventData(_eventSystem)
|
|
|
|
{
|
|
|
|
position = Input.mousePosition
|
|
|
|
};
|
|
|
|
|
|
|
|
List<RaycastResult> uiResults = new List<RaycastResult>();
|
|
|
|
_raycaster.Raycast(pointerData, uiResults);
|
|
|
|
|
|
|
|
if (uiResults.Count > 0)
|
|
|
|
{
|
|
|
|
Debug.Log($"Clicked on UI: {uiResults[0].gameObject.name}");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 2. 3D Raycast
|
|
|
|
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
|
|
|
if (Physics.Raycast(ray, out RaycastHit hit))
|
|
|
|
{
|
|
|
|
Debug.Log($"Clicked on 3D Object: {hit.collider.gameObject.name}");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 3. 2D Raycast
|
|
|
|
Vector2 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
|
|
|
|
RaycastHit2D hit2D = Physics2D.Raycast(mousePosition, Vector2.zero);
|
|
|
|
|
|
|
|
if (hit2D.collider != null)
|
|
|
|
{
|
|
|
|
Debug.Log($"Clicked on 2D Object: {hit2D.collider.gameObject.name}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-07-22 00:42:29 +00:00
|
|
|
|
|
|
|
private void OnDestroy()
|
|
|
|
{
|
2024-10-10 09:32:18 +00:00
|
|
|
EventManager.OnFadeInOut -= FadeInOut;
|
2024-07-22 00:42:29 +00:00
|
|
|
}
|
|
|
|
|
2024-06-07 17:31:08 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
// Initialize methods
|
|
|
|
#region Initialize methods
|
|
|
|
|
|
|
|
[Button("셋팅 초기화")]
|
|
|
|
private void InitializeComponents()
|
|
|
|
{
|
2024-06-18 18:16:19 +00:00
|
|
|
MainCanvas = GetComponent<Canvas>();
|
2024-11-07 09:13:54 +00:00
|
|
|
WorldCanvas = GameObject.Find("WorldCanvas").GetComponent<Canvas>();
|
2024-06-07 17:31:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
// Methods
|
|
|
|
#region Methods
|
2024-08-29 09:51:32 +00:00
|
|
|
|
|
|
|
public void FadeInOut(float fadeInTime, float fadeOutTime, Color? fadeColor = null, float delayAfterFadeIn = 0f)
|
|
|
|
{
|
|
|
|
var newColor = new Color(1f, 1f, 1f, 0f);
|
|
|
|
if (fadeColor != null)
|
|
|
|
{
|
|
|
|
newColor = (Color)fadeColor;
|
|
|
|
}
|
|
|
|
_fadeImage.color = newColor;
|
|
|
|
_fadeImage.enabled = true;
|
|
|
|
_fadeImage.DOFade(1f, fadeInTime).OnComplete(() =>
|
|
|
|
{
|
|
|
|
DOVirtual.DelayedCall(delayAfterFadeIn, () =>
|
|
|
|
{
|
|
|
|
_fadeImage.DOFade(0f, fadeOutTime).OnComplete(() =>
|
|
|
|
{
|
|
|
|
_fadeImage.enabled = false;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2024-07-22 00:42:29 +00:00
|
|
|
|
2024-06-07 17:31:08 +00:00
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|