using System; using System.Collections.Generic; using UnityEngine; namespace ModTool.Shared { /// /// Represents a platform or a combination of platforms. /// [Flags] [Serializable] public enum ModPlatform { Windows = 1, Linux = 2, OSX = 4, Android = 8 } /// /// Extension methods for ModPlatform. /// public static class ModPlatformExtensions { /// /// Does this ModPlatform include the equivalent RuntimePlatform? /// /// A ModPlatform instance. /// A RuntimePlatform. /// True if the ModPlatform includes the equivalent RuntimePlatform. public static bool HasRuntimePlatform(this ModPlatform self, RuntimePlatform runtimePlatform) { switch (runtimePlatform) { case RuntimePlatform.WindowsPlayer: if ((self & ModPlatform.Windows) == ModPlatform.Windows) return true; break; case RuntimePlatform.WindowsEditor: if ((self & ModPlatform.Windows) == ModPlatform.Windows) return true; break; case RuntimePlatform.LinuxPlayer: if ((self & ModPlatform.Linux) == ModPlatform.Linux) return true; break; case RuntimePlatform.OSXPlayer: if ((self & ModPlatform.OSX) == ModPlatform.OSX) return true; break; case RuntimePlatform.OSXEditor: if ((self & ModPlatform.OSX) == ModPlatform.OSX) return true; break; case RuntimePlatform.Android: if ((self & ModPlatform.Android) == ModPlatform.Android) return true; break; } return false; } /// /// Get the equivalent ModPlatform for this RuntimePlatform. /// /// A RuntimePlatform. /// The equivalent ModPlatform. public static ModPlatform GetModPlatform(this RuntimePlatform self) { switch(self) { case RuntimePlatform.WindowsPlayer: return ModPlatform.Windows; case RuntimePlatform.WindowsEditor: return ModPlatform.Windows; case RuntimePlatform.LinuxPlayer: return ModPlatform.Linux; case RuntimePlatform.OSXPlayer: return ModPlatform.OSX; case RuntimePlatform.OSXEditor: return ModPlatform.OSX; case RuntimePlatform.Android: return ModPlatform.Android; } return 0; } /// /// Get a list of the equivalent RuntimePlatforms for this ModPlatform /// /// A ModPlatform instance. /// A List of equivalent RuntimePlatforms. public static List GetRuntimePlatforms(this ModPlatform self) { List runtimePlatforms = new List(); var values = Enum.GetValues(typeof(RuntimePlatform)); foreach (RuntimePlatform r in values) { if (self.HasRuntimePlatform(r)) runtimePlatforms.Add(r); } return runtimePlatforms; } } }