Example #1
0
    // Use this for initialization
    void Start()
    {
        gameObject.AddComponent< AudioSource >();

        sound = LoadFromXML("SerializeTest.xml");
        audio.clip = sound.Clip;
    }
Example #2
0
        public static Node Create(Vector3 pos)
        {
            var name = "GameClear";
            var cmp = new MyGameClear ();

            var spr = new Sprite (200, 160);
            spr.AddTexture (new Texture ("media/GameClear.png"));

            var clip = new SoundClip ("SoundClip");
            clip.AddTrack (new SoundEffectTrack ("media/Announce.ogg"));
            clip.Volume = 0.3f;

            var mbox = new MailBox (name);

            var node = new Node (name);
            node.Attach (cmp);
            node.Attach (spr);
            node.Attach(mbox);
            node.UserData.Add (clip.Name, clip);

            node.Drawable = false;
            node.Translation = pos;

            return node;
        }
Example #3
0
        public static Node Create(Vector3 pos)
        {
            var cmp = new MyComponent ();

            var spr = new Sprite (480, 300);
            spr.AddTexture (new Texture ("media/Vanity.jpg"));
            spr.AddTexture (new Texture ("media/Tanks.png"));
            spr.AddTexture (new Texture ("media/TatamiRoom.png"));
            spr.AutoScale = true;

            Console.WriteLine ("tex = " + spr.GetTexture (0));
            Console.WriteLine ("spr = " + spr);

            var col = new CollisionObject();
            col.Shape  = new BoxShape(spr.Width/2, spr.Height/2, 100);
            col.SetOffset (spr.Width/2, spr.Height/2, 0);

            var ctr = new AnimationController ();

            var node = new Node ();
            node.Attach (cmp);
            node.Attach (spr);
            node.Attach (col);
            node.Attach (ctr);

            node.Translation = pos;

            var clip = new SoundClip ("Sound");
            clip.AddTrack (new SoundEffectTrack ("media/PinPon.wav"));

            node.UserData.Add (clip.Name, clip);

            return node;
        }
Example #4
0
 public MyController(MyTank tank)
 {
     this.tank = tank;
     this.TargetMarker = null;
     this.noise = new SoundClip("Noise");
     noise.AddTrack(new SoundEffectTrack("media/Sound-LoopNoise.wav"));
 }
Example #5
0
	void Awake () {
		gameController = GameObject.FindGameObjectWithTag("GameController").GetComponent<GameController>();
		gameController.onGameRestart += Start;

		sceneController = GameObject.Find ("SceneController")
			.GetComponent<SceneController>();
		soundmanager = GameObject.Find("SoundManager").GetComponent<SoundClip>();
	}
Example #6
0
        public void PlayClip( SoundClip clip )
        {
            if ( m_playbackObject == null )
            {
                CreatePlaybackObject();
            }

            m_playbackObject.audio.clip = clip.Clip;
            m_playbackObject.audio.Play();
        }
Example #7
0
	void Awake () {
		gameController = GameObject.FindGameObjectWithTag("GameController").GetComponent<GameController>();
		gameController.onGameLose += MoveLock;
		gameController.onGameWin += MoveLock;
		gameController.onGameRestart += Start;
		soundmanager = GameObject.Find ("SoundManager").GetComponent<SoundClip>();

		psMoveWrapper = gameObject.GetComponent<PSMoveWrapper>();
		psMoveWrapper.Connect();

		// TODO: activate this line if the player can't stop reaching the monster
		//gameController.onGamePlayStart += MoveLockThenUnlock;
	}
Example #8
0
        public void Test_AddClip()
        {
            var ply = new SoundPlayer ();
            var clip1 = new SoundClip ("PinPon.wav");
            var clip2 = new SoundClip ("nice_music.ogg");
            ply.AddClip (clip1);
            ply.AddClip (clip2);

            Assert.AreEqual (2, ply.ClipCount);
            Assert.AreEqual (2, ply.Clips.Count ());
            Assert.AreEqual (clip1, ply["PinPon.wav"]);
            Assert.AreEqual (clip2, ply["nice_music.ogg"]);
        }
Example #9
0
	void Awake () {
		gameController = GameObject.FindGameObjectWithTag("GameController")
			.GetComponent<GameController>();
		soundManager = GameObject.Find ("SoundManager")
			.GetComponent<SoundClip>();

		gameController.onGameWin += () => {
			StartVideo(3);
			Invoke ("PlayWinEnd", scenes[3].duration);
		};

		gameController.onGameLose += () => {
			StartVideo(5);
		};
	}
Example #10
0
        public static Node Create()
        {
            var clip = new SoundClip ("BattleScene");
            clip.AddTrack(new MusicTrack("media/BGM-BattleScene.ogg"));
            clip.Play ();
            clip.Volume = 0.5f;

            var ply = new SoundPlayer ();
            ply.AddClip (clip);

            var node = new Node ("BGM");
            node.Attach (ply);

            return node;
        }
        public static void ShowGraphEditor()
        {
            if ( ActiveClip == null )
            {
                ActiveClip = new SoundClip(
                    SynthGraphEditor.DEFAULT_CLIP_NAME,
                    SynthGraphEditor.DEFAULT_CLIP_LENGTH,
                    SynthGraphEditor.DEFAULT_CLIP_SAMPLE,
                    SynthGraphEditor.DEFAULT_CLIP_STEREO,
                    SynthGraphEditor.DEFAULT_CLIP_3D
                );
            }

            EditorWindow.GetWindow( typeof( SynthGraphEditor ) );
        }
Example #12
0
    private void SceneConfiguration()
    {
        var query = from settings in sceneSettings
                    where settings.scene == (Scene)Enum.Parse(typeof(Scene),
                                                              SceneManager.GetActiveScene().name.ToUpper())
                    select settings;

        activeSceneSettings = query.ToList()[0];

        {
            activeSoundClip        = activeSceneSettings.activeSoundClip;
            scoreLabel.enabled     = activeSceneSettings.scoreLabelEnabled;
            livesLabel.enabled     = activeSceneSettings.livesLabelEnabled;
            highScoreLabel.enabled = activeSceneSettings.highScoreLabelEnabled;
            startLabel.SetActive(activeSceneSettings.startLabelActive);
            endLabel.SetActive(activeSceneSettings.endLabelActive);
            startButton.SetActive(activeSceneSettings.startButtonActive);
            restartButton.SetActive(activeSceneSettings.restartButtonActive);
            highScoreLabel.text = "High Score: " + scoreBoard.highScore;
        }


        Lives = 5;
        Score = 0;


        if ((activeSoundClip != SoundClip.NONE) && (activeSoundClip != SoundClip.NUM_OF_CLIPS))
        {
            AudioSource activeAudioSource = audioSources[(int)activeSoundClip];
            activeAudioSource.playOnAwake = true;
            activeAudioSource.loop        = true;
            activeAudioSource.volume      = 0.5f;
            activeAudioSource.Play();
        }



        // creates an empty container (list) of type GameObject
        clouds = new List <GameObject>();

        for (int cloudNum = 0; cloudNum < numberOfClouds; cloudNum++)
        {
            clouds.Add(Instantiate(cloud));
        }

        Instantiate(island);
    }
Example #13
0
        private void PlaySound(string type, bool bloop = false)
        {
            if (soundConifg == null)
            {
                return;
            }
            SoundClip soundClip = soundConifg.GetSoundClip(type);

            if (soundClip != null && !string.IsNullOrEmpty(soundClip.SoundPath))
            {
                GuLog.Debug("<><SoundPlayer> SoundName:   " + soundClip);
                if (this.audioClipBuffer.ContainsKey(soundClip.SoundPath))
                {
                    this.Play(this.GetAudioSource(), this.audioClipBuffer[soundClip.SoundPath].AudioClip, bloop);
                    this.audioClipBuffer[soundClip.SoundPath].LastAccessTime = DateTime.Now;
                }
                else
                {
                    switch (soundClip.Storage.ToUpper())
                    {
                    case "LOCAL":
                        AudioClip localAudioClip = mPrefabRoot.GetObjectNoInstantiate <AudioClip>("Audio/Common", soundClip.SoundPath);
                        this.audioClipBuffer.Add(soundClip.SoundPath, new AudioClipData()
                        {
                            AudioClip = localAudioClip, LastAccessTime = DateTime.Now
                        });
                        this.Play(this.GetAudioSource(), localAudioClip, bloop);
                        break;

                    case "REMOTE":
                        this.StartCoroutine(this.ResourceUtils.LoadAudio(string.Format("Audio/Common/{0}.mp3", this.I18NConfig.GetAudioPath(soundClip.SoundPath)), (remoteAudioClip) =>
                        {
                            if (!this.audioClipBuffer.ContainsKey(soundClip.SoundPath))
                            {
                                this.audioClipBuffer.Add(soundClip.SoundPath, new AudioClipData()
                                {
                                    AudioClip = remoteAudioClip, LastAccessTime = DateTime.Now
                                });
                            }
                            this.Play(this.GetAudioSource(), remoteAudioClip, bloop);
                        }));
                        break;
                    }
                }
            }
        }
Example #14
0
    /*
     * PlayGameLost
     *
     * Play the game losing jingle
     * iff a sound of SoundType#GameComplete is not already playing.
     */
    public void PlayGameLost(bool dryrun = false)
    {
        // can't play multiple game winning or losing sounds at once
        var item = new SoundClip(SoundType.GameComplete);

        if (!currentlyPlaying.Contains(item))
        {
            ClearAll(); // Stop playing level soundtrack.
            currentlyPlaying.Add(new SoundClip(
                                     SoundType.GameComplete,
                                     gameLostClip,
                                     dryrun));
        }

        // We need to ensure we reload sounds on level restart.
        hasLoaded = false;
    }
    public bool IsDifferentSound(SoundClip clip)
    {
        if (clip == null)
        {
            return(false);
        }

        if (currentSound != null && currentSound.realId == clip.realId &&
            IsPlaying() && currentSound.isFadeOut == false)
        {
            return(false);
        }
        else
        {
            return(true);
        }
    }
