Snippets

Ivan Wang AudioClip drawer bug

Created by Ivan
using UnityEngine;
using UnityEditor;
using Sirenix.OdinInspector.Editor;
using System;
using System.Collections.Generic;

[CustomPropertyDrawer(typeof(AudioClip)), DrawerPriority(0, 0, 1, 0)]
public class AudioClipPropertyDrawer : PropertyDrawer {
    public override float GetPropertyHeight(SerializedProperty prop, GUIContent label) {
        return EditorGUI.GetPropertyHeight(prop);
    }

    public override void OnGUI(Rect position, SerializedProperty prop, GUIContent label) {
        EditorGUI.BeginProperty(position, label, prop);
        if (prop.objectReferenceValue != null) {
            float totalWidth = position.width;
            position.width = totalWidth - (totalWidth / 4);
            EditorGUI.PropertyField(position, prop, true);

            position.x += position.width;
            position.width = totalWidth / 4;
            GUI.Button(position, "test");
        } else {
            EditorGUI.PropertyField(position, prop, true);
        }
        EditorGUI.EndProperty();
    }
}
1
2
3
4
5
6
using UnityEngine;
using System.Collections;

public class SoundTest : MonoBehaviour {
    public AudioClip[] soundEffects;
}

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.