Beispiel #1
0
        //Root of all gui stuff
        public override void OnInspectorGUI()
        {
            IndexToClone  = -1;
            IndexToDelete = -1;

            DropAreas.Clear();


            //Top buttons
            EditorGUILayout.BeginVertical();

            //Add a new audio event
            if (GUILayout.Button("Add entry...", GUILayout.Height(TopButtonHeight)))
            {
                var newAudioEvent = new AudioEvent();
                newAudioEvent.EventName = "NEWKEY_" + Bank.AudioEvents.Count;
                Bank.AudioEvents.Add(newAudioEvent);
                var source = GetOrCreateAudioSourceProxy(newAudioEvent);
                newAudioEvent.TransferFromAudioSource(source);
            }

            //Stop all sounds from playing
            if (GUILayout.Button("Stop Playback", GUILayout.Height(TopButtonHeight)))
            {
                AudioPlayer.GetComponent <AudioSource>().Stop();
            }

            //Temporarily make our audio proxy sources visible, otherwise they are greyed out in the inspector
            if (AudioSourceProxyGO != null)
            {
                AudioSourceProxyGO.hideFlags = HideFlags.DontSaveInEditor;
            }


            EditorGUILayout.Space();
            EditorGUILayout.EndVertical();
            LastEventName = "";
            // ScrollPos = EditorGUILayout.BeginScrollView(ScrollPos);
            EditorGUILayout.BeginVertical();

            //Now display the individual events
            if (Bank != null)
            {
                TransferSettingsToProxies();
                if (Bank.AudioEvents != null)
                {
                    for (int c1 = 0; c1 < Bank.AudioEvents.Count; c1++)
                    {
                        DisplayLine(c1);
                    }
                }
            }

            //Clean up various bits of state we've had to keep going
            //If we've been asked to delete something, honour that
            if (IndexToDelete >= 0)
            {
                Bank.AudioEvents.RemoveAt(IndexToDelete);
            }

            //If we've been asked to clone something, honour that
            if (IndexToClone >= 0)
            {
                var clone = Bank.AudioEvents[IndexToClone].Clone();
                Bank.AudioEvents.Insert(IndexToClone, clone);
            }

            //Handle drag drop logic
            DoDragDrop();

            // EditorGUILayout.EndScrollView();
            EditorGUILayout.EndVertical();
            EditorUtility.SetDirty(target);

            //Set the audio source proxies back to being invisible
            if (AudioSourceProxyGO != null)
            {
                AudioSourceProxyGO.hideFlags = HideFlags.HideAndDontSave;
            }

            //Make sure same named events are adjacent
            if (CheckEventAdjacency)
            {
                CheckEventAdjacency = false;
                CleanupNonAdjacentEvents();
                GUI.FocusControl("");
            }
        }
Beispiel #2
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);
                    }
                }
            }
        }
        //Root of all gui stuff
        public override void OnInspectorGUI()
        {
            IndexToClone = -1;
            IndexToDelete = -1;

            DropAreas.Clear();

		
            //Top buttons
            EditorGUILayout.BeginVertical();

            //Add a new audio event
            if(GUILayout.Button("Add entry...", GUILayout.Height(TopButtonHeight)))
            {
                var	newAudioEvent = new AudioEvent();
                newAudioEvent.EventName = "NEWKEY_" + Bank.AudioEvents.Count;
                Bank.AudioEvents.Add(newAudioEvent);
                var source = GetOrCreateAudioSourceProxy(newAudioEvent);
                newAudioEvent.TransferFromAudioSource(source);
            }
            
            //Stop all sounds from playing
            if(GUILayout.Button("Stop Playback", GUILayout.Height(TopButtonHeight)))
            {
                AudioPlayer.GetComponent<AudioSource>().Stop();
            }

            //Temporarily make our audio proxy sources visible, otherwise they are greyed out in the inspector
            if(AudioSourceProxyGO!=null)
            {
                AudioSourceProxyGO.hideFlags = HideFlags.DontSaveInEditor;
            }


            EditorGUILayout.Space();
            EditorGUILayout.EndVertical();
            LastEventName = "";
            // ScrollPos = EditorGUILayout.BeginScrollView(ScrollPos);
            EditorGUILayout.BeginVertical();
        
            //Now display the individual events
            if(Bank != null)
            {
                TransferSettingsToProxies();
                if(Bank.AudioEvents!=null)
                {
                    for(int c1=0; c1<Bank.AudioEvents.Count; c1++)
                    {
                        DisplayLine(c1);
                    }
                }
            }
		
            //Clean up various bits of state we've had to keep going
            //If we've been asked to delete something, honour that
            if(IndexToDelete>=0)
            {
                Bank.AudioEvents.RemoveAt(IndexToDelete);
            }

            //If we've been asked to clone something, honour that
            if(IndexToClone>=0)
            {	
                var clone = Bank.AudioEvents[IndexToClone].Clone();
                Bank.AudioEvents.Insert(IndexToClone, clone);
            }

            //Handle drag drop logic
            DoDragDrop();
            
            // EditorGUILayout.EndScrollView();
            EditorGUILayout.EndVertical();
            EditorUtility.SetDirty(target);
            
            //Set the audio source proxies back to being invisible
            if(AudioSourceProxyGO!=null)
            {
                AudioSourceProxyGO.hideFlags = HideFlags.HideAndDontSave;
            }

            //Make sure same named events are adjacent
            if(CheckEventAdjacency)
            {
                CheckEventAdjacency = false;
                CleanupNonAdjacentEvents();
                GUI.FocusControl("");
            }

        }