"use strict"; cc._RF.push(module, '838b0XiIn1J+7iy0lkPnln6', 'misc_help'); // Scripts/ffengine/misc_help.js "use strict"; var EPlatform = cc.Enum({ Unknown: 0, WebBrowser_Mobile: 1, WebBrowser_Fixed: 2, Native_Android: 11, Native_IOS: 12, WindowsOrEditor: 15, Other: 999 }); var PlatformName = { "0": "Unknown", "1": "WebBrowser_Mobile", "2": "WebBrowser_Fixed", "11": "Native_Android", "12": "Native_IOS", "15": "WindowsOrEditor", "999": "Other" }; var CMiscHelp = cc.Class({ statics: { instance: null }, ctor: function ctor() { this.mPlatform = EPlatform.Unknown; }, getPlatform: function getPlatform() { if (EPlatform.Unknown !== this.mPlatform) { return this.mPlatform; } if (cc.sys.isBrowser) { this.mPlatform = cc.sys.OS_ANDROID === cc.sys.os || cc.sys.OS_IOS === cc.sys.os ? EPlatform.WebBrowser_Mobile : EPlatform.WebBrowser_Fixed; } else { if (cc.sys.isNative) { if (cc.sys.isMobile) { if (cc.sys.OS_ANDROID === cc.sys.os) { this.mPlatform = EPlatform.Native_Android; } else if (cc.sys.OS_IOS === cc.sys.os) { this.mPlatform = EPlatform.Native_IOS; } else { this.mPlatform = EPlatform.Other; } } else { this.mPlatform = EPlatform.WindowsOrEditor; } } else { this.mPlatform = EPlatform.Other; } } return this.mPlatform; }, /** * 获取当前平台名 * @return {string} */ getPlatformName: function getPlatformName() { var pt = this.getPlatform(); return PlatformName[pt] || PlatformName[0]; }, /** * 是否浏览器环境 * @return {boolean} */ isBrowser: function isBrowser() { return this.isMobileBrowser() || this.isWin32WebBrowser(); }, /** * 是否移动平台的浏览器 * @return {boolean} */ isMobileBrowser: function isMobileBrowser() { return EPlatform.WebBrowser_Mobile === this.getPlatform(); }, /** * 是否 win32,Mac等 非移动平台的浏览器 * @return {boolean} */ isWin32WebBrowser: function isWin32WebBrowser() { return EPlatform.WebBrowser_Fixed === this.getPlatform(); }, isNative: function isNative() { return this.isNativeAndroid() || this.isNativeIOS(); }, /** * 是否 Android 源生环境 * @return {boolean} */ isNativeAndroid: function isNativeAndroid() { return EPlatform.Native_Android === this.getPlatform(); }, /** * 是否 IOS 源生环境 * @return {boolean} */ isNativeIOS: function isNativeIOS() { return EPlatform.Native_IOS === this.getPlatform(); }, /** * 是否 Win32,Mac,编辑器 等源生环境 * @return {boolean} */ isWindowsOrEditor: function isWindowsOrEditor() { return EPlatform.WindowsOrEditor === this.getPlatform(); }, /** * @return {boolean} */ isValid: function isValid(target) { return undefined !== target && null !== target; }, /** * @return {boolean} */ isValidString: function isValidString(targetString) { return undefined !== targetString && null !== targetString && 0 !== targetString['length']; }, /** * @return {cc.Node} */ getValidNode: function getValidNode(node) { if (!node) { return null; } var realNodeVal = null; if (node instanceof cc.Node) { realNodeVal = node; } else if (node instanceof cc.Component) { realNodeVal = node.node; } else { return null; } if (realNodeVal && realNodeVal.isValid) { return realNodeVal; } return null; }, /** * @return {boolean} */ isValidNode: function isValidNode(node) { return null != this.getValidNode(node); } }); CMiscHelp.getInstance = function () { if (!CMiscHelp.instance) { CMiscHelp.instance = new CMiscHelp(); } return CMiscHelp.instance; }; module.exports = CMiscHelp; cc._RF.pop();