PsaiResult IAudioPlaybackLayerChannel.LoadSegment(Segment segment)
        {
            _segmentToLoad = segment;
            AudioClip = null;

            #if UNITY_PRO_LICENSE
            if (_psaiAsyncLoader == null)
            {
                GameObject psaiObject = PsaiCoreManager.Instance.gameObject;

                if (psaiObject == null)
                {
                    #if !(PSAI_NOLOG)
                    if (LogLevel.errors <= Logger.Instance.LogLevel)
                    {
                            Logger.Instance.Log("No 'Psai' object found in the Scene! Please make sure to add the Psai.prefab from the Psai.unitypackage to your Scene", LogLevel.errors);
                    }
                    #endif
                    return PsaiResult.initialization_error;
                }
                _psaiAsyncLoader = psaiObject.AddComponent<PsaiAsyncLoader>();
            }
            #endif

            // careful! Using Path.Combine for the subfolders does not work for the Resources subfolders,
            // neither does "\\" double backslashes. So leave it like this, it works for WebPlayer and Standalone.
            // not checked yet for iOS and Android. If in doubt, leave out the subfolders.

            //string pathToClip = null;
            string psaiBinaryDirectoryName = Logik.Instance.m_psaiCoreBinaryDirectoryName;
            if (psaiBinaryDirectoryName.Length > 0)
            {
                PathToClip = psaiBinaryDirectoryName + "/" + segment.audioData.filePathRelativeToProjectDir;
            }
            else
            {
                PathToClip = segment.audioData.filePathRelativeToProjectDir;
            }

            #if UNITY_PRO_LICENSE
            {
                _audioSource.clip = null;       // we reset the clip to prevent the situation in ScheduleSegmentPlayback(), where the previous clip was reported as readyToPlay, causing problems.
                _psaiAsyncLoader.LoadSegmentAsync(this);
            }
            return PsaiResult.OK;
            #else

            if (_tryToUseWrappers)
            {
                GameObject wrapperGameObject = (GameObject)UnityEngine.Resources.Load(PathToClipWrapper, typeof(GameObject));
                if (wrapperGameObject != null)
                {
                    PsaiAudioClipWrapper wrapperComponent = wrapperGameObject.GetComponent<PsaiAudioClipWrapper>();
                    if (wrapperComponent == null || wrapperComponent._audioClip == null)
                    {
                        Debug.LogError("a Wrapper prefab for AudioClip '" + _segmentToLoad.audioData.filePathRelativeToProjectDir + "' was found, but it was invalid. Please re-run the psaiMultiAudioObjectEditor on your soundtrack folder, and make sure 'create Wrappers' is enabled.");
                    }
                    else
                    {
                        AudioClip = wrapperComponent._audioClip;

                        #if (!PSAI_NOLOG)
                        if (LogLevel.debug <= Logger.Instance.LogLevel)
                        {
                            Logger.Instance.Log("success: audioClip loaded from Wrapper (synchronous)", LogLevel.debug);
                        }
                        #endif
                    }
                }
            }

            // Fallback: Load Clip directly.
            if (AudioClip == null)
            {

                AudioClip = UnityEngine.Resources.Load(PathToClip) as AudioClip;

            #if (!PSAI_NOLOG)

                if (_tryToUseWrappers && !_psaiWrapperWarningHasBeenShown && LogLevel.warnings <= Logger.Instance.LogLevel)
                {
                    Logger.Instance.Log("Due to an issue in Unity 4.x AudioClips will in some cases not be streamed from disk, even if their import settings are set accordingly. This may cause framerate drops whenever a new Segment is loaded. Psai provides a workaround for this, by wrapping each AudioClip in a dedicated GameObject. To have the Wrappers created, please right-click on your soundtrack folder in the Project window, and run the 'psai Multi Audio Object Editor'. Make sure 'use Wrappers' is enabled.", LogLevel.warnings);
                    _psaiWrapperWarningHasBeenShown = true;
                }
            #endif
            }

            /* final check to return PsaiResult and write Log */
            if (AudioClip == null)
            {
            #if (!PSAI_NOLOG)
                if (LogLevel.errors <= Logger.Instance.LogLevel)
                {
                    Logger.Instance.Log("Segment not found: " + PathToClipWrapper, LogLevel.errors);
                }
            #endif
                return PsaiResult.file_notFound;
            }
            else
            {

            #if (!PSAI_NOLOG)
                if (LogLevel.debug <= Logger.Instance.LogLevel)
                {
                    Logger.Instance.Log("LoadSegment() OK - segment.Name:" + segment.Name  + " _audioSource.clip: " + _audioSource.clip +  " PathToClip:"  + PathToClip, LogLevel.debug);
                }
            #endif
                return PsaiResult.OK;
            }
            #endif
        }
        PsaiResult IAudioPlaybackLayerChannel.LoadSegment(Segment segment)
        {
            _segmentToLoad = segment;
            AudioClip      = null;

#if UNITY_PRO_LICENSE
            if (_psaiAsyncLoader == null)
            {
                GameObject psaiObject = PsaiCoreManager.Instance.gameObject;

                if (psaiObject == null)
                {
                    #if !(PSAI_NOLOG)
                    if (LogLevel.errors <= Logger.Instance.LogLevel)
                    {
                        Logger.Instance.Log("No 'Psai' object found in the Scene! Please make sure to add the Psai.prefab from the Psai.unitypackage to your Scene", LogLevel.errors);
                    }
                    #endif
                    return(PsaiResult.initialization_error);
                }
                _psaiAsyncLoader = psaiObject.AddComponent <PsaiAsyncLoader>();
            }
#endif


            // careful! Using Path.Combine for the subfolders does not work for the Resources subfolders,
            // neither does "\\" double backslashes. So leave it like this, it works for WebPlayer and Standalone.
            // not checked yet for iOS and Android. If in doubt, leave out the subfolders.

            //string pathToClip = null;
            string psaiBinaryDirectoryName = Logik.Instance.m_psaiCoreBinaryDirectoryName;
            if (psaiBinaryDirectoryName.Length > 0)
            {
                PathToClip = psaiBinaryDirectoryName + "/" + segment.audioData.filePathRelativeToProjectDir;
            }
            else
            {
                PathToClip = segment.audioData.filePathRelativeToProjectDir;
            }


#if UNITY_PRO_LICENSE
            {
                _audioSource.clip = null;       // we reset the clip to prevent the situation in ScheduleSegmentPlayback(), where the previous clip was reported as readyToPlay, causing problems.
                _psaiAsyncLoader.LoadSegmentAsync(this);
            }
            return(PsaiResult.OK);
#else
            if (_tryToUseWrappers)
            {
                GameObject wrapperGameObject = (GameObject)UnityEngine.Resources.Load(PathToClipWrapper, typeof(GameObject));
                if (wrapperGameObject != null)
                {
                    PsaiAudioClipWrapper wrapperComponent = wrapperGameObject.GetComponent <PsaiAudioClipWrapper>();
                    if (wrapperComponent == null || wrapperComponent._audioClip == null)
                    {
                        Debug.LogError("a Wrapper prefab for AudioClip '" + _segmentToLoad.audioData.filePathRelativeToProjectDir + "' was found, but it was invalid. Please re-run the psaiMultiAudioObjectEditor on your soundtrack folder, and make sure 'create Wrappers' is enabled.");
                    }
                    else
                    {
                        AudioClip = wrapperComponent._audioClip;

                        #if (!PSAI_NOLOG)
                        if (LogLevel.debug <= Logger.Instance.LogLevel)
                        {
                            Logger.Instance.Log("success: audioClip loaded from Wrapper (synchronous)", LogLevel.debug);
                        }
                        #endif
                    }
                }
            }

            // Fallback: Load Clip directly.
            if (AudioClip == null)
            {
                AudioClip = UnityEngine.Resources.Load(PathToClip) as AudioClip;

#if (!PSAI_NOLOG)
                if (_tryToUseWrappers && !_psaiWrapperWarningHasBeenShown && LogLevel.warnings <= Logger.Instance.LogLevel)
                {
                    Logger.Instance.Log("Due to an issue in Unity 4.x AudioClips will in some cases not be streamed from disk, even if their import settings are set accordingly. This may cause framerate drops whenever a new Segment is loaded. Psai provides a workaround for this, by wrapping each AudioClip in a dedicated GameObject. To have the Wrappers created, please right-click on your soundtrack folder in the Project window, and run the 'psai Multi Audio Object Editor'. Make sure 'use Wrappers' is enabled.", LogLevel.warnings);
                    _psaiWrapperWarningHasBeenShown = true;
                }
#endif
            }


            /* final check to return PsaiResult and write Log */
            if (AudioClip == null)
            {
#if (!PSAI_NOLOG)
                if (LogLevel.errors <= Logger.Instance.LogLevel)
                {
                    Logger.Instance.Log("Segment not found: " + PathToClipWrapper, LogLevel.errors);
                }
#endif
                return(PsaiResult.file_notFound);
            }
            else
            {
#if (!PSAI_NOLOG)
                if (LogLevel.debug <= Logger.Instance.LogLevel)
                {
                    Logger.Instance.Log("LoadSegment() OK - segment.Name:" + segment.Name + " _audioSource.clip: " + _audioSource.clip + " PathToClip:" + PathToClip, LogLevel.debug);
                }
#endif
                return(PsaiResult.OK);
            }
#endif
        }
        PsaiResult IAudioPlaybackLayerChannel.LoadSegment(Segment segment)
        {
            _segmentToLoad = segment;
            AudioClip = null;

            #if (!PSAI_BUILT_BY_VS)
            if (_psaiAsyncLoader == null)
            {
                GameObject psaiObject = PsaiCoreManager.Instance.gameObject;

                if (psaiObject == null)
                {
                    #if !(PSAI_NOLOG)
                    if (LogLevel.errors <= Logger.Instance.LogLevel)
                    {
                            Logger.Instance.Log("No 'Psai' object found in the Scene! Please make sure to add the Psai.prefab from the Psai.unitypackage to your Scene", LogLevel.errors);
                    }
                    #endif
                    return PsaiResult.initialization_error;
                }
                _psaiAsyncLoader = psaiObject.AddComponent<PsaiAsyncLoader>();
            }
            #endif

            // careful! Using Path.Combine for the subfolders does not work for the Resources subfolders,
            // neither does "\\" double backslashes. So leave it like this, it works for WebPlayer and Standalone.
            // not checked yet for iOS and Android. If in doubt, leave out the subfolders.

            //string pathToClip = null;
            string psaiBinaryDirectoryName = Logik.Instance.m_psaiCoreBinaryDirectoryName;
            if (psaiBinaryDirectoryName.Length > 0)
            {
                PathToClip = psaiBinaryDirectoryName + "/" + segment.audioData.filePathRelativeToProjectDir;
            }
            else
            {
                PathToClip = segment.audioData.filePathRelativeToProjectDir;
            }

            _audioSource.clip = null;       // we reset the clip to prevent the situation in ScheduleSegmentPlayback(), where the previous clip was reported as readyToPlay, causing problems.
            _psaiAsyncLoader.LoadSegmentAsync(this);
            return PsaiResult.OK;

            /*
            // Fallback: Load Clip directly.
            if (AudioClip == null)
            {
                AudioClip = UnityEngine.Resources.Load(PathToClip) as AudioClip;
            }

            if (AudioClip == null)
            {
                #if (!PSAI_NOLOG)
                if (LogLevel.errors <= Logger.Instance.LogLevel)
                {
                    Logger.Instance.Log("Segment not found: " + PathToClip, LogLevel.errors);
                }
                #endif
                return PsaiResult.file_notFound;
            }
            else
            {

                #if (!PSAI_NOLOG)
                if (LogLevel.debug <= Logger.Instance.LogLevel)
                {
                    Logger.Instance.Log("LoadSegment() OK - segment.Name:" + segment.Name  + " _audioSource.clip: " + _audioSource.clip +  " PathToClip:"  + PathToClip, LogLevel.debug);
                }
                #endif

                return PsaiResult.OK;
            }
             */
        }
