Exemple #1
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))
                {
                    field.RecordObjects("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))
                {
                    field.RecordObjects("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))
                {
                    field.RecordObjects("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))
                {
                    field.RecordObjects("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))
                {
                    field.RecordObjects("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))
                {
                    field.RecordObjects("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))
                {
                    field.RecordObjects("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))
                {
                    field.RecordObjects("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;
        }
Exemple #2
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(Vector2Int))
            {
                Vector2Int[] values = field.GetValues <Vector2Int>();

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

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

                int result;
                if (IntegerEditor.DrawInt("X", x, style, out result))
                {
                    field.RecordObjects("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 (IntegerEditor.DrawInt("Y", y, style, out result))
                {
                    field.RecordObjects("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(Vector3Int))
            {
                Vector3Int[] values = field.GetValues <Vector3Int>();

                int[] x = new int[values.Length];
                int[] y = new int[values.Length];
                int[] z = new int[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;
                }

                int result;
                if (IntegerEditor.DrawInt("X", x, style, out result))
                {
                    field.RecordObjects("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 (IntegerEditor.DrawInt("Y", y, style, out result))
                {
                    field.RecordObjects("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 (IntegerEditor.DrawInt("Z", z, style, out result))
                {
                    field.RecordObjects("Edit " + field.Name + " Z");

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

            GUILayout.EndHorizontal();

            EditorGUIUtility.labelWidth = width;
        }
Exemple #3
0
        public override void Draw(InspectorField field, GUIStyle style)
        {
            int[] days  = new int[field.Instances.Length];
            int[] hours = new int[field.Instances.Length];
            int[] mins  = new int[field.Instances.Length];
            int[] secs  = new int[field.Instances.Length];
            for (int i = 0; i < field.Instances.Length; i++)
            {
                TimeSpan span = field.GetValue <TimeSpan>(field.Instances[i]);
                days[i]  = span.Days;
                hours[i] = span.Hours;
                mins[i]  = span.Minutes;
                secs[i]  = span.Seconds;
            }

            float labelWidth = EditorGUIUtility.labelWidth;

            EditorGUIUtility.labelWidth = 42;
            GUILayout.BeginHorizontal();

            int result;

            if (IntegerEditor.DrawInt("Days", days, style, out result))
            {
                result = Mathf.Clamp(result, 0, int.MaxValue);
                Undo.RecordObjects(field.SerializedInstances, "Edit " + field.Name + " Days");

                for (int i = 0; i < field.Instances.Length; i++)
                {
                    TimeSpan span = field.GetValue <TimeSpan>(field.Instances[i]);
                    span = new TimeSpan(result, span.Hours, span.Minutes, span.Seconds);
                    field.SetValue(field.Instances[i], span);
                }
            }

            if (IntegerEditor.DrawInt("Hours", hours, style, out result))
            {
                result = Mathf.Clamp(result, 0, int.MaxValue);
                Undo.RecordObjects(field.SerializedInstances, "Edit " + field.Name + " Hours");

                for (int i = 0; i < field.Instances.Length; i++)
                {
                    TimeSpan span = field.GetValue <TimeSpan>(field.Instances[i]);
                    span = new TimeSpan(span.Days, result, span.Minutes, span.Seconds);
                    field.SetValue(field.Instances[i], span);
                }
            }

            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();

            if (IntegerEditor.DrawInt("Mins", mins, style, out result))
            {
                result = Mathf.Clamp(result, 0, int.MaxValue);
                Undo.RecordObjects(field.SerializedInstances, "Edit " + field.Name + " Minutes");

                for (int i = 0; i < field.Instances.Length; i++)
                {
                    TimeSpan span = field.GetValue <TimeSpan>(field.Instances[i]);
                    span = new TimeSpan(span.Days, span.Hours, result, span.Seconds);
                    field.SetValue(field.Instances[i], span);
                }
            }

            if (IntegerEditor.DrawInt("Secs", secs, style, out result))
            {
                result = Mathf.Clamp(result, 0, int.MaxValue);
                Undo.RecordObjects(field.SerializedInstances, "Edit " + field.Name + " Seconds");

                for (int i = 0; i < field.Instances.Length; i++)
                {
                    TimeSpan span = field.GetValue <TimeSpan>(field.Instances[i]);
                    span = new TimeSpan(span.Days, span.Hours, span.Minutes, result);
                    field.SetValue(field.Instances[i], span);
                }
            }

            GUILayout.EndHorizontal();
            EditorGUILayout.Space();

            EditorGUIUtility.labelWidth = labelWidth;
        }
Exemple #4
0
        public override void Draw(InspectorField field, GUIStyle style)
        {
            RangeValueAttribute range = field.GetAttribute <RangeValueAttribute>();

            if (range == null)
            {
                return;
            }

            EditorGUILayout.BeginHorizontal();

            RangeInt[] ranges = field.GetValues <RangeInt>();

            int[] mins      = new int[ranges.Length];
            int[] maxs      = new int[ranges.Length];
            int   min       = ranges[0].min;
            int   max       = ranges[0].max;
            bool  different = false;

            for (int i = 0; i < ranges.Length; i++)
            {
                mins[i] = ranges[i].min;
                maxs[i] = ranges[i].max;
                if (ranges[i].min != min || ranges[0].max != max)
                {
                    different = true;
                }
            }

            if (IntegerEditor.DrawInt("", mins, out min, GUILayout.Width(64)))
            {
                for (int i = 0; i < field.Instances.Length; i++)
                {
                    field.SetValue(field.Instances[i], new RangeInt(min, ranges[i].max));
                }
            }

            EditorGUI.BeginChangeCheck();
            float fMin = min;
            float fMax = max;

            EditorGUI.showMixedValue = different;
            EditorGUILayout.MinMaxSlider(ref fMin, ref fMax, range.Min, range.Max);
            if (EditorGUI.EndChangeCheck() && min < max)
            {
                for (int i = 0; i < field.Instances.Length; i++)
                {
                    field.SetValue(field.Instances[i], new RangeInt((int)fMin, (int)fMax));
                }
            }

            if (IntegerEditor.DrawInt("", maxs, out max, GUILayout.Width(64)))
            {
                for (int i = 0; i < field.Instances.Length; i++)
                {
                    field.SetValue(field.Instances[i], new RangeInt(ranges[i].min, max));
                }
            }

            EditorGUILayout.EndHorizontal();
        }