Guest User

Untitled

a guest
Dec 10th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.26 KB | None | 0 0
  1. // Use this for initialization
  2.     void Start () {
  3.         inventory = GameObject.Find("PlayerInfo").GetComponent<Inventory>();
  4.         GetItemList();
  5.  
  6.         numRows = (int)Mathf.Round(itemList.Count / numColumns)+1;
  7.         itemLocations = new Rect[itemList.Count];
  8.  
  9.         //Item locations
  10.         int i = 0;
  11.         for (int y = 0; y < numRows; y++)
  12.         {
  13.             for (int x = 0; x < numColumns; x++)
  14.             {
  15.                 if (i == itemLocations.Length)
  16.                     return;
  17.  
  18.                 itemLocations[i] = new Rect(windowPos.x + spacing + (x * tileSize) + (spacing * x) + inventoryOffset.x + 10,
  19.                     windowPos.y + (y * tileSize) + (spacing * y) + inventoryOffset.y, tileSize, tileSize);
  20.                 i++;
  21.             }
  22.         }
  23.     }
  24.  
  25.     void GetItemList()
  26.     {
  27.         DirectoryInfo info = new DirectoryInfo(path);
  28.         folders = info.GetDirectories();
  29.  
  30.         FileInfo[] fileInfo;
  31.  
  32.         foreach (DirectoryInfo folder in folders)
  33.         {
  34.             fileInfo = folder.GetFiles("*.cs");
  35.  
  36.             foreach (FileInfo file in fileInfo)
  37.             {
  38.                 string name = file.Name;
  39.                 name = name.Replace(".cs", "");
  40.  
  41.                 System.Type itemType = System.Type.GetType(name);
  42.                 Item item = System.Activator.CreateInstance(itemType) as Item;
  43.                 itemList.Add(item);
  44.             }
  45.         }
  46.     }
  47.  
  48.     void OnGUI()
  49.     {
  50.         GUI.skin = skin;
  51.  
  52.         AllItems();
  53.     }
  54.  
  55.     private void AllItems()
  56.     {
  57.         if (inventory.showSheet == true)
  58.         {
  59.             //Start scroll bounds
  60.             GUI.skin.scrollView = style;
  61.             scrollPosition = GUI.BeginScrollView(
  62.                 new Rect(windowPos.x + inventoryOffset.x,
  63.                     windowPos.y + inventoryOffset.y + 10,
  64.                     inventoryWidth,
  65.                     inventoryHeight - 23),
  66.                 scrollPosition,
  67.                 new Rect(
  68.                     windowPos.x + inventoryOffset.x,
  69.                     windowPos.y + inventoryOffset.y,
  70.                     (numColumns * tileSize) + (numColumns * spacing),
  71.                     (numRows * tileSize) + (numRows * spacing) - 6)
  72.                 );
  73.  
  74.             //Draw box backgrounds
  75.             for (int i = 0; i < itemList.Count; i++)
  76.             {
  77.                 GUI.Box(itemLocations[i], "");
  78.  
  79.                 GUIContent content = new GUIContent("");
  80.                 if (itemList[i] != null)
  81.                 {
  82.                     content = new GUIContent(itemList[i].itemIcon, "  " + itemList[i].itemName + ": " + itemList[i].itemTooltip);
  83.                 }
  84.                 if (GUI.Button(itemLocations[i], content, "Slot"))
  85.                 {
  86.                     inventory.AddItem(itemList[i]);
  87.                 }
  88.             }
  89.  
  90.             //End scroll bounds
  91.             GUI.EndScrollView();
  92.         }
  93.     }
Add Comment
Please, Sign In to add comment