Exemplo n.º 1
0
        public static void Recalculate(int min, int max, LiteIntCrusher crusher)
        {
            int range;

            if (min < max)
            {
                crusher.smallest = min;
                crusher.biggest  = max;
            }
            else
            {
                crusher.smallest = max;
                crusher.biggest  = min;
            }

            range        = crusher.biggest - crusher.smallest;
            crusher.bits = GetBitsForMaxValue((uint)range);
        }
Exemplo n.º 2
0
        public override void OnGUI(Rect r, SerializedProperty property, GUIContent label)
        {
            SerializedProperty compType = property.FindPropertyRelative("compressType");
            SerializedProperty min      = property.FindPropertyRelative("min");
            SerializedProperty max      = property.FindPropertyRelative("max");

            float compTypeWidth = 100;
            float stretchleft   = r.xMin + compTypeWidth;
            float mLabelWidth   = 26;

            Rect rectBits = new Rect(r)
            {
                xMax = stretchleft
            };

            Rect rectStretch = new Rect(r)
            {
                xMin = stretchleft, xMax = r.xMax
            };
            Rect rectMin = new Rect(rectStretch)
            {
                width = rectStretch.width * .5f
            };
            Rect rectMax = new Rect(rectStretch)
            {
                xMin = rectStretch.xMin + rectStretch.width * .5f
            };

            EditorGUI.BeginChangeCheck();
            EditorGUI.PropertyField(rectBits, compType, GUIContent.none);
            if (compType.intValue == (int)LiteIntCompressType.Range)
            {
                EditorGUI.LabelField(new Rect(rectMin)
                {
                    width = mLabelWidth
                }, "min", new GUIStyle("MiniLabel")
                {
                    alignment = TextAnchor.UpperRight
                });
                EditorGUI.PropertyField(new Rect(rectMin)
                {
                    xMin = rectMin.xMin + mLabelWidth
                }, min, GUIContent.none);
                EditorGUI.LabelField(new Rect(rectMax)
                {
                    width = mLabelWidth
                }, "max", new GUIStyle("MiniLabel")
                {
                    alignment = TextAnchor.UpperRight
                });
                EditorGUI.PropertyField(new Rect(rectMax)
                {
                    xMin = rectMax.xMin + mLabelWidth
                }, max, GUIContent.none);
            }

            if (EditorGUI.EndChangeCheck())
            {
                SerializedProperty smallest = property.FindPropertyRelative("smallest");
                SerializedProperty biggest  = property.FindPropertyRelative("biggest");
                SerializedProperty bits     = property.FindPropertyRelative("bits");

                /// We only modify compressor values if we are using range. Other settings use a hard coded 32 bits.
                if (compType.intValue == (int)LiteIntCompressType.Range)
                {
                    int _smallest = 0, _biggest = 0, _bits = 0;
                    LiteIntCrusher.Recalculate(min.intValue, max.intValue, ref _smallest, ref _biggest, ref _bits);
                    smallest.intValue = _smallest;
                    biggest.intValue  = _biggest;
                    bits.intValue     = _bits;
                }

                property.serializedObject.ApplyModifiedProperties();
            }
        }