Last active
August 29, 2015 14:05
-
-
Save TarasOsiris/fe4ef88f11ab52ca419c to your computer and use it in GitHub Desktop.
RuntimePlatform utility class for Unity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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