//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Thursday, October 26, 2017
|
//--------------------------------------------------------
|
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
namespace Snxxz.UI
|
{
|
|
public class StatusTipWin : Window
|
{
|
|
private List<TipController> m_TipList = new List<TipController>();
|
private Stack<TipController> m_FreeList = new Stack<TipController>();
|
private List<TipController> m_RemoveList = new List<TipController>();
|
|
public int displayCount;
|
public float moveDuration;
|
public int space;
|
|
public bool useLanguage;
|
public string tip = "您获得了<color=red>[{0}]</color>的状态";
|
public TipController original;
|
|
private bool m_StartMove;
|
private Vector2 m_DistanceOffset;
|
private float m_MoveSpeed;
|
private float m_MoveDistance;
|
private float m_MoveTime;
|
private float m_TopLimit;
|
|
bool inited = false;
|
|
[SerializeField] RectTransform m_ContainerSpecialBuff;
|
[SerializeField] PositionTween m_SpeicalBuffTween;
|
[SerializeField] UIAlphaTween m_SpecialBuffAlplaTween;
|
[SerializeField] int m_SpecialBuffId;
|
#region Built-in
|
protected override void BindController()
|
{
|
|
}
|
|
protected override void AddListeners()
|
{
|
}
|
|
protected override void OnPreOpen()
|
{
|
StatusMgr.OnGainStatus += OnGainStatus;
|
for (int i = 0; i < m_TipList.Count; ++i)
|
{
|
m_TipList[i].Recyle();
|
m_FreeList.Push(m_TipList[i]);
|
}
|
m_TipList.Clear();
|
m_ContainerSpecialBuff.gameObject.SetActive(false);
|
}
|
|
protected override void LateUpdate()
|
{
|
base.LateUpdate();
|
|
//if (Input.GetKeyDown(KeyCode.Space))
|
//{
|
// OnGainStatus("测试测试");
|
//}
|
|
if (m_MoveTime > 0)
|
{
|
for (int i = 0; i < m_TipList.Count; ++i)
|
{
|
m_TipList[i].rectTransform.anchoredPosition += Vector2.up * m_MoveSpeed * Time.deltaTime;
|
|
if (m_TipList[i].rectTransform.anchoredPosition.y > m_TopLimit)
|
{
|
if (!m_RemoveList.Contains(m_TipList[i]))
|
{
|
m_RemoveList.Add(m_TipList[i]);
|
|
//Debug.LogFormat("checkY: {0}, originalY: {1}, topY: {2}",
|
// m_TipList[i].rectTransform.anchoredPosition.y,
|
// original.rectTransform.anchoredPosition.y,
|
// m_TopLimit);
|
}
|
}
|
|
if (m_TipList[i].rectTransform.anchoredPosition.y > original.rectTransform.anchoredPosition.y)
|
{
|
m_TipList[i].Play();
|
}
|
|
}
|
|
m_MoveTime -= Time.deltaTime;
|
|
if (m_MoveTime < 0)
|
{
|
m_MoveTime = 0;
|
}
|
}
|
|
for (int i = 0; i < m_TipList.Count; ++i)
|
{
|
if (m_TipList[i].isFadeOut)
|
{
|
if (!m_RemoveList.Contains(m_TipList[i]))
|
{
|
m_RemoveList.Add(m_TipList[i]);
|
}
|
}
|
|
}
|
|
for (int i = 0; i < m_RemoveList.Count; ++i)
|
{
|
m_RemoveList[i].Recyle();
|
m_TipList.Remove(m_RemoveList[i]);
|
m_FreeList.Push(m_RemoveList[i]);
|
}
|
|
m_RemoveList.Clear();
|
}
|
|
protected override void OnAfterOpen()
|
{
|
}
|
|
protected override void OnPreClose()
|
{
|
StatusMgr.OnGainStatus -= OnGainStatus;
|
for (int i = 0; i < m_TipList.Count; ++i)
|
{
|
m_TipList[i].Recyle();
|
}
|
m_TipList.Clear();
|
|
while (m_FreeList.Count > 0)
|
{
|
var behaviour = m_FreeList.Pop();
|
behaviour.Recyle();
|
}
|
}
|
|
protected override void OnAfterClose()
|
{
|
}
|
|
protected override void OnActived()
|
{
|
base.OnActived();
|
|
if (!inited)
|
{
|
m_MoveDistance = original.rectTransform.sizeDelta.y + space;
|
m_MoveSpeed = m_MoveDistance / moveDuration;
|
m_TopLimit = original.rectTransform.anchoredPosition.y;
|
m_TopLimit += (original.rectTransform.sizeDelta.y + space) * displayCount;
|
original.gameObject.SetActive(false);
|
inited = true;
|
}
|
}
|
|
#endregion
|
|
private void OnGainStatus(int skillId)
|
{
|
var skillConfig = SkillConfig.Get(skillId);
|
if (skillConfig != null)
|
{
|
if (skillConfig.SkillTypeID == m_SpecialBuffId)
|
{
|
DisplaySpecialTip();
|
}
|
else
|
{
|
DisplayLabelTip(skillConfig.SkillName);
|
}
|
}
|
}
|
|
void DisplayLabelTip(string buffName)
|
{
|
TipController _newController = null;
|
if (m_FreeList.Count > 0)
|
{
|
_newController = m_FreeList.Pop();
|
}
|
else
|
{
|
GameObject _new = Instantiate(original.gameObject);
|
_newController = _new.GetComponent<TipController>();
|
}
|
string _content = string.Format(tip, buffName);
|
_newController.Init(_content);
|
_newController.transform.SetParent(transform);
|
if (m_TipList.Count == 0)
|
{
|
_newController.transform.localPosition = original.transform.localPosition;
|
}
|
else
|
{
|
_newController.transform.localPosition = m_TipList[m_TipList.Count - 1].transform.localPosition - new Vector3(0, m_MoveDistance, 0);
|
}
|
_newController.transform.localScale = original.transform.localScale;
|
|
m_TipList.Add(_newController);
|
|
m_MoveTime += moveDuration;
|
}
|
|
void DisplaySpecialTip()
|
{
|
transform.SetAsLastSibling();
|
m_SpeicalBuffTween.SetStartState();
|
m_SpecialBuffAlplaTween.SetStartState();
|
m_SpeicalBuffTween.enabled = false;
|
m_SpecialBuffAlplaTween.enabled = false;
|
m_ContainerSpecialBuff.gameObject.SetActive(true);
|
m_SpeicalBuffTween.enabled = true;
|
m_SpeicalBuffTween.Play(OnSpecialBuffComplete);
|
}
|
|
private void OnSpecialBuffComplete()
|
{
|
m_SpecialBuffAlplaTween.enabled = true;
|
m_SpecialBuffAlplaTween.Play(OnSpecialBuffAlphaComplete);
|
}
|
|
private void OnSpecialBuffAlphaComplete()
|
{
|
m_ContainerSpecialBuff.gameObject.SetActive(false);
|
}
|
}
|
|
|
}
|
|
|
|
|