Audio animation events.
Inheritance: Events
示例#1
0
 private void Awake()
 {
     if (enterPlayer == null)
     {
         enterPlayer = new AudioEvents();
     }
 }
示例#2
0
        // Internal - Used by AudioBankMounter
        // If bankName is not loaded, loads it and sets the ref count to one
        // Otherwise it just increments the ref count
        public void LoadEventBank(string bankName)
        {
            if (BankReferenceCounts.ContainsKey(bankName))
            {
                BankReferenceCounts[bankName] += 1;
                return;
            }

            BankReferenceCounts[bankName] = 1;

            var bank = Resources.Load(bankName, typeof(AudioEventBank)) as AudioEventBank;

            if (bank == null)
            {
                Debug.Log("Failed to load audio bank " + bankName);
                return;
            }

            if (LogBankLoads)
            {
                Debug.Log("Loading bank " + bankName);
            }


            foreach (var se in bank.AudioEvents)
            {
                if (!AudioEvents.ContainsKey(se.EventName))
                {
                    AudioEvents[se.EventName] = new List <AudioEvent>();
                }
                se.BankName = bankName;
                AudioEvents[se.EventName].Add(se);
            }
        }
示例#3
0
        // Internal - Used by AudioBankMounter
        // Decrements the reference count on the bank named bankName
        // If it hits zero, unloads it
        public void UnloadEventBank(string bankName)
        {
            if (BankReferenceCounts.ContainsKey(bankName))
            {
                BankReferenceCounts[bankName] -= 1;
                if (BankReferenceCounts[bankName] <= 0)
                {
                    BankReferenceCounts.Remove(bankName);

                    Debug.Log("AudioManager: Unload bank " + bankName);

                    var keysToDelete = new List <string>();
                    foreach (var kvp in AudioEvents)
                    {
                        kvp.Value.RemoveAll(e => e.BankName == bankName);
                        if (kvp.Value.Count == 0)
                        {
                            keysToDelete.Add(kvp.Key);
                        }
                    }

                    foreach (var k in keysToDelete)
                    {
                        AudioEvents.Remove(k);
                    }
                }
            }
        }
示例#4
0
 // Called when we, from our code, send an event
 public void Raise(AudioEvents eventType, Vector2 position)
 {
     // Back to front so we can unsubscribe from within the loop and still be ok
     for (int i = listeners.Count - 1; i >= 0; i--)
     {
         listeners[i].OnEventRaised(eventType, position);               // Notifies GameEventListenerFloat that this event has been fired
     }
 }
示例#5
0
    private void OnCollisionEnter(Collision collision)
    {
        AudioEvents.PlayAt(collision.contacts[0].point);

        var turret = collision.gameObject.GetComponent <TurretBehavior>();

        if (turret)
        {
            StopAllCoroutines();
        }
    }
示例#6
0
    private void Awake()
    {
        movement    = GetComponent <IMovement>();
        particleSys = GetComponent <ParticleSystem>();
        mesh        = gameObject.GetComponent <MeshRenderer>();

        if (playerDestroy == null)
        {
            playerDestroy = new AudioEvents();
        }

        if (gameWin == null)
        {
            gameWin = new AudioEvents();
        }
    }
示例#7
0
        /// Recursively look up an event in the loaded banks, chopping bits off the audio event name until a match is found.
        /// If there are multiple AudioEvents with the same trigger, does weighted randomisation.
        AudioEvent GetSoundForEvent(string audioEventName)
        {
            if (LogLookups)
            {
                Debug.Log("$$$Looking for sound event " + audioEventName);
            }

            List <AudioEvent> events;

            if (AudioEvents.TryGetValue(audioEventName, out events))
            {
                AudioEvent audioEvent;

                //If we have more than one event, get a weighted, random one.
                if (events.Count > 1)
                {
                    audioEvent = GetRandomEvent(events);
                }
                else
                {
                    audioEvent = events[0];
                }

                if (LogLookups)
                {
                    Debug.Log("$$$Found sound event " + audioEventName);
                }

                return(audioEvent);
            }
            else
            {
                var splitLocation = audioEventName.IndexOf(AudioEventSeparator);
                if (splitLocation >= 0 && splitLocation + 1 < audioEventName.Length)
                {
                    var newEv = audioEventName.Substring(splitLocation + 1);
                    return(GetSoundForEvent(newEv));
                }
            }
            return(null);
        }
示例#8
0
    public void Play(AudioEvents audioEvent, Vector2 pos)
    {
        var eventAudioPlayersList = audioPlayers[audioEvent];
        var eventAudioPlayers     = eventAudioPlayersList[Random.Range(0, eventAudioPlayersList.Count)];

        foreach (var ap in eventAudioPlayers)
        {
            if (!ap.AudioSource.isPlaying && player)
            {
                float distance = Vector2.Distance(player.transform.position, pos);
                var   aE       = ap.AudioEventEmiter;
                distance = aE.volumeFalloff.keys[aE.volumeFalloff.keys.Length - 1].value > distance ? aE.volumeFalloff.keys[aE.volumeFalloff.keys.Length - 1].value : distance;
                ap.AudioSource.volume = aE.volume * aE.volumeFalloff.Evaluate(distance) * masterVolume * effectsVolume;

                ap.AudioSource.pitch = Random.Range(ap.AudioEventEmiter.minPitch, ap.AudioEventEmiter.maxPitch);
                ap.AudioSource.Play( );

                break;
            }
        }
    }
 public static void PlayWin()
 {
     AudioEvents.PlaySound("win");
 }
示例#10
0
 public static void PlayLose()
 {
     AudioEvents.PlaySound("lose");
 }
示例#11
0
 // Use this for initialization
 void Start()
 {
     audioEvents = GetComponent<AudioEvents>();
 }
示例#12
0
 public static void Restart()
 {
     AudioEvents.Restart();
 }
示例#13
0
	void OnSelectionChange()
	{
		if(Selection.activeGameObject != null){
			AudioEvents tmpAudioEvents = Selection.activeGameObject.GetComponent<AudioEvents>();
			if(tmpAudioEvents != null && tmpAudioEvents.GetComponent<AudioSource>().clip != null){
				audioEvents = tmpAudioEvents;
				clip = audioEvents.GetComponent<AudioSource>().clip;
				RecreateCurvePoints();
				CreateTriggers();
				GenerateAudioTexture();
			}
			else{
				audioEvents = null;
			}
		}
		doRepaint = true;
	}
示例#14
0
 public static void PlayPlop()
 {
     AudioEvents.PlaySound("plop");
 }
示例#15
0
 // This is called by UnityEventFloat when the event is fired
 public void OnEventRaised(AudioEvents eventType, Vector2 position)
 {
     response.Invoke(eventType, position);
 }
示例#16
0
 public static void Pause()
 {
     AudioEvents.Pause();
 }
示例#17
0
 public static void PlayGoal()
 {
     AudioEvents.PlaySound("goal");
 }
示例#18
0
 public static void PlayClick()
 {
     AudioEvents.PlaySound("misc_menu");
 }
 private async Task Implement(AudioEvents eventName)
 {
     await JSRuntime.InvokeVoidAsync("window.CustomEventHandler", Id, eventName.ToString().ToLower(), AudioState.GetPayload());
 }
示例#20
0
 public static void UnPause()
 {
     AudioEvents.UnPause();
 }