Skip to content

Added Inventory System #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions Vive VR/Assets/DisplayInventory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;

public class DisplayInventory : MonoBehaviour
{
public InventoryObject inventory;

public int X_START;
public int Y_START;
public int X_SPACE_BETWEEN_ITEM;
public int NUMBER_OF_COLUMN;
public int Y_SPACE_BETWEEN_ITEMS;

Dictionary<InventorySlot, GameObject> itemDisplayed = new Dictionary<InventorySlot, GameObject>();

private void Start()
{
CreateDisplay();
}

private void Update()
{
UpdateDisplay();
}

public void UpdateDisplay()
{
for (int i = 0; i < inventory.Container.Count; i++)
{
if (itemDisplayed.ContainsKey(inventory.Container[i]))
{
itemDisplayed[inventory.Container[i]].GetComponentInChildren<TextMeshProUGUI>().text = inventory.Container[i].amount.ToString("n0");
}
else
{
var obj = Instantiate(inventory.Container[i].item.prefab, Vector3.zero, Quaternion.identity, transform);
obj.GetComponent<RectTransform>().localPosition = GetPosition(i);
obj.GetComponentInChildren<TextMeshProUGUI>().text = inventory.Container[i].amount.ToString("n0");
itemDisplayed.Add(inventory.Container[i], obj);
}
}
}

public void CreateDisplay()
{
for (int i = 0; i < inventory.Container.Count; i++)
{
var obj = Instantiate(inventory.Container[i].item.prefab, Vector3.zero, Quaternion.identity, transform);
obj.GetComponent<RectTransform>().localPosition = GetPosition(i);
obj.GetComponentInChildren<TextMeshProUGUI>().text = inventory.Container[i].amount.ToString("n0");
itemDisplayed.Add(inventory.Container[i], obj);

}
}

public Vector3 GetPosition(int i)
{
return new Vector3(X_START + (X_SPACE_BETWEEN_ITEM * (i % NUMBER_OF_COLUMN)), Y_START + (-Y_SPACE_BETWEEN_ITEMS * (i / NUMBER_OF_COLUMN)), 0f);
}
}

8 changes: 8 additions & 0 deletions Vive VR/Assets/Item.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Item : MonoBehaviour
{
public ItemObject item;
}
55 changes: 55 additions & 0 deletions Vive VR/Assets/ItemClickBehavior.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ItemClickBehavior : MonoBehaviour
{
public InventoryObject inventory;

// Update is called once per frame
void Update()
{
if (Input.GetMouseButtonDown(0) && Input.GetMouseButtonDown(0))
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

if (Physics.Raycast(ray, out hit))
{
Collider other = hit.collider as Collider;
if ( other.GetComponent("Item") != null )
{
AddItemOnClick(other);
Destroy(other.gameObject);
Debug.Log("Item successfully added");
}
}
}

}

public void AddItemOnClick(Collider bc)
{
var item = bc.GetComponent<Item>();
if (item)
{
inventory.AddItem(item.item, 1);
}
}

public void OnItemClicked()
{
ItemDragHandler draghandler =

gameObject.transform.Find("Border").GetComponent<ItemDragHandler>();

Debug.Log("Slot plays animation");

}

// This resets the item count to zero upon closing the game.
private void OnApplicationQuit()
{
inventory.Container.Clear();
}
}
18 changes: 18 additions & 0 deletions Vive VR/Assets/ItemDragHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ItemDragHandler : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{

}

// Update is called once per frame
void Update()
{

}
}
21 changes: 21 additions & 0 deletions Vive VR/Assets/Player.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Player : MonoBehaviour


