Unity3D : Handle multi selection in property drawer

Unity3D : Handle multi selection in property drawer

keep forget how to do this, keep a simple template here.
idea : use property’s path to locate targetobjects(array)’s relative property.
so we can editor the property one by one.

public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
    if (property.serializedObject.isEditingMultipleObjects)
    {
        foreach(var to in property.serializedObject.targetObjects)
        {
            // Handle multi selection in property drawer
            if (to is Component comp)
            {
                var pPath           = property.propertyPath;
                var realProperty    = new SerializedObject(comp)?.FindProperty(pPath);
                Debug.Log(realProperty);
            }
            else if (to is ScriptableObject so)
            {
                // TODO:
            }
            else
            {
                EditorGUI.HelpBox(position, "Not support multiple object(s)", MessageType.Warning);
            }
        }

        EditorGUI.HelpBox(position, "Not support multiple object(s)",  MessageType.Warning);
        return;
    }
}

 

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

*

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料