156 lines
4.2 KiB
C#
156 lines
4.2 KiB
C#
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
using QFramework;
|
||
using System.Collections.Generic;
|
||
using DG.Tweening;
|
||
using DG.Tweening.Core;
|
||
using DG.Tweening.Plugins.Options;
|
||
|
||
namespace QFramework.Example
|
||
{
|
||
public class UITimeTipData : UIPanelData
|
||
{
|
||
public float time;
|
||
public string label;
|
||
public List<ValueItem> values = new List<ValueItem>();
|
||
public string finishedEvent;
|
||
public bool needClick = false;
|
||
public bool reverse = false;
|
||
public string format;
|
||
public class ValueItem
|
||
{
|
||
public float curValue;
|
||
public float startValue;
|
||
public float endValue;
|
||
|
||
public ValueItem(float startValue, float endValue)
|
||
{
|
||
this.curValue = startValue;
|
||
this.startValue = startValue;
|
||
this.endValue = endValue;
|
||
}
|
||
}
|
||
}
|
||
public partial class UITimeTip : UIPanel
|
||
{
|
||
public List<Sprite> sprites;
|
||
bool isRun = false;
|
||
List<TweenerCore<float, float, FloatOptions>> dotwens = new List<TweenerCore<float, float, FloatOptions>>();
|
||
TweenerCore<int, int, NoOptions> imgTwen;
|
||
int index = 0;
|
||
protected override void OnInit(IUIData uiData = null)
|
||
{
|
||
mData = uiData as UITimeTipData ?? new UITimeTipData();
|
||
// please add init code here
|
||
TypeEventSystem.Global.Register<OnModuleQuit>((arg) => Hide()).UnRegisterWhenGameObjectDestroyed(gameObject);
|
||
}
|
||
|
||
private void Update()
|
||
{
|
||
if (isRun)
|
||
{
|
||
object[] objects = new object[mData.values.Count];
|
||
for (int i = 0; i < mData.values.Count; i++)
|
||
{
|
||
if (string.IsNullOrEmpty(mData.format) == false)
|
||
{
|
||
|
||
objects[i] = string.Format(mData.format, mData.values[i].curValue);
|
||
}
|
||
else
|
||
{
|
||
objects[i] = mData.values[i].curValue;
|
||
}
|
||
}
|
||
|
||
Label.text = string.Format(mData.label, objects);
|
||
}
|
||
|
||
|
||
}
|
||
|
||
|
||
|
||
protected override void OnOpen(IUIData uiData = null)
|
||
{
|
||
mData = uiData as UITimeTipData ?? new UITimeTipData();
|
||
index = 0;
|
||
isRun = true;
|
||
int endIndex = sprites.Count - 1;
|
||
if (mData.reverse)
|
||
{
|
||
index = sprites.Count;
|
||
endIndex = 0;
|
||
}
|
||
imgTwen = DOTween.To(() => index, v =>
|
||
{
|
||
index = v;
|
||
if (index >= 0 && index < sprites.Count)
|
||
{
|
||
Img.sprite = sprites[index];
|
||
Img.SetNativeSize();
|
||
}
|
||
else
|
||
{
|
||
Debug.LogError("ͼƬ<CDBC><C6AC><EFBFBD><EFBFBD>Խ<EFBFBD><D4BD>");
|
||
}
|
||
|
||
}, endIndex, mData.time);
|
||
|
||
imgTwen.SetEase(Ease.Linear).onComplete = () =>
|
||
{
|
||
if (string.IsNullOrEmpty(mData.finishedEvent) == false)
|
||
{
|
||
StringEventSystem.Global.Send(mData.finishedEvent);
|
||
}
|
||
if (mData.needClick == true)
|
||
{
|
||
Bg.onClick.RemoveAllListeners();
|
||
Bg.onClick.AddListener(Hide);
|
||
}
|
||
else
|
||
{
|
||
Hide();
|
||
}
|
||
isRun = false;
|
||
};
|
||
foreach (var item in mData.values)
|
||
{
|
||
|
||
dotwens.Add(DOTween.To(() => item.curValue, x =>
|
||
{
|
||
item.curValue = x;
|
||
|
||
}, item.endValue, mData.time));
|
||
|
||
}
|
||
|
||
|
||
|
||
}
|
||
|
||
protected override void OnShow()
|
||
{
|
||
|
||
}
|
||
|
||
protected override void OnHide()
|
||
{
|
||
foreach (var item in dotwens)
|
||
{
|
||
item.Kill();
|
||
}
|
||
dotwens.Clear();
|
||
if (imgTwen != null)
|
||
{
|
||
imgTwen.Kill();
|
||
imgTwen = null;
|
||
}
|
||
}
|
||
|
||
protected override void OnClose()
|
||
{
|
||
}
|
||
}
|
||
}
|