feature: ui able to manage items between toolbar and equipment slots

This commit is contained in:
unfaiyted 2024-06-21 15:47:55 -05:00
parent eba44a7286
commit 60a47d93a4
93 changed files with 283675 additions and 264482 deletions

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 71c5e5231d33835438032cc8f41bc885
guid: 2986f9119f4d7ab41b64ba9a5a9b9d93
DefaultImporter:
externalObjects: {}
userData:

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 53d6c2bae7c54ea4bb76be08ec62cb81
guid: b370d582bb5522341abd050fff5adf3c
DefaultImporter:
externalObjects: {}
userData:

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 2986f9119f4d7ab41b64ba9a5a9b9d93
guid: 53d6c2bae7c54ea4bb76be08ec62cb81
DefaultImporter:
externalObjects: {}
userData:

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: b370d582bb5522341abd050fff5adf3c
guid: 71c5e5231d33835438032cc8f41bc885
DefaultImporter:
externalObjects: {}
userData:

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -5,12 +5,35 @@ using UnityEngine;
[CreateAssetMenu(fileName = "GameItem", menuName = "Game Data/Game Item")]
public class GameItem : ScriptableObject
{
public string itemName;
// item types
public enum ItemType
{
Quest,
Key,
Weapon,
Helmet,
Armor,
Boots,
Gloves,
Accessory,
Ring,
Consumable,
Stone,
Gatherable,
Crops,
Tool
}
public string name;
public Sprite icon;
public int itemValue;
public string rarity; // todo: maybe like enum type?
public string qty; //todo: should this be moved to the inventoryitem object?
public string quantity;
public int maxStack;
public int sellValue;
public ItemType type;
public bool isStackable;
public bool isEquippable;
@ -23,4 +46,18 @@ public class GameItem : ScriptableObject
public bool isDroppable;
public bool isDestroyable;
public bool isUsable;
// stat properties
public int attack;
public int defense;
public int speed;
public int luck;
public int magic;
public int sanity;
public int health; // ex. if consumable heals for 10 health or if equipment adds 10 health
public int experience;
// set how long the item will last
public int durability;
public int maxDurability;
}

View File

@ -4,7 +4,7 @@ MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
executionOrder: 220
icon: {instanceID: 0}
userData:
assetBundleName:

View File

@ -1,108 +0,0 @@
using UnityEngine;
// Example: InventoryItem.cs
[CreateAssetMenu(fileName = "InventorySlot", menuName = "Game Data/Game Slot")]
public class InventorySlot : ScriptableObject
{
public GameItem item;
public int quantity;
public int slotId = -1;
//todo: prevent item from being used if locked
public int isLocked;
public InventorySlot()
{
item = null;
quantity = 0;
}
public InventorySlot(GameItem item)
{
this.item = item;
quantity = 1;
}
public void Initialize(GameItem gameItem, int qty)
{
item = gameItem;
quantity = qty;
}
public void AssignGameItem(GameItem gameItem, int qty = 1)
{
item = gameItem;
quantity = qty;
}
public void AddQuantity(int amount)
{
quantity += amount;
}
public void RemoveQuantity(int amount)
{
quantity -= amount;
}
public void SetQuantity(int amount)
{
quantity = amount;
}
public void UseItem()
{
if (item.isConsumable) RemoveQuantity(1);
}
public void DropItem()
{
if (item.isDroppable) RemoveQuantity(1);
}
public void DestroyItem()
{
if (item.isDestroyable) RemoveQuantity(1);
}
public void SellItem()
{
if (item.isSellable) RemoveQuantity(1);
}
public bool IsEmpty()
{
return item == null;
}
public void AddItem(GameItem newItem)
{
item = newItem;
quantity = 1;
}
public Sprite GetIcon()
{
return item.icon;
}
public string GetItemName()
{
if (item == null)
{
Debug.Log("Item is null");
return null;
}
return item.itemName;
}
public float GetItemValue()
{
return item.itemValue;
}
}

View File

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 3856fd175b2b4b16a045dc6feea96a56
timeCreated: 1718720717

View File

@ -16,7 +16,8 @@ MonoBehaviour:
level: 1
health: 250
maxHealth: 300
inventorySize: 30
inventorySize: 15
toolbarSize: 10
experience: 10
gold: 111
attack: 1

View File

@ -9,6 +9,7 @@ public class PlayerData : ScriptableObject
public int health;
public int maxHealth;
public int inventorySize;
public int toolbarSize;
public int experience;
public int gold;
public int attack;

View File

@ -0,0 +1,155 @@
using System.Collections.Generic;
using UnityEngine;
// BaseSlot.cs
public class Slot : ScriptableObject
{
public enum SlotType
{
Inventory,
Toolbar,
Equipment,
Crafting,
Chest,
Shop,
Quest
}
public GameItem item;
public int quantity;
public int slotId = -1;
public bool isLocked;
public SlotType slotType;
public List<GameItem.ItemType> allowedItemTypes = new();
public Slot()
{
item = null;
quantity = 0;
isLocked = false;
}
public virtual void Initialize(GameItem gameItem, int qty)
{
item = gameItem;
quantity = qty;
}
public virtual void AssignGameItem(GameItem gameItem, int qty = 1)
{
item = gameItem;
quantity = qty;
}
public virtual void AddQuantity(int amount)
{
quantity += amount;
}
public virtual void RemoveQuantity(int amount)
{
quantity -= amount;
}
public virtual void SetQuantity(int amount)
{
quantity = amount;
}
public virtual bool IsEmpty()
{
return item == null;
}
public virtual Sprite GetIcon()
{
return item != null ? item.icon : null;
}
public virtual string GetItemName()
{
return item != null ? item.name : string.Empty;
}
public virtual float GetItemValue()
{
return item != null ? item.itemValue : 0f;
}
public bool IsSlotType<T>() where T : Slot
{
return this is T;
}
public void SetSlotType(SlotType type)
{
slotType = type;
}
public void SetSlotId(int id)
{
slotId = id;
}
public void SetLocked(bool locked)
{
isLocked = locked;
}
public void SetAllowedItemTypes(List<GameItem.ItemType> types)
{
allowedItemTypes = types;
}
public void AddAllowedItemType(GameItem.ItemType type)
{
allowedItemTypes.Add(type);
}
public void RemoveAllowedItemType(GameItem.ItemType type)
{
allowedItemTypes.Remove(type);
}
public bool IsAllowedItemType(GameItem.ItemType type)
{
return allowedItemTypes.Contains(type);
}
public void ClearAllowedItemTypes()
{
allowedItemTypes.Clear();
}
public List<GameItem.ItemType> GetAllowedItemTypes()
{
return allowedItemTypes;
}
public void ClearSlot()
{
item = null;
quantity = 0;
}
public bool IsAllowedItemTypes(GameItem.ItemType type)
{
var isAllowed = false;
Debug.Log("Checking allowed item types");
Debug.Log("Allowed item types: " + allowedItemTypes + " / " + type);
// pretty print list
foreach (var allowedItemType in allowedItemTypes)
{
Debug.Log("-- allowed" + allowedItemType);
if (allowedItemType == type)
{
Debug.Log("Item type is allowed in slot: " + type);
isAllowed = true;
break;
}
}
return isAllowed;
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 28a7a7137dd34ead88ce81d836f98c71
timeCreated: 1718832080

View File

@ -1,334 +0,0 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &3106263121269597043
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 3072652478592301654}
- component: {fileID: 2743964274091858802}
- component: {fileID: 1278534207583697277}
- component: {fileID: 9081298949960238590}
m_Layer: 5
m_Name: WhiteBg
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 2147483647
m_IsActive: 1
--- !u!224 &3072652478592301654
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3106263121269597043}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0.68, y: 0.71, z: 0.7111111}
m_ConstrainProportionsScale: 1
m_Children: []
m_Father: {fileID: 8824897443150766767}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: -0.59, y: -1.29}
m_SizeDelta: {x: 96, y: 96}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &2743964274091858802
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3106263121269597043}
m_CullTransparentMesh: 1
--- !u!114 &1278534207583697277
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3106263121269597043}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 1344c3c82d62a2a41a3576d8abb8e3ea, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: -876546973899608171, guid: 1789571b2fc5463458d4c6f6e15dcecb, type: 3}
m_Color: {r: 1, g: 1, b: 1, a: 0.29803923}
m_RaycastTarget: 0
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Texture: {fileID: 0}
m_UVRect:
serializedVersion: 2
x: 0
y: 0
width: 1
height: 1
--- !u!114 &9081298949960238590
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3106263121269597043}
m_Enabled: 0
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: cfabb0440166ab443bba8876756fdfa9, type: 3}
m_Name:
m_EditorClassIdentifier:
m_EffectColor: {r: 0, g: 0, b: 0, a: 0.8509804}
m_EffectDistance: {x: 1.75, y: 1.34}
m_UseGraphicAlpha: 1
--- !u!1 &3852562587987288138
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 8824897443150766767}
- component: {fileID: 6039662665188030577}
m_Layer: 5
m_Name: InventorySlot
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &8824897443150766767
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3852562587987288138}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: -0.000289917}
m_LocalScale: {x: 0.39479998, y: 0.39479998, z: 0.78959996}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 8958339508947205786}
- {fileID: 3072652478592301654}
- {fileID: 57135208304547328}
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &6039662665188030577
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3852562587987288138}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f60bac826c729984b9c384e8522693cd, type: 3}
m_Name:
m_EditorClassIdentifier:
icon: {fileID: 0}
itemName: {fileID: 0}
gameItem: {fileID: 0}
--- !u!1 &8166046317245665027
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 8958339508947205786}
- component: {fileID: 2154394341646261781}
- component: {fileID: 5800701584388656703}
- component: {fileID: 4273477519376654115}
m_Layer: 5
m_Name: TransBg
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &8958339508947205786
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8166046317245665027}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 8824897443150766767}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 100, y: 100}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &2154394341646261781
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8166046317245665027}
m_CullTransparentMesh: 1
--- !u!114 &5800701584388656703
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8166046317245665027}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 1344c3c82d62a2a41a3576d8abb8e3ea, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: -876546973899608171, guid: 1789571b2fc5463458d4c6f6e15dcecb, type: 3}
m_Color: {r: 0.8113208, g: 0.8113208, b: 0.8113208, a: 0.07058824}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Texture: {fileID: 0}
m_UVRect:
serializedVersion: 2
x: 0
y: 0
width: 1
height: 1
--- !u!114 &4273477519376654115
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8166046317245665027}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: cfabb0440166ab443bba8876756fdfa9, type: 3}
m_Name:
m_EditorClassIdentifier:
m_EffectColor: {r: 0, g: 0, b: 0, a: 1}
m_EffectDistance: {x: 1.13, y: -0.86}
m_UseGraphicAlpha: 1
--- !u!1001 &78227047173558916
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
serializedVersion: 3
m_TransformParent: {fileID: 8824897443150766767}
m_Modifications:
- target: {fileID: 134852072887714948, guid: 8097ab5fed74753418c9dd3d602c7b93, type: 3}
propertyPath: m_Pivot.x
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 134852072887714948, guid: 8097ab5fed74753418c9dd3d602c7b93, type: 3}
propertyPath: m_Pivot.y
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 134852072887714948, guid: 8097ab5fed74753418c9dd3d602c7b93, type: 3}
propertyPath: m_AnchorMax.x
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 134852072887714948, guid: 8097ab5fed74753418c9dd3d602c7b93, type: 3}
propertyPath: m_AnchorMax.y
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 134852072887714948, guid: 8097ab5fed74753418c9dd3d602c7b93, type: 3}
propertyPath: m_AnchorMin.x
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 134852072887714948, guid: 8097ab5fed74753418c9dd3d602c7b93, type: 3}
propertyPath: m_AnchorMin.y
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 134852072887714948, guid: 8097ab5fed74753418c9dd3d602c7b93, type: 3}
propertyPath: m_SizeDelta.x
value: 100
objectReference: {fileID: 0}
- target: {fileID: 134852072887714948, guid: 8097ab5fed74753418c9dd3d602c7b93, type: 3}
propertyPath: m_SizeDelta.y
value: 100
objectReference: {fileID: 0}
- target: {fileID: 134852072887714948, guid: 8097ab5fed74753418c9dd3d602c7b93, type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 134852072887714948, guid: 8097ab5fed74753418c9dd3d602c7b93, type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 134852072887714948, guid: 8097ab5fed74753418c9dd3d602c7b93, type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 134852072887714948, guid: 8097ab5fed74753418c9dd3d602c7b93, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 134852072887714948, guid: 8097ab5fed74753418c9dd3d602c7b93, type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 134852072887714948, guid: 8097ab5fed74753418c9dd3d602c7b93, type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 134852072887714948, guid: 8097ab5fed74753418c9dd3d602c7b93, type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 134852072887714948, guid: 8097ab5fed74753418c9dd3d602c7b93, type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 134852072887714948, guid: 8097ab5fed74753418c9dd3d602c7b93, type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 134852072887714948, guid: 8097ab5fed74753418c9dd3d602c7b93, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 134852072887714948, guid: 8097ab5fed74753418c9dd3d602c7b93, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 134852072887714948, guid: 8097ab5fed74753418c9dd3d602c7b93, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6548796882194455502, guid: 8097ab5fed74753418c9dd3d602c7b93, type: 3}
propertyPath: m_Name
value: Item
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 8097ab5fed74753418c9dd3d602c7b93, type: 3}
--- !u!224 &57135208304547328 stripped
RectTransform:
m_CorrespondingSourceObject: {fileID: 134852072887714948, guid: 8097ab5fed74753418c9dd3d602c7b93, type: 3}
m_PrefabInstance: {fileID: 78227047173558916}
m_PrefabAsset: {fileID: 0}

