using System.Collections; using System.Collections.Generic; using UnityEngine; using RPGCreationKit; using TMPro; using UnityEngine.UI; using UnityEngine.EventSystems; namespace RPGCreationKit.Player { /// /// Contains references to UI components and methods to modify/interact with them /// public class PlayerUIManager : MonoBehaviour { [Header("General")] public Slider playerHealthSlider; public Slider playerStaminaSlider; public Slider playerManaSlider; public TextMeshProUGUI Interact_text; public GameObject compassGameObject; // <-- removed public GameObject StatsUIGameObject; public GameObject crosshairGameObject; public GameObject crosshairHit; [Header("Dialogue System")] public GameObject dialogueContainer; public GameObject playerQuestionsContainer; public TextMeshProUGUI npc_Name; public TextMeshProUGUI npc_Line; public TextMeshProUGUI heardDialogues; public Transform playerQuestionsContent; [Header("Combat UI")] public GameObject enemyHealthContainer; public Slider enemyHealthSlider; public TextMeshProUGUI enemyName; [Header("Prefabs")] public GameObject interactiveObjectUIContainer; public Transform interactiveOptionContent; public TextMeshProUGUI interactiveObjectName; public TextMeshProUGUI interactiveObjectDescription; [Header("Prefabs")] public GameObject playerQuestionPrefab; public GameObject interactiveOptionUIPrefab; [SerializeField] public List allPlayerQuestions = new List(); private void Update() { if(RckPlayer.instance.isInConversation && RckInput.isUsingGamepad) PreventUnselectedQuestionWithGamepad(); } public void OnPlayerHits() { crosshairHit.SetActive(true); Invoke("OnHitEnds", RCKSettings.CROSSHAIR_HIT_TIME); } void OnPlayerHitEnds() { crosshairHit.SetActive(false); } public void ReorderQuestions() { List questions = new List(); foreach (Transform t in playerQuestionsContent) questions.Add(t.GetComponent()); questions.Sort(SortByPosition); for (int i = 0; i < questions.Count; i++) questions[i].GetComponent().SetSiblingIndex(questions[i].position); if(questions.Count > 0) EventSystem.current.SetSelectedGameObject(questions[0].gameObject); } public void PreventUnselectedQuestionWithGamepad() { if (EventSystem.current.currentSelectedGameObject == null && RckInput.isUsingGamepad) { if (playerQuestionsContent.childCount > 0 && playerQuestionsContent.GetChild(0) != null) EventSystem.current.SetSelectedGameObject(playerQuestionsContent.GetChild(0).gameObject); } } public static int SortByPosition(PlayerQuestionUI p1, PlayerQuestionUI p2) { return p1.position.CompareTo(p2.position); } } }