public FloatCompressor(FloatCompression compression)
            {
                if (compression.Min < compression.Max)
                {
                    _min = compression.Min;
                    _max = compression.Max;

                    _accuracy    = compression.Accuracy;
                    _accuracyInv = 1.0f / _accuracy;

                    _range = (uint)((compression.Max - compression.Min) * (1.0 / _accuracy));

                    _bits = Maths.BitsRequiredForNumber(_range);
                }
                else
                {
                    _min         = 0;
                    _max         = 0;
                    _range       = 0;
                    _accuracy    = 0;
                    _accuracyInv = 0;

                    _bits = 32;
                }
            }
Example #2
0
        static FloatCompression ExitAxis(FloatCompression compression, string label, bool enabled)
        {
            if (enabled)
            {
                EditorGUILayout.BeginHorizontal();
                GUILayout.Label(label, GUILayout.Width(15));
                compression = EditFloatCompression(compression);
                EditorGUILayout.EndHorizontal();
            }

            return(compression);
        }
    PropertyDefinition CreateProperty(PropertyAssetSettings settings)
    {
        PropertyDefinition def = new PropertyDefinition
        {
            Name         = "NewProperty",
            PropertyType = new PropertyTypeFloat {
                Compression = FloatCompression.Default()
            },
            AssetSettings   = settings,
            ReplicationMode = ReplicationMode.Everyone,
        };

        def.Oncreated();
        return(def);
    }
Example #4
0
        public static FloatCompression EditFloatCompression(FloatCompression c)
        {
            if (c == null)
            {
                c = FloatCompression.Default();
            }

            c.Enabled = Toggle(c.Enabled);

            UnityEditor.EditorGUI.BeginDisabledGroup(!c.Enabled);
            c.MinValue = Mathf.Min(IntFieldOverlay(c.MinValue, "Min"), c.MaxValue - 1);
            c.MaxValue = Mathf.Max(IntFieldOverlay(c.MaxValue, "Max"), c.MinValue + 1);
            c.Accuracy = Mathf.Max(FloatFieldOverlay(c.Accuracy, "Accuracy"), 0.001f);
            GUILayout.Label("Bits: " + (c.Enabled ? c.BitsRequired : 32), EditorStyles.miniLabel, GUILayout.Width(50));
            UnityEditor.EditorGUI.EndDisabledGroup();

            return(c);
        }
Example #5
0
        public static void Decompress(string decryptedFileName, string readFileName)
        {
            FileStream stream = File.Open(readFileName, FileMode.Open);

            float[] floats;
            if (FloatCompression.TryUnpack(stream, out floats))
            {
                StringBuilder builder = new StringBuilder();

                foreach (var f in floats)
                {
                    builder.Append(f.ToString());
                    builder.Append(";");
                }

                string[] writeStrings = new[] { builder.ToString() };

                File.WriteAllLines(decryptedFileName, writeStrings);
            }
        }