summaryrefslogtreecommitdiff
path: root/SurvivalTest/Assets/Scripts/UI/Panel/PanelTopStuffBar/UIItemBar.cs
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2022-04-25 10:09:11 +0800
committerchai <chaifix@163.com>2022-04-25 10:09:11 +0800
commit8131033510c711248de1904649cfa1dbe4bbe69f (patch)
tree80e0db1f24c6d624ac412f240f54cc18e626c3d0 /SurvivalTest/Assets/Scripts/UI/Panel/PanelTopStuffBar/UIItemBar.cs
parent71ae3d755a03a706d93291ca57c6de8e6f0d5926 (diff)
*rename item to prop
Diffstat (limited to 'SurvivalTest/Assets/Scripts/UI/Panel/PanelTopStuffBar/UIItemBar.cs')
-rw-r--r--SurvivalTest/Assets/Scripts/UI/Panel/PanelTopStuffBar/UIItemBar.cs97
1 files changed, 0 insertions, 97 deletions
diff --git a/SurvivalTest/Assets/Scripts/UI/Panel/PanelTopStuffBar/UIItemBar.cs b/SurvivalTest/Assets/Scripts/UI/Panel/PanelTopStuffBar/UIItemBar.cs
deleted file mode 100644
index 9025984..0000000
--- a/SurvivalTest/Assets/Scripts/UI/Panel/PanelTopStuffBar/UIItemBar.cs
+++ /dev/null
@@ -1,97 +0,0 @@
-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()
- {
- m_ItemTempalte.gameObject.SetActive(false);
-
- 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;
- }
-
-}