Files
2025-05-29 22:31:40 +03:00

264 lines
7.9 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Rendering.HighDefinition;
using TMPro;
using UnityEngine.Playables;
using UnityEngine.EventSystems;
using UnityEngine.Localization;
public class UIManager : MonoBehaviour
{
[Header("Raycast UI")]
public GameObject raycastDefault;
public GameObject raycastInteractabe;
public GameObject raycastLocked;
[Header("Spherecast UI")]
public GameObject sphereInteractable;
#region sanity related
[Header("Sanity")]
public RawImage SanityMeterUI; //The RawImage meter UI for the sanity of the player.
public float minimumAlphaColor = 0.0f; //The minimum alpha color of the sprite.
public float maximumAlphaColor = 1f; //The maximum alpha color of the sprite.
public float sanityDuration = 300f; // It must be the same with the _sanity from the sanity script to work.
[HideInInspector]
public float startTime;
#endregion
#region Notifications
[Header("Notifications")]
public GameObject messagesContainer;
public TextMeshProUGUI MessageText;
public LocalizedString localizedMessageText;
//public LocalizedString localizedMessageText;
public Animator AnimatorLabel;
public Image labelImage;
public bool messagesContainerIsEnabled = true;
#endregion
#region MouseUI
[Header("Mouse UI")]
public GameObject mouseUIMiddle;
public TextMeshProUGUI mouseUIMiddleText;
public LocalizedString localizedMouseUIMiddleLabel;
public GameObject mouseUILeft;
public TextMeshProUGUI mouseUILeftText;
public LocalizedString localizedMouseUILeftLabel;
public GameObject mouseUIRight;
public TextMeshProUGUI mouseUIRightText;
public LocalizedString localizedMouseUIRightLabel;
#endregion
[Header("Pocket Watch UI")]
public GameObject pocketWatchIndicationsPanel;
[Header("Tutorial UI")]
public Image tutorialHintBackgroundPanel;
public TextMeshProUGUI tutorialHintText;
[Header("Important Tutorial Hint")]
public RawImage importantTutorialHintImage;
public TextMeshProUGUI importantTutorialHintTitleText;
public TextMeshProUGUI importantTutorialHintDescriptionText;
public TextMeshProUGUI importantTutorialHintKeyToPressToClose;
public PlayableDirector tutorialHintFadeInPlayable;
public PlayableDirector tutorialHintFadeOutPlayable;
[HideInInspector] public ImportantTutorialHint currentImportantTutorialHint;
#region Cutscenes UI
[Header("Cutscenes UI")]
public TextMeshProUGUI TitlesUI;
#endregion
#region WorldUI
[Header("World UI")]
public GameObject worldUI_Icon;
public bool updateUI = false;
public bool userInterfaceIsOnScreen;
#endregion
public CustomPassVolume customPassUIRenderOnTop;
public LayerMask customPassUIRenderOnTopObjectsToExclude;
#region Inventory Related
[Header("Inventory UI Related")]
public CustomPassVolume customPassUIRenderOnTop_UIAndModels;
public CustomPassVolume CustomPassUIRenderOnTop_UIOnly;
#endregion
public EventSystem eventSystem;
private static UIManager _instance;
public static UIManager GetInstance() { return _instance; }
void Awake()
{
if (!_instance)
{
_instance = this;
}
#region Sanity related
//SanityMeterUI.color = new Color(1f, 1f, 1f, 0f); //Sets the alpha of the image to 0 as default before the game starts.
startTime = Time.time;
#endregion
#region MouseUI related
MouseUIMiddleDisable();
MouseUILeftDisable();
MouseUIRightDisable();
#endregion
}
private void Update()
{
if (userInterfaceIsOnScreen)
{
if (messagesContainerIsEnabled)
{
labelImage.enabled = false;
MessageText.enabled = false;
tutorialHintBackgroundPanel.enabled = false;
tutorialHintText.enabled = false;
messagesContainerIsEnabled = false;
}
}
else
{
if (messagesContainerIsEnabled == false)
{
labelImage.enabled = true;
MessageText.enabled = true;
tutorialHintBackgroundPanel.enabled = true;
tutorialHintText.enabled = true;
messagesContainerIsEnabled = true;
}
}
}
private void Start()
{
eventSystem = FindObjectOfType<EventSystem>();
// Force refresh των TMP Texts που έχουν <sprite> tags
if (tutorialHintText != null) tutorialHintText.ForceMeshUpdate();
if (importantTutorialHintDescriptionText != null) importantTutorialHintDescriptionText.ForceMeshUpdate();
if (importantTutorialHintKeyToPressToClose != null) importantTutorialHintKeyToPressToClose.ForceMeshUpdate();
if (mouseUIMiddleText != null) mouseUIMiddleText.ForceMeshUpdate();
if (mouseUILeftText != null) mouseUILeftText.ForceMeshUpdate();
if (mouseUIRightText != null) mouseUIRightText.ForceMeshUpdate();
if (MessageText != null) MessageText.ForceMeshUpdate();
Debug.Log(" UIManager TMP Texts refreshed at Start!");
}
public IEnumerator DisplayMessage(LocalizedString messageText)
{
MessageText.text = messageText.GetLocalizedString(localizedMessageText);
AnimatorLabel.SetBool("IsFadedIn", true);
yield return new WaitForSeconds(3.5f);
AnimatorLabel.SetBool("IsFadedIn", false);
}
public void DisplayMessageOnScreen(LocalizedString messageText)
{
StartCoroutine(DisplayMessage(messageText));
}
public void DisplayPrompt(LocalizedString promptText)
{
MessageText.text = promptText.GetLocalizedString();
}
#region Mouse UI
#region Mouse UI Activation
public void MouseUIMiddleDisplay(LocalizedString text)
{
mouseUIMiddle.SetActive(true);
mouseUIMiddleText.text = localizedMouseUIMiddleLabel.GetLocalizedString();
}
public void MouseUILeftDisplay(LocalizedString text)
{
mouseUILeft.SetActive(true);
mouseUILeftText.text = localizedMouseUILeftLabel.GetLocalizedString();
}
public void MouseUIRightDisplay(LocalizedString text)
{
mouseUIRight.SetActive(true);
mouseUIRightText.text = localizedMouseUIRightLabel.GetLocalizedString();
}
#endregion
#region MouseUI Disable
public void MouseUIMiddleDisable()
{
mouseUIMiddle.SetActive(false);
mouseUIMiddleText.text = "";
}
public void MouseUILeftDisable()
{
mouseUILeft.SetActive(false);
mouseUILeftText.text = "";
}
public void MouseUIRightDisable()
{
mouseUIRight.SetActive(false);
mouseUIRightText.text = "";
}
#endregion
#endregion
#region World UI Icons
public void DisableWorldUIIcon()
{
worldUI_Icon.SetActive(false);
}
public void DisableUIItemIconVisibility()
{
customPassUIRenderOnTop.gameObject.SetActive(false);
// Set the camera's culling mask to exclude objects on the specified layer
Camera.main.cullingMask &= ~customPassUIRenderOnTopObjectsToExclude.value;
}
public void EnableUIItemIconVisibility()
{
customPassUIRenderOnTop.gameObject.SetActive(true);
// Set the camera's culling mask to include the objects on the specified layer
Camera.main.cullingMask |= customPassUIRenderOnTopObjectsToExclude.value;
}
#endregion
#region Important Tutorial Hint
public void UpdateImportantTutorialHintInput()
{
currentImportantTutorialHint.UpdateTutorialInput();
}
#endregion
public void OpenPocketWatchIndicationsPanel()
{
pocketWatchIndicationsPanel.SetActive(true);
}
public void ClosePocketWatchIndicationsPanel()
{
pocketWatchIndicationsPanel.SetActive(false);
}
}