using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; public class GamesScrollController : MonoBehaviour, IPointerClickHandler { public Sprite upArrow; public Sprite downArrow; public GameObject localGamesPanel; public GameObject onlineGamesPanel; public GameObject finishedGamesPanel; public GameObject gamesPanel; public void expandThis(string objectName) { bool finishExpanded = finishedGamesPanel.GetComponent().rect.height > 31f ? true : false; bool localExpanded = localGamesPanel.GetComponent().rect.height > 31f ? true : false; bool onlineExpanded = onlineGamesPanel.GetComponent().rect.height > 31f ? true : false; int numberExpanded = 0; if (finishExpanded) { numberExpanded++; }; if (localExpanded) { numberExpanded++; }; if (onlineExpanded) { numberExpanded++; }; if (objectName.Equals("LocalGamesTitle")) { if (localExpanded) { Minimize(localGamesPanel); } else { Maximize(localGamesPanel); Minimize(onlineGamesPanel); Minimize(finishedGamesPanel); } } else if (objectName.Equals("OnlineGamesTitle")) { if (onlineExpanded) { Minimize(onlineGamesPanel); } else { Maximize(onlineGamesPanel); Minimize(localGamesPanel); Minimize(finishedGamesPanel); } } else if (objectName.Equals("FinishedGamesTitle")) { if (finishExpanded) { Minimize(finishedGamesPanel); finishedGamesPanel.GetComponentInChildren().handleRect.parent.GetComponentInChildren().enabled = false; } else { Maximize(finishedGamesPanel); Minimize(localGamesPanel); Minimize(onlineGamesPanel); finishedGamesPanel.GetComponentInChildren().handleRect.parent.GetComponentInChildren().enabled = true; } } } public void OnPointerClick(PointerEventData eventData) { GameObject clickedObject = GameObject.Find(eventData.pointerPress.name); expandThis(clickedObject.name); } private void Maximize(GameObject activeObject) { float gamesPanelHeight = gamesPanel.GetComponent().rect.height; activeObject.GetComponent().sizeDelta = new Vector2(activeObject.GetComponent().rect.width, gamesPanelHeight - 60f); } private void Minimize(GameObject activeObject) { activeObject.GetComponent().sizeDelta = new Vector2(activeObject.GetComponent().rect.width, 30f); } }