コード例 #1
0
        public override void OnGUI(Rect r, SerializedProperty property, GUIContent label)
        {
            SerializedProperty compressType = property.FindPropertyRelative("compressType");
            SerializedProperty min          = property.FindPropertyRelative("min");
            SerializedProperty max          = property.FindPropertyRelative("max");
            SerializedProperty ac           = property.FindPropertyRelative("accurateCenter");

            float bitsWidth           = 60;
            float accCenterLeft       = 52;
            float accCenterCheckWidth = 14;
            float stretchleft         = r.xMin + bitsWidth;
            float mLabelWidth         = 26;

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

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

            Rect racl = new Rect(r)
            {
                xMin = r.xMax - accCenterLeft, width = accCenterLeft - accCenterCheckWidth
            };
            Rect racc = new Rect(r)
            {
                xMin = r.xMax - accCenterCheckWidth
            };

            EditorGUI.BeginChangeCheck();
            EditorGUI.PropertyField(rectBits, compressType, GUIContent.none);
            if (compressType.intValue != (int)LiteFloatCompressType.Half16 && compressType.intValue != (int)LiteFloatCompressType.Full32)
            {
                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);

                EditorGUI.LabelField(racl, accCenterLabel, new GUIStyle("MiniLabel")
                {
                    alignment = TextAnchor.UpperRight
                });
                ac.boolValue = EditorGUI.Toggle(racc, GUIContent.none, ac.boolValue, (GUIStyle)"OL Toggle");
            }

            if (EditorGUI.EndChangeCheck())
            {
                SerializedProperty encoder = property.FindPropertyRelative("encoder");
                SerializedProperty decoder = property.FindPropertyRelative("decoder");
                SerializedProperty maxCVal = property.FindPropertyRelative("maxCVal");
                SerializedProperty bits    = property.FindPropertyRelative("bits");

                float _encoder = 0, _decoder = 0;
                int   _bits    = 0;
                ulong _maxCVal = 0;
                LiteFloatCrusher.Recalculate((LiteFloatCompressType)compressType.intValue, min.floatValue, max.floatValue, ac.boolValue, ref _bits, ref _encoder, ref _decoder, ref _maxCVal);

                encoder.floatValue = _encoder;
                decoder.floatValue = _decoder;
                bits.intValue      = _bits;
                maxCVal.longValue  = (long)_maxCVal;

                property.serializedObject.ApplyModifiedProperties();
            }
        }
コード例 #2
0
        public static void Recalculate(LiteFloatCompressType compressType, float min, float max, bool accurateCenter, LiteFloatCrusher crusher)
        {
            int bits = (int)compressType;

            crusher.bits = bits;

            float range   = max - min;
            ulong maxcval = (bits == 64) ? ulong.MaxValue : (((ulong)1 << (int)bits) - 1);

            if (accurateCenter && maxcval != 0)
            {
                maxcval--;
            }

            crusher.encoder = range == 0 ? 0 : maxcval / range;
            crusher.decoder = maxcval == 0 ? 0 : range / maxcval;

            crusher.maxCVal = maxcval;
        }