Ejemplo n.º 1
0
 /// <summary>
 /// 搖晃物件;
 /// fShakeAmount為 一倍時;位移量各為1,請視情況修改fShakeAmount(力道)
 /// </summary>
 /// <param name="gameobject">要使用的攝影機或遊戲物件</param>
 /// <param name="fShakeDuration">總執行時間,預設為0秒</param>
 /// <param name="fDelayTime">延遲呼叫的時間,預設為0秒</param>
 /// <param name="fShakeAmount">搖晃的力道,最後會乘上這個數值,可以當作倍率,預設為一倍</param>
 /// <param name="_eShakeType">搖晃的類型;目前提供 垂直、水平、垂直+水平、圓球(三軸)
 /// 預設為垂直+水平</param>
 /// <param name="tccCalllbackComplete">完成事件後將會被呼叫的函式,會回傳原本註冊
 /// 的GameObject</param>
 /// <param name="bUsePause">是否可被暫停,預設為不可被暫停</param>
 public static int ShakeGameObject(GameObject gameobject, float fShakeDuration = 0f,
                                   float fDelayTime                = 0, float fShakeAmount = 1f,
                                   eShakeType _eShakeType          = eShakeType.VerticalAndHorizontal,
                                   ccCallback tccCalllbackComplete = null, bool bUsePause = false)
 {
     object[] obj = new object[5];
     obj[0] = gameobject.transform;
     obj[1] = gameobject.transform.localPosition;
     obj[2] = fShakeAmount;
     obj[3] = _eShakeType;
     obj[4] = tccCalllbackComplete;
     return(ccUpdateEvent.Instance.f_RegEvent(fShakeDuration, Shake, fDelayTime, ShakeComplete, obj, bUsePause));
 }
Ejemplo n.º 2
0
        private static void Shake(object data, float fTime)
        {
            Vector3 v = Vector3.zero;

            object[]   obj          = ( object[] )data;
            Transform  camTransform = ( Transform )obj[0];
            Vector3    originalPos  = ( Vector3 )obj[1];
            float      fShakeAmount = ( float )obj[2];
            eShakeType m_ShakeType  = ( eShakeType )obj[3];

            switch (m_ShakeType)
            {
            case eShakeType.Vertical:
                v = Vector3.up * UnityEngine.Random.Range(-1.0f, 1.0f);
                break;

            case eShakeType.Horizontal:
                v = Vector3.right * UnityEngine.Random.Range(-1.0f, 1.0f);
                break;

            case eShakeType.VerticalAndHorizontal:
                v = Vector3.right * UnityEngine.Random.Range(-1.0f, 1.0f) +
                    Vector3.up * UnityEngine.Random.Range(-1.0f, 1.0f);
                break;

            case eShakeType.Sphere:
                v = UnityEngine.Random.insideUnitSphere;
                break;

            default:
                Debug.LogError("沒有選擇任何模式,當初註冊的eShakeType不存在於預設Enum中");
                break;
            }
            if (camTransform != null)
            {
                camTransform.localPosition = originalPos + v * fShakeAmount;
            }
        }