當前位置: 首頁>>代碼示例>>C#>>正文


C# UnityEngine.AudioClip類代碼示例

本文整理匯總了C#中UnityEngine.AudioClip的典型用法代碼示例。如果您正苦於以下問題:C# AudioClip類的具體用法?C# AudioClip怎麽用?C# AudioClip使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


AudioClip類屬於UnityEngine命名空間,在下文中一共展示了AudioClip類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: PlayMusic

    public void PlayMusic(AudioClip clip, float fadeDuration = 1) {
        activeMusicSourceIndex = 1 - activeMusicSourceIndex;
        musicSources[activeMusicSourceIndex].clip = clip;
        musicSources[activeMusicSourceIndex].Play();

        StartCoroutine(AnimateMusicCrossfade(fadeDuration));
    }
開發者ID:queekusme,項目名稱:Lamb-to-Slaughter,代碼行數:7,代碼來源:AudioManager.cs

示例2: PlayMusic

        /**
         * Plays game music using an audio clip.
         * One music clip may be played at a time.
         * @param musicClip The music clip to play
         * @param atTime Time in the music clip to start at
         */
        public void PlayMusic(AudioClip musicClip, bool loop, float fadeDuration, float atTime)
        {
            AudioSource audioSource = GetComponent<AudioSource>();
            if (audioSource == null || audioSource.clip == musicClip)
            {
                return;
            }

            if (fadeDuration == 0f)
            {
                audioSource.clip = musicClip;
                audioSource.loop = loop;
                audioSource.time = atTime;	// May be inaccurate if the audio source is compressed http://docs.unity3d.com/ScriptReference/AudioSource-time.html BK
                audioSource.Play();
            }
            else
            {
                float startVolume = audioSource.volume;

                LeanTween.value(gameObject, startVolume, 0f, fadeDuration)
                    .setOnUpdate( (v) => {
                        // Fade out current music
                        audioSource.volume = v;
                    }).setOnComplete( () => {
                        // Play new music
                        audioSource.volume = startVolume;
                        audioSource.clip = musicClip;
                        audioSource.loop = loop;
                        audioSource.time = atTime;	// May be inaccurate if the audio source is compressed http://docs.unity3d.com/ScriptReference/AudioSource-time.html BK
                        audioSource.Play();
                    });
            }
        }
開發者ID:rstruk,項目名稱:ProjetLaby,代碼行數:39,代碼來源:MusicController.cs

示例3: ParseTextAndSpeak

    //This is called by the Line Reader to parse a string and begin speaking
    public void ParseTextAndSpeak(string inputText, AudioClip inputAudio)
    {
        mouthQueue.Clear();
        textTime.Clear();
        currentSyllable = 0;
        //split the string up into
        string[] splitString = inputText.Split(';');
        for (int i = 0; i < splitString.Length; i++)
        {
            for (int m = 0; m < mouths.Length; m++)
            {
                for (int s = 0; s < mouths[m].syllable.Length; s++)
                {
                    if (splitString[i].StartsWith(mouths[m].syllable[s]))
                    {
                        mouthQueue.Add(m);
                        textTime.Add(splitString[i].Length * timePerInputCharacter);
                        //break;
                    }
                }

            }
        }
        //reset the coroutine
        CancelInvoke("SetNextMouth");
        SetNextMouth();
        myAudio.clip = inputAudio;
        myAudio.Play();
    }
開發者ID:nkornek,項目名稱:FartBuckets,代碼行數:30,代碼來源:LipSync.cs

示例4: OnShoot

    void OnShoot()
    {
        gunshot = Resources.Load<AudioClip>("Sounds/gunfire");
        source = GetComponent<AudioSource>();

        source.PlayOneShot(gunshot);
    }
開發者ID:raftelti,項目名稱:flamewars,代碼行數:7,代碼來源:SoundOnShoot.cs

示例5: PlayOneShot

 void PlayOneShot(AudioClip sound)
 {
     if(_state == State.Play)
     {
         SoundPlayer.PlayOneShot(sound);
     }
 }
開發者ID:funcodes,項目名稱:AirGame,代碼行數:7,代碼來源:SoundManager.cs

示例6: playSoundRandom

    public void playSoundRandom(Vector3 soundPos, AudioClip []arrayOfSounds, int sizeOfArray, int []availableSounds, int lenghtOfAvailableSounds)
    {
        bool numIsUsable = false;
        int ranNum = 0;

        for (int a = 0; a < 20; a++)
        {
            ranNum = Mathf.RoundToInt(Random.Range(0, sizeOfArray));

            for (int b = 0; b < lenghtOfAvailableSounds; b++)
            {
                if (ranNum == availableSounds[b])
                {
                    numIsUsable = true;
                    break;
                }
            }

            if (numIsUsable)
                break;
        }

        if (numIsUsable)
        {
            source.PlayOneShot(arrayOfSounds[ranNum]);
            //AudioSource.PlayClipAtPoint(arrayOfSounds[ranNum], soundPos);
            Debug.Log(ranNum);
        }
    }
開發者ID:kjarosz,項目名稱:Hookshot,代碼行數:29,代碼來源:SoundEffectHelper.cs

示例7: Start

    void Start()
    {
        _audioSource = gameObject.AddComponent <AudioSource>();

                _godzillaDamageAudioclip = _doLoadAudioClipByName (MainConstants.AUDIO_GODZILLA_DAMAGE);
                _mazingerDamageudioclip = _doLoadAudioClipByName (MainConstants.AUDIO_MAZINGER_DAMAGE);
    }
開發者ID:pmartinezalvarez,項目名稱:monsters-vs-robots,代碼行數:7,代碼來源:AudioManager.cs

示例8: Play

 public void Play(AudioClip sound)
 {
     GameObject temp;
     if (soundObjects.TryGetValue(sound, out temp)) {
         if (!temp.GetComponent<AudioSource>().isPlaying) temp.GetComponent<AudioSource>().Play();
     }
 }
開發者ID:acenode,項目名稱:unity-rts-demo,代碼行數:7,代碼來源:AudioElement.cs

示例9: Stop

 public void Stop(AudioClip sound)
 {
     GameObject temp;
     if (soundObjects.TryGetValue(sound, out temp)) {
         temp.GetComponent<AudioSource>().Stop ();
     }
 }
開發者ID:acenode,項目名稱:unity-rts-demo,代碼行數:7,代碼來源:AudioElement.cs

示例10: ReplaceMusic

 public void ReplaceMusic(AudioClip muse, float newVolume)
 {
     if (ownSource.clip != muse){
         nextMusic = muse;
         maxVolume = newVolume;
     }
 }
開發者ID:chorgan93,項目名稱:Ectoplazaa,代碼行數:7,代碼來源:BGMS.cs

示例11: justplaySfx

    IEnumerator justplaySfx(AudioClip _clip,float volume)
    {
        //audio.PlayOneShot (_clip, volume);
        audio.PlayOneShot (_clip, volume);

        yield return null;
    }
開發者ID:meetingmeeting,項目名稱:grass_sled_secure,代碼行數:7,代碼來源:playerAni.cs

示例12: PlaySoundLoop

	public void PlaySoundLoop(AudioClip inClip, float timeDelay = 0)
	{
		audio.loop = true;
		audio.clip = inClip;
		//audio.Play();
		audio.PlayDelayed(timeDelay);
	}
開發者ID:BGCX262,項目名稱:zzzstrawhatzzz-svn-to-git,代碼行數:7,代碼來源:SoundPlayerScript.cs

示例13: PlaySoundAt

 public AudioSource PlaySoundAt(AudioClip clip, Transform soundParent, string tag = "Untagged")
 {
     AudioSource source = PlaySoundAt(clip, soundParent.position, tag);
     source.transform.SetParent(soundParent, false);
     source.transform.localPosition = new Vector3(0, 0, 0);
     return source;
 }
開發者ID:JonECG,項目名稱:Spoopy,代碼行數:7,代碼來源:SoundManagerController.cs

示例14: setCard

 //Method that other scripts can use to pass new sprites into this object
 public void setCard(Sprite image, int inputId, string t, AudioClip c)
 {
     clip = c;
     id = inputId;
     type = t;
     GetComponent<SpriteRenderer>().sprite = image;
 }
開發者ID:dnaismyth,項目名稱:Learning-App,代碼行數:8,代碼來源:cardBack.cs

示例15: Play

		public void Play(AudioClip clip, float volume = 1.0f)
		{
			if (clip != null)
			{
				_source.PlayOneShot(clip, _source.volume * volume);
			}
		}
開發者ID:paveltimofeev,項目名稱:GameJamFramework,代碼行數:7,代碼來源:BaseAudioManager.cs


注:本文中的UnityEngine.AudioClip類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。