Example #16
0
    private static void PlayUiAudioOneShot(SoundClip soundClip)
    {
        if (_globalAudioVolume <= 0 || _uiVolume <= 0)
        {
            return;
        }

        if (_uiAudio == null)
        {
            CreateUiAudioSource();
        }

        if (_uiAudio != null)
        {
            _uiAudio.PlayOneShot(soundClip.clip, soundClip.volume * _uiVolume * _globalAudioVolume);
        }
    }
Example #17
0
        /// <summary>
        ///     The <c>Play</c> method plays a sound based on the <paramref name="clipName" />.
        /// </summary>
        /// <param name="clipName">Name of the <see cref="SoundClip" /> that should be played.</param>
        /// <returns>Returns a <see cref="AudioSource" /> created based on the settings defined in the <see cref="SoundClip" />.</returns>
        /// <exception cref="NullReferenceException">
        ///     Thrown when there is no <see cref="SoundClip" /> in the soundClips array named
        ///     <paramref name="clipName" />.
        /// </exception>
        public AudioSource Play(string clipName)
        {
            // Get sound clip from array.
            SoundClip soundClip = Array.Find(soundClips, clip => clip.Name == clipName);

            if (soundClip == null)
            {
                throw new NullReferenceException($"There is no clip named {clipName.Bold()} found in the soundClips array.");
            }

            // Throw an ArgumentException when the sound clip is not a SFX and there is already an child object with the same name.
            if (!soundClip.IsSFX)
            {
                if (CachedTransform.Cast <Transform>().Any(child => child.name == clipName))
                {
                    throw new ArgumentException(
                              $"There can only be one instance of the soundClip named {clipName.Bold()}. When I should have more instances it should be an SFX");
                }
            }

            // Make a new game object named 'clipName', and set it as a child of this object.
            var clipGameObject = new GameObject(clipName);

            clipGameObject.transform.SetParent(CachedTransform);

            // Adding and setting up a audio source component.
            var audioSource = clipGameObject.AddComponent <AudioSource>();

            audioSource.clip   = soundClip.AudioClip;
            audioSource.volume = soundClip.Volume;
            audioSource.loop   = !soundClip.IsSFX;
            audioSource.outputAudioMixerGroup = audioMixer.FindMatchingGroups("Master")[0];

            // Play the audio
            audioSource.Play();

            // If the sound clip is a SFX destroy the game object when it is done playing.
            if (soundClip.IsSFX)
            {
                Destroy(clipGameObject, audioSource.clip.length + 0.1f);
            }

            // Return audio source.
            return(audioSource);
        }
Example #18
0
 /// <summary>
 /// 사운드 재생.
 /// </summary>
 void PlayAudioSource(AudioSource source, SoundClip m)
 {
     if (source == null)
     {
         return;
     }
     source.Stop();
     source.clip         = m.GetClip();
     source.volume       = m.maxVolume;
     source.loop         = m.isLoop;
     source.pitch        = m.pitch;
     source.dopplerLevel = m.dopplerLevel;
     source.rolloffMode  = m.rollOffMode;
     source.minDistance  = m.minDistance;
     source.maxDistance  = m.maxDistance;
     source.spatialBlend = m.spatialBlend;
     source.Play();
 }
Example #19
0
    /// <summary>
    /// 배경음 사운드 재생.
    /// </summary>
    public void Play(SoundClip m)
    {
        if (this.CheckPlay(m))
        {
            this.fadeB_audioSource.Stop();
            this.lastSound    = this.currentSound;
            this.currentSound = m;

            PlayAudioSource(this.fadeA_audioSource, m);

            this.currentPlayingType = MusicPlayingType.SourceA;
            if (this.currentSound.HasLoop())
            {
                this.isTicking = true;
                DoTick();
            }
        }
    }
Example #20
0
 void PlayAudioSource(AudioSource source, SoundClip clip, float volume)
 {
     if (source == null || clip == null)
     {
         return;
     }
     source.Stop();
     source.clip         = clip.GetClip();
     source.volume       = volume;
     source.loop         = clip.isLoop;
     source.pitch        = clip.pitch;
     source.dopplerLevel = clip.dopplerLevel;
     source.rolloffMode  = clip.rolloffMode;
     source.minDistance  = clip.minDistance;
     source.maxDistance  = clip.maxDistance;
     source.spatialBlend = clip.spatialBlend;
     source.Play();
 }
Example #21
0
 /// <summary>
 /// サウンドの再生
 /// </summary>
 /// <param name="clip">再生するサウンドクリップ</param>
 /// <param name="isLoop">ループさせるかどうか</param>
 /// <param name="volume">音量</param>
 /// <returns>ハンドラID</returns>
 public int Play(SoundClip clip, bool isLoop, float volume = 0.5f)
 {
     for (int i = 0; i < this._sources.Length; ++i)
     {
         var source = _sources[i];
         if (source.isPlaying)
         {
             continue;
         }
         source.clip         = _clipList[(int)clip];
         source.volume       = volume;
         source.spatialBlend = 0.0f;
         source.loop         = isLoop;
         source.Play();
         return(i);
     }
     return(-1);
 }
Example #22
0
    public void ClearSoundClipResource()
    {
        foreach (string name in _dictionarySoundClip.Keys)
        {
            SoundClip soundClip = _dictionarySoundClip[name];

            if (soundClip.HasLoaded)
            {
                Resources.UnloadAsset(soundClip.Clip);
                soundClip.ClearClip();
            }
        }

        for (int i = 0; i < _sfxChannelsNumber; i++)
        {
            _sfxChannel[i].clip = null;
        }
    }
Example #23
0
 public void FadeIn(SoundClip clip, float time, Interpolate.EaseType ease)
 {
     if (IsDifferentSound(clip) == true)
     {
         fadeA_audio.Stop();
         fadeB_audio.Stop();
         lastSound    = currentSound;
         currentSound = clip;
         PlayAudioSource(fadeA_audio, currentSound, 0.0f);
         currentSound.FadeIn(time, ease);
         currentPlayingType = MusicPlayingType.SourceA;
         if (currentSound.HasLoop() == true)
         {
             isTicking = true;
             DoCheck();
         }
     }
 }
 //Interpolate.EaseType easeType 보간 곡선
 /// <summary>
 /// clip을 주어지는 time과 ease로 FadeIn
 /// </summary>
 public void FadeIn(SoundClip clip, float time, Interpolate.EaseType ease)
 {
     if (this.IsDifferentSound(clip)) //다른 사운드가 맞다면
     {
         fadeA_audio.Stop();
         fadeB_audio.Stop();
         this.lastSound    = this.currentSound;
         this.currentSound = clip;
         PlayAudioSource(fadeA_audio, currentSound, 0.0f);
         this.currentSound.FadeIn(time, ease);
         this.currentPlayingType = MusicPlayingType.SourceA;
         if (this.currentSound.HasLoop())
         {
             this.isTicking = true;
             DoCheck();
         }
     }
 }
 void SetLoopTime(bool isCheck, SoundClip clip, string timeString)
 {
     string[] time = timeString.Split('/');
     for (int i = 0; i < time.Length; i++)
     {
         if (time[i] != string.Empty)
         {
             if (isCheck == true)
             {
                 clip.checkTime[i] = float.Parse(time[i]);
             }
             else
             {
                 clip.setTime[i] = float.Parse(time[i]);
             }
         }
     }
 }
Example #26
0
    public void Play(Sound soundName)
    {
        SoundClip s = Array.Find(sounds, item => item.Name == soundName);

        if (s == null)
        {
            Debug.LogWarning("Sound: " + soundName + " not found!");
            return;
        }
        if (s.SoundType == SoundType.Music)
        {
            s.Source.Play();
        }
        else
        {
            s.Source.PlayOneShot(s.Clip);
        }
    }
    public void FadeTo(SoundClip clip, float time, Interpolate.EaseType ease)
    {
        if (currentPlayingType == MusicPlayingType.None)
        {
            FadeIn(clip, time, ease);
        }
        else if (this.IsDifferentSound(clip))
        {
            if (currentPlayingType == MusicPlayingType.AtoB)
            {
                fadeA_audio.Stop();
                currentPlayingType = MusicPlayingType.SourceB;
            }
            else if (currentPlayingType == MusicPlayingType.BtoA)
            {
                fadeB_audio.Stop();
                currentPlayingType = MusicPlayingType.SourceA;
            }

            lastSound    = currentSound;
            currentSound = clip;
            lastSound.FadeOut(time, ease);
            currentSound.FadeIn(time, ease);


            //FadeTo A->B, B->A 사운드 교체
            if (currentPlayingType == MusicPlayingType.SourceA)
            {
                PlayAudioSource(fadeB_audio, currentSound, 0.0f);
                currentPlayingType = MusicPlayingType.AtoB;
            }
            else if (currentPlayingType == MusicPlayingType.SourceB)
            {
                PlayAudioSource(fadeA_audio, currentSound, 0.0f);
                currentPlayingType = MusicPlayingType.BtoA;
            }

            if (currentSound.HasLoop())
            {
                isTicking = true;
                DoCheck();
            }
        }
    }
    public void PlayMusicTrack(string title)
    {
        var track = this.musicTracks.Find(track => track.title == title);

        if (null == track)
        {
            Debug.Log("Sound track not found: " + title);
            return;
        }

        track.audioSource.Play();

        if (null != this.trackPlaying)
        {
            this.trackPlaying.audioSource.Stop();
        }

        this.trackPlaying = track;
    }
