Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Use this for initialization
- void Start () {
- inventory = GameObject.Find("PlayerInfo").GetComponent<Inventory>();
- GetItemList();
- numRows = (int)Mathf.Round(itemList.Count / numColumns)+1;
- itemLocations = new Rect[itemList.Count];
- //Item locations
- int i = 0;
- for (int y = 0; y < numRows; y++)
- {
- for (int x = 0; x < numColumns; x++)
- {
- if (i == itemLocations.Length)
- return;
- itemLocations[i] = new Rect(windowPos.x + spacing + (x * tileSize) + (spacing * x) + inventoryOffset.x + 10,
- windowPos.y + (y * tileSize) + (spacing * y) + inventoryOffset.y, tileSize, tileSize);
- i++;
- }
- }
- }
- void GetItemList()
- {
- DirectoryInfo info = new DirectoryInfo(path);
- folders = info.GetDirectories();
- FileInfo[] fileInfo;
- foreach (DirectoryInfo folder in folders)
- {
- fileInfo = folder.GetFiles("*.cs");
- foreach (FileInfo file in fileInfo)
- {
- string name = file.Name;
- name = name.Replace(".cs", "");
- System.Type itemType = System.Type.GetType(name);
- Item item = System.Activator.CreateInstance(itemType) as Item;
- itemList.Add(item);
- }
- }
- }
- void OnGUI()
- {
- GUI.skin = skin;
- AllItems();
- }
- private void AllItems()
- {
- if (inventory.showSheet == true)
- {
- //Start scroll bounds
- GUI.skin.scrollView = style;
- scrollPosition = GUI.BeginScrollView(
- new Rect(windowPos.x + inventoryOffset.x,
- windowPos.y + inventoryOffset.y + 10,
- inventoryWidth,
- inventoryHeight - 23),
- scrollPosition,
- new Rect(
- windowPos.x + inventoryOffset.x,
- windowPos.y + inventoryOffset.y,
- (numColumns * tileSize) + (numColumns * spacing),
- (numRows * tileSize) + (numRows * spacing) - 6)
- );
- //Draw box backgrounds
- for (int i = 0; i < itemList.Count; i++)
- {
- GUI.Box(itemLocations[i], "");
- GUIContent content = new GUIContent("");
- if (itemList[i] != null)
- {
- content = new GUIContent(itemList[i].itemIcon, " " + itemList[i].itemName + ": " + itemList[i].itemTooltip);
- }
- if (GUI.Button(itemLocations[i], content, "Slot"))
- {
- inventory.AddItem(itemList[i]);
- }
- }
- //End scroll bounds
- GUI.EndScrollView();
- }
- }
Add Comment
Please, Sign In to add comment