예제 #1
0
        TypePopupCache GetTypePopup(SerializedProperty property)
        {
            // Cache this string. This property internally call Assembly.GetName, which result in a large allocation.
            string managedReferenceFieldTypename = property.managedReferenceFieldTypename;

            if (!m_TypePopups.TryGetValue(managedReferenceFieldTypename, out TypePopupCache result))
            {
                var state = new AdvancedDropdownState();

                Type baseType = ManagedReferenceUtility.GetType(managedReferenceFieldTypename);
                var  popup    = new AdvancedTypePopup(
                    TypeCache.GetTypesDerivedFrom(baseType).Append(baseType).Where(p =>
                                                                                   (p.IsPublic || p.IsNestedPublic) &&
                                                                                   !p.IsAbstract &&
                                                                                   !p.IsGenericType &&
                                                                                   !k_UnityObjectType.IsAssignableFrom(p) &&
                                                                                   Attribute.IsDefined(p, typeof(SerializableAttribute))
                                                                                   ),
                    k_MaxTypePopupLineCount,
                    state
                    );
                popup.OnItemSelected += item => {
                    Type   type = item.Type;
                    object obj  = m_TargetProperty.SetManagedReference(type);
                    m_TargetProperty.isExpanded = (obj != null);
                    m_TargetProperty.serializedObject.ApplyModifiedProperties();
                    m_TargetProperty.serializedObject.Update();
                };

                result = new TypePopupCache(popup, state);
                m_TypePopups.Add(managedReferenceFieldTypename, result);
            }
            return(result);
        }
예제 #2
0
 public TypePopupCache(AdvancedTypePopup typePopup, AdvancedDropdownState state)
 {
     TypePopup = typePopup;
     State     = state;
 }