Ejemplo n.º 1
0
        /**
         * <summary>Deserialises a string of data, and restores the GameObject to its previous state.</summary>
         * <param name = "stringData">The data, serialised as a string</param>
         */
        public override void LoadData(string stringData, bool restoringSaveFile = false)
        {
            SoundData data = Serializer.LoadScriptData <SoundData> (stringData);

            if (data == null)
            {
                return;
            }

            Sound       sound       = GetComponent <Sound>();
            AudioSource audioSource = GetComponent <AudioSource>();

            sound.relativeVolume = data.relativeVolume;
            if (!restoringSaveFile && sound.surviveSceneChange)
            {
                return;
            }

            if (data.isPlaying)
            {
                audioSource.clip = AssetLoader.RetrieveAsset(audioSource.clip, data.clipID);
                sound.PlayAtPoint(data.isLooping, data.samplePoint);
            }
            else
            {
                sound.Stop();
            }
        }
Ejemplo n.º 2
0
        override public float Run()
        {
            if (movieClipType == MovieClipType.VideoPlayer)
            {
                                #if UNITY_5_6_OR_NEWER && !UNITY_SWITCH
                if (videoPlayer != null)
                {
                    if (!isRunning)
                    {
                        isRunning = true;

                        if (movieMaterialMethod == MovieMaterialMethod.PlayMovie)
                        {
                                                        #if UNITY_WEBGL
                            if (!string.IsNullOrEmpty(movieURL))
                            {
                                videoPlayer.url = movieURL;
                            }
                                                        #else
                            if (newClip != null)
                            {
                                videoPlayer.clip = newClip;
                            }
                                                        #endif

                            if (prepareOnly)
                            {
                                videoPlayer.Prepare();

                                if (willWait)
                                {
                                    return(defaultPauseTime);
                                }
                            }
                            else
                            {
                                KickStarter.playerInput.skipMovieKey = "";
                                videoPlayer.Play();

                                if (videoPlayer.isLooping)
                                {
                                    ACDebug.LogWarning("Cannot wait for " + videoPlayer.name + " to finish because it is looping!", videoPlayer);
                                    return(0f);
                                }

                                if (canSkip && skipKey != "")
                                {
                                    KickStarter.playerInput.skipMovieKey = skipKey;
                                }

                                if (willWait)
                                {
                                    return(defaultPauseTime);
                                }
                            }
                        }
                        else if (movieMaterialMethod == MovieMaterialMethod.PauseMovie)
                        {
                            videoPlayer.Pause();
                        }
                        else if (movieMaterialMethod == MovieMaterialMethod.StopMovie)
                        {
                            videoPlayer.Stop();
                        }

                        return(0f);
                    }
                    else
                    {
                        if (prepareOnly)
                        {
                            if (!videoPlayer.isPrepared)
                            {
                                return(defaultPauseTime);
                            }
                        }
                        else
                        {
                            if (pauseWithGame)
                            {
                                if (KickStarter.stateHandler.gameState == GameState.Paused)
                                {
                                    if (videoPlayer.isPlaying && !isPaused)
                                    {
                                        videoPlayer.Pause();
                                        isPaused = true;
                                    }
                                    return(defaultPauseTime);
                                }
                                else
                                {
                                    if (!videoPlayer.isPlaying && isPaused)
                                    {
                                        isPaused = false;
                                        videoPlayer.Play();
                                    }
                                }
                            }

                            if (canSkip && skipKey != "" && KickStarter.playerInput.skipMovieKey == "")
                            {
                                videoPlayer.Stop();
                                isRunning = false;
                                return(0f);
                            }

                            if (!videoPlayer.isPrepared || videoPlayer.isPlaying)
                            {
                                return(defaultPauseTime);
                            }
                        }

                        videoPlayer.Stop();
                        isRunning = false;
                        return(0f);
                    }
                }
                else
                {
                    ACDebug.LogWarning("Cannot play video - no Video Player found!");
                }
                                #else
                ACDebug.LogWarning("Use of the VideoPlayer for movie playback is only available in Unity 5.6 or later.");
                                #endif
                return(0f);
            }

                        #if (UNITY_IOS || UNITY_ANDROID || UNITY_WP8 || UNITY_TVOS)
            if (!isRunning && filePath != "")
            {
                isRunning = true;

                if (canSkip)
                {
                    Handheld.PlayFullScreenMovie(filePath, Color.black, FullScreenMovieControlMode.CancelOnInput);
                }
                else
                {
                    Handheld.PlayFullScreenMovie(filePath, Color.black, FullScreenMovieControlMode.Hidden);
                }
                return(defaultPauseTime);
            }
            else
            {
                isRunning = false;
                return(0f);
            }
                        #elif UNITY_STANDALONE && (UNITY_5 || UNITY_2017_1_OR_NEWER || UNITY_PRO_LICENSE) && !UNITY_2017_2_OR_NEWER
            if (movieClip == null)
            {
                ACDebug.LogWarning("Cannot play movie - no movie clip set!");
                return(0f);
            }
            if (movieClipType == MovieClipType.OnMaterial && material == null)
            {
                ACDebug.LogWarning("Cannot play movie - no material has been assigned. A movie clip can only be played as a material's texture, so a material must be assigned.");
                return(0f);
            }
            if (includeAudio && sound == null)
            {
                ACDebug.LogWarning("Cannot play movie audio - no Sound object has been assigned.");
            }

            if (!isRunning)
            {
                isRunning  = true;
                guiTexture = null;

                KickStarter.playerInput.skipMovieKey = "";

                if (movieClipType == MovieClipType.FullScreen)
                {
                    CreateFullScreenMovie();
                }
                else if (movieClipType == MovieClipType.OnMaterial)
                {
                    if (movieMaterialMethod == MovieMaterialMethod.PlayMovie)
                    {
                        material.mainTexture = movieClip;
                    }
                    else if (movieMaterialMethod == MovieMaterialMethod.PauseMovie)
                    {
                        if (material.mainTexture == movieClip)
                        {
                            movieClip.Pause();
                            isRunning = false;
                            return(0f);
                        }
                    }
                    else if (movieMaterialMethod == MovieMaterialMethod.StopMovie)
                    {
                        if (material.mainTexture == movieClip)
                        {
                            movieClip.Stop();
                            isRunning = false;
                            return(0f);
                        }
                    }
                }

                movieClip.Play();

                if (includeAudio && sound != null)
                {
                    if (movieClipType == MovieClipType.OnMaterial && movieMaterialMethod != MovieMaterialMethod.PlayMovie)
                    {
                        if (movieMaterialMethod == MovieMaterialMethod.PauseMovie)
                        {
                            sound.GetComponent <AudioSource>().Pause();
                        }
                        else if (movieMaterialMethod == MovieMaterialMethod.StopMovie)
                        {
                            sound.Stop();
                        }
                    }
                    else
                    {
                        sound.GetComponent <AudioSource>().clip = movieClip.audioClip;
                        sound.Play(false);
                    }
                }

                if (movieClipType == MovieClipType.FullScreen || willWait)
                {
                    if (canSkip && skipKey != "")
                    {
                        KickStarter.playerInput.skipMovieKey = skipKey;
                    }
                    return(defaultPauseTime);
                }
                return(0f);
            }
            else
            {
                if (movieClip.isPlaying)
                {
                    if (!canSkip || KickStarter.playerInput.skipMovieKey != "")
                    {
                        return(defaultPauseTime);
                    }
                }

                OnComplete();
                isRunning = false;
                return(0f);
            }
                        #else
            ACDebug.LogWarning("On non-mobile platforms, this Action is only available in Unity 5 or Unity Pro.");
            return(0f);
                        #endif
        }
Ejemplo n.º 3
0
        override public float Run()
        {
            if (runtimeSound == null)
            {
                return(0f);
            }

            if (!isRunning)
            {
                isRunning = true;

                if (ignoreIfPlaying && (soundAction == SoundAction.Play || soundAction == SoundAction.FadeIn))
                {
                    if ((audioClip != null && runtimeSound.IsPlaying(audioClip)) || (audioClip == null && runtimeSound.IsPlaying()))
                    {
                        // Sound object is already playing the desired clip
                        return(0f);
                    }
                }

                if (audioClip && runtimeSound.GetComponent <AudioSource>())
                {
                    if (soundAction == SoundAction.Play || soundAction == SoundAction.FadeIn)
                    {
                        runtimeSound.GetComponent <AudioSource>().clip = audioClip;
                    }
                }

                if (runtimeSound.soundType == SoundType.Music && (soundAction == SoundAction.Play || soundAction == SoundAction.FadeIn))
                {
                    Sound[] sounds = FindObjectsOfType(typeof(Sound)) as Sound[];
                    foreach (Sound sound in sounds)
                    {
                        sound.EndOld(SoundType.Music, runtimeSound);
                    }
                }

                if (soundAction == SoundAction.Play)
                {
                    runtimeSound.Play(loop);

                    if (!loop && willWait)
                    {
                        return(defaultPauseTime);
                    }
                }
                else if (soundAction == SoundAction.FadeIn)
                {
                    if (fadeTime <= 0f)
                    {
                        runtimeSound.Play(loop);
                    }
                    else
                    {
                        runtimeSound.FadeIn(fadeTime, loop);

                        if (!loop && willWait)
                        {
                            return(defaultPauseTime);
                        }
                    }
                }
                else if (soundAction == SoundAction.FadeOut)
                {
                    if (fadeTime <= 0f)
                    {
                        runtimeSound.Stop();
                    }
                    else
                    {
                        runtimeSound.FadeOut(fadeTime);

                        if (willWait)
                        {
                            return(fadeTime);
                        }
                    }
                }
                else if (soundAction == SoundAction.Stop)
                {
                    runtimeSound.Stop();

                    if (affectChildren)
                    {
                        foreach (Transform child in runtimeSound.transform)
                        {
                            if (child.GetComponent <Sound>())
                            {
                                child.GetComponent <Sound>().Stop();
                            }
                        }
                    }
                }
            }
            else
            {
                if (soundAction == SoundAction.FadeOut)
                {
                    isRunning = false;
                    return(0f);
                }

                if (runtimeSound.IsPlaying())
                {
                    return(defaultPauseTime);
                }
                else
                {
                    isRunning = false;
                }
            }

            return(0f);
        }
