Advertisement
irwnsyh

onGameGUI

Sep 30th, 2019
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.79 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5.  
  6.  
  7. public class onGameGUI : MonoBehaviour {
  8.     public static onGameGUI GUI;
  9.  
  10.     //Keybindings
  11.  
  12.     Event keyEvent;
  13.     Text buttonText;
  14.     KeyCode newKey;
  15.     bool waitingForKey;
  16.     public GameObject textWait;
  17.  
  18.     [Header("Notification")]
  19.     public GameObject panelLevelUp;
  20.     public GameObject notifMainPanel;
  21.     public Text notifText1;
  22.     public Text notifText2;
  23.     public GameObject iconInformation;
  24.     //should be the image or logo for notfication
  25.  
  26.     [Header("Compass")]
  27.     public GameObject compassMainPanel;
  28.     public GameObject compassPointR;
  29.     public GameObject compassPointL;
  30.  
  31.     [Header("Player")]
  32.     public GameObject playerMainPanel;
  33.     //public GameObject playerBloodBar;
  34.     public GameObject playerTaunt1;
  35.     public Image playerParangLogo;
  36.  
  37.     [Header("Mission")]
  38.     public Text TextMission;
  39.     public Text TextDescription;
  40.  
  41.     [Header("Sound Effects")]
  42.     public GameObject inGameClickSFX;
  43.     public GameObject inGameHoverSFX;
  44.     public GameObject inGameAmbient;
  45.  
  46.     [Header("Player")]
  47.     public GameObject player;
  48.     private PlayerCombat combatScript;
  49.  
  50.     [Header("Tutorial Icon")]
  51.     public GameObject iconAttack;
  52.     public GameObject iconCamera;
  53.     public GameObject iconCrouch;
  54.     public GameObject iconDirection;
  55.     public GameObject iconRun;
  56.     public GameObject iconShield;
  57.     public GameObject iconInteract;
  58.     public GameObject iconSheath;
  59.     public GameObject frameTutorial;
  60.     public Text tutorialText;
  61.     public GameObject iconCrystal;
  62.  
  63.     [Header("Level Bar")]
  64.     public Text levelNumber;
  65.     public Image levelBar;
  66.  
  67.  
  68.     public static bool GameIsPaused = false;
  69.  
  70.     [Header("Warning Panel")]
  71.     public GameObject warningpanel;
  72.  
  73.     public Sprite crosscheck;
  74.     public GameObject textWallLevel;
  75.  
  76.     // Use this for initialization
  77.     void Start () {
  78.         combatScript = player.GetComponent<PlayerCombat>();
  79.  
  80.  
  81.         notifMainPanel.gameObject.SetActive (false);
  82.  
  83.         waitingForKey = false;
  84.  
  85.  
  86.     }
  87.  
  88.    
  89.     // Update is called once per frame
  90.     void Update () {
  91.         //AmbientSound ();
  92.         if (combatScript.swordState) {
  93.             if (playerParangLogo != null){
  94.                 if (!playerParangLogo.enabled) {
  95.                     playerParangLogo.gameObject.SetActive (true);
  96.                 }
  97.             }
  98.         } else {
  99.             if (playerParangLogo != null) {
  100.                 if (playerParangLogo.enabled) {
  101.                     playerParangLogo.gameObject.SetActive (false);
  102.                 }
  103.             } else {
  104.                 Debug.Log ("null");
  105.             }
  106.         }
  107.  
  108.         if (waitingForKey)
  109.             textWait.gameObject.SetActive (true);
  110.         else
  111.             textWait.gameObject.SetActive (false);
  112.     }
  113.  
  114.     public void ShowWindow (GameObject panel){
  115.         panel.SetActive (true);
  116.     }
  117.  
  118.     public void CloseWindow (GameObject panel){
  119.         panel.SetActive (false);
  120.     }
  121.  
  122.     public void ShowDiamondNotification (string header, string body){
  123.         notifText1.text = header;
  124.         notifText2.text = body;
  125.         StopCoroutine (showpanel());
  126.         StartCoroutine (showpanel());
  127.     }
  128.  
  129.     IEnumerator showpanel(){
  130.         yield return new WaitForSeconds (1);
  131.         notifMainPanel.SetActive (true);
  132.         notifText1.gameObject.SetActive (true);
  133.         notifText2.gameObject.SetActive (true);
  134.         iconInformation.SetActive (true);
  135.         yield return new WaitForSeconds (5);
  136.         notifMainPanel.SetActive (false);
  137.         notifText1.gameObject.SetActive (false);
  138.         notifText2.gameObject.SetActive (false);
  139.         iconInformation.SetActive (false);
  140.     }
  141.  
  142.     public void ShowRectangleNotification(string teks){
  143.         tutorialText.text = teks;
  144.  
  145.         StopCoroutine (showframe ());
  146.         StartCoroutine (showframe ());
  147.     }
  148.  
  149.     IEnumerator showframe(){
  150.         yield return new WaitForSeconds (1);
  151.         frameTutorial.SetActive (true);
  152.         tutorialText.gameObject.SetActive (true);
  153.         iconCrystal.SetActive (true);
  154.         yield return new WaitForSeconds (5);
  155.         frameTutorial.SetActive (false);
  156.         tutorialText.gameObject.SetActive (false);
  157.         iconCrystal.SetActive (false);
  158.     }
  159.  
  160.     void OnGUI(){
  161.         keyEvent = Event.current;
  162.  
  163.         if (keyEvent.isKey && waitingForKey) {
  164.             newKey = keyEvent.keyCode;
  165.             waitingForKey = false;
  166.         }
  167.     }
  168.  
  169.     public void StartAssignment(string keyName){
  170.         if (!waitingForKey) {
  171.             StartCoroutine(AssignKey(keyName));
  172.         }
  173.     }
  174.  
  175.     public void SendText(Text text){
  176.         buttonText = text;
  177.     }
  178.  
  179.     IEnumerator WaitForKey(){
  180.         while (!keyEvent.isKey)
  181.             yield return null;
  182.     }
  183.  
  184.     public IEnumerator AssignKey(string keyName){
  185.         waitingForKey = true;
  186.         yield return WaitForKey();
  187.  
  188.         switch (keyName) {
  189.         case "forward":
  190.             GameManager_Master.gm.forward = newKey;
  191.             buttonText.text = GameManager_Master.gm.forward.ToString ();
  192.             PlayerPrefs.SetString ("forwardKey", GameManager_Master.gm.forward.ToString ());
  193.             break;
  194.         case "backward":
  195.             GameManager_Master.gm.backward = newKey;
  196.             buttonText.text = GameManager_Master.gm.backward.ToString ();
  197.             PlayerPrefs.SetString ("backwardKey", GameManager_Master.gm.backward.ToString ());
  198.             break;
  199.         case "left":
  200.             GameManager_Master.gm.left = newKey;
  201.             buttonText.text = GameManager_Master.gm.left.ToString ();
  202.             PlayerPrefs.SetString ("leftKey", GameManager_Master.gm.left.ToString ());
  203.             break;
  204.         case "right":
  205.             GameManager_Master.gm.right = newKey;
  206.             buttonText.text = GameManager_Master.gm.right.ToString ();
  207.             PlayerPrefs.SetString ("rightKey", GameManager_Master.gm.right.ToString ());
  208.             break;
  209.         case "jump":
  210.             GameManager_Master.gm.jump = newKey;
  211.             buttonText.text = GameManager_Master.gm.jump.ToString ();
  212.             PlayerPrefs.SetString ("jumpKey",  GameManager_Master.gm.jump.ToString ());
  213.             break;
  214.         case "crouch":
  215.             GameManager_Master.gm.crouch = newKey;
  216.             buttonText.text = GameManager_Master.gm.crouch.ToString ();
  217.             PlayerPrefs.SetString ("crouchKey", GameManager_Master.gm.crouch.ToString ());
  218.             break;
  219.         case "run":
  220.             GameManager_Master.gm.run = newKey;
  221.             buttonText.text = GameManager_Master.gm.run.ToString ();
  222.             PlayerPrefs.SetString ("runKey", GameManager_Master.gm.run.ToString ());
  223.             break;
  224.         case "sword":
  225.             GameManager_Master.gm.sword = newKey;
  226.             buttonText.text = GameManager_Master.gm.sword.ToString ();
  227.             PlayerPrefs.SetString ("swordKey", GameManager_Master.gm.sword.ToString ());
  228.             break;
  229.         case "interact":
  230.             GameManager_Master.gm.interact = newKey;
  231.             buttonText.text = GameManager_Master.gm.interact.ToString ();
  232.             PlayerPrefs.SetString ("interactKey", GameManager_Master.gm.interact.ToString ());
  233.             break;
  234.         case "lightattack":
  235.             GameManager_Master.gm.lightattack = newKey;
  236.             buttonText.text = GameManager_Master.gm.lightattack.ToString ();
  237.             PlayerPrefs.SetString ("lightattackKey", GameManager_Master.gm.lightattack.ToString ());
  238.             break;
  239.         case "shield":
  240.             GameManager_Master.gm.shield = newKey;
  241.             buttonText.text = GameManager_Master.gm.shield.ToString ();
  242.             PlayerPrefs.SetString ("shieldKey", GameManager_Master.gm.shield.ToString ());
  243.             break;
  244.         case "pause":
  245.             GameManager_Master.gm.pause = newKey;
  246.             buttonText.text = GameManager_Master.gm.pause.ToString ();
  247.             PlayerPrefs.SetString ("pauseKey", GameManager_Master.gm.pause.ToString ());
  248.             break;
  249.         case "map":
  250.             GameManager_Master.gm.map = newKey;
  251.             buttonText.text = GameManager_Master.gm.map.ToString ();
  252.             PlayerPrefs.SetString ("mapKey", GameManager_Master.gm.map.ToString ());
  253.             break;
  254.         }
  255.         yield return null;
  256.     }
  257.  
  258.  
  259.  
  260.  
  261.  
  262.     public void DisableConfirmation(){
  263.         warningpanel.gameObject.SetActive (false);
  264.         //panel system dan quest raycast target = true
  265.     }
  266.  
  267.     public void QuitConfirmation(){
  268.         warningpanel.gameObject.SetActive (true);
  269.         //panel system dan quest raycast target = false
  270.  
  271.     }
  272.  
  273.     public void ClickSound(){
  274.         inGameClickSFX.GetComponent<AudioSource> ().Play ();
  275.     }
  276.  
  277.     public void HoverSound(){
  278.         inGameHoverSFX.GetComponent<AudioSource> ().Play ();
  279.     }
  280.  
  281.     public void AmbientSound(){
  282.         inGameAmbient.GetComponent<AudioSource> ().Play ();
  283.         if (inGameAmbient.GetComponent<AudioSource> ().volume < 1f) {
  284.             inGameAmbient.GetComponent<AudioSource> ().volume += 0.1f * Time.deltaTime;
  285.         }
  286.     }
  287.  
  288. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement