示例#1
0
 static public int set_IsValid(IntPtr l)
 {
     try {
                     #if DEBUG
         var    method     = System.Reflection.MethodBase.GetCurrentMethod();
         string methodName = GetMethodName(method);
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.BeginSample(methodName);
                     #else
         Profiler.BeginSample(methodName);
                     #endif
                     #endif
         SMSound        self = (SMSound)checkSelf(l);
         System.Boolean v;
         checkType(l, 2, out v);
         self.IsValid = v;
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
             #if DEBUG
     finally {
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.EndSample();
                     #else
         Profiler.EndSample();
                     #endif
     }
             #endif
 }
示例#2
0
    bool IsSoundFinished(SMSound sound)
    {
        if (sound.IsLoading)
        {
            return(false);
        }

        if (sound.Source.isPlaying)
        {
            return(false);
        }

        if (sound.Source.clip == null)
        {
            return(true);
        }

        if (sound.Source.clip.loadState == AudioDataLoadState.Loading)
        {
            return(false);
        }

        if (!sound.Source.ignoreListenerPause && AudioListener.pause)
        {
            return(false);
        }

        return(true);
    }
示例#3
0
 static public int constructor(IntPtr l)
 {
     try {
                     #if DEBUG
         var    method     = System.Reflection.MethodBase.GetCurrentMethod();
         string methodName = GetMethodName(method);
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.BeginSample(methodName);
                     #else
         Profiler.BeginSample(methodName);
                     #endif
                     #endif
         SMSound o;
         o = new SMSound();
         pushValue(l, true);
         pushValue(l, o);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
             #if DEBUG
     finally {
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.EndSample();
                     #else
         Profiler.EndSample();
                     #endif
     }
             #endif
 }
示例#4
0
 static public int get_IsAttachedToTransform(IntPtr l)
 {
     try {
                     #if DEBUG
         var    method     = System.Reflection.MethodBase.GetCurrentMethod();
         string methodName = GetMethodName(method);
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.BeginSample(methodName);
                     #else
         Profiler.BeginSample(methodName);
                     #endif
                     #endif
         SMSound self = (SMSound)checkSelf(l);
         pushValue(l, true);
         pushValue(l, self.IsAttachedToTransform);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
             #if DEBUG
     finally {
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.EndSample();
                     #else
         Profiler.EndSample();
                     #endif
     }
             #endif
 }
示例#5
0
 static public int SetPosition(IntPtr l)
 {
     try {
                     #if DEBUG
         var    method     = System.Reflection.MethodBase.GetCurrentMethod();
         string methodName = GetMethodName(method);
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.BeginSample(methodName);
                     #else
         Profiler.BeginSample(methodName);
                     #endif
                     #endif
         SMSound             self = (SMSound)checkSelf(l);
         UnityEngine.Vector3 a1;
         checkType(l, 2, out a1);
         var ret = self.SetPosition(a1);
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
             #if DEBUG
     finally {
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.EndSample();
                     #else
         Profiler.EndSample();
                     #endif
     }
             #endif
 }
    /// <summary>
    /// used internally to recycle SKSounds and their AudioSources
    /// </summary>
    /// <param name="sound">Sound.</param>
    public void recycleSound(SMSound sound)
    {
        var index = 0;

        while (index < _playingSounds.Count)
        {
            if (_playingSounds[index] == sound)
            {
                break;
            }
            index++;
        }

        if (index < _playingSounds.Count)
        {
            _playingSounds.RemoveAt(index);

            // if we are already over capacity dont recycle this sound but destroy it instead
            if (_availableSounds.Count + _playingSounds.Count >= _maxCapacity)
            {
                Destroy(sound.audioSource);
            }
            else
            {
                _availableSounds.Push(sound);
            }
        }
    }
    /// <summary>
    /// plays the AudioClip with the specified volumeScale and pitch
    /// </summary>
    /// <returns>The sound.</returns>
    /// <param name="audioClip">Audio clip.</param>
    /// <param name="volume">Volume.</param>
    public SMSound playSound(AudioClip audioClip, float volumeScale, float pitch)
    {
        // Find the first SKSound not being used. if they are all in use, create a new one
        SMSound sound = nextAvailableSound();

        sound.PlayAudioClip(audioClip, volumeScale * _soundEffectVolume, pitch);

        return(sound);
    }
    /// <summary>
    /// loops the AudioClip. Do note that you are responsible for calling either stop or fadeOutAndStop on the SKSound
    /// or it will not be recycled
    /// </summary>
    /// <returns>The sound looped.</returns>
    /// <param name="audioClip">Audio clip.</param>
    public SMSound playSoundLooped(AudioClip audioClip)
    {
        // find the first SKSound not being used. if they are all in use, create a new one
        SMSound sound = nextAvailableSound();

        sound.PlayAudioClip(audioClip, _soundEffectVolume, 1f);
        sound.SetLoop(true);

        return(sound);
    }
示例#9
0
 void LateUpdate()
 {
     for (int i = 0; i < _sounds.Count; i++)
     {
         SMSound sound = _sounds[i];
         if (sound.IsAttachedToTransform && sound.Attach != null)
         {
             sound.Source.transform.position = sound.Attach.position;
         }
     }
 }
    /// <summary>
    /// starts up the background music and optionally loops it. You can access the SKSound via the backgroundSound field.
    /// </summary>
    /// <param name="audioClip">Audio clip.</param>
    /// <param name="loop">If set to <c>true</c> loop.</param>
    public SMSound playBackgroundMusic(AudioClip audioClip, float volume, bool loop = true)
    {
        if (_backgroundSound == null)
        {
            _backgroundSound = new SMSound(this);
        }

        _backgroundSound.PlayAudioClip(audioClip, volume * _musicEffectVolume, 1f);
        _backgroundSound.SetLoop(loop);

        return(_backgroundSound);
    }
示例#11
0
    void StopSoundInternal(SMSound sound)
    {
        if (sound.IsLoading)
        {
            StopCoroutine(sound.LoadingCoroutine);
            if (sound.IsPossessedLoading)
            {
                _loadingInProgress = false;
            }

            sound.IsLoading = false;
        }
        else
        {
            sound.Source.Stop();
        }
    }
    /// <summary>
    /// fetches the next available sound and adds the sound to the _playingSounds List
    /// </summary>
    /// <returns>The available sound.</returns>
    private SMSound nextAvailableSound()
    {
        SMSound sound = null;

        if (_availableSounds.Count > 0)
        {
            sound = _availableSounds.Pop();
        }

        // if we didnt find an available found, bail out
        if (sound == null)
        {
            sound = new SMSound(this);
        }
        _playingSounds.Add(sound);

        return(sound);
    }
示例#13
0
    IEnumerator PlaySoundInternalAfterLoad(SMSound smSound, string soundName, string bundleName)
    {
        smSound.IsLoading = true;

        // Need to wait others sounds to be loaded to avoid Android LoadingPersistentStorage lags
        while (_loadingInProgress)
        {
            yield return(null);
        }

        _loadingInProgress         = true;
        smSound.IsPossessedLoading = true;
        AudioClip soundClip = null;

        soundClip = LoadClipFromBundle(bundleName, soundName);

        /*
         * if (bundle == null)
         * {
         *  ResourceRequest request = LoadClipAsync("Sounds/" + soundName);
         *  while (!request.isDone)
         *      yield return null;
         *  soundClip = (AudioClip)request.asset;
         * }
         * else
         * {
         *  AssetBundleRequest request = LoadClipFromBundleAsync(bundle, soundName);
         *  while (!request.isDone)
         *      yield return null;
         *  soundClip = (AudioClip)request.asset;
         * }
         */
        smSound.IsPossessedLoading = false;
        _loadingInProgress         = false;

        if (null == soundClip)
        {
            Debug.Log("Sound not loaded: " + soundName);
        }

        smSound.IsLoading   = false;
        smSound.Source.clip = soundClip;
        smSound.Source.Play();
    }
示例#14
0
    SMSound PlaySoundClipInternal(AudioClip clip, bool pausable)
    {
        SMSound sound = new SMSound();

        sound.Name       = clip.name;
        sound.SelfVolume = 1;

        if (_sounds.Count > 16)
        {
            Debug.Log("Too much sounds");
            sound.IsValid = false;
            return(sound);
        }

        GameObject soundGameObject = ObjectPool.Spawn();// new GameObject("Sound: " + sound.Name);

        soundGameObject.name = "Sound: " + sound.Name;
        AudioSource soundSource = soundGameObject.AddMissingComponent <AudioSource>();

        soundGameObject.transform.parent = transform;

        sound.Source  = soundSource;
        sound.IsValid = true;

        soundSource.clip = clip;
        soundSource.outputAudioMixerGroup = _settings.SoundAudioMixerGroup;
        soundSource.priority            = 128;
        soundSource.playOnAwake         = false;
        soundSource.mute                = _settings.GetSoundMuted();
        soundSource.volume              = _settings.GetSoundVolumeCorrected();
        soundSource.ignoreListenerPause = !pausable;
        soundSource.Play();

        _sounds.Add(sound);

        return(sound);
    }
示例#15
0
        internal static void SaveSettings()
        {
            if (Loaded && (HighLogic.LoadedScene == GameScenes.FLIGHT || HighLogic.LoadedScene == GameScenes.SPACECENTER))
            {
                if (EnableStockCrewXfer != PrevEnableStockCrewXfer)
                {
                    SetStockCrewTransferState();
                }
                if (SMSound.SoundSettingsChanged())
                {
                    SMSound.LoadSounds();
                }

                MemStoreTempSettings();
                if (Settings == null)
                {
                    Settings = LoadSettingsFile();
                }

                ConfigNode windowsNode = Settings.HasNode("SM_Windows")
          ? Settings.GetNode("SM_Windows")
          : Settings.AddNode("SM_Windows");
                ConfigNode realismNode = Settings.HasNode("SM_Realism")
          ? Settings.GetNode("SM_Realism")
          : Settings.AddNode("SM_Realism");
                ConfigNode highlightNode = Settings.HasNode("SM_Highlight")
          ? Settings.GetNode("SM_Highlight")
          : Settings.AddNode("SM_Highlight");
                ConfigNode toolTipsNode = Settings.HasNode("SM_ToolTips")
          ? Settings.GetNode("SM_ToolTips")
          : Settings.AddNode("SM_ToolTips");
                ConfigNode soundsNode = Settings.HasNode("SM_Sounds")
          ? Settings.GetNode("SM_Sounds")
          : Settings.AddNode("SM_Sounds");
                ConfigNode configNode = Settings.HasNode("SM_Config")
          ? Settings.GetNode("SM_Config")
          : Settings.AddNode("SM_Config");
                ConfigNode hiddenNode = Settings.HasNode("SM_Hidden")
          ? Settings.GetNode("SM_Hidden")
          : Settings.AddNode("SM_Hidden");

                // Write window positions
                WriteRectangle(windowsNode, "ManifestPosition", WindowManifest.Position);
                WriteRectangle(windowsNode, "TransferPosition", WindowTransfer.Position);
                WriteRectangle(windowsNode, "DebuggerPosition", WindowDebugger.Position);
                WriteRectangle(windowsNode, "SettingsPosition", WindowSettings.Position);
                WriteRectangle(windowsNode, "ControlPosition", WindowControl.Position);
                WriteRectangle(windowsNode, "RosterPosition", WindowRoster.Position);

                //Write settings...
                // Realism Settings
                WriteValue(realismNode, "RealismMode", RealismMode);
                WriteValue(realismNode, "RealXfers", RealXfers);
                WriteValue(realismNode, "RealControl", RealControl);
                WriteValue(realismNode, "EnableCrew", EnableCrew);
                WriteValue(realismNode, "EnableCrewModify", EnableCrewModify);
                WriteValue(realismNode, "EnableKerbalRename", EnableKerbalRename);
                WriteValue(realismNode, "EnableChangeProfession", EnableChangeProfession);
                WriteValue(realismNode, "EnablePfCrews", EnablePfCrews);
                WriteValue(realismNode, "EnableStockCrewTransfer", EnableStockCrewXfer);
                WriteValue(realismNode, "EnableScience", EnableScience);
                WriteValue(realismNode, "EnableResources", EnableResources);
                WriteValue(realismNode, "EnablePFResources", EnablePfResources);
                WriteValue(realismNode, "EnableCLS", EnableCls);
                WriteValue(realismNode, "OverrideStockCrewTransfer", OverrideStockCrewXfer);
                WriteValue(realismNode, "EnableClsAllowTransfer", EnableClsAllowTransfer);
                WriteValue(realismNode, "FlowRate", FlowRate);
                WriteValue(realismNode, "FlowCost", FlowCost);
                WriteValue(realismNode, "MinFlowRate", MinFlowRate);
                WriteValue(realismNode, "MaxFlowRate", MaxFlowRate);
                WriteValue(realismNode, "MaxFlowTimeSec", MaxFlowTimeSec);
                WriteValue(realismNode, "EnableXferCost", EnableXferCost);
                WriteValue(realismNode, "LockSettings", LockSettings);

                // Highlighting Settings
                WriteValue(highlightNode, "EnableHighlighting", EnableHighlighting);
                WriteValue(highlightNode, "OnlySourceTarget", OnlySourceTarget);
                WriteValue(highlightNode, "EnableCLSHighlighting", EnableClsHighlighting);
                WriteValue(highlightNode, "EnableEdgeHighlighting", EnableEdgeHighlighting);

                // ToolTip Settings
                WriteValue(toolTipsNode, "ShowToolTips", ShowToolTips);
                WriteValue(toolTipsNode, "DebuggerToolTips", WindowDebugger.ShowToolTips);
                WriteValue(toolTipsNode, "ManifestToolTips", WindowManifest.ShowToolTips);
                WriteValue(toolTipsNode, "TransferToolTips", WindowTransfer.ShowToolTips);
                WriteValue(toolTipsNode, "SettingsToolTips", WindowSettings.ShowToolTips);
                WriteValue(toolTipsNode, "RealismToolTips", TabRealism.ShowToolTips);
                WriteValue(toolTipsNode, "HighlightingToolTips", TabHighlight.ShowToolTips);
                WriteValue(toolTipsNode, "ToolTipsToolTips", TabToolTips.ShowToolTips);
                WriteValue(toolTipsNode, "SoundsToolTips", TabSounds.ShowToolTips);
                WriteValue(toolTipsNode, "ConfigToolTips", TabConfig.ShowToolTips);
                WriteValue(toolTipsNode, "RosterToolTips", WindowRoster.ShowToolTips);
                WriteValue(toolTipsNode, "ControlToolTips", WindowControl.ShowToolTips);
                WriteValue(toolTipsNode, "HatchToolTips", TabHatch.ShowToolTips);
                WriteValue(toolTipsNode, "PanelToolTips", TabSolarPanel.ShowToolTips);
                WriteValue(toolTipsNode, "AntennaToolTips", TabAntenna.ShowToolTips);
                WriteValue(toolTipsNode, "LightToolTips", TabLight.ShowToolTips);

                // Sound Settings
                WriteValue(soundsNode, "PumpSoundStart", PumpSoundStart);
                WriteValue(soundsNode, "PumpSoundRun", PumpSoundRun);
                WriteValue(soundsNode, "PumpSoundStop", PumpSoundStop);
                WriteValue(soundsNode, "CrewSoundStart", CrewSoundStart);
                WriteValue(soundsNode, "CrewSoundRun", CrewSoundRun);
                WriteValue(soundsNode, "CrewSoundStop", CrewSoundStop);
                WriteValue(soundsNode, "PumpSoundVol", PumpSoundVol);
                WriteValue(soundsNode, "CrewSoundVol", CrewSoundVol);

                // Config Settings
                WriteValue(configNode, "ShowDebugger", WindowDebugger.ShowWindow);
                WriteValue(configNode, "EnableBlizzyToolbar", EnableBlizzyToolbar);
                WriteValue(configNode, "VerboseLogging", VerboseLogging);
                WriteValue(configNode, "AutoSave", AutoSave);
                WriteValue(configNode, "SaveIntervalSec", SaveIntervalSec);
                WriteValue(configNode, "AutoDebug", AutoDebug);
                WriteValue(configNode, "DebugLogPath", DebugLogPath);
                WriteValue(configNode, "ErrorLogLength", ErrorLogLength);
                WriteValue(configNode, "SaveLogOnExit", SaveLogOnExit);
                WriteValue(configNode, "UseUnityStyle", UseUnityStyle);

                // Hidden Settings
                WriteValue(hiddenNode, "ResourcePartColor", ResourcePartColor);
                WriteValue(hiddenNode, "SourcePartColor", SourcePartColor);
                WriteValue(hiddenNode, "TargetPartColor", TargetPartColor);
                WriteValue(hiddenNode, "TargetPartCrewColor", TargetPartCrewColor);
                WriteValue(hiddenNode, "MouseOverColor", MouseOverColor);
                WriteValue(hiddenNode, "CrewXferDelaySec", CrewXferDelaySec);
                WriteValue(hiddenNode, "IvaUpdateFrameDelay", IvaUpdateFrameDelay);

                if (!Directory.Exists(SettingsPath))
                {
                    Directory.CreateDirectory(SettingsPath);
                }
                Settings.Save(SettingsFile);
            }
        }
示例#16
0
    void Update()
    {
        // Destory only one sound per frame
        SMSound soundToDelete = null;

        foreach (SMSound sound in _sounds)
        {
            if (IsSoundFinished(sound))
            {
                soundToDelete = sound;
                break;
            }
        }

        if (soundToDelete != null)
        {
            soundToDelete.IsValid = false;
            _sounds.Remove(soundToDelete);
            Destroy(soundToDelete.Source.gameObject);
        }

        if (_settings.AutoPause)
        {
            bool curPause = Time.timeScale < 0.1f;
            if (curPause != AudioListener.pause)
            {
                AudioListener.pause = curPause;
            }
        }

        for (int i = 0; i < _musicFadingsOut.Count; i++)
        {
            SMMusicFadingOut music = _musicFadingsOut[i];
            if (music.Source == null)
            {
                _musicFadingsOut.RemoveAt(i);
                i--;
            }
            else
            {
                music.Timer        += Time.unscaledDeltaTime;
                _musicFadingsOut[i] = music;
                if (music.Timer >= music.FadingTime)
                {
                    Destroy(music.Source.gameObject);
                    _musicFadingsOut.RemoveAt(i);
                    i--;
                }
                else
                {
                    float k = Mathf.Clamp01(music.Timer / music.FadingTime);
                    music.Source.volume = Mathf.Lerp(music.StartVolume, 0, k);
                }
            }
        }

        if (_music != null && _music.FadingIn)
        {
            _music.Timer += Time.unscaledDeltaTime;
            if (_music.Timer >= _music.FadingTime)
            {
                _music.Source.volume = _music.TargetVolume;
                _music.FadingIn      = false;
            }
            else
            {
                float k = Mathf.Clamp01(_music.Timer / _music.FadingTime);
                _music.Source.volume = Mathf.Lerp(0, _music.TargetVolume, k);
            }
        }
    }
示例#17
0
    void Update()
    {
        if (this.mChatSound != null)
        {
            if (IsSoundFinished(this.mChatSound))
            {
                this.mChatSound.IsValid = false;
                ObjectPool.Recycle(this.mChatSound.Source.gameObject);
                this.mChatSound = null;
            }
        }

        // Destory only one sound per frame
        SMSound soundToDelete = null;

        for (int i = 0; i < _sounds.Count; i++)
        {
            SMSound sound = _sounds[i];
            if (IsSoundFinished(sound))
            {
                soundToDelete = sound;
                break;
            }
        }

        if (soundToDelete != null)
        {
            soundToDelete.IsValid = false;
            _sounds.Remove(soundToDelete);
            //Destroy(soundToDelete.Source.gameObject);

            /*
             * if(!string.IsNullOrEmpty(soundToDelete.assetBundleName))
             * {
             *  AssetBundleManager.UnloadAssetBundle(soundToDelete.assetBundleName, false);
             * }
             */
            ObjectPool.Recycle(soundToDelete.Source.gameObject);
        }

        if (_settings.AutoPause)
        {
            bool curPause = Time.timeScale < 0.1f;
            if (curPause != AudioListener.pause)
            {
                AudioListener.pause = curPause;
            }
        }

        for (int i = 0; i < _musicFadingsOut.Count; i++)
        {
            SMMusicFadingOut music = _musicFadingsOut[i];
            if (music.Source == null)
            {
                _musicFadingsOut.RemoveAt(i);
                i--;
            }
            else
            {
                music.Timer        += Time.unscaledDeltaTime;
                _musicFadingsOut[i] = music;
                if (music.Timer >= music.FadingTime)
                {
                    Destroy(music.Source.gameObject);
                    _musicFadingsOut.RemoveAt(i);
                    i--;
                }
                else
                {
                    float k = Mathf.Clamp01(music.Timer / music.FadingTime);
                    music.Source.volume = Mathf.Lerp(music.StartVolume, 0, k);
                }
            }
        }

        if (_music != null && _music.FadingIn)
        {
            _music.Timer += Time.unscaledDeltaTime;
            if (_music.Timer >= _music.FadingTime)
            {
                _music.Source.volume = _music.TargetVolume;
                _music.FadingIn      = false;
            }
            else
            {
                float k = Mathf.Clamp01(_music.Timer / _music.FadingTime);
                _music.Source.volume = Mathf.Lerp(0, _music.TargetVolume, k);
            }
        }
    }
示例#18
0
 public void Stop(SMSound smSound)
 {
     StopSoundInternal(smSound);
 }
示例#19
0
    SMSound PlaySoundInternal(string assetBundleName, string soundName, bool pausable)
    {
        SMSound sound = new SMSound();

        sound.assetBundleName = assetBundleName;
        sound.Name            = soundName;
        sound.SelfVolume      = 1;

        if (string.IsNullOrEmpty(soundName))
        {
            Debug.Log("Sound null or empty");
            sound.IsValid = false;
            return(sound);
        }

        int sameCountGuard = 0;

        foreach (SMSound smSound in _sounds)
        {
            if (smSound.Name == soundName)
            {
                sameCountGuard++;
            }
        }

        if (sameCountGuard > 8)
        {
            Debug.Log("Too much duplicates for sound: " + soundName);
            sound.IsValid = false;
            return(sound);
        }

        if (_sounds.Count > 16)
        {
            Debug.Log("Too much sounds");
            sound.IsValid = false;
            return(sound);
        }

        GameObject soundGameObject = ObjectPool.Spawn();// new GameObject("Sound: " + soundName);

        soundGameObject.name = "Sound: " + soundName;
        AudioSource soundSource = soundGameObject.AddMissingComponent <AudioSource>();

        soundGameObject.transform.parent = transform;

        sound.Source  = soundSource;
        sound.IsValid = true;

        soundSource.outputAudioMixerGroup = _settings.SoundAudioMixerGroup;
        soundSource.priority            = 128;
        soundSource.playOnAwake         = false;
        soundSource.mute                = _settings.GetSoundMuted();
        soundSource.volume              = _settings.GetSoundVolumeCorrected();
        soundSource.ignoreListenerPause = !pausable;

        _sounds.Add(sound);

        PreloadedClip preloadedClip;

        if (_preloadedClips.TryGetValue(soundName, out preloadedClip))
        {
            soundSource.clip = preloadedClip.clip;
            soundSource.Play();
        }
        else
        {
            sound.LoadingCoroutine = PlaySoundInternalAfterLoad(sound, soundName, assetBundleName);
            StartCoroutine(sound.LoadingCoroutine);
        }

        return(sound);
    }