| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- 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<RectTransform>().rect.height > 31f ? true : false;
- bool localExpanded = localGamesPanel.GetComponent<RectTransform>().rect.height > 31f ? true : false;
- bool onlineExpanded = onlineGamesPanel.GetComponent<RectTransform>().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<Scrollbar>().handleRect.parent.GetComponentInChildren<Image>().enabled = false;
- } else {
- Maximize(finishedGamesPanel);
- Minimize(localGamesPanel);
- Minimize(onlineGamesPanel);
- finishedGamesPanel.GetComponentInChildren<Scrollbar>().handleRect.parent.GetComponentInChildren<Image>().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<RectTransform>().rect.height;
- activeObject.GetComponent<RectTransform>().sizeDelta = new Vector2(activeObject.GetComponent<RectTransform>().rect.width, gamesPanelHeight - 60f);
- }
- private void Minimize(GameObject activeObject) {
- activeObject.GetComponent<RectTransform>().sizeDelta = new Vector2(activeObject.GetComponent<RectTransform>().rect.width, 30f);
- }
- }
|