public void DrawEvent(EditorEventRef selectedEvent, bool isNarrow) { AffirmResources(); DrawCopyableTextField("Full Path", selectedEvent.Path); DrawTextField("Banks", string.Join(", ", selectedEvent.Banks.Select(x => x.Name).ToArray())); EditorGUILayout.BeginHorizontal(); DrawTextField("Panning", selectedEvent.Is3D ? "3D" : "2D"); DrawTextField("Oneshot", selectedEvent.IsOneShot.ToString()); TimeSpan t = TimeSpan.FromMilliseconds(selectedEvent.Length); DrawTextField("Length", selectedEvent.Length > 0 ? string.Format("{0:D2}:{1:D2}:{2:D3}", t.Minutes, t.Seconds, t.Milliseconds) : "N/A"); if (!isNarrow) { DrawTextField("Streaming", selectedEvent.IsStream.ToString()); } EditorGUILayout.EndHorizontal(); if (isNarrow) { DrawTextField("Streaming", selectedEvent.IsStream.ToString()); } }
private void RefreshEventRef() { if (eventPath != eventPlayable.eventReference.Path) { eventPath = eventPlayable.eventReference.Path; if (!string.IsNullOrEmpty(eventPath)) { editorEventRef = EventManager.EventFromPath(eventPath); } else { editorEventRef = null; } if (editorEventRef != null) { eventPlayable.UpdateEventDuration( editorEventRef.IsOneShot ? editorEventRef.Length : float.PositiveInfinity); } ValidateParameterSettings(); RefreshMissingParameterLists(); } }
private static void HandleDragEvents(Rect position, SerializedProperty 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)) { EditorEventRef eventRef = DragAndDrop.objectReferences[0] as EditorEventRef; property.SetEventReference(eventRef.Guid, eventRef.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(); } } }
public static void PreviewEvent(EditorEventRef eventRef) { bool load = true; if (previewEventDesc != null) { Guid guid; previewEventDesc.getID(out guid); if (guid == eventRef.Guid) { load = false; } else { PreviewStop(); } } if (load) { CheckResult(System.loadBankFile(EventManager.MasterBank.Path, FMOD.Studio.LOAD_BANK_FLAGS.NORMAL, out masterBank)); CheckResult(System.loadBankFile(eventRef.Banks[0].Path, FMOD.Studio.LOAD_BANK_FLAGS.NORMAL, out previewBank)); CheckResult(System.getEventByID(eventRef.Guid, out previewEventDesc)); CheckResult(previewEventDesc.createInstance(out previewEventInstance)); } CheckResult(previewEventInstance.start()); previewState = PreviewState.Playing; }
public void OnGUI(EditorEventRef eventRef, bool matchingEvents) { foreach (SerializedObject serializedTarget in serializedTargets) { serializedTarget.Update(); } if (Event.current.type == EventType.Layout) { RefreshPropertyRecords(eventRef); } DrawHeader(matchingEvents); if (paramsProperty.isExpanded) { if (matchingEvents) { DrawValues(); } else { GUILayout.Box("Cannot change parameters when different events are selected", GUILayout.ExpandWidth(true)); } } foreach (SerializedObject serializedTarget in serializedTargets) { serializedTarget.ApplyModifiedProperties(); } }
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) { float baseHeight = GetBaseHeight(); EventReference eventReference = property.GetEventReference(); EditorEventRef editorEventRef = GetEditorEventRef(eventReference); if (editorEventRef == null) { return(baseHeight + WarningSize().y); } else { float height; if (property.isExpanded) { height = baseHeight * 6; // 5 lines of info } else { height = baseHeight; } if (GetMismatch(eventReference, editorEventRef) != null) { height += WarningSize().y; } return(height); } }
public void OnEnable() { eventPlayable = target as FMODEventPlayable; if (eventPlayable && !string.IsNullOrEmpty(eventPlayable.eventName)) { editorEventRef = EventManager.EventFromPath(eventPlayable.eventName); eventPlayable.UpdateEventDuration(editorEventRef.IsOneShot ? editorEventRef.Length : float.PositiveInfinity); } }
private static bool IsValidEventRef(string reference) { if (string.IsNullOrEmpty(reference)) { return(true); } EditorEventRef eventRef = EventManager.EventFromPath(reference); return(eventRef != null); }
// Rebuilds the propertyRecords and missingParameters collections. private void RefreshPropertyRecords(EditorEventRef eventRef) { propertyRecords.Clear(); foreach (SerializedObject serializedTarget in serializedTargets) { SerializedProperty paramsProperty = serializedTarget.FindProperty("Params"); foreach (SerializedProperty parameterProperty in paramsProperty) { string name = parameterProperty.FindPropertyRelative("Name").stringValue; SerializedProperty valueProperty = parameterProperty.FindPropertyRelative("Value"); PropertyRecord record = propertyRecords.Find(r => r.name == name); if (record != null) { record.valueProperties.Add(valueProperty); } else { EditorParamRef paramRef = eventRef.LocalParameters.Find(p => p.Name == name); if (paramRef != null) { propertyRecords.Add( new PropertyRecord() { paramRef = paramRef, valueProperties = new List <SerializedProperty>() { valueProperty }, }); } } } } // Only sort if there is a multi-selection. If there is only one object selected, // the user can revert to prefab, and the behaviour depends on the array order, // so it's helpful to show the true order. if (serializedTargets.Count > 1) { propertyRecords.Sort((a, b) => EditorUtility.NaturalCompare(a.name, b.name)); } missingParameters.Clear(); missingParameters.AddRange(eventRef.LocalParameters.Where( p => { PropertyRecord record = propertyRecords.Find(r => r.name == p.Name); return(record == null || record.valueProperties.Count < serializedTargets.Count); })); }
void SetEvent(EditorEventRef eventRef) { if (eventRef != currentEvent) { currentEvent = eventRef; EditorUtils.PreviewStop(); transportControls.Reset(); event3DPreview.Reset(); parameterControls.Reset(); } }
public static void PreviewEvent(EditorEventRef eventRef, Dictionary <string, float> previewParamValues) { bool load = true; if (previewEventDesc.isValid()) { Guid guid; previewEventDesc.getID(out guid); if (guid == eventRef.Guid) { load = false; } else { PreviewStop(); } } if (load) { masterBanks.Clear(); foreach (EditorBankRef masterBankRef in EventManager.MasterBanks) { FMOD.Studio.Bank masterBank; CheckResult(System.loadBankFile(masterBankRef.Path, FMOD.Studio.LOAD_BANK_FLAGS.NORMAL, out masterBank)); masterBanks.Add(masterBank); } if (!EventManager.MasterBanks.Exists(x => eventRef.Banks.Contains(x))) { CheckResult(System.loadBankFile(eventRef.Banks[0].Path, FMOD.Studio.LOAD_BANK_FLAGS.NORMAL, out previewBank)); } else { previewBank.clearHandle(); } CheckResult(System.getEventByID(eventRef.Guid, out previewEventDesc)); CheckResult(previewEventDesc.createInstance(out previewEventInstance)); } foreach (EditorParamRef param in eventRef.Parameters) { FMOD.Studio.PARAMETER_DESCRIPTION paramDesc; CheckResult(previewEventDesc.getParameterDescriptionByName(param.Name, out paramDesc)); param.ID = paramDesc.id; PreviewUpdateParameter(param.ID, previewParamValues[param.Name]); } CheckResult(previewEventInstance.start()); previewState = PreviewState.Playing; }
private static void SetEvent(SerializedProperty property, string path) { EditorEventRef eventRef = EventManager.EventFromPath(path); if (eventRef != null) { property.SetEventReference(eventRef.Guid, eventRef.Path); } else { property.SetEventReference(new FMOD.GUID(), path); } }
static void DrawGizmo(StudioEventEmitter studioEmitter, GizmoType gizmoType) { Gizmos.DrawIcon(studioEmitter.transform.position, "FMODEmitter.tiff", true); if ((int)(gizmoType & GizmoType.Selected) != 0 && studioEmitter.Event != null) { EditorEventRef editorEvent = EventManager.EventFromPath(studioEmitter.Event.Path); if (editorEvent != null && editorEvent.Is3D) { Gizmos.DrawWireSphere(studioEmitter.transform.position, editorEvent.MinDistance); Gizmos.DrawWireSphere(studioEmitter.transform.position, editorEvent.MaxDistance); } } }
private void PreviewSnapshot(Rect previewRect, EditorEventRef selectedEvent) { using (new GUILayout.AreaScope(previewRect)) { var style = new GUIStyle(EditorStyles.label); EditorStyles.label.fontStyle = FontStyle.Bold; EditorGUIUtility.labelWidth = 75; EditorGUILayout.LabelField("Full Path", selectedEvent.Path, style); EditorGUIUtility.labelWidth = 0; EditorStyles.label.fontStyle = FontStyle.Normal; } }
private void PreviewSnapshot(Rect previewRect, EditorEventRef selectedEvent) { GUILayout.BeginArea(previewRect); var style = new GUIStyle(EditorStyles.label); EditorStyles.label.fontStyle = FontStyle.Bold; EditorGUIUtility.labelWidth = 75; EditorGUILayout.LabelField("Full Path", selectedEvent.Path, style); EditorGUIUtility.labelWidth = 0; EditorStyles.label.fontStyle = FontStyle.Normal; GUILayout.EndArea(); }
private static EditorEventRef GetRenamedEventRef(EventReference eventReference) { if (Settings.Instance.EventLinkage == EventLinkage.Path && !eventReference.Guid.IsNull) { EditorEventRef editorEventRef = EventManager.EventFromGUID(eventReference.Guid); if (editorEventRef != null && editorEventRef.Path != eventReference.Path) { return(editorEventRef); } } return(null); }
public void OnGUI() { AffirmResources(); ScriptableObject selectedObject = treeView.SelectedObject; if (selectedObject is EditorEventRef) { SetEvent(selectedObject as EditorEventRef); } else { SetEvent(null); } if (selectedObject != null) { GUILayout.BeginVertical(mainStyle, GUILayout.ExpandWidth(true)); if (selectedObject is EditorEventRef) { EditorEventRef eventRef = selectedObject as EditorEventRef; if (eventRef.Path.StartsWith("event:")) { DrawEventPreview(eventRef); } else if (eventRef.Path.StartsWith("snapshot:")) { detailsView.DrawSnapshot(eventRef); } } else if (selectedObject is EditorBankRef) { detailsView.DrawBank(selectedObject as EditorBankRef); } else if (selectedObject is EditorParamRef) { detailsView.DrawParameter(selectedObject as EditorParamRef); } GUILayout.EndVertical(); if (Event.current.type == EventType.Repaint) { Rect rect = GUILayoutUtility.GetLastRect(); isNarrow = rect.width < 600; } } }
private static void UpdateParamsOnEmitter(UnityEngine.Object obj, EditorEventRef eventRef) { var emitter = obj as StudioEventEmitter; for (int i = 0; i < emitter.Params.Length; i++) { if (!eventRef.Parameters.Exists((x) => x.Name == emitter.Params[i].Name)) { int end = emitter.Params.Length - 1; emitter.Params[i] = emitter.Params[end]; Array.Resize <ParamRef>(ref emitter.Params, end); i--; } } }
public static void PreviewEvent(EditorEventRef eventRef) { bool load = true; if (previewEventDesc.isValid()) { Guid guid; previewEventDesc.getID(out guid); if (guid == eventRef.Guid) { load = false; } else { PreviewStop(); } } if (load) { masterBanks.Clear(); foreach (EditorBankRef masterBankRef in EventManager.MasterBanks) { FMOD.Studio.Bank masterBank; CheckResult(System.loadBankFile(masterBankRef.Path, FMOD.Studio.LOAD_BANK_FLAGS.NORMAL, out masterBank)); masterBanks.Add(masterBank); } if (!EventManager.MasterBanks.Exists(x => eventRef.Banks.Contains(x))) { CheckResult(System.loadBankFile(eventRef.Banks[0].Path, FMOD.Studio.LOAD_BANK_FLAGS.NORMAL, out previewBank)); } else { previewBank.clearHandle(); } CheckResult(System.getEventByID(eventRef.Guid, out previewEventDesc)); CheckResult(previewEventDesc.createInstance(out previewEventInstance)); } CheckResult(previewEventInstance.start()); previewState = PreviewState.Playing; }
private void DrawEventPreview(EditorEventRef eventRef) { detailsView.DrawEvent(eventRef, isNarrow); DrawSeparatorLine(); // Playback controls, 3D Preview and meters EditorGUILayout.BeginHorizontal(GUILayout.Height(event3DPreview.Height)); GUILayout.FlexibleSpace(); EditorGUILayout.BeginVertical(); if (!isNarrow) { GUILayout.FlexibleSpace(); } transportControls.OnGUI(eventRef, parameterControls.ParameterValues); if (isNarrow) { EditorGUILayout.Separator(); meters.OnGUI(true); } else { GUILayout.FlexibleSpace(); } EditorGUILayout.EndVertical(); event3DPreview.OnGUI(eventRef); if (!isNarrow) { meters.OnGUI(false); } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); DrawSeparatorLine(); parameterControls.OnGUI(eventRef); }
public void OnGUI(EditorEventRef selectedEvent, Dictionary <string, float> parameterValues) { AffirmResources(); var previewState = EditorUtils.PreviewState; bool playing = previewState == PreviewState.Playing; bool paused = previewState == PreviewState.Paused; bool stopped = previewState == PreviewState.Stopped; EditorGUILayout.BeginHorizontal(); if (GUILayout.Button(stopped || paused ? stopOn : stopOff, buttonStyle, GUILayout.ExpandWidth(false))) { forceRepaint = false; if (paused) { EditorUtils.PreviewStop(); } if (playing) { EditorUtils.PreviewPause(); } } if (GUILayout.Button(playing ? playOn : playOff, buttonStyle, GUILayout.ExpandWidth(false))) { if (playing || stopped) { EditorUtils.PreviewEvent(selectedEvent, parameterValues); } else { EditorUtils.PreviewPause(); } forceRepaint = true; } if (GUILayout.Button(new GUIContent(openIcon, "Show Event in FMOD Studio"), buttonStyle, GUILayout.ExpandWidth(false))) { string cmd = string.Format("studio.window.navigateTo(studio.project.lookup(\"{0}\"))", selectedEvent.Guid.ToString("b")); EditorUtils.SendScriptCommand(cmd); } EditorGUILayout.EndHorizontal(); }
void SetPreviewEvent(EditorEventRef eventRef) { forceRepaint = false; EditorUtils.PreviewStop(); previewParamValues.Clear(); previewDistance = 0; previewOrientation = 0; if (eventRef != null) { foreach (var paramRef in eventRef.Parameters) { previewParamValues.Add(paramRef.Name, paramRef.Default); } } eventPosition = new Vector2(0, 0); }
public void OnGUI(EditorEventRef selectedEvent) { scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUILayout.Height(EditorGUIUtility.singleLineHeight * 3.5f)); foreach (EditorParamRef paramRef in selectedEvent.Parameters) { if (!parameterValues.ContainsKey(paramRef.Name)) { parameterValues[paramRef.Name] = paramRef.Default; } parameterValues[paramRef.Name] = EditorGUILayout.Slider(paramRef.Name, parameterValues[paramRef.Name], paramRef.Min, paramRef.Max); EditorUtils.PreviewUpdateParameter(paramRef.ID, parameterValues[paramRef.Name]); } GUILayout.EndScrollView(); }
private static MismatchInfo GetMismatch(EventReference eventReference, EditorEventRef editorEventRef) { if (EventManager.GetEventLinkage(eventReference) == EventLinkage.Path) { if (eventReference.Guid != editorEventRef.Guid) { return(new MismatchInfo() { Message = "GUID doesn't match path", HelpText = string.Format( "The GUID on this EventReference doesn't match the path.\n" + "You can click the repair button to update the GUID to match the path, or run the " + "<b>{0}</b> command to scan your project for similar issues and fix them all.", EventReferenceUpdater.MenuPath), RepairTooltip = string.Format("Repair: set GUID to {0}", editorEventRef.Guid), RepairAction = (property) => { property.FindPropertyRelative("Guid").SetGuid(editorEventRef.Guid); }, }); } } else // EventLinkage.GUID { if (eventReference.Path != editorEventRef.Path) { return(new MismatchInfo() { Message = "Path doesn't match GUID", HelpText = string.Format( "The path on this EventReference doesn't match the GUID.\n" + "You can click the repair button to update the path to match the GUID, or run the " + "<b>{0}</b> command to scan your project for similar issues and fix them all.", EventReferenceUpdater.MenuPath), RepairTooltip = string.Format("Repair: set path to '{0}'", editorEventRef.Path), RepairAction = (property) => { property.FindPropertyRelative("Path").stringValue = editorEventRef.Path; }, }); } } return(null); }
public void OnSceneGUI() { var emitter = target as StudioEventEmitter; EditorEventRef editorEvent = EventManager.EventFromGUID(emitter.EventReference.Guid); if (editorEvent != null && editorEvent.Is3D) { EditorGUI.BeginChangeCheck(); float minDistance = emitter.OverrideAttenuation ? emitter.OverrideMinDistance : editorEvent.MinDistance; float maxDistance = emitter.OverrideAttenuation ? emitter.OverrideMaxDistance : editorEvent.MaxDistance; minDistance = Handles.RadiusHandle(Quaternion.identity, emitter.transform.position, minDistance); maxDistance = Handles.RadiusHandle(Quaternion.identity, emitter.transform.position, maxDistance); if (EditorGUI.EndChangeCheck() && emitter.OverrideAttenuation) { Undo.RecordObject(emitter, "Change Emitter Bounds"); emitter.OverrideMinDistance = Mathf.Clamp(minDistance, 0, emitter.OverrideMaxDistance); emitter.OverrideMaxDistance = Mathf.Max(emitter.OverrideMinDistance, maxDistance); } } }
private void PreviewEvent(Rect previewRect, EditorEventRef selectedEvent) { GUILayout.BeginArea(previewRect); bool isNarrow = previewRect.width < 400; var style = new GUIStyle(EditorStyles.label); EditorStyles.label.fontStyle = FontStyle.Bold; EditorGUIUtility.labelWidth = 75; EditorGUILayout.LabelField("Full Path", selectedEvent.Path, style); if (Event.current.type == EventType.Repaint) { previewPathRect = GUILayoutUtility.GetLastRect(); } if (Event.current.type == EventType.mouseDown && previewPathRect.Contains(Event.current.mousePosition) && Event.current.clickCount == 2) { EditorGUIUtility.systemCopyBuffer = selectedEvent.Path; this.ShowNotification(new GUIContent("Event Path Copied to Clipboard")); Event.current.Use(); } StringBuilder builder = new StringBuilder(); selectedEvent.Banks.ForEach((x) => { builder.Append(Path.GetFileNameWithoutExtension(x.Path)); builder.Append(", "); }); EditorGUILayout.LabelField("Banks", builder.ToString(0, Math.Max(0, builder.Length - 2)), style); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Panning", selectedEvent.Is3D ? "3D" : "2D", style); EditorGUILayout.LabelField("Oneshot", selectedEvent.IsOneShot.ToString(), style); if (!isNarrow) EditorGUILayout.LabelField("Streaming", selectedEvent.IsStream.ToString(), style); EditorGUILayout.EndHorizontal(); if (isNarrow) EditorGUILayout.LabelField("Streaming", selectedEvent.IsStream.ToString(), style); EditorGUIUtility.labelWidth = 0; EditorStyles.label.fontStyle = FontStyle.Normal; if (Event.current.type == EventType.Repaint) { var lastRect = GUILayoutUtility.GetLastRect(); if (!isNarrow) { previewCustomRect = new Rect(lastRect.width / 2 - 200, lastRect.yMax + 10, 400, 150); } else { previewCustomRect = new Rect(lastRect.width / 2 - 130, lastRect.yMax + 10, 260, 150); } } GUI.Box(new Rect(0, previewCustomRect.yMin, previewRect.width, 1), GUIContent.none); GUI.Box(new Rect(0, previewCustomRect.yMax, previewRect.width, 1), GUIContent.none); GUILayout.BeginArea(previewCustomRect); Texture playOff = EditorGUIUtility.Load("FMOD/TransportPlayButtonOff.png") as Texture; Texture playOn = EditorGUIUtility.Load("FMOD/TransportPlayButtonOn.png") as Texture; Texture stopOff = EditorGUIUtility.Load("FMOD/TransportStopButtonOff.png") as Texture; Texture stopOn = EditorGUIUtility.Load("FMOD/TransportStopButtonOn.png") as Texture; Texture openIcon = EditorGUIUtility.Load("FMOD/transportOpen.png") as Texture; var transportButtonStyle = new GUIStyle(); transportButtonStyle.padding.left = 4; transportButtonStyle.padding.top = 10; var previewState = EditorUtils.PreviewState; bool playing = previewState == PreviewState.Playing; bool paused = previewState == PreviewState.Paused; bool stopped = previewState == PreviewState.Stopped; EditorGUILayout.BeginVertical(); if (!isNarrow) GUILayout.FlexibleSpace(); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button(stopped || paused ? stopOn : stopOff, transportButtonStyle, GUILayout.ExpandWidth(false))) { forceRepaint = false; if (paused) { EditorUtils.PreviewStop(); } if (playing) { EditorUtils.PreviewPause(); } } if (GUILayout.Button(playing ? playOn : playOff, transportButtonStyle, GUILayout.ExpandWidth(false))) { if (playing || stopped) { EditorUtils.PreviewEvent(selectedEvent); } else { EditorUtils.PreviewPause(); } forceRepaint = true; } if (GUILayout.Button(new GUIContent(openIcon, "Show Event in FMOD Studio"), transportButtonStyle, GUILayout.ExpandWidth(false))) { string cmd = string.Format("studio.window.navigateTo(studio.project.lookup(\"{0}\"))", selectedEvent.Guid.ToString("b")); EditorUtils.SendScriptCommand(cmd); } EditorGUILayout.EndHorizontal(); if (!isNarrow) GUILayout.FlexibleSpace(); EditorGUILayout.EndVertical(); { Texture circle = EditorGUIUtility.Load("FMOD/preview.png") as Texture; Texture circle2 = EditorGUIUtility.Load("FMOD/previewemitter.png") as Texture; var originalColour = GUI.color; if (!selectedEvent.Is3D) { GUI.color = new Color(1.0f, 1.0f, 1.0f, 0.1f); } Rect rect = new Rect(isNarrow ? 120 : 150, 10, 128, 128); GUI.DrawTexture(rect, circle); Vector2 centre = rect.center; Rect rect2 = new Rect(rect.center.x + eventPosition.x - 6, rect.center.y + eventPosition.y - 6, 12, 12); GUI.DrawTexture(rect2, circle2); GUI.color = originalColour; if (selectedEvent.Is3D && (Event.current.type == EventType.mouseDown || Event.current.type == EventType.mouseDrag) && rect.Contains(Event.current.mousePosition)) { var newPosition = Event.current.mousePosition; Vector2 delta = (newPosition - centre); float distance = delta.magnitude; if (distance < 60) { eventPosition = newPosition - rect.center; previewDistance = distance / 60.0f * selectedEvent.MaxDistance; delta.Normalize(); float angle = Mathf.Atan2(delta.y, delta.x); previewOrientation = angle + Mathf.PI * 0.5f; } Event.current.Use(); } EditorUtils.PreviewUpdatePosition(previewDistance, previewOrientation); } float hoffset = isNarrow ? 15 : 300; float voffset = isNarrow ? 50 : 10; Texture meterOn = EditorGUIUtility.Load("FMOD/LevelMeter.png") as Texture; Texture meterOff = EditorGUIUtility.Load("FMOD/LevelMeterOff.png") as Texture; float[] metering = EditorUtils.GetMetering(); int meterHeight = isNarrow ? 86 : 128; int meterWidth = (int)((128 / (float)meterOff.height) * meterOff.width); foreach (float rms in metering) { GUI.DrawTexture(new Rect(hoffset, voffset, meterWidth, meterHeight), meterOff); float db = 20.0f * Mathf.Log10(rms * Mathf.Sqrt(2.0f)); db = Mathf.Clamp(db, -80.0f, 10.0f); float visible = 0; int[] segmentPixels = new int[] { 0, 18, 38, 60, 89, 130, 187, 244, 300 }; float[] segmentDB = new float[] { -80.0f, -60.0f, -50.0f, -40.0f, -30.0f, -20.0f, -10.0f, 0, 10.0f }; int segment = 1; while (segmentDB[segment] < db) { segment++; } visible = segmentPixels[segment - 1] + ((db - segmentDB[segment - 1]) / (segmentDB[segment] - segmentDB[segment - 1])) * (segmentPixels[segment] - segmentPixels[segment - 1]); visible *= meterHeight / (float)meterOff.height; Rect levelPosRect = new Rect(hoffset, meterHeight - visible + voffset, meterWidth, visible); Rect levelUVRect = new Rect(0, 0, 1.0f, visible / meterHeight); GUI.DrawTextureWithTexCoords(levelPosRect, meterOn, levelUVRect); hoffset += meterWidth + 5.0f; } GUILayout.EndArea(); Rect paramRect = new Rect(0, previewCustomRect.yMax + 10, previewRect.width, previewRect.height - (previewCustomRect.yMax + 10)); GUILayout.BeginArea(paramRect); paramScroll = GUILayout.BeginScrollView(paramScroll, false, false); foreach (var paramRef in selectedEvent.Parameters) { if (!previewParamValues.ContainsKey(paramRef.Name)) { previewParamValues[paramRef.Name] = paramRef.Default; } previewParamValues[paramRef.Name] = EditorGUILayout.Slider(paramRef.Name, previewParamValues[paramRef.Name], paramRef.Min, paramRef.Max); EditorUtils.PreviewUpdateParameter(paramRef.Name, previewParamValues[paramRef.Name]); } GUILayout.EndScrollView(); GUILayout.EndArea(); GUILayout.EndArea(); }
//Rect previewPathRect; private void PreviewEvent(Rect previewRect, EditorEventRef selectedEvent) { GUILayout.BeginArea(previewRect); bool isNarrow = previewRect.width < 400; var style = new GUIStyle(EditorStyles.label); EditorStyles.label.fontStyle = FontStyle.Bold; EditorGUIUtility.labelWidth = 75; var copyIcon = EditorGUIUtility.Load("FMOD/CopyIcon.png") as Texture; EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Full Path", selectedEvent.Path, style, GUILayout.ExpandWidth(true)); if (GUILayout.Button(copyIcon, GUILayout.ExpandWidth(false))) { EditorGUIUtility.systemCopyBuffer = selectedEvent.Path; } EditorGUILayout.EndHorizontal(); StringBuilder builder = new StringBuilder(); selectedEvent.Banks.ForEach((x) => { builder.Append(Path.GetFileNameWithoutExtension(x.Path)); builder.Append(", "); }); EditorGUILayout.LabelField("Banks", builder.ToString(0, Math.Max(0, builder.Length - 2)), style); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Panning", selectedEvent.Is3D ? "3D" : "2D", style); EditorGUILayout.LabelField("Oneshot", selectedEvent.IsOneShot.ToString(), style); TimeSpan t = System.TimeSpan.FromMilliseconds(selectedEvent.Length); EditorGUILayout.LabelField("Length", selectedEvent.Length > 0 ? string.Format("{0:D2}:{1:D2}:{2:D3}", t.Minutes, t.Seconds, t.Milliseconds) : "N/A", style); if (!isNarrow) { EditorGUILayout.LabelField("Streaming", selectedEvent.IsStream.ToString(), style); } EditorGUILayout.EndHorizontal(); if (isNarrow) { EditorGUILayout.LabelField("Streaming", selectedEvent.IsStream.ToString(), style); } EditorGUIUtility.labelWidth = 0; EditorStyles.label.fontStyle = FontStyle.Normal; if (Event.current.type == EventType.Repaint) { var lastRect = GUILayoutUtility.GetLastRect(); if (!isNarrow) { previewCustomRect = new Rect(lastRect.width / 2 - 200, lastRect.yMax + 10, 400, 150); } else { previewCustomRect = new Rect(lastRect.width / 2 - 130, lastRect.yMax + 10, 260, 150); } } GUI.Box(new Rect(0, previewCustomRect.yMin, previewRect.width, 1), GUIContent.none); GUI.Box(new Rect(0, previewCustomRect.yMax, previewRect.width, 1), GUIContent.none); GUILayout.BeginArea(previewCustomRect); Texture playOff = EditorGUIUtility.Load("FMOD/TransportPlayButtonOff.png") as Texture; Texture playOn = EditorGUIUtility.Load("FMOD/TransportPlayButtonOn.png") as Texture; Texture stopOff = EditorGUIUtility.Load("FMOD/TransportStopButtonOff.png") as Texture; Texture stopOn = EditorGUIUtility.Load("FMOD/TransportStopButtonOn.png") as Texture; Texture openIcon = EditorGUIUtility.Load("FMOD/transportOpen.png") as Texture; var transportButtonStyle = new GUIStyle(); transportButtonStyle.padding.left = 4; transportButtonStyle.padding.top = 10; var previewState = EditorUtils.PreviewState; bool playing = previewState == PreviewState.Playing; bool paused = previewState == PreviewState.Paused; bool stopped = previewState == PreviewState.Stopped; EditorGUILayout.BeginVertical(); if (!isNarrow) { GUILayout.FlexibleSpace(); } EditorGUILayout.BeginHorizontal(); if (GUILayout.Button(stopped || paused ? stopOn : stopOff, transportButtonStyle, GUILayout.ExpandWidth(false))) { forceRepaint = false; if (paused) { EditorUtils.PreviewStop(); } if (playing) { EditorUtils.PreviewPause(); } } if (GUILayout.Button(playing ? playOn : playOff, transportButtonStyle, GUILayout.ExpandWidth(false))) { if (playing || stopped) { EditorUtils.PreviewEvent(selectedEvent); } else { EditorUtils.PreviewPause(); } forceRepaint = true; } if (GUILayout.Button(new GUIContent(openIcon, "Show Event in FMOD Studio"), transportButtonStyle, GUILayout.ExpandWidth(false))) { string cmd = string.Format("studio.window.navigateTo(studio.project.lookup(\"{0}\"))", selectedEvent.Guid.ToString("b")); EditorUtils.SendScriptCommand(cmd); } EditorGUILayout.EndHorizontal(); if (!isNarrow) { GUILayout.FlexibleSpace(); } EditorGUILayout.EndVertical(); { Texture circle = EditorGUIUtility.Load("FMOD/preview.png") as Texture; Texture circle2 = EditorGUIUtility.Load("FMOD/previewemitter.png") as Texture; var originalColour = GUI.color; if (!selectedEvent.Is3D) { GUI.color = new Color(1.0f, 1.0f, 1.0f, 0.1f); } Rect rect = new Rect(isNarrow ? 120 : 150, 10, 128, 128); GUI.DrawTexture(rect, circle); Vector2 centre = rect.center; Rect rect2 = new Rect(rect.center.x + eventPosition.x - 6, rect.center.y + eventPosition.y - 6, 12, 12); GUI.DrawTexture(rect2, circle2); GUI.color = originalColour; #if UNITY_2017_3_OR_NEWER if (selectedEvent.Is3D && (Event.current.type == EventType.MouseDown || Event.current.type == EventType.MouseDrag) && rect.Contains(Event.current.mousePosition)) #else if (selectedEvent.Is3D && (Event.current.type == EventType.mouseDown || Event.current.type == EventType.mouseDrag) && rect.Contains(Event.current.mousePosition)) #endif { var newPosition = Event.current.mousePosition; Vector2 delta = (newPosition - centre); float distance = delta.magnitude; if (distance < 60) { eventPosition = newPosition - rect.center; previewDistance = distance / 60.0f * selectedEvent.MaxDistance; delta.Normalize(); float angle = Mathf.Atan2(delta.y, delta.x); previewOrientation = angle + Mathf.PI * 0.5f; } Event.current.Use(); } EditorUtils.PreviewUpdatePosition(previewDistance, previewOrientation); } float hoffset = isNarrow ? 15 : 300; float voffset = isNarrow ? 50 : 10; Texture meterOn = EditorGUIUtility.Load("FMOD/LevelMeter.png") as Texture; Texture meterOff = EditorGUIUtility.Load("FMOD/LevelMeterOff.png") as Texture; float[] metering = EditorUtils.GetMetering(); int meterHeight = isNarrow ? 86 : 128; int meterWidth = (int)((128 / (float)meterOff.height) * meterOff.width); foreach (float rms in metering) { GUI.DrawTexture(new Rect(hoffset, voffset, meterWidth, meterHeight), meterOff); float db = 20.0f * Mathf.Log10(rms * Mathf.Sqrt(2.0f)); db = Mathf.Clamp(db, -80.0f, 10.0f); float visible = 0; int[] segmentPixels = new int[] { 0, 18, 38, 60, 89, 130, 187, 244, 300 }; float[] segmentDB = new float[] { -80.0f, -60.0f, -50.0f, -40.0f, -30.0f, -20.0f, -10.0f, 0, 10.0f }; int segment = 1; while (segmentDB[segment] < db) { segment++; } visible = segmentPixels[segment - 1] + ((db - segmentDB[segment - 1]) / (segmentDB[segment] - segmentDB[segment - 1])) * (segmentPixels[segment] - segmentPixels[segment - 1]); visible *= meterHeight / (float)meterOff.height; Rect levelPosRect = new Rect(hoffset, meterHeight - visible + voffset, meterWidth, visible); Rect levelUVRect = new Rect(0, 0, 1.0f, visible / meterHeight); GUI.DrawTextureWithTexCoords(levelPosRect, meterOn, levelUVRect); hoffset += meterWidth + 5.0f; } GUILayout.EndArea(); Rect paramRect = new Rect(0, previewCustomRect.yMax + 10, previewRect.width, previewRect.height - (previewCustomRect.yMax + 10)); GUILayout.BeginArea(paramRect); paramScroll = GUILayout.BeginScrollView(paramScroll, false, false); foreach (var paramRef in selectedEvent.Parameters) { if (!previewParamValues.ContainsKey(paramRef.Name)) { previewParamValues[paramRef.Name] = paramRef.Default; } previewParamValues[paramRef.Name] = EditorGUILayout.Slider(paramRef.Name, previewParamValues[paramRef.Name], paramRef.Min, paramRef.Max); EditorUtils.PreviewUpdateParameter(paramRef.Name, previewParamValues[paramRef.Name]); } GUILayout.EndScrollView(); GUILayout.EndArea(); GUILayout.EndArea(); }
static void UpdateCacheBank(EditorBankRef bankRef) { // Clear out any cached events from this bank eventCache.EditorEvents.ForEach((x) => x.Banks.Remove(bankRef)); FMOD.Studio.Bank bank; bankRef.LoadResult = EditorUtils.System.loadBankFile(bankRef.Path, FMOD.Studio.LOAD_BANK_FLAGS.NORMAL, out bank); if (bankRef.LoadResult == FMOD.RESULT.ERR_EVENT_ALREADY_LOADED) { EditorUtils.System.getBank(bankRef.Name, out bank); bank.unload(); bankRef.LoadResult = EditorUtils.System.loadBankFile(bankRef.Path, FMOD.Studio.LOAD_BANK_FLAGS.NORMAL, out bank); } if (bankRef.LoadResult == FMOD.RESULT.OK) { // Iterate all events in the bank and cache them FMOD.Studio.EventDescription[] eventList; var result = bank.getEventList(out eventList); if (result == FMOD.RESULT.OK) { foreach (var eventDesc in eventList) { string path; result = eventDesc.getPath(out path); EditorEventRef eventRef = eventCache.EditorEvents.Find((x) => x.Path == path); if (eventRef == null) { eventRef = ScriptableObject.CreateInstance <EditorEventRef>(); AssetDatabase.AddObjectToAsset(eventRef, eventCache); AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(eventRef)); eventRef.Banks = new List <EditorBankRef>(); eventCache.EditorEvents.Add(eventRef); eventRef.Parameters = new List <EditorParamRef>(); } eventRef.Banks.Add(bankRef); Guid guid; eventDesc.getID(out guid); eventRef.Guid = guid; eventRef.Path = eventRef.name = path; eventDesc.is3D(out eventRef.Is3D); eventDesc.isOneshot(out eventRef.IsOneShot); eventDesc.isStream(out eventRef.IsStream); eventDesc.getMaximumDistance(out eventRef.MaxDistance); eventDesc.getMinimumDistance(out eventRef.MinDistance); eventDesc.getLength(out eventRef.Length); int paramCount = 0; eventDesc.getParameterDescriptionCount(out paramCount); eventRef.Parameters.ForEach((x) => x.Exists = false); for (int paramIndex = 0; paramIndex < paramCount; paramIndex++) { FMOD.Studio.PARAMETER_DESCRIPTION param; eventDesc.getParameterDescriptionByIndex(paramIndex, out param); if ((param.flags & FMOD.Studio.PARAMETER_FLAGS.READONLY) != 0) { continue; } EditorParamRef paramRef = eventRef.Parameters.Find((x) => x.name == param.name); if (paramRef == null) { paramRef = ScriptableObject.CreateInstance <EditorParamRef>(); AssetDatabase.AddObjectToAsset(paramRef, eventCache); AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(paramRef)); eventRef.Parameters.Add(paramRef); } paramRef.Name = param.name; paramRef.name = "parameter:/" + Path.GetFileName(path) + "/" + paramRef.Name; paramRef.Min = param.minimum; paramRef.Max = param.maximum; paramRef.Default = param.defaultvalue; paramRef.Exists = true; } eventRef.Parameters.RemoveAll((x) => !x.Exists); } } // Update global parameter list for each bank FMOD.Studio.PARAMETER_DESCRIPTION[] parameterDescriptions; result = EditorUtils.System.getParameterDescriptionList(out parameterDescriptions); if (result == FMOD.RESULT.OK) { for (int i = 0; i < parameterDescriptions.Length; i++) { FMOD.Studio.PARAMETER_DESCRIPTION param = parameterDescriptions[i]; if (param.flags == FMOD.Studio.PARAMETER_FLAGS.GLOBAL) { EditorParamRef paramRef = eventCache.EditorParameters.Find((x) => (parameterDescriptions[i].id.data1 == x.ID.data1 && param.id.data2 == x.ID.data2)); if (paramRef == null) { paramRef = ScriptableObject.CreateInstance <EditorParamRef>(); AssetDatabase.AddObjectToAsset(paramRef, eventCache); AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(paramRef)); eventCache.EditorParameters.Add(paramRef); paramRef.ID = param.id; } paramRef.Name = paramRef.name = param.name; paramRef.Min = param.minimum; paramRef.Max = param.maximum; paramRef.Default = param.defaultvalue; paramRef.Exists = true; } } } bank.unload(); } else { Debug.LogError(string.Format("FMOD Studio: Unable to load {0}: {1}", bankRef.Name, FMOD.Error.String(bankRef.LoadResult))); eventCache.StringsBankWriteTime = DateTime.MinValue; } }
public static void PreviewEvent(EditorEventRef eventRef) { bool load = true; if (previewEventDesc != null) { Guid guid; previewEventDesc.getID(out guid); if (guid == eventRef.Guid) { load = false; } else { PreviewStop(); } } if (load) { CheckResult(System.loadBankFile(EventManager.MasterBank.Path, FMOD.Studio.LOAD_BANK_FLAGS.NORMAL, out masterBank)); if (eventRef.Banks[0] != EventManager.MasterBank) { CheckResult(System.loadBankFile(eventRef.Banks[0].Path, FMOD.Studio.LOAD_BANK_FLAGS.NORMAL, out previewBank)); } else { previewBank = null; } CheckResult(System.getEventByID(eventRef.Guid, out previewEventDesc)); CheckResult(previewEventDesc.createInstance(out previewEventInstance)); } CheckResult(previewEventInstance.start()); previewState = PreviewState.Playing; }
private static void UpdateParamsOnEmitter(UnityEngine.Object obj, EditorEventRef eventRef) { var emitter = obj as StudioEventEmitter; if (emitter == null) { // Custom game object return; } for (int i = 0; i < emitter.Params.Length; i++) { if (!eventRef.Parameters.Exists((x) => x.Name == emitter.Params[i].Name)) { int end = emitter.Params.Length - 1; emitter.Params[i] = emitter.Params[end]; Array.Resize<ParamRef>(ref emitter.Params, end); i--; } } }
public override void OnInspectorGUI() { var begin = serializedObject.FindProperty("PlayEvent"); var end = serializedObject.FindProperty("StopEvent"); var tag = serializedObject.FindProperty("CollisionTag"); var ev = serializedObject.FindProperty("Event"); var param = serializedObject.FindProperty("Params"); var fadeout = serializedObject.FindProperty("AllowFadeout"); var once = serializedObject.FindProperty("TriggerOnce"); var preload = serializedObject.FindProperty("Preload"); var overrideAtt = serializedObject.FindProperty("OverrideAttenuation"); var minDistance = serializedObject.FindProperty("OverrideMinDistance"); var maxDistance = serializedObject.FindProperty("OverrideMaxDistance"); EditorGUILayout.PropertyField(begin, new GUIContent("Play Event")); EditorGUILayout.PropertyField(end, new GUIContent("Stop Event")); if ((begin.enumValueIndex >= 3 && begin.enumValueIndex <= 6) || (end.enumValueIndex >= 3 && end.enumValueIndex <= 6)) { tag.stringValue = EditorGUILayout.TagField("Collision Tag", tag.stringValue); } EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(ev, new GUIContent("Event")); EditorEventRef editorEvent = EventManager.EventFromPath(ev.stringValue); if (EditorGUI.EndChangeCheck()) { EditorUtils.UpdateParamsOnEmitter(serializedObject, ev.stringValue); if (editorEvent != null) { overrideAtt.boolValue = false; minDistance.floatValue = editorEvent.MinDistance; maxDistance.floatValue = editorEvent.MaxDistance; } } // Attenuation if (editorEvent != null) { { EditorGUI.BeginDisabledGroup(editorEvent == null || !editorEvent.Is3D); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Override Attenuation"); EditorGUI.BeginChangeCheck(); overrideAtt.boolValue = EditorGUILayout.Toggle(overrideAtt.boolValue, GUILayout.Width(20)); if (EditorGUI.EndChangeCheck() || (minDistance.floatValue == -1 && maxDistance.floatValue == -1) // never been initialiased ) { minDistance.floatValue = editorEvent.MinDistance; maxDistance.floatValue = editorEvent.MaxDistance; } EditorGUI.BeginDisabledGroup(!overrideAtt.boolValue); EditorGUIUtility.labelWidth = 30; minDistance.floatValue = EditorGUILayout.FloatField("Min", minDistance.floatValue); minDistance.floatValue = Mathf.Clamp(minDistance.floatValue, 0, maxDistance.floatValue); maxDistance.floatValue = EditorGUILayout.FloatField("Max", maxDistance.floatValue); maxDistance.floatValue = Mathf.Max(minDistance.floatValue, maxDistance.floatValue); EditorGUIUtility.labelWidth = 0; EditorGUI.EndDisabledGroup(); EditorGUILayout.EndHorizontal(); EditorGUI.EndDisabledGroup(); } param.isExpanded = EditorGUILayout.Foldout(param.isExpanded, "Initial Parameter Values"); if (ev.hasMultipleDifferentValues) { if (param.isExpanded) { GUILayout.Box("Cannot change parameters when different events are selected", GUILayout.ExpandWidth(true)); } } else { var eventRef = EventManager.EventFromPath(ev.stringValue); if (param.isExpanded && eventRef != null) { foreach (var paramRef in eventRef.Parameters) { bool set; float value; bool matchingSet, matchingValue; CheckParameter(paramRef.Name, out set, out matchingSet, out value, out matchingValue); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel(paramRef.Name); EditorGUI.showMixedValue = !matchingSet; EditorGUI.BeginChangeCheck(); bool newSet = EditorGUILayout.Toggle(set, GUILayout.Width(20)); EditorGUI.showMixedValue = false; if (EditorGUI.EndChangeCheck()) { Undo.RecordObjects(serializedObject.isEditingMultipleObjects ? serializedObject.targetObjects : new UnityEngine.Object[] { serializedObject.targetObject }, "Inspector"); if (newSet) { AddParameterValue(paramRef.Name, paramRef.Default); } else { DeleteParameterValue(paramRef.Name); } set = newSet; } EditorGUI.BeginDisabledGroup(!newSet); if (set) { EditorGUI.showMixedValue = !matchingValue; EditorGUI.BeginChangeCheck(); value = EditorGUILayout.Slider(value, paramRef.Min, paramRef.Max); if (EditorGUI.EndChangeCheck()) { Undo.RecordObjects(serializedObject.isEditingMultipleObjects ? serializedObject.targetObjects : new UnityEngine.Object[] { serializedObject.targetObject }, "Inspector"); SetParameterValue(paramRef.Name, value); } EditorGUI.showMixedValue = false; } else { EditorGUI.showMixedValue = !matchingValue; EditorGUILayout.Slider(paramRef.Default, paramRef.Min, paramRef.Max); EditorGUI.showMixedValue = false; } EditorGUI.EndDisabledGroup(); EditorGUILayout.EndHorizontal(); } } } fadeout.isExpanded = EditorGUILayout.Foldout(fadeout.isExpanded, "Advanced Controls"); if (fadeout.isExpanded) { EditorGUILayout.PropertyField(preload, new GUIContent("Preload Sample Data")); EditorGUILayout.PropertyField(fadeout, new GUIContent("Allow Fadeout When Stopping")); EditorGUILayout.PropertyField(once, new GUIContent("Trigger Once")); } } serializedObject.ApplyModifiedProperties(); }
void SetPreviewEvent(EditorEventRef eventRef) { forceRepaint = false; EditorUtils.PreviewStop(); previewParamValues.Clear(); previewDistance = 0; previewOrientation = 0; if (eventRef != null) { foreach (var paramRef in eventRef.Parameters) { previewParamValues.Add(paramRef.Name, 0); } } eventPosition = new Vector2(0, 0); }
static void UpdateCacheBank(EditorBankRef bankRef) { // Clear out any cached events from this bank eventCache.EditorEvents.ForEach((x) => x.Banks.Remove(bankRef)); FMOD.Studio.Bank bank; bankRef.LoadResult = EditorUtils.System.loadBankFile(bankRef.Path, FMOD.Studio.LOAD_BANK_FLAGS.NORMAL, out bank); if (bankRef.LoadResult == FMOD.RESULT.ERR_EVENT_ALREADY_LOADED) { EditorUtils.System.getBank(bankRef.Name, out bank); bank.unload(); bankRef.LoadResult = EditorUtils.System.loadBankFile(bankRef.Path, FMOD.Studio.LOAD_BANK_FLAGS.NORMAL, out bank); } if (bankRef.LoadResult == FMOD.RESULT.OK) { // Iterate all events in the bank and cache them FMOD.Studio.EventDescription[] eventList; var result = bank.getEventList(out eventList); if (result == FMOD.RESULT.OK) { foreach (var eventDesc in eventList) { string path; eventDesc.getPath(out path); EditorEventRef eventRef = eventCache.EditorEvents.Find((x) => x.Path == path); if (eventRef == null) { eventRef = ScriptableObject.CreateInstance <EditorEventRef>(); AssetDatabase.AddObjectToAsset(eventRef, CacheAssetFullName); eventRef.Banks = new List <EditorBankRef>(); eventCache.EditorEvents.Add(eventRef); } eventRef.Banks.Add(bankRef); Guid guid; eventDesc.getID(out guid); eventRef.Guid = guid; eventRef.Path = path; eventDesc.is3D(out eventRef.Is3D); eventDesc.isOneshot(out eventRef.IsOneShot); eventDesc.isStream(out eventRef.IsStream); eventDesc.getMaximumDistance(out eventRef.MaxDistance); eventDesc.getMinimumDistance(out eventRef.MinDistance); int paramCount = 0; eventDesc.getParameterCount(out paramCount); eventRef.Parameters = new List <EditorParamRef>(paramCount); for (int paramIndex = 0; paramIndex < paramCount; paramIndex++) { EditorParamRef paramRef = ScriptableObject.CreateInstance <EditorParamRef>(); AssetDatabase.AddObjectToAsset(paramRef, CacheAssetFullName); FMOD.Studio.PARAMETER_DESCRIPTION param; eventDesc.getParameterByIndex(paramIndex, out param); paramRef.Name = param.name; paramRef.Min = param.minimum; paramRef.Max = param.maximum; eventRef.Parameters.Add(paramRef); } } } bank.unload(); } else { // TODO: log the error //UnityEngine.Debug.LogWarning("Cannot load ); } }
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(); }