UI效果

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();
    }

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值