Example #1
0
        public static Type InferTypeFromPropType(ControlDisplayType propType)
        {
            switch (propType)
            {
            case ControlDisplayType.Bool: { return(typeof(bool)); }

            case ControlDisplayType.Integer: { return(typeof(int)); }

            case ControlDisplayType.Float: { return(typeof(float)); }

            case ControlDisplayType.String: { return(typeof(string)); }

            case ControlDisplayType.UnityObject: { return(typeof(UnityEngine.Object)); }

            case ControlDisplayType.Guid: { return(typeof(Guid)); }

            case ControlDisplayType.Color: { return(typeof(Color)); }

            case ControlDisplayType.DropDownList: { return(typeof(string)); }

            case ControlDisplayType.DropDownEnum: { return(typeof(int)); }

            case ControlDisplayType.Curve: { return(typeof(AnimationCurve)); }

            default: return(typeof(object));
            }
        }
Example #2
0
        /// <summary>
        /// Constructs a new property with the given name and property type.
        /// </summary>
        /// <param name="name">The name of the property.</param>
        /// <param name="propType"></param>
        public DatabaseProperty(string name, ControlDisplayType propType, Type establishedType)
        {
            var inferred = BindingUtility.InferTypeFromPropType(propType);

            if (establishedType != inferred && !establishedType.IsSubclassOf(inferred))
            {
                throw new ArgumentException("The established type '" + establishedType + "' is not compatible with the property type '" + propType.ToString() + "'.");
            }
            _Name            = name;
            _PropType        = propType;
            _EstablishedType = establishedType;
        }
Example #3
0
        /// <summary>
        /// Adds a new property of the given type to this definition.
        /// </summary>
        /// <param name="controlType">The type of property to add.</param>
        /// <param name="propertyName">Optional name to give to the property that will be created.</param>
        /// <returns>A reference to the newly created property.</returns>
        public DatabaseProperty AddProperty(ControlDisplayType controlType, Type dataType, string propertyName = null)
        {
            _Version++;
            if (string.IsNullOrEmpty(propertyName))
            {
                propertyName = "New Property";
            }
            var prop = new DatabaseProperty(Database.GenerateUniqueName(propertyName, AllPropertyNames), controlType, dataType);

            Properties.Add(prop);
            return(prop);
        }