Ejemplo n.º 4
0
        override public float Run()
        {
                        #if UNITY_WEBGL
            return(0f);
                        #elif UNITY_IOS || UNITY_ANDROID || UNITY_WP8
            if (!isRunning && filePath != "")
            {
                isRunning = true;

                if (canSkip)
                {
                    Handheld.PlayFullScreenMovie(filePath, Color.black, FullScreenMovieControlMode.CancelOnInput);
                }
                else
                {
                    Handheld.PlayFullScreenMovie(filePath, Color.black, FullScreenMovieControlMode.Full);
                }
                return(defaultPauseTime);
            }
            else
            {
                isRunning = false;
                return(0f);
            }
                        #elif UNITY_5 || UNITY_PRO
            if (movieClip == null)
            {
                Debug.LogWarning("No movie clip set");
                return(0f);
            }
            if (material == null)
            {
                Debug.LogWarning("No material set");
                return(0f);
            }
            if (includeAudio && sound == null)
            {
                Debug.LogWarning("No sound set");
            }

            if (!isRunning)
            {
                isRunning = true;
                KickStarter.playerInput.skipMovieKey = "";

                material.mainTexture = movieClip;
                movieClip.Play();

                if (includeAudio)
                {
                    sound.GetComponent <AudioSource>().clip = movieClip.audioClip;
                    sound.Play(false);
                }

                if (willWait)
                {
                    if (canSkip && skipKey != "")
                    {
                        KickStarter.playerInput.skipMovieKey = skipKey;
                        return(defaultPauseTime);
                    }
                    return(movieClip.duration);
                }
                return(0f);
            }
            else
            {
                if (canSkip && movieClip.isPlaying)
                {
                    if (KickStarter.playerInput.skipMovieKey != "")
                    {
                        return(defaultPauseTime);
                    }
                }

                if (includeAudio)
                {
                    sound.Stop();
                }
                movieClip.Stop();
                isRunning = false;
                KickStarter.playerInput.skipMovieKey = "";
                return(0f);
            }
                        #else
            Debug.LogWarning("On non-mobile platforms, this Action is only available in Unity 5 or Unity Pro.");
            return(0f);
                        #endif
        }
