private void Initialize(SerializedProperty property)
    {
        SubclassSelectorAttribute utility = (SubclassSelectorAttribute)attribute;

        GetAllInheritedTypes(GetFieldType(property), utility.IsIncludeMono());
        GetInheritedTypeNameArrays();
    }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (property.propertyType != SerializedPropertyType.ManagedReference)
            {
                return;
            }

            SubclassSelectorAttribute utility = (SubclassSelectorAttribute)attribute;

            LazyGetAllInheritedType(utility.FieldType);

            var  indentedRect  = EditorGUI.IndentedRect(position);
            Rect popupPosition = GetPopupPosition(position);

            popupPosition.width -= 60;

            string[] typePopupNameArray = m_ReflectionType.Select(type => type == null ? "<null>" : type.ToString()).ToArray();
            string[] typeFullNameArray  = m_ReflectionType.Select(type => type == null ? "" : string.Format("{0} {1}", type.Assembly.ToString().Split(',')[0], type.FullName)).ToArray();

            //Get the type of serialized object
            int  currentTypeIndex  = Array.IndexOf(typeFullNameArray, property.managedReferenceFullTypename);
            Type currentObjectType = m_ReflectionType[currentTypeIndex];
            int  selectedTypeIndex = EditorGUI.Popup(popupPosition, currentTypeIndex, typePopupNameArray);

            if (selectedTypeIndex >= 0 && selectedTypeIndex < m_ReflectionType.Count)
            {
                if (currentObjectType != m_ReflectionType[selectedTypeIndex])
                {
                    property.managedReferenceValue = m_ReflectionType[selectedTypeIndex] == null
                        ? null
                        : Activator.CreateInstance(m_ReflectionType[selectedTypeIndex]);
                    currentObjectType = m_ReflectionType[selectedTypeIndex];
                }
            }

            if (m_InitializeFold == false)
            {
                property.isExpanded = false;
                m_InitializeFold    = true;
            }

            if (currentObjectType != null)
            {
                string path           = GetMonoScriptPathFor(currentObjectType);
                Rect   buttonPosition = new Rect(indentedRect)
                {
                    width  = 55,
                    x      = indentedRect.x + indentedRect.width - 55,
                    height = EditorGUIUtility.singleLineHeight,
                };

                if (GUI.Button(buttonPosition, "edit"))
                {
                    var texturePath = AssetDatabase.LoadMainAssetAtPath(path);
                    AssetDatabase.OpenAsset(texturePath);
                }
            }
            EditorGUI.PropertyField(indentedRect, property, label, true);
        }
Exemplo n.º 3
0
    private void Initialize(SerializedProperty property)
    {
        SubclassSelectorAttribute utility = (SubclassSelectorAttribute)attribute;
        var type = utility.Type();

        if (type == null)
        {
            type = GetType(property);
        }
        GetAllInheritedTypes(type, utility.IsIncludeMono());
        GetInheritedTypeNameArrays();
    }