GamesScrollController.cs 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. } else {
  41. Maximize(finishedGamesPanel);
  42. Minimize(localGamesPanel);
  43. Minimize(onlineGamesPanel);
  44. }
  45. }
  46. }
  47. public void OnPointerClick(PointerEventData eventData) {
  48. GameObject clickedObject = GameObject.Find(eventData.pointerPress.name);
  49. expandThis(clickedObject.name);
  50. // Möjligt populera finished games när den expanderas
  51. }
  52. private void Maximize(GameObject activeObject) {
  53. float gamesPanelHeight = gamesPanel.GetComponent<RectTransform>().rect.height;
  54. activeObject.GetComponent<RectTransform>().sizeDelta = new Vector2(activeObject.GetComponent<RectTransform>().rect.width, gamesPanelHeight - 60f);
  55. for (int i = 0; i < activeObject.transform.childCount; i++) {
  56. if (activeObject.transform.GetChild(i).gameObject.tag.Equals("GamesPanelContent")) {
  57. activeObject.transform.GetChild(i).GetComponent<CanvasGroup>().alpha = 1f;
  58. break;
  59. }
  60. }
  61. }
  62. private void Minimize(GameObject activeObject) {
  63. activeObject.GetComponent<RectTransform>().sizeDelta = new Vector2(activeObject.GetComponent<RectTransform>().rect.width, 30f);
  64. for (int i = 0; i < activeObject.transform.childCount; i++) {
  65. if (activeObject.transform.GetChild(i).gameObject.tag.Equals("GamesPanelContent")) {
  66. activeObject.transform.GetChild(i).GetComponent<CanvasGroup>().alpha = 0f;
  67. break;
  68. }
  69. }
  70. }
  71. }