summaryrefslogtreecommitdiff
path: root/SurvivalTest/Assets/Scripts/UI/Panel/PanelTopStuffBar
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2022-04-24 15:59:07 +0800
committerchai <chaifix@163.com>2022-04-24 15:59:07 +0800
commit6158af99ad803d9e29096ee6f65026d5e0db0f1f (patch)
tree7e9a58f33ad255c721f92a84d6ded8847f8c5b8f /SurvivalTest/Assets/Scripts/UI/Panel/PanelTopStuffBar
parent1ab081709bbba66a426371e07efe38bc36072453 (diff)
*misc
Diffstat (limited to 'SurvivalTest/Assets/Scripts/UI/Panel/PanelTopStuffBar')
-rw-r--r--SurvivalTest/Assets/Scripts/UI/Panel/PanelTopStuffBar/PanelTopStuffBar.cs17
-rw-r--r--SurvivalTest/Assets/Scripts/UI/Panel/PanelTopStuffBar/PanelTopStuffBar.cs.meta11
-rw-r--r--SurvivalTest/Assets/Scripts/UI/Panel/PanelTopStuffBar/UIDecorationBar.cs42
-rw-r--r--SurvivalTest/Assets/Scripts/UI/Panel/PanelTopStuffBar/UIDecorationBar.cs.meta11
-rw-r--r--SurvivalTest/Assets/Scripts/UI/Panel/PanelTopStuffBar/UIEquipBar.cs41
-rw-r--r--SurvivalTest/Assets/Scripts/UI/Panel/PanelTopStuffBar/UIEquipBar.cs.meta11
-rw-r--r--SurvivalTest/Assets/Scripts/UI/Panel/PanelTopStuffBar/UIItemBar.cs95
-rw-r--r--SurvivalTest/Assets/Scripts/UI/Panel/PanelTopStuffBar/UIItemBar.cs.meta11
8 files changed, 239 insertions, 0 deletions
diff --git a/SurvivalTest/Assets/Scripts/UI/Panel/PanelTopStuffBar/PanelTopStuffBar.cs b/SurvivalTest/Assets/Scripts/UI/Panel/PanelTopStuffBar/PanelTopStuffBar.cs
new file mode 100644
index 0000000..2d1e02b
--- /dev/null
+++ b/SurvivalTest/Assets/Scripts/UI/Panel/PanelTopStuffBar/PanelTopStuffBar.cs
@@ -0,0 +1,17 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public class PanelTopStuffBar : PanelBase
+{
+ public UIEquipBar m_EquipBar;
+ public UIItemBar m_ItemBar;
+ public UIDecorationBar m_DecorationBar;
+
+ public override void Set(object param)
+ {
+ m_EquipBar.Set();
+ m_ItemBar.Set();
+ m_DecorationBar.Set();
+ }
+} \ No newline at end of file
diff --git a/SurvivalTest/Assets/Scripts/UI/Panel/PanelTopStuffBar/PanelTopStuffBar.cs.meta b/SurvivalTest/Assets/Scripts/UI/Panel/PanelTopStuffBar/PanelTopStuffBar.cs.meta
new file mode 100644
index 0000000..ba0424f
--- /dev/null
+++ b/SurvivalTest/Assets/Scripts/UI/Panel/PanelTopStuffBar/PanelTopStuffBar.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 9c7a0239a22d86847b5806d7e4f2e500
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/SurvivalTest/Assets/Scripts/UI/Panel/PanelTopStuffBar/UIDecorationBar.cs b/SurvivalTest/Assets/Scripts/UI/Panel/PanelTopStuffBar/UIDecorationBar.cs
new file mode 100644
index 0000000..6dce384
--- /dev/null
+++ b/SurvivalTest/Assets/Scripts/UI/Panel/PanelTopStuffBar/UIDecorationBar.cs
@@ -0,0 +1,42 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public class UIDecorationBar : MonoBehaviour
+{
+ public UIDecorationWidget m_DecorationTemplate;
+
+ public UISimpleGrid m_DecorationGrid;
+
+ private List<UIDecorationWidget> m_Decorations = new List<UIDecorationWidget>();
+
+ public void Set()
+ {
+ m_DecorationTemplate.gameObject.SetActive(false);
+
+ for (int i = 0; i < PlayerManager.Instance.decorations.Count; ++i)
+ {
+ UIDecorationWidget widget = MakeDecorationWidget(PlayerManager.Instance.decorations[i]);
+ m_Decorations.Add(widget);
+ }
+ }
+
+ UIDecorationWidget MakeDecorationWidget(DecorationBase decoration)
+ {
+ UIDecorationWidget widget = Instantiate<UIDecorationWidget>(m_DecorationTemplate);
+ widget.transform.SetParent(m_DecorationGrid.transform);
+ widget.gameObject.SetActive(true);
+ widget.GetComponent<RectTransform>().anchoredPosition = new Vector2(0, 0);
+#if UNITY_EDITOR
+ widget.name = "decoration (" + decoration.name + ")";
+#endif
+
+ UIDecorationWidgetParam param = new UIDecorationWidgetParam();
+ param.decoration = decoration;
+ widget.Set(param);
+ return widget;
+ }
+
+
+
+} \ No newline at end of file
diff --git a/SurvivalTest/Assets/Scripts/UI/Panel/PanelTopStuffBar/UIDecorationBar.cs.meta b/SurvivalTest/Assets/Scripts/UI/Panel/PanelTopStuffBar/UIDecorationBar.cs.meta
new file mode 100644
index 0000000..ac771c3
--- /dev/null
+++ b/SurvivalTest/Assets/Scripts/UI/Panel/PanelTopStuffBar/UIDecorationBar.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: d41adc469fe729a488b68790c33b6856
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/SurvivalTest/Assets/Scripts/UI/Panel/PanelTopStuffBar/UIEquipBar.cs b/SurvivalTest/Assets/Scripts/UI/Panel/PanelTopStuffBar/UIEquipBar.cs
new file mode 100644
index 0000000..d658663
--- /dev/null
+++ b/SurvivalTest/Assets/Scripts/UI/Panel/PanelTopStuffBar/UIEquipBar.cs
@@ -0,0 +1,41 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public class UIEquipBar : MonoBehaviour
+{
+ public UIEquipWidget m_EquipTemplate;
+
+ public UISimpleGrid m_EquipGrid;
+
+ private List<UIEquipWidget> m_Equips = new List<UIEquipWidget>();
+
+ public void Set()
+ {
+ m_EquipTemplate.gameObject.SetActive(false);
+
+ for (int i = 0; i < PlayerManager.Instance.equips.Count; ++i)
+ {
+ UIEquipWidget widget = MakeEquipWidget(PlayerManager.Instance.equips[i]);
+ m_Equips.Add(widget);
+ }
+ }
+
+ UIEquipWidget MakeEquipWidget(EquipBase equip)
+ {
+ UIEquipWidget widget = Instantiate<UIEquipWidget>(m_EquipTemplate);
+ widget.transform.SetParent(m_EquipGrid.transform);
+ widget.gameObject.SetActive(true);
+ widget.GetComponent<RectTransform>().anchoredPosition = new Vector2(0, 0);
+#if UNITY_EDITOR
+ widget.name = "equip (" + equip.name + ")";
+#endif
+
+ UIEquipWidgetParam param = new UIEquipWidgetParam();
+ param.equip = equip;
+ widget.Set(param);
+ return widget;
+ }
+
+
+}
diff --git a/SurvivalTest/Assets/Scripts/UI/Panel/PanelTopStuffBar/UIEquipBar.cs.meta b/SurvivalTest/Assets/Scripts/UI/Panel/PanelTopStuffBar/UIEquipBar.cs.meta
new file mode 100644
index 0000000..68bf843
--- /dev/null
+++ b/SurvivalTest/Assets/Scripts/UI/Panel/PanelTopStuffBar/UIEquipBar.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 3eefcc4321abff24e88f7cbb843e3fda
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/SurvivalTest/Assets/Scripts/UI/Panel/PanelTopStuffBar/UIItemBar.cs b/SurvivalTest/Assets/Scripts/UI/Panel/PanelTopStuffBar/UIItemBar.cs
new file mode 100644
index 0000000..ecb6ea1
--- /dev/null
+++ b/SurvivalTest/Assets/Scripts/UI/Panel/PanelTopStuffBar/UIItemBar.cs
@@ -0,0 +1,95 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+using UnityEngine.UI;
+
+public class UIItemBar : MonoBehaviour
+{
+ public ItemWidget m_ItemTempalte;
+
+ public UISimpleGrid m_ItemGrid;
+
+ public Text m_TextName;
+
+ private List<ItemWidget> m_Items = new List<ItemWidget>();
+
+ private int m_CurrentIndex = 0;
+
+ public void Set()
+ {
+ for (int i = 0; i < PlayerManager.Instance.items.Count; ++i)
+ {
+ ItemWidget widget = MakeItemWidget(PlayerManager.Instance.items[i]);
+ m_Items.Add(widget);
+ }
+
+ SelectItemWidget(0);
+ }
+
+ bool SwitchToLeft()
+ {
+ return Input.GetButtonDown("LeftItem");
+ }
+
+ bool SwitchToRight()
+ {
+ return Input.GetButtonDown("RightItem");
+ }
+
+ bool UseItem()
+ {
+ return Input.GetButtonDown("Fire3");
+ }
+
+ ItemWidget MakeItemWidget(ItemBase item)
+ {
+ ItemWidget widget = Instantiate<ItemWidget>(m_ItemTempalte);
+ widget.transform.SetParent(m_ItemGrid.transform);
+ widget.gameObject.SetActive(true);
+ widget.GetComponent<RectTransform>().anchoredPosition = new Vector2(0, 0);
+#if UNITY_EDITOR
+ widget.name = "item (" + item.name + ")";
+#endif
+
+ ItemWidgetParam param = new ItemWidgetParam();
+ //param.onSelected = OnSelectItemWidget;
+ param.item = item;
+ widget.Set(param);
+ return widget;
+ }
+
+ protected void Update()
+ {
+ if (SwitchToLeft())
+ {
+ int newIndex = Mathf.Clamp(m_CurrentIndex - 1, 0, m_Items.Count - 1);
+ SelectItemWidget(newIndex);
+ }
+ if (SwitchToRight())
+ {
+ int newIndex = Mathf.Clamp(m_CurrentIndex + 1, 0, m_Items.Count - 1);
+ SelectItemWidget(newIndex);
+ }
+ if (UseItem())
+ {
+ m_Items[m_CurrentIndex].OnUseCallback();
+ PlayerManager.Instance.UseItem(m_Items[m_CurrentIndex].item);
+ }
+ }
+
+ void SelectItemWidget(int index)
+ {
+ if (index < 0 || index > m_Items.Count - 1)
+ {
+ return;
+ }
+ m_Items[m_CurrentIndex].OnDeselectCallback();
+ m_Items[index].OnSelectCallback();
+
+ m_TextName.text = m_Items[index].item.name;
+ m_TextName.gameObject.SetActive(false);
+
+ m_CurrentIndex = index;
+ }
+
+}
diff --git a/SurvivalTest/Assets/Scripts/UI/Panel/PanelTopStuffBar/UIItemBar.cs.meta b/SurvivalTest/Assets/Scripts/UI/Panel/PanelTopStuffBar/UIItemBar.cs.meta
new file mode 100644
index 0000000..0e07369
--- /dev/null
+++ b/SurvivalTest/Assets/Scripts/UI/Panel/PanelTopStuffBar/UIItemBar.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: b480696215d6c2a4b8d69edc2946cf3d
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant: