Пример #1
0
        private void Awake()
        {
            _levelManager = Camera.main.GetComponent <LevelManager>();

            _audioResults   = _menuItems[(int)MenuItems.Results].GetComponent <AudioSource>();
            _playingResults = _menuItems[(int)MenuItems.Results].GetComponent <PlayingSound>();
        }
Пример #2
0
    public void mungGoonSound()
    {
        int i = UnityEngine.Random.Range(1, 6);

        switch (i)
        {
        case 1:
            aud.PlayOneShot(mungGoon1);
            break;

        case 2:
            aud.PlayOneShot(mungGoon2);
            break;

        case 3:
            aud.PlayOneShot(mungGoon3);
            break;

        case 4:
            aud.PlayOneShot(mungGoon4);
            break;

        case 5:
            aud.PlayOneShot(mungGoon5);
            break;
        }
        JangGoonSound.SetActive(false);
        PlayingSound.SetActive(true);
    }
Пример #3
0
    IEnumerator Fade(PlayingSound sound, float from, float to, float time)
    {
        if (sound.soundSource.active)
        {
            float step = 1.0f / time;
            float i    = 0.0f;

            while (i <= 1.0f)
            {
                // stop fading if sound source has been deactivated
                if (sound.soundSource == null || !sound.soundSource.active)
                {
                    break;
                }

                i += step * Time.deltaTime;
                sound.soundSource.audio.volume = Mathf.Lerp(from, to, i);

#if DEBUG_SOUNDS
                Debug.Log("fade sound: " + sound.name + " volume at " + sound.soundSource.audio.volume);
#endif

                yield return(new WaitForSeconds(step * Time.deltaTime));
            }
        }
    }
Пример #4
0
    // Use this for initialization
    void Start()
    {
        this.aud       = GetComponent <AudioSource>();
        view           = GetComponent <PhotonView>();
        anchor         = GameObject.Find("Anchor");
        searchPath     = GameObject.Find("SearchPath").GetComponent <SearchPath>();
        publicVariable = GameObject.Find("PublicVariable").GetComponent <PublicVariable>();
        jangGoonCheck  = GameObject.Find("JangGoonCheck").GetComponent <JangGoonCheck>();
        GameStartImage.gameObject.SetActive(true);
        publicVariable.setIsStart(true);
        StartCoroutine("GameStart");

        for (i = 1; i <= 9; i++)
        {
            for (j = 1; j <= 10; j++)
            {
                position_name          = "w" + i + "h" + j;
                mal_position[i, j]     = position_name;
                attackedPosition[i, j] = false;
            }
        }

        if (!PhotonNetwork.isMasterClient)
        {
            field = GameObject.Find("JangGiField(Clone)");
            field.transform.Rotate(0, 180.0f, 0);
            myTag = "Han";
        }

        CreateDefaultMal();

        aud.PlayOneShot(startSound);
        PlayingSound.SetActive(true);
    }
Пример #5
0
        public static async Task PlaySoundAsync(Sound sound)
        {
            List <Sound> soundList = new List <Sound>
            {
                sound
            };

            MediaPlayer player = await FileManager.CreateMediaPlayerAsync(soundList, 0);

            if (player == null)
            {
                return;
            }

            // If PlayOneSoundAtOnce is true, remove all sounds from PlayingSounds List
            if (FileManager.itemViewHolder.PlayOneSoundAtOnce)
            {
                List <PlayingSound> removedPlayingSounds = new List <PlayingSound>();
                foreach (PlayingSound pSound in FileManager.itemViewHolder.PlayingSounds)
                {
                    removedPlayingSounds.Add(pSound);
                }

                await RemoveSoundsFromPlayingSoundsListAsync(removedPlayingSounds);
            }

            PlayingSound playingSound = new PlayingSound(sound, player)
            {
                Uuid = await FileManager.AddPlayingSoundAsync(Guid.Empty, soundList, 0, 0, false, player.Volume)
            };

            FileManager.itemViewHolder.PlayingSounds.Add(playingSound);
            playingSound.MediaPlayer.Play();
        }