View File

@ -86,7 +86,7 @@ GameObject:
- component: {fileID: 134852072887714948}
- component: {fileID: 2817832434996736045}
m_Layer: 5
m_Name: InventoryItem
m_Name: ItemPrefab
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
@ -124,10 +124,9 @@ MonoBehaviour:
m_GameObject: {fileID: 6548796882194455502}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 893e9fbe2ce947cba19dbac86dd2c901, type: 3}
m_Script: {fileID: 11500000, guid: 6b363dff4da946008c3bf994802907c3, type: 3}
m_Name:
m_EditorClassIdentifier:
canvas: {fileID: 0}
--- !u!1 &7835567476815678593
GameObject:
m_ObjectHideFlags: 0

View File

@ -11,7 +11,7 @@ GameObject:
- component: {fileID: 2395631025470230569}
- component: {fileID: 1467857066312432754}
m_Layer: 5
m_Name: EmptyInventorySlot
m_Name: SlotPrefab
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
@ -47,10 +47,9 @@ MonoBehaviour:
m_GameObject: {fileID: 1662876271322988295}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f60bac826c729984b9c384e8522693cd, type: 3}
m_Script: {fileID: 11500000, guid: 0ad9b6cc13ef42e18dc900bb5e92f78e, type: 3}
m_Name:
m_EditorClassIdentifier:
gameItem: {fileID: 0}
--- !u!1 &5710397912220141739
GameObject:
m_ObjectHideFlags: 0

View File

@ -12,20 +12,32 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 644ae2138142da14c860cb25fd5c0554, type: 3}
m_Name: Axe
m_EditorClassIdentifier:
itemName: Axe
name: Axe
icon: {fileID: 1866816216, guid: 8cb35144684c70446b308bddac40a586, type: 3}
itemValue: 0
rarity:
qty:
quantity:
maxStack: 1
sellValue: 0
type: 2
isStackable: 0
isEquippable: 0
isConsumable: 0
isQuestItem: 1
isQuestItem: 0
isKeyItem: 0
isCraftable: 0
isCraftable: 1
isTradeable: 0
isSellable: 0
isDroppable: 0
isSellable: 1
isDroppable: 1
isDestroyable: 0
isUsable: 0
attack: 5
defense: 1
speed: 0
luck: 1
magic: 1
sanity: 1
health: 0
experience: 1
durability: 1
maxDurability: 0

View File

@ -0,0 +1,43 @@
%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: 644ae2138142da14c860cb25fd5c0554, type: 3}
m_Name: Basic Armour
m_EditorClassIdentifier:
name: Basic Armour
icon: {fileID: 345959697, guid: 8cb35144684c70446b308bddac40a586, type: 3}
itemValue: 10
rarity:
quantity:
maxStack: 1
sellValue: 0
type: 4
isStackable: 0
isEquippable: 1
isConsumable: 0
isQuestItem: 0
isKeyItem: 0
isCraftable: 1
isTradeable: 0
isSellable: 0
isDroppable: 1
isDestroyable: 1
isUsable: 0
attack: 0
defense: 0
speed: 0
luck: 0
magic: 0
sanity: 0
health: 0
experience: 0
durability: 0
maxDurability: 0

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 398cacc5e86826d4db2533ef15245fff
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,43 @@
%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: 644ae2138142da14c860cb25fd5c0554, type: 3}
m_Name: Boots
m_EditorClassIdentifier:
name: Boots
icon: {fileID: -134027260, guid: 8cb35144684c70446b308bddac40a586, type: 3}
itemValue: 0
rarity:
quantity:
maxStack: 1
sellValue: 0
type: 5
isStackable: 0
isEquippable: 1
isConsumable: 0
isQuestItem: 1
isKeyItem: 0
isCraftable: 1
isTradeable: 1
isSellable: 0
isDroppable: 1
isDestroyable: 1
isUsable: 0
attack: 0
defense: 0
speed: 0
luck: 0
magic: 0
sanity: 0
health: 0
experience: 0
durability: 0
maxDurability: 0

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e18a208e58524924ea9efd894eac8157
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -12,12 +12,14 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 644ae2138142da14c860cb25fd5c0554, type: 3}
m_Name: Bow
m_EditorClassIdentifier:
itemName: Arrow
name: Bow
icon: {fileID: 1551391340, guid: 8cb35144684c70446b308bddac40a586, type: 3}
itemValue: 0
rarity:
qty:
quantity:
maxStack: 1
sellValue: 0
type: 2
isStackable: 0
isEquippable: 0
isConsumable: 0
@ -29,3 +31,13 @@ MonoBehaviour:
isDroppable: 0
isDestroyable: 0
isUsable: 0
attack: 0
defense: 0
speed: 0
luck: 0
magic: 0
sanity: 0
health: 0
experience: 0
durability: 0
maxDurability: 0

View File

@ -12,6 +12,32 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 644ae2138142da14c860cb25fd5c0554, type: 3}
m_Name: Corn
m_EditorClassIdentifier:
itemName: Corn
name: Corn
icon: {fileID: 591171343, guid: 8cb35144684c70446b308bddac40a586, type: 3}
itemValue: 0
rarity:
quantity:
maxStack: 1
sellValue: 0
type: 12
isStackable: 0
isEquippable: 0
isConsumable: 0
isQuestItem: 0
isKeyItem: 0
isCraftable: 0
isTradeable: 0
isSellable: 0
isDroppable: 0
isDestroyable: 0
isUsable: 0
attack: 0
defense: 0
speed: 0
luck: 0
magic: 0
sanity: 0
health: 0
experience: 0
durability: 0
maxDurability: 0

View File

