浏览代码

Inventory System Base (from official thread) (#100)

* Added the basic inventory system

* Removed prefixes, added CreateAssetMenu to ingredient

* Added CreateAssetMenu to Inventory

* Updated to use tabs and prefixes

* Added prefix to inventory item

* Added a means to iterate over items in Inventory

* Moved accessor

* Spaces to tabs (again)

* Added default assignment to prevent warning

* Added a CustomEditor for Inventory

* added Items according to @chema descrription.

* Marked out item type

* follow code convention

* Added character Customization script.
Added folder structure for scripable objects

* removed marked out lines

* Changed Inventory to contain a list of ItemStacks instead of a dictrionary of Items.

* added item background color

* Reimplemented all the methods in Inventory.cs to work better with List.

* simplified member field namings

* made changed according to request by @Ciro_unity - moved scirpable objects to i...
/main
GitHub 4 年前
当前提交
2487e7bb
共有 30 个文件被更改,包括 368 次插入0 次删除
  1. 8
      UOP1_Project/Assets/Inventory.meta
  2. 8
      UOP1_Project/Assets/Scripts/Inventory.meta
  3. 8
      UOP1_Project/Assets/Inventory/ScriptableObjects.meta
  4. 8
      UOP1_Project/Assets/Inventory/ScriptableObjects/ItemTypes.meta
  5. 15
      UOP1_Project/Assets/Inventory/ScriptableObjects/ItemTypes/CharacterCustomization.asset
  6. 8
      UOP1_Project/Assets/Inventory/ScriptableObjects/ItemTypes/CharacterCustomization.asset.meta
  7. 15
      UOP1_Project/Assets/Inventory/ScriptableObjects/ItemTypes/Dish.asset
  8. 8
      UOP1_Project/Assets/Inventory/ScriptableObjects/ItemTypes/Dish.asset.meta
  9. 15
      UOP1_Project/Assets/Inventory/ScriptableObjects/ItemTypes/Ingredient.asset
  10. 8
      UOP1_Project/Assets/Inventory/ScriptableObjects/ItemTypes/Ingredient.asset.meta
  11. 15
      UOP1_Project/Assets/Inventory/ScriptableObjects/ItemTypes/Utensil.asset
  12. 8
      UOP1_Project/Assets/Inventory/ScriptableObjects/ItemTypes/Utensil.asset.meta
  13. 18
      UOP1_Project/Assets/Scripts/Inventory/InventoryController.cs
  14. 11
      UOP1_Project/Assets/Scripts/Inventory/InventoryController.cs.meta
  15. 11
      UOP1_Project/Assets/Scripts/Inventory/ItemInstance.cs
  16. 11
      UOP1_Project/Assets/Scripts/Inventory/ItemInstance.cs.meta
  17. 12
      UOP1_Project/Assets/Scripts/Inventory/ItemStack.cs
  18. 11
      UOP1_Project/Assets/Scripts/Inventory/ItemStack.cs.meta
  19. 8
      UOP1_Project/Assets/Scripts/Inventory/ScriptableObjects.meta
  20. 80
      UOP1_Project/Assets/Scripts/Inventory/ScriptableObjects/Inventory.cs
  21. 11
      UOP1_Project/Assets/Scripts/Inventory/ScriptableObjects/Inventory.cs.meta
  22. 36
      UOP1_Project/Assets/Scripts/Inventory/ScriptableObjects/Item.cs
  23. 11
      UOP1_Project/Assets/Scripts/Inventory/ScriptableObjects/Item.cs.meta
  24. 13
      UOP1_Project/Assets/Scripts/Inventory/ScriptableObjects/ItemType.cs
  25. 11
      UOP1_Project/Assets/Scripts/Inventory/ScriptableObjects/ItemType.cs.meta

8
UOP1_Project/Assets/Inventory.meta


fileFormatVersion: 2
guid: c63a4917c16ecb94082a0b8f3577466b
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

8
UOP1_Project/Assets/Scripts/Inventory.meta


fileFormatVersion: 2
guid: 8b5b1f0aab7d74e4b9c6be7a4cb8d1ef
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

8
UOP1_Project/Assets/Inventory/ScriptableObjects.meta


fileFormatVersion: 2
guid: 8719ac9353c353b4cb2fcbf19a96e336
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

8
UOP1_Project/Assets/Inventory/ScriptableObjects/ItemTypes.meta


fileFormatVersion: 2
guid: 79d3df99dfa8b554fb6f5e5696e1a6c9
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

15
UOP1_Project/Assets/Inventory/ScriptableObjects/ItemTypes/CharacterCustomization.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d4a0228c25582bd46b1423a709ce06cf, type: 3}
m_Name: CharacterCustomization
m_EditorClassIdentifier:
_actionName: Equip

