本文整理汇总了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);
}
}
示例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;
}
}
示例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();
}
示例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);
}
示例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.");
}
}
示例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();
}
}