@ -12,6 +12,32 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 644ae2138142da14c860cb25fd5c0554, type: 3}
m_Name: Magic Dust
m_EditorClassIdentifier:
itemName: Magic Dust
name: Magic Dust
icon: {fileID: -194468443, guid: 8cb35144684c70446b308bddac40a586, type: 3}
itemValue: 0
rarity:
quantity:
maxStack: 1
sellValue: 0
type: 9
isStackable: 0
isEquippable: 0
isConsumable: 0
isQuestItem: 0
isKeyItem: 0
isCraftable: 0
isTradeable: 0
isSellable: 0
isDroppable: 0
isDestroyable: 0
isUsable: 0
attack: 0
defense: 0
speed: 0
luck: 0
magic: 0
sanity: 0
health: 0
experience: 0
durability: 0
maxDurability: 0

View File

@ -0,0 +1,43 @@
%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: 644ae2138142da14c860cb25fd5c0554, type: 3}
m_Name: Necklace
m_EditorClassIdentifier:
name: Necklace
icon: {fileID: 305518499, guid: 8cb35144684c70446b308bddac40a586, type: 3}
itemValue: 10
rarity:
quantity:
maxStack: 1
sellValue: 0
type: 7
isStackable: 0
isEquippable: 1
isConsumable: 0
isQuestItem: 0
isKeyItem: 0
isCraftable: 1
isTradeable: 0
isSellable: 0
isDroppable: 1
isDestroyable: 1
isUsable: 0
attack: 0
defense: 0
speed: 0
luck: 0
magic: 0
sanity: 0
health: 0
experience: 0
durability: 0
maxDurability: 0

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 44ed1a00e6030f3499dd6d3103636dbd
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -12,6 +12,32 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 644ae2138142da14c860cb25fd5c0554, type: 3}
m_Name: Potion
m_EditorClassIdentifier:
itemName: Potion
name: Potion
icon: {fileID: 1117107715, guid: 8cb35144684c70446b308bddac40a586, type: 3}
itemValue: 0
rarity:
quantity:
maxStack: 1
sellValue: 0
type: 9
isStackable: 0
isEquippable: 0
isConsumable: 0
isQuestItem: 0
isKeyItem: 0
isCraftable: 0
isTradeable: 0
isSellable: 0
isDroppable: 0
isDestroyable: 0
isUsable: 0
attack: 0
defense: 0
speed: 0
luck: 0
magic: 0
sanity: 0
health: 0
experience: 0
durability: 0
maxDurability: 0

View File

@ -0,0 +1,43 @@
%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: 644ae2138142da14c860cb25fd5c0554, type: 3}
m_Name: Ring
m_EditorClassIdentifier:
name: Ring of Trust
icon: {fileID: -379072453, guid: fd0a8ab92d5cb1747a30af6d302c3d25, type: 3}
itemValue: 0
rarity:
quantity:
maxStack: 1
sellValue: 0
type: 8
isStackable: 0
isEquippable: 1
isConsumable: 0
isQuestItem: 0
isKeyItem: 0
isCraftable: 0
isTradeable: 0
isSellable: 0
isDroppable: 0
isDestroyable: 1
isUsable: 0
attack: 0
defense: 3
speed: 1
luck: 10
magic: 0
sanity: 0
health: 0
experience: 0
durability: 0
maxDurability: 0

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 91a1ea02aea314541b5db2a410398c58
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -12,12 +12,14 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 644ae2138142da14c860cb25fd5c0554, type: 3}
m_Name: Scroll
m_EditorClassIdentifier:
itemName: Scroll
name: Scroll of Trust
icon: {fileID: -988535385, guid: 8cb35144684c70446b308bddac40a586, type: 3}
itemValue: 0
rarity:
qty:
quantity:
maxStack: 1
sellValue: 0
type: 9
isStackable: 0
isEquippable: 0
isConsumable: 0
@ -29,3 +31,13 @@ MonoBehaviour:
isDroppable: 0
isDestroyable: 0
isUsable: 0
attack: 0
defense: 0
speed: 0
luck: 0
magic: 0
sanity: 0
health: 0
experience: 0
durability: 0
maxDurability: 0

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,7 @@
fileFormatVersion: 2
guid: 19788f49ce1c96f42831c9406c785bbd
PrefabImporter:
guid: 5ba1555a7b4608e4b8f1a6086d5d702d
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:

View File

