using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public static class XUIEffectHelper
{
// 合成后飞组件特效
static IEnumerator mFlyIEnumerator = null;
static List<Transform> mFlyCacheList = new List<Transform>();
public delegate void OnFlyCb();
public static void FlyPart(List<Transform> formList, Vector3 toPosition, float lifeTime, OnFlyCb voidEvent, OnFlyCb everyItemCb = null, bool allItemSync = false)
{
for (int i = 0; i < mFlyCacheList.Count; ++i)
{
if (mFlyCacheList != null)
GameObject.Destroy(mFlyCacheList[i].gameObject);
}
mFlyCacheList.Clear();
if (mFlyIEnumerator != null)
XCoroutineHelper.StopCoroutine(mFlyIEnumerator);
mFlyIEnumerator = CoShowFly(formList, toPosition, lifeTime, voidEvent, everyItemCb, allItemSync);
XCoroutineHelper.StartCoroutine(mFlyIEnumerator);
}
static IEnumerator CoShowFly(List<Transform> formList, Vector3 toPosition, float lifeTime, OnFlyCb voidEvent, OnFlyCb everyItemCb = null, bool allItemSync = false)
{
for (int i = 0; i < formList.Count; ++i)
{
Transform copyT = (Transform)GameObject.Instantiate(formList[i], formList[i].transform.position, formList[i].transform.rotation);
copyT.parent = formList[i].parent;
copyT.localPosition = formList[i].transform.localPosition;
copyT.localScale = new Vector3(1, 1, 1);
copyT.gameObject.SetActive(true);
mFlyCacheList.Add(copyT);
TweenPosition.Begin(copyT.gameObject, lifeTime, toPosition);
if (!allItemSync)
{
yield return new WaitForSeconds(lifeTime);
GameObject.Destroy(copyT.gameObject);
mFlyCacheList.Remove(copyT);
}
if (everyItemCb != null)
everyItemCb();
}
if (allItemSync)
{
yield return new WaitForSeconds(lifeTime);
for (int i = 0; i < mFlyCacheList.Count; ++i)
{
if (mFlyCacheList != null)
GameObject.Destroy(mFlyCacheList[i].gameObject);
}
mFlyCacheList.Clear();
}
if (voidEvent != null)
voidEvent();
}
// 加属性的飘字效果
static IEnumerator mFlyAttrsIEnumerator = null;
static List<Transform> mFlyAttrsList = new List<Transform>();
static Color fromColor = new Color(0f, 86 / 255f, 0f, 1f);
static Color toColor = new Color(0f, 1f, 0f, 1f);
public delegate void OnFlyAttrCb();
public static void FlyAttrs(List<string> attrs, int addY, Transform parentFom, Transform tmplate, OnFlyAttrCb callCb = null, float lifeTime = 0.4f, OnFlyAttrCb everItemCb = null)
{
for (int i = 0; i < mFlyAttrsList.Count; ++i)
{
if (mFlyAttrsList != null)
GameObject.Destroy(mFlyAttrsList[i].gameObject);
}
mFlyAttrsList.Clear();
if (mFlyAttrsIEnumerator != null)
XCoroutineHelper.StopCoroutine(mFlyAttrsIEnumerator);
mFlyAttrsIEnumerator = CoShowFlyAttrs(attrs, addY, lifeTime, parentFom, tmplate, callCb, everItemCb);
XCoroutineHelper.StartCoroutine(mFlyAttrsIEnumerator);
}
static IEnumerator CoShowFlyAttrs(List<string> attrs, int addY, float lifeTime, Transform parentFom, Transform tmplate, OnFlyAttrCb callCb, OnFlyAttrCb everItemCb = null)
{
for (int i = 0; i < attrs.Count; ++i)
{
Transform copyT = (Transform)GameObject.Instantiate(tmplate, tmplate.transform.position, tmplate.transform.rotation);
copyT.parent = parentFom;
copyT.localPosition = tmplate.transform.localPosition;
copyT.localScale = new Vector3(1, 1, 1);
UILabel lb = copyT.GetComponent<UILabel>();
lb.text = attrs[i];
lb.color = fromColor;
copyT.gameObject.SetActive(true);
mFlyAttrsList.Add(copyT);
//foreach (UIWidget widget in copyT.GetComponentsInChildren<UIWidget>())
//{
lb.color = fromColor;
TweenPosition.Begin(copyT.gameObject, lifeTime, copyT.transform.localPosition + new Vector3(0, addY, 0));
TweenColor.Begin(lb.gameObject, lifeTime / 2, toColor);
//}
yield return new WaitForSeconds(lifeTime);
GameObject.Destroy(copyT.gameObject);
mFlyAttrsList.Remove(copyT);
if (everItemCb != null)
everItemCb();
}
if (callCb != null)
callCb();
}
}
UI效果
最新推荐文章于 2025-04-01 00:00:00 发布