Example #1
0
        private void DrawTypeReferenceField(Rect position, SerializedProperty property)
        {
            var typeOptionsAttribute = attribute as TypeOptionsAttribute ?? TypeOptionsAttribute.Default;
            var serializedTypeRef    = new SerializedTypeReference(property);

            var selectedType = TypeCache.GetType(serializedTypeRef.TypeNameAndAssembly);

            if (selectedType != null && !typeOptionsAttribute.MatchesRequirements(selectedType))
            {
                Debug.Log($"{property.name} had the {selectedType} value but the type does not match " +
                          "constraints set in the attribute, so it was set to null.");
                selectedType = null;
                serializedTypeRef.TypeNameAndAssembly = string.Empty;
            }

            var dropdownDrawer = new TypeDropdownDrawer(selectedType, typeOptionsAttribute, fieldInfo?.DeclaringType);

            var fieldDrawer = new TypeFieldDrawer(
                serializedTypeRef,
                position,
                dropdownDrawer,
                typeOptionsAttribute.ShortName,
                typeOptionsAttribute.UseBuiltInNames);

            fieldDrawer.Draw();
        }
 public TypeFieldDrawer(
     SerializedTypeReference serializedTypeRef,
     Rect position,
     TypeDropdownDrawer dropdownDrawer,
     bool showShortName)
 {
     _serializedTypeRef = serializedTypeRef;
     _position          = position;
     _dropdownDrawer    = dropdownDrawer;
     _showShortName     = showShortName;
 }
Example #3
0
 public TypeFieldDrawer(
     SerializedTypeReference serializedTypeRef,
     Rect position,
     TypeDropdownDrawer dropdownDrawer,
     bool showShortName,
     Action <Type> onTypeSelected = null,
     bool triggerDropdown         = false)
 {
     _serializedTypeRef = serializedTypeRef;
     _position          = position;
     _dropdownDrawer    = dropdownDrawer;
     _showShortName     = showShortName;
     _onTypeSelected    = onTypeSelected;
     _triggerDropdown   = triggerDropdown;
 }