@ -0,0 +1,77 @@
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class ItemComponent : MonoBehaviour
{
public PrefabManager prefabManager = PrefabManager.Instance;
public ItemHandler itemHandler;
public GameItem item;
public TMP_Text nameText;
public Image itemIcon;
public Text quantityText;
private void Awake()
{
prefabManager = PrefabManager.Instance;
nameText = transform.Find("ItemName").GetComponent<TMP_Text>();
if (nameText == null) Debug.LogError("ItemName not found");
quantityText = transform.Find("qty").GetComponent<Text>();
if (quantityText == null) Debug.LogError("qty not found");
itemIcon = transform.Find("Icon").GetComponent<Image>();
if (itemIcon == null) Debug.LogError("Icon not found");
itemHandler = gameObject.AddComponent<ItemHandler>();
if (itemHandler == null) Debug.LogError("ItemHandler not found");
}
public void SetQuantity(string qty)
{
// Find the Quantity child and get the TMP_Text component
quantityText.text = qty;
}
public void SetName(string name)
{
// Find the ItemName child and get the TMP_Text component
nameText.text = name;
}
public void SetIcon(Sprite icon)
{
// Find the Icon child and get the Image component
itemIcon.sprite = icon;
}
public void SetItem(GameItem newItem)
{
// todo: Use the new Item to update the ItemName, Icon, qty
SetName(newItem.name);
SetIcon(newItem.icon);
SetQuantity(newItem.quantity);
item = newItem;
}
public void DeleteItem()
{
// need to delete the parent of this item Component
Destroy(transform.gameObject);
}
public GameItem GetItem()
{
return item;
}
public ItemComponent Copy()
{
Debug.Log("Copying item");
var newItem = gameObject.AddComponent<ItemComponent>();
newItem.SetItem(item);
return newItem;
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 6b363dff4da946008c3bf994802907c3
timeCreated: 1718893760

View File

@ -0,0 +1,177 @@
using Managers;
using Unity.VisualScripting;
using UnityEngine;
public class SlotComponent : MonoBehaviour
{
public int SlotId;
public Slot.SlotType SlotType;
private readonly PrefabManager prefabManager = PrefabManager.Instance;
private ItemComponent itemComponent;
protected GameObject itemPrefab;
protected PlayerManager playerManager;
protected SlotHandler slotHandler;
private void Awake()
{
playerManager = GameObject.Find("PlayerManager").GetComponent<PlayerManager>();
// PrintHierarchy(gameObject);
slotHandler = gameObject.AddComponent<SlotHandler>();
slotHandler.SetSlotComponent(this);
// ListAllComponents();
// ListAllComponentsInChildren();
if (slotHandler == null) Debug.LogError("SlotHandler not found");
}
public void SetSlotId(int id)
{
SlotId = id;
}
public void PrintHierarchy(GameObject obj, string indent = "")
{
// Print the name of the current GameObject
Debug.Log(indent + obj.name);
// Print the names of all components attached to the current GameObject
foreach (var component in obj.GetComponents<Component>()) Debug.Log(indent + " - " + component.GetType().Name);
// Recursively print the hierarchy for each child of the current GameObject
foreach (Transform child in obj.transform) PrintHierarchy(child.gameObject, indent + " ");
}
public void ListAllComponents()
{
var components = GetComponents<Component>();
foreach (var component in components) Debug.Log(component.GetType().Name);
}
public void ListAllComponentsInChildren()
{
var components = GetComponentsInChildren<Component>();
foreach (var component in components) Debug.Log(component.GetType().Name);
}
// use slot type to choose manager to get slot from
protected void SwapItems(GameItem draggedItemHandler)
{
// Get parent slot of the dragged item
var draggedSlot = draggedItemHandler.GetComponentInParent<SlotComponent>();
var destinationSlot = GetComponent<SlotComponent>();
// we need to check the slot type of the dragged item to see if it can be placed in this slot
if (draggedSlot.SlotType != SlotType)
{
Debug.Log("Cannot place item in this slot");
return;
}
playerManager.SwapItems(draggedSlot.SlotType, draggedSlot.SlotId, SlotType, SlotId);
var tempItem = destinationSlot;
// assigns to the destination slot the dragged item
AssignItem(draggedItemHandler);
// If this slot had an item, move it to the dragged item's original slot
if (destinationSlot != null)
{
draggedSlot.AssignItem(destinationSlot.GetItem());
UIManager.Instance.InventoryUIController.UpdateUI();
}
else
{
Destroy(draggedItemHandler);
}
}
public void AssignItem(GameItem newItem)
{
// Remove any existing ItemPrefab(Clone) from this slot
DeleteItem();
if (itemPrefab == null)
// Debug.LogError("ItemPrefab not set");
// return;
itemPrefab = prefabManager.GetItemPrefab();
var newItemInstance = Instantiate(itemPrefab, transform);
itemComponent = newItemInstance.GetComponent<ItemComponent>();
itemComponent.SetItem(newItem);
}
public GameItem GetItem()
{
if (itemComponent == null) return null;
return itemComponent.GetItem();
}
public ItemComponent GetItemComponent()
{
Debug.Log("Getting item component");
return itemComponent;
}
public int GetSlotId()
{
return SlotId;
}
public void DeleteSlot()
{
if (itemComponent == null) return;
Destroy(itemComponent.transform.parent.gameObject);
// Destroy(itemComponent.itemHandler);
// Destroy(itemComponent);
itemComponent = null;
}
public void SetSlotDetails(Slot slotDetails)
{
SlotId = slotDetails.slotId;
SlotType = slotDetails.slotType;
if (slotDetails.item != null) AssignItem(slotDetails.item);
if (slotDetails.item == null) DeleteItem();
}
public Slot.SlotType GetSlotType()
{
return SlotType;
}
public void AssignItemComponent(ItemComponent destinationItem)
{
if (destinationItem == null)
{
DeleteItem();
return;
}
AssignItem(destinationItem.GetItem());
/*itemComponent.transform.SetParent(transform, false);
itemComponent.GetComponent<RectTransform>().anchoredPosition = Vector2.zero;
itemComponent.GetComponent<RectTransform>().offsetMin = Vector2.zero;
itemComponent.GetComponent<RectTransform>().offsetMax = Vector2.zero;*/
}
public void DeleteItem()
{
if (itemComponent == null) return;
itemComponent.DeleteItem();
itemComponent = null;
}
public bool IsAllowedItemTypes(Slot.SlotType slotType, int slotId, GameItem.ItemType type)
{
var slot = playerManager.GetSlot(slotType, slotId);
return slot.IsAllowedItemTypes(type);
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 0ad9b6cc13ef42e18dc900bb5e92f78e
timeCreated: 1718833945

View File

@ -1,8 +1,3 @@
fileFormatVersion: 2
guid: 5ba1555a7b4608e4b8f1a6086d5d702d
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: ffa7671ec1b841bba356d6fdd19decc1
timeCreated: 1718893691

View File

@ -0,0 +1,64 @@
using System.Collections.Generic;
using UnityEngine;
// InventoryUI.cs
public class EquipmentUIController : MonoBehaviour
{
public Transform itemParent;
public EquipmentManager equipmentManager;
public PrefabManager prefabManager;
private readonly Dictionary<int, GameObject> _slots = new();
private void Start()
{
Debug.Log("EquipmentUI Start");
if (itemParent == null)
{
Debug.LogWarning("ItemParent is null! Can not attach");
return;
}
// Delete existing children if any.
foreach (Transform child in itemParent) Destroy(child.gameObject);
if (equipmentManager.Slots.Count == 0)
equipmentManager.Initialize();
var slotPrefab = prefabManager.GetSlotPrefab();
// var itemPrefab = prefabManager.GetItemPrefab();
foreach (var slot in equipmentManager.Slots)
{
// Draw slots to screen
var slotDisplay = Instantiate(slotPrefab, itemParent);
slotDisplay.transform.localScale = new Vector3((float)0.5, (float)0.5, (float)0.5);
var i = slot.Key;
var slotComponent = slotDisplay.GetComponent<SlotComponent>();
// Add prefab to slot
slotComponent.SetSlotDetails(slot.Value);
_slots.Add(i, slotDisplay);
}
Debug.Log("Finished adding items to toolbar slots");
}
public void ListChildren(GameObject parent)
{
foreach (Transform child in parent.transform) Debug.Log("Child: " + child.name);
}
public void UpdateUI()
{
// Get values from inventory and redraw the inventory slots based on that.
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 49d5d25853404cd18083e9b5b16de617
timeCreated: 1718996861

View File

@ -1,167 +0,0 @@
using System;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Serialization;
public class InventorySlotDisplayController : MonoBehaviour, IDropHandler
{
// public Image icon;
// public Text itemName;
[FormerlySerializedAs("inventoryItem")]
public InventoryManager inventoryManager;
public GameObject inventoryItemPrefab;
// private Transform inventoryItemContainer;
private int _slotId;
public void OnDrop(PointerEventData eventData)
{
Debug.Log("Dropped on internal slot: " + _slotId);
inventoryManager = GameObject.Find("InventoryManager").GetComponent<InventoryManager>();
var destinationSlot = inventoryManager.GetSlot(_slotId);
var destinationItem = inventoryManager.GetItemFromSlot(destinationSlot.slotId);
var draggedSlotController = eventData.pointerDrag.GetComponentInParent<InventorySlotDisplayController>();
var draggedComponent = eventData.pointerDrag.GetComponent<InventoryItemDisplayController>();
var draggedItem = draggedComponent.gameItem;
var draggedSlotId = draggedSlotController._slotId;
Debug.Log("Dropped item: " + draggedItem.itemName);
// var sourceSlot = eventData.pointerDrag.GetComponentInParent<InventorySlotDisplayController>();
if (eventData.pointerDrag != null)
{
if (draggedItem == null)
{
Debug.Log("inventory item does not exist");
// Delete visual representation of dragged item
Destroy(eventData.pointerDrag);
return;
}
// Place the dragged item in this slot
// draggedComponent.GetComponent<RectTransform>().anchoredPosition =
// GetComponent<RectTransform>().anchoredPosition;
if (destinationItem == null)
{
Debug.Log("Destination slot is empty");
inventoryManager.SwapItems(destinationSlot.slotId, draggedSlotId);
// Re parent to this slot
draggedComponent.transform.SetParent(transform, false);
draggedComponent.GetComponent<RectTransform>().anchoredPosition = Vector2.zero;
draggedComponent.GetComponent<RectTransform>().offsetMin = Vector2.zero;
draggedComponent.GetComponent<RectTransform>().offsetMax = Vector2.zero;
}
else
{
Debug.Log("Destination slot is not empty");
inventoryManager.SwapItems(draggedSlotId, destinationSlot.slotId);
// Get the parent of the dragged component
// originalSlot.SetSlotDetails();
var selfItem = transform.Find("InventoryItem(Clone)").GetComponent<InventoryItemDisplayController>();
if (selfItem == null) Debug.Log("Self item is null");
selfItem.transform.SetParent(draggedSlotController.transform, false);
selfItem.GetComponent<RectTransform>().anchoredPosition = Vector2.zero;
selfItem.GetComponent<RectTransform>().offsetMin = Vector2.zero;
selfItem.GetComponent<RectTransform>().offsetMax = Vector2.zero;
// Re parent to this slot
draggedComponent.transform.SetParent(transform, false);
draggedComponent.GetComponent<RectTransform>().anchoredPosition = Vector2.zero;
draggedComponent.GetComponent<RectTransform>().offsetMin = Vector2.zero;
draggedComponent.GetComponent<RectTransform>().offsetMax = Vector2.zero;
}
}
}
public void SetSlotId(int id)
{
_slotId = id;
}
private void SwapItems(InventoryItemDisplayController draggedItemDisplayController)
{
inventoryManager = GameObject.Find("InventoryManager").GetComponent<InventoryManager>();
Debug.Log("!!!!!Swapping items");
var destinationSlot = inventoryManager.GetSlot(_slotId);
var originalSlot = draggedItemDisplayController.GetComponentInParent<InventorySlotDisplayController>();
var tempItem = destinationSlot.item;
// assigns to the destination slot the dragged item
AssignInventoryItem(draggedItemDisplayController.gameItem);
// If this slot had an item, move it to the dragged item's original slot
if (destinationSlot.item != null)
{
originalSlot.AssignInventoryItem(tempItem);
UIManager.Instance.InventoryUIController.UpdateUI();
}
else
{
Destroy(draggedItemDisplayController.gameObject);
}
}
public void AssignInventoryItem(GameItem newItem)
{
// Remove any existing InventoryItem(Clone) from this slot
try
{
Destroy(transform.Find("InventoryItem(Clone)")?.gameObject);
}
catch (Exception e)
{
Debug.Log("No item to destroy");
}
if (inventoryItemPrefab == null)
{
Debug.LogError("InventoryItemPrefab not set");
return;
}
// Instantiate the new item in this slot
var newItemInstance = Instantiate(inventoryItemPrefab, transform);
var itemDisplay = newItemInstance.GetComponent<InventoryItemDisplayController>();
itemDisplay.SetItem(newItem);
}
public void SetInventoryItemPrefab(GameObject prefab)
{
inventoryItemPrefab = prefab;
}
public void DeleteInventoryItem()
{
Destroy(transform.Find("InventoryItem(Clone)")?.gameObject);
}
public void SetSlotDetails(InventorySlot slotDetails)
{
inventoryManager = GameObject.Find("InventoryManager").GetComponent<InventoryManager>();
_slotId = slotDetails.slotId;
if (slotDetails.item != null) AssignInventoryItem(slotDetails.item);
if (slotDetails.item == null) DeleteInventoryItem();
}
public void UpdateUI()
{
}
}

View File

@ -1,16 +1,16 @@
using System.Collections.Generic;
using Managers;
using UnityEngine;
// InventoryUI.cs
public class InventoryUIController : MonoBehaviour
{
public InventoryManager inventoryManager;
public Transform itemParent;
public GameObject itemSlotPrefab;
public GameObject inventoryItemPrefab;
public InventoryManager inventoryManager;
public PrefabManager prefabManager;
public readonly Dictionary<int, GameObject> DisplayedSlots = new();
private readonly Dictionary<int, GameObject> _slots = new();
private void Start()
{
@ -24,60 +24,31 @@ public class InventoryUIController : MonoBehaviour
// Delete existing children if any.
foreach (Transform child in itemParent) Destroy(child.gameObject);
if (inventoryManager.inventorySlots.Count == 0)
inventoryManager.InitializeInventory();
if (inventoryManager.Slots.Count == 0)
inventoryManager.InitializeInventory(PlayerManager.Instance.playerData);
var slotPrefab = prefabManager.GetSlotPrefab();
var itemPrefab = prefabManager.GetItemPrefab();
foreach (var inventorySlot in inventoryManager.inventorySlots)
foreach (var inventorySlot in inventoryManager.Slots)
{
// Draw slots to screen
var slotDisplay = Instantiate(itemSlotPrefab, itemParent);
var i = inventorySlot.slotId;
var slotDisplay = Instantiate(slotPrefab, itemParent);
var i = inventorySlot.Key;
var inventorySlotComponent = slotDisplay.GetComponent<SlotComponent>();
// Add prefab to slot
slotDisplay.GetComponent<InventorySlotDisplayController>().SetInventoryItemPrefab(inventoryItemPrefab);
slotDisplay.GetComponent<InventorySlotDisplayController>().SetSlotDetails(inventorySlot);
inventorySlotComponent.SetSlotDetails(inventorySlot.Value);
DisplayedSlots.Add(i, slotDisplay);
// GenerateInventorySlotDisplay(inventorySlot);
_slots.Add(i, slotDisplay);
}
// Debug.Log("Adding item to slot:" + item.GetItemName());
Debug.Log("Finished adding items to slots");
}
private void AddItemToSlot(GameItem gameItem, int id)
{
/*Debug.Log(item);
Debug.Log(item.itemName);
ListChildren(slot);
var itemNameText = slot.GetComponentInChildren<TextMeshProUGUI>();
if (itemNameText != null)
itemNameText.text = item.itemName;
else
Debug.LogWarning("ItemName Text component not found in slot: " + slot);
// slot.GetComponentInChildren<Text>().text = item.itemName;
var iconTransform = slot.transform.Find("Icon");
if (iconTransform != null)
{
var iconImage = iconTransform.GetComponent<Image>();
if (iconImage != null)
iconImage.sprite = item.icon;
else
Debug.LogWarning("Image component not found on Icon child: " + slot);
}
else
{
Debug.LogWarning("Icon child not found in slot: " + slot);
}*/
}
public void ListChildren(GameObject parent)
{
foreach (Transform child in parent.transform) Debug.Log("Child: " + child.name);

View File

@ -0,0 +1,63 @@
using System.Collections.Generic;
using UnityEngine;
// InventoryUI.cs
public class ToolbarUIController : MonoBehaviour
{
public Transform itemParent;
public ToolbarManager toolbarManager;
public PrefabManager prefabManager;
private readonly Dictionary<int, GameObject> _slots = new();
private void Start()
{
Debug.Log("ToolbarUI Start");
if (itemParent == null)
{
Debug.LogWarning("ItemParent is null! Can not attach");
return;
}
// Delete existing children if any.
foreach (Transform child in itemParent) Destroy(child.gameObject);
if (toolbarManager.Slots.Count == 0)
toolbarManager.InitializeToolbar();
var slotPrefab = prefabManager.GetSlotPrefab();
// var itemPrefab = prefabManager.GetItemPrefab();
foreach (var toolbarSlot in toolbarManager.Slots)
{
// Draw slots to screen
var slotDisplay = Instantiate(slotPrefab, itemParent);
slotDisplay.transform.localScale = new Vector3(1, 1, 1);
var i = toolbarSlot.Key;
var slotComponent = slotDisplay.GetComponent<SlotComponent>();
// Add prefab to slot
slotComponent.SetSlotDetails(toolbarSlot.Value);
_slots.Add(i, slotDisplay);
}
Debug.Log("Finished adding items to toolbar slots");
}
public void ListChildren(GameObject parent)
{
foreach (Transform child in parent.transform) Debug.Log("Child: " + child.name);
}
public void UpdateUI()
{
// Get values from inventory and redraw the inventory slots based on that.
}
}

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: f60bac826c729984b9c384e8522693cd
guid: 81002747340646ad817796a4737cda25
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b12a0e4f342942f48bfd7caf836eaf18
timeCreated: 1718834918

View File

@ -1,19 +1,15 @@
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Serialization;
using UnityEngine.UI;
// Drag Dropable
public class InventoryItemDisplayController : MonoBehaviour, IPointerDownHandler, IBeginDragHandler, IEndDragHandler,
public class ItemHandler : MonoBehaviour, IPointerDownHandler, IBeginDragHandler, IEndDragHandler,
IDragHandler
{
[SerializeField] private Canvas canvas;
[FormerlySerializedAs("InventoryItem")]
public GameItem gameItem;
private CanvasGroup _canvasGroup;
private Canvas _dragLayerCanvas;
private Transform _originalParent;
@ -31,13 +27,12 @@ public class InventoryItemDisplayController : MonoBehaviour, IPointerDownHandler
_dragLayerCanvas = GameObject.Find("DragLayerCanvas").GetComponent<Canvas>();
}
// Update is called once per frame
private void Update()
{
}
public void OnBeginDrag(PointerEventData eventData)
{
// starting slot type and slot index
var parentSlotComponent = eventData.pointerDrag.GetComponentInParent<SlotComponent>();
Debug.Log("Parent Slot Type: " + parentSlotComponent.GetSlotType());
Debug.Log("Begin Drag");
_originalPosition = _rectTransform.anchoredPosition;
_canvasGroup.alpha = 0.6f;
@ -54,31 +49,33 @@ public class InventoryItemDisplayController : MonoBehaviour, IPointerDownHandler
return;
}
// Convert the mouse position to canvas space and update the item's position
Vector2 localPointerPosition;
RectTransformUtility.ScreenPointToLocalPointInRectangle(
canvas.transform as RectTransform,
eventData.position,
canvas.worldCamera,
out localPointerPosition);
// Convert the mouse position to world position
var gameCamera = GameObject.Find("Main Camera").GetComponent<Camera>();
var worldPosition = gameCamera.ScreenToWorldPoint(eventData.position);
worldPosition.z = 0f; // Set z-coordinate to 0 to ensure the item stays on the UI plane
_rectTransform.localPosition = localPointerPosition;
// Update the item's position to follow the mouse
_rectTransform.position = worldPosition;
}
public void OnEndDrag(PointerEventData eventData)
{
Debug.Log("End Drag");
var parentSlotComponent = eventData.pointerDrag.GetComponentInParent<SlotComponent>();
// Check if dropped on a valid slot
var hitObjects = eventData.hovered;
var droppedOnValidSlot = false;
foreach (var obj in hitObjects)
if (obj.GetComponent<InventorySlotDisplayController>() != null)
if (obj.GetComponent<SlotComponent>() != null && obj.GetComponent<SlotComponent>() != parentSlotComponent)
{
droppedOnValidSlot = true;
break;
}
// if its the same slot then retur to last position
if (!droppedOnValidSlot)
// Snap back to original position if not dropped in a valid slot
_rectTransform.anchoredPosition = _originalPosition;
@ -94,25 +91,20 @@ public class InventoryItemDisplayController : MonoBehaviour, IPointerDownHandler
}
public void SetItem(GameItem item)
public void DisplayItem(GameItem item)
{
if (item == null)
{
Debug.Log("Item is null!");
gameItem = null;
Destroy(transform.gameObject);
return;
}
gameItem = item;
Debug.Log(transform.GetChild(1));
transform.Find("ItemName").GetComponent<TMP_Text>().text = item.itemName;
transform.Find("qty").GetComponent<Text>().text = item.qty;
// Debug.Log(transform.GetChild(1));
transform.Find("ItemName").GetComponent<TMP_Text>().text = item.name;
transform.Find("qty").GetComponent<Text>().text = item.quantity;
transform.Find("Icon").GetComponent<Image>().sprite = item.icon;
Debug.Log("completed processing set item");
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 8da4d6bbd5744beebed5bb6eb0bcfaed
timeCreated: 1718834088

View File

@ -1,7 +1,7 @@
// Example: PlayerState.cs
public enum PlayerState {
Idle,
Walking,
Running,
Attacking
}
// Example: PlayerState.cs
public enum PlayerState {
Idle,
Walking,
Running,
Attacking
}

View File

@ -0,0 +1,165 @@
using Managers;
using UnityEngine;
using UnityEngine.EventSystems;
public class SlotHandler : MonoBehaviour, IDropHandler
{
public PlayerManager playerManager;
private SlotComponent _slotComponent;
private void Awake()
{
playerManager = GameObject.Find("PlayerManager").GetComponent<PlayerManager>();
}
// get allowed item types
public void OnDrop(PointerEventData eventData)
{
Debug.Log("Dropped on internal slot: " + _slotComponent.GetSlotId());
// dragged From (new item)
var sourceSlot = eventData.pointerDrag.GetComponentInParent<SlotComponent>();
var sourceSlotItem = sourceSlot.GetItemComponent();
var destinationSlotData = playerManager.GetSlot(_slotComponent.GetSlotType(), _slotComponent.GetSlotId());
var destinationItem = _slotComponent.GetItemComponent();
var currentSlot = GetComponent<SlotComponent>();
// check if valid swap
Debug.Log("Source Slot Type: " + sourceSlot.GetSlotType());
Debug.Log("Destination Slot Type: " + _slotComponent.GetSlotType());
/*if (sourceSlot.GetSlotType() != _slotComponent.GetSlotType())
{
Debug.Log("Invalid swap");
// Reset the item to its original position
sourceSlotItem.GetComponent<RectTransform>().anchoredPosition = Vector2.zero;
sourceSlotItem.GetComponent<RectTransform>().offsetMin = Vector2.zero;
sourceSlotItem.GetComponent<RectTransform>().offsetMax = Vector2.zero;
return;
}*/
// check item type to see if it can be placed in the slot for equipment
if (currentSlot.GetSlotType() == Slot.SlotType.Equipment)
{
var sourceItem = sourceSlot.GetItemComponent();
// check if is allowed in slot
if (currentSlot.IsAllowedItemTypes(currentSlot.GetSlotType(), currentSlot.GetSlotId(),
sourceItem.GetItem().type) == false)
{
Debug.Log("Invalid swap");
// Reset the item to its original position
sourceSlotItem.GetComponent<RectTransform>().anchoredPosition = Vector2.zero;
sourceSlotItem.GetComponent<RectTransform>().offsetMin = Vector2.zero;
sourceSlotItem.GetComponent<RectTransform>().offsetMax = Vector2.zero;
return;
}
}
// dragged To (this)
playerManager.SwapItems(_slotComponent.GetSlotType(), _slotComponent.GetSlotId(), sourceSlot.GetSlotType(),
sourceSlot.GetSlotId());
// If the destination slot is empty, assign the dragged item to it
if (destinationItem == null)
{
currentSlot.AssignItemComponent(sourceSlotItem);
sourceSlot.DeleteItem();
// sourceSlotItem.transform.SetParent(transform, false);
// sourceSlotItem.GetComponent<RectTransform>().anchoredPosition = Vector2.zero;
// sourceSlotItem.GetComponent<RectTransform>().offsetMin = Vector2.zero;
// sourceSlotItem.GetComponent<RectTransform>().offsetMax = Vector2.zero;
}
else
{
// If the destination slot is not empty, swap the items
currentSlot.AssignItemComponent(sourceSlotItem);
sourceSlotItem.DeleteItem();
sourceSlot.AssignItemComponent(destinationItem);
destinationItem.DeleteItem();
// sourceSlotItem.transform.SetParent(transform, false);
// sourceSlotItem.GetComponent<RectTransform>().anchoredPosition = Vector2.zero;
// sourceSlotItem.GetComponent<RectTransform>().offsetMin = Vector2.zero;
// sourceSlotItem.GetComponent<RectTransform>().offsetMax = Vector2.zero;
}
}
public void SetSlotComponent(SlotComponent slotComponent)
{
_slotComponent = slotComponent;
}
}
//
// var destinationSlot = playerManager.inventoryManager.GetSlot(_slotId);
// var destinationItem = playerManager.inventoryManager.GetItemFromSlot(destinationSlot.slotId);
// var draggedSlotController = eventData.pointerDrag.GetComponentInParent<SlotComponent>();
// var draggedComponent = eventData.pointerDrag.GetComponent<ItemHandler>();
// var draggedItem = draggedSlotController.GetItem();
//
// var draggedSlotId = draggedSlotController.GetSlotId();
//
// Debug.Log("Dropped item: " + draggedItem.name);
//
//
// if (eventData.pointerDrag != null)
// {
// if (draggedItem == null)
// {
// Debug.Log("inventory item does not exist");
// // Delete visual representation of dragged item
// Destroy(eventData.pointerDrag);
// return;
// }
//
// // Place the dragged item in this slot
// // draggedComponent.GetComponent<RectTransform>().anchoredPosition =
//
// if (destinationItem == null)
// {
// Debug.Log("Destination slot is empty");
// inventoryManager.SwapItems(destinationSlot.slotId, draggedSlotId);
//
// // Re parent to this slot
// draggedComponent.transform.SetParent(transform, false);
// draggedComponent.GetComponent<RectTransform>().anchoredPosition = Vector2.zero;
// draggedComponent.GetComponent<RectTransform>().offsetMin = Vector2.zero;
// draggedComponent.GetComponent<RectTransform>().offsetMax = Vector2.zero;
// }
// else
// {
// Debug.Log("Destination slot is not empty");
// inventoryManager.SwapItems(draggedSlotId, destinationSlot.slotId);
//
// // Get the parent of the dragged component
//
// // originalSlot.SetSlotDetails();
//
//
// var selfItem = transform.Find("InventoryItem(Clone)").GetComponent<ItemHandler>();
//
// if (selfItem == null) Debug.Log("Self item is null");
//
//
// selfItem.transform.SetParent(draggedSlotController.transform, false);
// selfItem.GetComponent<RectTransform>().anchoredPosition = Vector2.zero;
// selfItem.GetComponent<RectTransform>().offsetMin = Vector2.zero;
// selfItem.GetComponent<RectTransform>().offsetMax = Vector2.zero;
//
// // Re parent to this slot
// draggedComponent.transform.SetParent(transform, false);
// draggedComponent.GetComponent<RectTransform>().anchoredPosition = Vector2.zero;
// draggedComponent.GetComponent<RectTransform>().offsetMin = Vector2.zero;
// draggedComponent.GetComponent<RectTransform>().offsetMax = Vector2.zero;
// }

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 4a8699e848ac4a709fe38ea6a96021e0
timeCreated: 1718837253

View File

@ -1,3 +1,4 @@
using Managers;
using UnityEngine;
public class GameManager : MonoBehaviour
@ -6,7 +7,8 @@ public class GameManager : MonoBehaviour
public static GameManager Instance { get; private set; }
public UIManager UIManager { get; private set; }
public InventoryManager InventoryManager { get; private set; }
public PlayerManager PlayerManager { get; private set; }
public GameItemManager GameItemManager { get; set; }
@ -24,8 +26,8 @@ public class GameManager : MonoBehaviour
// Initialize managers
UIManager = GetComponent<UIManager>();
GameItemManager = GetComponent<GameItemManager>();
InventoryManager = GetComponent<InventoryManager>();
AudioManager = GetComponent<AudioManager>();
PlayerManager = GetComponent<PlayerManager>();
}
else
{

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 0fecc5d6a08b4716b911784e0d3a65f4
timeCreated: 1718884590

View File

@ -0,0 +1,13 @@
public interface IItemManager<TSlot> where TSlot : Slot
{
public static IItemManager<TSlot> Instance;
GameItem GetItemFromSlot(int slotId);
void RemoveItemFromSlot(int slotId);
void AddItemToOpenSlot(GameItem item);
void AddItemToSlot(GameItem item, int slotId);
void AddSlot(TSlot slot);
void RemoveSlot(int slotId);
TSlot GetSlot(int slotId);
void SwapItems(int slotId1, int slotId2);
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: dbd25d5de2bf4780ae6354c857cae04f
timeCreated: 1718884512

View File

@ -1,131 +0,0 @@
using System.Collections.Generic;
using Managers;
using UnityEngine;
// InventoryManager.cs
public class InventoryManager : MonoBehaviour
{
public List<InventorySlot> inventorySlots = new();
public PlayerManager playerManager;
private void Start()
{
Debug.Log("InventoryManager Start");
InitializeInventory();
}
private void AddSlot(InventorySlot slot)
{
inventorySlots.Add(slot);
}
public InventorySlot GetSlot(int slotId)
{
foreach (var slot in inventorySlots)
if (slot.slotId == slotId)
{
Debug.Log("Got slot: " + slotId);
return slot;
}
Debug.LogWarning("Slot not found: " + slotId);
return null;
}
private void RemoveSlot(InventorySlot slot)
{
inventorySlots.Remove(slot);
}
public void RemoveItemFromSlot(GameItem item)
{
foreach (var slot in inventorySlots)
if (slot.item == item)
{
slot.item = null;
Debug.Log("Removed item from slot: " + item.itemName);
return;
}
Debug.LogWarning("Item not found in any slot: " + item.itemName);
}
public GameItem GetItemFromSlot(int slotId)
{
Debug.Log("Getting item from slot: " + slotId);
foreach (var slot in inventorySlots)
if (slot.slotId == slotId && slot.item != null)
{
Debug.Log("Got item from slot: " + slot.item.itemName);
return slot.item;
}
Debug.LogWarning("Item not found in slot: " + slotId);
return null;
}
public void SetItemInSlot(int slotId, GameItem item)
{
Debug.Log("Setting item in slot: " + slotId + " / " + item?.itemName ?? "null");
foreach (var slot in inventorySlots)
if (slot.slotId == slotId)
{
if (item == null)
{
Debug.Log("Item is null, removing item from slot: " + slotId);
slot.item = null;
return;
}
slot.item = item;
return;
}
Debug.LogWarning("Item not found in slot: " + slotId);
}
public void SwapItems(int slotId1, int slotId2)
{
var item1 = GetItemFromSlot(slotId1);
var item2 = GetItemFromSlot(slotId2);
SetItemInSlot(slotId1, item2);
SetItemInSlot(slotId2, item1);
}
public void AddItemToOpenSlot(GameItem item)
{
foreach (var slot in inventorySlots)
if (slot.IsEmpty())
{
slot.slotId = inventorySlots.IndexOf(slot);
slot.item = item;
Debug.Log("Added item to slot: " + slot.slotId + " / " + item.itemName);
return;
}
Debug.LogWarning("No empty slots available to add item: " + item.itemName);
}
public void InitializeInventory()
{
// create player slots for inventory
for (var i = 0; i < playerManager.playerData.inventorySize; i++)
{
var slot = ScriptableObject.CreateInstance<InventorySlot>();
slot.slotId = i;
slot.item = null;
AddSlot(slot);
}
AddItemToOpenSlot(GameItemManager.Instance.gameItems[0]);
AddItemToOpenSlot(GameItemManager.Instance.gameItems[1]);
AddItemToOpenSlot(GameItemManager.Instance.gameItems[2]);
AddItemToOpenSlot(GameItemManager.Instance.gameItems[3]);
Debug.Log("Completed Initialized items in InventoryManager");
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d3d01eb40fff47c7a4c405597be0940a
timeCreated: 1718898248

View File

@ -0,0 +1,38 @@
using System.Collections.Generic;
using Managers;
using UnityEngine;
public abstract class BaseItemManager : MonoBehaviour
{
public static BaseItemManager Instance;
public PlayerManager playerManager;
public readonly Dictionary<int, Slot> slots = new();
private void Awake()
{
if (Instance == null)
{
Instance = this;
DontDestroyOnLoad(gameObject);
}
else
{
Destroy(gameObject);
}
}
// Common methods here
public abstract GameItem GetItemFromSlot(int slotId);
public abstract void RemoveItemFromSlot(int slotId);
public abstract void AddItemToOpenSlot(GameItem item);
public abstract void AddItemToSlot(GameItem item, int slotId);
public abstract void AddSlot(Slot slot);
public abstract void RemoveSlot(int slotId);
public Slot GetSlot(int slotId)
{
return slots.GetValueOrDefault(slotId, null);
}
public abstract void SwapItems(int slotId1, int slotId2);
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c4c8e112403d44809ccfedeef9514300
timeCreated: 1718898445

View File

@ -0,0 +1,167 @@
using System.Collections.Generic;
using UnityEngine;
// InventoryManager.cs
public class EquipmentManager : MonoBehaviour, IItemManager<Slot>
{
public static EquipmentManager Instance;
public readonly Dictionary<int, Slot> Slots = new();
public Slot ActiveSlot { get; set; }
private void Awake()
{
if (Instance == null)
{
Instance = this;
DontDestroyOnLoad(gameObject);
}
else
{
Destroy(gameObject);
}
}
private void Start()
{
Debug.Log("EquipmentManager Start");
Initialize();
}
public GameItem GetItemFromSlot(int slotId)
{
return Slots.TryGetValue(slotId, out var slot) ? slot.item : null;
}
public void RemoveItemFromSlot(int slotId)
{
if (Slots.TryGetValue(slotId, out var slot))
slot.item = null;
else
Debug.LogWarning("Slot not found: " + slotId);
}
public void AddItemToOpenSlot(GameItem item)
{
foreach (var slot in Slots.Values)
if (slot.IsEmpty())
{
slot.item = item;
Debug.Log("Added item to slot: " + slot.slotId + " / " + item.name);
return;
}
Debug.LogWarning("No empty slots available to add item: " + item.name);
}
public void AddItemToSlot(GameItem item, int slotId)
{
if (Slots.TryGetValue(slotId, out var slot))
slot.item = item;
else
Debug.LogWarning("Slot not found: " + slotId);
}
public void RemoveSlot(int slotId)
{
Slots.Remove(slotId);
}
public void SwapItems(int slotId1, int slotId2)
{
if (Slots.TryGetValue(slotId1, out var slot1) &&
Slots.TryGetValue(slotId2, out var slot2))
(slot1.item, slot2.item) = (slot2.item, slot1.item);
}
public void AddSlot(Slot slot)
{
Slots[slot.slotId] = slot;
}
public Slot GetSlot(int slotId)
{
return Slots.GetValueOrDefault(slotId, null);
}
public void RemoveItemFromSlot(GameItem item)
{
foreach (var slot in Slots.Values)
if (slot.item == item)
{
slot.item = null;
Debug.Log("Removed item from slot: " + item.name);
return;
}
Debug.LogWarning("Item not found in any slot: " + item.name);
}
public void SetItemInSlot(int slotId, GameItem item)
{
// TODO: check if item is valid for slot
if (Slots.TryGetValue(slotId, out var slot))
slot.item = item;
else
Debug.LogWarning("Slot not found: " + slotId);
}
public void SetActiveSlot(int slotId)
{
ActiveSlot = Slots[slotId];
}
public void Initialize()
{
// create player slots for inventory
var equipmentSlot = ScriptableObject.CreateInstance<Slot>();
equipmentSlot.slotId = 0;
equipmentSlot.item = null;
equipmentSlot.slotType = Slot.SlotType.Equipment;
equipmentSlot.allowedItemTypes.Add(GameItem.ItemType.Helmet);
AddSlot(equipmentSlot);
equipmentSlot = ScriptableObject.CreateInstance<Slot>();
equipmentSlot.slotId = 1;
equipmentSlot.slotType = Slot.SlotType.Equipment;
equipmentSlot.allowedItemTypes.Add(GameItem.ItemType.Accessory);
equipmentSlot.item = null;
AddSlot(equipmentSlot);
// feet
equipmentSlot = ScriptableObject.CreateInstance<Slot>();
equipmentSlot.slotId = 2;
equipmentSlot.slotType = Slot.SlotType.Equipment;
equipmentSlot.allowedItemTypes.Add(GameItem.ItemType.Armor);
equipmentSlot.item = null;
AddSlot(equipmentSlot);
equipmentSlot = ScriptableObject.CreateInstance<Slot>();
equipmentSlot.slotId = 3;
equipmentSlot.slotType = Slot.SlotType.Equipment;
equipmentSlot.allowedItemTypes.Add(GameItem.ItemType.Accessory);
equipmentSlot.allowedItemTypes.Add(GameItem.ItemType.Ring);
equipmentSlot.item = null;
AddSlot(equipmentSlot);
equipmentSlot = ScriptableObject.CreateInstance<Slot>();
equipmentSlot.slotId = 4;
equipmentSlot.slotType = Slot.SlotType.Equipment;
equipmentSlot.allowedItemTypes.Add(GameItem.ItemType.Boots);
equipmentSlot.item = null;
AddSlot(equipmentSlot);
equipmentSlot = ScriptableObject.CreateInstance<Slot>();
equipmentSlot.slotId = 5;
equipmentSlot.slotType = Slot.SlotType.Equipment;
equipmentSlot.allowedItemTypes.Add(GameItem.ItemType.Ring);
equipmentSlot.item = null;
AddSlot(equipmentSlot);
Debug.Log("Completed Initialized items in EquipmentManager");
}
}

View File

@ -1,10 +1,10 @@
fileFormatVersion: 2
guid: 893e9fbe2ce947cba19dbac86dd2c901
guid: a01e628262f74ce98e48cc21247081a3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 700
executionOrder: 285
icon: {instanceID: 0}
userData:
assetBundleName:

View File

@ -32,13 +32,13 @@ public class GameItemManager : MonoBehaviour
public void AddItem(GameItem item)
{
gameItems.Add(item);
Debug.Log("Added item: " + item.itemName);
Debug.Log("Added item: " + item.name);
}
public void RemoveItem(GameItem item)
{
gameItems.Remove(item);
Debug.Log("Removed item: " + item.itemName);
Debug.Log("Removed item: " + item.name);
}

View File

@ -0,0 +1,146 @@
using System.Collections.Generic;
using Managers;
using UnityEngine;
// InventoryManager.cs
public class InventoryManager : MonoBehaviour, IItemManager<Slot>
{
public static InventoryManager Instance;
public readonly Dictionary<int, Slot> Slots = new();
private void Awake()
{
if (Instance == null)
{
Instance = this;
DontDestroyOnLoad(gameObject);
}
else
{
Destroy(gameObject);
}
}
private void Start()
{
Debug.Log("InventoryManager Start");
InitializeInventory(PlayerManager.Instance.playerData);
}
/*public override InventorySlot GetSlot(int slotId)
{
return InventorySlots.GetValueOrDefault(slotId, null);
}*/
public Slot GetSlot(int slotId)
{
return Slots.GetValueOrDefault(slotId, null);
}
public GameItem GetItemFromSlot(int slotId)
{
return Slots.TryGetValue(slotId, out var slot) ? slot.item : null;
}
public void RemoveItemFromSlot(int slotId)
{
if (Slots.TryGetValue(slotId, out var slot))
slot.item = null;
else
Debug.LogWarning("Slot not found: " + slotId);
}
public void AddItemToOpenSlot(GameItem item)
{
foreach (var slot in Slots.Values)
if (slot.IsEmpty())
{
slot.item = item;
Debug.Log("Added item to slot: " + slot.slotId + " / " + item.name);
return;
}
Debug.LogWarning("No empty slots available to add item: " + item.name);
}
public void AddItemToSlot(GameItem item, int slotId)
{
if (Slots.TryGetValue(slotId, out var slot))
slot.item = item;
else
Debug.LogWarning("Slot not found: " + slotId);
}
public void SwapItems(int slotId1, int slotId2)
{
if (Slots.TryGetValue(slotId1, out var slot1) &&
Slots.TryGetValue(slotId2, out var slot2))
(slot1.item, slot2.item) = (slot2.item, slot1.item);
}
public void RemoveSlot(int slotId)
{
Slots.Remove(slotId);
}
public void AddSlot(Slot slot)
{
Slots[slot.slotId] = slot;
}
public void RemoveItemFromSlot(GameItem item)
{
foreach (var slot in Slots.Values)
if (slot.item == item)
{
slot.item = null;
Debug.Log("Removed item from slot: " + item.name);
return;
}
Debug.LogWarning("Item not found in any slot: " + item.name);
}
public void RemoveItemInSlot(int slotId)
{
if (Slots.TryGetValue(slotId, out var slot))
slot.item = null;
else
Debug.LogWarning("Slot not found: " + slotId);
}
public void InitializeInventory(PlayerData playerData)
{
// create player slots for inventory
for (var i = 0; i < playerData.inventorySize; i++)
{
var slot = ScriptableObject.CreateInstance<Slot>();
slot.slotId = i;
slot.item = null;
AddSlot(slot);
}
AddItemToOpenSlot(GameItemManager.Instance.gameItems[0]);
/*AddItemToOpenSlot(GameItemManager.Instance.gameItems[1]);
AddItemToOpenSlot(GameItemManager.Instance.gameItems[2]);
AddItemToOpenSlot(GameItemManager.Instance.gameItems[3]);
AddItemToOpenSlot(GameItemManager.Instance.gameItems[4]);
AddItemToOpenSlot(GameItemManager.Instance.gameItems[5]);*/
// add up to ten items or stop on error
for (var i = 0; i < 10; i++)
try
{
var item = GameItemManager.Instance.gameItems[i];
if (item == null)
break;
AddItemToOpenSlot(item);
}
catch
{
Debug.Log("Error adding items to inventory slots. Stopped at: " + i + " items.");
}
Debug.Log("Completed Initialized items in InventoryManager");
}
}

View File

@ -0,0 +1,123 @@
using System.Collections.Generic;
using Managers;
using UnityEngine;
// InventoryManager.cs
public class ToolbarManager : MonoBehaviour, IItemManager<Slot>
{
// private static ToolbarManager Instance;
public PlayerManager playerManager;
public readonly Dictionary<int, Slot> Slots = new();
private Slot.SlotType slotType = Slot.SlotType.Toolbar;
public Slot ActiveSlot { get; set; }
private void Start()
{
Debug.Log("ToolbarManager Start");
InitializeToolbar();
}
public GameItem GetItemFromSlot(int slotId)
{
return Slots.TryGetValue(slotId, out var slot) ? slot.item : null;
}
public void RemoveItemFromSlot(int slotId)
{
if (Slots.TryGetValue(slotId, out var slot))
slot.item = null;
else
Debug.LogWarning("Slot not found: " + slotId);
}
public void AddItemToOpenSlot(GameItem item)
{
foreach (var slot in Slots.Values)
if (slot.IsEmpty())
{
slot.item = item;
Debug.Log("Added item to slot: " + slot.slotId + " / " + item.name);
return;
}
Debug.LogWarning("No empty slots available to add item: " + item.name);
}
public void AddItemToSlot(GameItem item, int slotId)
{
if (Slots.TryGetValue(slotId, out var slot))
slot.item = item;
else
Debug.LogWarning("Slot not found: " + slotId);
}
public void AddSlot(Slot slot)
{
Slots[slot.slotId] = slot;
}
public void RemoveSlot(int slotId)
{
Slots.Remove(slotId);
}
public Slot GetSlot(int slotId)
{
return Slots[slotId];
}
public void SwapItems(int slotId1, int slotId2)
{
if (Slots.TryGetValue(slotId1, out var slot1) &&
Slots.TryGetValue(slotId2, out var slot2))
(slot1.item, slot2.item) = (slot2.item, slot1.item);
}
public void RemoveItemFromSlot(GameItem item)
{
foreach (var slot in Slots.Values)
if (slot.item == item)
{
slot.item = null;
Debug.Log("Removed item from slot: " + item.name);
return;
}
Debug.LogWarning("Item not found in any slot: " + item.name);
}
public void SetItemInSlot(int slotId, GameItem item)
{
if (Slots.TryGetValue(slotId, out var slot))
slot.item = item;
else
Debug.LogWarning("Slot not found: " + slotId);
}
public void SetActiveSlot(int slotId)
{
ActiveSlot = Slots[slotId];
}
public void InitializeToolbar()
{
// create player slots for inventory
for (var i = 0; i < playerManager.playerData.toolbarSize; i++)
{
var toolbarSlot = ScriptableObject.CreateInstance<Slot>();
toolbarSlot.slotId = i;
toolbarSlot.item = null;
toolbarSlot.slotType = Slot.SlotType.Toolbar;
AddSlot(toolbarSlot);
}
AddItemToOpenSlot(GameItemManager.Instance.gameItems[3]);
AddItemToOpenSlot(GameItemManager.Instance.gameItems[2]);
AddItemToOpenSlot(GameItemManager.Instance.gameItems[1]);
AddItemToOpenSlot(GameItemManager.Instance.gameItems[0]);
Debug.Log("Completed Initialized items in ToolbarManager");
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: fb47975b92514e63abbe9147cff0c7ac
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 450
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -5,6 +5,11 @@ namespace Managers
public class PlayerManager : MonoBehaviour
{
public PlayerData playerData;
public InventoryManager inventoryManager;
public EquipmentManager equipmentManager;
public ToolbarManager toolbarManager;
public static PlayerManager Instance { get; private set; }
private void Awake()
@ -12,6 +17,10 @@ namespace Managers
if (Instance == null)
{
Instance = this;
inventoryManager = GameObject.Find("InventoryManager").GetComponent<InventoryManager>();
toolbarManager = GameObject.Find("ToolbarManager").GetComponent<ToolbarManager>();
equipmentManager = GameObject.Find("EquipmentManager").GetComponent<EquipmentManager>();
DontDestroyOnLoad(gameObject);
}
else
@ -47,9 +56,137 @@ namespace Managers
playerData.gold += amount;
}
public void RemoveGold(int amount)
{
playerData.gold -= amount;
}
public void AddItemToInventory(GameItem item)
{
GameManager.Instance.InventoryManager.AddItemToOpenSlot(item);
inventoryManager.AddItemToOpenSlot(item);
}
public void AddItemToToolbar(GameItem item)
{
toolbarManager.AddItemToOpenSlot(item);
}
public void AddItemToInventorySlot(GameItem item, int slotId)
{
inventoryManager.AddItemToSlot(item, slotId);
}
public void AddItemToToolbarSlot(GameItem item, int slotId)
{
toolbarManager.AddItemToSlot(item, slotId);
}
public void AddItemToEquipmentSlot(GameItem item, int slotId)
{
equipmentManager.AddItemToSlot(item, slotId);
}
// move item from one manager to another
public void MoveItem<TSlot>(IItemManager<TSlot> sourceManager, int sourceSlotId,
IItemManager<TSlot> destinationManager,
int destinationSlotId) where TSlot : Slot
{
var item = sourceManager.GetItemFromSlot(sourceSlotId);
if (item == null) return;
sourceManager.RemoveItemFromSlot(destinationSlotId);
destinationManager.AddItemToSlot(item, destinationSlotId);
}
// swap items within the same manager
public void SwapItems<TSlot>(IItemManager<TSlot> manager, int slotId1, int slotId2) where TSlot : Slot
{
var item1 = manager.GetItemFromSlot(slotId1);
var item2 = manager.GetItemFromSlot(slotId2);
manager.RemoveItemFromSlot(slotId1);
manager.RemoveItemFromSlot(slotId2);
if (item1 != null) manager.AddItemToSlot(item1, slotId2);
if (item2 != null) manager.AddItemToSlot(item2, slotId1);
}
// swap items between two different managers
public void SwapItems(IItemManager<Slot> manager1, int slotId1, IItemManager<Slot> manager2,
int slotId2)
{
var item1 = manager1.GetItemFromSlot(slotId1);
var item2 = manager2.GetItemFromSlot(slotId2);
manager1.RemoveItemFromSlot(slotId1);
manager2.RemoveItemFromSlot(slotId2);
if (item1 != null) manager2.AddItemToSlot(item1, slotId2);
if (item2 != null) manager1.AddItemToSlot(item2, slotId1);
}
//swap items by slot type and slot id
public void SwapItems(Slot.SlotType slotType1, int slotId1, Slot.SlotType slotType2, int slotId2)
{
var manager1 = GetManagerBySlotType(slotType1);
var manager2 = GetManagerBySlotType(slotType2);
if (manager1 == null || manager2 == null) return;
SwapItems(manager1, slotId1, manager2, slotId2);
}
// gets manager by slot type
public IItemManager<Slot> GetManagerBySlotType(Slot.SlotType slotType)
{
switch (slotType)
{
case Slot.SlotType.Inventory:
Debug.Log("Getting Inventory Manager");
return inventoryManager;
case Slot.SlotType.Toolbar:
Debug.Log("Getting Toolbar Manager");
return toolbarManager;
case Slot.SlotType.Equipment:
Debug.Log("Getting Equipment Manager");
return equipmentManager;
default:
return null;
}
}
// remove item by slot type and slot id
public void RemoveItemBySlotType(Slot.SlotType slotType, int slotId)
{
var manager = GetManagerBySlotType(slotType);
if (manager == null) return;
manager.RemoveItemFromSlot(slotId);
}
public void RemoveItemFromInventorySlot(int slotId)
{
inventoryManager.RemoveItemFromSlot(slotId);
}
public void RemoveItemFromToolbarSlot(int slotId)
{
toolbarManager.RemoveItemFromSlot(slotId);
}
public void RemoveItemFromEquipmentSlot(int slotId)
{
equipmentManager.RemoveItemFromSlot(slotId);
}
public Slot GetSlot(Slot.SlotType slotType, int slotId)
{
Debug.Log("Getting SlotType " + slotType + " / " + slotId);
var manager = GetManagerBySlotType(slotType);
if (manager == null) Debug.LogError("Manager not found");
return manager.GetSlot(slotId);
}
}
}

View File

@ -0,0 +1,42 @@
using UnityEngine;
public class PrefabManager : MonoBehaviour
{
public static PrefabManager Instance;
public GameObject slotPrefab;
public GameObject itemPrefab;
public GameObject hotkeyEntryPrefab;
private void Awake()
{
Debug.Log("PrefabManager Awake");
if (Instance == null)
{
Instance = this;
DontDestroyOnLoad(gameObject);
}
else
{
Destroy(gameObject);
}
}
public GameObject GetSlotPrefab()
{
Debug.Log("Getting Slot Pefab");
if (slotPrefab == null) Debug.LogWarning("SlotPrefab is null");
return slotPrefab;
}
public GameObject GetHotkeyEntryPrefab()
{
Debug.Log("Getting HotkeyEntry Pefab");
if (hotkeyEntryPrefab == null) Debug.LogWarning("HotkeyEntryPrefab is null");
return hotkeyEntryPrefab;
}
public GameObject GetItemPrefab()
{
return itemPrefab;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 74ab37462cef4f6d99b759fd094b1d6c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 210
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -4,7 +4,7 @@ MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
executionOrder: 260
icon: {instanceID: 0}
userData:
assetBundleName:

View File

@ -21,6 +21,11 @@ public class UIManager : MonoBehaviour
public InventoryUIController InventoryUIController;
// public HotkeyUIController HotkeyUIController;
// public EquipmentUIController EquipmentUIController;
// public ToolbarUIController ToolbarUIController;
private void Awake()
{
// Implement singleton pattern

1
debug.log Normal file
View File

@ -0,0 +1 @@
[0621/084955.670:ERROR:registration_protocol_win.cc(107)] CreateFile: The system cannot find the file specified. (0x2)