Skip to content

Instantly share code, notes, and snippets.

@n0mimono
Created December 1, 2020 10:15
Show Gist options
  • Save n0mimono/37695ce2ab990d6ccfbe372c94d6fb6b to your computer and use it in GitHub Desktop.
Save n0mimono/37695ce2ab990d6ccfbe372c94d6fb6b to your computer and use it in GitHub Desktop.
public struct UnityVersion
{
public int stream;
public int number;
public int minor;
public string phase;
public int revision;
public UnityVersion(string unityVersion)
{
var ms = System.Text.RegularExpressions.Regex.Matches(unityVersion, @"(\d+)|([abf])");
try
{
this.stream = int.Parse(ms[0].Value);
this.number = int.Parse(ms[1].Value);
this.minor = int.Parse(ms[2].Value);
this.phase = ms[3].Value;
this.revision = int.Parse(ms[4].Value);
}
catch (System.Exception)
{
this.stream = 0;
this.number = 0;
this.minor = 0;
this.phase = string.Empty;
this.revision = 0;
}
}
public override string ToString()
{
return $"{stream}.{number}.{minor}{phase}{revision}";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment