Esempio n. 1
0
        internal static void CreateCustomVectorField(Rect position, SerializedProperty property, GUIContent label, PropertyAttribute attribute)
        {
            CustomVector4StackedAttribute customVector = (CustomVector4StackedAttribute)attribute;

            label = CustomVectorUtils.GetLabel(label, customVector.label);

            if (property.propertyType == SerializedPropertyType.Vector4)
            {
                property.vector4Value = EditorGUI.Vector4Field(position, label, property.vector4Value,
                                                               customVector.xLabel, customVector.yLabel, customVector.zLabel, customVector.wLabel, customVector.expandWidth, true);
            }
            else
            {
                CustomVectorUtils.ErrorMessage(position, label, customVector, "Vector4");
            }
        }
Esempio n. 2
0
        internal static void CreateCustomVectorField(Rect position, SerializedProperty property, GUIContent label, PropertyAttribute attribute)
        {
            CustomVector2Attribute customVector = (CustomVector2Attribute)attribute;

            label = CustomVectorUtils.GetLabel(label, customVector.label);

            if (property.propertyType == SerializedPropertyType.Vector2)
            {
                property.vector2Value = EditorGUI.Vector2Field(position, label, property.vector2Value,
                                                               customVector.xLabel, customVector.yLabel, customVector.expandWidth);
            }
            else if (property.propertyType == SerializedPropertyType.Vector2Int)
            {
                property.vector2IntValue = EditorGUI.Vector2IntField(position, label, property.vector2IntValue,
                                                                     customVector.xLabel, customVector.yLabel, customVector.expandWidth);
            }
            else
            {
                CustomVectorUtils.ErrorMessage(position, label, customVector, "Vector2 or Vector2Int");
            }
        }
Esempio n. 3
0
        internal static void CreateCustomVectorField(Rect position, SerializedProperty property, GUIContent label, PropertyAttribute attribute)
        {
            CustomVector3Attribute customVector = (CustomVector3Attribute)attribute;

            if (customVector != null)
            {
                label = CustomVectorUtils.GetLabel(label, customVector.label);
            }

            if (property.propertyType == SerializedPropertyType.Vector3)
            {
                property.vector3Value = EditorGUI.Vector3Field(position, label, property.vector3Value,
                                                               customVector.xLabel, customVector.yLabel, customVector.zLabel);
            }
            else if (property.propertyType == SerializedPropertyType.Vector3Int)
            {
                property.vector3IntValue = EditorGUI.Vector3IntField(position, label, property.vector3IntValue,
                                                                     customVector.xLabel, customVector.yLabel, customVector.zLabel);
            }
            else
            {
                CustomVectorUtils.ErrorMessage(position, label, customVector, "Vector3 or Vector3Int");
            }
        }
Esempio n. 4
0
        internal static void CreateCustomVectorField(Rect position, SerializedProperty property, GUIContent label, PropertyAttribute attribute)
        {
            CustomVector4Attribute customVector = (CustomVector4Attribute)attribute;

            label = CustomVectorUtils.GetLabel(label, customVector.label);

            if (property.propertyType == SerializedPropertyType.Vector4)
            {
                string  foldoutLabel = label.text;
                Vector4 v4Value      = property.vector4Value;

                float fieldHeight         = EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
                int   rows                = EditorGUIUtility.wideMode ? 1 : 2;
                float foldoutFieldsHeight = EditorGUIUnity.GetPropertyHeight(property) - (fieldHeight * rows);

                Rect foldoutPos = position;
                foldoutPos.y -= foldoutFieldsHeight / 2;

                property.isExpanded = EditorGUIUnity.Foldout(foldoutPos, property.isExpanded, foldoutLabel);

                if (property.isExpanded)
                {
                    GUIContent[] subLabels = new GUIContent[]
                    {
                        EditorGUIUtility.TrTextContent(customVector.xLabel),
                        EditorGUIUtility.TrTextContent(customVector.yLabel),
                        EditorGUIUtility.TrTextContent(customVector.zLabel),
                        EditorGUIUtility.TrTextContent(customVector.wLabel)
                    };

                    float[] values = new float[]
                    {
                        v4Value.x,
                        v4Value.y,
                        v4Value.z,
                        v4Value.w
                    };

                    float spacing = EditorGUIUtility.wideMode ? 0 : EditorGUIUtility.singleLineHeight + 1;
                    position.y     += EditorGUIUtility.standardVerticalSpacing + spacing;
                    position.height = EditorGUIUtility.singleLineHeight;

                    using (var check = new EditorGUIUnity.ChangeCheckScope())
                    {
                        float oldLabelWidth  = EditorGUIUtility.labelWidth;
                        int   oldIndentLevel = EditorGUIUnity.indentLevel;
                        EditorGUIUnity.indentLevel = 1;

                        for (int i = 0; i < values.Length; i++)
                        {
                            position.y += fieldHeight;
                            values[i]   = EditorGUIUnity.FloatField(position, subLabels[i], values[i]);
                        }

                        EditorGUIUtility.labelWidth = oldLabelWidth;
                        EditorGUIUnity.indentLevel  = oldIndentLevel;

                        if (check.changed)
                        {
                            v4Value.x = values[0];
                            v4Value.y = values[1];
                            v4Value.z = values[2];
                            v4Value.w = values[3];
                        }
                    }
                }

                property.vector4Value = v4Value;
            }
            else
            {
                CustomVectorUtils.ErrorMessage(position, label, customVector, "Vector4");
            }
        }