Compare commits
2 Commits
01ddeb3bb9
...
02f42a6201
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
02f42a6201 | ||
|
|
68cdc0bfc6 |
8
Assets/Gameplay/Resources/UIElement.meta
Normal file
8
Assets/Gameplay/Resources/UIElement.meta
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 4328eae6d5fca594caa6478b215c8dfb
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
188
Assets/Gameplay/Resources/UIElement/MessageElement.prefab
Normal file
188
Assets/Gameplay/Resources/UIElement/MessageElement.prefab
Normal file
@@ -0,0 +1,188 @@
|
|||||||
|
%YAML 1.1
|
||||||
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
|
--- !u!1 &5061647711168035207
|
||||||
|
GameObject:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
serializedVersion: 6
|
||||||
|
m_Component:
|
||||||
|
- component: {fileID: 8062437110539039050}
|
||||||
|
- component: {fileID: 8014471761701525819}
|
||||||
|
- component: {fileID: 2391606645527795103}
|
||||||
|
m_Layer: 5
|
||||||
|
m_Name: Message
|
||||||
|
m_TagString: Untagged
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 1
|
||||||
|
--- !u!224 &8062437110539039050
|
||||||
|
RectTransform:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 5061647711168035207}
|
||||||
|
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: 3272154471127507218}
|
||||||
|
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: 300, y: 60}
|
||||||
|
m_Pivot: {x: 0.5, y: 0.5}
|
||||||
|
--- !u!222 &8014471761701525819
|
||||||
|
CanvasRenderer:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 5061647711168035207}
|
||||||
|
m_CullTransparentMesh: 1
|
||||||
|
--- !u!114 &2391606645527795103
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 5061647711168035207}
|
||||||
|
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: New Text
|
||||||
|
m_isRightToLeft: 0
|
||||||
|
m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
|
||||||
|
m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, 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: 36
|
||||||
|
m_fontSizeBase: 36
|
||||||
|
m_fontWeight: 400
|
||||||
|
m_enableAutoSizing: 0
|
||||||
|
m_fontSizeMin: 18
|
||||||
|
m_fontSizeMax: 72
|
||||||
|
m_fontStyle: 0
|
||||||
|
m_HorizontalAlignment: 4
|
||||||
|
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_TextWrappingMode: 0
|
||||||
|
m_wordWrappingRatios: 0.4
|
||||||
|
m_overflowMode: 0
|
||||||
|
m_linkedTextComponent: {fileID: 0}
|
||||||
|
parentLinkedComponent: {fileID: 0}
|
||||||
|
m_enableKerning: 0
|
||||||
|
m_ActiveFontFeatures: 6e72656b
|
||||||
|
m_enableExtraPadding: 0
|
||||||
|
checkPaddingRequired: 0
|
||||||
|
m_isRichText: 1
|
||||||
|
m_EmojiFallbackSupport: 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 &8692905588342055126
|
||||||
|
GameObject:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
serializedVersion: 6
|
||||||
|
m_Component:
|
||||||
|
- component: {fileID: 3272154471127507218}
|
||||||
|
- component: {fileID: 2592335091632914261}
|
||||||
|
m_Layer: 5
|
||||||
|
m_Name: MessageElement
|
||||||
|
m_TagString: Untagged
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 1
|
||||||
|
--- !u!224 &3272154471127507218
|
||||||
|
RectTransform:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 8692905588342055126}
|
||||||
|
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:
|
||||||
|
- {fileID: 8062437110539039050}
|
||||||
|
m_Father: {fileID: 0}
|
||||||
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
|
m_AnchorMin: {x: 1, y: 1}
|
||||||
|
m_AnchorMax: {x: 1, y: 1}
|
||||||
|
m_AnchoredPosition: {x: 0, y: 0}
|
||||||
|
m_SizeDelta: {x: 300, y: 60}
|
||||||
|
m_Pivot: {x: 1, y: 1}
|
||||||
|
--- !u!114 &2592335091632914261
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 8692905588342055126}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: 6a0067f01fbaadf478392b05bee47a0d, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
messageText: {fileID: 2391606645527795103}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: a6ec0dbfc517dbb48a1068c730460a19
|
||||||
|
PrefabImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
97
Assets/Gameplay/Resources/UIPanel/MessagePanel.prefab
Normal file
97
Assets/Gameplay/Resources/UIPanel/MessagePanel.prefab
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
%YAML 1.1
|
||||||
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
|
--- !u!1 &443750150023295006
|
||||||
|
GameObject:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
serializedVersion: 6
|
||||||
|
m_Component:
|
||||||
|
- component: {fileID: 3533661521810076078}
|
||||||
|
- component: {fileID: 5853945544556872844}
|
||||||
|
- component: {fileID: 7823836936872427456}
|
||||||
|
m_Layer: 5
|
||||||
|
m_Name: MessagePanel
|
||||||
|
m_TagString: Untagged
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 1
|
||||||
|
--- !u!224 &3533661521810076078
|
||||||
|
RectTransform:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 443750150023295006}
|
||||||
|
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:
|
||||||
|
- {fileID: 8154055666567944616}
|
||||||
|
m_Father: {fileID: 0}
|
||||||
|
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_Pivot: {x: 0.5, y: 0.5}
|
||||||
|
--- !u!222 &5853945544556872844
|
||||||
|
CanvasRenderer:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 443750150023295006}
|
||||||
|
m_CullTransparentMesh: 1
|
||||||
|
--- !u!114 &7823836936872427456
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 443750150023295006}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: d9d93c1e7bfbced4cb3128c5c42890b8, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
messageElementPrefab: {fileID: 2592335091632914261, guid: a6ec0dbfc517dbb48a1068c730460a19, type: 3}
|
||||||
|
content: {fileID: 8154055666567944616}
|
||||||
|
--- !u!1 &1676423706689725415
|
||||||
|
GameObject:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
serializedVersion: 6
|
||||||
|
m_Component:
|
||||||
|
- component: {fileID: 8154055666567944616}
|
||||||
|
m_Layer: 5
|
||||||
|
m_Name: Content
|
||||||
|
m_TagString: Untagged
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 1
|
||||||
|
--- !u!224 &8154055666567944616
|
||||||
|
RectTransform:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1676423706689725415}
|
||||||
|
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: 3533661521810076078}
|
||||||
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
|
m_AnchorMin: {x: 1, y: 0.5}
|
||||||
|
m_AnchorMax: {x: 1, y: 0.5}
|
||||||
|
m_AnchoredPosition: {x: 0, y: 0}
|
||||||
|
m_SizeDelta: {x: 300, y: 400}
|
||||||
|
m_Pivot: {x: 1, y: 0.5}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: a53e8aec56290604399ba08fdbb7c594
|
||||||
|
PrefabImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using A2W;
|
using A2W;
|
||||||
|
using Cysharp.Threading.Tasks;
|
||||||
|
|
||||||
public class LaunchManager : SceneSingleton<LaunchManager>
|
public class LaunchManager : SceneSingleton<LaunchManager>
|
||||||
{
|
{
|
||||||
@@ -8,5 +9,17 @@ public class LaunchManager : SceneSingleton<LaunchManager>
|
|||||||
UIManager.instance.Init();
|
UIManager.instance.Init();
|
||||||
|
|
||||||
await UIManager.instance.ShowPanel<LaunchPanel>();
|
await UIManager.instance.ShowPanel<LaunchPanel>();
|
||||||
|
|
||||||
|
//await UniTask.Delay(2000);
|
||||||
|
|
||||||
|
//var panel = await UIManager.instance.ShowPanel<MessagePanel>();
|
||||||
|
|
||||||
|
//await UniTask.Delay(2000);
|
||||||
|
|
||||||
|
//panel.AddMessage("Test Message Forever");
|
||||||
|
|
||||||
|
//await UniTask.Delay(2000);
|
||||||
|
|
||||||
|
//panel.AddMessage("Test Message 2s", 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
8
Assets/Gameplay/Scripts/UI/Element.meta
Normal file
8
Assets/Gameplay/Scripts/UI/Element.meta
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 5fd248778c5af0f4ea63115e6bcc3ab5
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
86
Assets/Gameplay/Scripts/UI/Element/MessageElement.cs
Normal file
86
Assets/Gameplay/Scripts/UI/Element/MessageElement.cs
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using MonsterLove.StateMachine;
|
||||||
|
using DG.Tweening;
|
||||||
|
|
||||||
|
public enum MessageStates
|
||||||
|
{
|
||||||
|
Init,
|
||||||
|
Add,
|
||||||
|
Show,
|
||||||
|
Del
|
||||||
|
}
|
||||||
|
|
||||||
|
public class MessageElement : MonoBehaviour
|
||||||
|
{
|
||||||
|
[SerializeField] TMPro.TextMeshProUGUI messageText;
|
||||||
|
|
||||||
|
public RectTransform RectTransform
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return transform as RectTransform;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Message { get; private set; }
|
||||||
|
|
||||||
|
private float remaining;
|
||||||
|
|
||||||
|
private MessagePanel panel;
|
||||||
|
|
||||||
|
StateMachine<MessageStates> fsm;
|
||||||
|
|
||||||
|
public void Init(MessagePanel panel, string message, float duration)
|
||||||
|
{
|
||||||
|
this.panel = panel;
|
||||||
|
|
||||||
|
Message = message;
|
||||||
|
remaining = duration;
|
||||||
|
|
||||||
|
if (remaining < 0)
|
||||||
|
{
|
||||||
|
remaining = float.MaxValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fsm is null)
|
||||||
|
{
|
||||||
|
fsm = StateMachine<MessageStates>.Initialize(this);
|
||||||
|
}
|
||||||
|
fsm.ChangeState(MessageStates.Init);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Init_Enter()
|
||||||
|
{
|
||||||
|
// 这里初始化,包括位置和消息信息
|
||||||
|
messageText.text = Message;
|
||||||
|
messageText.rectTransform.anchoredPosition = new Vector2(messageText.rectTransform.rect.width, 0);
|
||||||
|
|
||||||
|
fsm.ChangeState(MessageStates.Add);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Add_Enter()
|
||||||
|
{
|
||||||
|
// 这里播动画
|
||||||
|
messageText.rectTransform.DOAnchorPosX(0, 0.2f);
|
||||||
|
|
||||||
|
fsm.ChangeState(MessageStates.Show);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Show_Update()
|
||||||
|
{
|
||||||
|
remaining -= Time.deltaTime;
|
||||||
|
if (remaining <= 0)
|
||||||
|
{
|
||||||
|
remaining = float.MaxValue;
|
||||||
|
fsm.ChangeState(MessageStates.Del);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Del_Enter()
|
||||||
|
{
|
||||||
|
// 理论上这里也需要做个动画,先不管了
|
||||||
|
|
||||||
|
panel.DelMessage(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 6a0067f01fbaadf478392b05bee47a0d
|
||||||
79
Assets/Gameplay/Scripts/UI/MessagePanel.cs
Normal file
79
Assets/Gameplay/Scripts/UI/MessagePanel.cs
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using A2W;
|
||||||
|
using Cysharp.Threading.Tasks;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using DG.Tweening;
|
||||||
|
|
||||||
|
public class MessagePanel : UIPanel
|
||||||
|
{
|
||||||
|
[SerializeField] MessageElement messageElementPrefab;
|
||||||
|
[SerializeField] RectTransform content;
|
||||||
|
|
||||||
|
List<MessageElement> messages;
|
||||||
|
|
||||||
|
public override void Init()
|
||||||
|
{
|
||||||
|
messages = new List<MessageElement>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async UniTask Show()
|
||||||
|
{
|
||||||
|
await UniTask.Yield();
|
||||||
|
|
||||||
|
gameObject.SetActive(true);
|
||||||
|
}
|
||||||
|
public override async UniTask Hide()
|
||||||
|
{
|
||||||
|
await UniTask.Yield();
|
||||||
|
|
||||||
|
gameObject.SetActive(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddMessage(string message, float duration = -1)
|
||||||
|
{
|
||||||
|
// 默认加到开头
|
||||||
|
AddMessage(message, duration, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddMessage(string message, float duration, int index)
|
||||||
|
{
|
||||||
|
var msgEle = Instantiate<MessageElement>(messageElementPrefab, content, false);
|
||||||
|
msgEle.Init(this, message, duration);
|
||||||
|
//messages.Add(msgEle);
|
||||||
|
messages.Insert(index, msgEle);
|
||||||
|
|
||||||
|
|
||||||
|
UpdateMessagesPosY();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DelMessage(string message)
|
||||||
|
{
|
||||||
|
foreach (var msg in messages)
|
||||||
|
{
|
||||||
|
if (msg.Message == message)
|
||||||
|
{
|
||||||
|
DelMessage(msg);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async void DelMessage(MessageElement msgEle)
|
||||||
|
{
|
||||||
|
messages.Remove(msgEle);
|
||||||
|
Destroy(msgEle.gameObject);
|
||||||
|
|
||||||
|
await UniTask.Yield();
|
||||||
|
|
||||||
|
UpdateMessagesPosY();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdateMessagesPosY()
|
||||||
|
{
|
||||||
|
// 根据messageElement的index使用Dotween移动PosY到指定位置(-index * Height
|
||||||
|
for (int i = 0; i < messages.Count; i++)
|
||||||
|
{
|
||||||
|
messages[i].RectTransform.DOAnchorPosY(-i * messages[i].RectTransform.rect.height, 0.2f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
2
Assets/Gameplay/Scripts/UI/MessagePanel.cs.meta
Normal file
2
Assets/Gameplay/Scripts/UI/MessagePanel.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: d9d93c1e7bfbced4cb3128c5c42890b8
|
||||||
Reference in New Issue
Block a user