Skip to content

Instantly share code, notes, and snippets.

@TarasOsiris
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TarasOsiris/fe4ef88f11ab52ca419c to your computer and use it in GitHub Desktop.
Save TarasOsiris/fe4ef88f11ab52ca419c to your computer and use it in GitHub Desktop.
RuntimePlatform utility class for Unity
using UnityEngine;
public static class RuntimePlatformUtils
{
private static RuntimePlatform _platform;
static RuntimePlatformUtils()
{
_platform = Application.platform;
}
public static bool IsWebPlayer()
{
return Application.isWebPlayer;
}
public static bool IsEditor()
{
return Application.isEditor;
}
public static bool IsFlash()
{
return _platform == RuntimePlatform.FlashPlayer;
}
#region mobile
public static bool IsMobile()
{
return IsIOS() || IsAndroid() || IsWP8() || IsBlackberry();
}
public static bool IsIOS()
{
return Application.platform == RuntimePlatform.IPhonePlayer;
}
public static bool IsAndroid()
{
return Application.platform == RuntimePlatform.Android;
}
public static bool IsWP8()
{
return Application.platform == RuntimePlatform.WP8Player;
}
public static bool IsBlackberry()
{
return Application.platform == RuntimePlatform.BlackBerryPlayer;
}
#endregion
#region console
public static bool IsGameConsole()
{
return IsPlaystation3() || IsXBox360();
}
public static bool IsXBox360()
{
return _platform == RuntimePlatform.XBOX360;
}
public static bool IsPlaystation3()
{
return _platform == RuntimePlatform.PS3;
}
#endregion
#region desktop
public static bool IsDesktopPlayer()
{
return _platform == RuntimePlatform.LinuxPlayer ||
_platform == RuntimePlatform.WindowsPlayer ||
_platform == RuntimePlatform.OSXPlayer;
}
#endregion
#region convenience_methods
public static bool IsDesktopOrEditor()
{
return IsDesktopPlayer() || IsEditor();
}
#endregion
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment