Esempio n. 1
0
        public override void Draw(InspectorField field, GUIStyle style)
        {
            Type type = field.BaseType;

            float width = EditorGUIUtility.labelWidth;

            EditorGUIUtility.labelWidth = VECTOR_FIELD_WIDTH;

            GUILayout.BeginHorizontal();
            if (type == typeof(Vector2))
            {
                Vector2[] values = field.GetValues <Vector2>();

                float[] x = new float[values.Length];
                float[] y = new float[values.Length];

                for (int i = 0; i < values.Length; i++)
                {
                    x[i] = values[i].x;
                    y[i] = values[i].y;
                }

                float result;
                if (FloatEditor.DrawFloat("X", x, style, out result))
                {
                    Undo.RecordObjects(field.SerializedInstances, "Edit " + field.Name + " X");

                    for (int i = 0; i < field.Instances.Length; i++)
                    {
                        values[i].x = result;
                        field.SetValue(field.Instances[i], values[i]);
                    }
                }

                if (FloatEditor.DrawFloat("Y", y, style, out result))
                {
                    Undo.RecordObjects(field.SerializedInstances, "Edit " + field.Name + " Y");

                    for (int i = 0; i < field.Instances.Length; i++)
                    {
                        values[i].y = result;
                        field.SetValue(field.Instances[i], values[i]);
                    }
                }
            }
            else if (type == typeof(Vector3))
            {
                Vector3[] values = field.GetValues <Vector3>();

                float[] x = new float[values.Length];
                float[] y = new float[values.Length];
                float[] z = new float[values.Length];

                for (int i = 0; i < values.Length; i++)
                {
                    x[i] = values[i].x;
                    y[i] = values[i].y;
                    z[i] = values[i].z;
                }

                float result;
                if (FloatEditor.DrawFloat("X", x, style, out result))
                {
                    Undo.RecordObjects(field.SerializedInstances, "Edit " + field.Name + " X");

                    for (int i = 0; i < field.Instances.Length; i++)
                    {
                        values[i].x = result;
                        field.SetValue(field.Instances[i], values[i]);
                    }
                }

                if (FloatEditor.DrawFloat("Y", y, style, out result))
                {
                    Undo.RecordObjects(field.SerializedInstances, "Edit " + field.Name + " Y");

                    for (int i = 0; i < field.Instances.Length; i++)
                    {
                        values[i].y = result;
                        field.SetValue(field.Instances[i], values[i]);
                    }
                }

                if (FloatEditor.DrawFloat("Z", z, style, out result))
                {
                    Undo.RecordObjects(field.SerializedInstances, "Edit " + field.Name + " Z");

                    for (int i = 0; i < field.Instances.Length; i++)
                    {
                        values[i].z = result;
                        field.SetValue(field.Instances[i], values[i]);
                    }
                }
            }
            else if (type == typeof(Vector4))
            {
                Vector4[] values = field.GetValues <Vector4>();

                float[] x = new float[values.Length];
                float[] y = new float[values.Length];
                float[] z = new float[values.Length];
                float[] w = new float[values.Length];

                for (int i = 0; i < values.Length; i++)
                {
                    x[i] = values[i].x;
                    y[i] = values[i].y;
                    z[i] = values[i].z;
                    w[i] = values[i].w;
                }

                float result;
                if (FloatEditor.DrawFloat("X", x, style, out result))
                {
                    Undo.RecordObjects(field.SerializedInstances, "Edit " + field.Name + " X");

                    for (int i = 0; i < field.Instances.Length; i++)
                    {
                        values[i].x = result;
                        field.SetValue(field.Instances[i], values[i]);
                    }
                }

                if (FloatEditor.DrawFloat("Y", y, style, out result))
                {
                    Undo.RecordObjects(field.SerializedInstances, "Edit " + field.Name + " Y");

                    for (int i = 0; i < field.Instances.Length; i++)
                    {
                        values[i].y = result;
                        field.SetValue(field.Instances[i], values[i]);
                    }
                }

                if (FloatEditor.DrawFloat("Z", z, style, out result))
                {
                    Undo.RecordObjects(field.SerializedInstances, "Edit " + field.Name + " Z");

                    for (int i = 0; i < field.Instances.Length; i++)
                    {
                        values[i].z = result;
                        field.SetValue(field.Instances[i], values[i]);
                    }
                }

                if (FloatEditor.DrawFloat("W", w, style, out result))
                {
                    Undo.RecordObjects(field.SerializedInstances, "Edit " + field.Name + " W");

                    for (int i = 0; i < field.Instances.Length; i++)
                    {
                        values[i].w = result;
                        field.SetValue(field.Instances[i], values[i]);
                    }
                }
            }
            GUILayout.EndHorizontal();

            EditorGUIUtility.labelWidth = width;
        }
Esempio n. 2
0
        public override void Draw(InspectorField field, GUIStyle style)
        {
            Type type = field.BaseType;

            float labelWidth = EditorGUIUtility.labelWidth;

            EditorGUIUtility.labelWidth = VECTOR_FIELD_WIDTH;

            if (type == typeof(Rect))
            {
                Rect[] values = field.GetValues <Rect>();

                float[] x      = new float[values.Length];
                float[] y      = new float[values.Length];
                float[] height = new float[values.Length];
                float[] width  = new float[values.Length];

                for (int i = 0; i < values.Length; i++)
                {
                    x[i]      = values[i].x;
                    y[i]      = values[i].y;
                    height[i] = values[i].height;
                    width[i]  = values[i].width;
                }

                GUILayout.BeginHorizontal();
                float result;
                if (FloatEditor.DrawFloat("X", x, style, out result))
                {
                    Undo.RecordObjects(field.SerializedInstances, "Edit " + field.Name + " X");

                    for (int i = 0; i < field.Instances.Length; i++)
                    {
                        values[i].x = result;
                        field.SetValue(field.Instances[i], values[i]);
                    }
                }

                if (FloatEditor.DrawFloat("Y", y, style, out result))
                {
                    Undo.RecordObjects(field.SerializedInstances, "Edit " + field.Name + " Y");

                    for (int i = 0; i < field.Instances.Length; i++)
                    {
                        values[i].y = result;
                        field.SetValue(field.Instances[i], values[i]);
                    }
                }
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                if (FloatEditor.DrawFloat("W", width, style, out result))
                {
                    Undo.RecordObjects(field.SerializedInstances, "Edit " + field.Name + " Width");

                    for (int i = 0; i < field.Instances.Length; i++)
                    {
                        values[i].width = result;
                        field.SetValue(field.Instances[i], values[i]);
                    }
                }

                if (FloatEditor.DrawFloat("H", height, style, out result))
                {
                    Undo.RecordObjects(field.SerializedInstances, "Edit " + field.Name + " Height");

                    for (int i = 0; i < field.Instances.Length; i++)
                    {
                        values[i].height = result;
                        field.SetValue(field.Instances[i], values[i]);
                    }
                }
                GUILayout.EndHorizontal();
            }
            else if (type == typeof(RectOffset))
            {
                RectOffset[] values = field.GetValues <RectOffset>();

                int[] left   = new int[values.Length];
                int[] right  = new int[values.Length];
                int[] top    = new int[values.Length];
                int[] bottom = new int[values.Length];

                for (int i = 0; i < values.Length; i++)
                {
                    left[i]   = values[i].left;
                    right[i]  = values[i].right;
                    top[i]    = values[i].top;
                    bottom[i] = values[i].bottom;
                }

                GUILayout.BeginHorizontal();
                int result;
                if (IntegerEditor.DrawInt("L", left, style, out result))
                {
                    Undo.RecordObjects(field.SerializedInstances, "Edit " + field.Name + " Left");

                    for (int i = 0; i < field.Instances.Length; i++)
                    {
                        values[i].left = result;
                        field.SetValue(field.Instances[i], values[i]);
                    }
                }

                if (IntegerEditor.DrawInt("R", right, style, out result))
                {
                    Undo.RecordObjects(field.SerializedInstances, "Edit " + field.Name + " Right");

                    for (int i = 0; i < field.Instances.Length; i++)
                    {
                        values[i].right = result;
                        field.SetValue(field.Instances[i], values[i]);
                    }
                }
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                if (IntegerEditor.DrawInt("T", top, style, out result))
                {
                    Undo.RecordObjects(field.SerializedInstances, "Edit " + field.Name + " Top");

                    for (int i = 0; i < field.Instances.Length; i++)
                    {
                        values[i].top = result;
                        field.SetValue(field.Instances[i], values[i]);
                    }
                }

                if (IntegerEditor.DrawInt("B", bottom, style, out result))
                {
                    Undo.RecordObjects(field.SerializedInstances, "Edit " + field.Name + " Bottom");

                    for (int i = 0; i < field.Instances.Length; i++)
                    {
                        values[i].bottom = result;
                        field.SetValue(field.Instances[i], values[i]);
                    }
                }
                GUILayout.EndHorizontal();
            }

            EditorGUILayout.Space();

            EditorGUIUtility.labelWidth = labelWidth;
        }
        public override void Draw(InspectorField field, GUIStyle style)
        {
            float labelWidth = EditorGUIUtility.labelWidth;

            EditorGUIUtility.labelWidth = VECTOR_FIELD_WIDTH;

            Bounds[] values = field.GetValues <Bounds>();

            float[] centerX = new float[values.Length];
            float[] centerY = new float[values.Length];
            float[] centerZ = new float[values.Length];
            float[] extendX = new float[values.Length];
            float[] extendY = new float[values.Length];
            float[] extendZ = new float[values.Length];

            for (int i = 0; i < values.Length; i++)
            {
                centerX[i] = values[i].center.x;
                centerY[i] = values[i].center.y;
                centerZ[i] = values[i].center.z;
                extendX[i] = values[i].extents.x;
                extendY[i] = values[i].extents.y;
                extendZ[i] = values[i].extents.z;
            }

            GUILayout.BeginHorizontal();
            float result;

            EditorGUILayout.LabelField("Center: ", GUILayout.Width(48));
            if (FloatEditor.DrawFloat("X", centerX, style, out result))
            {
                field.RecordObjects("Edit " + field.Name + " Center X");

                for (int i = 0; i < field.Instances.Length; i++)
                {
                    Vector3 center = values[i].center;
                    center.x         = result;
                    values[i].center = center;
                    field.SetValue(field.Instances[i], values[i]);
                }
            }

            if (FloatEditor.DrawFloat("Y", centerY, style, out result))
            {
                field.RecordObjects("Edit " + field.Name + " Center Y");

                for (int i = 0; i < field.Instances.Length; i++)
                {
                    Vector3 center = values[i].center;
                    center.y         = result;
                    values[i].center = center;
                    field.SetValue(field.Instances[i], values[i]);
                }
            }

            if (FloatEditor.DrawFloat("Z", centerZ, style, out result))
            {
                field.RecordObjects("Edit " + field.Name + " Center Z");

                for (int i = 0; i < field.Instances.Length; i++)
                {
                    Vector3 center = values[i].center;
                    center.z         = result;
                    values[i].center = center;
                    field.SetValue(field.Instances[i], values[i]);
                }
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Extend: ", GUILayout.Width(48));
            if (FloatEditor.DrawFloat("X", extendX, style, out result))
            {
                field.RecordObjects("Edit " + field.Name + " Extend X");

                for (int i = 0; i < field.Instances.Length; i++)
                {
                    Vector3 extents = values[i].extents;
                    extents.x         = result;
                    values[i].extents = extents;
                    field.SetValue(field.Instances[i], values[i]);
                }
            }

            if (FloatEditor.DrawFloat("Y", extendY, style, out result))
            {
                field.RecordObjects("Edit " + field.Name + " Extend Y");

                for (int i = 0; i < field.Instances.Length; i++)
                {
                    Vector3 extents = values[i].extents;
                    extents.y         = result;
                    values[i].extents = extents;
                    field.SetValue(field.Instances[i], values[i]);
                }
            }

            if (FloatEditor.DrawFloat("Z", extendZ, style, out result))
            {
                field.RecordObjects("Edit " + field.Name + " Extend Z");

                for (int i = 0; i < field.Instances.Length; i++)
                {
                    Vector3 extents = values[i].extents;
                    extents.z         = result;
                    values[i].extents = extents;
                    field.SetValue(field.Instances[i], values[i]);
                }
            }
            GUILayout.EndHorizontal();

            EditorGUILayout.Space();

            EditorGUIUtility.labelWidth = labelWidth;
        }