You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
133 lines
3.3 KiB
133 lines
3.3 KiB
using System;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UnityEngine.Assertions;
|
|
|
|
public partial class GamePlayBuffCoolTimeView : View
|
|
{
|
|
[SerializeField] SlotUI[] slots;
|
|
|
|
int activeBuffCount = 0;
|
|
|
|
private void Start()
|
|
{
|
|
for(int i = 0; i < slots.Length; ++i)
|
|
{
|
|
slots[i].SetBuffData(null);
|
|
}
|
|
|
|
Show();
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
for(int i = 0; i < activeBuffCount; i++)
|
|
{
|
|
var slot = slots[i];
|
|
if (slot.buffData is null) continue;
|
|
|
|
slot.Update();
|
|
|
|
if (slot.buffData.RemainTime <= 0)
|
|
{
|
|
for(int j = i; j < activeBuffCount - 1; j++)
|
|
{
|
|
BuffData tmp;
|
|
tmp = slots[j].buffData;
|
|
slots[j].SetBuffData(slots[j + 1].buffData);
|
|
slots[j + 1].SetBuffData(tmp);
|
|
}
|
|
|
|
activeBuffCount--;
|
|
slots[activeBuffCount].SetBuffData(null);
|
|
i--;
|
|
}
|
|
}
|
|
}
|
|
|
|
public override void Show()
|
|
{
|
|
GamePlayBuffMgr.Instance.BuffGroup.OnChanged += RefreshBuffList;
|
|
|
|
viewState = ViewState.Shown;
|
|
gameObject.SetActive(true);
|
|
}
|
|
|
|
public override void Hide()
|
|
{
|
|
gameObject.SetActive(false);
|
|
viewState = ViewState.Hidden;
|
|
|
|
GamePlayBuffMgr.Instance.BuffGroup.OnChanged -= RefreshBuffList;
|
|
}
|
|
|
|
public void RefreshBuffList(BuffData buffData, bool added)
|
|
{
|
|
if(added)
|
|
{
|
|
Debug.Assert(activeBuffCount + 1 < slots.Length, "Buff count exid slot count");
|
|
activeBuffCount++;
|
|
slots[activeBuffCount - 1].SetBuffData(buffData);
|
|
}
|
|
else
|
|
{
|
|
for(int i = 0; i < activeBuffCount; i++)
|
|
{
|
|
if (slots[i].buffData == buffData)
|
|
{
|
|
for(int j = i; j < activeBuffCount - 1; j++)
|
|
{
|
|
BuffData tmp;
|
|
tmp = slots[j].buffData;
|
|
slots[j].SetBuffData(slots[j + 1].buffData);
|
|
slots[j + 1].SetBuffData(tmp);
|
|
}
|
|
|
|
activeBuffCount--;
|
|
slots[activeBuffCount].SetBuffData(null);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public partial class GamePlayBuffCoolTimeView : View
|
|
{
|
|
[Serializable]
|
|
struct SlotUI
|
|
{
|
|
public GameObject root;
|
|
public ExtendImage backGroundImage;
|
|
public ExtendImage buffImage;
|
|
public Image remainTimeFillImg;
|
|
public BuffData buffData { get; private set; }
|
|
|
|
public void SetBuffData(BuffData buffData)
|
|
{
|
|
this.buffData = buffData;
|
|
|
|
if(buffData is null)
|
|
{
|
|
root.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
root.SetActive(true);
|
|
|
|
//TODO: Set buff image
|
|
}
|
|
}
|
|
|
|
public void Update()
|
|
{
|
|
if (remainTimeFillImg is null) return;
|
|
|
|
float fillRate = 0f;
|
|
if(!buffData.IsInfiniteDuration)
|
|
fillRate = buffData.ElapsedDuration / buffData.Duration;
|
|
|
|
remainTimeFillImg.fillAmount = fillRate;
|
|
}
|
|
}
|
|
}
|