Ejemplo n.º 5
0
        override public float Run()
        {
                        #if UNITY_WEBGL
            return(0f);
                        #elif UNITY_IOS || UNITY_ANDROID || UNITY_WP8
            if (!isRunning && filePath != "")
            {
                isRunning = true;

                if (canSkip)
                {
                    Handheld.PlayFullScreenMovie(filePath, Color.black, FullScreenMovieControlMode.CancelOnInput);
                }
                else
                {
                    Handheld.PlayFullScreenMovie(filePath, Color.black, FullScreenMovieControlMode.Full);
                }
                return(defaultPauseTime);
            }
            else
            {
                isRunning = false;
                return(0f);
            }
                        #elif UNITY_5 || UNITY_PRO_LICENSE
            if (movieClip == null)
            {
                ACDebug.LogWarning("Cannot play movie - no movie clip set!");
                return(0f);
            }
            if (movieClipType == MovieClipType.OnMaterial && material == null)
            {
                ACDebug.LogWarning("Cannot play movie - no material has been assigned. A movie clip can only be played as a material's texture, so a material must be assigned.");
                return(0f);
            }
            if (includeAudio && sound == null)
            {
                ACDebug.LogWarning("Cannot play movie audio - no Sound object has been assigned.");
            }

            if (!isRunning)
            {
                isRunning  = true;
                guiTexture = null;

                KickStarter.playerInput.skipMovieKey = "";

                if (movieClipType == MovieClipType.FullScreen)
                {
                    CreateFullScreenMovie();
                }
                else if (movieClipType == MovieClipType.OnMaterial)
                {
                    if (movieMaterialMethod == MovieMaterialMethod.PlayMovie)
                    {
                        material.mainTexture = movieClip;
                    }
                    else if (movieMaterialMethod == MovieMaterialMethod.PauseMovie)
                    {
                        if (material.mainTexture == movieClip)
                        {
                            movieClip.Pause();
                            isRunning = false;
                            return(0f);
                        }
                    }
                    else if (movieMaterialMethod == MovieMaterialMethod.StopMovie)
                    {
                        if (material.mainTexture == movieClip)
                        {
                            movieClip.Stop();
                            isRunning = false;
                            return(0f);
                        }
                    }
                }

                movieClip.Play();

                if (includeAudio && sound != null)
                {
                    if (movieClipType == MovieClipType.OnMaterial && movieMaterialMethod != MovieMaterialMethod.PlayMovie)
                    {
                        if (movieMaterialMethod == MovieMaterialMethod.PauseMovie)
                        {
                            sound.GetComponent <AudioSource>().Pause();
                        }
                        else if (movieMaterialMethod == MovieMaterialMethod.StopMovie)
                        {
                            sound.Stop();
                        }
                    }
                    else
                    {
                        sound.GetComponent <AudioSource>().clip = movieClip.audioClip;
                        sound.Play(false);
                    }
                }

                if (movieClipType == MovieClipType.FullScreen || willWait)
                {
                    if (canSkip && skipKey != "")
                    {
                        KickStarter.playerInput.skipMovieKey = skipKey;
                    }
                    return(defaultPauseTime);
                }
                return(0f);
            }
            else
            {
                if (movieClip.isPlaying)
                {
                    if (!canSkip || KickStarter.playerInput.skipMovieKey != "")
                    {
                        return(defaultPauseTime);
                    }
                }

                if (includeAudio)
                {
                    sound.Stop();
                }
                movieClip.Stop();
                KickStarter.playerInput.skipMovieKey = "";

                if (movieClipType == MovieClipType.FullScreen)
                {
                    EndFullScreenMovie();
                }

                isRunning = false;
                return(0f);
            }
                        #else
            ACDebug.LogWarning("On non-mobile platforms, this Action is only available in Unity 5 or Unity Pro.");
            return(0f);
                        #endif
        }