Пример #6
0
        public IStoppable PlaySound(string path, bool looping, bool ui)
        {
            foreach (var sound in m_sounds)
            {
                if (sound.Playback.Sound.Path == path &&
                    sound.Looping == looping &&
                    sound.UI == ui &&
                    (looping || sound.StartFrame == m_frame))
                {
                    sound.AddRef();
                    return(sound);
                }
            }

            var playback = m_audio.PlaySound(path, looping);

            if (playback != null)
            {
                if (!ui)
                {
                    playback.Rate = m_rate;
                }
                var sound = new PlayingSound(playback, m_frame, ui);
                m_sounds.Add(sound);
                return(sound);
            }
            return(null);
        }
 private void PlayingSoundTemplate_DataContextChanged(FrameworkElement sender, DataContextChangedEventArgs args)
 {
     if (DataContext != null)
     {
         PlayingSound = DataContext as PlayingSound;
         InitializePlayingSound();
     }
 }
Пример #8
0
        protected virtual void Awake()
        {
            _rigidbody = GetComponent <Rigidbody2D>();
            _animator  = GetComponent <Animator>();
            _sprite    = GetComponent <SpriteRenderer>();

            _playingSound = transform.parent.GetComponentInParent <PlayingSound>();
            _levelManager = Camera.main.GetComponent <LevelManager>();
        }
Пример #9
0
    void CookieCollected(GameObject player)
    {
        PlayingSound ps =
            Play(GlobalNames.SOUND.Cookie_Collected + Random.Range(1, 5),
                 player);

        StartCoroutine(UpdatePosition(ps));
        StartCoroutine(Stop(ps, ps.soundSource.audio.clip.length));
    }
Пример #10
0
        public void StopPlayback(PlayingSound sound)
        {
            if (isDisposed)
            {
                return;
            }

            mixer.RemoveMixerInput(sound.SampleProvider);
        }
Пример #11
0
    /// <summary>
    /// Plays a sound effect
    /// </summary>
    /// <param name="Id">Id of the sound effect in the catalog</param>
    /// <param name="source">AudioSource where the sound will come from. Null to generate a temporary one</param>
    /// <param name="loop">Is the sound looped?</param>
    /// <param name="finished">Specify a method you want to be invoked when the sound finished playing</param>
    public void PlaySfx(string Id, AudioSource source, bool loop, GameManager.GameEvent finished)
    {
        if (!string.IsNullOrEmpty(Id))
        {
            AudioCatalog.IndexedClipList clip = findSfxInCatalogs(Id);
            AudioClip aClip = null;
            if (clip != null)
            {
                //decide which audio clip to play
                if ((clip.Clips != null) && (clip.Clips.Length > 0))
                {
                    //select a random clip from the ones available
                    aClip = clip.Clips[Random.Range(0, clip.Clips.Length)];
                }
                else
                {
                    Debug.LogError(string.Format("SFX {0} does not contains any AudioClips!", Id));
                }

                bool asCreated = false;
                if (aClip != null)
                {
                    //if no AudioSource was specified, create a new one
                    if (source == null)
                    {
                        GameObject gO = GetAudioObject(Id);
                        source    = gO.GetComponent <AudioSource>();
                        asCreated = true;
                    }

                    //Add the sound to the sounds being played
                    PlayingSound pS = new PlayingSound();
                    pS.Source          = source;
                    pS.DestroyOnFinish = asCreated;
                    pS.Looped          = loop;
                    pS.Finished        = finished;
                    pS.Id          = Id;
                    pS.InmediateCC = clip.InmediateCC;
                    pS.recycle     = asCreated;
                    this.playingSounds.Add(pS);

                    //TODO: Soporte de Closed Captions

                    //actually play the sound
                    source.clip   = aClip;
                    source.loop   = loop;
                    source.volume = GameManager.Instance.Options.Options.SfxVolume;
                    source.Play();
                }
            }
            else
            {
                Debug.LogError(string.Format("SFX {0} not defined in any AudioCatalog!", Id));
            }
        }
    }
Пример #12
0
    void PlayerJumpEnd(GameObject player)
    {
        PlayingSound ps = Play(GlobalNames.SOUND.Player_Land, player);

        // HACK this event is called even after the component has been destroyed
        if (this != null)
        {
            StartCoroutine(Stop(ps, ps.soundSource.audio.clip.length));
        }
    }