Example #29
0
 void PlayAudioSource(AudioSource source, SoundClip clip, float volume)
 {
     if (source == null || clip == null)
     {
         Debug.LogWarning("Plz check this PlayAudioSource");
         return;
     }
     source.Stop();
     source.clip         = clip.GetClip();
     source.volume       = volume;
     source.loop         = clip.IsLoop;
     source.pitch        = clip.Pitch;
     source.dopplerLevel = clip.DopplerLevel;
     source.rolloffMode  = clip.audioRolloffMode;
     source.minDistance  = clip.MinDistance;
     source.maxDistance  = clip.MaxDistance;
     source.spatialBlend = clip.SpatialBlend;
     source.Play();
 }
    public override void OnInspectorGUI()
    {
        serializedObject.Update();

        SoundClip clip = (SoundClip)target;

        EditorGUILayout.Slider(_recycleThreshold, 0, 100, "Recycle % Threshold");
        _recycleThreshold.floatValue = Mathf.FloorToInt(_recycleThreshold.floatValue);

        Rect dropArea = GUILayoutUtility.GetRect(0.0f, 50.0f, GUILayout.ExpandWidth(true));

        GUI.Box(dropArea, "Drag audio clips here (hold ctrl to replace all clips)");

        EditorGUILayout.PropertyField(_clips, true);

        DropAreaGUI(dropArea);

        serializedObject.ApplyModifiedProperties();
    }
    /// <summary>
    /// source를 clip, volume으로 세팅
    /// </summary>
    void PlayAudioSource(AudioSource source, SoundClip clip, float volume)
    {
        if (source == null || clip == null)
        {
            Debug.LogError("SoundManager/PlayAudioSource source or clip is null");
            return;
        }

        source.Stop();
        source.clip         = clip.GetClip();
        source.volume       = volume;
        source.pitch        = clip.pitch;
        source.dopplerLevel = clip.dopplerLevel;
        source.rolloffMode  = clip.rolloffMode;
        source.minDistance  = clip.minDistance;
        source.maxDistance  = clip.maxDistance;
        source.spatialBlend = clip.spatialBlend;
        source.Play();
    }
Example #32
0
    public bool IsPlaying(int nSoundId)
    {
        SoundClip clip = null;

        if (mSoundClipPools.m_SoundClipMap.TryGetValue(nSoundId, out clip))
        {
            for (var nIndex = 0; nIndex < mSFXChannelsCount; ++nIndex) //先找已经在播放或者播放过的
            {
                if (null != mSFXChannel[nIndex] && mSFXChannel[nIndex].m_uID == clip.mUID)
                {
                    if (null != mSFXChannel[nIndex].m_AudioSource)
                    {
                        return(mSFXChannel[nIndex].m_AudioSource.isPlaying);
                    }
                }
            }
        }
        return(false);
    }
Example #33
0
 void PlayAudioSource(AudioSource _source, SoundClip _clip, float _volume)
 {
     if (_source == null || _clip == null)
     {
         Debug.LogWarning("Plz check this PlayAudioSource");
         return;
     }
     _source.Stop();
     _source.clip         = _clip.GetClip();
     _source.volume       = _volume;
     _source.loop         = _clip.isLoop;
     _source.pitch        = _clip.pitch;
     _source.dopplerLevel = _clip.dopplerLevel;
     _source.rolloffMode  = _clip.audioRolloffMode;
     _source.minDistance  = _clip.minDistance;
     _source.maxDistance  = _clip.maxDistance;
     _source.spatialBlend = _clip.spatialBlend;
     _source.Play();
 }
    public void PlayEffectSound(SoundClip clip)
    {
        //찢어지는 사운드 방지(특정 채널 갯수 이하로만 재생)
        bool isPlaySuccess = false;

        for (int i = 0; i < this.EffectChannelCount; i++)
        {
            if (this.effect_audios[i].isPlaying == false)
            {
                PlayAudioSource(this.effect_audios[i], clip, clip.maxVolume);
                effect_PlayStartTime[i] = Time.realtimeSinceStartup;
                isPlaySuccess           = true;
                break;
            }
            else if (this.effect_audios[i].clip == clip.GetClip())
            {
                this.effect_audios[i].Stop();
                PlayAudioSource(this.effect_audios[i], clip, clip.maxVolume);
                effect_PlayStartTime[i] = Time.realtimeSinceStartup;
                isPlaySuccess           = true;
                break;
            }
        }


        // 이미 EffectChannelCount만큼 이펙트 사운드가 진행중이라면,
        // 현잰 진행중인 EffectSound 중에서 가장 오래 진행된 것을 꺼버리고 새로운 clip 재생
        if (isPlaySuccess == false)
        {
            float maxTime     = 0.0f;
            int   selectIndex = 0;
            for (int i = 0; i < EffectChannelCount; i++) //최대값 찾기
            {
                if (effect_PlayStartTime[i] > maxTime)
                {
                    maxTime     = effect_PlayStartTime[i];
                    selectIndex = i;
                }
            }

            PlayAudioSource(effect_audios[selectIndex], clip, clip.maxVolume);
        }
    }
Example #35
0
    /// <summary>
    /// Plays the clip at tile's location, on the channel group chanGroup. Pitch ranges from -freqRange to +freqRange in semitones.
    /// Volume ranges from -volRange to No change in decibels.
    /// </summary>
    /// <param name="clip">Sound to Play.</param>
    /// <param name="tile">Tile's location to play at. If null, plays at camera's position.</param>
    /// <param name="chanGroup">Chan group to play the sound on.</param>
    /// <param name="freqRange">Frequency range in semitones.</param>
    /// <param name="volRange">Volume range in decibels.</param>
    public void PlaySoundAt(SoundClip clip, Tile tile, string chanGroup = "master", float freqRange = 0f, float volRange = 0f, float cooldownTime = 0.1f)
    {
        if (clip == null || !clip.CanPlay())
        {
            return;
        }

        clip.SetCooldown(cooldownTime);
        ChannelGroup channelGroup;

        if (AudioManager.channelGroups.TryGetValue(chanGroup, out channelGroup) == false)
        {
            channelGroup = AudioManager.channelGroups["master"];
        }

        FMOD.System soundSystem = AudioManager.SoundSystem;
        Channel     channel;

        soundSystem.playSound(clip.Get(), channelGroup, true, out channel);
        if (tile != null)
        {
            VECTOR tilePos = GetVectorFrom(tile);
            channel.set3DAttributes(ref tilePos, ref zero, ref zero);
        }

        if (!freqRange.AreEqual(0f))
        {
            float pitch = Mathf.Pow(1.059f, Random.Range(-freqRange, freqRange));
            channel.setPitch(pitch);
        }

        if (!volRange.AreEqual(0f))
        {
            float curVol;
            channel.getVolume(out curVol);
            float volChange = Random.Range(-volRange, 0f);
            channel.setVolume(curVol * DecibelsToVolume(volChange));
        }

        channel.set3DLevel(SettingsKeyHolder.LocationalSound ? 0.75f : 0f);
        channel.setPaused(false);
    }
Example #36
0
    /// <summary>
    /// 이펙트 사운드 재생.
    /// </summary>
    void Play_EffectSound(SoundClip m)
    {
        bool isPlaySuccess = false;

        //가지고 있는 오디오 채널중에 플레이중이 아닌 채널을 찾아보거나.
        for (int idx = 0; idx < this.effectAudioChannelCount; idx++)
        {
            if (this.effect_audioSource[idx].isPlaying == false)
            {
                PlayAudioSource(this.effect_audioSource[idx], m);
                this.Effect_PlayStartTime[idx] = Time.realtimeSinceStartup;
                isPlaySuccess = true;
                break;
            }
            else if (this.effect_audioSource[idx].clip == m.GetClip())
            {
                //같은 사운드가 거의 동시에 재생하여야 하는 경우 특정 폰의 경우 소리가 클리핑이나 피크 현상이 발생.
                //기존 사운드를 멈췄다가 다시 재생하는게 덜 어색할지도.
                this.effect_audioSource[idx].Stop();
                PlayAudioSource(this.effect_audioSource[idx], m);
                this.Effect_PlayStartTime[idx] = Time.realtimeSinceStartup;

                isPlaySuccess = true;
                break;
            }
        }

        if (isPlaySuccess == false)
        {
            float standTime   = 0.0f;
            int   selectIndex = 0;
            for (int idx = 0; idx < this.effectAudioChannelCount; idx++)
            {
                if (this.Effect_PlayStartTime[idx] > standTime)
                {
                    standTime   = this.Effect_PlayStartTime[idx];
                    selectIndex = idx;
                }
            }
            PlayAudioSource(this.effect_audioSource[selectIndex], m);
        }
    }
    private void DropAreaGUI(Rect dropArea)
    {
        var evt = Event.current;

        if (evt.type == EventType.DragUpdated)
        {
            if (dropArea.Contains(evt.mousePosition))
            {
                DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
            }
        }

        if (evt.type == EventType.DragPerform)
        {
            if (dropArea.Contains(evt.mousePosition))
            {
                DragAndDrop.AcceptDrag();
                UnityEngine.Object[] draggedObjects = DragAndDrop.objectReferences as UnityEngine.Object[];
                var clips = new List <AudioClip>();
                foreach (var obj in draggedObjects)
                {
                    var c = obj as AudioClip;
                    if ((c != null) && !clips.Contains(c))
                    {
                        clips.Add(c);
                    }
                }

                clips.Sort((a, b) => a.name.CompareTo(b.name));

                SoundClip clip = (SoundClip)target;
                if (evt.control)
                {
                    clip.InspectorSetClips(clips);
                }
                else
                {
                    clip.InspectorAddClips(clips);
                }
            }
        }
    }
Example #38
0
        public static World Create()
        {
            var cmp = new MyWorld ();

            var spr = new Sprite (new Texture ("media/DarkGalaxy.jpg"));

            var clip = new SoundClip ();
            clip.AddTrack (new MusicTrack ("media/BGM(Field04).ogg"));
            clip.Play ();
            clip.Volume = 0.3f;

            var wld = new World ("First Script");
            wld.Attach (cmp);
            wld.Attach (spr);
            wld.UserData.Add (clip.Name, clip);

            wld.DrawPriority = 127;

            return wld;
        }
Example #39
0
    private static void Load(string resource, float volume = 1f, Action <SoundClip> notify = null)
    {
        LoadSoundResource(resource, audioClip =>
        {
            SoundClip soundClip = null;
            if (audioClip == null)
            {
                Debug.LogError(string.Format("The AudioClip[resource={0}] is null.", resource));
            }
            else
            {
                soundClip = new SoundClip(audioClip as AudioClip, volume);
            }

            if (notify != null)
            {
                notify.Invoke(soundClip);
            }
        });
    }
Example #40
0
    public void FadeTo(SoundClip _clip, float _time, Interpolate.EaseType _ease)
    {
        if (currentPlayingType == MusicPlayingType.None)
        {
            FadeIn(_clip, _time, _ease);
        }
        else if (IsDifferentSound(_clip) == true)
        {
            if (currentPlayingType == MusicPlayingType.AtoB)
            {
                fadeA_audio.Stop();
                currentPlayingType = MusicPlayingType.SourceB;
            }
            else if (currentPlayingType == MusicPlayingType.BtoA)
            {
                fadeB_audio.Stop();
                currentPlayingType = MusicPlayingType.SourceA;
            }

            //fade to
            lastSound    = currentSound;
            currentSound = _clip;
            lastSound.FadeOut(_time, _ease);
            currentSound.FadeIn(_time, _ease);
            if (currentPlayingType == MusicPlayingType.SourceA)
            {
                PlayAudioSource(fadeB_audio, currentSound, 0.0f);
                currentPlayingType = MusicPlayingType.AtoB;
            }
            else if (currentPlayingType == MusicPlayingType.SourceB)
            {
                PlayAudioSource(fadeA_audio, currentSound, 0.0f);
                currentPlayingType = MusicPlayingType.BtoA;
            }
            if (currentSound.HasLoop())
            {
                isTicking = true;
                DoCheck();
            }
        }
    }
Example #41
0
    public void FadeTo(SoundClip clip, float time, Interpolate.EaseType ease)
    {
        if (this.currentPlayingType == MusicPlayingType.None)
        {
            this.FadeIn(clip, time, ease);
        }
        else if (this.IsDifferentSound(clip) == true)
        {
            if (this.currentPlayingType == MusicPlayingType.AtoB)
            {
                this.fadeA_audio.Stop();
                this.currentPlayingType = MusicPlayingType.SourceB;
            }
            else if (this.currentPlayingType == MusicPlayingType.BtoA)
            {
                this.fadeB_audio.Stop();
                this.currentPlayingType = MusicPlayingType.SourceA;
            }

            //fade to
            this.lastSound    = this.currentSound;
            this.currentSound = clip;
            this.lastSound.FadeOut(time, ease);
            this.currentSound.FadeIn(time, ease);
            if (this.currentPlayingType == MusicPlayingType.SourceA)
            {
                PlayAudioSource(fadeB_audio, this.currentSound, 0.0f);
                this.currentPlayingType = MusicPlayingType.AtoB;
            }
            else if (this.currentPlayingType == MusicPlayingType.SourceB)
            {
                PlayAudioSource(fadeA_audio, this.currentSound, 0.0f);
                this.currentPlayingType = MusicPlayingType.BtoA;
            }
            if (this.currentSound.HasLoop())
            {
                this.isTicking = true;
                DoCheck();
            }
        }
    }
Example #42
0
    void SetLoopTime(bool isCheck, SoundClip clip, string times)
    {
        if (times == string.Empty)
        {
            return;
        }
        string timeString = times; // 예)3.0f/10.0f/13.0f

        string[] time = timeString.Split('/');
        for (int i = 0; i < time.Length; i++)
        {
            if (isCheck == true)
            {
                clip.CheckTime[i] = float.Parse(time[i]);
            }
            else
            {
                clip.SetTime[i] = float.Parse(time[i]);
            }
        }
    }
Example #43
0
        public void Fire()
        {
            var pos = Node.GlobalTransform.Apply (0, -80, 0);

            Vector3 T;
            Quaternion R;
            Vector3 S;
            Node.GlobalTransform.Decompress (out T, out R, out S);

            var node = MyProjectile.Create (pos, R);
            World.AddChild (node);

            var clip = new SoundClip ("media/Sound-Shot.wav");
            Sound.AddClip (clip, true);

            var tank = Node.Parent.GetComponent<MyTank>();
            var mychar = tank.MyCharacter.GetComponent<MyCharacter>();
            mychar.Say (BalloonMessage.Fire);

            var proj = node.GetComponent<MyProjectile> ();
            proj.Sender = tank.MyCharacter;
        }
Example #44
0
        public static Node Create(string name, Vector3 pos)
        {
            var cmp = new MyCharacterButton (name);

            var spr = new Sprite (128, 64);
            spr.AddTexture (Resource.GetDefaultTexture ());

            var label1 = new Label ();
            label1.Text = cmp.dbCharacter.FullName;
            label1.SetOffset (10, 10);
            label1.Color = Color.Black;

            var label2 = new Label ();
            label2.Text = cmp.dbCharacter.FullNameYomi;
            label2.SetOffset (10, 30);
            label2.Color = Color.Black;

            var col = new CollisionObject ();
            col.Shape = new BoxShape (64, 32, 100);
            col.SetOffset (64, 32, 0);

            var snd = new SoundEffectTrack ("media/PinPon.wav");
            var clip = new SoundClip ("クリック音");
            clip.AddTrack (snd);

            var node = new Node ("Button(" + name + ")");
            node.Attach (cmp);
            node.Attach (spr);
            node.Attach (label1);
            node.Attach (label2);
            node.Attach (col);

            node.UserData.Add (clip.Name, clip);

            node.Translation = pos;
            node.DrawPriority = -1;

            return node;
        }
        private void RebuildNodeGUICache( SoundClip clip )
        {
            Log ("Rebuilding node cache");

            Dictionary< ISynthGraphNode, NodeGUIBase > cache = new Dictionary<ISynthGraphNode, NodeGUIBase>( m_graphCache );
            m_graphCache.Clear();

            CacheNode( clip.Root, cache );

            m_cachedClip = clip;
            SetDirty( false );

            Log (string.Format("Cached {0} nodes", m_graphCache.Count ) );

            // Move remaining nodes to floating selection
            foreach ( KeyValuePair< ISynthGraphNode, NodeGUIBase > kvp in cache )
            {
                m_floatingSelection.Add( kvp.Key, kvp.Value );
            }
            Log ( string.Format("Floating selection contains {0} nodes", m_floatingSelection.Count ) );
        }
Example #46
0
    //Play background music
    public static bool PlayBackgroundMusic(string name, bool loop)
    {
        //Don't do shit if mute
        if (GlobalMuteBGM) return false;

        //Check BGM
        if (m_Instance.m_BackgroundMusic != null && m_Instance.m_BackgroundMusic.Name != name) {
            //Stop and clean
            StopBackgroundMusic(true);
        }

        //Create new bgm if needed
        if (m_Instance.m_BackgroundMusic == null) {
            //Create
            SoundClip s = new SoundClip(name, BGM_PATH);
            m_Instance.m_BackgroundMusic = s;
        }

        //Set attributes
        m_Instance.m_BackgroundMusic.Loop = loop;
        m_Instance.m_BackgroundMusic.Volume = m_Instance.m_BackgroundMusicVolume;

        //Play
        m_Instance.m_BackgroundMusic.Play();

        //Return
        return true;
    }
Example #47
0
    //Play with loop, must stop manually
    public static bool PlaySoundEffectOneShot(string name, bool loop, float volume)
    {
        //Don't do shit if mute
        if (GlobalMuteSFX) return false;

        //Check total count, play nothing if > max
        if (m_Instance.m_ActiveSound >= MAX_ACTIVE_SFX) return false;

        //Check first if looping, don't create again if already there
        if (loop) {
            foreach(SoundClip clip in m_Instance.m_SoundEffectOneShot) {
                if (clip.Name == name) {
                    //Play again
                    clip.Play();

                    //Return here
                    return true;
                }
            }
        }

        //Create new sound clip
        SoundClip s = new SoundClip(name, SFX_PATH);
        s.Volume = volume;
        s.Loop = loop;

        //Add to list and play
        m_Instance.m_SoundEffectOneShot.Add(s);
        s.Play();

        //Add number
        m_Instance.m_ActiveSound++;

        return true;
    }
Example #48
0
	// Use this for initialization
	void Start () {
        soundmanager = GameObject.Find("SoundManager").GetComponent<SoundClip>();
    }
Example #49
0
    //Prefabricate sound effect object at certain number
    public static bool PreloadSoundEffect(string name, int objectCount)
    {
        //Don't do shit if mute
        if (GlobalMuteSFX) return false;

        //Check
        if (!m_Instance.IsSoundExists(name)) {
            //Create entry in pool
            m_Instance.m_SoundEffectPool.Add(name, new List<SoundClip>());
            m_Instance.m_SoundEffectActive.Add(name, new List<SoundClip>());

            //Add to sounds
            m_Instance.m_Sounds.Add(name);
        }

        //Get pool
        List<SoundClip> pool = m_Instance.m_SoundEffectPool[name];

        //Add new soundclip
        for(int i=0;i<objectCount;i++) {
            //Create
            SoundClip s = new SoundClip(name, SFX_PATH);
            pool.Add(s);

            //Make all inactive
            s.SoundObject.SetActive(false);
        }

        return true;
    }
Example #50
0
 public override void OnUpdateInit(long msec)
 {
     var clip = new SoundClip ("media/PinPon.wav");
     clip.Volume = 0.2f;
     Sound.AddClip (clip, true);
 }
        private void RebuildConnectionCache( SoundClip clip )
        {
            Log ("Rebuilding connection cache");
            m_connectionCache.Clear();

            CacheConnection( clip.Root );

            Log ( string.Format("Cached {0} connections" , m_connectionCache.Count ) );
        }
Example #52
0
 public void Say(BalloonMessage msg)
 {
     switch (msg) {
         case BalloonMessage.Fire: {
                 var rnd = new Random ();
                 if (rnd.Next (2) == 0) {
                     Speak ("撃てーーー!", 500);
                 }
                 var clip = new SoundClip ("media/0001_さとうささら_撃てーーー.wav");
                 Sound.AddClip (clip, true);
                 break;
             }
         case BalloonMessage.Destroy: {
                 Speak ("一気撃破!!", 2000);
                 var clip = new SoundClip ("media/0000_さとうささら_一機、撃破.wav");
                 Sound.AddClip (clip, true);
                 break;
             }
         case BalloonMessage.Complete: {
                 Speak ("敵殲滅を確認", 30000);
                 var clip = new SoundClip ("media/0002_さとうささら_敵機殲滅を確認しました.wav");
                 Sound.AddClip (clip, true);
                 break;
             }
         default: Speak ("default", 3000); break; ;
     }
 }