예제 #1
0
        private string GetTypeToShow(string typeName)
        {
            if (_useBuiltInNames)
            {
                string builtInName = typeName.ReplaceWithBuiltInName();
                if (builtInName != typeName)
                {
                    return(builtInName);
                }
            }

            if (_showShortName)
            {
                typeName = TypeNameFormatter.GetShortName(typeName);
            }

            if (typeName == string.Empty)
            {
                return(TypeReference.NoneElement);
            }

            if (TypeCache.GetType(_serializedTypeRef.TypeNameAndAssembly) == null)
            {
                return(typeName + MissingSuffix);
            }

            return(typeName);
        }
예제 #2
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();
        }
        private string GetTypeToShow(string typeName)
        {
            if (_useBuiltInNames && TypeNameFormatter.TryReplaceWithBuiltInName(ref typeName, true))
            {
                return(typeName);
            }

            if (_showShortName)
            {
                typeName = TypeNameFormatter.GetShortName(typeName);
            }

            if (typeName == string.Empty)
            {
                return(TypeReference.NoneElement);
            }

            if (TypeCache.GetType(_serializedTypeRef.TypeNameAndAssembly) == null)
            {
                _serializedTypeRef.TryUpdatingTypeUsingGUID();

                if (TypeCache.GetType(_serializedTypeRef.TypeNameAndAssembly) == null)
                {
                    return(typeName + MissingSuffix);
                }
            }

            return(typeName);
        }