//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Thursday, September 14, 2017
|
//--------------------------------------------------------
|
using UnityEngine;
|
using System.Collections;
|
using UnityEngine.UI;
|
using System.Collections.Generic;
|
|
namespace Snxxz.UI
|
{
|
|
public class ExperienceFloat : MonoBehaviour
|
{
|
[SerializeField] ScreenMoveTo m_MoveTo;
|
[SerializeField] UIAlphaTween m_AlphaTween;
|
|
[SerializeField] Text m_Experience;
|
[SerializeField] Text m_ExperienceRate;
|
|
public Pattern pattern { get; set; }
|
|
int sourceBuf = -1;
|
long experienceBuf = 0;
|
int experienceRateBuf = 0;
|
|
private void Start()
|
{
|
|
}
|
|
public void Begin(int _source, long _experience)
|
{
|
if (experienceBuf != _experience)
|
{
|
experienceBuf = _experience;
|
m_Experience.text = StringUtility.Contact("+$", _experience);
|
}
|
|
if (sourceBuf != _source || experienceRateBuf != PlayerDatas.Instance.totalExpRate)
|
{
|
sourceBuf = _source;
|
experienceRateBuf = PlayerDatas.Instance.totalExpRate;
|
|
switch (_source)
|
{
|
case 2:
|
case 5:
|
m_ExperienceRate.text = StringUtility.Contact("(", experienceRateBuf / 100, "%)");
|
break;
|
case 4:
|
m_ExperienceRate.text = StringUtility.Contact("(", experienceRateBuf / 100 + 100, "%)?");
|
break;
|
case 6:
|
m_ExperienceRate.text = "!";
|
break;
|
default:
|
m_ExperienceRate.text = "";
|
break;
|
}
|
}
|
|
m_MoveTo.Begin(OnFloatEnd);
|
m_Experience.color = m_Experience.color.SetA(1f);
|
m_AlphaTween.SetStartState();
|
m_AlphaTween.Play();
|
}
|
|
public void SetEnable(bool _enable)
|
{
|
m_MoveTo.enabled = _enable;
|
m_AlphaTween.enabled = _enable;
|
}
|
|
private void OnFloatEnd()
|
{
|
ExperienceFloatPool.Recycle(this);
|
}
|
|
public enum Pattern
|
{
|
Normal = 1,
|
LongFeng = 2,
|
}
|
|
}
|
|
public class ExperienceFloatPool
|
{
|
static Dictionary<int, GameObjectPoolManager.GameObjectPool> pools = new Dictionary<int, GameObjectPoolManager.GameObjectPool>();
|
|
public static ExperienceFloat Require(ExperienceFloat.Pattern _pattern)
|
{
|
var patternInt = (int)_pattern;
|
GameObjectPoolManager.GameObjectPool pool;
|
if (!pools.ContainsKey(patternInt))
|
{
|
var prefab = UILoader.LoadPrefab(StringUtility.Contact("ExperienceFloat_", patternInt));
|
pool = GameObjectPoolManager.Instance.RequestPool(prefab);
|
pool.AddReleaseListener(ReleaseCallBack);
|
|
pools[patternInt] = pool;
|
}
|
else
|
{
|
pool = pools[patternInt];
|
}
|
|
if (pool != null)
|
{
|
var instance = pool.Request();
|
var experienceFloat = instance.GetComponent<ExperienceFloat>();
|
experienceFloat.SetEnable(true);
|
experienceFloat.pattern = _pattern;
|
return experienceFloat;
|
}
|
else
|
{
|
return null;
|
}
|
}
|
|
public static void Recycle(ExperienceFloat _float)
|
{
|
if (_float == null)
|
{
|
return;
|
}
|
|
var patternInt = (int)_float.pattern;
|
if (pools.ContainsKey(patternInt))
|
{
|
pools[patternInt].Release(_float.gameObject);
|
}
|
|
}
|
|
public static void RecycleAll()
|
{
|
foreach (var pool in pools.Values)
|
{
|
if (pool != null)
|
{
|
pool.ReleaseAll();
|
}
|
}
|
|
}
|
|
static void ReleaseCallBack(GameObject _go)
|
{
|
var behaviour = _go.GetComponent<ExperienceFloat>();
|
behaviour.SetEnable(false);
|
}
|
|
}
|
|
|
}
|
|
|
|