Guest User

Untitled

a guest
May 24th, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.05 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using UnityEngine.SceneManagement;
  6.  
  7. public class PauseMenu : MonoBehaviour {
  8.  
  9.     Transform[] rightColumn;
  10.     Transform[] leftColumn;
  11.     GameObject canvas;
  12.     PlayerCamera playerCamera;
  13.     Sprite boxWCross, boxWOCross;
  14.     List<Transform> rightList = new List<Transform>();
  15.     List<Transform> leftList = new List<Transform>();
  16.     int listIndex;
  17.     int maxIndex, minIndex = 0;
  18.     bool isRightColumn;
  19.     bool delay = true;
  20.     bool isInvertedH, isInvertedV;
  21.     bool resumeGame = false;
  22.     float counter = 0;
  23.     SelectedColumn column;
  24.  
  25.     enum SelectedColumn
  26.     {
  27.         left,
  28.         right
  29.     }
  30.  
  31.     public void Initialize()
  32.     {
  33.         rightColumn = GameObject.Find("rightColumn").transform.GetComponentsInChildren<Transform>();
  34.         leftColumn = GameObject.Find("leftColumn").transform.GetComponentsInChildren<Transform>();
  35.         playerCamera = Camera.main.gameObject.GetComponent<PlayerCamera>();
  36.  
  37.         for (int i = 0; i < rightColumn.Length; i++)
  38.         {
  39.             if (rightColumn[i].transform.parent == GameObject.Find("rightColumn").transform)
  40.             {
  41.                rightList.Add(rightColumn[i]);
  42.             }
  43.         }
  44.         for (int i = 0; i < leftColumn.Length; i++)
  45.         {
  46.             if (leftColumn[i].transform.parent == GameObject.Find("leftColumn").transform)
  47.             {
  48.                 leftList.Add(leftColumn[i]);
  49.             }
  50.         }
  51.  
  52.         LoadSprites();
  53.  
  54.         canvas = GameObject.Find("PauseMenu");
  55.         canvas.SetActive(false);
  56.     }
  57.     public void Activate()
  58.     {
  59.         canvas.SetActive(true);
  60.         resumeGame = false;
  61.     }
  62.  
  63.     public void Deactivate()
  64.     {
  65.         canvas.SetActive(false);
  66.     }
  67.  
  68.     public bool UpdatePauseMenu()
  69.     {
  70.  
  71.         //Select what you want to change
  72.  
  73.  
  74.  
  75.         switch (column)
  76.         {
  77.             case SelectedColumn.left:
  78.                 Column(leftList);
  79.                 if (Input.GetAxisRaw("Horizontal") == 1)
  80.                 {
  81.                     listIndex = rightList.Count - 1;
  82.                     for (int i = 0; i < leftList.Count; i++)
  83.                     {
  84.                         leftList[i].gameObject.GetComponent<Image>().color = Color.white;
  85.                     }
  86.                     rightList[listIndex].gameObject.GetComponent<Image>().color = Color.red;
  87.                     column = SelectedColumn.right;
  88.                 }
  89.                 break;
  90.             case SelectedColumn.right:
  91.                 if (Input.GetAxisRaw("Horizontal") == -1)
  92.                 {
  93.                     listIndex = leftList.Count - 1;
  94.                     for (int i = 0; i < rightList.Count; i++)
  95.                     {
  96.                         rightList[i].gameObject.GetComponent<Image>().color = Color.white;
  97.                     }
  98.                     leftList[listIndex].gameObject.GetComponent<Image>().color = Color.red;
  99.                     column = SelectedColumn.left;
  100.                 }
  101.                 Column(rightList);
  102.                 break;
  103.         }
  104.         if (Input.GetKeyDown(KeyCode.Joystick1Button7) || resumeGame)
  105.             return false;
  106.         else
  107.             return true;
  108.     }
  109.  
  110.     void Column(List<Transform> _tList)
  111.     {
  112.         maxIndex = _tList.Count - 1;
  113.         if (Input.GetAxisRaw("Vertical") < 0)
  114.         {
  115.             if (delay)
  116.             {
  117.                 _tList[listIndex].gameObject.GetComponent<Image>().color = Color.white;
  118.                 listIndex++;
  119.                 if (listIndex > maxIndex)
  120.                 {
  121.                     listIndex = maxIndex;
  122.                 }
  123.                 _tList[listIndex].gameObject.GetComponent<Image>().color = Color.red;
  124.                 delay = false;
  125.             }
  126.             else
  127.             {
  128.                 counter += Time.deltaTime;
  129.             }
  130.            
  131.  
  132.             if (counter > 0.1f)
  133.             {
  134.                 delay = true;
  135.                 counter = 0f;
  136.             }
  137.         }
  138.         else if (Input.GetAxisRaw("Vertical") > 0)
  139.         {
  140.             if (delay)
  141.             {
  142.                 _tList[listIndex].gameObject.GetComponent<Image>().color = Color.white;
  143.                 listIndex--;
  144.                 if (listIndex < minIndex)
  145.                 {
  146.                     listIndex = minIndex;
  147.                 }
  148.                 _tList[listIndex].gameObject.GetComponent<Image>().color = Color.red;
  149.                 delay = false;
  150.             }
  151.             else
  152.             {
  153.                 counter += Time.deltaTime;
  154.             }
  155.  
  156.             if (counter > 0.1f)
  157.             {
  158.                 delay = true;
  159.                 counter = 0f;
  160.             }
  161.         }
  162.  
  163.         if (Input.GetKeyDown(KeyCode.Joystick1Button0))
  164.         {
  165.             if (_tList[listIndex].name == "vInverted")
  166.             {
  167.                 isInvertedV = !isInvertedV;
  168.                 if (isInvertedV)
  169.                     _tList[listIndex].gameObject.GetComponent<Image>().sprite = boxWCross;
  170.                 else
  171.                     _tList[listIndex].gameObject.GetComponent<Image>().sprite = boxWOCross;
  172.             }
  173.  
  174.             else if(_tList[listIndex].name == "hInverted")
  175.             {
  176.                 isInvertedH = !isInvertedH;
  177.                 if (isInvertedH)
  178.                     _tList[listIndex].gameObject.GetComponent<Image>().sprite = boxWCross;
  179.                 else
  180.                     _tList[listIndex].gameObject.GetComponent<Image>().sprite = boxWOCross;
  181.             }
  182.  
  183.  
  184.             if (_tList[listIndex].name == "resume game")
  185.                 resumeGame = true;
  186.             if (_tList[listIndex].name == "restart game")
  187.                 SceneManager.LoadScene("Scene_main");
  188.  
  189.             SetSettings();
  190.         }
  191.     }
  192.  
  193.  
  194.     void SetSettings()
  195.     {
  196.         playerCamera.SetInverted(isInvertedH, isInvertedV);
  197.     }
  198.  
  199.     void LoadSprites()
  200.     {
  201.         boxWCross = Resources.Load<Sprite>("Menu/Box_W_Cross");
  202.         boxWOCross = Resources.Load<Sprite>("Menu/Box_WO_Cross");
  203.     }
  204. }
Advertisement
Add Comment
Please, Sign In to add comment