Beispiel #1
0
 static void UpdateInstance()
 {
     if (instance == null)
     {
         instance = FindObjectOfType <SfxrPlayer>();
     }
     if (instance == null)
     {
         Debug.LogError($"No {nameof(SfxrPlayer)} found in Scene. Add one!");
     }
 }
Beispiel #2
0
        void OnExpandedGUI(ref Rect position, SerializedProperty property)
        {
            position.y += EditorGUIUtility.singleLineHeight + Margin;
            var previewRect = new Rect(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight * 5);

            // stick a button behind the preview so we can click it to play
            if (GUI.Button(previewRect, "play"))
            {
                PlayPreview(property);
            }

            // don't render the preview if it's tiny
            if (previewRect.width > 1)
            {
                DoRenderPreview(SfxrPlayer.GetClip(PropertyToParams(property)), previewRect);
            }

            position.y += previewRect.height + Margin;

            expandPresets = EditorGUI.Foldout(position, expandPresets, "Presets");
            // the change check needs to go after the foldout, if not it'll trigger a preview on open/close
            EditorGUI.BeginChangeCheck();

            if (expandPresets)
            {
                position.y += EditorGUIUtility.singleLineHeight + Margin;
                OnPresetGUI(position, property);
                position.y += EditorGUIUtility.singleLineHeight + Margin;
            }

            foreach (var prop in GetVisibleChildren(property))
            {
                position.y += EditorGUIUtility.singleLineHeight + Margin;

                if (prop.type == "Enum")
                {
                    WidgetWaveType(position, prop);
                }
                else if (prop.type == "float")
                {
                    WidgetSlider(position, prop);
                }
            }

            if (!EditorGUI.EndChangeCheck())
            {
                return;
            }
            property.serializedObject.ApplyModifiedProperties();

            PlayPreview(property);
        }
Beispiel #3
0
 static void PlayPreview(SerializedProperty property)
 {
     SfxrPlayer.Play(PropertyToParams(property), true);
 }