• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            l

            成都手游碼農(nóng)一枚
            隨筆 - 32, 文章 - 0, 評(píng)論 - 117, 引用 - 0
            數(shù)據(jù)加載中……

            [Unity3D]海島奇兵金幣等資源收取效果

            仿海島奇兵中金幣收取的效果,簡(jiǎn)單的粒子實(shí)現(xiàn)。
            注:由于場(chǎng)景和UI相機(jī)是分離的,所以代碼中增加了一次坐標(biāo)轉(zhuǎn)換的操作,防止場(chǎng)景拖動(dòng)造成金幣整體便宜的問題。
              1using UnityEngine;
              2using System.Collections;
              3
              4public class CoinsAnimation : MonoBehaviour 
              5{
              6
              7    public GameObject[] mCoinPrefab;
              8    public float mRate = 0.25f;
              9    public float mMoveSpeed = 2;
             10    public AnimationCurve mMoveSpeedCurve;
             11    public float mRotateSpeed = 3;
             12
             13    private static CoinsAnimation Instance;
             14
             15    private class Coin
             16    {
             17        public float mMoveTime;
             18        public Transform mTransform;
             19        public Vector3 mRotateSpeed;
             20    }

             21
             22    private void Start()
             23    {
             24        Instance = this;
             25    }

             26
             27    private void OnDestroy()
             28    {
             29        Instance = null;
             30    }

             31
             32    private IEnumerator OnAnimation(float flyTime, int type, Vector3 sourceIn, Vector3 targetIn, int count)
             33    {
             34        Camera sceneCamera = Camera.main;
             35        Camera uiCamera = Global.Instance().GetUIManager().UICamera;
             36
             37        Vector3 source, target;
             38        if (null != uiCamera)
             39        {
             40            source = sourceIn;
             41            target = targetIn;
             42
             43            // 將UI起點(diǎn)坐標(biāo)轉(zhuǎn)換為場(chǎng)景起點(diǎn)坐標(biāo)并保存
             44            sourceIn = sceneCamera.ViewportToWorldPoint(uiCamera.WorldToViewportPoint(sourceIn));
             45        }

             46        else
             47        {
             48            source = sourceIn;
             49            target = targetIn;
             50        }

             51
             52        System.Collections.Generic.List<Coin> coins = new System.Collections.Generic.List<Coin>();
             53        float generateTime = 0;
             54        float generateCount = 0;
             55        float moveSpeed = 1 / flyTime;
             56
             57        while (true)
             58        {
             59            if (generateCount < count && generateTime <= 0)
             60            {
             61                Coin coin = new Coin();
             62
             63                coin.mRotateSpeed = new Vector3(
             64                    Mathf.Lerp(0360, Random.Range(01.0f)),
             65                    Mathf.Lerp(0360, Random.Range(01.0f)),
             66                    Mathf.Lerp(0360, Random.Range(01.0f))) * mRotateSpeed;
             67
             68                GameObject go = Instantiate(mCoinPrefab[type], source, Random.rotationUniform) as GameObject;
             69                coin.mTransform = go.transform;
             70
             71                coins.Add(coin);
             72                generateTime = mRate;
             73                generateCount++;
             74            }

             75            else
             76            {
             77                generateTime -= Time.deltaTime;
             78            }

             79
             80            if (null != uiCamera)
             81            {
             82                // 將場(chǎng)景起點(diǎn)坐標(biāo)轉(zhuǎn)換為UI起點(diǎn)坐標(biāo),因?yàn)閳?chǎng)景可以拖動(dòng),不然會(huì)造成效果分離的問題,所以必須轉(zhuǎn)換一次
             83                source = uiCamera.ViewportToWorldPoint(sceneCamera.WorldToViewportPoint(sourceIn));
             84            }

             85
             86            for (int i = coins.Count - 1; i >= 0--i)
             87            {
             88                Coin coin = coins[i];
             89                coin.mTransform.position = Vector3.Lerp(source, target, coins[i].mMoveTime);
             90                coin.mTransform.Rotate(coin.mRotateSpeed.x * Time.deltaTime, coin.mRotateSpeed.y * Time.deltaTime, coin.mRotateSpeed.z * Time.deltaTime);
             91                coin.mMoveTime = coin.mMoveTime + Mathf.Max(mMoveSpeedCurve.Evaluate(coin.mMoveTime), 0.1f* moveSpeed * Time.deltaTime;
             92
             93                if (coin.mMoveTime >= 1)
             94                {
             95                    coins.RemoveAt(i);
             96                    Destroy(coin.mTransform.gameObject);
             97                }

             98            }

             99
            100            if (generateCount >= count && coins.Count == 0)
            101            {
            102                break;
            103            }

            104
            105            yield return null;
            106        }

            107    }

            108
            109    public float BeginAnimation(int type, Vector3 source, Vector3 target, int count)
            110    {
            111        // 飛行時(shí)長(zhǎng)
            112        float flyTime = (target - source).magnitude / mMoveSpeed;
            113        StartCoroutine(OnAnimation(flyTime, type, source, target, Mathf.Clamp(count, 120)));
            114        return flyTime;
            115    }

            116
            117    /// <summary>
            118    /// 播放特效
            119    /// </summary>
            120    /// <param name="type">類型</param>
            121    /// <param name="source">UI相機(jī)中的起點(diǎn)坐標(biāo)</param>
            122    /// <param name="target">UI相機(jī)中的終點(diǎn)坐標(biāo)</param>
            123    /// <param name="count">粒子數(shù)量</param>
            124    /// <returns>播放時(shí)長(zhǎng)</returns>

            125    public static float Play(int type, Vector3 source, Vector3 target, int count)
            126    {
            127        if (null != Instance)
            128        {
            129            return Instance.BeginAnimation(type, source, target, count);
            130        }

            131        return 0;
            132    }

            133    
            134}

            135




            posted on 2015-12-15 09:50 l1989 閱讀(3266) 評(píng)論(1)  編輯 收藏 引用 所屬分類: 游戲

            評(píng)論

            # re: [Unity3D]海島奇兵金幣等資源收取效果  回復(fù)  更多評(píng)論   

            一個(gè)簡(jiǎn)單卻又不簡(jiǎn)單的效果
            2016-01-06 15:42 | bns
            国产精品久久永久免费| 香蕉99久久国产综合精品宅男自 | 久久91这里精品国产2020| 国产L精品国产亚洲区久久| 99久久99久久精品国产| 国产精品久久婷婷六月丁香| 99久久99这里只有免费费精品| 欧美伊香蕉久久综合类网站| 亚洲国产精品无码久久九九| 色婷婷综合久久久中文字幕| 狠狠久久综合| 色8久久人人97超碰香蕉987| 国产精品日韩欧美久久综合| 久久久久亚洲AV无码专区首JN| 麻豆精品久久精品色综合| 亚洲午夜久久久久久噜噜噜| 国产免费久久精品99久久| 精品少妇人妻av无码久久| 思思久久99热免费精品6| 久久精品水蜜桃av综合天堂| 久久有码中文字幕| 青青国产成人久久91网| 无码AV波多野结衣久久| 人妻无码久久精品| 精品久久久久中文字幕一区| 久久偷看各类wc女厕嘘嘘| 亚洲精品无码久久久久AV麻豆| 国产99久久九九精品无码| 国产99精品久久| 久久精品夜夜夜夜夜久久| 久久精品人妻中文系列| 亚洲欧美日韩精品久久亚洲区| 国产精品久久久久乳精品爆| 国产成人精品久久| 久久最新精品国产| 97精品伊人久久久大香线蕉| 国产精品视频久久| 久久精品国产只有精品2020| 91精品国产高清91久久久久久| 久久发布国产伦子伦精品| 国产成人精品白浆久久69|