public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { Texture browseIcon = EditorGUIUtility.Load("FMOD/SearchIconBlack.png") as Texture; SerializedProperty pathProperty = property; EditorGUI.BeginProperty(position, label, property); Event e = Event.current; if (e.type == EventType.DragPerform && position.Contains(e.mousePosition)) { if (DragAndDrop.objectReferences.Length > 0 && DragAndDrop.objectReferences[0] != null && DragAndDrop.objectReferences[0].GetType() == typeof(EditorBankRef)) { pathProperty.stringValue = ((EditorBankRef)DragAndDrop.objectReferences[0]).Name; e.Use(); } } if (e.type == EventType.DragUpdated && position.Contains(e.mousePosition)) { if (DragAndDrop.objectReferences.Length > 0 && DragAndDrop.objectReferences[0] != null && DragAndDrop.objectReferences[0].GetType() == typeof(EditorBankRef)) { DragAndDrop.visualMode = DragAndDropVisualMode.Move; DragAndDrop.AcceptDrag(); e.Use(); } } float baseHeight = GUI.skin.textField.CalcSize(new GUIContent()).y; position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label); var buttonStyle = new GUIStyle(GUI.skin.button); buttonStyle.padding.top = buttonStyle.padding.bottom = 1; Rect searchRect = new Rect(position.x + position.width - browseIcon.width - 15, position.y, browseIcon.width + 10, baseHeight); Rect pathRect = new Rect(position.x, position.y, searchRect.x - position.x - 5, baseHeight); EditorGUI.PropertyField(pathRect, pathProperty, GUIContent.none); if (GUI.Button(searchRect, new GUIContent(browseIcon, "Select FMOD Bank"), buttonStyle)) { var eventBrowser = EventBrowser.CreateInstance <EventBrowser>(); eventBrowser.SelectBank(property); var windowRect = position; windowRect.position = GUIUtility.GUIToScreenPoint(windowRect.position); windowRect.height = searchRect.height + 1; eventBrowser.ShowAsDropDown(windowRect, new Vector2(windowRect.width, 400)); } EditorGUI.EndProperty(); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label); EditorGUI.BeginProperty(position, label, property); float baseHeight = GUI.skin.textField.CalcSize(new GUIContent()).y; Rect rect = new Rect(position.x, position.y, position.width, baseHeight); SerializedProperty allProperty = property.FindPropertyRelative("AllBanks"); SerializedProperty banksProperty = property.FindPropertyRelative("Banks"); EditorGUI.PropertyField(rect, allProperty, new GUIContent("All Banks")); if (!allProperty.boolValue) { GUIContent addButtonContent = new GUIContent("Add Bank"); float addButtonWidth = GUI.skin.textField.CalcSize(addButtonContent).x + 20; Rect buttonRect = new Rect(position.x, position.y + baseHeight + 2, addButtonWidth, baseHeight); if (GUI.Button(buttonRect, addButtonContent)) { banksProperty.InsertArrayElementAtIndex(banksProperty.arraySize); SerializedProperty newBank = banksProperty.GetArrayElementAtIndex(banksProperty.arraySize - 1); newBank.FindPropertyRelative("Name").stringValue = ""; var browser = EventBrowser.CreateInstance <EventBrowser>(); browser.titleContent = new GUIContent("Select FMOD Bank"); browser.SelectBank(newBank); browser.ShowUtility(); } Texture deleteTexture = EditorGUIUtility.Load("FMOD/Delete.png") as Texture; GUIContent deleteContent = new GUIContent(deleteTexture, "Delete Bank"); float deleteWidth = deleteTexture.width + 5; Rect deleteRect = new Rect(position.x + position.width - deleteWidth - 10, position.y + baseHeight * 2 + 4, deleteWidth, baseHeight); Rect bankRect = new Rect(position.x, position.y + baseHeight * 2 + 4, position.width - deleteWidth - 10, baseHeight); for (int i = 0; i < banksProperty.arraySize; i++) { EditorGUI.PropertyField(bankRect, banksProperty.GetArrayElementAtIndex(i), GUIContent.none); if (GUI.Button(deleteRect, deleteContent)) { banksProperty.DeleteArrayElementAtIndex(i); } bankRect.y += baseHeight + 2; deleteRect.y += baseHeight + 2; } } else { banksProperty.ClearArray(); } EditorGUI.EndProperty(); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { Texture browseIcon = EditorGUIUtility.Load("FMOD/SearchIconBlack.png") as Texture; Texture openIcon = EditorGUIUtility.Load("FMOD/BrowserIcon.png") as Texture; Texture addIcon = EditorGUIUtility.Load("FMOD/AddIcon.png") as Texture; EditorGUI.BeginProperty(position, label, property); SerializedProperty pathProperty = property; Event e = Event.current; if (e.type == EventType.dragPerform && position.Contains(e.mousePosition)) { if (DragAndDrop.objectReferences.Length > 0 && DragAndDrop.objectReferences[0] != null && DragAndDrop.objectReferences[0].GetType() == typeof(EditorEventRef)) { pathProperty.stringValue = ((EditorEventRef)DragAndDrop.objectReferences[0]).Path; GUI.changed = true; e.Use(); } } if (e.type == EventType.DragUpdated && position.Contains(e.mousePosition)) { if (DragAndDrop.objectReferences.Length > 0 && DragAndDrop.objectReferences[0] != null && DragAndDrop.objectReferences[0].GetType() == typeof(EditorEventRef)) { DragAndDrop.visualMode = DragAndDropVisualMode.Move; DragAndDrop.AcceptDrag(); e.Use(); } } float baseHeight = GUI.skin.textField.CalcSize(new GUIContent()).y; position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label); GUIStyle buttonStyle = new GUIStyle(GUI.skin.button); buttonStyle.padding.top = 1; buttonStyle.padding.bottom = 1; Rect addRect = new Rect(position.x + position.width - addIcon.width - 7, position.y, addIcon.width + 7, baseHeight); Rect openRect = new Rect(addRect.x - openIcon.width - 7, position.y, openIcon.width + 6, baseHeight); Rect searchRect = new Rect(openRect.x - browseIcon.width - 9, position.y, browseIcon.width + 8, baseHeight); Rect pathRect = new Rect(position.x, position.y, searchRect.x - position.x - 3, baseHeight); EditorGUI.PropertyField(pathRect, pathProperty, GUIContent.none); if (GUI.Button(searchRect, new GUIContent(browseIcon, "Search"), buttonStyle)) { var eventBrowser = EventBrowser.CreateInstance <EventBrowser>(); eventBrowser.SelectEvent(property); var windowRect = position; windowRect.position = GUIUtility.GUIToScreenPoint(windowRect.position); windowRect.height = openRect.height + 1; eventBrowser.ShowAsDropDown(windowRect, new Vector2(windowRect.width, 400)); } if (GUI.Button(addRect, new GUIContent(addIcon, "Create New Event in Studio"), buttonStyle)) { var addDropdown = EditorWindow.CreateInstance <CreateEventPopup>(); addDropdown.SelectEvent(property); var windowRect = position; windowRect.position = GUIUtility.GUIToScreenPoint(windowRect.position); windowRect.height = openRect.height + 1; addDropdown.ShowAsDropDown(windowRect, new Vector2(windowRect.width, 500)); } if (GUI.Button(openRect, new GUIContent(openIcon, "Open In Browser"), buttonStyle) && !String.IsNullOrEmpty(pathProperty.stringValue) && EventManager.EventFromPath(pathProperty.stringValue) != null ) { EventBrowser.ShowEventBrowser(); var eventBrowser = EditorWindow.GetWindow <EventBrowser>(); eventBrowser.JumpToEvent(pathProperty.stringValue); } if (!String.IsNullOrEmpty(pathProperty.stringValue) && EventManager.EventFromPath(pathProperty.stringValue) != null) { Rect foldoutRect = new Rect(position.x + 10, position.y + baseHeight, position.width, baseHeight); property.isExpanded = EditorGUI.Foldout(foldoutRect, property.isExpanded, "Event Properties"); if (property.isExpanded) { var style = new GUIStyle(GUI.skin.label); style.richText = true; EditorEventRef eventRef = EventManager.EventFromPath(pathProperty.stringValue); float width = style.CalcSize(new GUIContent("<b>Oneshot</b>")).x; Rect labelRect = new Rect(position.x, position.y + baseHeight * 2, width, baseHeight); Rect valueRect = new Rect(position.x + width + 10, position.y + baseHeight * 2, pathRect.width, baseHeight); GUI.Label(labelRect, new GUIContent("<b>GUID</b>"), style); EditorGUI.SelectableLabel(valueRect, eventRef.Guid.ToString("b")); labelRect.y += baseHeight; valueRect.y += baseHeight; GUI.Label(labelRect, new GUIContent("<b>Banks</b>"), style); StringBuilder builder = new StringBuilder(); eventRef.Banks.ForEach((x) => { builder.Append(Path.GetFileNameWithoutExtension(x.Path)); builder.Append(", "); }); GUI.Label(valueRect, builder.ToString(0, builder.Length - 2)); labelRect.y += baseHeight; valueRect.y += baseHeight; GUI.Label(labelRect, new GUIContent("<b>Panning</b>"), style); GUI.Label(valueRect, eventRef.Is3D ? "3D" : "2D"); labelRect.y += baseHeight; valueRect.y += baseHeight; GUI.Label(labelRect, new GUIContent("<b>Stream</b>"), style); GUI.Label(valueRect, eventRef.IsStream.ToString()); labelRect.y += baseHeight; valueRect.y += baseHeight; GUI.Label(labelRect, new GUIContent("<b>Oneshot</b>"), style); GUI.Label(valueRect, eventRef.IsOneShot.ToString()); labelRect.y += baseHeight; valueRect.y += baseHeight; } } else { Rect labelRect = new Rect(position.x, position.y + baseHeight, position.width, baseHeight); GUI.Label(labelRect, new GUIContent("Event Not Found", EditorGUIUtility.Load("FMOD/NotFound.png") as Texture2D)); } EditorGUI.EndProperty(); }
public override void OnInspectorGUI() { var load = serializedObject.FindProperty("LoadEvent"); var unload = serializedObject.FindProperty("UnloadEvent"); var tag = serializedObject.FindProperty("CollisionTag"); var banks = serializedObject.FindProperty("Banks"); var preload = serializedObject.FindProperty("PreloadSamples"); EditorGUILayout.PropertyField(load, new GUIContent("Load")); EditorGUILayout.PropertyField(unload, new GUIContent("Unload")); if ((load.enumValueIndex >= 3 && load.enumValueIndex <= 6) || (unload.enumValueIndex >= 3 && unload.enumValueIndex <= 6)) { tag.stringValue = EditorGUILayout.TagField("Collision Tag", tag.stringValue); } EditorGUILayout.PropertyField(preload, new GUIContent("Preload Sample Data")); //EditorGUILayout.PropertyField(banks); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Banks"); EditorGUILayout.BeginVertical(); if (GUILayout.Button("Add Bank", GUILayout.ExpandWidth(false))) { banks.InsertArrayElementAtIndex(banks.arraySize); SerializedProperty newBank = banks.GetArrayElementAtIndex(banks.arraySize - 1); newBank.stringValue = ""; var browser = EventBrowser.CreateInstance <EventBrowser>(); #if UNITY_5_0 || UNITY_5_1 browser.title = "Select FMOD Bank"; #else browser.titleContent = new GUIContent("Select FMOD Bank"); #endif browser.SelectBank(newBank); browser.ShowUtility(); } Texture deleteTexture = EditorGUIUtility.Load("FMOD/Delete.png") as Texture; GUIContent deleteContent = new GUIContent(deleteTexture, "Delete Bank"); var buttonStyle = new GUIStyle(GUI.skin.button); buttonStyle.padding.top = buttonStyle.padding.bottom = 1; buttonStyle.margin.top = 2; buttonStyle.padding.left = buttonStyle.padding.right = 4; buttonStyle.fixedHeight = GUI.skin.textField.CalcSize(new GUIContent()).y; for (int i = 0; i < banks.arraySize; i++) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(banks.GetArrayElementAtIndex(i), GUIContent.none); if (GUILayout.Button(deleteContent, buttonStyle, GUILayout.ExpandWidth(false))) { banks.DeleteArrayElementAtIndex(i); } EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); Event e = Event.current; if (e.type == EventType.dragPerform) { if (DragAndDrop.objectReferences.Length > 0 && DragAndDrop.objectReferences[0] != null && DragAndDrop.objectReferences[0].GetType() == typeof(EditorBankRef)) { int pos = banks.arraySize; banks.InsertArrayElementAtIndex(pos); var pathProperty = banks.GetArrayElementAtIndex(pos); pathProperty.stringValue = ((EditorBankRef)DragAndDrop.objectReferences[0]).Name; e.Use(); } } if (e.type == EventType.DragUpdated) { if (DragAndDrop.objectReferences.Length > 0 && DragAndDrop.objectReferences[0] != null && DragAndDrop.objectReferences[0].GetType() == typeof(EditorBankRef)) { DragAndDrop.visualMode = DragAndDropVisualMode.Move; DragAndDrop.AcceptDrag(); e.Use(); } } serializedObject.ApplyModifiedProperties(); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { Texture browseIcon = EditorGUIUtility.Load("FMOD/SearchIconBlack.png") as Texture; Texture openIcon = EditorGUIUtility.Load("FMOD/StudioIcon.png") as Texture; EditorGUI.BeginProperty(position, label, property); SerializedProperty pathProperty = property; Event e = Event.current; if (e.type == EventType.dragPerform && position.Contains(e.mousePosition)) { if (DragAndDrop.objectReferences.Length > 0 && DragAndDrop.objectReferences[0] != null && DragAndDrop.objectReferences[0].GetType() == typeof(EditorEventRef)) { pathProperty.stringValue = ((EditorEventRef)DragAndDrop.objectReferences[0]).Path; GUI.changed = true; e.Use(); } } if (e.type == EventType.DragUpdated && position.Contains(e.mousePosition)) { if (DragAndDrop.objectReferences.Length > 0 && DragAndDrop.objectReferences[0] != null && DragAndDrop.objectReferences[0].GetType() == typeof(EditorEventRef)) { DragAndDrop.visualMode = DragAndDropVisualMode.Move; DragAndDrop.AcceptDrag(); e.Use(); } } float baseHeight = GUI.skin.textField.CalcSize(new GUIContent()).y; position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label); GUIStyle buttonStyle = GUI.skin.button; buttonStyle.padding.top = 1; buttonStyle.padding.bottom = 1; Rect openRect = new Rect(position.x + position.width - openIcon.width - 15, position.y, openIcon.width + 10, baseHeight); Rect searchRect = new Rect(openRect.x - browseIcon.width - 15, position.y, browseIcon.width + 10, baseHeight); Rect pathRect = new Rect(position.x, position.y, searchRect.x - position.x - 5, baseHeight); EditorGUI.PropertyField(pathRect, pathProperty, GUIContent.none); if (GUI.Button(searchRect, new GUIContent(browseIcon, "Search"), buttonStyle)) { var eventBrowser = EventBrowser.CreateInstance <EventBrowser>(); eventBrowser.titleContent = new GUIContent("Select FMOD Event"); eventBrowser.SelectEvent(property); eventBrowser.ShowUtility(); } if (GUI.Button(openRect, new GUIContent(openIcon, "Open In FMOD Studio"), buttonStyle) && !String.IsNullOrEmpty(pathProperty.stringValue) && EventManager.EventFromPath(pathProperty.stringValue) != null ) { EditorEventRef eventRef = EventManager.EventFromPath(pathProperty.stringValue); string cmd = string.Format("studio.window.navigateTo(studio.project.lookup(\"{0}\"))", eventRef.Guid.ToString("b")); EditorUtils.SendScriptCommand(cmd); } if (!String.IsNullOrEmpty(pathProperty.stringValue) && EventManager.EventFromPath(pathProperty.stringValue) != null) { Rect foldoutRect = new Rect(position.x + 10, position.y + baseHeight, position.width, baseHeight); displayProperties = EditorGUI.Foldout(foldoutRect, displayProperties, "Event Properties"); if (displayProperties) { var style = new GUIStyle(GUI.skin.label); style.richText = true; EditorEventRef eventRef = EventManager.EventFromPath(pathProperty.stringValue); float width = style.CalcSize(new GUIContent("<b>Oneshot</b>")).x; Rect labelRect = new Rect(position.x, position.y + baseHeight * 2, width, baseHeight); Rect valueRect = new Rect(position.x + width + 10, position.y + baseHeight * 2, pathRect.width, baseHeight); GUI.Label(labelRect, new GUIContent("<b>GUID</b>"), style); EditorGUI.SelectableLabel(valueRect, eventRef.Guid.ToString("b")); labelRect.y += baseHeight; valueRect.y += baseHeight; GUI.Label(labelRect, new GUIContent("<b>Banks</b>"), style); StringBuilder builder = new StringBuilder(); eventRef.Banks.ForEach((x) => { builder.Append(Path.GetFileNameWithoutExtension(x.Path)); builder.Append(", "); }); GUI.Label(valueRect, builder.ToString(0, builder.Length - 2)); labelRect.y += baseHeight; valueRect.y += baseHeight; GUI.Label(labelRect, new GUIContent("<b>Panning</b>"), style); GUI.Label(valueRect, eventRef.Is3D ? "3D" : "2D"); labelRect.y += baseHeight; valueRect.y += baseHeight; GUI.Label(labelRect, new GUIContent("<b>Stream</b>"), style); GUI.Label(valueRect, eventRef.IsStream.ToString()); labelRect.y += baseHeight; valueRect.y += baseHeight; GUI.Label(labelRect, new GUIContent("<b>Oneshot</b>"), style); GUI.Label(valueRect, eventRef.IsOneShot.ToString()); labelRect.y += baseHeight; valueRect.y += baseHeight; } } else { Rect labelRect = new Rect(position.x, position.y + baseHeight, position.width, baseHeight); GUI.Label(labelRect, new GUIContent("Event Not Found", EditorGUIUtility.Load("FMOD/NotFound.png") as Texture2D)); } EditorGUI.EndProperty(); }