コード例 #1
0
    // Use this for initialization
    void Start()
    {
        helper = new gPhys.Sound.Helper();

        Vector3 enginePositionV = Vector3.zero;

        if (enginePosition != null)
        {
            enginePositionV = enginePosition.transform.position;
        }

        if (ExtCoasterSnd == null)
        {
            ExtCoasterSnd = new CarSoundItem[0];
        }
        if (IntCoasterSnd == null)
        {
            IntCoasterSnd = new CarSoundItem[0];
        }
        if (ExtPowerSnd == null)
        {
            ExtPowerSnd = new CarSoundItem[0];
        }
        if (IntPowerSnd == null)
        {
            IntPowerSnd = new CarSoundItem[0];
        }

        // ext
        // power
        System.Array.Resize(ref extPowerSrc, ExtPowerSnd.Length);
        for (int i = 0; i < ExtPowerSnd.Length; i++)
        {
            extPowerSrc[i] = CreateAudioSource(ExtPowerSnd[i].Audio, true, true, enginePositionV);
        }
        // coaster
        System.Array.Resize(ref extCoasterSrc, ExtCoasterSnd.Length);
        for (int i = 0; i < ExtCoasterSnd.Length; i++)
        {
            extCoasterSrc[i] = CreateAudioSource(ExtCoasterSnd[i].Audio, true, true, enginePositionV);
        }
        // idle
        if (ExtIdleSnd != null)
        {
            extIdleSrc = CreateAudioSource(ExtIdleSnd.Audio, true, true, enginePositionV);
        }
        // limiter
        if (ExtLimiterSnd != null)
        {
            extLimiterSrc = CreateAudioSource(ExtLimiterSnd.Audio, true, true, enginePositionV);
        }
        // reverse
        if (ExtReverseSnd != null)
        {
            extReverseSrc = CreateAudioSource(ExtReverseSnd.Audio, true, true, enginePositionV);
        }
        // turbo
        if (ExtTurboSnd != null)
        {
            extTurboSrc = CreateAudioSource(ExtTurboSnd.Audio, true, true, enginePositionV);
        }

        // int
        // power
        System.Array.Resize(ref intPowerSrc, IntPowerSnd.Length);
        for (int i = 0; i < IntPowerSnd.Length; i++)
        {
            intPowerSrc[i] = CreateAudioSource(IntPowerSnd[i].Audio, true, true, enginePositionV);
        }
        // coaster
        System.Array.Resize(ref intCoasterSrc, IntCoasterSnd.Length);
        for (int i = 0; i < IntCoasterSnd.Length; i++)
        {
            intCoasterSrc[i] = CreateAudioSource(IntCoasterSnd[i].Audio, true, true, enginePositionV);
        }
        // idle
        if (IntIdleSnd != null)
        {
            intIdleSrc = CreateAudioSource(IntIdleSnd.Audio, true, true, enginePositionV);
        }
        // limiter
        if (IntLimiterSnd != null)
        {
            intLimiterSrc = CreateAudioSource(IntLimiterSnd.Audio, true, true, enginePositionV);
        }
        // reverse
        if (IntReverseSnd != null)
        {
            intReverseSrc = CreateAudioSource(IntReverseSnd.Audio, true, true, enginePositionV);
        }
        // turbo
        if (IntTurboSnd != null)
        {
            intTurboSrc = CreateAudioSource(IntTurboSnd.Audio, true, true, enginePositionV);
        }
    }
