private Rect DrawSubAssetsControl(SerializedProperty property, List <Object> subAssets) { assetDropDownRect = new Rect(assetDropDownRect.position, new Vector2(assetDropDownRect.width / 2, assetDropDownRect.height)); var objRect = new Rect(assetDropDownRect.xMax, assetDropDownRect.y, assetDropDownRect.width, assetDropDownRect.height); float pickerWidth = 20f; Rect pickerRect = objRect; pickerRect.width = pickerWidth; pickerRect.x = objRect.xMax - pickerWidth; bool multipleSubassets = false; // Check if targetObjects have multiple different selected if (property.serializedObject.targetObjects.Length > 1) { multipleSubassets = AssetReferenceDrawerUtilities.CheckTargetObjectsSubassetsAreDifferent(property, m_AssetRefObject.SubObjectName, fieldInfo, m_label.text); } bool isPickerPressed = Event.current.type == EventType.MouseDown && Event.current.button == 0 && pickerRect.Contains(Event.current.mousePosition); if (isPickerPressed) { // Do custom popup with scroll to pick subasset if (m_SubassetPopup == null || m_SubassetPopup.m_property != property) { m_SubassetPopup = CreateSubAssetPopup(property, subAssets ?? AssetReferenceDrawerUtilities.GetSubAssetsList(m_AssetRefObject)); } PopupWindow.Show(objRect, m_SubassetPopup); } if (m_SubassetPopup != null && m_SubassetPopup.SelectionChanged) { m_SubassetPopup.UpdateSubAssets(); } // Show selected name GUIContent nameSelected = new GUIContent("--"); if (!multipleSubassets) { nameSelected.text = AssetReferenceDrawerUtilities.FormatName(m_AssetRefObject.SubObjectName); } UnityEngine.GUI.Box(objRect, nameSelected, EditorStyles.objectField); #if UNITY_2019_1_OR_NEWER // Draw picker arrow DrawCaret(pickerRect); #endif return(assetDropDownRect); }
private void DrawSubassets(SerializedProperty property) { if (m_AssetRefObject.editorAsset != null && m_ReferencesSame) { List <Object> subAssets = null; bool hasSubAssets = !string.IsNullOrEmpty(m_AssetRefObject.SubObjectName); if (!hasSubAssets) { subAssets = AssetReferenceDrawerUtilities.GetSubAssetsList(m_AssetRefObject); hasSubAssets = subAssets.Count > 1; } if (hasSubAssets) { assetDropDownRect = DrawSubAssetsControl(property, subAssets); } } }