8
UOP1_Project/Assets/Inventory/ScriptableObjects/ItemTypes/CharacterCustomization.asset.meta


fileFormatVersion: 2
guid: ee81531f56f7f944485268fe581c6965
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:

15
UOP1_Project/Assets/Inventory/ScriptableObjects/ItemTypes/Dish.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d4a0228c25582bd46b1423a709ce06cf, type: 3}
m_Name: Dish
m_EditorClassIdentifier:
_actionName: Use

8
UOP1_Project/Assets/Inventory/ScriptableObjects/ItemTypes/Dish.asset.meta


fileFormatVersion: 2
guid: 5aa0722ca1325a242b6923d6cb0d5864
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:

15
UOP1_Project/Assets/Inventory/ScriptableObjects/ItemTypes/Ingredient.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d4a0228c25582bd46b1423a709ce06cf, type: 3}
m_Name: Ingredient
m_EditorClassIdentifier:
_actionName: Use

8
UOP1_Project/Assets/Inventory/ScriptableObjects/ItemTypes/Ingredient.asset.meta


fileFormatVersion: 2
guid: 24ac82c7b4c359e46971d2d454d1f434
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:

15
UOP1_Project/Assets/Inventory/ScriptableObjects/ItemTypes/Utensil.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d4a0228c25582bd46b1423a709ce06cf, type: 3}
m_Name: Utensil
m_EditorClassIdentifier:
_actionName: Use

8
UOP1_Project/Assets/Inventory/ScriptableObjects/ItemTypes/Utensil.asset.meta


fileFormatVersion: 2
guid: 811ad0ded48a33640abb267981cf32b9
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:

18
UOP1_Project/Assets/Scripts/Inventory/InventoryController.cs


using UnityEngine;
// Created with collaboration from:
// https://forum.unity.com/threads/inventory-system.980646/
public class InventoryController : MonoBehaviour
{
[SerializeField]
private Inventory _inventory = default;
private void OnTriggerEnter(Collider other)
{
if (other.TryGetComponent<ItemInstance>(out ItemInstance itemInstance))
{
_inventory.Add(itemInstance.Item);
Destroy(itemInstance);
}
}
}

11
UOP1_Project/Assets/Scripts/Inventory/InventoryController.cs.meta


fileFormatVersion: 2
guid: 9d977368908c08a4798b90a8757a255b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

11
UOP1_Project/Assets/Scripts/Inventory/ItemInstance.cs


using UnityEngine;
// Created with collaboration from:
// https://forum.unity.com/threads/inventory-system.980646/
public class ItemInstance : MonoBehaviour
{
[SerializeField]
private Item _item;
public Item Item => _item;
}

11
UOP1_Project/Assets/Scripts/Inventory/ItemInstance.cs.meta


fileFormatVersion: 2
guid: 6c69c8ccffb196541940408e7b7316bc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

12
UOP1_Project/Assets/Scripts/Inventory/ItemStack.cs


public class ItemStack
{
public Item Item { get; }
public int Amount { get; set; }
public ItemStack(Item item, int amount)
{
Item = item;
Amount = amount;
}
}

11
UOP1_Project/Assets/Scripts/Inventory/ItemStack.cs.meta