Ejemplo n.º 6
0
        override public float Run()
        {
            if (soundObject)
            {
                if ((audioClip != null && soundObject.IsPlaying(audioClip)) || (audioClip == null && soundObject.IsPlaying()))
                {
                    // Sound object is already playing the desired clip
                    if (ignoreIfPlaying && (soundAction == SoundAction.Play || soundAction == SoundAction.FadeIn))
                    {
                        return(0f);
                    }
                }

                if (audioClip && soundObject.GetComponent <AudioSource>())
                {
                    if (soundAction == SoundAction.Play || soundAction == SoundAction.FadeIn)
                    {
                        soundObject.GetComponent <AudioSource>().clip = audioClip;
                    }
                }

                if (soundObject.soundType == SoundType.Music && (soundAction == SoundAction.Play || soundAction == SoundAction.FadeIn))
                {
                    Sound[] sounds = FindObjectsOfType(typeof(Sound)) as Sound[];
                    foreach (Sound sound in sounds)
                    {
                        sound.EndOldMusic(soundObject);
                    }
                }

                if (soundAction == SoundAction.Play)
                {
                    soundObject.Play(loop);
                }
                else if (soundAction == SoundAction.FadeIn)
                {
                    if (fadeTime == 0f)
                    {
                        soundObject.Play(loop);
                    }
                    else
                    {
                        soundObject.FadeIn(fadeTime, loop);
                    }
                }
                else if (soundAction == SoundAction.FadeOut)
                {
                    if (fadeTime == 0f)
                    {
                        soundObject.Stop();
                    }
                    else
                    {
                        soundObject.FadeOut(fadeTime);
                    }
                }
                else if (soundAction == SoundAction.Stop)
                {
                    soundObject.Stop();

                    if (affectChildren)
                    {
                        foreach (Transform child in soundObject.transform)
                        {
                            if (child.GetComponent <Sound>())
                            {
                                child.GetComponent <Sound>().Stop();
                            }
                        }
                    }
                }
            }

            return(0f);
        }
Ejemplo n.º 7
0
        override public float Run()
        {
            if (movieClipType == MovieClipType.VideoPlayer)
            {
                                #if ALLOW_VIDEOPLAYER
                if (videoPlayer != null)
                {
                    if (!isRunning)
                    {
                        isRunning = true;

                        if (movieMaterialMethod == MovieMaterialMethod.PlayMovie)
                        {
                            if (prepareOnly)
                            {
                                videoPlayer.Prepare();

                                if (willWait)
                                {
                                    return(defaultPauseTime);
                                }
                            }
                            else
                            {
                                KickStarter.playerInput.skipMovieKey = "";
                                videoPlayer.Play();

                                if (videoPlayer.isLooping)
                                {
                                    ACDebug.LogWarning("Cannot wait for " + videoPlayer.name + " to finish because it is looping!");
                                    return(0f);
                                }

                                if (canSkip && skipKey != "")
                                {
                                    KickStarter.playerInput.skipMovieKey = skipKey;
                                }

                                if (willWait)
                                {
                                    return(defaultPauseTime);
                                }
                            }
                        }
                        else if (movieMaterialMethod == MovieMaterialMethod.PauseMovie)
                        {
                            videoPlayer.Pause();
                        }
                        else if (movieMaterialMethod == MovieMaterialMethod.StopMovie)
                        {
                            videoPlayer.Stop();
                        }

                        return(0f);
                    }
                    else
                    {
                        if (prepareOnly)
                        {
                            if (!videoPlayer.isPrepared)
                            {
                                return(defaultPauseTime);
                            }
                        }
                        else
                        {
                            if (canSkip && skipKey != "" && KickStarter.playerInput.skipMovieKey == "")
                            {
                                videoPlayer.Stop();
                                isRunning = false;
                                return(0f);
                            }

                            if (!videoPlayer.isPrepared || videoPlayer.isPlaying)
                            {
                                return(defaultPauseTime);
                            }
                        }

                        isRunning = false;
                        return(0f);
                    }
                }
                else
                {
                    ACDebug.LogWarning("Cannot play video - no Video Player found!");
                }
                                #else
                ACDebug.LogWarning("Use of the VideoPlayer for movie playback is only available in Unity 5.6 or later.");
                                #endif
                return(0f);
            }

                        #if ALLOW_HANDHELD
            if (!isRunning && filePath != "")
            {
                isRunning = true;

                if (canSkip)
                {
                    Handheld.PlayFullScreenMovie(filePath, Color.black, FullScreenMovieControlMode.CancelOnInput);
                }
                else
                {
                    Handheld.PlayFullScreenMovie(filePath, Color.black, FullScreenMovieControlMode.Hidden);
                }
                return(defaultPauseTime);
            }
            else
            {
                isRunning = false;
                return(0f);
            }
                        #elif ALLOW_MOVIETEXTURES
            if (movieClip == null)
            {
                ACDebug.LogWarning("Cannot play movie - no movie clip set!");
                return(0f);
            }
            if (movieClipType == MovieClipType.OnMaterial && material == null)
            {
                ACDebug.LogWarning("Cannot play movie - no material has been assigned. A movie clip can only be played as a material's texture, so a material must be assigned.");
                return(0f);
            }
            if (includeAudio && sound == null)
            {
                ACDebug.LogWarning("Cannot play movie audio - no Sound object has been assigned.");
            }

            if (!isRunning)
            {
                isRunning  = true;
                guiTexture = null;

                KickStarter.playerInput.skipMovieKey = "";

                if (movieClipType == MovieClipType.FullScreen)
                {
                    CreateFullScreenMovie();
                }
                else if (movieClipType == MovieClipType.OnMaterial)
                {
                    if (movieMaterialMethod == MovieMaterialMethod.PlayMovie)
                    {
                        material.mainTexture = movieClip;
                    }
                    else if (movieMaterialMethod == MovieMaterialMethod.PauseMovie)
                    {
                        if (material.mainTexture == movieClip)
                        {
                            movieClip.Pause();
                            isRunning = false;
                            return(0f);
                        }
                    }
                    else if (movieMaterialMethod == MovieMaterialMethod.StopMovie)
                    {
                        if (material.mainTexture == movieClip)
                        {
                            movieClip.Stop();
                            isRunning = false;
                            return(0f);
                        }
                    }
                }

                movieClip.Play();

                if (includeAudio && sound != null)
                {
                    if (movieClipType == MovieClipType.OnMaterial && movieMaterialMethod != MovieMaterialMethod.PlayMovie)
                    {
                        if (movieMaterialMethod == MovieMaterialMethod.PauseMovie)
                        {
                            sound.GetComponent <AudioSource>().Pause();
                        }
                        else if (movieMaterialMethod == MovieMaterialMethod.StopMovie)
                        {
                            sound.Stop();
                        }
                    }
                    else
                    {
                        sound.GetComponent <AudioSource>().clip = movieClip.audioClip;
                        sound.Play(false);
                    }
                }

                if (movieClipType == MovieClipType.FullScreen || willWait)
                {
                    if (canSkip && skipKey != "")
                    {
                        KickStarter.playerInput.skipMovieKey = skipKey;
                    }
                    return(defaultPauseTime);
                }
                return(0f);
            }
            else
            {
                if (movieClip.isPlaying)
                {
                    if (!canSkip || KickStarter.playerInput.skipMovieKey != "")
                    {
                        return(defaultPauseTime);
                    }
                }

                OnComplete();
                isRunning = false;
                return(0f);
            }
                        #else
            ACDebug.LogWarning("On non-mobile platforms, this Action is only available in Unity 5 or Unity Pro.");
            return(0f);
                        #endif
        }