From 4c2a468084adae81d14409fd9727ccae8c6f9da6 Mon Sep 17 00:00:00 2001 From: Cyh28 <2606851972@qq.com> Date: Sat, 6 Apr 2024 21:58:16 +0800 Subject: [PATCH] feat: :art: Add Button UI --- .../Assets/Prefabs/Button_.prefab | 149 ++++++++++++++++++ .../Assets/Scenes/Game - cyh.unity | 34 ++-- .../Scripts/InteractBase/InteractControl.cs | 31 ++++ .../Assets/Scripts/UI/ButtonCostControl.cs | 32 ++++ .../Scripts/UI/ButtonCostControl.cs.meta | 11 ++ .../Assets/Scripts/UI/UIPanelControl.cs | 1 + 6 files changed, 241 insertions(+), 17 deletions(-) create mode 100644 interface/interface_local/Assets/Scripts/UI/ButtonCostControl.cs create mode 100644 interface/interface_local/Assets/Scripts/UI/ButtonCostControl.cs.meta diff --git a/interface/interface_local/Assets/Prefabs/Button_.prefab b/interface/interface_local/Assets/Prefabs/Button_.prefab index 77ac11fe..0d92cd74 100644 --- a/interface/interface_local/Assets/Prefabs/Button_.prefab +++ b/interface/interface_local/Assets/Prefabs/Button_.prefab @@ -13,6 +13,7 @@ GameObject: - component: {fileID: 457037433653746193} - component: {fileID: 494760107565601563} - component: {fileID: 5201532282260106589} + - component: {fileID: 595894871502997581} m_Layer: 5 m_Name: Button_ m_TagString: Untagged @@ -33,6 +34,7 @@ RectTransform: m_ConstrainProportionsScale: 0 m_Children: - {fileID: 2564765854438951958} + - {fileID: 7196093104036570849} m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} @@ -136,6 +138,153 @@ MonoBehaviour: m_EditorClassIdentifier: sacleOrigin: {x: 0, y: 0, z: 0} scaleChange: {x: 0, y: 0, z: 0} +--- !u!114 &595894871502997581 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6520991344062563853} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: eecc027f9f8258346900c03e9bddc13d, type: 3} + m_Name: + m_EditorClassIdentifier: + cost: {fileID: 8063348834605561237} +--- !u!1 &8063348834605561237 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 7196093104036570849} + - component: {fileID: 7866578951150204429} + - component: {fileID: 200479297252645773} + m_Layer: 5 + m_Name: Cost + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 0 +--- !u!224 &7196093104036570849 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 8063348834605561237} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 4455675442406268739} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 0.5} + m_AnchorMax: {x: 0, y: 0.5} + m_AnchoredPosition: {x: -85, y: 0} + m_SizeDelta: {x: 150, y: 30} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!222 &7866578951150204429 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 8063348834605561237} + m_CullTransparentMesh: 1 +--- !u!114 &200479297252645773 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 8063348834605561237} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_RaycastTarget: 1 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_text: Cost + m_isRightToLeft: 0 + m_fontAsset: {fileID: 11400000, guid: 83f36b9cce81c054eaa21e581c525770, type: 2} + m_sharedMaterial: {fileID: -4048921244979861397, guid: 83f36b9cce81c054eaa21e581c525770, type: 2} + m_fontSharedMaterials: [] + m_fontMaterial: {fileID: 0} + m_fontMaterials: [] + m_fontColor32: + serializedVersion: 2 + rgba: 4294246144 + m_fontColor: {r: 0, g: 1, b: 0.9553776, a: 1} + m_enableVertexGradient: 0 + m_colorMode: 3 + m_fontColorGradient: + topLeft: {r: 1, g: 1, b: 1, a: 1} + topRight: {r: 1, g: 1, b: 1, a: 1} + bottomLeft: {r: 1, g: 1, b: 1, a: 1} + bottomRight: {r: 1, g: 1, b: 1, a: 1} + m_fontColorGradientPreset: {fileID: 0} + m_spriteAsset: {fileID: 0} + m_tintAllSprites: 0 + m_StyleSheet: {fileID: 0} + m_TextStyleHashCode: -1183493901 + m_overrideHtmlColors: 0 + m_faceColor: + serializedVersion: 2 + rgba: 4294967295 + m_fontSize: 15 + m_fontSizeBase: 15 + m_fontWeight: 400 + m_enableAutoSizing: 0 + m_fontSizeMin: 18 + m_fontSizeMax: 72 + m_fontStyle: 1 + m_HorizontalAlignment: 4 + m_VerticalAlignment: 256 + m_textAlignment: 65535 + m_characterSpacing: 0 + m_wordSpacing: 0 + m_lineSpacing: 0 + m_lineSpacingMax: 0 + m_paragraphSpacing: 0 + m_charWidthMaxAdj: 0 + m_enableWordWrapping: 1 + m_wordWrappingRatios: 0.4 + m_overflowMode: 0 + m_linkedTextComponent: {fileID: 0} + parentLinkedComponent: {fileID: 0} + m_enableKerning: 1 + m_enableExtraPadding: 0 + checkPaddingRequired: 0 + m_isRichText: 1 + m_parseCtrlCharacters: 1 + m_isOrthographic: 1 + m_isCullingEnabled: 0 + m_horizontalMapping: 0 + m_verticalMapping: 0 + m_uvLineOffset: 0 + m_geometrySortingOrder: 0 + m_IsTextObjectScaleStatic: 0 + m_VertexBufferAutoSizeReduction: 0 + m_useMaxVisibleDescender: 1 + m_pageToDisplay: 1 + m_margin: {x: 0, y: 0, z: 0, w: 0} + m_isUsingLegacyAnimationComponent: 0 + m_isVolumetricText: 0 + m_hasFontAssetChanged: 0 + m_baseMaterial: {fileID: 0} + m_maskOffset: {x: 0, y: 0, z: 0, w: 0} --- !u!1 &8637768614659552370 GameObject: m_ObjectHideFlags: 0 diff --git a/interface/interface_local/Assets/Scenes/Game - cyh.unity b/interface/interface_local/Assets/Scenes/Game - cyh.unity index 2285442f..5d157633 100644 --- a/interface/interface_local/Assets/Scenes/Game - cyh.unity +++ b/interface/interface_local/Assets/Scenes/Game - cyh.unity @@ -156,14 +156,12 @@ RectTransform: m_ConstrainProportionsScale: 0 m_Children: - {fileID: 1043650395} - - {fileID: 1627875130} - - {fileID: 1934484270} m_Father: {fileID: 1507083278} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_AnchorMin: {x: 0, y: 0} + m_AnchorMin: {x: 1, y: 1} m_AnchorMax: {x: 1, y: 1} - m_AnchoredPosition: {x: 0, y: 0} - m_SizeDelta: {x: -21.66, y: 0} + m_AnchoredPosition: {x: -303.13, y: -84.99997} + m_SizeDelta: {x: 281.47, y: 511.5} m_Pivot: {x: 0, y: 1} --- !u!114 &21997620 MonoBehaviour: @@ -1244,7 +1242,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 1, y: 0} - m_AnchoredPosition: {x: 0, y: 824} + m_AnchoredPosition: {x: 0, y: 511.5} m_SizeDelta: {x: 0, y: 0} m_Pivot: {x: 0, y: 1} --- !u!114 &1043650396 @@ -1260,9 +1258,9 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: m_Padding: - m_Left: 0 + m_Left: 50 m_Right: 0 - m_Top: 80 + m_Top: 5 m_Bottom: 20 m_ChildAlignment: 1 m_Spacing: 15 @@ -1444,12 +1442,14 @@ RectTransform: m_Children: - {fileID: 21997619} - {fileID: 1638806967} + - {fileID: 1627875130} + - {fileID: 1934484270} m_Father: {fileID: 2076035942} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 1, y: 1} - m_AnchoredPosition: {x: 0, y: 0} - m_SizeDelta: {x: 0, y: 0} + m_AnchoredPosition: {x: -40, y: 0} + m_SizeDelta: {x: 80, y: 0} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &1507083279 MonoBehaviour: @@ -1698,11 +1698,11 @@ RectTransform: m_LocalScale: {x: 0.6, y: 0.6, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] - m_Father: {fileID: 21997619} + m_Father: {fileID: 1507083278} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0.5, y: 1} m_AnchorMax: {x: 0.5, y: 1} - m_AnchoredPosition: {x: 0, y: -50} + m_AnchoredPosition: {x: -10.830037, y: -50} m_SizeDelta: {x: 256, y: 64} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &1627875131 @@ -2488,11 +2488,11 @@ RectTransform: m_LocalScale: {x: 0.6, y: 0.6, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] - m_Father: {fileID: 21997619} + m_Father: {fileID: 1507083278} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0.5, y: 1} m_AnchorMax: {x: 0.5, y: 1} - m_AnchoredPosition: {x: 0, y: -53} + m_AnchoredPosition: {x: -10.830037, y: -53} m_SizeDelta: {x: 256, y: 64} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &1934484271 @@ -2568,8 +2568,8 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 1, y: 0} m_AnchorMax: {x: 1, y: 1} - m_AnchoredPosition: {x: -111.56006, y: 0} - m_SizeDelta: {x: 223.13, y: 0} + m_AnchoredPosition: {x: -111.56, y: 100.25} + m_SizeDelta: {x: 223.13, y: -200.5} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &2076035943 MonoBehaviour: @@ -2584,7 +2584,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: m_Material: {fileID: 0} - m_Color: {r: 0, g: 0, b: 0, a: 0.34117648} + m_Color: {r: 0, g: 0, b: 0, a: 0} m_RaycastTarget: 1 m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} m_Maskable: 1 diff --git a/interface/interface_local/Assets/Scripts/InteractBase/InteractControl.cs b/interface/interface_local/Assets/Scripts/InteractBase/InteractControl.cs index f006a38f..82bb1c14 100644 --- a/interface/interface_local/Assets/Scripts/InteractBase/InteractControl.cs +++ b/interface/interface_local/Assets/Scripts/InteractBase/InteractControl.cs @@ -110,4 +110,35 @@ public enum InteractOption {InteractOption.ConstructFort, "建造堡垒"}, {InteractOption.RepairWormhole, "修复虫洞"}, }; + public readonly Dictionary textCost = new Dictionary() + { + {InteractOption.None, ""}, + {InteractOption.BuildCivil, "$400"}, + {InteractOption.BuildMilitary, "$1200"}, + {InteractOption.BuildFlag, "$5000"}, + {InteractOption.RecycleShip, ""}, + {InteractOption.RecoverShip, ""}, + {InteractOption.InstallModuleArmor1, "$600"}, + {InteractOption.InstallModuleArmor2, "$1200"}, + {InteractOption.InstallModuleArmor3, "$1800"}, + {InteractOption.InstallModuleShield1, "$600"}, + {InteractOption.InstallModuleShield2, "$1200"}, + {InteractOption.InstallModuleShield3, "$1800"}, + {InteractOption.InstallModuleProducer1, "$0"}, + {InteractOption.InstallModuleProducer2, "$400"}, + {InteractOption.InstallModuleProducer3, "$800"}, + {InteractOption.InstallModuleConstructor1, "$0"}, + {InteractOption.InstallModuleConstructor2, "$400"}, + {InteractOption.InstallModuleConstructor3, "$800"}, + {InteractOption.InstallModuleLaserGun, "$0"}, + {InteractOption.InstallModulePlasmaGun, "$1200"}, + {InteractOption.InstallModuleShellGun, "$1300"}, + {InteractOption.InstallModuleMissileGun, "$1800"}, + {InteractOption.InstallModuleArcGun, "$2400"}, + {InteractOption.Produce, ""}, + {InteractOption.ConstructFactory, "$8000"}, + {InteractOption.ConstructCommunity, "$6000"}, + {InteractOption.ConstructFort, "$12000"}, + {InteractOption.RepairWormhole, "$18000"}, + }; } diff --git a/interface/interface_local/Assets/Scripts/UI/ButtonCostControl.cs b/interface/interface_local/Assets/Scripts/UI/ButtonCostControl.cs new file mode 100644 index 00000000..c04b2255 --- /dev/null +++ b/interface/interface_local/Assets/Scripts/UI/ButtonCostControl.cs @@ -0,0 +1,32 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEditor; +using UnityEngine; +using UnityEngine.EventSystems; +public class ButtonCostControl : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerUpHandler +{ + public GameObject cost; + // Start is called before the first frame update + void Start() + { + + } + public void OnPointerEnter(PointerEventData eventData) + { + cost.SetActive(true); + } + public void OnPointerExit(PointerEventData eventData) + { + cost.SetActive(false); + } + public void OnPointerUp(PointerEventData eventData) + { + + } + // Update is called once per frame + void Update() + { + + } + +} diff --git a/interface/interface_local/Assets/Scripts/UI/ButtonCostControl.cs.meta b/interface/interface_local/Assets/Scripts/UI/ButtonCostControl.cs.meta new file mode 100644 index 00000000..5dd1aca8 --- /dev/null +++ b/interface/interface_local/Assets/Scripts/UI/ButtonCostControl.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: eecc027f9f8258346900c03e9bddc13d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/interface/interface_local/Assets/Scripts/UI/UIPanelControl.cs b/interface/interface_local/Assets/Scripts/UI/UIPanelControl.cs index 79dfd1af..50da3709 100644 --- a/interface/interface_local/Assets/Scripts/UI/UIPanelControl.cs +++ b/interface/interface_local/Assets/Scripts/UI/UIPanelControl.cs @@ -19,6 +19,7 @@ void Start() obj = Instantiate(button_, transform.Find("Content")); obj.name = "Button_" + option.ToString(); obj.transform.Find("Text").GetComponent().text = InteractControl.GetInstance().textDic[option]; + obj.transform.Find("Cost").GetComponent().text = InteractControl.GetInstance().textCost[option]; // Debug.Log(obj.GetComponent