Пример #13
0
 private void markSfxForDestruction(PlayingSound sToDestroy, float fadeTime)
 {
     if (sToDestroy != null)
     {
         sToDestroy.FadeStartVolume = (sToDestroy.Source != null) ? sToDestroy.Source.volume : 0.0f;
         sToDestroy.Fading          = true;
         sToDestroy.FadeTimeLeft    = fadeTime;
         sToDestroy.FadeDuration    = fadeTime;
     }
 }
Пример #14
0
    IEnumerator UpdatePosition(PlayingSound sound)
    {
        // if the sound is set inactive it does not follow the object anymore
        if (sound.soundSource != null)
        {
            sound.soundSource.transform.position = sound.soundObject.transform.position;
            yield return(new WaitForEndOfFrame());

            StartCoroutine(UpdatePosition(sound));
        }
    }
Пример #15
0
        private void Awake()
        {
            _animator    = GetComponent <Animator>();
            _boxCollider = GetComponent <BoxCollider2D>();
            PlayingSound = GetComponent <PlayingSound>();

            _flames = GetComponentInChildren <Flames>();
            _flames.Extinguished += PutOutStretcher;

            // Устанавливаем зеленый статус носилок
            Status = ColorStatus.Statuses.Green;

            // Получаем уровень носилок
            StretcherLevel = PlayerPrefs.GetInt("stretcher");
        }
Пример #16
0
    /// <summary>
    /// Update the sounds being played
    /// </summary>
    private void updatePlayingSounds()
    {
        for (int i = 0; i < this.playingSounds.Count; i++)
        {
            PlayingSound s = this.playingSounds[i];
            if ((s == null) || (s.Source == null))
            {
                this.playingSounds.RemoveAt(i);
            }
            else
            {
                //fading sounds, must be destroyed when the fade is done
                bool justDestroyed = false;
                if (s.Fading)
                {
                    s.FadeTimeLeft -= Time.deltaTime;
                    if (s.FadeTimeLeft <= 0.0f)
                    {
                        destroySound(s);
                        this.playingSounds.RemoveAt(i);
                        justDestroyed = true;
                    }
                    else
                    {
                        s.Source.volume = s.FadeStartVolume * (s.FadeTimeLeft / s.FadeDuration);
                    }
                }

                //sounds that has finished playing and are loop
                if (!justDestroyed)
                {
                    if ((s.Source == null) || (!s.Source.isPlaying))
                    {
                        if (s.Looped && (s.Source != null))
                        {
                            s.Source.Play();
                        }
                        else
                        {
                            destroySound(s);
                            this.playingSounds.RemoveAt(i);
                        }
                    }
                }
            }
        }
    }
    public void PlayOnNextBeat(AudioSource source, bool loop, OnBeatCallbackFunction onBeatCallback = null)
    {
        source.loop = loop;
        RemoveNonPlayingSounds();
        var playingSound = new PlayingSound(source, onBeatCallback);

        PlayingSounds.Add(playingSound);
        if (SyncBasis == null)
        {
            StartSyncing(playingSound);
            return;
        }
        double timeElapsed    = (double)SyncBasis.timeSamples / SyncBasis.clip.frequency;
        double offsetFromBeat = timeElapsed % AudioSyncBeatIntervalSeconds;

        playingSound.PlayScheduled(AudioSettings.dspTime + AudioSyncBeatIntervalSeconds - offsetFromBeat);
    }
Пример #18
0
 protected void PlaySound(string path, bool looping = false)
 {
     if (!m_sounds.ContainsKey(path))
     {
         var audio = Level.Audio;
         if (audio != null)
         {
             var playback = audio.PlaySound(path, looping);
             if (playback != null)
             {
                 var sound = new PlayingSound();
                 sound.Playback  = playback;
                 sound.TimeStamp = CurrentTime;
                 m_sounds.Add(path, sound);
             }
         }
     }
 }
Пример #19
0
 void PlayerMakingNoise(GameObject player, string sound, bool stop)
 {
     if (!stop)
     {
         PlayingSound ps = Play(sound, player);
         ps.soundSource.audio.loop = true;
         StartCoroutine(UpdatePosition(ps));
     }
     else if (playingSounds.ContainsKey(sound))
     {
         PlayingSound ps = playingSounds[sound];
         StartCoroutine(Fade(
                            ps,
                            clips.Find(item => item.name == sound).volume, 0,
                            ps.soundSource.audio.clip.length));
         StartCoroutine(Stop(ps, ps.soundSource.audio.clip.length));
     }
 }
Пример #20
0
    /// <summary>
    /// Stops a sound playing with the given Id
    /// </summary>
    public void StopSfx(string Id, float fadeTime)
    {
        //find the sound by its Id
        PlayingSound sToDestroy = null;

        for (int i = 0; i < this.playingSounds.Count; i++)
        {
            PlayingSound s = this.playingSounds[i];
            if ((s.Id == Id) && (!s.Fading))
            {
                sToDestroy = s;
                break;
            }
        }

        //mark it for destruction
        markSfxForDestruction(sToDestroy, fadeTime);
    }
Пример #21
0
    void attack_RPC(string lastTouchSensor, string touchTargetSensor)
    {
        GameObject lastTouch   = GameObject.Find(lastTouchSensor).GetComponent <SensorControl>().getCollisionObj();
        GameObject touchTarget = GameObject.Find(touchTargetSensor).GetComponent <SensorControl>().getCollisionObj();

        preSensor = lastTouchSensor;
        nowSensor = touchTargetSensor;
        lastTouch.transform.position = touchTarget.transform.position;
        lastMovedPosition            = setMovePosition(touchTarget);
        moveSound(lastTouch);
        Destroy(touchTarget);
        if (nowTurn.Equals("Han"))
        {
            nowTurn = "Cho";
        }
        else
        {
            nowTurn = "Han";
        }

        if (touchTarget.name.Equals("Han_King(Clone)") || touchTarget.name.Equals("Cho_King(Clone)"))
        {
            if (touchTarget.name.Substring(0, 3).Equals(myTag))   // 패배
            {
                aud.PlayOneShot(loseSound);
                LosePanel.SetActive(true);
                PlayingSound.SetActive(false);
                JangGoonSound.SetActive(false);
            }
            else   // 승리
            {
                aud.PlayOneShot(winSound);
                WinPanel.SetActive(true);
                PlayingSound.SetActive(false);
                JangGoonSound.SetActive(false);
            }
        }

        else
        {
            StartCoroutine("JangGoonCheck");
        }
    }
Пример #22
0
    void PlayerWalking(GameObject player, bool startWalking)
    {
        if (startWalking)
        {
            PlayingSound ps = Play(GlobalNames.SOUND.Player_Walk, player);

            ps.soundSource.audio.loop = true;
            // use this for moving sounds
            StartCoroutine(UpdatePosition(ps));
            // fade from 0 to 1 in 1 second
            StartCoroutine(Fade(ps, 0.0f, 1.0f, 1.0f));
        }
        // if the walking sound is still playing but the player stopped
        // walking
        else if (playingSounds.ContainsKey(GlobalNames.SOUND.Player_Walk))
        {
            StartCoroutine(
                Stop(playingSounds[GlobalNames.SOUND.Player_Walk]));
        }
    }
Пример #23
0
    IEnumerator Stop(PlayingSound sound, float time = 0.0f)
    {
        float currentTime = time;

        while ((currentTime -= Time.deltaTime) > 0)
        {
            yield return(new WaitForEndOfFrame());
        }

        if (sound.soundSource)
        {
            sound.soundSource.audio.Stop();
            sound.soundSource.active = false;
            Destroy(sound.soundSource);
            playingSounds.Remove(sound.name);
#if DEBUG_SOUNDS
            Debug.Log("stop sound: " + sound.name);
#endif
        }
    }
Пример #24
0
    PlayingSound Play(string name, GameObject soundObject, float volume = -1.0f, float pitch = -1.0f)
    {
#if DEBUG_SOUNDS
        Debug.Log("play sound: " + name);
#endif
        PlayingSound ps;
        if (!playingSounds.ContainsKey(name))
        {
            GameObject newSoundSource =
                new GameObject("Audio: " + name);
            newSoundSource.AddComponent <AudioSource>();

            ps = new PlayingSound
            {
                name        = name,
                soundSource = newSoundSource,
                soundObject = soundObject
            };

            playingSounds.Add(ps.name, ps);

            ps.soundSource.active = true;

            AudioData data = clips.Find(item => item.name == name);
            ps.soundSource.audio.clip   = data.clip;
            ps.soundSource.audio.volume = volume < 0 ? data.volume : volume;
            ps.soundSource.audio.pitch  = pitch < 0 ? data.pitch : pitch;

            ps.soundSource.transform.position = ps.soundObject.transform.position;

            ps.soundSource.audio.Play();
        }
        else
        {
            ps = playingSounds[name];
        }

        return(ps);
    }
Пример #25
0
    /// <summary>
    /// Destroy a sound that was playing
    /// </summary>
    private void destroySound(PlayingSound s)
    {
        if (s.Source != null)
        {
            s.Source.Stop();
            s.Source.clip = null;
            if (s.DestroyOnFinish)
            {
                if (s.recycle)
                {
                    RecycleAudioObject(s.Source.gameObject);
                }
                s.Source = null;
            }
        }

        //if there is someone interested in know when
        if (s.Finished != null)
        {
            s.Finished();
        }
        s.Finished = null;
    }
Пример #26
0
        public static async Task PlaySoundsAsync(List <Sound> sounds, int repetitions, bool randomly)
        {
            // If randomly is true, shuffle sounds
            if (randomly)
            {
                Random random = new Random();
                sounds = sounds.OrderBy(a => random.Next()).ToList();
            }

            MediaPlayer player = await FileManager.CreateMediaPlayerAsync(sounds, 0);

            if (player == null)
            {
                return;
            }

            // If PlayOneSoundAtOnce is true, remove all sounds from PlayingSounds List
            if (FileManager.itemViewHolder.PlayOneSoundAtOnce)
            {
                List <PlayingSound> removedPlayingSounds = new List <PlayingSound>();
                foreach (PlayingSound pSound in FileManager.itemViewHolder.PlayingSounds)
                {
                    removedPlayingSounds.Add(pSound);
                }

                await RemoveSoundsFromPlayingSoundsListAsync(removedPlayingSounds);
            }

            PlayingSound playingSound = new PlayingSound(Guid.Empty, sounds, player, repetitions, randomly, 0)
            {
                Uuid = await FileManager.AddPlayingSoundAsync(Guid.Empty, sounds, 0, repetitions, false, player.Volume)
            };

            FileManager.itemViewHolder.PlayingSounds.Add(playingSound);
            playingSound.MediaPlayer.Play();
        }
Пример #27
0
    IEnumerator Fade(PlayingSound sound, float from, float to, float time)
    {
        if (sound.soundSource.active)
        {
            float step = 1.0f / time;
            float i = 0.0f;

            while (i <= 1.0f)
            {
                // stop fading if sound source has been deactivated
                if (sound.soundSource == null || !sound.soundSource.active)
                    break;

                i += step * Time.deltaTime;
                sound.soundSource.audio.volume = Mathf.Lerp(from, to, i);

        #if DEBUG_SOUNDS
                Debug.Log("fade sound: " + sound.name + " volume at " + sound.soundSource.audio.volume);
        #endif

                yield return new WaitForSeconds(step * Time.deltaTime);
            }
        }
    }
Пример #28
0
    PlayingSound Play(string name, GameObject soundObject, float volume = -1.0f, float pitch = -1.0f)
    {
        #if DEBUG_SOUNDS
        Debug.Log("play sound: " + name);
        #endif
        PlayingSound ps;
        if (!playingSounds.ContainsKey(name))
        {
            GameObject newSoundSource =
                    new GameObject("Audio: " + name);
            newSoundSource.AddComponent<AudioSource>();

            ps = new PlayingSound
            {
                name = name,
                soundSource = newSoundSource,
                soundObject = soundObject
            };

            playingSounds.Add(ps.name, ps);

            ps.soundSource.active = true;

            AudioData data = clips.Find(item => item.name == name);
            ps.soundSource.audio.clip = data.clip;
            ps.soundSource.audio.volume = volume < 0 ? data.volume : volume;
            ps.soundSource.audio.pitch = pitch < 0 ? data.pitch : pitch;

            ps.soundSource.transform.position = ps.soundObject.transform.position;

            ps.soundSource.audio.Play();
        }
        else
        {
            ps = playingSounds[name];
        }

        return ps;
    }
