PlatUtils.ts 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. import { utils } from "./Utils";
  2. const { ccclass, property } = cc._decorator;
  3. @ccclass
  4. export default class PlatUtils {
  5. /**
  6. * 原生安卓平台
  7. */
  8. public static get IsNativeAndroid() {
  9. // jsb and android
  10. return (cc.sys.os == cc.sys.OS_ANDROID && CC_JSB);
  11. }
  12. public static get IsNativeIOS() {
  13. return (cc.sys.os == cc.sys.OS_IOS && CC_JSB);
  14. }
  15. /**
  16. * uc平台
  17. */
  18. public static get ISUC() {
  19. //@ts-ignore
  20. return window.uc;
  21. }
  22. /**s
  23. * cocos平台
  24. */
  25. public static get ISCocos() {
  26. //@ts-ignore
  27. return (window.loadRuntime && !this.IsOPPO && !this.IsVIVO && !window.kwaigame && !this.IsWiFi && !this.IsHuaWei);
  28. }
  29. /**
  30. * 安卓系统
  31. */
  32. public static get IsAndroid() {
  33. return cc.sys.os == cc.sys.OS_ANDROID;
  34. }
  35. /**
  36. * IOS系统
  37. */
  38. public static get IsIOS() {
  39. return cc.sys.os == cc.sys.OS_IOS;
  40. }
  41. /**
  42. * 微信平台
  43. */
  44. public static get IsWechat() {
  45. return cc.sys.platform == cc.sys.WECHAT_GAME && !this.IsDouyin && !this.IsQQ && !this.IsKwai;
  46. }
  47. /**
  48. * OPPO快游戏
  49. */
  50. public static get IsOPPO() {
  51. return cc.sys.platform == cc.sys.OPPO_GAME;
  52. }
  53. /**
  54. * 百度小游戏
  55. */
  56. public static get IsBaidu() {
  57. // return cc.sys.os == cc.sys.OS_ANDROID && cc.sys.platform == cc.sys.BAIDU_GAME;
  58. cc.sys.FB_PLAYABLE_ADS
  59. return cc.sys.platform == cc.sys.BAIDU_GAME;
  60. }
  61. /**
  62. * VIVO小游戏
  63. */
  64. public static get IsVIVO() {
  65. return cc.sys.platform == cc.sys.VIVO_GAME;
  66. }
  67. /**
  68. * 抖音小游戏
  69. */
  70. public static get IsDouyin() {
  71. //@ts-ignorett
  72. return window.tt;
  73. }
  74. /**
  75. * QQ小游戏
  76. * @returns 是否QQ平台
  77. */
  78. public static get IsQQ(): boolean {
  79. //@ts-ignore
  80. return window.qq;
  81. }
  82. /**
  83. * 趣头条
  84. * @returns 是否趣头条平台
  85. */
  86. public static get IsQTT(): boolean {
  87. //@ts-ignore
  88. return window.qttGame;
  89. }
  90. /**
  91. * 小米
  92. * @returns 是否小米平台
  93. */
  94. public static get IsXiaoMi(): boolean {
  95. //@ts-ignore
  96. if (!PlatUtils.IsOPPO && !PlatUtils.IsVIVO && !PlatUtils.IsHuaWei && window.qg) {
  97. return true;
  98. } else {
  99. return false;
  100. }
  101. }
  102. /**
  103. * h5-4399
  104. * @returns 是否4399-h5平台
  105. */
  106. public static get Is4399(): boolean {
  107. //@ts-ignore
  108. return window.h5api;
  109. }
  110. /**
  111. * 是否bili平台
  112. * @returns 是否bili平台
  113. */
  114. public static get IsBili(): boolean {
  115. //@ts-ignore
  116. return window.bl;
  117. }
  118. /**
  119. * 是否快手平台
  120. * @returns 是否快手平台
  121. */
  122. public static get IsKwai(): boolean {
  123. //@ts-ignore
  124. return typeof KSGameGlobal != 'undefined';
  125. }
  126. /**
  127. * 是否连尚平台
  128. * @returns 是否连尚平台
  129. */
  130. public static get IsWiFi(): boolean {
  131. //@ts-ignore
  132. return window.wuji;
  133. }
  134. /**
  135. * 是否Hago平台
  136. * @returns 是否Hago平台
  137. */
  138. public static get IsHago(): boolean {
  139. //@ts-ignore
  140. return window.hg;
  141. }
  142. /**
  143. * 是否华为平台
  144. * @returns 是否华为平台
  145. */
  146. public static get IsHuaWei(): boolean {
  147. //@ts-ignore
  148. return window.hbs;
  149. }
  150. /**
  151. * 是否测试平台
  152. * @returns 是否测试平台
  153. */
  154. public static get IsTest(): boolean {
  155. //@ts-ignore
  156. return false;
  157. }
  158. /**
  159. * 是否facebook小游戏
  160. */
  161. public static get IsFaceBook(): boolean {
  162. //@ts-ignore
  163. return window.FB !== undefined || window.minigame_sdk !== undefined
  164. }
  165. /**
  166. * 获取安卓当前的渠道号
  167. */
  168. public static get androidChannel() {
  169. if (utils.config && utils.config.nativeAndroidConfig) {
  170. return utils.config.nativeAndroidConfig.channel;
  171. }
  172. return "";
  173. }
  174. /**
  175. * 是否安卓传音平台
  176. */
  177. public static get IsAndroidChuanYin(): boolean {
  178. if (this.androidChannel == "chuanyin") {
  179. return true;
  180. }
  181. return false;
  182. }
  183. /**
  184. * 是否安卓OPPO平台
  185. */
  186. public static get IsAndroidOppo(): boolean {
  187. if (this.androidChannel == "oppo") {
  188. return true;
  189. }
  190. return false;
  191. }
  192. /**
  193. * 是否安卓VIVO平台
  194. */
  195. public static get IsAndroidVivo(): boolean {
  196. if (this.androidChannel == "vivo") {
  197. return true;
  198. }
  199. return false;
  200. }
  201. /**
  202. * 是否安卓抖音平台
  203. */
  204. public static get IsAndroidDouYin(): boolean {
  205. if (this.androidChannel == "douyin") {
  206. return true;
  207. }
  208. return false;
  209. }
  210. /**
  211. * 是否安卓华为平台
  212. */
  213. public static get IsAndroidHuaWei(): boolean {
  214. if (this.androidChannel.indexOf("huawei") > -1) {
  215. return true;
  216. }
  217. return false;
  218. }
  219. /**
  220. * 是否谷歌Web游戏
  221. */
  222. public static get IsGoogleWeb(): boolean {
  223. //@ts-ignore
  224. if (window.googleApi) {
  225. return true;
  226. }
  227. return false;
  228. }
  229. // sh export_kwai.sh -z /Volumes/D/cocos_project/common-project/1.1.2/CommonProject-2.0.9/build/cocos-runtime -v 1.0.0 -l false -f default
  230. }