Ejemplo n.º 1
0
        internal void GetSelectedSubassetIndex(List <Object> subAssets, out int selIndex, out string[] objNames)
        {
            var subAssetNames = subAssets.Select(sa => sa == null ? "<none>" : $"{AssetReferenceDrawerUtilities.FormatName(sa.name)}:{sa.GetType()}").ToList();

            objNames = subAssetNames.ToArray();

            selIndex = subAssetNames.IndexOf($"{m_AssetRefObject.SubObjectName}:{m_AssetRefObject.SubOjbectType}");
            if (selIndex == -1)
            {
                selIndex = 0;
            }
        }
Ejemplo n.º 2
0
        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);
        }