//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Saturday, October 07, 2017
|
//--------------------------------------------------------
|
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
namespace vnxbqy.UI
|
{
|
|
public class ScrollTipWin : Window
|
{
|
[SerializeField] RectTransform content;
|
[SerializeField] RectTransform mask;
|
|
[SerializeField, Header("显示条数")]
|
int tipDisplayCnt = 3;
|
[SerializeField, Header("每次滚动的距离")]
|
float m_TipDistance = 50.0f;
|
[SerializeField, Header("提示预制体高度")]
|
float m_TipHeight = 40.0f;
|
[SerializeField, Header("显示时间")]
|
float m_TipShowTime = 1.0f;
|
[SerializeField, Header("移动时间")]
|
float m_TipMoveTime = 0.2f;
|
[SerializeField, Header("隐藏时间")]
|
float m_TipHideTime = 0.5f;
|
#region Win
|
protected override void AddListeners()
|
{
|
|
}
|
|
protected override void BindController()
|
{
|
|
}
|
|
protected override void OnAfterClose()
|
{
|
|
}
|
|
protected override void OnAfterOpen()
|
{
|
|
}
|
|
protected override void OnPreClose()
|
{
|
ScrollTip.OnTipReceiveEvent -= OnTipReceiveEvent;
|
ScrollTip.ReleaseAll();
|
}
|
|
protected override void OnPreOpen()
|
{
|
ScrollTip.tipMoveTime = m_TipMoveTime;
|
ScrollTip.OnTipReceiveEvent += OnTipReceiveEvent;
|
mask.sizeDelta = mask.sizeDelta.SetY(tipDisplayCnt * m_TipHeight + (tipDisplayCnt - 1) * (m_TipDistance - m_TipHeight) + 10);
|
for (int i = 0; i < ScrollTip.m_Hints.Count; i++)
|
{
|
OnTipReceiveEvent();
|
}
|
}
|
|
protected override void LateUpdate()
|
{
|
base.LateUpdate();
|
}
|
#endregion
|
|
private void OnTipReceiveEvent()
|
{
|
if (ScrollTip.m_Hints.Count > 0 && IsCanAdd())
|
{
|
if (ScrollTip.m_ActiveTips.Count >= tipDisplayCnt)
|
{
|
ScrollTip.Release(ScrollTip.m_ActiveTips[0], false);
|
}
|
if (ScrollTip.m_ActiveTips.Count >= tipDisplayCnt)
|
{
|
ScrollTip.tipMoveTime = Time.deltaTime;
|
}
|
else
|
{
|
ScrollTip.tipMoveTime = m_TipMoveTime;
|
}
|
for (int i = 0; i < ScrollTip.m_ActiveTips.Count; i++)
|
{
|
ScrollTip.m_ActiveTips[i].Play(ScrollTip.ScrollTipState.Move);
|
}
|
ScrollTipDetail tipDetail = ScrollTip.Request();
|
if (tipDetail != null)
|
{
|
tipDetail.SetTipConfig(m_TipShowTime, m_TipHideTime, m_TipDistance);
|
ScrollTip.m_ActiveTips.Add(tipDetail);
|
var rt = tipDetail.transform;
|
rt.SetParent(content.parent);
|
rt.localScale = Vector3.one;
|
rt.localPosition = content.localPosition;
|
var _hint = ScrollTip.m_Hints[0];
|
ScrollTip.m_Hints.RemoveAt(0);
|
tipDetail.ShowTip(_hint);
|
tipDetail.Play(ScrollTip.ScrollTipState.Idle);
|
}
|
}
|
}
|
|
private bool IsCanAdd()
|
{
|
for (int i = 0; i < ScrollTip.m_ActiveTips.Count; i++)
|
{
|
if (ScrollTip.m_ActiveTips[i].presentState == ScrollTip.ScrollTipState.Move)
|
{
|
return false;
|
}
|
}
|
return true;
|
}
|
}
|
|
}
|
|
|
|
|