mirror of
https://github.com/DerTyp7/harvestdale-unity.git
synced 2025-10-29 04:42:08 +01:00
GuiManager
This commit is contained in:
@@ -56726,6 +56726,7 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: 9269c8c372de3f5498d2af345ee9c855, type: 3}
|
m_Script: {fileID: 11500000, guid: 9269c8c372de3f5498d2af345ee9c855, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
|
panelName: Inventory
|
||||||
slotPrefab: {fileID: 9079120991637034566, guid: 9fb7f575f90d73343b4841c421d17567, type: 3}
|
slotPrefab: {fileID: 9079120991637034566, guid: 9fb7f575f90d73343b4841c421d17567, type: 3}
|
||||||
slotListObj: {fileID: 1707136373}
|
slotListObj: {fileID: 1707136373}
|
||||||
slotUIList: []
|
slotUIList: []
|
||||||
@@ -57525,8 +57526,9 @@ GameObject:
|
|||||||
- component: {fileID: 2143575112}
|
- component: {fileID: 2143575112}
|
||||||
- component: {fileID: 2143575111}
|
- component: {fileID: 2143575111}
|
||||||
- component: {fileID: 2143575110}
|
- component: {fileID: 2143575110}
|
||||||
|
- component: {fileID: 2143575114}
|
||||||
m_Layer: 5
|
m_Layer: 5
|
||||||
m_Name: Canvas
|
m_Name: GUI
|
||||||
m_TagString: Untagged
|
m_TagString: Untagged
|
||||||
m_Icon: {fileID: 0}
|
m_Icon: {fileID: 0}
|
||||||
m_NavMeshLayer: 0
|
m_NavMeshLayer: 0
|
||||||
@@ -57615,3 +57617,15 @@ RectTransform:
|
|||||||
m_AnchoredPosition: {x: 0, y: 0}
|
m_AnchoredPosition: {x: 0, y: 0}
|
||||||
m_SizeDelta: {x: 0, y: 0}
|
m_SizeDelta: {x: 0, y: 0}
|
||||||
m_Pivot: {x: 0, y: 0}
|
m_Pivot: {x: 0, y: 0}
|
||||||
|
--- !u!114 &2143575114
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 2143575109}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: 2ccedadcedce99843833ee718fc06377, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
|||||||
@@ -35,6 +35,11 @@ public class PlayerController : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Input.GetKeyDown(KeyCode.Tab))
|
||||||
|
{
|
||||||
|
GuiManager.Instance.TogglePanel("Inventory");
|
||||||
|
}
|
||||||
|
|
||||||
//! DEBUG
|
//! DEBUG
|
||||||
if (Input.GetKeyDown(KeyCode.U))
|
if (Input.GetKeyDown(KeyCode.U))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,8 +2,6 @@ using UnityEngine;
|
|||||||
using UnityEngine.EventSystems;
|
using UnityEngine.EventSystems;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class DraggableSlotContentUI : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler
|
public class DraggableSlotContentUI : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler
|
||||||
{
|
{
|
||||||
public int slotIndex; // slotIndex is set by SlotUI
|
public int slotIndex; // slotIndex is set by SlotUI
|
||||||
|
|||||||
140
Assets/Scripts/UI/GuiManager.cs
Normal file
140
Assets/Scripts/UI/GuiManager.cs
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class GuiManager : MonoBehaviour
|
||||||
|
{
|
||||||
|
|
||||||
|
private static GuiManager instance;
|
||||||
|
|
||||||
|
public static GuiManager Instance
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (instance == null)
|
||||||
|
{
|
||||||
|
instance = FindObjectOfType<GuiManager>();
|
||||||
|
if (instance == null)
|
||||||
|
{
|
||||||
|
Debug.LogError("No GuiManager found in the scene.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[SerializeField] private List<GuiPanel> panels = new List<GuiPanel>();
|
||||||
|
|
||||||
|
private void Awake()
|
||||||
|
{
|
||||||
|
if (instance == null)
|
||||||
|
{
|
||||||
|
instance = this;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Destroy(gameObject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void RegisterPanel(GuiPanel panel)
|
||||||
|
{
|
||||||
|
panel.gameObject.SetActive(false);
|
||||||
|
panels.Add(panel);
|
||||||
|
}
|
||||||
|
|
||||||
|
public GuiPanel GetPanelByName(string name)
|
||||||
|
{
|
||||||
|
name = name.ToLower();
|
||||||
|
foreach (GuiPanel panel in panels)
|
||||||
|
{
|
||||||
|
if (panel.GetName().ToLower() == name)
|
||||||
|
{
|
||||||
|
return panel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OpenPanel(string name)
|
||||||
|
{
|
||||||
|
GuiPanel panel = GetPanelByName(name);
|
||||||
|
if (panel != null)
|
||||||
|
{
|
||||||
|
OpenPanel(panel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OpenPanel(GuiPanel panel)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (!panel.gameObject.activeSelf)
|
||||||
|
{
|
||||||
|
panel.gameObject.SetActive(true);
|
||||||
|
panel.OnClose();
|
||||||
|
Debug.Log("Open Panel");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Debug.Log("Panel is already opened");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void ClosePanel(string name)
|
||||||
|
{
|
||||||
|
GuiPanel panel = GetPanelByName(name);
|
||||||
|
if (panel != null)
|
||||||
|
{
|
||||||
|
ClosePanel(panel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ClosePanel(GuiPanel panel)
|
||||||
|
{
|
||||||
|
if (panel.gameObject.activeSelf)
|
||||||
|
{
|
||||||
|
panel.gameObject.SetActive(false);
|
||||||
|
panel.OnClose();
|
||||||
|
Debug.Log("Closed Panel");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Debug.Log("Panel is already closed");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void CloseAllPanels()
|
||||||
|
{
|
||||||
|
foreach (GuiPanel panel in panels)
|
||||||
|
{
|
||||||
|
if (panel.gameObject.activeSelf)
|
||||||
|
{
|
||||||
|
ClosePanel(panel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void TogglePanel(string name)
|
||||||
|
{
|
||||||
|
GuiPanel panel = GetPanelByName(name);
|
||||||
|
if (panel != null)
|
||||||
|
{
|
||||||
|
TogglePanel(panel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void TogglePanel(GuiPanel panel)
|
||||||
|
{
|
||||||
|
if (panel != null)
|
||||||
|
{
|
||||||
|
if (panel.gameObject.activeSelf)
|
||||||
|
{
|
||||||
|
ClosePanel(panel);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
OpenPanel(panel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Assets/Scripts/UI/GuiManager.cs.meta
Normal file
11
Assets/Scripts/UI/GuiManager.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 2ccedadcedce99843833ee718fc06377
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
22
Assets/Scripts/UI/GuiPanel.cs
Normal file
22
Assets/Scripts/UI/GuiPanel.cs
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public abstract class GuiPanel : MonoBehaviour
|
||||||
|
{
|
||||||
|
[SerializeField] private string panelName;
|
||||||
|
|
||||||
|
public string GetName()
|
||||||
|
{
|
||||||
|
return panelName;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Awake()
|
||||||
|
{
|
||||||
|
GuiManager.Instance.RegisterPanel(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void OnOpen();
|
||||||
|
public abstract void OnClose();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
11
Assets/Scripts/UI/GuiPanel.cs.meta
Normal file
11
Assets/Scripts/UI/GuiPanel.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 65c73c21bddab2d45b5b2f5a01bc9056
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -2,7 +2,7 @@ using System.Collections;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
public class InventoryUI : MonoBehaviour
|
public class InventoryUI : GuiPanel
|
||||||
{
|
{
|
||||||
[SerializeField] private GameObject slotPrefab;
|
[SerializeField] private GameObject slotPrefab;
|
||||||
[SerializeField] private GameObject slotListObj;
|
[SerializeField] private GameObject slotListObj;
|
||||||
@@ -15,10 +15,16 @@ public class InventoryUI : MonoBehaviour
|
|||||||
playerInventory = GameObject.FindGameObjectWithTag("Player").GetComponent<Inventory>();
|
playerInventory = GameObject.FindGameObjectWithTag("Player").GetComponent<Inventory>();
|
||||||
Inventory.OnPlayerInventoryChanged += UpdateSlots;
|
Inventory.OnPlayerInventoryChanged += UpdateSlots;
|
||||||
CreateSlots();
|
CreateSlots();
|
||||||
|
}
|
||||||
|
public override void OnOpen()
|
||||||
|
{
|
||||||
UpdateSlots();
|
UpdateSlots();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void OnClose()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
private void CreateSlots()
|
private void CreateSlots()
|
||||||
{
|
{
|
||||||
playerInventory = GameObject.FindGameObjectWithTag("Player").GetComponent<Inventory>();
|
playerInventory = GameObject.FindGameObjectWithTag("Player").GetComponent<Inventory>();
|
||||||
|
|||||||
Reference in New Issue
Block a user