当前位置: 首页>>代码示例>>C#>>正文


C# AudioSource.GetComponent方法代码示例

本文整理汇总了C#中UnityEngine.AudioSource.GetComponent方法的典型用法代码示例。如果您正苦于以下问题:C# AudioSource.GetComponent方法的具体用法?C# AudioSource.GetComponent怎么用?C# AudioSource.GetComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UnityEngine.AudioSource的用法示例。


在下文中一共展示了AudioSource.GetComponent方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddTargetForClip

        public static void AddTargetForClip(string clipName, AudioSource source) {
            if (!AudioResourceTargetsByName.ContainsKey(clipName)) {
                AudioResourceTargetsByName.Add(clipName, new List<AudioSource> {
                    source
                });
            } else {
                var sources = AudioResourceTargetsByName[clipName];

                // populate the audio clip even if it was loaded previous by another
                AudioClip populatedClip = null;
                // ReSharper disable once ForCanBeConvertedToForeach
                for (var i = 0; i < sources.Count; i++) {
                    var clip = sources[i].clip;

                    if (clip == null) {
                        continue;
                    }

                    populatedClip = clip;
                    break;
                }

                if (populatedClip != null) {
                    source.clip = populatedClip;
                    var aVar = source.GetComponent<SoundGroupVariation>();

                    if (aVar != null) {
                        aVar.internetFileLoadStatus = MasterAudio.InternetFileLoadStatus.Loaded;
                    }
                }

                sources.Add(source);
            }
        }
开发者ID:Avatarchik,项目名称:Off-Peak,代码行数:34,代码来源:AudioResourceOptimizer.cs

示例2: BeforePlay

	void BeforePlay()
	{
		float time = GetProceedTime();
		
		if( time > m_Timing)
		{
			switch( m_ActionSound.LoopType)
			{
			case eLoopType.Once:
				m_Sound = AsSoundManager.Instance.PlaySound( m_ActionSound.FileName, m_EntityTrn.position, false);
				break;
			case eLoopType.Once_Cycle:
				if(m_Sound == null)
				{
					m_Sound = AsSoundManager.Instance.PlaySound( m_ActionSound.FileName, m_EntityTrn.position, false);
					if(m_Sound != null)
						GameObject.Destroy( m_Sound.GetComponent<AsSoundObject>());
//					else
//						Debug.LogError("SoundProcessor::BeforePlay: '" + m_ActionSound.FileName + "' is not found");
				}
				else
				{
					m_Sound.Play();
				}
				break;
			case eLoopType.Loop:
				m_Sound = AsSoundManager.Instance.PlaySound( m_ActionSound.FileName, m_EntityTrn.position, true);
				break;
			}
			
			m_State = eSoundState.After_Play;
		}
	}
开发者ID:ftcaicai,项目名称:ArkClient,代码行数:33,代码来源:SoundProcessor.cs

示例3: init

  public void init() {
    // Calculate number of samples between each beat.
    OnDisable();
    audioSource = GetComponent<AudioSource>();
    float audioBpm = audioSource.GetComponent<BeatSynchronizer>().bpm;
    //Debug.Log("BPM: " + audioBpm);
    beatPeriod = (60f / (audioBpm * BeatDecimalValues.values[(int)beatValue]));
    samplePeriod = beatPeriod * audioSource.clip.frequency;

    //RhythmManager.rm.setPeriod((60f / (audioBpm * BeatDecimalValues.values[(int)beatValue])));

    if (beatOffset != BeatValue.None) {
      sampleOffset = (60f / (audioBpm * BeatDecimalValues.values[(int)beatOffset])) * audioSource.clip.frequency;
      if (negativeBeatOffset) {
        sampleOffset = samplePeriod - sampleOffset;
      }
    }

    samplePeriod *= beatScalar;
    sampleOffset *= beatScalar;
    nextBeatSample = 0f;
    lastSamplePeriod = samplePeriod;
    OnEnable();
  }
开发者ID:spilist,项目名称:shoong,代码行数:24,代码来源:BeatCounter.cs

示例4: Start

    void Start()
    {
        Screen.orientation = ScreenOrientation.Portrait;
        scrollingTexture = GameObject.Find ("Plane").GetComponent<ScrollingTexture> ();
        anim = GameObject.Find ("MainMenuCanvas").GetComponentInChildren<Animator> ();
        sushianimators = GameObject.Find ("Sushis").GetComponentsInChildren<Animator> ();

        laughingManager = GameObject.Find("LaughingManager").GetComponent<AudioSource>();
        audioPlayScript = audioManager.GetComponent<AudioPlayScript> ();
        laughingPlayScript = laughingManager.GetComponent <LaughingPlayScript> ();
        Invoke ("PlayHelloSound", 0.5f);
    }
开发者ID:Failender,项目名称:CrowdRunner,代码行数:12,代码来源:MenuManager.cs

示例5: DuckSoundGroup

	public static void DuckSoundGroup(string soundGroupName, AudioSource aSource) {
        var ma = MasterAudio.Instance;

        if (!ma.EnableMusicDucking || !ma.duckingBySoundType.ContainsKey(soundGroupName)) {
            return;
        }

        var matchingDuck = ma.duckingBySoundType[soundGroupName];
		
        // duck music
        var duckLength = aSource.GetComponent<AudioSource>().clip.length;
        var duckPitch = aSource.pitch;

        var pcs = PlaylistController.Instances;
        for (var i = 0; i < pcs.Count; i++)
        {
            pcs[i].DuckMusicForTime(duckLength, duckPitch, matchingDuck.riseVolStart);
        }

        if (pcs.Count == 0) 
        {
            Debug.LogWarning("Playlist Controller is not in the Scene. Cannot duck music.");
        }
	}
开发者ID:pandaboy,项目名称:Village,代码行数:24,代码来源:MasterAudio.cs

示例6: StopLoop

 protected void StopLoop(AudioSource source)
 {
     if (fadeDuration > 0)
     {
         LeanTween.value(source.gameObject,_audioSource.Value.volume,0,fadeDuration
         ).setOnUpdate(
             (float updateVolume)=>{
             source.volume = updateVolume;
         }
         ).setOnComplete(
             ()=>{
             
             source.GetComponent<AudioSource>().Stop();
             if (waitUntilFinished)
             {
                 Continue();
             }
         }
         );
     }
     else
     {
         source.GetComponent<AudioSource>().Stop();
     }
 }
开发者ID:KRUR,项目名称:NotJustASheep,代码行数:25,代码来源:ControlAudio.cs


注:本文中的UnityEngine.AudioSource.GetComponent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。