コード例 #2
0
    void Update()
    {
        if (!debugSound)
        {
            muteSound(extCoasterSrc);
            muteSound(extPowerSrc);
            if (extIdleSrc != null)
            {
                muteSound(extIdleSrc);
            }
            if (extLimiterSrc != null)
            {
                muteSound(extLimiterSrc);
            }
            if (extReverseSrc != null)
            {
                muteSound(extReverseSrc);
            }

            muteSound(intCoasterSrc);
            muteSound(intPowerSrc);
            if (intIdleSrc != null)
            {
                muteSound(intIdleSrc);
            }
            if (intLimiterSrc != null)
            {
                muteSound(intLimiterSrc);
            }
            if (intReverseSrc != null)
            {
                muteSound(intReverseSrc);
            }
            return;
        }
        if (fakeRpm > fFakeRpm)
        {
            Throttle = true;
        }
        if (fakeRpm < fFakeRpm)
        {
            Throttle = false;
        }
        fFakeRpm = fakeRpm;

        rpm        = Convert.ToSingle(fakeRpm);
        clipsValue = rpm / FindObjectOfType <GR_PhEngine>().RpmLimit;

        if (Throttle)
        {
            coasterVolume  = 0.0f;
            throttleVolume = 1.0f;
        }
        else
        {
            coasterVolume  = 1.0f;
            throttleVolume = 0.0f;
        }

        bool interior = false;

        // check
        if (ExtIdleSnd != null && extIdleSrc == null)
        {
            extIdleSrc = CreateAudioSource(ExtIdleSnd.Audio, true, true, Vector3.zero);
        }
        if (ExtLimiterSnd != null && extLimiterSrc == null)
        {
            extLimiterSrc = CreateAudioSource(ExtLimiterSnd.Audio, true, true, Vector3.zero);
        }
        if (ExtReverseSnd != null && extReverseSrc == null)
        {
            extReverseSrc = CreateAudioSource(ExtReverseSnd.Audio, true, true, Vector3.zero);
        }
        if (IntIdleSnd != null && intIdleSrc == null)
        {
            intIdleSrc = CreateAudioSource(IntIdleSnd.Audio, true, true, Vector3.zero);
        }
        if (IntLimiterSnd != null && intLimiterSrc == null)
        {
            intLimiterSrc = CreateAudioSource(IntLimiterSnd.Audio, true, true, Vector3.zero);
        }
        if (IntReverseSnd != null && intReverseSrc == null)
        {
            intReverseSrc = CreateAudioSource(IntReverseSnd.Audio, true, true, Vector3.zero);
        }
        if (helper == null)
        {
            helper = new gPhys.Sound.Helper();
        }

        helper.Update(interior, pitchCorrection, clipsValue, throttleVolume,
                      ref ExtPowerSnd, ref ExtCoasterSnd,
                      ref IntPowerSnd, ref IntCoasterSnd,
                      ref ExtIdleSnd, ref IntIdleSnd,
                      ref ExtReverseSnd, ref IntReverseSnd,
                      ref ExtLimiterSnd, ref IntLimiterSnd,
                      ref extPowerSrc, ref extCoasterSrc,
                      ref intPowerSrc, ref intCoasterSrc,
                      ref extIdleSrc, ref intIdleSrc,
                      ref extReverseSrc, ref intReverseSrc,
                      ref extLimiterSrc, ref intLimiterSrc);

        if (!interior)
        {
#if UNITY_EDITOR
            if (!EnableIdle)
            {
                extIdleSrc.volume = 0.0f;
            }
            if (!EnableRev)
            {
                extReverseSrc.volume = 0.0f;
            }
            if (!EnableLimit)
            {
                extLimiterSrc.volume = 0.0f;
            }

            DebugIdle  = string.Format("{0:0.00}", extIdleSrc.volume);
            DebugRev   = string.Format("{0:0.00}", extReverseSrc.volume);
            DebugLimit = string.Format("{0:0.00}", extLimiterSrc.volume);

            string tmp = "";
            foreach (var item in extPowerSrc)
            {
                //if (!EnablePower) item.volume = 0.0f;
                tmp += string.Format("{0:0.00} ", item.volume);
            }
            DebugPower = tmp;
            tmp        = "";
            foreach (var item in extCoasterSrc)
            {
                //if (!EnableCoaster) item.volume = 0.0f;
                tmp += string.Format("{0:0.00} ", item.volume);
            }
            DebugCoaster = tmp;
#endif
        }
        else
        {
        }
    }