fileFormatVersion: 2
guid: 260195354f73b2f4ca9681baf3f089a2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

8
UOP1_Project/Assets/Scripts/Inventory/ScriptableObjects.meta


fileFormatVersion: 2
guid: 3aaece2a364bfda4281658087bcff70d
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

80
UOP1_Project/Assets/Scripts/Inventory/ScriptableObjects/Inventory.cs


using System.Collections.Generic;
using UnityEngine;
// Created with collaboration from:
// https://forum.unity.com/threads/inventory-system.980646/
[CreateAssetMenu(fileName = "Inventory", menuName = "Inventory/Inventory", order = 51)]
public class Inventory : ScriptableObject
{
[Tooltip("The collection of items and their quantities.")]
[SerializeField]
private List<ItemStack> _items = new List<ItemStack>();
public List<ItemStack> Items => _items;
public void Add(Item item, int count = 1)
{
if (count <= 0)
return;
for (int i = 0; i < _items.Count; i++)
{
ItemStack currentItemStack = _items[i];
if (item == currentItemStack.Item)
{
currentItemStack.Amount += count;
return;
}
}
_items.Add(new ItemStack(item, count));
}
public void Remove(Item item, int count = 1)
{
if (count <= 0)
return;
for (int i = 0; i < _items.Count; i++)
{
ItemStack currentItemStack = _items[i];
if (currentItemStack.Item == item)
{
currentItemStack.Amount -= count;
if (currentItemStack.Amount <= 0)
_items.Remove(currentItemStack);
return;
}
}
}
public bool Contains(Item item)
{
for (int i = 0; i < _items.Count; i++)
{
if (item == _items[i].Item)
{
return true;
}
}
return false;
}
public int Count(Item item)
{
for (int i = 0; i < _items.Count; i++)
{
ItemStack currentItemStack = _items[i];
if (item == currentItemStack.Item)
{
return currentItemStack.Amount;
}
}
return 0;
}
}

11
UOP1_Project/Assets/Scripts/Inventory/ScriptableObjects/Inventory.cs.meta


fileFormatVersion: 2
guid: b39a296438081ff4c99abec393d12d54
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

36
UOP1_Project/Assets/Scripts/Inventory/ScriptableObjects/Item.cs


using UnityEngine;
// Created with collaboration from:
// https://forum.unity.com/threads/inventory-system.980646/
[CreateAssetMenu(fileName = "Item", menuName = "Inventory/Item", order = 51)]
public class Item : ScriptableObject
{
[Tooltip("The name of the item")]
[SerializeField]
private string _name;
[Tooltip("A preview image for the item")]
[SerializeField]
private Sprite _previewImage;
[Tooltip("A description of the item")]
[SerializeField]
[Multiline]
private string _description;
[Tooltip("The type of item")]
[SerializeField]
private ItemType _itemType;
[Tooltip("A prefab reference for the model of the item")]
[SerializeField]
private GameObject _prefab;
public string Name => _name;
public Sprite PreviewImage => _previewImage;
public string Description => _description;
public ItemType ItemType => _itemType;
public GameObject Prefab => _prefab;
}

11
UOP1_Project/Assets/Scripts/Inventory/ScriptableObjects/Item.cs.meta


fileFormatVersion: 2
guid: 58a5b32581978a141a66d240261449d0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

13
UOP1_Project/Assets/Scripts/Inventory/ScriptableObjects/ItemType.cs


using UnityEngine;
// Created with collaboration from:
// https://forum.unity.com/threads/inventory-system.980646/
[CreateAssetMenu(fileName = "ItemType", menuName = "Inventory/ItemType", order = 51)]
public class ItemType : ScriptableObject
{
[Tooltip("The action associated with the item type")]
[SerializeField]
private string _actionName;
public string ActionName => _actionName;
}

11
UOP1_Project/Assets/Scripts/Inventory/ScriptableObjects/ItemType.cs.meta


fileFormatVersion: 2
guid: d4a0228c25582bd46b1423a709ce06cf
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存