diff options
Diffstat (limited to 'SurvivalTest/Assets/Scripts')
37 files changed, 615 insertions, 67 deletions
diff --git a/SurvivalTest/Assets/Scripts/Devices.meta b/SurvivalTest/Assets/Scripts/Devices.meta new file mode 100644 index 0000000..6a5b0d0 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Devices.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: f4cd3d0fd06d3d949981090c941f9e0f +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Devices/DeviceBase.cs b/SurvivalTest/Assets/Scripts/Devices/DeviceBase.cs new file mode 100644 index 0000000..61e347f --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Devices/DeviceBase.cs @@ -0,0 +1,12 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +/// <summary> +/// 设备 +/// </summary> +public class DeviceBase : MonoBehaviour +{ + + +}
\ No newline at end of file diff --git a/SurvivalTest/Assets/Scripts/Devices/DeviceBase.cs.meta b/SurvivalTest/Assets/Scripts/Devices/DeviceBase.cs.meta new file mode 100644 index 0000000..ba0b4c7 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Devices/DeviceBase.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7b9b9975b634cad43b8e89424dddb2fc +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/GameApp.cs b/SurvivalTest/Assets/Scripts/GameApp.cs index d5f9d70..cfc93d9 100644 --- a/SurvivalTest/Assets/Scripts/GameApp.cs +++ b/SurvivalTest/Assets/Scripts/GameApp.cs @@ -8,13 +8,20 @@ public class GameApp : MonoBehaviour void Start() { - + PlayerManager.Instance.Init(); + BattleManager.Instance.Init(); + + } void Update() { + //公共模块 GameLoop.Instance.Update(); TinyCountDown.Instance.Update(); + + BattleManager.Instance.Update(); + PlayerManager.Instance.Update(); } void LateUpdate() diff --git a/SurvivalTest/Assets/Scripts/Items/ItemBase.cs b/SurvivalTest/Assets/Scripts/Items/ItemBase.cs index 91beca8..a19ebcf 100644 --- a/SurvivalTest/Assets/Scripts/Items/ItemBase.cs +++ b/SurvivalTest/Assets/Scripts/Items/ItemBase.cs @@ -8,6 +8,12 @@ using UnityEngine; public abstract class ItemBase { + public abstract string name { get; } + + public abstract string iconPath { get; } + public abstract void OnUse(GameObject owner); + public virtual void Update() { } + }
\ No newline at end of file diff --git a/SurvivalTest/Assets/Scripts/Items/Item_B2Phone.cs b/SurvivalTest/Assets/Scripts/Items/Item_B2Phone.cs index eb870b0..5301d85 100644 --- a/SurvivalTest/Assets/Scripts/Items/Item_B2Phone.cs +++ b/SurvivalTest/Assets/Scripts/Items/Item_B2Phone.cs @@ -7,10 +7,18 @@ using UnityEngine; /// </summary> public class Item_B2Phone : ItemBase { + public override string name => "B2轰炸机"; + + public override string iconPath => "art/ui/skillicon/plane"; + + string prefabPath = "prefabs/weapon/b2"; public override void OnUse(GameObject owner) { + TestB2 b2 = UnityEngine.Object.Instantiate(ResourceManager.Instance.Load<TestB2>(prefabPath)); + Vector3 pos3D = owner.GetComponent<TopDownTransform>().GetProjectedPosition(); + b2.Set(pos3D + new Vector3(-15, 0, 0), pos3D + new Vector3(15, 0, 0), 20f, 3f); } }
\ No newline at end of file diff --git a/SurvivalTest/Assets/Scripts/Items/Item_SpaceBeamer.cs b/SurvivalTest/Assets/Scripts/Items/Item_SpaceBeamer.cs index 2ccbb9c..73492ee 100644 --- a/SurvivalTest/Assets/Scripts/Items/Item_SpaceBeamer.cs +++ b/SurvivalTest/Assets/Scripts/Items/Item_SpaceBeamer.cs @@ -4,10 +4,18 @@ using UnityEngine; public class Item_SpaceBeamer : ItemBase { + public override string name => "太空射线"; + + public override string iconPath => "art/ui/skillicon/space_beamer"; + + string prefabPath = "prefabs/weapon/space_beam"; public override void OnUse(GameObject owner) { + TestSpaceBeam beam = UnityEngine.Object.Instantiate<TestSpaceBeam>(ResourceManager.Instance.Load<TestSpaceBeam>(prefabPath)); + Vector3 pos3D = owner.GetComponent<TopDownTransform>().position; + beam.Set(pos3D + new Vector3(3, 0, 0)); } }
\ No newline at end of file diff --git a/SurvivalTest/Assets/Scripts/Managers/BattleManager.cs b/SurvivalTest/Assets/Scripts/Managers/BattleManager.cs new file mode 100644 index 0000000..102bc34 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Managers/BattleManager.cs @@ -0,0 +1,17 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class BattleManager : Singleton<BattleManager> +{ + + public void Init() + { + UIManager.Instance.OpenPanel(PanelType.PanelItemBar, null); + } + + public void Update() + { + } + +}
\ No newline at end of file diff --git a/SurvivalTest/Assets/Scripts/Managers/BattleManager.cs.meta b/SurvivalTest/Assets/Scripts/Managers/BattleManager.cs.meta new file mode 100644 index 0000000..ce61fdc --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Managers/BattleManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0625fb778ee3237468a8f99fc92c37bd +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Managers/PlayerManager.cs b/SurvivalTest/Assets/Scripts/Managers/PlayerManager.cs new file mode 100644 index 0000000..59593b0 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Managers/PlayerManager.cs @@ -0,0 +1,35 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public partial class PlayerManager : Singleton<PlayerManager> +{ + + // 角色 + private CrewScript m_Crew; + + // 持有的装备 + public List<EquipBase> equips { get { return m_Equips; } } + private List<EquipBase> m_Equips = new List<EquipBase>(); + + // 持有的饰品 + public List<DecorationBase> decorations { get { return m_Decorations; } } + private List<DecorationBase> m_Decorations = new List<DecorationBase>(); + + public void Init() + { + InitItems(); + + } + + public void Update() + { + UpdateItems(); + } + + public void SetCrew(CrewScript crew) + { + m_Crew = crew; + } + +}
\ No newline at end of file diff --git a/SurvivalTest/Assets/Scripts/Managers/PlayerManager.cs.meta b/SurvivalTest/Assets/Scripts/Managers/PlayerManager.cs.meta new file mode 100644 index 0000000..848ec64 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Managers/PlayerManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c2c3da009e0d8114597080ecff2e380c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Managers/PlayerManager_Decorations.cs b/SurvivalTest/Assets/Scripts/Managers/PlayerManager_Decorations.cs new file mode 100644 index 0000000..ce85849 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Managers/PlayerManager_Decorations.cs @@ -0,0 +1,10 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + + +public partial class PlayerManager : Singleton<PlayerManager> +{ + + +}
\ No newline at end of file diff --git a/SurvivalTest/Assets/Scripts/Managers/PlayerManager_Decorations.cs.meta b/SurvivalTest/Assets/Scripts/Managers/PlayerManager_Decorations.cs.meta new file mode 100644 index 0000000..3cc2dc3 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Managers/PlayerManager_Decorations.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6f2b538b1ec21a548b41fe478e5b3bd3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Managers/PlayerManager_Equips.cs b/SurvivalTest/Assets/Scripts/Managers/PlayerManager_Equips.cs new file mode 100644 index 0000000..ce85849 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Managers/PlayerManager_Equips.cs @@ -0,0 +1,10 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + + +public partial class PlayerManager : Singleton<PlayerManager> +{ + + +}
\ No newline at end of file diff --git a/SurvivalTest/Assets/Scripts/Managers/PlayerManager_Equips.cs.meta b/SurvivalTest/Assets/Scripts/Managers/PlayerManager_Equips.cs.meta new file mode 100644 index 0000000..c43b512 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Managers/PlayerManager_Equips.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 19dc8d657411e8d47a563a47442d687d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Managers/PlayerManager_Items.cs b/SurvivalTest/Assets/Scripts/Managers/PlayerManager_Items.cs new file mode 100644 index 0000000..a0cfe52 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Managers/PlayerManager_Items.cs @@ -0,0 +1,51 @@ +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>(); + + // 当前选中的物品 + ItemBase m_CurrentItem = null; + + void InitItems() + { + m_Items.Add(new Item_B2Phone()); + m_Items.Add(new Item_SpaceBeamer()); + } + + /// <summary> + /// 选中物品 + /// </summary> + public void SetCurrentItem(ItemBase item) + { + if (!items.Contains(item)) + { + Debug.LogError("No such item"); + return; + } + m_CurrentItem = item; + } + + /// <summary> + /// 使用当前道具 + /// </summary> + public void UseCurrentItem() + { + if (m_CurrentItem == null) + return; + + m_CurrentItem.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 new file mode 100644 index 0000000..c0307e5 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Managers/PlayerManager_Items.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2b31f1faa8e2c6a4085213ca15e56220 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Resources/ResourceManager.cs b/SurvivalTest/Assets/Scripts/Resources/ResourceManager.cs index ddd3225..193d8b3 100644 --- a/SurvivalTest/Assets/Scripts/Resources/ResourceManager.cs +++ b/SurvivalTest/Assets/Scripts/Resources/ResourceManager.cs @@ -4,7 +4,7 @@ using UnityEngine; public class ResourceManager : Singleton<ResourceManager> { - T Load<T>(string path) where T : UnityEngine.Object + public T Load<T>(string path) where T : UnityEngine.Object { return Resources.Load<T>(path); } diff --git a/SurvivalTest/Assets/Scripts/Test/TestPeaceMaker.cs b/SurvivalTest/Assets/Scripts/Test/TestPeaceMaker.cs index 2a7af2f..033f198 100644 --- a/SurvivalTest/Assets/Scripts/Test/TestPeaceMaker.cs +++ b/SurvivalTest/Assets/Scripts/Test/TestPeaceMaker.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using UnityEngine; using UnityEngine.Events; -public class TestPeaceMaker : MonoBehaviour +public class TestPeaceMaker : CrewScript { [SerializeField] private Transform m_Camera; @@ -16,8 +16,6 @@ public class TestPeaceMaker : MonoBehaviour [SerializeField] private Vector2 m_Zoom; [SerializeField] private GameObject m_LaunchVfx; [SerializeField] private Transform m_LaunchPoint; - [SerializeField] private TestB2 m_B2; - [SerializeField] private TestSpaceBeam m_SpaceBeam; private Vector3 zoomIn { @@ -56,6 +54,11 @@ public class TestPeaceMaker : MonoBehaviour } private ControlMode m_ControlMode; + private void Awake() + { + PlayerManager.Instance.SetCrew(this); + } + void Start() { m_SpriteRenderer = GetComponent<SpriteRenderer>(); @@ -77,9 +80,6 @@ public class TestPeaceMaker : MonoBehaviour bool isFire = Fire(); bool isGrenade = LaunchGrenade(); - bool isBeam = SpaceBeam(); - - CallB2(); CameraFollow(); @@ -290,30 +290,4 @@ public class TestPeaceMaker : MonoBehaviour } } - void CallB2() - { - if(Input.GetButtonDown("Fire3")) - { - TestB2 b2 = Instantiate<TestB2>(m_B2); - - Vector3 pos3D = m_Coord.GetProjectedPosition(); - b2.Set(pos3D + new Vector3(-15, 0,0 ), pos3D + new Vector3(15, 0,0 ), 20f, 3f); - } - } - - bool SpaceBeam() - { - if (Input.GetButtonDown("SpaceBeam")) - { - TestSpaceBeam beam = Instantiate<TestSpaceBeam>(m_SpaceBeam); - - Vector3 pos3D = m_Coord.position; - beam.Set(pos3D + new Vector3(3, 0, 0)); - - TinyCountDown.Instance.Set("SpaceBeam", 0.1f); - return true; - } - return TinyCountDown.Instance.Get("SpaceBeam") > 0; - } - } diff --git a/SurvivalTest/Assets/Scripts/UI/Common/UIGridItemBase.cs b/SurvivalTest/Assets/Scripts/UI/Common/UIGridItemBase.cs new file mode 100644 index 0000000..8e5ff24 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/UI/Common/UIGridItemBase.cs @@ -0,0 +1,10 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public abstract class UIGridItemBase : MonoBehaviour +{ + + public abstract void Set(object param); + +} diff --git a/SurvivalTest/Assets/Scripts/UI/Common/UIGridItemBase.cs.meta b/SurvivalTest/Assets/Scripts/UI/Common/UIGridItemBase.cs.meta new file mode 100644 index 0000000..a3f1f69 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/UI/Common/UIGridItemBase.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9e490364ec1d9c8419f9bece4e2ab365 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/UI/Panel/PanelBase.cs b/SurvivalTest/Assets/Scripts/UI/Panel/PanelBase.cs index 3081d97..9d1157c 100644 --- a/SurvivalTest/Assets/Scripts/UI/Panel/PanelBase.cs +++ b/SurvivalTest/Assets/Scripts/UI/Panel/PanelBase.cs @@ -2,26 +2,41 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; +[ExecuteInEditMode] [DisallowMultipleComponent] -public class PanelBase : MonoBehaviour +public abstract class PanelBase : MonoBehaviour { - public virtual void Set(object param) + public abstract void Set(object param); + + public virtual void OnEnable() { + InitRectTransform(); } - void Start() - { - - } + public void InitRectTransform() + { + RectTransform rect = gameObject.GetComponent<RectTransform>(); + rect.anchorMin = new Vector2(0, 0); + rect.anchorMax = new Vector2(1, 1); + + rect.localScale = new Vector3(1, 1, 1); + + rect.anchoredPosition3D = Vector3.zero; + + rect.offsetMin = new Vector2(0, 0); + rect.offsetMax = new Vector2(0, 0); - protected virtual void Update() - { - } + rect.pivot = new Vector2(0.5f, 0.5f); + } + + protected virtual void Update() + { + } protected virtual void OnSecondUpdate() { } -} +}
\ No newline at end of file diff --git a/SurvivalTest/Assets/Scripts/UI/Panel/PanelEquipBar.cs b/SurvivalTest/Assets/Scripts/UI/Panel/PanelEquipBar.cs index 61f99e5..dbec362 100644 --- a/SurvivalTest/Assets/Scripts/UI/Panel/PanelEquipBar.cs +++ b/SurvivalTest/Assets/Scripts/UI/Panel/PanelEquipBar.cs @@ -2,17 +2,9 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; -public class PanelEquipBar : MonoBehaviour +public class PanelEquipBar : PanelBase { - // Start is called before the first frame update - void Start() - { - - } - - // Update is called once per frame - void Update() - { - - } + public override void Set(object param) + { + } } diff --git a/SurvivalTest/Assets/Scripts/UI/Panel/PanelItemBar/ItemWidget.cs b/SurvivalTest/Assets/Scripts/UI/Panel/PanelItemBar/ItemWidget.cs index 55898f2..552672a 100644 --- a/SurvivalTest/Assets/Scripts/UI/Panel/PanelItemBar/ItemWidget.cs +++ b/SurvivalTest/Assets/Scripts/UI/Panel/PanelItemBar/ItemWidget.cs @@ -1,9 +1,123 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; +using UnityEngine.UI; -public class ItemWidget : MonoBehaviour +public struct ItemWidgetParam { - + // 主动点击 + public System.Action<ItemWidget> onSelected; + public ItemBase item; +} + +public class ItemWidget : UIGridItemBase +{ + public Image Image_Icon; + public Image Image_SelectBg; + + public Image Image_Use; + + private System.Action<ItemWidget> onSelected; + + public ItemBase item { get { return m_Item; } } + private ItemBase m_Item; + + private Coroutine m_CoUse; + + private int m_PendingUse = 0; + + public void SetSelectBg(bool selected) + { + Image_SelectBg.gameObject.SetActive(selected); + } + + public override void Set(object param) + { + ItemWidgetParam info = (ItemWidgetParam)param; + onSelected = info.onSelected; + m_Item = info.item; + + Image_Icon.sprite = ResourceManager.Instance.Load<Sprite>(info.item.iconPath); + + SetSelectBg(false); + + Image_Use.gameObject.SetActive(false); + } + + public void OnSelectCallback() + { + SetSelectBg(true); + } + + public void OnDeselectCallback() + { + SetSelectBg(false); + } + + public void OnUseCallback() + { + m_PendingUse++; + PlayUseAnimation(); + } + + private void PlayUseAnimation() + { + if (m_CoUse != null) + return; + Image_Use.gameObject.SetActive(true); + m_CoUse = StartCoroutine(CoUseAnimation()); + } + + IEnumerator CoUseAnimation() + { + float speed = 5f; + + while(m_PendingUse > 0) + { + Image_Use.fillOrigin = (int)Image.OriginVertical.Bottom; + float t = 0; + while (true) + { + t += speed * Time.deltaTime; + + if (t > 1) + break; + + Image_Use.fillAmount = Mathf.Lerp(0, 1, t); + + yield return null; + } + + Image_Use.fillOrigin = (int)Image.OriginVertical.Top; + t = 0; + while (true) + { + t += speed * Time.deltaTime; + + if (t > 1) + break; + + Image_Use.fillAmount = Mathf.Lerp(1, 0, t); + + yield return null; + } + m_PendingUse--; + } + + Image_Use.gameObject.SetActive(false); + + m_CoUse = null; + + yield break; + } + + private void StopUseAnimation() + { + if (m_CoUse != null) + { + StopCoroutine(m_CoUse); + } + Image_Use.gameObject.SetActive(false); + } } diff --git a/SurvivalTest/Assets/Scripts/UI/Panel/PanelItemBar/PanelItemBar.cs b/SurvivalTest/Assets/Scripts/UI/Panel/PanelItemBar/PanelItemBar.cs index 00acafc..74f90c3 100644 --- a/SurvivalTest/Assets/Scripts/UI/Panel/PanelItemBar/PanelItemBar.cs +++ b/SurvivalTest/Assets/Scripts/UI/Panel/PanelItemBar/PanelItemBar.cs @@ -1,13 +1,31 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; +using UnityEngine.UI; public class PanelItemBar : PanelBase { - /// <summary> - /// 当前持有的Items - /// </summary> - public List<ItemWidget> m_Items = new List<ItemWidget>(); + public ItemWidget m_ItemTempalte; + + public UISimpleGrid m_ItemGrid; + + public Text m_TextName; + + // 当前持有的Items + 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() { @@ -19,14 +37,58 @@ public class PanelItemBar : PanelBase 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); + + 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.UseCurrentItem(); + } + } + + 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_CurrentIndex = index; + + PlayerManager.Instance.SetCurrentItem(m_Items[index].item); } } diff --git a/SurvivalTest/Assets/Scripts/UI/UIManager_Panels.cs b/SurvivalTest/Assets/Scripts/UI/UIManager_Panels.cs index 049f733..d29c24a 100644 --- a/SurvivalTest/Assets/Scripts/UI/UIManager_Panels.cs +++ b/SurvivalTest/Assets/Scripts/UI/UIManager_Panels.cs @@ -1,18 +1,27 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; +using UnityEngine.UI; public enum PanelType { - None, + None, - PanelLevelBar, + PanelLevelBar, PanelItemBar, } public partial class UIManager : Singleton<UIManager> { private Dictionary<PanelType, string> m_Panels = new Dictionary<PanelType, string>(); + private Dictionary<PanelType, PanelBase> m_OpenedPanels = new Dictionary<PanelType, PanelBase>(); + + private Canvas m_Canvas; + + public void SetRootCanvas(Canvas canvas) + { + m_Canvas = canvas; + } void SetPanels() { @@ -25,9 +34,27 @@ public partial class UIManager : Singleton<UIManager> m_Panels.Add(type, "prefabs/ui/" + path); } - void OpenPanel(PanelType type, object param) + public PanelBase OpenPanel(PanelType type, object param = null) { - + if(m_OpenedPanels.ContainsKey(type)) + { + return m_OpenedPanels[type]; + } + + PanelBase prefab = ResourceManager.Instance.Load<PanelBase>(m_Panels[type]); + if (prefab == null) + { + Debug.LogError("UI Prefab in not available, path=" + m_Panels[type]); + return null; + } + PanelBase panel = UnityEngine.Object.Instantiate<PanelBase>(prefab); + panel.name = prefab.name; + panel.transform.SetParent(m_Canvas.transform); + panel.Set(param); + panel.InitRectTransform(); + panel.gameObject.SetActive(true); + + return panel; } -} +}
\ No newline at end of file diff --git a/SurvivalTest/Assets/Scripts/UI/UIRootCanvas.cs b/SurvivalTest/Assets/Scripts/UI/UIRootCanvas.cs new file mode 100644 index 0000000..541d21a --- /dev/null +++ b/SurvivalTest/Assets/Scripts/UI/UIRootCanvas.cs @@ -0,0 +1,13 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class UIRootCanvas : MonoBehaviour +{ + + private void Awake() + { + UIManager.Instance.SetRootCanvas(gameObject.GetComponent<Canvas>()); + } + +} diff --git a/SurvivalTest/Assets/Scripts/UI/UIRootCanvas.cs.meta b/SurvivalTest/Assets/Scripts/UI/UIRootCanvas.cs.meta new file mode 100644 index 0000000..5423e4e --- /dev/null +++ b/SurvivalTest/Assets/Scripts/UI/UIRootCanvas.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 097b021f29d7fc8468055a35bbc92ca8 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/UI/Widget.meta b/SurvivalTest/Assets/Scripts/UI/Widgets.meta index c0a26ea..c0a26ea 100644 --- a/SurvivalTest/Assets/Scripts/UI/Widget.meta +++ b/SurvivalTest/Assets/Scripts/UI/Widgets.meta diff --git a/SurvivalTest/Assets/Scripts/UI/Widget/UIButton.cs b/SurvivalTest/Assets/Scripts/UI/Widgets/UIButton.cs index 616b69d..616b69d 100644 --- a/SurvivalTest/Assets/Scripts/UI/Widget/UIButton.cs +++ b/SurvivalTest/Assets/Scripts/UI/Widgets/UIButton.cs diff --git a/SurvivalTest/Assets/Scripts/UI/Widget/UIButton.cs.meta b/SurvivalTest/Assets/Scripts/UI/Widgets/UIButton.cs.meta index 41e16d0..41e16d0 100644 --- a/SurvivalTest/Assets/Scripts/UI/Widget/UIButton.cs.meta +++ b/SurvivalTest/Assets/Scripts/UI/Widgets/UIButton.cs.meta diff --git a/SurvivalTest/Assets/Scripts/UI/Widgets/UIGrid.cs b/SurvivalTest/Assets/Scripts/UI/Widgets/UIGrid.cs new file mode 100644 index 0000000..5eeee61 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/UI/Widgets/UIGrid.cs @@ -0,0 +1,18 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class UIGrid : MonoBehaviour +{ + // Start is called before the first frame update + void Start() + { + + } + + // Update is called once per frame + void Update() + { + + } +} diff --git a/SurvivalTest/Assets/Scripts/UI/Widgets/UIGrid.cs.meta b/SurvivalTest/Assets/Scripts/UI/Widgets/UIGrid.cs.meta new file mode 100644 index 0000000..c3570c0 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/UI/Widgets/UIGrid.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e0cbe5d6d2aaef54dba4bb837871787f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/UI/Widgets/UISimpleGrid.cs b/SurvivalTest/Assets/Scripts/UI/Widgets/UISimpleGrid.cs new file mode 100644 index 0000000..a4e480a --- /dev/null +++ b/SurvivalTest/Assets/Scripts/UI/Widgets/UISimpleGrid.cs @@ -0,0 +1,22 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UI; + +/// <summary> +/// 简易Grid +/// </summary> +public class UISimpleGrid : MonoBehaviour +{ + // Start is called before the first frame update + void Start() + { + + } + + // Update is called once per frame + void Update() + { + + } +} diff --git a/SurvivalTest/Assets/Scripts/UI/Widgets/UISimpleGrid.cs.meta b/SurvivalTest/Assets/Scripts/UI/Widgets/UISimpleGrid.cs.meta new file mode 100644 index 0000000..e071d58 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/UI/Widgets/UISimpleGrid.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4dbae61f498dde342a95489aca8ff68c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Unit/Crew/CrewScript.cs b/SurvivalTest/Assets/Scripts/Unit/Crew/CrewScript.cs new file mode 100644 index 0000000..6532317 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Unit/Crew/CrewScript.cs @@ -0,0 +1,8 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class CrewScript : MonoBehaviour +{ + +} diff --git a/SurvivalTest/Assets/Scripts/Unit/Crew/CrewScript.cs.meta b/SurvivalTest/Assets/Scripts/Unit/Crew/CrewScript.cs.meta new file mode 100644 index 0000000..0e1ebed --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Unit/Crew/CrewScript.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9601f63e791a9974fbc9cd04c352b442 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: |