protected override void Setup() { myScript = (AudioTriggerFeedback)target; sound = serializedObject.FindProperty("sound"); soundFile = serializedObject.FindProperty("soundFile"); triggersWith = serializedObject.FindProperty("triggersWith"); triggerEvent = serializedObject.FindProperty("triggerEvent"); }
public override void OnInspectorGUI() { if (am == null) { am = AudioManager.instance; } AudioTriggerFeedback myScript = (AudioTriggerFeedback)target; List <string> options = new List <string>(); options.Add("None"); foreach (string s in am.GetSoundDictionary().Keys) { options.Add(s); } string sound = serializedObject.FindProperty("sound").stringValue; if (sound == "None" && myScript.GetAttachedSound() == null) { EditorGUILayout.HelpBox("Choose a sound to play on trigger enter before running!", MessageType.Error); } DrawDefaultInspector(); GUIContent soundDesc = new GUIContent("Sound", "Sound that will be played on collision"); if (sound.Equals("") || !options.Contains(sound)) // Default to "None" { sound = options[EditorGUILayout.Popup(soundDesc, 0, options.ToArray())]; } else { sound = options[EditorGUILayout.Popup(soundDesc, options.IndexOf(sound), options.ToArray())]; } serializedObject.FindProperty("sound").stringValue = sound; serializedObject.ApplyModifiedProperties(); }
private void OnEnable() { myScript = (AudioTriggerFeedback)target; if (AudioManager.instance) { enumType = AudioManager.instance.GetSceneSoundEnum(); if (enumType != null) { foreach (string s in System.Enum.GetNames(enumType)) { options.Add(s); } } } sound = serializedObject.FindProperty("sound"); soundFile = serializedObject.FindProperty("soundFile"); triggersWith = serializedObject.FindProperty("triggersWith"); triggerEvent = serializedObject.FindProperty("triggerEvent"); }
public override void OnInspectorGUI() { AudioTriggerFeedback myScript = (AudioTriggerFeedback)target; List <string> options = new List <string>(); System.Type enumType = null; if (!AudioManager.instance) { EditorGUILayout.HelpBox("Could not find Audio Manager in the scene! This component needs AudioManager " + "in order to function!", MessageType.Error); } else { enumType = AudioManager.instance.GetSceneSoundEnum(); if (enumType == null) { EditorGUILayout.HelpBox("Could not find Audio File info! Try regenerating Audio Files in AudioManager!", MessageType.Error); } else { foreach (string s in System.Enum.GetNames(enumType)) { options.Add(s); } } } EditorGUILayout.LabelField("Choose a Sound to Play", EditorStyles.boldLabel); int sound = serializedObject.FindProperty("sound").intValue; GUIContent soundDesc = new GUIContent("Sound", "Sound that will be played on intersection with another collider"); using (new EditorGUI.DisabledScope(myScript.GetAttachedSound() != null)) { serializedObject.FindProperty("sound").intValue = EditorGUILayout.Popup(soundDesc, sound, options.ToArray()); } GUIContent fileText = new GUIContent("Custom AudioClip", "Overrides the \"Sound\" parameter with an AudioClip if not null"); SerializedProperty customSound = serializedObject.FindProperty("soundFile"); EditorGUILayout.Space(); GUIContent fontent = new GUIContent("Custom AudioClip Settings", "These settings only apply if you input your own custom AudioClip rather than choosing from the generated Audio Library"); if (myScript.GetAttachedSound() == null) { showAudioClipSettings = EditorGUILayout.Foldout(showAudioClipSettings, fontent); } else { showAudioClipSettings = EditorGUILayout.BeginFoldoutHeaderGroup(showAudioClipSettings, fontent); } if (showAudioClipSettings) { EditorGUILayout.ObjectField(customSound, fileText); using (new EditorGUI.DisabledScope(myScript.GetAttachedSound() == null)) { DrawPropertiesExcluding(serializedObject, new[] { "m_Script", "soundFile", "playOnStart", "playOnEnable", "stopOnDisable", "stopOnDestroy", "triggersWith", "triggerEvent" }); } } if (myScript.GetAttachedSound() != null) { EditorGUILayout.EndFoldoutHeaderGroup(); } EditorGUILayout.PropertyField(serializedObject.FindProperty("triggersWith")); EditorGUILayout.PropertyField(serializedObject.FindProperty("triggerEvent")); serializedObject.ApplyModifiedProperties(); EditorGUILayout.Space(); showHowTo = EditorGUILayout.BeginFoldoutHeaderGroup(showHowTo, "Quick Reference Guide"); if (showHowTo) { EditorGUILayout.Space(); EditorGUILayout.LabelField("Overview", EditorStyles.boldLabel); EditorGUILayout.HelpBox("This component is meant to be attached to a physics-enabled object." + " When something intersects with that physics-enabled object, this component will play a sound." + " You can choose to change the trigger event that plays the sound by using the Trigger Event drop-down." + " You can select a sound to play using the drop-down at the top of the component." , MessageType.None); EditorGUILayout.HelpBox("This component should be placed on the same GameObject that holds the physics object's Rigidbody" , MessageType.None); EditorGUILayout.HelpBox("AudioTriggerFeedback responds to both 2D and 3D trigger events." , MessageType.None); EditorGUILayout.Space(); EditorGUILayout.LabelField("Tips", EditorStyles.boldLabel); EditorGUILayout.HelpBox("Sometimes you want your object to produce different sounds when intersecting different things" + " so you can specify different collision layers for this component to react to under" + " the Trigger Settings field. " , MessageType.None); EditorGUILayout.HelpBox("Feel free to use multiple different AudioTriggerFeedback components on the same GameObject!" , MessageType.None); } EditorGUILayout.EndFoldoutHeaderGroup(); }