Ejemplo n.º 1
0
        public static bool GetPropertyType(PropertyInfo info, out SerializedPropertyType propertyType)
        {
            propertyType = SerializedPropertyType.Generic;
            System.Type type = info.PropertyType;

            if (_serializedPropertyTypeMap.ContainsKey(type))
            {
                propertyType = _serializedPropertyTypeMap[type];
                return(true);
            }

            if (type.IsEnum)
            {
                propertyType = SerializedPropertyType.Enum;
                return(true);
            }

            if (type.IsClass)
            {
                propertyType = SerializedPropertyType.ObjectReference;
                return(true);
            }

            return(false);
        }
Ejemplo n.º 2
0
    public override void Setup(InspectorData data)
    {
        base.Setup(data);

        propertyType = m_SerializedProperty.propertyType;

        var val = string.Empty;

        switch (m_SerializedProperty.propertyType)
        {
        case SerializedPropertyType.ArraySize:
        case SerializedPropertyType.Integer:
            val = m_SerializedProperty.intValue.ToString();
            m_InputField.numberType = NumericInputField.NumberType.Int;
            break;

        case SerializedPropertyType.Float:
            val = m_SerializedProperty.floatValue.ToString();
            m_InputField.numberType = NumericInputField.NumberType.Float;
            break;
        }

        m_InputField.text = val;
        m_InputField.ForceUpdateLabel();
    }
    public static bool GetPropertyType(PropertyInfo info, out SerializedPropertyType propertyType)
    {
        Type type = info.PropertyType;

        propertyType = SerializedPropertyType.Generic;
        if (type == typeof(int))
        {
            propertyType = SerializedPropertyType.Integer;
        }
        else if (type == typeof(float))
        {
            propertyType = SerializedPropertyType.Float;
        }
        else if (type == typeof(bool))
        {
            propertyType = SerializedPropertyType.Boolean;
        }
        else if (type == typeof(string))
        {
            propertyType = SerializedPropertyType.String;
        }
        else if (type == typeof(Vector2))
        {
            propertyType = SerializedPropertyType.Vector2;
        }
        else if (type == typeof(Vector3))
        {
            propertyType = SerializedPropertyType.Vector3;
        }
        else if (type.IsEnum)
        {
            propertyType = SerializedPropertyType.Enum;
        }
        return(propertyType != SerializedPropertyType.Generic);
    }
Ejemplo n.º 4
0
        public override void    Find(AssetMatches assetMatches, Object asset, AssetFinder finder, SearchResult result)
        {
            SerializedObject   so       = new SerializedObject(asset);
            SerializedProperty property = so.FindProperty("m_DefaultReferences.Array");

            if (property != null)
            {
                string                 lastString = string.Empty;
                SerializedProperty     end        = property.GetEndProperty();
                SerializedPropertyType type       = property.propertyType;

                while (property.Next(type == SerializedPropertyType.Generic) == true &&
                       SerializedProperty.EqualContents(property, end) == false)
                {
                    type = property.propertyType;

                    if (type == SerializedPropertyType.String)
                    {
                        lastString = property.stringValue;
                    }
                    else if (type == SerializedPropertyType.ObjectReference)
                    {
                        ++result.potentialMatchesCount;
                        if (property.objectReferenceValue == this.window.TargetAsset)
                        {
                            assetMatches.matches.Add(new Match(asset, property.propertyPath)
                            {
                                nicifiedPath = Utility.NicifyVariableName(lastString)
                            });
                            ++result.effectiveMatchesCount;
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public static PropertyField[] GetProperties(object obj)
        {
            List <PropertyField> fields = new List <PropertyField>();

            var objectType = obj.GetType();

            if (excludedTypeName.Contains(objectType.Name))
            {
                return(fields.ToArray());
            }

            PropertyInfo[] infos = objectType.GetProperties(BindingFlags.Public | BindingFlags.Instance);

            foreach (PropertyInfo info in infos)
            {
                if (!(info.CanRead && info.CanWrite))
                {
                    continue;
                }

                if (excludedPropertyName.Contains(info.Name))
                {
                    continue;
                }

                SerializedPropertyType type = SerializedPropertyType.Integer;

                if (PropertyField.GetPropertyType(info, out type))
                {
                    PropertyField field = new PropertyField(obj, info, type);
                    fields.Add(field);
                }
            }
            return(fields.ToArray());
        }
Ejemplo n.º 6
0
        public SerializedProperty(BinaryReader reader)
        {
            m_Name        = reader.ReadAlignedString();
            m_Description = reader.ReadAlignedString();

            int numAttributes = reader.ReadInt32();

            m_Attributes = new List <string>(numAttributes);
            for (int i = 0; i < numAttributes; i++)
            {
                m_Attributes.Add(reader.ReadAlignedString());
            }

            m_Type  = (SerializedPropertyType)reader.ReadInt32();
            m_Flags = reader.ReadUInt32();

            int numValues = 4;

            m_DefValue = new List <float>(numValues);
            for (int i = 0; i < numValues; i++)
            {
                m_DefValue.Add(reader.ReadSingle());
            }

            m_DefTexture = new SerializedTextureProperty(reader);
        }
Ejemplo n.º 7
0
        public static object DrawFieldElementCompact(SerializedPropertyType type, object value, System.Type sysType, ShowInEditorRange range, ShowInEditorStyle style)
        {
            switch (type)
            {
            case SerializedPropertyType.Integer:
                return(DrawIntegerField("", value, sysType, range, style));

            case SerializedPropertyType.Float:
                return(DrawFloatField("", value, sysType, range, style));

            case SerializedPropertyType.Boolean:
                // for some reason, editor gui layout doesn't work here
                return(GUILayout.Toggle((bool)value, new GUIContent(""), new GUILayoutOption[] { GUILayout.Width(24) }));

            case SerializedPropertyType.String:
                return(EditorGUILayout.TextField((string)value));

            case SerializedPropertyType.Enum:
                return(EditorGUILayout.EnumPopup((System.Enum)value));

            default:
                break;
            }

            return(null);
        }
		public SerializedPropertyEx( SerializedProperty property )
		{
			propertyType = property.propertyType;
			propertyPath = property.propertyPath;
				
			value = GetPropertyStringValue( property );
		}
 // Check if the property type is supported one.
 public static bool IsPropertyTypeSupported(SerializedPropertyType type)
 {
     return(type == SerializedPropertyType.Float ||
            type == SerializedPropertyType.Vector3 ||
            type == SerializedPropertyType.Quaternion ||
            type == SerializedPropertyType.Color);
 }
Ejemplo n.º 10
0
        public static string GetPropertyDisplayString(SerializedPropertyType propertyType)
        {
            string propertyName = null;

            switch (propertyType)
            {
            case SerializedPropertyType.Generic:
                throw new ArgumentException($"{SerializedPropertyType.Generic} cannot be handled by {nameof(GetPropertyDisplayString)}");

            case SerializedPropertyType.Integer:
            case SerializedPropertyType.Float:
                propertyName = "NumericalDisplay";
                break;

            case SerializedPropertyType.Boolean:
                break;

            case SerializedPropertyType.String:
                propertyName = "StringDisplay";
                break;

            case SerializedPropertyType.Color:
                propertyName = "ColorDisplay";
                break;

            case SerializedPropertyType.ObjectReference:
                propertyName = "ObjectDisplay";
                break;

            case SerializedPropertyType.LayerMask:
            case SerializedPropertyType.Enum:
                propertyName = "EnumDisplay";
                break;

            case SerializedPropertyType.Vector2:
            case SerializedPropertyType.Vector3:
            case SerializedPropertyType.Vector4:
            case SerializedPropertyType.Rect:
            case SerializedPropertyType.ArraySize:
            case SerializedPropertyType.Character:
            case SerializedPropertyType.AnimationCurve:
            case SerializedPropertyType.Bounds:
            case SerializedPropertyType.Gradient:
            case SerializedPropertyType.Quaternion:
            case SerializedPropertyType.ExposedReference:
            case SerializedPropertyType.FixedBufferSize:
            case SerializedPropertyType.Vector2Int:
            case SerializedPropertyType.Vector3Int:
            case SerializedPropertyType.RectInt:
            case SerializedPropertyType.BoundsInt:
                                #if UNITY_2019_3_OR_NEWER
            case SerializedPropertyType.ManagedReference:
                                #endif
            default:
                propertyName = "DefaultDisplay";
                break;
            }

            return(propertyName);
        }
        private Rect GetLineRect(ref Rect position, SerializedPropertyType type)
        {
            Rect rect = new Rect(position.x, position.y, position.width, EditorGUI.GetPropertyHeight(type, null));

            position = new Rect(rect.x, rect.yMax, rect.width, rect.height);
            return(rect);
        }
Ejemplo n.º 12
0
        protected float GetHeightOfPropertyType(SerializedPropertyType type)
        {
            switch (type)
            {
            case SerializedPropertyType.Bounds:
                return(EditorGUIUtility.singleLineHeight * 3);

            case SerializedPropertyType.Rect:
                if (EditorGUIUtility.wideMode)
                {
                    return(EditorGUIUtility.singleLineHeight * 2);
                }
                return(EditorGUIUtility.singleLineHeight * 3);

            case SerializedPropertyType.Vector2:
            case SerializedPropertyType.Vector3:
                if (EditorGUIUtility.wideMode)
                {
                    return(EditorGUIUtility.singleLineHeight);
                }
                return(EditorGUIUtility.singleLineHeight * 2);

            case SerializedPropertyType.Vector4:
                return(EditorGUIUtility.singleLineHeight * 2);

            default:
                return(EditorGUIUtility.singleLineHeight);
            }
        }
Ejemplo n.º 13
0
    string GetParamString(SerializedProperty property)
    {
        string paramString = "";

        SerializedPropertyType propertyType = property.propertyType;

        switch (propertyType)
        {
        case SerializedPropertyType.Boolean:
            paramString = property.boolValue.ToString();
            break;

        case SerializedPropertyType.Float:
            paramString = property.floatValue.ToString();
            break;

        case SerializedPropertyType.Integer:
            paramString = property.intValue.ToString();
            break;

        case SerializedPropertyType.String:
            paramString = property.stringValue.ToString();
            break;

        default:
            paramString = "Type \'" + property.type + "\' is not supported.";
            break;
        }
        return(paramString);
    }
Ejemplo n.º 14
0
        private bool SetSerialzedProperty(SerializedProperty sp, object variableValue)
        {
            SerializedPropertyType type = sp.propertyType; // get the property type

            switch (type)
            {
            case SerializedPropertyType.Integer:
                int intValue = (int)variableValue;
                if (sp.intValue != intValue)
                {
                    sp.intValue = intValue;
                }
                break;

            case SerializedPropertyType.String:
                string strValue = (string)variableValue;
                if (sp.stringValue != strValue)
                {
                    sp.stringValue = strValue;
                }
                break;

            case SerializedPropertyType.ObjectReference:
                Object objValue = (Object)variableValue;
                if (sp.objectReferenceValue != objValue)
                {
                    sp.objectReferenceValue = objValue;
                }
                break;

            default:
                return(false);
            }
            return(true);
        }
        public static bool IsAnimatable(SerializedPropertyType t)
        {
            bool result;

            switch (t)
            {
            case 1:
            case 2:
            case 4:
            case 8:
            case 9:
            case 10:
                goto IL_3E;

            case 3:
            case 5:
            case 6:
            case 7:
IL_31:
                if (t != 17)
                {
                    result = false;
                    return(result);
                }
                goto IL_3E;
            }
            goto IL_31;
IL_3E:
            result = true;
            return(result);
        }
Ejemplo n.º 16
0
        public SerializedPropertyEx(SerializedProperty property)
        {
            propertyType = property.propertyType;
            propertyPath = property.propertyPath;

            value = GetPropertyStringValue(property);
        }
    bool CanSort(SerializedPropertyType type)
    {
        switch (type)
        {
        case SerializedPropertyType.AnimationCurve:
        case SerializedPropertyType.Bounds:
        case SerializedPropertyType.BoundsInt:
        case SerializedPropertyType.Character:
        case SerializedPropertyType.Color:
        case SerializedPropertyType.ExposedReference:
        case SerializedPropertyType.FixedBufferSize:
        case SerializedPropertyType.Generic:
        case SerializedPropertyType.Gradient:
        case SerializedPropertyType.ObjectReference:
        case SerializedPropertyType.Quaternion:
        case SerializedPropertyType.Rect:
        case SerializedPropertyType.RectInt:
        case SerializedPropertyType.Vector2:
        case SerializedPropertyType.Vector2Int:
        case SerializedPropertyType.Vector3:
        case SerializedPropertyType.Vector3Int:
        case SerializedPropertyType.Vector4:
            return(false);

        default:
            break;
        }

        return(true);
    }
        public StratusOdinSerializedProperty(FieldInfo field, object target)
        {
            this.field        = field;
            this.type         = this.field.FieldType;
            this.propertyType = SerializedSystemObject.DeducePropertyType(this.field);
            this.displayName  = ObjectNames.NicifyVariableName(this.field.Name);
            this.target       = target;

            // Enum
            if (this.propertyType == SerializedPropertyType.Enum)
            {
                this.enumDisplayNames = StratusSearchableEnum.GetEnumDisplayNames(this.type);
            }

            // Array
            this.isArray = typeof(IList).IsAssignableFrom(this.type);
            if (this.isArray)
            {
                this.list            = this.field.GetValue(target) as IList;
                this.listElementType = Utilities.Reflection.GetIndexedType(list);
            }

            // Set the drawer
            this.drawer = SerializedSystemObject.GetObjectDrawer(this.isArray ? this.listElementType : this.type);
        }
Ejemplo n.º 19
0
 public PropertyData(AssetListConfiguration configuration, SerializedProperty property)
 {
     Type              = property.propertyType;
     IsArray           = property.isArray;
     IsInConfiguration = configuration.Columns != null &&
                         configuration.Columns.Any(c => c.PropertyPath.Equals(property.propertyPath));
 }
Ejemplo n.º 20
0
    protected int GetDimentions(SerializedPropertyType type)
    {
        switch (type)
        {
        case SerializedPropertyType.Float:
            return(1);

        case SerializedPropertyType.Integer:
            return(1);

        case SerializedPropertyType.Vector2:
            return(2);

        case SerializedPropertyType.Vector3:
            return(3);

        case SerializedPropertyType.Vector4:
            return(4);

        case SerializedPropertyType.Quaternion:
            return(4);

        case SerializedPropertyType.Color:
            return(4);

        default:
            return(-1);
        }
    }
Ejemplo n.º 21
0
        public void TraverseProperty(string assetId, Type objType, object obj, SerializedProperty property, string propertyPath, Stack <PathSegment> stack)
        {
            SerializedPropertyType type = property.propertyType;

            stack.Push(new PathSegment(propertyPath, PathSegmentType.Property));

            if (!m_assetIdToResolver.ContainsKey(assetId))
            {
                Debug.LogErrorFormat("AssetSerializedPropertyTraverser: could not find guid {0} in resolver list", assetId);
            }

            foreach (SerializedPropertyTraverserSubSystem subSystem in m_assetIdToResolver[assetId])
            {
                SerializedPropertyTraverserSubSystem.Result result = subSystem.GetDependency(objType, obj, property, propertyPath, type, stack);

                if (result == null)
                {
                    continue;
                }

                if (assetId == result.Id)
                {
                    continue;
                }

                subSystem.AddDependency(assetId, new Dependency(result.Id, result.ConnectionType, result.NodeType, stack.ToArray()));
            }

            stack.Pop();
        }
Ejemplo n.º 22
0
    public static PropertyField[] GetProperties(object obj)
    {
        var fields = new List <PropertyField>();

        PropertyInfo[] infos = obj.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);
        foreach (var info in infos)
        {
            if (!(info.CanRead && info.CanWrite))
            {
                continue;
            }

            var attributes = info.GetCustomAttributes(true);
            if (attributes.All(o => o.GetType() != typeof(ExposePropertyAttribute)))
            {
                continue;
            }

            SerializedPropertyType type = SerializedPropertyType.Integer;
            if (PropertyField.GetPropertyType(info, out type))
            {
                var field = new PropertyField(obj, info, type);
                fields.Add(field);
            }
        }

        return(fields.ToArray());
    }
Ejemplo n.º 23
0
 public PropertyField(object obj, PropertyInfo info, SerializedPropertyType type)
 {
     this.obj  = obj;
     this.info = info;
     this.type = type;
     getter    = this.info.GetGetMethod();
     setter    = this.info.GetSetMethod();
 }
Ejemplo n.º 24
0
            public PropertyField(System.Object instance, ShowInEditor attribute, SerializedPropertyType type, PropertyInfo info)
                : base(instance, attribute, type)
            {
                _info = info;

                _getter = _info.GetGetMethod();
                _setter = _info.GetSetMethod();
            }
Ejemplo n.º 25
0
 public FieldInfoDrawer(FieldInfo field) : this()
 {
     this.field        = field;
     this.type         = this.field.FieldType;
     this.label        = ObjectNames.NicifyVariableName(field.Name);
     this.propertyType = DeducePropertyType(field);
     isValid           = propertyType != SerializedPropertyType.Generic;
 }
        public override void Setup(InspectorData data)
        {
            base.Setup(data);

            propertyType = m_SerializedProperty.propertyType;

            OnObjectModified();
        }
Ejemplo n.º 27
0
 public PropertyField(object obj, PropertyInfo info, SerializedPropertyType serializedType)
 {
     this.Object         = obj;
     this.info           = info;
     this.SerializedType = serializedType;
     this.getter         = this.info.GetGetMethod();
     this.setter         = this.info.GetSetMethod();
 }
Ejemplo n.º 28
0
        /// <summary>
        /// Gets the type of the property.
        /// </summary>
        /// <returns><c>true</c>, if property type was gotten, <c>false</c> otherwise.</returns>
        /// <param name="info">Info.</param>
        /// <param name="propertyType">Property type.</param>
        public static bool GetPropertyType(PropertyInfo info, out SerializedPropertyType propertyType)
        {
            propertyType = SerializedPropertyType.Generic;

            Type type = info.PropertyType;

            if (type == typeof(int))
            {
                propertyType = SerializedPropertyType.Integer;
                return(true);
            }

            if (type == typeof(float))
            {
                propertyType = SerializedPropertyType.Float;
                return(true);
            }

            if (type == typeof(bool))
            {
                propertyType = SerializedPropertyType.Boolean;
                return(true);
            }

            if (type == typeof(string))
            {
                propertyType = SerializedPropertyType.String;
                return(true);
            }

            if (type == typeof(Vector2))
            {
                propertyType = SerializedPropertyType.Vector2;
                return(true);
            }

            if (type == typeof(Vector3))
            {
                propertyType = SerializedPropertyType.Vector3;
                return(true);
            }

            if (type.IsEnum)
            {
                propertyType = SerializedPropertyType.Enum;
                return(true);
            }

            //NEW
            if (type == typeof(Rect))
            {
                propertyType = SerializedPropertyType.Rect;
                return(true);
            }


            return(false);
        }
    public static bool GetPropertyType(PropertyInfo info, out SerializedPropertyType propertyType)
    {
        propertyType = SerializedPropertyType.Generic;

        Type type = info.PropertyType;

        if (type == typeof(int))
        {
            propertyType = SerializedPropertyType.Integer;
            return(true);
        }

        if (type == typeof(float))
        {
            propertyType = SerializedPropertyType.Float;
            return(true);
        }

        if (type == typeof(bool))
        {
            propertyType = SerializedPropertyType.Boolean;
            return(true);
        }

        if (type == typeof(string))
        {
            propertyType = SerializedPropertyType.String;
            return(true);
        }

        if (type == typeof(Vector2))
        {
            propertyType = SerializedPropertyType.Vector2;
            return(true);
        }

        if (type == typeof(Vector3))
        {
            propertyType = SerializedPropertyType.Vector3;
            return(true);
        }

        if (type.IsEnum)
        {
            propertyType = SerializedPropertyType.Enum;
            return(true);
        }

        if (type == typeof(GameObject) ||
            type == typeof(UnityEngine.Object) ||
            type == typeof(Texture2D))
        {
            propertyType = SerializedPropertyType.ObjectReference;
            return(true);
        }

        return(false);
    }
        //--------------------------------------
        //  Methods
        //--------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="com.unity3d.wiki.expose_properties.PropertyField"/> class.
        /// </summary>
        /// <param name="instance">Instance.</param>
        /// <param name="info">Info.</param>
        /// <param name="type">Type.</param>
        public PropertyField( System.Object instance, PropertyInfo info, SerializedPropertyType type )
        {
            m_Instance = instance;
            m_Info = info;
            m_Type = type;

            m_Getter = m_Info.GetGetMethod();
            m_Setter = m_Info.GetSetMethod();
        }
Ejemplo n.º 31
0
        public PropertyData(Object owner, PropertyInfo propertyInfo)
        {
            _owner = owner;
            PropertyInfo = propertyInfo;
            UnityPropertyType = GetSerializedPropertyTypeFrom(PropertyInfo);

            _propertyGetter = PropertyInfo.GetGetMethod();
            _propertySetter = PropertyInfo.GetSetMethod();
        }
Ejemplo n.º 32
0
        /// <summary>
        ///   Creates a new wrapper for mono behaviour properties exposed in the Unity inspector.
        /// </summary>
        /// <param name="instance">Object to wrap the property of.</param>
        /// <param name="property">Property to wrap.</param>
        /// <param name="type">Type of the property to wrap.</param>
        public PropertyField(object instance, PropertyInfo property, SerializedPropertyType type)
        {
            this.instance = instance;
            this.property = property;
            this.type = type;

            this.getter = this.property.GetGetMethod();
            this.setter = this.property.GetSetMethod();
        }
    public CoherentPropertyField(System.Object instance, PropertyInfo info, SerializedPropertyType type)
    {
        m_Instance = instance;
        m_Info     = info;
        m_Type     = type;

        m_Getter = m_Info.GetGetMethod();
        m_Setter = m_Info.GetSetMethod();
    }
Ejemplo n.º 34
0
    public PropertyField(object instance, PropertyInfo info, SerializedPropertyType type)
    {
        _instance = instance;
        _info     = info;
        _type     = type;

        _getter = _info.GetGetMethod();
        _setter = _info.GetSetMethod();
    }
Ejemplo n.º 35
0
        protected float GetHeightOfPropertyType(SerializedPropertyType type)
        {
            switch (type)
            {
                case SerializedPropertyType.Bounds:
                    return EditorGUIUtility.singleLineHeight * 3;

                case SerializedPropertyType.Rect:
                    if (EditorGUIUtility.wideMode) return EditorGUIUtility.singleLineHeight * 2;
                    return EditorGUIUtility.singleLineHeight * 3;

                case SerializedPropertyType.Vector2:
                case SerializedPropertyType.Vector3:
                    if (EditorGUIUtility.wideMode) return EditorGUIUtility.singleLineHeight;
                    return EditorGUIUtility.singleLineHeight * 2;

                case SerializedPropertyType.Vector4:
                    return EditorGUIUtility.singleLineHeight * 2;

                default:
                    return EditorGUIUtility.singleLineHeight;
            }
        }
Ejemplo n.º 36
0
        protected void OnGUIOfPropertyType(SerializedPropertyType type, Rect rect, GUIContent label)
        {
            switch (type)
            {
                case SerializedPropertyType.AnimationCurve:
                    EditorGUI.BeginChangeCheck(); GetAnimationCurve();
                    animationCurveValue = EditorGUI.CurveField(rect, label, animationCurveValue);
                    if (EditorGUI.EndChangeCheck()) SetAnimationCurve();
                    return;

                case SerializedPropertyType.Boolean:
                    EditorGUI.BeginChangeCheck(); GetBool();
                    boolValue = EditorGUI.Toggle(rect, label, boolValue);
                    if (EditorGUI.EndChangeCheck()) SetBool();
                    return;

                case SerializedPropertyType.Bounds:
                    EditorGUI.BeginChangeCheck(); GetBounds();
                    boundsValue = EditorGUI.BoundsField(rect, label, boundsValue);
                    if (EditorGUI.EndChangeCheck()) SetBounds();
                    return;

                case SerializedPropertyType.Color:
                    EditorGUI.BeginChangeCheck(); GetColor();
                    colorValue = EditorGUI.ColorField(rect, label, colorValue);
                    if (EditorGUI.EndChangeCheck()) SetColor();
                    return;

                case SerializedPropertyType.Enum:
                    EditorGUI.BeginChangeCheck(); GetEnum();
                    enumValue = EditorGUI.EnumPopup(rect, label, enumValue);
                    if (EditorGUI.EndChangeCheck()) SetEnum();
                    return;

                case SerializedPropertyType.Float:
                    EditorGUI.BeginChangeCheck(); GetFloat();
                    floatValue = EditorGUI.FloatField(rect, label, floatValue);
                    if (EditorGUI.EndChangeCheck()) SetFloat();
                    return;

                case SerializedPropertyType.Integer:
                    EditorGUI.BeginChangeCheck(); GetInt();
                    intValue = EditorGUI.IntField(rect, label, intValue);
                    if (EditorGUI.EndChangeCheck()) SetInt();
                    return;

                case SerializedPropertyType.LayerMask:
                    SerializedProperty property = BasePropertyDrawer.property;
                    GetLayerMask();
                    EditorKit.LayerMaskField(rect, label, layerMaskValue,
                        mask =>
                        {
                            property.serializedObject.Update();
                            BasePropertyDrawer.property = property;
                            layerMaskValue = mask;
                            SetLayerMask();
                            property.serializedObject.ApplyModifiedProperties();
                        });
                    return;

                case SerializedPropertyType.ObjectReference:
                    EditorGUI.BeginChangeCheck(); GetObjectReference();
                    objectReferenceValue = EditorGUI.ObjectField(rect, label, objectReferenceValue,
                        fieldInfo.FieldType, !EditorUtility.IsPersistent(BasePropertyDrawer.property.serializedObject.targetObject));
                    if (EditorGUI.EndChangeCheck()) SetObjectReference();
                    return;

                case SerializedPropertyType.Rect:
                    EditorGUI.BeginChangeCheck(); GetRect();
                    rectValue = EditorGUI.RectField(rect, label, rectValue);
                    if (EditorGUI.EndChangeCheck()) SetRect();
                    return;

                case SerializedPropertyType.String:
                    EditorGUI.BeginChangeCheck(); GetString();
                    stringValue = EditorGUI.TextField(rect, label, stringValue);
                    if (EditorGUI.EndChangeCheck()) SetString();
                    return;

                case SerializedPropertyType.Vector2:
                    EditorGUI.BeginChangeCheck(); GetVector2();
                    vector2Value = EditorGUI.Vector2Field(rect, label, vector2Value);
                    if (EditorGUI.EndChangeCheck()) SetVector2();
                    return;

                case SerializedPropertyType.Vector3:
                    EditorGUI.BeginChangeCheck(); GetVector3();
                    vector3Value = EditorGUI.Vector3Field(rect, label, vector3Value);
                    if (EditorGUI.EndChangeCheck()) SetVector3();
                    return;

                case SerializedPropertyType.Vector4:
                    EditorGUI.BeginChangeCheck(); GetVector4();
                    vector4Value = EditorGUI.Vector4Field(rect, label.text, vector4Value);
                    if (EditorGUI.EndChangeCheck()) SetVector4();
                    return;

                default:
                    EditorGUI.LabelField(rect, label.text, "Not supported");
                    return;
            }
        }
    void MySetValue(Object c, object value, string prName, SerializedPropertyType type)
    {
        IEnumerable<Object> array;

        if (AllObjects)
            array = FindObjectsOfTypeIncludingAssets(c.GetType()).Where(a => a.name == c.name);
        else
        {
            array = Selection.gameObjects.Select(a => a.GetComponent(c.GetType())).Cast<Object>().Union(Selection.objects.Where(a => !(a is GameObject)));

            if (c is Material)
            {
                var d = Selection.gameObjects.Select(a => a.renderer).SelectMany(a => a.sharedMaterials).Distinct();
                array = array.Union(d.Cast<Object>());
            }
        }
        foreach (var nc in array) //êîìïîíåíòû gameobjectîâ è âûáðàíûå Objectû
        {
            if (nc != null && nc != c)
            {
                SerializedObject so = new SerializedObject(nc);
                var pr = so.FindProperty(prName);
                switch (type)
                {
                    case SerializedPropertyType.Float:
                        pr.floatValue = (float)value;
                        break;
                    case SerializedPropertyType.Boolean:
                        pr.boolValue = (bool)value;
                        break;
                    case SerializedPropertyType.String:
                        pr.stringValue = (string)value;
                        break;
                    case SerializedPropertyType.Integer:
                        pr.intValue = (int)value;
                        break;
                    case SerializedPropertyType.Color:
                        pr.colorValue = (Color)value;
                        break;
                    case SerializedPropertyType.Enum:
                        pr.enumValueIndex = (int)value;
                        break;
                }

                so.ApplyModifiedProperties();
            }
        }
    }
Ejemplo n.º 38
0
 /// <summary>
 /// Returns whether the property type should always be expanded
 /// </summary>
 public static bool PropertyTypeMustExpand(SerializedPropertyType propType)
 {
     return propType.Equals(SerializedPropertyType.AnimationCurve) ||
            propType.Equals(SerializedPropertyType.Bounds) ||
            propType.Equals(SerializedPropertyType.Rect);
 }
Ejemplo n.º 39
0
 /// <summary>
 /// Returns whether the property type can be expanded with a foldout or not
 /// </summary>
 public static bool PropertyTypeCanExpand(SerializedPropertyType propType)
 {
     return !propType.Equals(SerializedPropertyType.Color) &&
            !propType.Equals(SerializedPropertyType.LayerMask) &&
            !propType.Equals(SerializedPropertyType.ObjectReference) &&
            !propType.Equals(SerializedPropertyType.String) &&
            !propType.Equals(SerializedPropertyType.Vector2) &&
            !propType.Equals(SerializedPropertyType.Vector3);
 }
Ejemplo n.º 40
0
 /// <summary>
 /// Returns whether this is a standard property type or one of the few special ones.
 /// </summary>
 public static bool IsStandardProperty(SerializedPropertyType propType)
 {
     return !PropertyTypeMustExpand(propType);
 }
Ejemplo n.º 41
0
        /// <summary>
        /// Returns the property field name for the given prop type
        /// </summary>
        public static string GetPropFieldName(SerializedPropertyType propType)
        {
            if (_propTypesToFieldName.ContainsKey(propType)) {
                return _propTypesToFieldName[propType];
            }

            return string.Empty;
        }
Ejemplo n.º 42
0
    public PropertyField(System.Object instance, PropertyInfo info, SerializedPropertyType type)
    {

        this.instance = instance;
        this.info = info;
        mType = type;

        getter = this.info.GetGetMethod();
        setter = this.info.GetSetMethod();
    }
Ejemplo n.º 43
0
 public static bool GetPropertyType(PropertyInfo info, out SerializedPropertyType propertyType)
 {
     Type type = info.PropertyType;
     propertyType = SerializedPropertyType.Generic;
     if (type == typeof(int))
         propertyType = SerializedPropertyType.Integer;
     else if (type == typeof(float))
         propertyType = SerializedPropertyType.Float;
     else if (type == typeof(bool))
         propertyType = SerializedPropertyType.Boolean;
     else if (type == typeof(string))
         propertyType = SerializedPropertyType.String;
     else if (type == typeof(Vector2))
         propertyType = SerializedPropertyType.Vector2;
     else if (type == typeof(Vector3))
         propertyType = SerializedPropertyType.Vector3;
     else if (type.IsEnum)
         propertyType = SerializedPropertyType.Enum;
     else if (typeof(MonoBehaviour).IsAssignableFrom(type))
         propertyType = SerializedPropertyType.ObjectReference;
     return propertyType != SerializedPropertyType.Generic;
 }
		public static bool GetPropertyType(PropertyInfo info, out SerializedPropertyType propertyType)
		{
			Type type = info.PropertyType;
			propertyType = SerializedPropertyType.Generic;
			if (type == typeof(int))
				propertyType = SerializedPropertyType.Integer;
			else if (type == typeof(float))
				propertyType = SerializedPropertyType.Float;
			else if (type == typeof(bool))
				propertyType = SerializedPropertyType.Boolean;
			else if (type == typeof(string))
				propertyType = SerializedPropertyType.String;
			else if (type == typeof(Vector2))
				propertyType = SerializedPropertyType.Vector2;
			else if (type == typeof(Vector3))
				propertyType = SerializedPropertyType.Vector3;
			else if (type.IsEnum)
				propertyType = SerializedPropertyType.Enum;
			else if (type == typeof(Color))
				propertyType = SerializedPropertyType.Color;
			return propertyType != SerializedPropertyType.Generic;
		}
Ejemplo n.º 45
0
    void MySetValue(Object c, object value, string prName, SerializedPropertyType type)
    {
        var array = Selection.gameObjects.Select(a => a.GetComponent(c.GetType())).Cast<Object>().Union(Selection.objects.Where(a => !(a is GameObject)));
        if (c is Material)
        {
            var d = Selection.gameObjects.Select(a => a.renderer).SelectMany(a => a.sharedMaterials).Distinct();
            array = array.Union(d.Cast<Object>());
        }

        foreach (var nc in array) //компоненты gameobjectов и выбраные Objectы
        {
            if (nc != null && nc != c)
            {
                SerializedObject so = new SerializedObject(nc);
                var pr = so.FindProperty(prName);
                switch (type)
                {
                    case SerializedPropertyType.Float:
                        pr.floatValue = (float)value;
                        break;
                    case SerializedPropertyType.Boolean:
                        pr.boolValue = (bool)value;
                        break;
                    case SerializedPropertyType.String:
                        pr.stringValue = (string)value;
                        break;
                    case SerializedPropertyType.Integer:
                        pr.intValue = (int)value;
                        break;
                    case SerializedPropertyType.Color:
                        pr.colorValue = (Color)value;
                        break;
                    case SerializedPropertyType.Enum:
                        pr.enumValueIndex = (int)value;
                        break;
                }

                so.ApplyModifiedProperties();
            }
        }
    }
Ejemplo n.º 46
0
    public static bool GetPropertyType(PropertyInfo info, out SerializedPropertyType propertyType)
    {
        propertyType = SerializedPropertyType.Generic;

        Type type = info.PropertyType;

        if (type == typeof(int))
        {
            propertyType = SerializedPropertyType.Integer;
            return true;
        }

        if (type == typeof(float))
        {
            propertyType = SerializedPropertyType.Float;
            return true;
        }

        if (type == typeof(bool))
        {
            propertyType = SerializedPropertyType.Boolean;
            return true;
        }

        if (type == typeof(string))
        {
            propertyType = SerializedPropertyType.String;
            return true;
        }

        if (type == typeof(Vector2))
        {
            propertyType = SerializedPropertyType.Vector2;
            return true;
        }

        if (type == typeof(Vector3))
        {
            propertyType = SerializedPropertyType.Vector3;
            return true;
        }

        if (type.IsEnum)
        {
            propertyType = SerializedPropertyType.Enum;
            return true;
        }

        return false;
    }
		public PropertyField(object obj, PropertyInfo info, SerializedPropertyType type)
		{
			this.obj = obj;
			this.info = info;
			this.type = type;
			
			getter = this.info.GetGetMethod();
			setter = this.info.GetSetMethod();
		}
Ejemplo n.º 48
0
        /// <summary>
        ///   Returns the property type and the conversion functions to use when showing the value in the inspector and when
        ///   the value is written back to the property.
        /// </summary>
        /// <param name="info"> Property info. </param>
        /// <param name="propertyType"> Defines which inspector control to use to show the value. </param>
        /// <param name="getConversionFunc"> Conversion function when getting the value to show in the inspector. </param>
        /// <param name="setConversionFunc"> Conversion function when writing the value from the inspector back to the property. </param>
        /// <returns> True if the property contains a value which can be visualized in the inspector; otherwise, false. </returns>
        public static bool GetPropertyType(
            PropertyInfo info,
            out SerializedPropertyType propertyType,
            out Func<object, object> getConversionFunc,
            out Func<object, object> setConversionFunc)
        {
            propertyType = SerializedPropertyType.Generic;
            getConversionFunc = null;
            setConversionFunc = null;

            Type type = info.PropertyType;

            if (type == typeof(int))
            {
                propertyType = SerializedPropertyType.Integer;
                return true;
            }

            if (type == typeof(float))
            {
                propertyType = SerializedPropertyType.Float;
                return true;
            }

            if (type == typeof(bool))
            {
                propertyType = SerializedPropertyType.Boolean;
                return true;
            }

            if (type == typeof(string))
            {
                propertyType = SerializedPropertyType.String;
                return true;
            }

            if (type == typeof(Vector2))
            {
                propertyType = SerializedPropertyType.Vector2;
                return true;
            }

            if (type == typeof(Vector3))
            {
                propertyType = SerializedPropertyType.Vector3;
                return true;
            }

            if (type == typeof(Rect))
            {
                propertyType = SerializedPropertyType.Rect;
                return true;
            }

            if (type == typeof(RectangleI))
            {
                propertyType = SerializedPropertyType.Rect;
                getConversionFunc = o => ((RectangleI)o).ToRect();
                setConversionFunc = o => ((Rect)o).ToRectangleI();
                return true;
            }

            if (type == typeof(RectangleF))
            {
                propertyType = SerializedPropertyType.Rect;
                getConversionFunc = o => ((RectangleF)o).ToRect();
                setConversionFunc = o => ((Rect)o).ToRectangleF();
                return true;
            }

            if (type.IsEnum)
            {
                propertyType = SerializedPropertyType.Enum;
                return true;
            }

            return false;
        }