示例#1
0
        public void PlayDefaultSound(AudioClip audioClip, bool doLoop)
        {
            if (defaultSound == null)
            {
                Debug.Log("Cannot play sound since no Default Sound Prefab is defined - please set one in the Scene Manager.");
                return;
            }

            if (audioClip && defaultSound.GetComponent <AudioSource>())
            {
                defaultSound.GetComponent <AudioSource>().clip = audioClip;
                defaultSound.Play(doLoop);
            }
        }
示例#2
0
        /**
         * <summary>Plays an AudioClip on the default Sound prefab.</summary>
         * <param name = "audioClip">The AudioClip to play</param>
         * <param name = "doLoop">If True, the sound will loop</param>
         */
        public void PlayDefaultSound(AudioClip audioClip, bool doLoop)
        {
            if (audioClip == null)
            {
                return;
            }

            if (defaultSound == null)
            {
                ACDebug.Log("Cannot play audio '" + audioClip.name + "' since no Default Sound is defined in the scene - please assign one in the Scene Manager.", audioClip);
                return;
            }

            if (KickStarter.stateHandler.IsPaused() && !defaultSound.playWhilePaused)
            {
                ACDebug.LogWarning("Cannot play audio '" + audioClip.name + "' on Sound '" + defaultSound.gameObject.name + "' while the game is paused - check 'Play while game paused?' on the Sound component's Inspector.", defaultSound);
            }

            if (defaultAudioSource == null)
            {
                defaultAudioSource = defaultSound.GetComponent <AudioSource> ();
            }

            if (doLoop)
            {
                defaultAudioSource.clip = audioClip;
                defaultSound.Play(doLoop);
            }
            else
            {
                defaultSound.SetMaxVolume();
                defaultAudioSource.PlayOneShot(audioClip);
            }
        }
示例#3
0
        public void OnAwake()
        {
            KickStarter.navigationManager.OnAwake();

            // Turn off all NavMesh objects
            NavigationMesh[] navMeshes = FindObjectsOfType(typeof(NavigationMesh)) as NavigationMesh[];
            foreach (NavigationMesh _navMesh in navMeshes)
            {
                if (navMesh != _navMesh)
                {
                    _navMesh.TurnOff();
                }
            }

            if (navMesh)
            {
                navMesh.TurnOn();
            }

            stateChangeHooks = GetStateChangeHooks(GetComponents(typeof(IStateChange)));

            if (defaultSound != null)
            {
                defaultAudioSource = defaultSound.GetComponent <AudioSource>();
            }
        }
示例#4
0
        /**
         * <summary>Gets, and creates if necessary, an AudioSource used for Narration speech. If the narratorSound variable is empty, one will be generated and its AudioSource referenced.</summary>
         * <returns>The AudioSource for Narration speech</returns>
         */
        public AudioSource GetNarratorAudioSource()
        {
            if (narratorAudioSource == null)
            {
                if (narratorSound != null)
                {
                    narratorAudioSource = narratorSound.GetComponent <AudioSource>();
                }
                else
                {
                    GameObject narratorSoundOb = new GameObject("Narrator");
                    UnityVersionHandler.PutInFolder(narratorSoundOb, "_Sounds");

                    narratorAudioSource = narratorSoundOb.AddComponent <AudioSource>();
                    AdvGame.AssignMixerGroup(narratorAudioSource, SoundType.Speech);
                    narratorAudioSource.spatialBlend = 0f;

                    narratorSound           = narratorSoundOb.AddComponent <Sound>();
                    narratorSound.soundType = SoundType.Speech;
                }
            }

            narratorSound.SetMaxVolume();
            return(narratorAudioSource);
        }
示例#5
0
        public override void OnInspectorGUI()
        {
            Sound _target = (Sound)target;

            _target.soundType       = (SoundType)EditorGUILayout.EnumPopup("Sound type:", _target.soundType);
            _target.playWhilePaused = EditorGUILayout.Toggle("Play while game paused?", _target.playWhilePaused);
            _target.relativeVolume  = EditorGUILayout.Slider("Relative volume:", _target.relativeVolume, 0f, 1f);

            _target.surviveSceneChange = EditorGUILayout.Toggle("Play across scenes?", _target.surviveSceneChange);
            if (_target.surviveSceneChange)
            {
                if (_target.transform.root != null && _target.transform.root != _target.gameObject.transform)
                {
                    EditorGUILayout.HelpBox("For Sound to survive scene-changes, please move this object out of its hierarchy, so that it has no parent GameObject.", MessageType.Warning);
                }
                if (_target.GetComponent <ConstantID>() == null)
                {
                    EditorGUILayout.HelpBox("To avoid duplicates when re-loading the scene, please attach a ConstantID or RememberSound script component.", MessageType.Warning);
                }
            }

            if (GUI.changed)
            {
                EditorUtility.SetDirty(_target);
            }
        }
示例#6
0
 private void Awake()
 {
     if (soundToPlayFrom != null)
     {
         audioSource = soundToPlayFrom.GetComponent <AudioSource>();
     }
     character = GetComponent <Char>();
 }
示例#7
0
        private void Awake()
        {
            if (soundToPlayFrom != null)
            {
                audioSource = soundToPlayFrom.GetComponent <AudioSource>();
            }

            if (character == null)
            {
                character = GetComponent <Char>();
            }
            delayTime = walkSeparationTime / 2f;
        }
示例#8
0
        protected void Awake()
        {
            if (soundToPlayFrom != null)
            {
                audioSource = soundToPlayFrom.GetComponent <AudioSource>();
            }
            if (audioSource == null)
            {
                audioSource = GetComponent <AudioSource>();
            }

            if (character == null)
            {
                character = GetComponent <Char>();
            }
            delayTime = walkSeparationTime / 2f;

            if (soundToPlayFrom != null)
            {
                originalRelativeSound = soundToPlayFrom.relativeVolume;
            }
        }
示例#9
0
        protected void PlayMoveSound(float speed, float trackValue)
        {
            if (speed > slideSoundThreshold)
            {
                moveSound.relativeVolume = (speed - slideSoundThreshold);                // * 5f;
                moveSound.SetMaxVolume();
                if (slidePitchFactor > 0f)
                {
                    moveSound.GetComponent <AudioSource>().pitch = Mathf.Lerp(GetComponent <AudioSource>().pitch, Mathf.Min(1f, speed), Time.deltaTime * 5f);
                }
            }

            if (speed > slideSoundThreshold && !moveSound.IsPlaying())             // && trackValue > 0.02f && trackValue < 0.98f)
            {
                moveSound.relativeVolume = (speed - slideSoundThreshold);          // * 5f;
                moveSound.Play(moveSoundClip, true);
            }
            else if (speed <= slideSoundThreshold && moveSound.IsPlaying() && !moveSound.IsFading())
            {
                moveSound.FadeOut(0.2f);
            }
        }
示例#10
0
        public override void OnInspectorGUI()
        {
            Sound _target = (Sound)target;

            _target.soundType       = (SoundType)CustomGUILayout.EnumPopup("Sound type:", _target.soundType, "", "The type of sound, so far as volume levels go");
            _target.playWhilePaused = CustomGUILayout.Toggle("Play while game paused?", _target.playWhilePaused, "", "If True, then the sound can play when the game is paused");
            _target.relativeVolume  = CustomGUILayout.Slider("Relative volume:", _target.relativeVolume, 0f, 1f, "", "The volume of the sound, relative to its categoriy's 'global' volume set within OptionsData");

            _target.surviveSceneChange = CustomGUILayout.Toggle("Play across scenes?", _target.surviveSceneChange, "", "If True, then the GameObject this is attached to will not be destroyed when changing scene");
            if (_target.surviveSceneChange)
            {
                if (_target.transform.root != null && _target.transform.root != _target.gameObject.transform)
                {
                    EditorGUILayout.HelpBox("For Sound to survive scene-changes, please move this object out of its hierarchy, so that it has no parent GameObject.", MessageType.Warning);
                }
                if (_target.GetComponent <ConstantID>() == null)
                {
                    EditorGUILayout.HelpBox("To avoid duplicates when re-loading the scene, please attach a ConstantID or RememberSound script component.", MessageType.Warning);
                }
            }

            UnityVersionHandler.CustomSetDirty(_target);
        }
示例#11
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
        }
示例#12
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);
        }
示例#13
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
        }
示例#14
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
        }
示例#15
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);
        }
示例#16
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
        }