Пример #29
0
        public static async Task RemovePlayingSoundAsync(PlayingSound playingSound)
        {
            await FileManager.DeletePlayingSoundAsync(playingSound.Uuid);

            FileManager.itemViewHolder.PlayingSounds.Remove(playingSound);
        }
 private void StartSyncing(PlayingSound sound)
 {
     SyncBasis = sound.Source;
     sound.Play();
 }
Пример #31
0
    void PlayerJumpStart(GameObject player)
    {
        PlayingSound ps = Play(GlobalNames.SOUND.Player_Jump, player);

        StartCoroutine(Stop(ps, ps.soundSource.audio.clip.length));
    }
Пример #32
0
    IEnumerator Stop(PlayingSound sound, float time = 0.0f)
    {
        float currentTime = time;
        while ((currentTime -= Time.deltaTime) > 0)
        {
            yield return new WaitForEndOfFrame();
        }

        if (sound.soundSource)
        {
            sound.soundSource.audio.Stop();
            sound.soundSource.active = false;
            Destroy(sound.soundSource);
            playingSounds.Remove(sound.name);
        #if DEBUG_SOUNDS
            Debug.Log("stop sound: " + sound.name);
        #endif
        }
    }
Пример #33
0
    void FixedUpdate()
    {
        if (Input.GetMouseButtonDown(0) && nowTurn.Equals(myTag))
        {
            touchTarget = GetClickedObject();

            if (!touchTarget.tag.Equals("Field"))
            {
                removeAllEnemyObjs();
                if (lastMeObj != null)
                {
                    removeObj(lastMeObj);
                }
                if (lastMovedPosition != null)
                {
                    removeObj(lastMovedPosition);
                }
            }

            if (touchTarget.tag.Equals("Han") || touchTarget.tag.Equals("Cho"))   // 말 선택시

            {
                if (isChoosing && !touchTarget.tag.Equals(myTag))   // 말 선택 중 다른 팀 선택 했을때
                {
                    if (touchTarget.GetComponent <MalScript>().getSensorObj().GetComponent <Renderer>().enabled)
                    {
                        view.RPC("attack_RPC", PhotonTargets.All, lastTouch.GetComponent <MalScript>().getSensorObj().name, touchTarget.GetComponent <MalScript>().getSensorObj().name);
                        offAllSensors();
                        isChoosing = false;
                    }
                }

                else if (touchTarget.tag.Equals(myTag))   // 자기 팀을 선택 하면
                {
                    offAllSensors();
                    lastMeObj = setMeObj(touchTarget);
                    lastTouch = touchTarget;
                    if (publicVariable.getIsModeling())
                    {
                        touchVoice(touchTarget.name);
                    }
                    searchPath.searchPath(touchTarget.GetComponent <MalScript>().getSensorObj().name, touchTarget.name);
                    isChoosing = true;
                }
            }

            else if (touchTarget.tag.Equals("Sensor"))                           // 센서 선택시
            {
                if (isChoosing && touchTarget.GetComponent <Renderer>().enabled) // 말 선택 중 이동가능한 센서 선택시
                {
                    preSensor = lastTouch.GetComponent <MalScript>().getSensorObj().name;
                    view.RPC("move_RPC", PhotonTargets.All, preSensor, touchTarget.name);
                    isChoosing = false;
                    offAllSensors();
                }
            }
        }

        if (!publicVariable.getIsPlayer())   // 상대나가면 승리
        {
            aud.PlayOneShot(winSound);
            WinPanel.SetActive(true);
            PlayingSound.SetActive(false);
            JangGoonSound.SetActive(false);
        }
    }
Пример #34
0
 IEnumerator UpdatePosition(PlayingSound sound)
 {
     // if the sound is set inactive it does not follow the object anymore
     if (sound.soundSource != null)
     {
         sound.soundSource.transform.position = sound.soundObject.transform.position;
         yield return new WaitForEndOfFrame();
         StartCoroutine(UpdatePosition(sound));
     }
 }