添加层级UI关联

This commit is contained in:
YangHua 2024-07-10 20:31:20 +08:00
parent 933e6c77b7
commit 02f8f1cc46
8 changed files with 62471 additions and 57160 deletions

View File

@ -1,5 +1,192 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &1391453459713271123
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 7961143038953216452}
- component: {fileID: 1313496498328362290}
- component: {fileID: 1663807556969581687}
- component: {fileID: 2802092426076630164}
m_Layer: 0
m_Name: Count
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &7961143038953216452
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1391453459713271123}
m_LocalRotation: {x: -0, y: 1, z: -0, w: 0}
m_LocalPosition: {x: 0, y: 0, z: 0.027999878}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 3189462245748133917}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: -4.55, y: 5.0000005}
m_SizeDelta: {x: 0, y: 5}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!23 &1313496498328362290
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1391453459713271123}
m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 0
m_DynamicOccludee: 1
m_StaticShadowCaster: 0
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RayTraceProcedural: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 5181339696652704507, guid: b8d4664f5fbc53a42894922de3bc7f8c, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_AdditionalVertexStreams: {fileID: 0}
--- !u!114 &1663807556969581687
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1391453459713271123}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 9541d86e2fd84c1d9990edf0852d74ab, 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: 0.3<size=20>MW</size>
m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: b8d4664f5fbc53a42894922de3bc7f8c, type: 2}
m_sharedMaterial: {fileID: 5181339696652704507, guid: b8d4664f5fbc53a42894922de3bc7f8c,
type: 2}
m_fontSharedMaterials: []
m_fontMaterial: {fileID: 0}
m_fontMaterials: []
m_fontColor32:
serializedVersion: 2
rgba: 4294967295
m_fontColor: {r: 1, g: 1, b: 1, 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: 25
m_fontSizeBase: 25
m_fontWeight: 400
m_enableAutoSizing: 0
m_fontSizeMin: 18
m_fontSizeMax: 72
m_fontStyle: 0
m_HorizontalAlignment: 2
m_VerticalAlignment: 512
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: 0
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.6904383, y: 0.7132971, z: 0.73112583, w: 0.6904204}
m_isUsingLegacyAnimationComponent: 0
m_isVolumetricText: 0
_SortingLayer: 0
_SortingLayerID: 0
_SortingOrder: 0
m_hasFontAssetChanged: 0
m_renderer: {fileID: 1313496498328362290}
m_maskType: 0
--- !u!114 &2802092426076630164
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1391453459713271123}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 3245ec927659c4140ac4f8d17403cc18, type: 3}
m_Name:
m_EditorClassIdentifier:
m_HorizontalFit: 2
m_VerticalFit: 0
--- !u!1 &2903201443363598303
GameObject:
m_ObjectHideFlags: 0
@ -11,8 +198,9 @@ GameObject:
- component: {fileID: 6037173998447792942}
- component: {fileID: 1258097430723790164}
- component: {fileID: 182625262040063529}
- component: {fileID: 7425786837419354187}
m_Layer: 0
m_Name: Count
m_Name: Data
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
@ -25,17 +213,17 @@ RectTransform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2903201443363598303}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: -0.028}
m_LocalRotation: {x: -0, y: 1, z: -0, w: 0}
m_LocalPosition: {x: 0, y: 0, z: 0.027999878}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 6829193728477757397}
m_Father: {fileID: 3189462245748133917}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 20, y: 5}
m_AnchoredPosition: {x: 4.43, y: 5.0000005}
m_SizeDelta: {x: 0, y: 5}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!23 &1258097430723790164
MeshRenderer:
@ -99,7 +287,7 @@ MonoBehaviour:
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_text: "\u4E1C\u8425\u6492(29)"
m_text: "\u70DF\u53F0(1)"
m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: b8d4664f5fbc53a42894922de3bc7f8c, type: 2}
m_sharedMaterial: {fileID: 5181339696652704507, guid: b8d4664f5fbc53a42894922de3bc7f8c,
@ -127,8 +315,8 @@ MonoBehaviour:
m_faceColor:
serializedVersion: 2
rgba: 4294967295
m_fontSize: 16
m_fontSizeBase: 16
m_fontSize: 25
m_fontSizeBase: 25
m_fontWeight: 400
m_enableAutoSizing: 0
m_fontSizeMin: 18
@ -163,7 +351,7 @@ MonoBehaviour:
m_VertexBufferAutoSizeReduction: 0
m_useMaxVisibleDescender: 1
m_pageToDisplay: 1
m_margin: {x: 1.1199245, y: 0.7132971, z: 9.997579, w: 0.6904204}
m_margin: {x: 2.7041607, y: 0.6127169, z: 2.742629, w: 0.6904204}
m_isUsingLegacyAnimationComponent: 0
m_isVolumetricText: 0
_SortingLayer: 0
@ -172,6 +360,20 @@ MonoBehaviour:
m_hasFontAssetChanged: 0
m_renderer: {fileID: 1258097430723790164}
m_maskType: 0
--- !u!114 &7425786837419354187
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2903201443363598303}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 3245ec927659c4140ac4f8d17403cc18, type: 3}
m_Name:
m_EditorClassIdentifier:
m_HorizontalFit: 2
m_VerticalFit: 0
--- !u!1 &3642205659786239540
GameObject:
m_ObjectHideFlags: 0
@ -201,9 +403,7 @@ Transform:
m_LocalPosition: {x: 0, y: 5, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 6037173998447792942}
- {fileID: 6481934859134185512}
m_Children: []
m_Father: {fileID: 3189462245748133917}
m_LocalEulerAnglesHint: {x: 0, y: 180, z: 0}
--- !u!212 &2265163985726705411
@ -252,7 +452,7 @@ SpriteRenderer:
m_FlipX: 0
m_FlipY: 0
m_DrawMode: 1
m_Size: {x: 18, y: 3}
m_Size: {x: 18, y: 4}
m_AdaptiveModeThreshold: 0.5
m_SpriteTileMode: 0
m_WasSpriteAssigned: 1
@ -289,6 +489,8 @@ Transform:
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 6829193728477757397}
- {fileID: 6037173998447792942}
- {fileID: 7961143038953216452}
- {fileID: 2789264866873497265}
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@ -304,181 +506,12 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: deac56328b1a8f14783a00a90bac4bf3, type: 3}
m_Name:
m_EditorClassIdentifier:
countInfo: {fileID: 182625262040063529}
dataInfo: {fileID: 1899281474033451619}
countInfo: {fileID: 1663807556969581687}
dataInfo: {fileID: 182625262040063529}
instructTextBackground: {fileID: 2265163985726705411}
marginHorizontal: 1
marginVertical: 4
isHaveValue: 0
--- !u!1 &8279618592568050451
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 6481934859134185512}
- component: {fileID: 1562423644800345147}
- component: {fileID: 1899281474033451619}
m_Layer: 0
m_Name: Data
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &6481934859134185512
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8279618592568050451}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: -0.028}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 6829193728477757397}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 1.469, y: 0}
m_SizeDelta: {x: 20, y: 5}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!23 &1562423644800345147
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8279618592568050451}
m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 0
m_DynamicOccludee: 1
m_StaticShadowCaster: 0
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RayTraceProcedural: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 5181339696652704507, guid: b8d4664f5fbc53a42894922de3bc7f8c, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_AdditionalVertexStreams: {fileID: 0}
--- !u!114 &1899281474033451619
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8279618592568050451}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 9541d86e2fd84c1d9990edf0852d74ab, 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: 4.789MW
m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: b8d4664f5fbc53a42894922de3bc7f8c, type: 2}
m_sharedMaterial: {fileID: 5181339696652704507, guid: b8d4664f5fbc53a42894922de3bc7f8c,
type: 2}
m_fontSharedMaterials: []
m_fontMaterial: {fileID: 0}
m_fontMaterials: []
m_fontColor32:
serializedVersion: 2
rgba: 4294967295
m_fontColor: {r: 1, g: 1, b: 1, 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: 21
m_fontSizeBase: 21
m_fontWeight: 400
m_enableAutoSizing: 0
m_fontSizeMin: 18
m_fontSizeMax: 72
m_fontStyle: 0
m_HorizontalAlignment: 2
m_VerticalAlignment: 512
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: 0
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: 8.530459, y: 0.55673194, z: 2.5545158, w: 0.5447171}
m_isUsingLegacyAnimationComponent: 0
m_isVolumetricText: 0
_SortingLayer: 0
_SortingLayerID: 0
_SortingOrder: 0
m_hasFontAssetChanged: 0
m_renderer: {fileID: 1562423644800345147}
m_maskType: 0
--- !u!1 &8589215555972230123
GameObject:
m_ObjectHideFlags: 0