{
public InventoryObject inventory;

public void OnTriggerEnter(Collider other)
{
var item = other.GetComponent<Item>();
if (item)
{
inventory.AddItem(item.item, 1);
Destroy(other.gameObject);
Debug.Log("Item Successfully Added");
}
}
}
136 changes: 136 additions & 0 deletions Vive VR/Assets/Prefabs/Image Variant 1.prefab
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1001 &5979329689359008624
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 5506508268488860543, guid: 6ac353dd06a8d9c4fa5bcde302826962,
type: 3}
propertyPath: m_Name
value: Image Variant 1
objectReference: {fileID: 0}
- target: {fileID: 5506508268481749371, guid: 6ac353dd06a8d9c4fa5bcde302826962,
type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5506508268481749371, guid: 6ac353dd06a8d9c4fa5bcde302826962,
type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5506508268481749371, guid: 6ac353dd06a8d9c4fa5bcde302826962,
type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5506508268481749371, guid: 6ac353dd06a8d9c4fa5bcde302826962,
type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5506508268481749371, guid: 6ac353dd06a8d9c4fa5bcde302826962,
type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5506508268481749371, guid: 6ac353dd06a8d9c4fa5bcde302826962,
type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5506508268481749371, guid: 6ac353dd06a8d9c4fa5bcde302826962,
type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5506508268481749371, guid: 6ac353dd06a8d9c4fa5bcde302826962,
type: 3}
propertyPath: m_RootOrder
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5506508268481749371, guid: 6ac353dd06a8d9c4fa5bcde302826962,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5506508268481749371, guid: 6ac353dd06a8d9c4fa5bcde302826962,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5506508268481749371, guid: 6ac353dd06a8d9c4fa5bcde302826962,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5506508268481749371, guid: 6ac353dd06a8d9c4fa5bcde302826962,
type: 3}
propertyPath: m_AnchoredPosition.x
value: -39.3
objectReference: {fileID: 0}
- target: {fileID: 5506508268481749371, guid: 6ac353dd06a8d9c4fa5bcde302826962,
type: 3}
propertyPath: m_AnchoredPosition.y
value: 71.2
objectReference: {fileID: 0}
- target: {fileID: 5506508268481749371, guid: 6ac353dd06a8d9c4fa5bcde302826962,
type: 3}
propertyPath: m_SizeDelta.x
value: 20.35
objectReference: {fileID: 0}
- target: {fileID: 5506508268481749371, guid: 6ac353dd06a8d9c4fa5bcde302826962,
type: 3}
propertyPath: m_SizeDelta.y
value: 20.35
objectReference: {fileID: 0}
- target: {fileID: 5506508268481749371, guid: 6ac353dd06a8d9c4fa5bcde302826962,
type: 3}
propertyPath: m_AnchorMin.x
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 5506508268481749371, guid: 6ac353dd06a8d9c4fa5bcde302826962,
type: 3}
propertyPath: m_AnchorMin.y
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 5506508268481749371, guid: 6ac353dd06a8d9c4fa5bcde302826962,
type: 3}
propertyPath: m_AnchorMax.x
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 5506508268481749371, guid: 6ac353dd06a8d9c4fa5bcde302826962,
type: 3}
propertyPath: m_AnchorMax.y
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 5506508268481749371, guid: 6ac353dd06a8d9c4fa5bcde302826962,
type: 3}
propertyPath: m_Pivot.x
value: 0.49999994
objectReference: {fileID: 0}
- target: {fileID: 5506508268481749371, guid: 6ac353dd06a8d9c4fa5bcde302826962,
type: 3}
propertyPath: m_Pivot.y
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 5506508268488860540, guid: 6ac353dd06a8d9c4fa5bcde302826962,
type: 3}
propertyPath: m_Color.r
value: 0.30980393
objectReference: {fileID: 0}
- target: {fileID: 5506508268488860540, guid: 6ac353dd06a8d9c4fa5bcde302826962,
type: 3}
propertyPath: m_Color.b
value: 0.57084167
objectReference: {fileID: 0}
- target: {fileID: 5506508268488860540, guid: 6ac353dd06a8d9c4fa5bcde302826962,
type: 3}
propertyPath: m_Color.g
value: 0.6431373
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 6ac353dd06a8d9c4fa5bcde302826962, type: 3}
7 changes: 7 additions & 0 deletions Vive VR/Assets/Prefabs/Image Variant 1.prefab.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading