Advertisement
Guest User

Inventory.cs

a guest
Mar 14th, 2014
356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.83 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4.  
  5. public class Inventory : MonoBehaviour {
  6.  
  7.     private Vector2 ScrollInventory = Vector2.zero;
  8.  
  9.     //All Items in game
  10.     public List<Item> items = new List<Item>();
  11.  
  12.     //Player's Inventory
  13.     [HideInInspector]
  14.     public static List<Item> mainInventory = new List<Item>();
  15.  
  16.     //Equipped Apparel
  17.     //[0] = Head, [1] = Body, [2] = Legs, [3] = Feet, [4] = Hand, [5] = Neck
  18.     List<Item> equippedApparel = new List<Item>();
  19.     //Equipped Weapons/Tools
  20.     //[0] = Left Hand, [1] = Right Hand
  21.     List<Item> equippedWeapons = new List<Item>();
  22.    
  23.     public GameObject player;
  24.  
  25.     string currentMenu = "";
  26.     bool open = false;
  27.  
  28.     void Start() {
  29.         mainInventory.Add (items [0]);
  30.         mainInventory.Add (items [1]);
  31.         mainInventory.Add (items [2]);
  32.         mainInventory.Add (items [3]);
  33.         mainInventory.Add (items [4]);
  34.         mainInventory.Add (items [5]);
  35.         mainInventory.Add (items [6]);
  36.         mainInventory.Add (items [7]);
  37.         mainInventory.Add (items [8]);
  38.         mainInventory.Add (items [9]);
  39.         mainInventory.Add (items [10]);
  40.         mainInventory.Add (items [11]);
  41.         //mainInventory.Add (items [12]);
  42.     }
  43.  
  44.     void Update() {
  45.         if(Input.GetKeyDown(KeyCode.E)) {
  46.             if(open == false) {
  47.                 open = true;
  48.                 NavigateTo("Sel");
  49.             } else {
  50.                 open = false;
  51.                 currentMenu = "";
  52.             }
  53.         }
  54.        
  55.         if(open == true) {
  56.             player.GetComponent<FirstPersonController>().enabled = false;
  57.             //player.GetComponent<BasicSettings>().enabled = false;
  58.         } else {
  59.             player.GetComponent<FirstPersonController>().enabled = true;
  60.             //player.GetComponent<BasicSettings>().enabled = true;
  61.             currentMenu = "";
  62.         }
  63.     }
  64.  
  65.     void OnGUI() {
  66.         if(currentMenu == "Sel")
  67.             InvenSelect();
  68.         if(currentMenu == "Weap")
  69.             InvenWeap();
  70.         if(currentMenu == "Tool")
  71.             InvenTool();
  72.         if(currentMenu == "App")
  73.             InvenApperal();
  74.         if(currentMenu == "Food")
  75.             InvenFood();
  76.         if(currentMenu == "Misc")
  77.             InvenMisc();
  78.        
  79.         /*GUI.Box(new Rect(0, 0, 200, Screen.height), "");
  80.         ScrollInventory = GUILayout.BeginScrollView(ScrollInventory, GUILayout.MaxWidth(200));
  81.         for(int x = 0;x < items.Count;x++) {
  82.             if(GUILayout.Button("" + items[x].name)) {
  83.                 Debug.Log(items[x].desc);
  84.             }
  85.         }
  86.         GUILayout.EndArea();*/
  87.     }
  88.    
  89.     public void NavigateTo(string nextmenu) {
  90.         currentMenu = nextmenu;
  91.     }
  92.    
  93.     public void InvenSelect() {
  94.         GUI.Box(new Rect(0, 0, 200, Screen.height), "Inventory");
  95.         if(GUI.Button (new Rect(10, 30, 180, 30), "Weapons")) {
  96.             NavigateTo("Weap");
  97.         }
  98.         if(GUI.Button (new Rect(10, 70, 180, 30), "Apperal")) {
  99.             NavigateTo("App");
  100.         }
  101.         if(GUI.Button (new Rect(10, 110, 180, 30), "Tools")) {
  102.             NavigateTo("Tool");
  103.         }
  104.         if(GUI.Button (new Rect(10, 150, 180, 30), "Food")) {
  105.             NavigateTo("Food");
  106.         }
  107.         if(GUI.Button (new Rect(10, 190, 180, 30), "Misc.")) {
  108.             NavigateTo("Misc");
  109.         }
  110.         if(GUI.Button (new Rect(10, Screen.height - 40, 180, 30), "Back")) {
  111.             open = false;
  112.         }
  113.     }
  114.    
  115.     public void InvenWeap() {
  116.         GUI.Box (new Rect(0, 0, 200, Screen.height), "Weapons");
  117.         ScrollInventory = GUILayout.BeginScrollView(ScrollInventory, GUILayout.MaxWidth(200));
  118.         GUILayout.Space(40);
  119.             for(int x = 0;x < mainInventory.Count;x++) {
  120.                 if(mainInventory[x].type == ItemType.weapon) {
  121.                     if(GUILayout.Button("" + mainInventory[x].name)) {
  122.                         Debug.Log(mainInventory[x].desc);
  123.                     }
  124.                 }
  125.             }
  126.         GUILayout.EndArea();
  127.         if(GUI.Button (new Rect(10, Screen.height - 40, 180, 30), "Back")) {
  128.             NavigateTo("Sel");
  129.         }
  130.     }
  131.    
  132.     public void InvenApperal() {
  133.         GUI.Box (new Rect(0, 0, 200, Screen.height), "Apperal");
  134.         ScrollInventory = GUILayout.BeginScrollView(ScrollInventory, GUILayout.MaxWidth(200));
  135.         GUILayout.Space(40);
  136.             for(int x = 0;x < mainInventory.Count;x++) {
  137.                 if(mainInventory[x].type == ItemType.head || mainInventory[x].type == ItemType.body || mainInventory[x].type == ItemType.legs || mainInventory[x].type == ItemType.feet || mainInventory[x].type == ItemType.hand || mainInventory[x].type == ItemType.neck) {
  138.                     if(GUILayout.Button("" + mainInventory[x].name)) {
  139.                         Debug.Log(mainInventory[x].desc);
  140.                     }
  141.                 }
  142.             }
  143.         GUILayout.EndArea();
  144.         if(GUI.Button (new Rect(10, Screen.height - 40, 180, 30), "Back")) {
  145.             NavigateTo("Sel");
  146.         }
  147.     }
  148.    
  149.     public void InvenTool() {
  150.         GUI.Box (new Rect(0, 0, 200, Screen.height), "Tools");
  151.         ScrollInventory = GUILayout.BeginScrollView(ScrollInventory, GUILayout.MaxWidth(200));
  152.         GUILayout.Space(40);
  153.             for(int x = 0;x < mainInventory.Count;x++) {
  154.                 if(mainInventory[x].type == ItemType.tool) {
  155.                     if(GUILayout.Button("" + mainInventory[x].name)) {
  156.                         Debug.Log(mainInventory[x].desc);
  157.                     }
  158.                 }
  159.             }
  160.         GUILayout.EndArea();
  161.         if(GUI.Button (new Rect(10, Screen.height - 40, 180, 30), "Back")) {
  162.             NavigateTo("Sel");
  163.         }
  164.     }
  165.    
  166.     public void InvenFood() {
  167.         GUI.Box (new Rect(0, 0, 200, Screen.height), "Food");
  168.         ScrollInventory = GUILayout.BeginScrollView(ScrollInventory, GUILayout.MaxWidth(200));
  169.         GUILayout.Space(40);
  170.             for(int x = 0;x < mainInventory.Count;x++) {
  171.                 if(mainInventory[x].type == ItemType.food) {
  172.                     if(GUILayout.Button("" + mainInventory[x].name)) {
  173.                         Debug.Log(mainInventory[x].desc);
  174.                     }
  175.                 }
  176.             }
  177.         GUILayout.EndArea();
  178.         if(GUI.Button (new Rect(10, Screen.height - 40, 180, 30), "Back")) {
  179.             NavigateTo("Sel");
  180.         }
  181.     }
  182.    
  183.     public void InvenMisc() {
  184.         GUI.Box (new Rect(0, 0, 200, Screen.height), "Misc");
  185.         ScrollInventory = GUILayout.BeginScrollView(ScrollInventory, GUILayout.MaxWidth(200));
  186.         GUILayout.Space(40);
  187.             for(int x = 0;x < mainInventory.Count;x++) {
  188.                 if(mainInventory[x].type == ItemType.misc) {
  189.                     if(GUILayout.Button("" + mainInventory[x].name)) {
  190.                         Debug.Log(mainInventory[x].desc);
  191.                     }
  192.                 }
  193.             }
  194.         GUILayout.EndArea();
  195.         if(GUI.Button (new Rect(10, Screen.height - 40, 180, 30), "Back")) {
  196.             NavigateTo("Sel");
  197.         }
  198.     }
  199. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement