You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
2.0 KiB

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class PlayerUIManager : MonoBehaviour
  5. {
  6. [SerializeField]
  7. private RectTransform Inventory;
  8. [SerializeField]
  9. private float AnimationSpeed = 0.5f;
  10. [SerializeField]
  11. private BlockInput characterInput;
  12. [SerializeField]
  13. private LogicTrayUI TrayUI;
  14. private Vector3 ShowPosition;
  15. private Vector3 HidePosition;
  16. private void Awake()
  17. {
  18. ShowPosition = new Vector3(0, -Inventory.rect.height / 2, 0);
  19. HidePosition = new Vector3(0, Inventory.rect.height/2, 0);
  20. Debug.Log(Inventory.rect.height);
  21. Inventory.anchoredPosition = HidePosition;
  22. TrayUI.SetBlockReader(characterInput.blockReader);
  23. }
  24. [ContextMenu("Show")]
  25. public void OnClick_Show()
  26. {
  27. StopAllCoroutines();
  28. StartCoroutine( LerpPosition(Inventory, ShowPosition, AnimationSpeed));
  29. }
  30. [ContextMenu("Hide")]
  31. public void OnClick_Hide()
  32. {
  33. StopAllCoroutines();
  34. StartCoroutine( LerpPosition(Inventory, HidePosition, AnimationSpeed));
  35. }
  36. public void OnClick_Toggle()
  37. {
  38. if (Vector3.Distance(Inventory.anchoredPosition,ShowPosition) < Vector3.Distance(Inventory.anchoredPosition, HidePosition))
  39. {
  40. Debug.Log("Hiding Menu");
  41. OnClick_Hide();
  42. }
  43. else
  44. {
  45. Debug.Log("Showing Menu");
  46. OnClick_Show();
  47. }
  48. }
  49. public void OnClick_Play() {
  50. OnClick_Hide();
  51. characterInput.ReadAll();
  52. }
  53. private IEnumerator LerpPosition(RectTransform rt, Vector3 endPosition, float time)
  54. {
  55. float elapsedTime = 0;
  56. Vector3 startPos = rt.anchoredPosition;
  57. while (elapsedTime < time)
  58. {
  59. rt.anchoredPosition = Vector3.Slerp(startPos, endPosition, (elapsedTime / time));
  60. elapsedTime += Time.deltaTime;
  61. yield return new WaitForEndOfFrame();
  62. }
  63. rt.anchoredPosition = endPosition;
  64. }
  65. }