private static void BitCountfrom1(ref Vector3PackSettings settings, CustomAttributeArgument arg) { // check vs all 3 axis int bitCount = (int)arg.Value; ValidateBitCount(bitCount, (s) => new Vector3PackException(s)); settings.bitCount = new Vector3Int(bitCount, bitCount, bitCount); }
private static void Precisionfrom1(ref Vector3PackSettings settings, CustomAttributeArgument arg) { // check vs all 3 axis float precision = (float)arg.Value; ValidatePrecision(settings.max.x, precision, (s) => new Vector3PackException(s)); ValidatePrecision(settings.max.y, precision, (s) => new Vector3PackException(s)); ValidatePrecision(settings.max.z, precision, (s) => new Vector3PackException(s)); settings.precision = new Vector3(precision, precision, precision); }
private static void BitCountFrom3(ref Vector3PackSettings settings, CustomAttributeArgument xArg, CustomAttributeArgument yArg, CustomAttributeArgument zArg) { // check vs all 3 axis ValidateBitCount((int)xArg.Value, (s) => new Vector3PackException(s)); ValidateBitCount((int)yArg.Value, (s) => new Vector3PackException(s)); ValidateBitCount((int)zArg.Value, (s) => new Vector3PackException(s)); settings.bitCount = new Vector3Int( (int)xArg.Value, (int)yArg.Value, (int)zArg.Value); }
private static void PrecisionFrom3(ref Vector3PackSettings settings, CustomAttributeArgument xArg, CustomAttributeArgument yArg, CustomAttributeArgument zArg) { // check vs all 3 axis var precision = new Vector3( (float)xArg.Value, (float)yArg.Value, (float)zArg.Value); ValidatePrecision(settings.max.x, precision.x, (s) => new Vector3PackException(s)); ValidatePrecision(settings.max.y, precision.y, (s) => new Vector3PackException(s)); ValidatePrecision(settings.max.z, precision.z, (s) => new Vector3PackException(s)); settings.precision = precision; }
protected override Vector3PackSettings GetSettings(TypeReference fieldType, CustomAttribute attribute) { if (!fieldType.Is <Vector3>()) { throw new Vector3PackException($"{fieldType} is not a supported type for [Vector3Pack]"); } var settings = new Vector3PackSettings(); for (int i = 0; i < 3; i++) { settings.max[i] = (float)attribute.ConstructorArguments[i].Value; if (settings.max[i] <= 0) { throw new Vector3PackException($"Max must be above 0, max:{settings.max}"); } } if (attribute.ConstructorArguments.Count == 4) { CustomAttributeArgument arg = attribute.ConstructorArguments[3]; if (arg.Type.Is <float>()) { Precisionfrom1(ref settings, arg); } else { BitCountfrom1(ref settings, arg); } } else { CustomAttributeArgument xArg = attribute.ConstructorArguments[3]; CustomAttributeArgument yArg = attribute.ConstructorArguments[4]; CustomAttributeArgument zArg = attribute.ConstructorArguments[5]; if (xArg.Type.Is <float>()) { PrecisionFrom3(ref settings, xArg, yArg, zArg); } else { BitCountFrom3(ref settings, xArg, yArg, zArg); } } return(settings); }