using System; using UnityEngine; namespace Ubisoft.Hotel.Package { [Serializable] public class Version : IComparable { public static string GetVersionAsString(int major, int minor, int patch) { return "" + major + SEPARATOR + minor + SEPARATOR + patch; } private const char SEPARATOR = '.'; [SerializeField] private int m_major = 0; [SerializeField] private int m_minor = 0; [SerializeField] private int m_patch = 1; public Version(string versionAsString) { if (!string.IsNullOrEmpty(versionAsString)) { string[] tokens = versionAsString.Split(SEPARATOR); int length = tokens.Length; if (length > 0) { _ = int.TryParse(tokens[0], out m_major); } if (length > 1) { _ = int.TryParse(tokens[1], out m_minor); } if (length > 2) { _ = int.TryParse(tokens[2], out m_patch); } } } public int Major { get { return m_major; } set { m_major = value; } } public int Minor { get { return m_minor; } set { m_minor = value; } } public int Patch { get { return m_patch; } set { m_patch = value; } } public int CompareTo(object obj) { int returnValue = 1; Version otherVersion = null; if (obj != null) { otherVersion = obj as Version; } if (otherVersion != null) { returnValue = Major.CompareTo(otherVersion.Major); if (returnValue == 0) { returnValue = Minor.CompareTo(otherVersion.Minor); if (returnValue == 0) { returnValue = Patch.CompareTo(otherVersion.Patch); } } } return returnValue; } public override string ToString() { return GetVersionAsString(Major, Minor, Patch); } } }