GamesScrollController.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.EventSystems;
  5. using UnityEngine.UI;
  6. public class GamesScrollController : MonoBehaviour, IPointerClickHandler {
  7. public Sprite upArrow;
  8. public Sprite downArrow;
  9. public GameObject localGamesPanel;
  10. public GameObject onlineGamesPanel;
  11. public GameObject finishedGamesPanel;
  12. public GameObject gamesPanel;
  13. public void OnPointerClick(PointerEventData eventData) {
  14. GameObject clickedObject = GameObject.Find(eventData.pointerPress.name);
  15. bool finishExpanded = finishedGamesPanel.GetComponent<RectTransform>().rect.height > 31f ? true : false;
  16. bool localExpanded = localGamesPanel.GetComponent<RectTransform>().rect.height > 31f ? true : false;
  17. bool onlineExpanded = onlineGamesPanel.GetComponent<RectTransform>().rect.height > 31f ? true : false;
  18. int numberExpanded = 0;
  19. if (finishExpanded) { numberExpanded++; };
  20. if (localExpanded) { numberExpanded++; };
  21. if (onlineExpanded) { numberExpanded++; };
  22. if (clickedObject.name.Equals("LocalGamesTitle")) {
  23. if (localExpanded) {
  24. Minimize(localGamesPanel);
  25. } else {
  26. Maximize(localGamesPanel);
  27. Minimize(onlineGamesPanel);
  28. Minimize(finishedGamesPanel);
  29. }
  30. } else if (clickedObject.name.Equals("OnlineGamesTitle")) {
  31. if (onlineExpanded) {
  32. Minimize(onlineGamesPanel);
  33. } else {
  34. Maximize(onlineGamesPanel);
  35. Minimize(localGamesPanel);
  36. Minimize(finishedGamesPanel);
  37. }
  38. } else if (clickedObject.name.Equals("FinishedGamesTitle")) {
  39. if (finishExpanded) {
  40. Minimize(finishedGamesPanel);
  41. finishedGamesPanel.GetComponentInChildren<Scrollbar>().handleRect.parent.GetComponentInChildren<Image>().enabled = false;
  42. } else {
  43. Maximize(finishedGamesPanel);
  44. Minimize(localGamesPanel);
  45. Minimize(onlineGamesPanel);
  46. finishedGamesPanel.GetComponentInChildren<Scrollbar>().handleRect.parent.GetComponentInChildren<Image>().enabled = true;
  47. }
  48. }
  49. }
  50. private void Maximize(GameObject activeObject) {
  51. float gamesPanelHeight = gamesPanel.GetComponent<RectTransform>().rect.height;
  52. activeObject.GetComponent<RectTransform>().sizeDelta = new Vector2(activeObject.GetComponent<RectTransform>().rect.width, gamesPanelHeight - 60f);
  53. }
  54. private void Minimize(GameObject activeObject) {
  55. activeObject.GetComponent<RectTransform>().sizeDelta = new Vector2(activeObject.GetComponent<RectTransform>().rect.width, 30f);
  56. }
  57. }