File diff suppressed because it is too large Load Diff

View File

@ -69,7 +69,7 @@ public class Bootstrap : MonoSingleton<Bootstrap>
//public Transform provincialCapitalView;
public Button[] cityBtns;
public LevelBtnAttach[] cityBtns;
public Transform lastCity;
@ -112,7 +112,7 @@ public class Bootstrap : MonoSingleton<Bootstrap>
for (int i = 0; i < cityBtns.Length; i++)
{
int index = i;
cityBtns[index].onClick.AddListener(() =>
cityBtns[index].selfBtns.onClick.AddListener(() =>
{
if (index == 1)
SwitchLand(index, true);
@ -124,9 +124,9 @@ public class Bootstrap : MonoSingleton<Bootstrap>
});
}
cityBtns[2].GetComponentInChildren<TMP_Text>().text = "ɽ¶«Ê¡";
cityBtns[1].gameObject.SetActive(false);
cityBtns[0].gameObject.SetActive(false);
cityBtns[2].SetStates(true, true, 2, "ɽ¶«Ê¡");
cityBtns[1].SetStates(false);
cityBtns[0].SetStates(false);
}
@ -237,7 +237,8 @@ public class Bootstrap : MonoSingleton<Bootstrap>
{
case 2:
cameraRt.SetTarget(provincialCapital, 120f);
cityBtns[1].gameObject.SetActive(false);
cityBtns[1].SetStates(false);
cityBtns[2].SetStates(true, true, 2);
//Debug.Log("ĘĄťá");
for (int i = 0; i < cityParents.childCount; i++)
{
@ -255,8 +256,9 @@ public class Bootstrap : MonoSingleton<Bootstrap>
cameraRt.SetTarget(lastCity, 30f);
if (currentArea != null)
currentArea.SetActive(false);
cityBtns[0].gameObject.SetActive(false);
cityBtns[2].interactable = true;
cityBtns[0].SetStates(false);
cityBtns[1].SetStates(true, true, 2);
cityBtns[2].SetStates(true, true, 1);
string disCode = currentArea.GetComponent<CityInfo>().distCode;
if (!string.IsNullOrEmpty(disCode))
currentDistCode = int.Parse(disCode.Substring(0, 4));
@ -273,9 +275,9 @@ public class Bootstrap : MonoSingleton<Bootstrap>
var child = cityParents.GetChild(i).gameObject;
child.SetActive(child.name == clickLand.name);
}
cityBtns[1].gameObject.SetActive(true);
currentDistCode = int.Parse(clickLand.GetComponent<CityInfo>().distCode);
cityBtns[1].GetComponentInChildren<TMP_Text>().text = clickLand.GetComponent<CityInfo>().cityName;
cityBtns[1].SetStates(true, true, 2, clickLand.GetComponent<CityInfo>().cityName);
cityBtns[2].SetStates(true, true, 1);
SwitchMatHide(provincialCapital);
}
}
@ -294,9 +296,9 @@ public class Bootstrap : MonoSingleton<Bootstrap>
}
}
string disCodeTemp = currentArea.GetComponent<CityInfo>().distCode;
cityBtns[0].gameObject.SetActive(true);
cityBtns[0].GetComponentInChildren<TMP_Text>().text = clickLand.GetComponent<CityInfo>().cityName;
cityBtns[2].interactable = false;
cityBtns[0].SetStates(true, true, 2, clickLand.GetComponent<CityInfo>().cityName);
cityBtns[1].SetStates(true, true, 1);
cityBtns[2].SetStates(true, false, 0);
if (!string.IsNullOrEmpty(disCodeTemp))
{
currentDistCode = int.Parse(disCodeTemp);

View File

@ -2,6 +2,9 @@ using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using UnityEngine.UI;
using static UnityEngine.UI.ContentSizeFitter;
using Cysharp.Threading.Tasks;
public class AggregateStation : MonoBehaviour
{
@ -9,14 +12,50 @@ public class AggregateStation : MonoBehaviour
//public SpriteRenderer instruct;
public TMP_Text countInfo;
public TMP_Text dataInfo;
public SpriteRenderer instructTextBackground;
public float marginHorizontal;
public float marginVertical;
public bool isHaveValue;
public void SetInfo(string num, string data)
{
string cityName = transform.parent.name.Substring(0, 2);
countInfo.text = $"{cityName}({num})";
dataInfo.text = $"{data}<size=15>MW</size>";
dataInfo.text = $"{cityName}({num})";
countInfo.text = $"{data}<size=20>MW</size>";
gameObject.SetActive(num != "0");
isHaveValue = num != "0" ? true : false;
//Vector2 size = GetPreferredSize(dataInfo) + GetPreferredSize(countInfo);
//float x = size.x - marginHorizontal;
//float y = size.y - marginVertical;
//instructTextBackground.size = new Vector2(x, y);
}
private void OnEnable()
{
Vector2 size = GetPreferredSize(dataInfo) + GetPreferredSize(countInfo);
float x = size.x - marginHorizontal;
float y = size.y - marginVertical;
instructTextBackground.size = new Vector2(x, y);
}
public Vector2 GetPreferredSize(TMP_Text temp)
{
LayoutRebuilder.ForceRebuildLayoutImmediate(temp.GetComponent<RectTransform>());
return new Vector2((HandleSelfFittingAlongAxis(0, temp)), (HandleSelfFittingAlongAxis(1, temp)));
}
public float HandleSelfFittingAlongAxis(int axis, TMP_Text temp)
{
ContentSizeFitter c = temp.GetComponent<ContentSizeFitter>();
RectTransform r = temp.GetComponent<RectTransform>();
FitMode fitting = (axis == 0 ? c.horizontalFit : c.verticalFit);
if (fitting == FitMode.MinSize)
{
return LayoutUtility.GetMinSize(r, axis);
}
else
{
return LayoutUtility.GetPreferredSize(r, axis);
}
}
}

View File

@ -0,0 +1,32 @@
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class LevelBtnAttach : MonoBehaviour
{
public Sprite[] states;
public Image selfImage;
public Button selfBtns;
public TMP_Text selfText;
public string currrentCityName;
public int index = 0;
void Start()
{
selfImage = GetComponent<Image>();
selfBtns = GetComponent<Button>();
selfText = transform.GetComponentInChildren<TMP_Text>();
}
public void SetStates(bool isOn = true, bool isClick = true, int index = 0, string cityName = "")
{
gameObject.SetActive(isOn);
selfImage.sprite = states[index];
selfBtns.interactable = isClick;
if (cityName != "")
selfText.text = cityName;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1db3b0b730aa63c41bfa8c7be69d0db4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: