Beispiel #1
0
        public static AudioEmitter Create(Transform attachedTo, AudioEvent ev)
        {
            GameObject go = new GameObject("AudioEmitter");
            AudioEmitter emitter = go.AddComponent<AudioEmitter>();
            emitter._Source = go.AddComponent<AudioSource>();

            go.transform.parent = AudioManager.Instance.gameObject.transform;
            go.transform.position = attachedTo.position;
            emitter.AttachedTo = attachedTo;
            emitter.AudioSoundEvent = ev;
            ev.TransferToAudioSource(emitter._Source);
            return emitter;
        }
Beispiel #2
0
        public static AudioEmitter Create(Transform attachedTo, AudioEvent ev)
        {
            GameObject   go      = new GameObject("AudioEmitter");
            AudioEmitter emitter = go.AddComponent <AudioEmitter>();

            emitter._Source = go.AddComponent <AudioSource>();

            go.transform.parent     = AudioManager.Instance.gameObject.transform;
            go.transform.position   = attachedTo.position;
            emitter.AttachedTo      = attachedTo;
            emitter.AudioSoundEvent = ev;
            ev.TransferToAudioSource(emitter._Source);
            return(emitter);
        }
Beispiel #3
0
        //Play an audio event.
        //If onlythisOne is false, it chooses a random weighted event from the group
        void PlayAudio(int index, bool onlyThisOne)
        {
            if (Application.isPlaying)
            {
                return;
            }

            if (AudioPlayer)
            {
                AudioPlayer.GetComponent <AudioSource>().Stop();
            }
            else
            {
                CreateAudioPlayer();
            }

            AudioEvent audioEvent = null;

            if (onlyThisOne)
            {
                audioEvent = Bank.AudioEvents[index];
            }
            else
            {
                var audioEventName            = Bank.AudioEvents[index].EventName;
                List <AudioEvent> audioEvents = new List <AudioEvent>();

                foreach (var evt in Bank.AudioEvents)
                {
                    if (evt.EventName == audioEventName)
                    {
                        audioEvents.Add(evt);
                    }
                }

                audioEvent = AudioManager.GetRandomEvent(audioEvents);
            }

            if (audioEvent != null)
            {
                var source = AudioPlayer.GetComponent <AudioSource>();

                audioEvent.TransferToAudioSource(source);
                source.Play();
            }
        }
Beispiel #4
0
        //Draw a single audio event
        public void DisplayLine(int audioEventIndex)
        {
            AudioEvent audioEvent = Bank.AudioEvents[audioEventIndex];

            //Visually seperate items from different groups
            if (audioEvent.EventName != LastEventName)
            {
                LastEventName = audioEvent.EventName;
                EditorGUILayout.Space();
            }

            //Draw all these controls on a single line
            EditorGUILayout.BeginHorizontal();

            //Drag handle
            Rect dropArea = GUILayoutUtility.GetRect(40, 20);

            dropArea.width = 30;

            bool topLevelEvent = IsEventIndexTopOfGroup(audioEventIndex);

            if (topLevelEvent)
            {
                GUI.Box(dropArea, "");
                DropAreas.Add(new DropArea(audioEventIndex, dropArea));
            }

            //Show all the summary details and buttons
            EditorGUI.BeginChangeCheck();

            //Event name
            EditorGUIUtility.labelWidth = 20;
            EditorGUIUtility.fieldWidth = 100;
            GUI.SetNextControlName("TextField");
            audioEvent.EventName = EditorGUILayout.TextField(audioEvent.EventName);

            //If we've changed the event name, make sure we update any adjacency issues.
            if (Event.current.isKey && Event.current.keyCode == KeyCode.Return && GUI.GetNameOfFocusedControl() == "TextField")
            {
                CheckEventAdjacency = true;
            }

            //The audio clip
            EditorGUIUtility.labelWidth = 30;
            EditorGUIUtility.fieldWidth = 100;
            audioEvent.AudioClip        = (AudioClip)EditorGUILayout.ObjectField("", audioEvent.AudioClip, typeof(AudioClip), false, GUILayout.MinWidth(60));

            //The random weight control
            EditorGUIUtility.labelWidth = 25;
            EditorGUIUtility.fieldWidth = 35;
            audioEvent.RandomWeight     = EditorGUILayout.FloatField(new GUIContent("Wgt", "Weight"), audioEvent.RandomWeight, GUILayout.MaxWidth(60));

            //Show the loop/lifetime mask
            DrawAudioEventOptionsMask(audioEvent);

            //Details foldout
            bool foldedOut = false;

            if (FoldedOut.ContainsKey(audioEvent.GetHashCode()))
            {
                foldedOut = FoldedOut[audioEvent.GetHashCode()];
            }
            if (GUILayout.Button(new GUIContent("A", "Audio source settings"), GUILayout.MaxWidth(PlayButtonWidth)))
            {
                foldedOut = !foldedOut;
            }
            FoldedOut[audioEvent.GetHashCode()] = foldedOut;

            //Playback controls
            if (GUILayout.Button(new GUIContent("T", "Play this audio event"), GUILayout.MaxWidth(PlayButtonWidth)))
            // if (GUILayout.Button(new GUIContent("T", "Play this audio event"), GUILayout.ExpandWidth(false)))
            {
                PlayAudio(audioEventIndex, true);
            }

            if (GUILayout.Button(new GUIContent("R", "Play random event in this group"), GUILayout.MaxWidth(PlayButtonWidth)))
            {
                PlayAudio(audioEventIndex, false);
            }

            //Clone an item?
            if (GUILayout.Button(new GUIContent("C", "Clone this event"), GUILayout.MaxWidth(PlayButtonWidth)))
            {
                IndexToClone = audioEventIndex;
            }

            //Delete an item?
            if (GUILayout.Button(new GUIContent("X", "Delete this event"), GUILayout.MaxWidth(PlayButtonWidth)))
            {
                IndexToDelete = audioEventIndex;
            }

            // GUILayout.FlexibleSpace();

            //If any data was changed, transfer them to the proxy audio source
            if (EditorGUI.EndChangeCheck())
            {
                audioEvent.TransferToAudioSource(GetOrCreateAudioSourceProxy(audioEvent));
            }

            EditorGUILayout.EndHorizontal();

            //If we're folded out, show the details from the proxy audio source
            if (foldedOut)
            {
                var source = EventToSourceMap[audioEvent];
                if (source != null)
                {
                    EditorGUIUtility.labelWidth = 0;
                    EditorGUIUtility.fieldWidth = 0;
                    EditorGUI.BeginChangeCheck();
                    DrawProxy(audioEvent);
                    if (EditorGUI.EndChangeCheck())
                    {
                        audioEvent.TransferFromAudioSource(source);
                    }
                }
            }
        }