181 lines
5.5 KiB
C#
181 lines
5.5 KiB
C#
using System;
|
|
using Animancer;
|
|
using Logic.CrashSight;
|
|
using Logic.Multilingual;
|
|
using RuntimeData;
|
|
using TH1_Logic.Core;
|
|
using TH1_Renderer.Prefab;
|
|
using TH1Renderer;
|
|
using TH1Resource;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
|
|
namespace TH1_Renderer
|
|
{
|
|
public enum BubbleState
|
|
{
|
|
Prepared,
|
|
Playing,
|
|
Finished
|
|
}
|
|
|
|
public class BubbleRenderer
|
|
{
|
|
private BubbleData _bubbleData;
|
|
private BubbleMono _bubbleMono;
|
|
|
|
public BubbleState State;
|
|
private uint _gridId;
|
|
private GridData _gridData;
|
|
public GameObject ROHint; // 实例化的 Hint GameObject
|
|
private Action _onClick;
|
|
|
|
private GameObject _bubble; // 点击用的气泡按钮
|
|
private GameObject _title;
|
|
private GameObject _text; // 显示文字的文本对象
|
|
private GameObject _closeButton; // 关闭按钮
|
|
private GameObject _textPanel; // 包含文字和关闭按钮的面板
|
|
|
|
|
|
public BubbleRenderer(GameObject prefab, Transform father, BubbleData hintData)
|
|
{
|
|
|
|
_gridId = hintData.GridId;
|
|
_bubbleData = hintData;
|
|
State = BubbleState.Finished;
|
|
Main.MapData.GridMap.GetGridDataByGid(_gridId, out _gridData);
|
|
|
|
Vector3 tpos = Table.Instance.GridToWorld(_gridData);
|
|
//ROHint = GameObject.Instantiate(prefab, tpos, Quaternion.identity, father);
|
|
ROHint = GameObject.Instantiate(prefab, father);
|
|
|
|
ROHint.transform.position = tpos;
|
|
ROHint.transform.localRotation = Quaternion.identity;
|
|
ROHint.transform.localScale = Vector3.one;
|
|
|
|
|
|
Init();
|
|
SetInfo();
|
|
}
|
|
|
|
public void SetInfo()
|
|
{
|
|
if (!Table.Instance.HintDataAssets.GetHintInfo(_bubbleData.HintType, out var hintInfo)) return;
|
|
|
|
if (_title == null) LogSystem.LogError($"BubbleRenderer SetInfo _title is null");
|
|
else MultilingualManager.Instance.SetUIText(_title.GetComponent<TextMeshProUGUI>(),hintInfo.HintName);
|
|
|
|
if (_text == null) LogSystem.LogError($"BubbleRenderer SetInfo _text is null");
|
|
else MultilingualManager.Instance.SetUIText(_text.GetComponent<TextMeshProUGUI>(),hintInfo.HintContent);
|
|
_onClick = _bubbleData.BubbleType switch
|
|
{
|
|
BubbleType.Gather => BubbleGather,
|
|
BubbleType.Examine => BubbleExamine,
|
|
BubbleType.Capture => BubbleExamine,
|
|
BubbleType.Upgrade => BubbleExamine,
|
|
_ => NoneAction
|
|
};
|
|
}
|
|
|
|
public void SetFinished() { State = BubbleState.Finished; }
|
|
|
|
public void NoneAction()
|
|
{
|
|
|
|
}
|
|
|
|
//收集还行
|
|
public void BubbleGather()
|
|
{
|
|
if (false) return;
|
|
}
|
|
public void BubbleExamine()
|
|
{
|
|
if (false) return;
|
|
}
|
|
|
|
public void BubbleUpgrade()
|
|
{
|
|
if (false) return;
|
|
}
|
|
|
|
public void BubbleCapture()
|
|
{
|
|
if (false) return;
|
|
}
|
|
|
|
public void Update() { }
|
|
|
|
public void Init()
|
|
{
|
|
_bubbleMono = ROHint.GetComponent<BubbleMono>();
|
|
if (_bubbleMono == null) return;
|
|
|
|
// 默认全部隐藏
|
|
if (_bubble != null) _bubble.SetActive(false);
|
|
|
|
// 初始化气泡
|
|
if (_bubble != null)
|
|
{
|
|
// 绑定点击事件:点击气泡后显示文字面板
|
|
var btn = _bubble.GetComponent<UnityEngine.UI.Button>();
|
|
if (btn != null)
|
|
{
|
|
btn.onClick.RemoveAllListeners();
|
|
btn.onClick.AddListener(OnClicked);
|
|
State = BubbleState.Prepared;
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 外部主动触发:显示气泡并播放动画
|
|
/// </summary>
|
|
public void StartBubble()
|
|
{
|
|
if (_bubble != null)
|
|
{
|
|
_bubble.SetActive(true);
|
|
State = BubbleState.Playing;
|
|
var animancer = _bubble.GetComponent<AnimancerComponent>();
|
|
if (animancer != null)
|
|
{
|
|
animancer.Play(ResourceCache.Instance.AnimCache.HintBubbleShow);
|
|
Timer.Instance.TimerRegister(this, () =>
|
|
{
|
|
animancer.Play(ResourceCache.Instance.AnimCache.HintBubbleIdle);
|
|
},0.25f,"HintRenderer_StartBubble");
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
public void OnClicked()
|
|
{
|
|
HideBubble();
|
|
State = BubbleState.Finished;
|
|
_onClick.Invoke();
|
|
}
|
|
|
|
public void HideBubble()
|
|
{
|
|
|
|
var animancer = _bubble.GetComponent<AnimancerComponent>();
|
|
animancer.Play(ResourceCache.Instance.AnimCache.HintBubbleHide);
|
|
var timeToWait = 0f;
|
|
if (ResourceCache.Instance.AnimCache.HintBubbleHide != null)
|
|
timeToWait = ResourceCache.Instance.AnimCache.HintBubbleHide.length;
|
|
Timer.Instance.TimerRegister(this, () =>
|
|
{
|
|
_bubble.SetActive(false);
|
|
},timeToWait,"HintRender_HideBubble");
|
|
|
|
}
|
|
|
|
|
|
}
|
|
}
|