diff options
41 files changed, 308 insertions, 292 deletions
diff --git a/SurvivalTest/Assets/Resources/Art/ui/common/select_item_bg.png b/SurvivalTest/Assets/Resources/Art/ui/common/select_prop_bg.png Binary files differindex 7668f87..7668f87 100644 --- a/SurvivalTest/Assets/Resources/Art/ui/common/select_item_bg.png +++ b/SurvivalTest/Assets/Resources/Art/ui/common/select_prop_bg.png diff --git a/SurvivalTest/Assets/Resources/Art/ui/common/select_item_bg.png.meta b/SurvivalTest/Assets/Resources/Art/ui/common/select_prop_bg.png.meta index b17ce05..e84aaf7 100644 --- a/SurvivalTest/Assets/Resources/Art/ui/common/select_item_bg.png.meta +++ b/SurvivalTest/Assets/Resources/Art/ui/common/select_prop_bg.png.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 899f0bb9c626be04390cd94aecead58b +guid: 8630c8ae104e08c428e33792d22ac023 TextureImporter: internalIDToNameTable: [] externalObjects: {} diff --git a/SurvivalTest/Assets/Resources/Art/ui/propicon.meta b/SurvivalTest/Assets/Resources/Art/ui/propicon.meta new file mode 100644 index 0000000..b7cb295 --- /dev/null +++ b/SurvivalTest/Assets/Resources/Art/ui/propicon.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: f73132da31336fe49b91b42adb23933e +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Resources/Art/ui/itemicon/nuclear_bomb.png b/SurvivalTest/Assets/Resources/Art/ui/propicon/nuclear_bomb.png Binary files differindex 68fa345..68fa345 100644 --- a/SurvivalTest/Assets/Resources/Art/ui/itemicon/nuclear_bomb.png +++ b/SurvivalTest/Assets/Resources/Art/ui/propicon/nuclear_bomb.png diff --git a/SurvivalTest/Assets/Resources/Art/ui/itemicon/nuclear_bomb.png.meta b/SurvivalTest/Assets/Resources/Art/ui/propicon/nuclear_bomb.png.meta index 53f3b74..53f3b74 100644 --- a/SurvivalTest/Assets/Resources/Art/ui/itemicon/nuclear_bomb.png.meta +++ b/SurvivalTest/Assets/Resources/Art/ui/propicon/nuclear_bomb.png.meta diff --git a/SurvivalTest/Assets/Resources/Art/ui/itemicon/plane.png b/SurvivalTest/Assets/Resources/Art/ui/propicon/plane.png Binary files differindex c558407..c558407 100644 --- a/SurvivalTest/Assets/Resources/Art/ui/itemicon/plane.png +++ b/SurvivalTest/Assets/Resources/Art/ui/propicon/plane.png diff --git a/SurvivalTest/Assets/Resources/Art/ui/itemicon/plane.png.meta b/SurvivalTest/Assets/Resources/Art/ui/propicon/plane.png.meta index 740a92d..740a92d 100644 --- a/SurvivalTest/Assets/Resources/Art/ui/itemicon/plane.png.meta +++ b/SurvivalTest/Assets/Resources/Art/ui/propicon/plane.png.meta diff --git a/SurvivalTest/Assets/Resources/Art/ui/itemicon/space_beamer.png b/SurvivalTest/Assets/Resources/Art/ui/propicon/space_beamer.png Binary files differindex 2b61d5b..2b61d5b 100644 --- a/SurvivalTest/Assets/Resources/Art/ui/itemicon/space_beamer.png +++ b/SurvivalTest/Assets/Resources/Art/ui/propicon/space_beamer.png diff --git a/SurvivalTest/Assets/Resources/Art/ui/itemicon/space_beamer.png.meta b/SurvivalTest/Assets/Resources/Art/ui/propicon/space_beamer.png.meta index c5581ad..c5581ad 100644 --- a/SurvivalTest/Assets/Resources/Art/ui/itemicon/space_beamer.png.meta +++ b/SurvivalTest/Assets/Resources/Art/ui/propicon/space_beamer.png.meta diff --git a/SurvivalTest/Assets/Resources/Prefabs/ui/PanelTopSuffBar.prefab b/SurvivalTest/Assets/Resources/Prefabs/ui/PanelTopSuffBar.prefab index 65d34ed..18acb13 100644 --- a/SurvivalTest/Assets/Resources/Prefabs/ui/PanelTopSuffBar.prefab +++ b/SurvivalTest/Assets/Resources/Prefabs/ui/PanelTopSuffBar.prefab @@ -129,9 +129,9 @@ GameObject: serializedVersion: 6 m_Component: - component: {fileID: 184174568} - - component: {fileID: 184174569} + - component: {fileID: 696148772594564393} m_Layer: 5 - m_Name: ItemTemplate + m_Name: PropTemplate m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -159,7 +159,7 @@ RectTransform: m_AnchoredPosition: {x: 0, y: 0} m_SizeDelta: {x: 40, y: 40} m_Pivot: {x: 1, y: 1} ---- !u!114 &184174569 +--- !u!114 &696148772594564393 MonoBehaviour: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} @@ -168,7 +168,7 @@ MonoBehaviour: m_GameObject: {fileID: 184174567} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 677576640bb11e34e961b72e3c139f6a, type: 3} + m_Script: {fileID: 11500000, guid: 4ccf65ebe78138644a8bc5283d21ae1a, type: 3} m_Name: m_EditorClassIdentifier: Image_Icon: {fileID: 81451859} @@ -387,7 +387,7 @@ MonoBehaviour: m_OnCullStateChanged: m_PersistentCalls: m_Calls: [] - m_Sprite: {fileID: 21300000, guid: 899f0bb9c626be04390cd94aecead58b, type: 3} + m_Sprite: {fileID: 21300000, guid: 8630c8ae104e08c428e33792d22ac023, type: 3} m_Type: 0 m_PreserveAspect: 0 m_FillCenter: 1 @@ -981,7 +981,7 @@ GameObject: - component: {fileID: 1986034769} - component: {fileID: 1336027010569382835} m_Layer: 5 - m_Name: Root_Item + m_Name: Root_Prop m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -1021,8 +1021,8 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: b480696215d6c2a4b8d69edc2946cf3d, type: 3} m_Name: m_EditorClassIdentifier: - m_ItemTempalte: {fileID: 184174569} - m_ItemGrid: {fileID: 710832701} + m_PropTempalte: {fileID: 696148772594564393} + m_PropGrid: {fileID: 710832701} m_TextName: {fileID: 1482618826} --- !u!1 &1996007142 GameObject: @@ -1538,5 +1538,5 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: m_WeaponBar: {fileID: 696148772594564389} - m_ItemBar: {fileID: 1336027010569382835} + m_PropBar: {fileID: 1336027010569382835} m_DecorationBar: {fileID: 1323087931109695763} diff --git a/SurvivalTest/Assets/Scripts/Managers/BattleManager.cs b/SurvivalTest/Assets/Scripts/Managers/BattleManager.cs index c473a5d..399ea18 100644 --- a/SurvivalTest/Assets/Scripts/Managers/BattleManager.cs +++ b/SurvivalTest/Assets/Scripts/Managers/BattleManager.cs @@ -9,7 +9,7 @@ public class BattleManager : Singleton<BattleManager> { UIManager.Instance.OpenPanel(PanelType.PanelTopSuffBar, null); //UIManager.Instance.OpenPanel(PanelType.PanelBossHpBar, null); - //UIManager.Instance.OpenPanel(PanelType.PanelItemBar, null); + //UIManager.Instance.OpenPanel(PanelType.PanelPropBar, null); //UIManager.Instance.OpenPanel(PanelType.PanelWeaponBar, null); } diff --git a/SurvivalTest/Assets/Scripts/Managers/PlayerManager.cs b/SurvivalTest/Assets/Scripts/Managers/PlayerManager.cs index bae437e..ce27739 100644 --- a/SurvivalTest/Assets/Scripts/Managers/PlayerManager.cs +++ b/SurvivalTest/Assets/Scripts/Managers/PlayerManager.cs @@ -10,7 +10,7 @@ public partial class PlayerManager : Singleton<PlayerManager> public void Init() { - InitItems(); + InitProps(); InitWeapons(); InitDecorations(); } @@ -19,7 +19,7 @@ public partial class PlayerManager : Singleton<PlayerManager> { CheckInput(); - UpdateItems(); + UpdateProps(); UpdateWeapons(); UpdateDecorations(); } diff --git a/SurvivalTest/Assets/Scripts/Managers/PlayerManager_Items.cs b/SurvivalTest/Assets/Scripts/Managers/PlayerManager_Items.cs deleted file mode 100644 index a22947a..0000000 --- a/SurvivalTest/Assets/Scripts/Managers/PlayerManager_Items.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public partial class PlayerManager : Singleton<PlayerManager> -{ - // 持有的物品 - public List<ItemBase> items { get { return m_Items; } } - private List<ItemBase> m_Items = new List<ItemBase>(); - - void InitItems() - { - m_Items.Add(new Item_B2Phone()); - m_Items.Add(new Item_SpaceBeamer()); - m_Items.Add(new Item_NuclearBomb()); - } - - public void UseItem(ItemBase item) - { - if(!items.Contains(item)) - { - Debug.LogError("No such item, name=" + item.name); - return; - } - item.OnUse(m_Crew.gameObject); - } - - void UpdateItems() - { - for(int i = 0; i < items.Count; ++i) - { - items[i].Update(); - } - } -}
\ No newline at end of file diff --git a/SurvivalTest/Assets/Scripts/Managers/PlayerManager_Items.cs.meta b/SurvivalTest/Assets/Scripts/Managers/PlayerManager_Items.cs.meta deleted file mode 100644 index c0307e5..0000000 --- a/SurvivalTest/Assets/Scripts/Managers/PlayerManager_Items.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 2b31f1faa8e2c6a4085213ca15e56220 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Managers/PlayerManager_Props.cs b/SurvivalTest/Assets/Scripts/Managers/PlayerManager_Props.cs new file mode 100644 index 0000000..59801f7 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Managers/PlayerManager_Props.cs @@ -0,0 +1,35 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public partial class PlayerManager : Singleton<PlayerManager> +{ + // 持有的物品 + public List<PropBase> props { get { return m_Props; } } + private List<PropBase> m_Props = new List<PropBase>(); + + void InitProps() + { + m_Props.Add(new Prop_B2Phone()); + m_Props.Add(new Prop_SpaceBeamer()); + m_Props.Add(new Prop_NuclearBomb()); + } + + public void UseProp(PropBase prop) + { + if(!props.Contains(prop)) + { + Debug.LogError("No such prop, name=" + prop.name); + return; + } + prop.OnUse(m_Crew.gameObject); + } + + void UpdateProps() + { + for(int i = 0; i < props.Count; ++i) + { + props[i].Update(); + } + } +}
\ No newline at end of file diff --git a/SurvivalTest/Assets/Scripts/Items/ItemBase.cs.meta b/SurvivalTest/Assets/Scripts/Managers/PlayerManager_Props.cs.meta index 97b7e17..7588f45 100644 --- a/SurvivalTest/Assets/Scripts/Items/ItemBase.cs.meta +++ b/SurvivalTest/Assets/Scripts/Managers/PlayerManager_Props.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: a1be6fd9c07374849acc8fe23dd6a6d0 +guid: 704fc6666fbbf0146be9db79e42d7601 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/SurvivalTest/Assets/Scripts/Props.meta b/SurvivalTest/Assets/Scripts/Props.meta new file mode 100644 index 0000000..5a2e05a --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Props.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 2bbb6fa5760fbef4284bb97f88132a7f +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Items/ItemBase.cs b/SurvivalTest/Assets/Scripts/Props/PropBase.cs index a19ebcf..3976a3c 100644 --- a/SurvivalTest/Assets/Scripts/Items/ItemBase.cs +++ b/SurvivalTest/Assets/Scripts/Props/PropBase.cs @@ -5,7 +5,7 @@ using UnityEngine; /// <summary> /// 物品 /// </summary> -public abstract class ItemBase +public abstract class PropBase { public abstract string name { get; } diff --git a/SurvivalTest/Assets/Scripts/Items/Item_B2Phone.cs.meta b/SurvivalTest/Assets/Scripts/Props/PropBase.cs.meta index 224b947..524ed68 100644 --- a/SurvivalTest/Assets/Scripts/Items/Item_B2Phone.cs.meta +++ b/SurvivalTest/Assets/Scripts/Props/PropBase.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 8c784b1bd77f0eb4384b262c56b0d2bb +guid: 2699d737bf98397438346e5642d38a2d MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/SurvivalTest/Assets/Scripts/Items/Item_B2Phone.cs b/SurvivalTest/Assets/Scripts/Props/Prop_B2Phone.cs index a7aff51..40d2f87 100644 --- a/SurvivalTest/Assets/Scripts/Items/Item_B2Phone.cs +++ b/SurvivalTest/Assets/Scripts/Props/Prop_B2Phone.cs @@ -5,11 +5,11 @@ using UnityEngine; /// <summary> /// B2呼叫机 /// </summary> -public class Item_B2Phone : ItemBase +public class Prop_B2Phone : PropBase { public override string name => "B2"; - public override string iconPath => "art/ui/itemicon/plane"; + public override string iconPath => "art/ui/propicon/plane"; string prefabPath = "prefabs/weapon/b2"; diff --git a/SurvivalTest/Assets/Scripts/Items/Item_NuclearBomb.cs.meta b/SurvivalTest/Assets/Scripts/Props/Prop_B2Phone.cs.meta index 3428826..f9e8411 100644 --- a/SurvivalTest/Assets/Scripts/Items/Item_NuclearBomb.cs.meta +++ b/SurvivalTest/Assets/Scripts/Props/Prop_B2Phone.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 529a65114183a5c479ca08229cb6e458 +guid: ecd5acd5480dcc841819ef81be7f8a09 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/SurvivalTest/Assets/Scripts/Items/Item_NuclearBomb.cs b/SurvivalTest/Assets/Scripts/Props/Prop_NuclearBomb.cs index eb483e2..576e24e 100644 --- a/SurvivalTest/Assets/Scripts/Items/Item_NuclearBomb.cs +++ b/SurvivalTest/Assets/Scripts/Props/Prop_NuclearBomb.cs @@ -2,11 +2,11 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; -public class Item_NuclearBomb : ItemBase +public class Prop_NuclearBomb : PropBase { public override string name => "核弹密码箱"; - public override string iconPath => "art/ui/itemicon/nuclear_bomb"; + public override string iconPath => "art/ui/propicon/nuclear_bomb"; public override void OnUse(GameObject owner) { diff --git a/SurvivalTest/Assets/Scripts/Items/Item_SpaceBeamer.cs.meta b/SurvivalTest/Assets/Scripts/Props/Prop_NuclearBomb.cs.meta index 2a064aa..2084041 100644 --- a/SurvivalTest/Assets/Scripts/Items/Item_SpaceBeamer.cs.meta +++ b/SurvivalTest/Assets/Scripts/Props/Prop_NuclearBomb.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 3ce271fd294dfa141b3467d795a524b0 +guid: 849a1a076e0ee154884d0ef95cb784cf MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/SurvivalTest/Assets/Scripts/Items/Item_SpaceBeamer.cs b/SurvivalTest/Assets/Scripts/Props/Prop_SpaceBeamer.cs index db76bb8..e191d41 100644 --- a/SurvivalTest/Assets/Scripts/Items/Item_SpaceBeamer.cs +++ b/SurvivalTest/Assets/Scripts/Props/Prop_SpaceBeamer.cs @@ -2,11 +2,11 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; -public class Item_SpaceBeamer : ItemBase +public class Prop_SpaceBeamer : PropBase { public override string name => "卫星射线"; - public override string iconPath => "art/ui/itemicon/space_beamer"; + public override string iconPath => "art/ui/propicon/space_beamer"; string prefabPath = "prefabs/weapon/space_beam"; diff --git a/SurvivalTest/Assets/Scripts/Props/Prop_SpaceBeamer.cs.meta b/SurvivalTest/Assets/Scripts/Props/Prop_SpaceBeamer.cs.meta new file mode 100644 index 0000000..925d582 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Props/Prop_SpaceBeamer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 33aa5992bcf34864fb2fa6254c0da57c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/UI/Common/UIGridItemBase.cs b/SurvivalTest/Assets/Scripts/UI/Common/UIGridItemBase.cs index 8e5ff24..d593a39 100644 --- a/SurvivalTest/Assets/Scripts/UI/Common/UIGridItemBase.cs +++ b/SurvivalTest/Assets/Scripts/UI/Common/UIGridItemBase.cs @@ -2,7 +2,7 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; -public abstract class UIGridItemBase : MonoBehaviour +public abstract class UIGridPropBase : MonoBehaviour { public abstract void Set(object param); diff --git a/SurvivalTest/Assets/Scripts/UI/Panel/PanelDecorationBar/UIDecorationWidget.cs b/SurvivalTest/Assets/Scripts/UI/Panel/PanelDecorationBar/UIDecorationWidget.cs index 57a4071..c9d9312 100644 --- a/SurvivalTest/Assets/Scripts/UI/Panel/PanelDecorationBar/UIDecorationWidget.cs +++ b/SurvivalTest/Assets/Scripts/UI/Panel/PanelDecorationBar/UIDecorationWidget.cs @@ -8,7 +8,7 @@ public struct UIDecorationWidgetParam public DecorationBase decoration; } -public class UIDecorationWidget : UIGridItemBase +public class UIDecorationWidget : UIGridPropBase { public Image Image_Icon; diff --git a/SurvivalTest/Assets/Scripts/UI/Panel/PanelItemBar/ItemWidget.cs.meta b/SurvivalTest/Assets/Scripts/UI/Panel/PanelItemBar/ItemWidget.cs.meta deleted file mode 100644 index 29d8747..0000000 --- a/SurvivalTest/Assets/Scripts/UI/Panel/PanelItemBar/ItemWidget.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 677576640bb11e34e961b72e3c139f6a -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/UI/Panel/PanelItemBar/PanelItemBar.cs b/SurvivalTest/Assets/Scripts/UI/Panel/PanelItemBar/PanelItemBar.cs deleted file mode 100644 index 9ca1220..0000000 --- a/SurvivalTest/Assets/Scripts/UI/Panel/PanelItemBar/PanelItemBar.cs +++ /dev/null @@ -1,95 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; -using UnityEngine.UI; - -public class PanelItemBar : PanelBase -{ - 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 override void Set(object param) - { - 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 override 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/PanelItemBar.meta b/SurvivalTest/Assets/Scripts/UI/Panel/PanelPropBar.meta index 4d64c73..4d64c73 100644 --- a/SurvivalTest/Assets/Scripts/UI/Panel/PanelItemBar.meta +++ b/SurvivalTest/Assets/Scripts/UI/Panel/PanelPropBar.meta diff --git a/SurvivalTest/Assets/Scripts/UI/Panel/PanelPropBar/PanelPropBar.cs b/SurvivalTest/Assets/Scripts/UI/Panel/PanelPropBar/PanelPropBar.cs new file mode 100644 index 0000000..99a2c58 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/UI/Panel/PanelPropBar/PanelPropBar.cs @@ -0,0 +1,95 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UI; + +public class PanelPropBar : PanelBase +{ + public PropWidget m_PropTempalte; + + public UISimpleGrid m_PropGrid; + + public Text m_TextName; + + private List<PropWidget> m_Props = new List<PropWidget>(); + + private int m_CurrentIndex = 0; + + public override void Set(object param) + { + for(int i = 0; i < PlayerManager.Instance.props.Count; ++i) + { + PropWidget widget = MakePropWidget(PlayerManager.Instance.props[i]); + m_Props.Add(widget); + } + + SelectPropWidget(0); + } + + bool SwitchToLeft() + { + return Input.GetButtonDown("LeftProp"); + } + + bool SwitchToRight() + { + return Input.GetButtonDown("RightProp"); + } + + bool UseProp() + { + return Input.GetButtonDown("Fire3"); + } + + PropWidget MakePropWidget(PropBase prop) + { + PropWidget widget = Instantiate<PropWidget>(m_PropTempalte); + widget.transform.SetParent(m_PropGrid.transform); + widget.gameObject.SetActive(true); + widget.GetComponent<RectTransform>().anchoredPosition = new Vector2(0, 0); +#if UNITY_EDITOR + widget.name = "prop (" + prop.name + ")"; +#endif + + PropWidgetParam param = new PropWidgetParam(); + //param.onSelected = OnSelectPropWidget; + param.prop = prop; + widget.Set(param); + return widget; + } + + protected override void Update() + { + if (SwitchToLeft()) + { + int newIndex = Mathf.Clamp(m_CurrentIndex - 1, 0, m_Props.Count - 1); + SelectPropWidget(newIndex); + } + if (SwitchToRight()) + { + int newIndex = Mathf.Clamp(m_CurrentIndex + 1, 0, m_Props.Count - 1); + SelectPropWidget(newIndex); + } + if (UseProp()) + { + m_Props[m_CurrentIndex].OnUseCallback(); + PlayerManager.Instance.UseProp(m_Props[m_CurrentIndex].prop); + } + } + + void SelectPropWidget(int index) + { + if(index < 0 || index > m_Props.Count - 1) + { + return ; + } + m_Props[m_CurrentIndex].OnDeselectCallback(); + m_Props[index].OnSelectCallback(); + + m_TextName.text = m_Props[index].prop.name; + m_TextName.gameObject.SetActive(false); + + m_CurrentIndex = index; + } + +} diff --git a/SurvivalTest/Assets/Scripts/UI/Panel/PanelItemBar/PanelItemBar.cs.meta b/SurvivalTest/Assets/Scripts/UI/Panel/PanelPropBar/PanelPropBar.cs.meta index 3925db5..3925db5 100644 --- a/SurvivalTest/Assets/Scripts/UI/Panel/PanelItemBar/PanelItemBar.cs.meta +++ b/SurvivalTest/Assets/Scripts/UI/Panel/PanelPropBar/PanelPropBar.cs.meta diff --git a/SurvivalTest/Assets/Scripts/UI/Panel/PanelItemBar/ItemWidget.cs b/SurvivalTest/Assets/Scripts/UI/Panel/PanelPropBar/PropWidget.cs index 3227bd8..863e89e 100644 --- a/SurvivalTest/Assets/Scripts/UI/Panel/PanelItemBar/ItemWidget.cs +++ b/SurvivalTest/Assets/Scripts/UI/Panel/PanelPropBar/PropWidget.cs @@ -3,24 +3,24 @@ using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; -public struct ItemWidgetParam +public struct PropWidgetParam { // 主动点击 - public System.Action<ItemWidget> onSelected; - public ItemBase item; + public System.Action<PropWidget> onSelected; + public PropBase prop; } -public class ItemWidget : UIGridItemBase +public class PropWidget : UIGridPropBase { public Image Image_Icon; public Image Image_SelectBg; public Image Image_Use; - private System.Action<ItemWidget> onSelected; + private System.Action<PropWidget> onSelected; - public ItemBase item { get { return m_Item; } } - private ItemBase m_Item; + public PropBase prop { get { return m_Prop; } } + private PropBase m_Prop; private Coroutine m_CoUse; @@ -33,11 +33,11 @@ public class ItemWidget : UIGridItemBase public override void Set(object param) { - ItemWidgetParam info = (ItemWidgetParam)param; + PropWidgetParam info = (PropWidgetParam)param; onSelected = info.onSelected; - m_Item = info.item; + m_Prop = info.prop; - Image_Icon.sprite = ResourceManager.Instance.Load<Sprite>(info.item.iconPath); + Image_Icon.sprite = ResourceManager.Instance.Load<Sprite>(info.prop.iconPath); SetSelectBg(false); diff --git a/SurvivalTest/Assets/Scripts/UI/Panel/PanelPropBar/PropWidget.cs.meta b/SurvivalTest/Assets/Scripts/UI/Panel/PanelPropBar/PropWidget.cs.meta new file mode 100644 index 0000000..f9f85a3 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/UI/Panel/PanelPropBar/PropWidget.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4ccf65ebe78138644a8bc5283d21ae1a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/UI/Panel/PanelTopStuffBar/PanelTopStuffBar.cs b/SurvivalTest/Assets/Scripts/UI/Panel/PanelTopStuffBar/PanelTopStuffBar.cs index 6e91c6b..98ff288 100644 --- a/SurvivalTest/Assets/Scripts/UI/Panel/PanelTopStuffBar/PanelTopStuffBar.cs +++ b/SurvivalTest/Assets/Scripts/UI/Panel/PanelTopStuffBar/PanelTopStuffBar.cs @@ -5,13 +5,13 @@ using UnityEngine; public class PanelTopStuffBar : PanelBase { public UIWeaponBar m_WeaponBar; - public UIItemBar m_ItemBar; + public UIPropBar m_PropBar; public UIDecorationBar m_DecorationBar; public override void Set(object param) { m_WeaponBar.Set(); - m_ItemBar.Set(); + m_PropBar.Set(); m_DecorationBar.Set(); } }
\ No newline at end of file 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; - } - -} diff --git a/SurvivalTest/Assets/Scripts/UI/Panel/PanelTopStuffBar/UIPropBar.cs b/SurvivalTest/Assets/Scripts/UI/Panel/PanelTopStuffBar/UIPropBar.cs new file mode 100644 index 0000000..d50aed1 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/UI/Panel/PanelTopStuffBar/UIPropBar.cs @@ -0,0 +1,97 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UI; + +public class UIPropBar : MonoBehaviour +{ + public PropWidget m_PropTempalte; + + public UISimpleGrid m_PropGrid; + + public Text m_TextName; + + private List<PropWidget> m_Props = new List<PropWidget>(); + + private int m_CurrentIndex = 0; + + public void Set() + { + m_PropTempalte.gameObject.SetActive(false); + + for (int i = 0; i < PlayerManager.Instance.props.Count; ++i) + { + PropWidget widget = MakePropWidget(PlayerManager.Instance.props[i]); + m_Props.Add(widget); + } + + SelectPropWidget(0); + } + + bool SwitchToLeft() + { + return Input.GetButtonDown("LeftProp"); + } + + bool SwitchToRight() + { + return Input.GetButtonDown("RightProp"); + } + + bool UseProp() + { + return Input.GetButtonDown("Fire3"); + } + + PropWidget MakePropWidget(PropBase prop) + { + PropWidget widget = Instantiate<PropWidget>(m_PropTempalte); + widget.transform.SetParent(m_PropGrid.transform); + widget.gameObject.SetActive(true); + widget.GetComponent<RectTransform>().anchoredPosition = new Vector2(0, 0); +#if UNITY_EDITOR + widget.name = "prop (" + prop.name + ")"; +#endif + + PropWidgetParam param = new PropWidgetParam(); + //param.onSelected = OnSelectPropWidget; + param.prop = prop; + widget.Set(param); + return widget; + } + + protected void Update() + { + if (SwitchToLeft()) + { + int newIndex = Mathf.Clamp(m_CurrentIndex - 1, 0, m_Props.Count - 1); + SelectPropWidget(newIndex); + } + if (SwitchToRight()) + { + int newIndex = Mathf.Clamp(m_CurrentIndex + 1, 0, m_Props.Count - 1); + SelectPropWidget(newIndex); + } + if (UseProp()) + { + m_Props[m_CurrentIndex].OnUseCallback(); + PlayerManager.Instance.UseProp(m_Props[m_CurrentIndex].prop); + } + } + + void SelectPropWidget(int index) + { + if (index < 0 || index > m_Props.Count - 1) + { + return; + } + m_Props[m_CurrentIndex].OnDeselectCallback(); + m_Props[index].OnSelectCallback(); + + m_TextName.text = m_Props[index].prop.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/UIPropBar.cs.meta index 0e07369..0e07369 100644 --- a/SurvivalTest/Assets/Scripts/UI/Panel/PanelTopStuffBar/UIItemBar.cs.meta +++ b/SurvivalTest/Assets/Scripts/UI/Panel/PanelTopStuffBar/UIPropBar.cs.meta diff --git a/SurvivalTest/Assets/Scripts/UI/Panel/PanelWeaponBar/UIWeaponWidget.cs b/SurvivalTest/Assets/Scripts/UI/Panel/PanelWeaponBar/UIWeaponWidget.cs index f061a3b..baac0d2 100644 --- a/SurvivalTest/Assets/Scripts/UI/Panel/PanelWeaponBar/UIWeaponWidget.cs +++ b/SurvivalTest/Assets/Scripts/UI/Panel/PanelWeaponBar/UIWeaponWidget.cs @@ -8,7 +8,7 @@ public struct UIWeaponWidgetParam public WeaponBase weapon; } -public class UIWeaponWidget : UIGridItemBase +public class UIWeaponWidget : UIGridPropBase { public Image Image_Icon; public Image Image_CD; diff --git a/SurvivalTest/Assets/Scripts/UI/UIManager_Panels.cs b/SurvivalTest/Assets/Scripts/UI/UIManager_Panels.cs index 649d685..bb48afd 100644 --- a/SurvivalTest/Assets/Scripts/UI/UIManager_Panels.cs +++ b/SurvivalTest/Assets/Scripts/UI/UIManager_Panels.cs @@ -8,7 +8,7 @@ public enum PanelType None, PanelLevelBar, - PanelItemBar, + PanelPropBar, PanelWeaponBar, PanelTopSuffBar, PanelBossHpBar, @@ -29,7 +29,7 @@ public partial class UIManager : Singleton<UIManager> void SetPanels() { AddPanel(PanelType.PanelLevelBar, "PanelLevelBar"); - AddPanel(PanelType.PanelItemBar, "PanelItemBar"); + AddPanel(PanelType.PanelPropBar, "PanelPropBar"); AddPanel(PanelType.PanelWeaponBar, "PanelWeaponBar"); AddPanel(PanelType.PanelTopSuffBar, "PanelTopSuffBar"); AddPanel(PanelType.PanelBossHpBar, "PanelBossHpBar"); diff --git a/SurvivalTest/ProjectSettings/InputManager.asset b/SurvivalTest/ProjectSettings/InputManager.asset index 1c2591f..1a8154e 100644 --- a/SurvivalTest/ProjectSettings/InputManager.asset +++ b/SurvivalTest/ProjectSettings/InputManager.asset @@ -566,7 +566,7 @@ InputManager: axis: 0 joyNum: 0 - serializedVersion: 3 - m_Name: LeftItem + m_Name: LeftProp descriptiveName: descriptiveNegativeName: negativeButton: @@ -582,7 +582,7 @@ InputManager: axis: 0 joyNum: 0 - serializedVersion: 3 - m_Name: RightItem + m_Name: RightProp descriptiveName: descriptiveNegativeName: negativeButton: |