mirror of
https://github.com/AssetRipper/AssetRipper.Primitives.git
synced 2026-11-13 04:26:30 -10:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b8b8bb94b0 | ||
|
|
9b60458f1d | ||
|
|
b80421fb6c | ||
|
|
ade88858b4 | ||
|
|
79940dc376 | ||
|
|
dddb3f98e1 | ||
|
|
616b101747 | ||
|
|
dba487c1e2 | ||
|
|
c506979787 | ||
|
|
e712430913 | ||
|
|
c48b62e600 | ||
|
|
6caf19db67 | ||
|
|
07c4f74cb3 | ||
|
|
6467eaf99f | ||
|
|
9c5a28da57 |
No files matched your search
@@ -0,0 +1,53 @@
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace AssetRipper.VersionUtilities.Tests
|
||||
{
|
||||
public class ComparisonTests
|
||||
{
|
||||
private static readonly UnityVersion lowValue = new UnityVersion(2017, 3, 0, UnityVersionType.Patch, 1);
|
||||
private static readonly UnityVersion mediumValue = new UnityVersion(2019, 4, 3, UnityVersionType.Final, 1);
|
||||
private static readonly UnityVersion highValue = new UnityVersion(2020, 2, 0, UnityVersionType.Final, 1);
|
||||
|
||||
[Test]
|
||||
public void LessThanIsTransitive()
|
||||
{
|
||||
Assert.IsTrue(lowValue < mediumValue);
|
||||
Assert.IsTrue(mediumValue < highValue);
|
||||
Assert.IsTrue(lowValue < highValue);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GreaterThanIsTransitive()
|
||||
{
|
||||
Assert.IsTrue(mediumValue > lowValue);
|
||||
Assert.IsTrue(highValue > mediumValue);
|
||||
Assert.IsTrue(highValue > lowValue);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WeakInequalityHolds()
|
||||
{
|
||||
UnityVersion low = lowValue;
|
||||
Assert.IsTrue(lowValue <= low);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MinimumValueDefinition()
|
||||
{
|
||||
Assert.IsTrue(UnityVersion.MinVersion == new UnityVersion(ushort.MinValue, ushort.MinValue, ushort.MinValue, UnityVersionType.Alpha, byte.MinValue));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MaximumValueDefinition()
|
||||
{
|
||||
Assert.IsTrue(UnityVersion.MaxVersion == new UnityVersion(ushort.MaxValue, ushort.MaxValue, ushort.MaxValue, (UnityVersionType)byte.MaxValue, byte.MaxValue));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AnIncreaseOfTypeNumberMakesInequal()
|
||||
{
|
||||
Assert.IsTrue(UnityVersion.MinVersion < new UnityVersion(ushort.MinValue, ushort.MinValue, ushort.MinValue, UnityVersionType.Alpha, 1));
|
||||
Assert.IsTrue(lowValue < new UnityVersion(lowValue.Major, lowValue.Minor, lowValue.Build, lowValue.Type, (byte)(lowValue.TypeNumber + 1)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace AssetRipper.VersionUtilities.Tests
|
||||
{
|
||||
public class DistanceTests
|
||||
{
|
||||
private static readonly UnityVersion version3 = new UnityVersion(3, 0, 0, UnityVersionType.Final, 1);
|
||||
private static readonly UnityVersion version4 = new UnityVersion(4, 4, 0, UnityVersionType.Alpha, 1);
|
||||
private static readonly UnityVersion version5 = new UnityVersion(5, 6, 1, UnityVersionType.Final, 11);
|
||||
private static readonly UnityVersion version6 = new UnityVersion(6, 0, 0, UnityVersionType.Final, 1);
|
||||
private static readonly UnityVersion version7 = new UnityVersion(7, 0, 0, UnityVersionType.Final, 1);
|
||||
private static readonly UnityVersion version8 = new UnityVersion(8, 0, 0, UnityVersionType.Final, 1);
|
||||
private static readonly UnityVersion version9 = new UnityVersion(9, 0, 0, UnityVersionType.Final, 1);
|
||||
private static readonly UnityVersion[] versionArray = new UnityVersion[] { version3, version4, version5, version6, version7, version8, version9 };
|
||||
|
||||
[Test]
|
||||
public void DistanceFunctionIsSymmetric()
|
||||
{
|
||||
ulong distance1 = UnityVersion.Distance(version4, version5);
|
||||
ulong distance2 = UnityVersion.Distance(version5, version4);
|
||||
Assert.IsTrue(distance1 == distance2);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DistanceIsZeroForEquivalentVersions()
|
||||
{
|
||||
ulong distance = UnityVersion.Distance(version4, version4);
|
||||
Assert.IsTrue(distance == 0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CorrectlyReturnsVersion6()
|
||||
{
|
||||
UnityVersion version = new UnityVersion(6, 1);
|
||||
UnityVersion closest = version.GetClosestVersion(versionArray);
|
||||
Assert.IsTrue(closest == version6);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CorrectlyReturnsVersion5()
|
||||
{
|
||||
UnityVersion version = new UnityVersion(5, 4, 9);
|
||||
UnityVersion closest = version.GetClosestVersion(versionArray);
|
||||
Assert.IsTrue(closest == version5);
|
||||
}
|
||||
}
|
||||
}
|
||||
File renamed without changes.
@@ -1,26 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace AssetRipper.VersionUtilities
|
||||
{
|
||||
internal static class CharacterExtensions
|
||||
{
|
||||
public static int ParseDigit(this char _this)
|
||||
{
|
||||
return _this - '0';
|
||||
}
|
||||
|
||||
public static UnityVersionType ToUnityVersionType(this char _this)
|
||||
{
|
||||
return _this switch
|
||||
{
|
||||
'a' => UnityVersionType.Alpha,
|
||||
'b' => UnityVersionType.Beta,
|
||||
'c' => UnityVersionType.China,
|
||||
'f' => UnityVersionType.Final,
|
||||
'p' => UnityVersionType.Patch,
|
||||
'x' => UnityVersionType.Experimental,
|
||||
_ => throw new Exception($"Unsupported version type {_this}"),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
|
||||
namespace AssetRipper.VersionUtilities.Extensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Extensions for <see cref="char"/>
|
||||
/// </summary>
|
||||
public static class CharacterExtensions
|
||||
{
|
||||
internal static int ParseDigit(this char _this)
|
||||
{
|
||||
return _this - '0';
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a character into a Unity Version Type
|
||||
/// </summary>
|
||||
/// <param name="c">The character</param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentException">No version type for character</exception>
|
||||
public static UnityVersionType ToUnityVersionType(this char c)
|
||||
{
|
||||
return c switch
|
||||
{
|
||||
'a' => UnityVersionType.Alpha,
|
||||
'b' => UnityVersionType.Beta,
|
||||
'c' => UnityVersionType.China,
|
||||
'f' => UnityVersionType.Final,
|
||||
'p' => UnityVersionType.Patch,
|
||||
'x' => UnityVersionType.Experimental,
|
||||
_ => throw new ArgumentException($"There is no version type {c}", nameof(c)),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
[assembly: InternalsVisibleTo("VersionUtilities.Tests")]
|
||||
@@ -2,68 +2,66 @@
|
||||
{
|
||||
public readonly partial struct UnityVersion
|
||||
{
|
||||
private const ulong subMajorMask = 0x0000FFFFFFFFFFFFUL;
|
||||
private const ulong subMinorMask = 0x00000000FFFFFFFFUL;
|
||||
private const ulong subBuildMask = 0x000000000000FFFFUL;
|
||||
private const ulong subTypeMask = 0x00000000000000FFUL;
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
public bool IsEqual(int major) => this == From(major);
|
||||
public bool IsEqual(int major, int minor) => this == From(major, minor);
|
||||
public bool IsEqual(int major, int minor, int build) => this == From(major, minor, build);
|
||||
public bool IsEqual(int major, int minor, int build, UnityVersionType type) => this == From(major, minor, build, type);
|
||||
public bool IsEqual(int major, int minor, int build, UnityVersionType type, int typeNumber) => this == new UnityVersion(major, minor, build, type, typeNumber);
|
||||
public bool IsEqual(ushort major) => this == From(major);
|
||||
public bool IsEqual(ushort major, ushort minor) => this == From(major, minor);
|
||||
public bool IsEqual(ushort major, ushort minor, ushort build) => this == From(major, minor, build);
|
||||
public bool IsEqual(ushort major, ushort minor, ushort build, UnityVersionType type) => this == From(major, minor, build, type);
|
||||
public bool IsEqual(ushort major, ushort minor, ushort build, UnityVersionType type, byte typeNumber) => this == new UnityVersion(major, minor, build, type, typeNumber);
|
||||
public bool IsEqual(string version) => this == Parse(version);
|
||||
|
||||
public bool IsLess(int major) => this < From(major);
|
||||
public bool IsLess(int major, int minor) => this < From(major, minor);
|
||||
public bool IsLess(int major, int minor, int build) => this < From(major, minor, build);
|
||||
public bool IsLess(int major, int minor, int build, UnityVersionType type) => this < From(major, minor, build, type);
|
||||
public bool IsLess(int major, int minor, int build, UnityVersionType type, int typeNumber) => this < new UnityVersion(major, minor, build, type, typeNumber);
|
||||
public bool IsLess(ushort major) => this < From(major);
|
||||
public bool IsLess(ushort major, ushort minor) => this < From(major, minor);
|
||||
public bool IsLess(ushort major, ushort minor, ushort build) => this < From(major, minor, build);
|
||||
public bool IsLess(ushort major, ushort minor, ushort build, UnityVersionType type) => this < From(major, minor, build, type);
|
||||
public bool IsLess(ushort major, ushort minor, ushort build, UnityVersionType type, byte typeNumber) => this < new UnityVersion(major, minor, build, type, typeNumber);
|
||||
public bool IsLess(string version) => this < Parse(version);
|
||||
|
||||
public bool IsLessEqual(int major) => this <= From(major);
|
||||
public bool IsLessEqual(int major, int minor) => this <= From(major, minor);
|
||||
public bool IsLessEqual(int major, int minor, int build) => this <= From(major, minor, build);
|
||||
public bool IsLessEqual(int major, int minor, int build, UnityVersionType type) => this <= From(major, minor, build, type);
|
||||
public bool IsLessEqual(int major, int minor, int build, UnityVersionType type, int typeNumber) => this <= new UnityVersion(major, minor, build, type, typeNumber);
|
||||
public bool IsLessEqual(ushort major) => this <= From(major);
|
||||
public bool IsLessEqual(ushort major, ushort minor) => this <= From(major, minor);
|
||||
public bool IsLessEqual(ushort major, ushort minor, ushort build) => this <= From(major, minor, build);
|
||||
public bool IsLessEqual(ushort major, ushort minor, ushort build, UnityVersionType type) => this <= From(major, minor, build, type);
|
||||
public bool IsLessEqual(ushort major, ushort minor, ushort build, UnityVersionType type, byte typeNumber) => this <= new UnityVersion(major, minor, build, type, typeNumber);
|
||||
public bool IsLessEqual(string version) => this <= Parse(version);
|
||||
|
||||
public bool IsGreater(int major) => this > From(major);
|
||||
public bool IsGreater(int major, int minor) => this > From(major, minor);
|
||||
public bool IsGreater(int major, int minor, int build) => this > From(major, minor, build);
|
||||
public bool IsGreater(int major, int minor, int build, UnityVersionType type) => this > From(major, minor, build, type);
|
||||
public bool IsGreater(int major, int minor, int build, UnityVersionType type, int typeNumber) => this > new UnityVersion(major, minor, build, type, typeNumber);
|
||||
public bool IsGreater(ushort major) => this > From(major);
|
||||
public bool IsGreater(ushort major, ushort minor) => this > From(major, minor);
|
||||
public bool IsGreater(ushort major, ushort minor, ushort build) => this > From(major, minor, build);
|
||||
public bool IsGreater(ushort major, ushort minor, ushort build, UnityVersionType type) => this > From(major, minor, build, type);
|
||||
public bool IsGreater(ushort major, ushort minor, ushort build, UnityVersionType type, byte typeNumber) => this > new UnityVersion(major, minor, build, type, typeNumber);
|
||||
public bool IsGreater(string version) => this > Parse(version);
|
||||
|
||||
public bool IsGreaterEqual(int major) => this >= From(major);
|
||||
public bool IsGreaterEqual(int major, int minor) => this >= From(major, minor);
|
||||
public bool IsGreaterEqual(int major, int minor, int build) => this >= From(major, minor, build);
|
||||
public bool IsGreaterEqual(int major, int minor, int build, UnityVersionType type) => this >= From(major, minor, build, type);
|
||||
public bool IsGreaterEqual(int major, int minor, int build, UnityVersionType type, int typeNumber) => this >= new UnityVersion(major, minor, build, type, typeNumber);
|
||||
public bool IsGreaterEqual(ushort major) => this >= From(major);
|
||||
public bool IsGreaterEqual(ushort major, ushort minor) => this >= From(major, minor);
|
||||
public bool IsGreaterEqual(ushort major, ushort minor, ushort build) => this >= From(major, minor, build);
|
||||
public bool IsGreaterEqual(ushort major, ushort minor, ushort build, UnityVersionType type) => this >= From(major, minor, build, type);
|
||||
public bool IsGreaterEqual(ushort major, ushort minor, ushort build, UnityVersionType type, byte typeNumber) => this >= new UnityVersion(major, minor, build, type, typeNumber);
|
||||
public bool IsGreaterEqual(string version) => this >= Parse(version);
|
||||
|
||||
private UnityVersion From(int major)
|
||||
private UnityVersion From(ushort major)
|
||||
{
|
||||
ulong data = ((ulong)(major & 0xFFFF) << 48) | (0x0000FFFFFFFFFFFFUL & m_data);
|
||||
ulong data = ((ulong)major << majorOffset) | subMajorMask & m_data;
|
||||
return new UnityVersion(data);
|
||||
}
|
||||
private UnityVersion From(int major, int minor)
|
||||
private UnityVersion From(ushort major, ushort minor)
|
||||
{
|
||||
ulong data = ((ulong)(major & 0xFFFF) << 48) | ((ulong)(minor & 0xFF) << 40) | (0x000000FFFFFFFFFFUL & m_data);
|
||||
ulong data = ((ulong)major << majorOffset) | ((ulong)minor << minorOffset) | subMinorMask & m_data;
|
||||
return new UnityVersion(data);
|
||||
}
|
||||
private UnityVersion From(int major, int minor, int build)
|
||||
private UnityVersion From(ushort major, ushort minor, ushort build)
|
||||
{
|
||||
ulong data = ((ulong)(major & 0xFFFF) << 48) | ((ulong)(minor & 0xFF) << 40) | ((ulong)(build & 0xFF) << 32) |
|
||||
(0x00000000FFFFFFFFUL & m_data);
|
||||
ulong data = ((ulong)major << majorOffset) | ((ulong)minor << minorOffset) | ((ulong)build << buildOffset) |
|
||||
subBuildMask & m_data;
|
||||
return new UnityVersion(data);
|
||||
}
|
||||
private UnityVersion From(int major, int minor, int build, UnityVersionType type)
|
||||
private UnityVersion From(ushort major, ushort minor, ushort build, UnityVersionType type)
|
||||
{
|
||||
ulong data = ((ulong)(major & 0xFFFF) << 48) | ((ulong)(minor & 0xFF) << 40) | ((ulong)(build & 0xFF) << 32) |
|
||||
((ulong)((int)type & 0xFF) << 24) | (0x0000000000FFFFFFUL & m_data);
|
||||
return new UnityVersion(data);
|
||||
}
|
||||
private UnityVersion From(int major, int minor, int build, UnityVersionType type, int typeNumber)
|
||||
{
|
||||
ulong data = ((ulong)(major & 0xFFFF) << 48) | ((ulong)(minor & 0xFF) << 40) | ((ulong)(build & 0xFF) << 32)
|
||||
| ((ulong)((int)type & 0xFF) << 24) | ((ulong)(typeNumber & 0xFF) << 16) | (0x000000000000FFFFUL & m_data);
|
||||
ulong data = ((ulong)major << majorOffset) | ((ulong)minor << minorOffset) | ((ulong)build << buildOffset) |
|
||||
((ulong)(ushort)type << typeOffset) | subTypeMask & m_data;
|
||||
return new UnityVersion(data);
|
||||
}
|
||||
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
namespace AssetRipper.VersionUtilities
|
||||
using System;
|
||||
|
||||
namespace AssetRipper.VersionUtilities
|
||||
{
|
||||
public readonly partial struct UnityVersion
|
||||
{
|
||||
@@ -43,5 +45,39 @@
|
||||
? right.m_data - left.m_data
|
||||
: left.m_data - right.m_data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the closest Unity version in an array of versions using <see cref="Distance(UnityVersion, UnityVersion)"/>
|
||||
/// </summary>
|
||||
/// <param name="versions">The Unity version array</param>
|
||||
/// <returns>The closest Unity version</returns>
|
||||
/// <exception cref="ArgumentNullException">The array is null</exception>
|
||||
/// <exception cref="ArgumentException">The array is empty</exception>
|
||||
public UnityVersion GetClosestVersion(UnityVersion[] versions)
|
||||
{
|
||||
if (versions is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(versions));
|
||||
}
|
||||
|
||||
if (versions.Length == 0)
|
||||
{
|
||||
throw new ArgumentException("Length cannot be zero", nameof(versions));
|
||||
}
|
||||
|
||||
UnityVersion result = versions[0];
|
||||
ulong currentDistance = Distance(this, result);
|
||||
for(int i = 1; i < versions.Length; i++)
|
||||
{
|
||||
ulong newDistance = Distance(this, versions[i]);
|
||||
if (newDistance < currentDistance)
|
||||
{
|
||||
currentDistance = newDistance;
|
||||
result = versions[i];
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using AssetRipper.VersionUtilities.Extensions;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
@@ -12,7 +13,7 @@ namespace AssetRipper.VersionUtilities
|
||||
/// <returns>A new string like 2019.4.3f1</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{Major}.{Minor}.{Build}{Type.ToLiteral()}{TypeNumber}";
|
||||
return $"{Major}.{Minor}.{Build}{Type.ToCharacter()}{TypeNumber}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -37,7 +38,7 @@ namespace AssetRipper.VersionUtilities
|
||||
sb.Append(separator);
|
||||
sb.Append(Build);
|
||||
sb.Append(separator);
|
||||
sb.Append(Type.ToLiteral());
|
||||
sb.Append(Type.ToCharacter());
|
||||
sb.Append(TypeNumber);
|
||||
|
||||
if(hasExtension)
|
||||
@@ -46,6 +47,15 @@ namespace AssetRipper.VersionUtilities
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Serialize the version as a string
|
||||
/// </summary>
|
||||
/// <returns>A new string like 2019.4.3</returns>
|
||||
public string ToStringWithoutType()
|
||||
{
|
||||
return $"{Major}.{Minor}.{Build}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a dll name like _2019_4_3f1.dll
|
||||
/// </summary>
|
||||
@@ -152,7 +162,7 @@ namespace AssetRipper.VersionUtilities
|
||||
typeNumber = typeNumber * 10 + c.ParseDigit();
|
||||
}
|
||||
|
||||
return new UnityVersion(major, minor, build, versionType, typeNumber);
|
||||
return new UnityVersion((ushort)major, (ushort)minor, (ushort)build, versionType, (byte)typeNumber);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,32 +5,40 @@
|
||||
/// </summary>
|
||||
public readonly partial struct UnityVersion
|
||||
{
|
||||
private const int majorOffset = 48;
|
||||
private const int minorOffset = 32;
|
||||
private const int buildOffset = 16;
|
||||
private const int typeOffset = 8;
|
||||
|
||||
private const ulong byteMask = 0xFFUL;
|
||||
private const ulong ushortMask = 0xFFFFUL;
|
||||
|
||||
private readonly ulong m_data;
|
||||
|
||||
/// <summary>
|
||||
/// The first number in a Unity version string
|
||||
/// </summary>
|
||||
public int Major => unchecked((int)((m_data >> 48) & 0xFFFFUL));
|
||||
public ushort Major => unchecked((ushort)((m_data >> majorOffset) & ushortMask));
|
||||
|
||||
/// <summary>
|
||||
/// The second number in a Unity version string
|
||||
/// </summary>
|
||||
public int Minor => unchecked((int)((m_data >> 40) & 0xFFUL));
|
||||
public ushort Minor => unchecked((ushort)((m_data >> minorOffset) & ushortMask));
|
||||
|
||||
/// <summary>
|
||||
/// The third number in a Unity version string
|
||||
/// </summary>
|
||||
public int Build => unchecked((int)((m_data >> 32) & 0xFFUL));
|
||||
public ushort Build => unchecked((ushort)((m_data >> buildOffset) & ushortMask));
|
||||
|
||||
/// <summary>
|
||||
/// The letter in a Unity version string
|
||||
/// </summary>
|
||||
public UnityVersionType Type => (UnityVersionType)unchecked((int)((m_data >> 24) & 0xFFUL));
|
||||
public UnityVersionType Type => (UnityVersionType)unchecked((byte)((m_data >> typeOffset) & byteMask));
|
||||
|
||||
/// <summary>
|
||||
/// The last number in a Unity version string
|
||||
/// </summary>
|
||||
public int TypeNumber => unchecked((int)((m_data >> 16) & 0xFFUL));
|
||||
public byte TypeNumber => unchecked((byte)(m_data & byteMask));
|
||||
|
||||
/// <summary>
|
||||
/// The minimum value this type can have
|
||||
@@ -45,43 +53,43 @@
|
||||
/// <summary>
|
||||
/// Construct a new Unity version
|
||||
/// </summary>
|
||||
public UnityVersion(int major)
|
||||
public UnityVersion(ushort major)
|
||||
{
|
||||
m_data = (ulong)(major & 0xFFFF) << 48;
|
||||
m_data = (ulong)major << majorOffset;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Construct a new Unity version
|
||||
/// </summary>
|
||||
public UnityVersion(int major, int minor)
|
||||
public UnityVersion(ushort major, ushort minor)
|
||||
{
|
||||
m_data = ((ulong)(major & 0xFFFF) << 48) | ((ulong)(minor & 0xFF) << 40);
|
||||
m_data = ((ulong)major << majorOffset) | ((ulong)minor << minorOffset);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Construct a new Unity version
|
||||
/// </summary>
|
||||
public UnityVersion(int major, int minor, int build)
|
||||
public UnityVersion(ushort major, ushort minor, ushort build)
|
||||
{
|
||||
m_data = ((ulong)(major & 0xFFFF) << 48) | ((ulong)(minor & 0xFF) << 40) | ((ulong)(build & 0xFF) << 32);
|
||||
m_data = ((ulong)major << majorOffset) | ((ulong)minor << minorOffset) | ((ulong)build << buildOffset);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Construct a new Unity version
|
||||
/// </summary>
|
||||
public UnityVersion(int major, int minor, int build, UnityVersionType type)
|
||||
public UnityVersion(ushort major, ushort minor, ushort build, UnityVersionType type)
|
||||
{
|
||||
m_data = ((ulong)(major & 0xFFFF) << 48) | ((ulong)(minor & 0xFF) << 40) | ((ulong)(build & 0xFF) << 32)
|
||||
| ((ulong)((int)type & 0xFF) << 24);
|
||||
m_data = ((ulong)major << majorOffset) | ((ulong)minor << minorOffset) | ((ulong)build << buildOffset)
|
||||
| ((ulong)type << typeOffset);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Construct a new Unity version
|
||||
/// </summary>
|
||||
public UnityVersion(int major, int minor, int build, UnityVersionType type, int typeNumber)
|
||||
public UnityVersion(ushort major, ushort minor, ushort build, UnityVersionType type, byte typeNumber)
|
||||
{
|
||||
m_data = ((ulong)(major & 0xFFFF) << 48) | ((ulong)(minor & 0xFF) << 40) | ((ulong)(build & 0xFF) << 32)
|
||||
| ((ulong)((int)type & 0xFF) << 24) | ((ulong)(typeNumber & 0xFF) << 16);
|
||||
m_data = ((ulong)major << majorOffset) | ((ulong)minor << minorOffset) | ((ulong)build << buildOffset)
|
||||
| ((ulong)type << typeOffset) | typeNumber;
|
||||
}
|
||||
|
||||
private UnityVersion(ulong data)
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace AssetRipper.VersionUtilities
|
||||
/// <summary>
|
||||
/// An enumeration representing the letter in a Unity Version string
|
||||
/// </summary>
|
||||
public enum UnityVersionType
|
||||
public enum UnityVersionType : byte
|
||||
{
|
||||
/// <summary>
|
||||
/// a
|
||||
@@ -53,9 +53,18 @@ namespace AssetRipper.VersionUtilities
|
||||
/// <param name="_this">A Unity version type</param>
|
||||
/// <returns>The character this value represents</returns>
|
||||
/// <exception cref="ArgumentOutOfRangeException">The type is not a valid value</exception>
|
||||
public static char ToLiteral(this UnityVersionType _this)
|
||||
[Obsolete("Changed to ToCharacter", true)]
|
||||
public static char ToLiteral(this UnityVersionType _this) => _this.ToCharacter();
|
||||
|
||||
/// <summary>
|
||||
/// Convert to the relevant character
|
||||
/// </summary>
|
||||
/// <param name="type">A Unity version type</param>
|
||||
/// <returns>The character this value represents</returns>
|
||||
/// <exception cref="ArgumentOutOfRangeException">The type is not a valid value</exception>
|
||||
public static char ToCharacter(this UnityVersionType type)
|
||||
{
|
||||
return _this switch
|
||||
return type switch
|
||||
{
|
||||
UnityVersionType.Alpha => 'a',
|
||||
UnityVersionType.Beta => 'b',
|
||||
@@ -63,7 +72,7 @@ namespace AssetRipper.VersionUtilities
|
||||
UnityVersionType.Final => 'f',
|
||||
UnityVersionType.Patch => 'p',
|
||||
UnityVersionType.Experimental => 'x',
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(_this), $"Unsupported version type {_this}"),
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(type), $"Unsupported version type {type}"),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
<RootNamespace>AssetRipper.VersionUtilities</RootNamespace>
|
||||
<Authors>ds5678</Authors>
|
||||
<Company>AssetRipper</Company>
|
||||
<Version>1.0.0.0</Version>
|
||||
<AssemblyVersion>1.0.0.0</AssemblyVersion>
|
||||
<Version>1.1.0.0</Version>
|
||||
<AssemblyVersion>1.1.0.0</AssemblyVersion>
|
||||
<PackageId>AssetRipper.VersionUtilities</PackageId>
|
||||
<PackageTags>C# version unity unity3d</PackageTags>
|
||||
<RepositoryUrl>https://github.com/AssetRipper/VersionUtilities</RepositoryUrl>
|
||||
|
||||
Reference in new issue
Block a user