static void DrawPlayStopButton(AudioClip newClip, float x, float y, bool isPlaying, bool sourceState, GUIContent onGUI, bool looped, Object targetObject) { bool wasEnabled = GUI.enabled; GUI.enabled = wasEnabled && (!isPlaying || sourceState); if (DrawIconButton(x, y, sourceState, onGUI)) { if (isPlaying) { EditorAudioTools.StopClip(newClip); } else { EditorAudioTools.PlayClip(newClip, looped, targetObject); } } GUI.enabled = wasEnabled; }
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { EditorGUI.BeginProperty(pos, label, prop); Object oldClip = prop.objectReferenceValue; float toolbarStart = pos.width - fullToolbarSize; Rect rect = new Rect(pos.x, pos.y, toolbarStart, EditorGUIUtility.singleLineHeight); if ((attribute as PreviewedAudioAttribute).useAssetSelector) { AssetSelector.Draw(typeof(AudioClip), rect, prop, label, null); } else { EditorGUI.PropertyField(rect, prop, label); } if (oldClip != prop.objectReferenceValue) { EditorAudioTools.StopClip(oldClip as AudioClip); } GUITools.DrawToolbarDivider(pos.x + toolbarStart, pos.y); GUI.enabled = prop.objectReferenceValue != null; pos = new Rect(pos.x + toolbarStart + GUITools.toolbarDividerSize, pos.y, optionsToolbarSize, EditorGUIUtility.singleLineHeight); AudioClip newClip = prop.objectReferenceValue as AudioClip; AudioSource source; bool isPlaying = EditorAudioTools.IsClipPlaying(newClip, out source); DrawPlayStopButton(newClip, pos.x, pos.y, isPlaying, isPlaying && !source.loop, playGUI, false, prop.serializedObject.targetObject); DrawPlayStopButton(newClip, pos.x + GUITools.iconButtonWidth, pos.y, isPlaying, isPlaying && source.loop, playGUILooped, true, prop.serializedObject.targetObject); GUI.enabled = true; EditorGUI.EndProperty(); }
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { UnityEngine.Object oldClip = prop.objectReferenceValue; Rect rect = new Rect(pos.x, pos.y, pos.width - fullToolbarSize, EditorGUIUtility.singleLineHeight); if ((attribute as PreviewedAudioAttribute).useAssetSelector) { AssetSelector.Draw(typeof(AudioClip), rect, prop, label, null, null); } else { EditorGUI.PropertyField(rect, prop, label); } float toolbarStart = pos.x + pos.width - fullToolbarSize; if (oldClip != prop.objectReferenceValue) { EditorAudioTools.StopClip(oldClip as AudioClip); } GUITools.DrawToolbarDivider(toolbarStart, pos.y); GUI.enabled = prop.objectReferenceValue != null; AudioClip newClip = prop.objectReferenceValue as AudioClip; AudioSource source; bool isPlaying = EditorAudioTools.IsClipPlaying(newClip, out source); float xStart = toolbarStart + GUITools.toolbarDividerSize; UnityEngine.Object targetObject = prop.serializedObject.targetObject; DrawPlayStopButton(newClip, xStart + GUITools.iconButtonWidth * 0, pos.y, isPlaying, isPlaying && !source.loop, BuiltInIcons.GetIcon("preAudioPlayOff", "Play Clip"), false, targetObject); DrawPlayStopButton(newClip, xStart + GUITools.iconButtonWidth * 1, pos.y, isPlaying, isPlaying && source.loop, BuiltInIcons.GetIcon("preAudioLoopOff", "Play Clip Looped"), true, targetObject); GUI.enabled = true; }