feature: able to use inventor system and able to create box like entities for testing for now with temp items
This commit is contained in:
parent
60a47d93a4
commit
3b6f7945b1
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
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
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
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
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
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,75 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
// BaseSlot.cs
|
||||
public class Box : ScriptableObject
|
||||
{
|
||||
public int boxId;
|
||||
public int size;
|
||||
public int boxName;
|
||||
|
||||
public readonly Dictionary<int, Slot> Slots = new();
|
||||
|
||||
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 Slot GetSlot(int slotId)
|
||||
{
|
||||
return Slots.GetValueOrDefault(slotId, null);
|
||||
}
|
||||
|
||||
public Slot GetValueOrDefault(int slotId, object o)
|
||||
{
|
||||
if (Slots.TryGetValue(slotId, out var slot))
|
||||
return slot;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 467733b3158d462e9cacf4234b34c4de
|
||||
timeCreated: 1719005008
|
||||
|
|
@ -16,7 +16,7 @@ MonoBehaviour:
|
|||
level: 1
|
||||
health: 250
|
||||
maxHealth: 300
|
||||
inventorySize: 15
|
||||
inventorySize: 30
|
||||
toolbarSize: 10
|
||||
experience: 10
|
||||
gold: 111
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ public class Slot : ScriptableObject
|
|||
Toolbar,
|
||||
Equipment,
|
||||
Crafting,
|
||||
Chest,
|
||||
Box,
|
||||
Shop,
|
||||
Quest
|
||||
}
|
||||
|
|
|
|||
|
|
@ -101,8 +101,8 @@ RectTransform:
|
|||
m_GameObject: {fileID: 6548796882194455502}
|
||||
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_LocalScale: {x: 1.5, y: 1.5, z: 1.2}
|
||||
m_ConstrainProportionsScale: 1
|
||||
m_Children:
|
||||
- {fileID: 8938081173362829900}
|
||||
- {fileID: 3626715591636932856}
|
||||
|
|
@ -127,6 +127,12 @@ MonoBehaviour:
|
|||
m_Script: {fileID: 11500000, guid: 6b363dff4da946008c3bf994802907c3, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
prefabManager: {fileID: 0}
|
||||
itemHandler: {fileID: 0}
|
||||
item: {fileID: 0}
|
||||
nameText: {fileID: 0}
|
||||
itemIcon: {fileID: 0}
|
||||
quantityText: {fileID: 0}
|
||||
--- !u!1 &7835567476815678593
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
|
|
|||
|
|
@ -50,6 +50,8 @@ MonoBehaviour:
|
|||
m_Script: {fileID: 11500000, guid: 0ad9b6cc13ef42e18dc900bb5e92f78e, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
SlotId: 0
|
||||
SlotType: 0
|
||||
--- !u!1 &5710397912220141739
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
|
@ -78,8 +80,8 @@ RectTransform:
|
|||
m_GameObject: {fileID: 5710397912220141739}
|
||||
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_LocalScale: {x: 0.8, y: 0.8, z: 0.8}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 2395631025470230569}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,7 @@
|
|||
namespace Components
|
||||
{
|
||||
public class BoxComponent
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9f2f2de2d65841c18e96d19127d4da02
|
||||
timeCreated: 1719010389
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
// InventoryUI.cs
|
||||
|
||||
public class BoxUIController : MonoBehaviour
|
||||
{
|
||||
public Transform itemParent;
|
||||
public BoxManager boxManager;
|
||||
public PrefabManager prefabManager;
|
||||
|
||||
private readonly Dictionary<int, GameObject> _slots = new();
|
||||
|
||||
private void Start()
|
||||
{
|
||||
Debug.Log("BoxUI Start");
|
||||
if (itemParent == null)
|
||||
{
|
||||
Debug.LogWarning("ItemParent is null! Can not attach");
|
||||
return;
|
||||
}
|
||||
|
||||
boxManager.OnActiveBoxChanged += UpdateUI;
|
||||
|
||||
// Delete existing children if any.
|
||||
foreach (Transform child in itemParent) Destroy(child.gameObject);
|
||||
|
||||
if (boxManager.ActiveBox == null)
|
||||
return;
|
||||
|
||||
if (boxManager.ActiveBox.Slots.Count == 0)
|
||||
boxManager.Initialize();
|
||||
|
||||
UpdateUI(boxManager.ActiveBox);
|
||||
|
||||
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(Box box)
|
||||
{
|
||||
// clear all exisitings slots
|
||||
Debug.Log("Updating UI displaying box: " + box.boxId + " / " + box.name);
|
||||
_slots.Clear();
|
||||
foreach (Transform child in itemParent) Destroy(child.gameObject);
|
||||
|
||||
// Get values from inventory and redraw the inventory slots based on that.
|
||||
var slotPrefab = prefabManager.GetSlotPrefab();
|
||||
// var itemPrefab = prefabManager.GetItemPrefab();
|
||||
|
||||
|
||||
foreach (var slot in box.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 89c6659565db4d76b99029ad30b6322b
|
||||
timeCreated: 1719004513
|
||||
|
|
@ -0,0 +1,162 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
// InventoryManager.cs
|
||||
public class BoxManager : MonoBehaviour, IItemManager<Slot>
|
||||
{
|
||||
public delegate void ActiveBoxChangedHandler(Box box);
|
||||
|
||||
public static BoxManager Instance;
|
||||
|
||||
public readonly Dictionary<int, Box> Boxes = new();
|
||||
public Box ActiveBox { get; set; }
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (Instance == null)
|
||||
{
|
||||
Instance = this;
|
||||
DontDestroyOnLoad(gameObject);
|
||||
}
|
||||
else
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
Debug.Log("InventoryManager Start");
|
||||
Initialize();
|
||||
}
|
||||
|
||||
public void AddItemToSlot(GameItem item, int slotId)
|
||||
{
|
||||
if (ActiveBox.Slots.TryGetValue(slotId, out var slot))
|
||||
slot.item = item;
|
||||
else
|
||||
Debug.LogWarning("Slot not found: " + slotId);
|
||||
}
|
||||
|
||||
public void RemoveSlot(int slotId)
|
||||
{
|
||||
ActiveBox.Slots.Remove(slotId);
|
||||
}
|
||||
|
||||
public GameItem GetItemFromSlot(int slotId)
|
||||
{
|
||||
return ActiveBox.Slots.TryGetValue(slotId, out var slot) ? slot.item : null;
|
||||
}
|
||||
|
||||
public void AddItemToOpenSlot(GameItem item)
|
||||
{
|
||||
foreach (var slot in ActiveBox.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 RemoveItemFromSlot(int slotId)
|
||||
{
|
||||
if (ActiveBox.Slots.TryGetValue(slotId, out var slot))
|
||||
slot.item = null;
|
||||
else
|
||||
Debug.LogWarning("Slot not found: " + slotId);
|
||||
}
|
||||
|
||||
public Slot GetSlot(int slotId)
|
||||
{
|
||||
return ActiveBox.Slots.GetValueOrDefault(slotId, null);
|
||||
}
|
||||
|
||||
public void AddSlot(Slot slot)
|
||||
{
|
||||
ActiveBox.AddSlot(slot);
|
||||
}
|
||||
|
||||
public void SwapItems(int slotId1, int slotId2)
|
||||
{
|
||||
if (ActiveBox.Slots.TryGetValue(slotId1, out var slot1) &&
|
||||
ActiveBox.Slots.TryGetValue(slotId2, out var slot2))
|
||||
(slot1.item, slot2.item) = (slot2.item, slot1.item);
|
||||
}
|
||||
|
||||
public event ActiveBoxChangedHandler OnActiveBoxChanged;
|
||||
|
||||
public void RemoveItemFromSlot(GameItem item)
|
||||
{
|
||||
foreach (var slot in ActiveBox.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 (ActiveBox.Slots.TryGetValue(slotId, out var slot))
|
||||
slot.item = null;
|
||||
else
|
||||
Debug.LogWarning("Slot not found: " + slotId);
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
var testBoxCount = 5;
|
||||
|
||||
for (var i = 0; i < testBoxCount; i++)
|
||||
{
|
||||
var box = ScriptableObject.CreateInstance<Box>();
|
||||
box.boxId = i;
|
||||
Boxes[i] = box;
|
||||
|
||||
// box created
|
||||
Debug.Log("Created box: " + i);
|
||||
|
||||
// add 30 slots to each box
|
||||
for (var j = 0; j < 30; j++)
|
||||
{
|
||||
var slot = ScriptableObject.CreateInstance<Slot>();
|
||||
Debug.LogWarning("Added slots to box: " + j + " / 30 slots added");
|
||||
slot.slotId = j;
|
||||
slot.slotType = Slot.SlotType.Box;
|
||||
slot.item = null;
|
||||
box.AddSlot(slot);
|
||||
}
|
||||
|
||||
|
||||
SetActiveBox(i);
|
||||
// add random inventory to box
|
||||
for (var j = 0; j < 10; j++)
|
||||
{
|
||||
var item = GameItemManager.Instance.gameItems[
|
||||
Random.Range(0, GameItemManager.Instance.gameItems.Count - 1)];
|
||||
|
||||
|
||||
box.AddItemToOpenSlot(item);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Debug.Log("Completed Initialized items in BoxManager");
|
||||
}
|
||||
|
||||
|
||||
public void SetActiveBox(int boxId)
|
||||
{
|
||||
Debug.Log("Active box set to: " + boxId);
|
||||
ActiveBox = Boxes.GetValueOrDefault(boxId);
|
||||
|
||||
// Trigger the event
|
||||
OnActiveBoxChanged?.Invoke(ActiveBox);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0f6eb69f2c964afb864140ddb42c39c6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 288
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -9,6 +9,7 @@ namespace Managers
|
|||
public InventoryManager inventoryManager;
|
||||
public EquipmentManager equipmentManager;
|
||||
public ToolbarManager toolbarManager;
|
||||
public BoxManager boxManager;
|
||||
|
||||
public static PlayerManager Instance { get; private set; }
|
||||
|
||||
|
|
@ -20,6 +21,7 @@ namespace Managers
|
|||
inventoryManager = GameObject.Find("InventoryManager").GetComponent<InventoryManager>();
|
||||
toolbarManager = GameObject.Find("ToolbarManager").GetComponent<ToolbarManager>();
|
||||
equipmentManager = GameObject.Find("EquipmentManager").GetComponent<EquipmentManager>();
|
||||
boxManager = GameObject.Find("BoxManager").GetComponent<BoxManager>();
|
||||
|
||||
DontDestroyOnLoad(gameObject);
|
||||
}
|
||||
|
|
@ -151,6 +153,9 @@ namespace Managers
|
|||
case Slot.SlotType.Equipment:
|
||||
Debug.Log("Getting Equipment Manager");
|
||||
return equipmentManager;
|
||||
case Slot.SlotType.Box:
|
||||
Debug.Log("Getting Box Manager");
|
||||
return boxManager;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,6 +45,16 @@ public class UIManager : MonoBehaviour
|
|||
// Register hotkeys with HotkeyManager
|
||||
HotkeyManager.Instance.RegisterHotkey("Toggle Inventory", KeyCode.I, ToggleInventory);
|
||||
HotkeyManager.Instance.RegisterHotkey("Toggle UI", KeyCode.Home, ToggleUI);
|
||||
HotkeyManager.Instance.RegisterHotkey("Show Hotkey UI", KeyCode.H, ToggleHotkey);
|
||||
HotkeyManager.Instance.RegisterHotkey("Show Character UI", KeyCode.C, () => ShowPanel("character"));
|
||||
// HotkeyManager.Instance.RegisterHotkey("Show Inventory UI", KeyCode.I, () => ShowPanel("inventory"));
|
||||
HotkeyManager.Instance.RegisterHotkey("Show Relationship UI", KeyCode.R, () => ShowPanel("relationship"));
|
||||
HotkeyManager.Instance.RegisterHotkey("Show Settings UI", KeyCode.F1, () => ShowPanel("settings"));
|
||||
|
||||
// close all panels
|
||||
HotkeyManager.Instance.RegisterHotkey("Close All Panels", KeyCode.Escape, CloseAllPanels);
|
||||
|
||||
|
||||
// HotkeyUIManager.Instance.PopulateHotkeyList();
|
||||
}
|
||||
|
||||
|
|
@ -57,6 +67,12 @@ public class UIManager : MonoBehaviour
|
|||
if (ToolbarPanel != null) ToolbarPanel.SetActive(!ToolbarPanel.activeSelf);
|
||||
}
|
||||
|
||||
// close all panels in ManagementPanel
|
||||
public void CloseAllPanels()
|
||||
{
|
||||
if (ManagementPanel != null) ManagementPanel.SetActive(false);
|
||||
}
|
||||
|
||||
public void ToggleInventory()
|
||||
{
|
||||
if (InventoryPanel != null) ShowPanel("inventory");
|
||||
|
|
@ -94,6 +110,8 @@ public class UIManager : MonoBehaviour
|
|||
public void ShowPanel(string panelName)
|
||||
{
|
||||
// Hide all panels first
|
||||
ManagementPanel.SetActive(true);
|
||||
|
||||
if (SettingsPanel != null && panelName != "settings") SettingsPanel.SetActive(false);
|
||||
if (CharacterPanel != null && panelName != "character") CharacterPanel.SetActive(false);
|
||||
if (InventoryPanel != null && panelName != "inventory") InventoryPanel.SetActive(false);
|
||||
|
|
|
|||
Loading…
Reference in New Issue