GamesScrollController.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 expandThis(string objectName) {
  14. bool finishExpanded = finishedGamesPanel.GetComponent<RectTransform>().rect.height > 31f ? true : false;
  15. bool localExpanded = localGamesPanel.GetComponent<RectTransform>().rect.height > 31f ? true : false;
  16. bool onlineExpanded = onlineGamesPanel.GetComponent<RectTransform>().rect.height > 31f ? true : false;
  17. int numberExpanded = 0;
  18. if (finishExpanded) { numberExpanded++; };
  19. if (localExpanded) { numberExpanded++; };
  20. if (onlineExpanded) { numberExpanded++; };
  21. if (objectName.Equals("LocalGamesTitle")) {
  22. if (localExpanded) {
  23. Minimize(localGamesPanel);
  24. } else {
  25. Maximize(localGamesPanel);
  26. Minimize(onlineGamesPanel);
  27. Minimize(finishedGamesPanel);
  28. }
  29. } else if (objectName.Equals("OnlineGamesTitle")) {
  30. if (onlineExpanded) {
  31. Minimize(onlineGamesPanel);
  32. } else {
  33. Maximize(onlineGamesPanel);
  34. Minimize(localGamesPanel);
  35. Minimize(finishedGamesPanel);
  36. }
  37. } else if (objectName.Equals("FinishedGamesTitle")) {
  38. if (finishExpanded) {
  39. Minimize(finishedGamesPanel);
  40. finishedGamesPanel.GetComponentInChildren<Scrollbar>().handleRect.parent.GetComponentInChildren<Image>().enabled = false;
  41. } else {
  42. Maximize(finishedGamesPanel);
  43. Minimize(localGamesPanel);
  44. Minimize(onlineGamesPanel);
  45. finishedGamesPanel.GetComponentInChildren<Scrollbar>().handleRect.parent.GetComponentInChildren<Image>().enabled = true;
  46. }
  47. }
  48. }
  49. public void OnPointerClick(PointerEventData eventData) {
  50. GameObject clickedObject = GameObject.Find(eventData.pointerPress.name);
  51. expandThis(clickedObject.name);
  52. }
  53. private void Maximize(GameObject activeObject) {
  54. float gamesPanelHeight = gamesPanel.GetComponent<RectTransform>().rect.height;
  55. activeObject.GetComponent<RectTransform>().sizeDelta = new Vector2(activeObject.GetComponent<RectTransform>().rect.width, gamesPanelHeight - 60f);
  56. }
  57. private void Minimize(GameObject activeObject) {
  58. activeObject.GetComponent<RectTransform>().sizeDelta = new Vector2(activeObject.GetComponent<RectTransform>().rect.width, 30f);
  59. }
  60. }