Пример #4
0
        PsaiResult IAudioPlaybackLayerChannel.LoadSegment(Segment segment)
        {
            _segmentToLoad = segment;
            AudioClip      = null;


#if (!PSAI_BUILT_BY_VS)
            if (_psaiAsyncLoader == null)
            {
                GameObject psaiObject = PsaiCoreManager.Instance.gameObject;

                if (psaiObject == null)
                {
                    #if !(PSAI_NOLOG)
                    if (LogLevel.errors <= Logger.Instance.LogLevel)
                    {
                        Logger.Instance.Log("No 'Psai' object found in the Scene! Please make sure to add the Psai.prefab from the Psai.unitypackage to your Scene", LogLevel.errors);
                    }
                    #endif
                    return(PsaiResult.initialization_error);
                }
                _psaiAsyncLoader = psaiObject.AddComponent <PsaiAsyncLoader>();
            }
#endif

            // careful! Using Path.Combine for the subfolders does not work for the Resources subfolders,
            // neither does "\\" double backslashes. So leave it like this, it works for WebPlayer and Standalone.
            // not checked yet for iOS and Android. If in doubt, leave out the subfolders.

            //string pathToClip = null;
            string psaiBinaryDirectoryName = Logik.Instance.m_psaiCoreBinaryDirectoryName;
            if (psaiBinaryDirectoryName.Length > 0)
            {
                PathToClip = psaiBinaryDirectoryName + "/" + segment.audioData.filePathRelativeToProjectDir;
            }
            else
            {
                PathToClip = segment.audioData.filePathRelativeToProjectDir;
            }

            _audioSource.clip = null;       // we reset the clip to prevent the situation in ScheduleSegmentPlayback(), where the previous clip was reported as readyToPlay, causing problems.
            _psaiAsyncLoader.LoadSegmentAsync(this);
            return(PsaiResult.OK);

            /*
             * // Fallback: Load Clip directly.
             * if (AudioClip == null)
             * {
             *  AudioClip = UnityEngine.Resources.Load(PathToClip) as AudioClip;
             * }
             *
             * if (AudioClip == null)
             * {
             #if (!PSAI_NOLOG)
             *  if (LogLevel.errors <= Logger.Instance.LogLevel)
             *  {
             *      Logger.Instance.Log("Segment not found: " + PathToClip, LogLevel.errors);
             *  }
             #endif
             *  return PsaiResult.file_notFound;
             * }
             * else
             * {
             *
             #if (!PSAI_NOLOG)
             *  if (LogLevel.debug <= Logger.Instance.LogLevel)
             *  {
             *      Logger.Instance.Log("LoadSegment() OK - segment.Name:" + segment.Name  + " _audioSource.clip: " + _audioSource.clip +  " PathToClip:"  + PathToClip, LogLevel.debug);
             *  }
             #endif
             *
             *  return PsaiResult.OK;
             * }
             */
        }