Exemple #1
0
        private static void BitCountfrom1(ref Vector2PackSettings settings, CustomAttributeArgument arg)
        {
            int bitCount = (int)arg.Value;

            ValidateBitCount(bitCount, (s) => new Vector2PackException(s));
            settings.bitCount = new Vector2Int(bitCount, bitCount);
        }
Exemple #2
0
 private static void BitCountFrom2(ref Vector2PackSettings settings, CustomAttributeArgument xArg, CustomAttributeArgument yArg)
 {
     // check vs all 3 axis
     ValidateBitCount((int)xArg.Value, (s) => new Vector2PackException(s));
     ValidateBitCount((int)yArg.Value, (s) => new Vector2PackException(s));
     settings.bitCount = new Vector2Int(
         (int)xArg.Value,
         (int)yArg.Value);
 }
Exemple #3
0
        private static void Precisionfrom1(ref Vector2PackSettings settings, CustomAttributeArgument arg)
        {
            // check vs all 3 axis
            float precision = (float)arg.Value;

            ValidatePrecision(settings.max.x, precision, (s) => new Vector2PackException(s));
            ValidatePrecision(settings.max.y, precision, (s) => new Vector2PackException(s));
            settings.precision = new Vector2(precision, precision);
        }
Exemple #4
0
        private static void PrecisionFrom2(ref Vector2PackSettings settings, CustomAttributeArgument xArg, CustomAttributeArgument yArg)
        {
            // check vs all 3 axis
            var precision = new Vector2(
                (float)xArg.Value,
                (float)yArg.Value);

            ValidatePrecision(settings.max.x, precision.x, (s) => new Vector2PackException(s));
            ValidatePrecision(settings.max.y, precision.y, (s) => new Vector2PackException(s));
            settings.precision = precision;
        }
Exemple #5
0
        protected override Vector2PackSettings GetSettings(TypeReference fieldType, CustomAttribute attribute)
        {
            if (!fieldType.Is <Vector2>())
            {
                throw new Vector2PackException($"{fieldType} is not a supported type for [Vector2Pack]");
            }

            var settings = new Vector2PackSettings();

            for (int i = 0; i < 2; i++)
            {
                settings.max[i] = (float)attribute.ConstructorArguments[i].Value;
                if (settings.max[i] <= 0)
                {
                    throw new Vector2PackException($"Max must be above 0, max:{settings.max}");
                }
            }

            if (attribute.ConstructorArguments.Count == 3)
            {
                CustomAttributeArgument arg = attribute.ConstructorArguments[2];
                if (arg.Type.Is <float>())
                {
                    Precisionfrom1(ref settings, arg);
                }
                else
                {
                    BitCountfrom1(ref settings, arg);
                }
            }
            else
            {
                CustomAttributeArgument xArg = attribute.ConstructorArguments[2];
                CustomAttributeArgument yArg = attribute.ConstructorArguments[3];
                if (xArg.Type.Is <float>())
                {
                    PrecisionFrom2(ref settings, xArg, yArg);
                }
                else
                {
                    BitCountFrom2(ref settings, xArg, yArg);
                }
            }

            return(settings);
        }