コード例 #1
0
    public void DoShake1(GameObject target, int curveIndex)
    {
        LoadCurves();
        if (m_Curves.ContainsKey(curveIndex))
        {
            CameraShakeData       data      = m_Curves[curveIndex];
            CameraShake.ShakeType shakeType = CameraShake.ShakeType.LocalPosition;
            if (data.m_ShakeType == "CameraMatrix")
            {
                shakeType = CameraShake.ShakeType.CameraMatrix;
            }
            bool isScale = true;
            if (data.m_MultiplyByTimeScale == 0)
            {
                isScale = false;
            }
            CameraShake comp = target.AddUniqueCompoment <CameraShake>();

            comp.shakeType           = shakeType;
            comp.numberOfShakes      = data.m_NumOfShakes;
            comp.shakeAmount         = data.m_ShakeAmount;
            comp.rotationAmount      = data.m_RotationAmount;
            comp.distance            = data.m_Distance;
            comp.speed               = data.m_Speed;
            comp.decay               = data.m_Decay;
            comp.guiShakeModifier    = data.m_GuiShakeModifier;
            comp.multiplyByTimeScale = isScale;
            comp.Shake();
        }
    }
コード例 #2
0
    /// <summary>
    /// 解析CameraShake事件字符串
    /// "camera_shake 2 0 1.5,0.3 4 0.2"
    /// </summary>
    static public void ParseShakeEvent(string evt, out CameraShake.ShakeType shakeType,
                                       out CameraShake.NoiseType noiseType, out Vector3 moveExt,
                                       out float speed,
                                       out float duration)
    {
        // 参数使用空白分割
        var args = evt.Split(' ');

        try {
            // 参数0是指令参数,通常为camera_shake
            shakeType = (CameraShake.ShakeType)ParseUtil.ParseInt(args [1]);
            noiseType = (CameraShake.NoiseType)ParseUtil.ParseInt(args [2]);
            moveExt   = ParseUtil.ParseVector2(args [3]);
            speed     = ParseUtil.ParseFloat(args [4]);
            duration  = ParseUtil.ParseFloat(args [5]);
        }
        catch (System.Exception ex) {
            shakeType = CameraShake.ShakeType.Constant;
            noiseType = CameraShake.NoiseType.Perlin;
            moveExt   = default(Vector3);
            speed     = 0f;
            duration  = 0f;
            Debug.LogError($"解析CameraShake事件字符串失败:{evt}");
        }
    }