| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- /**custom method set */
- export class CMS {
- /**
- * find a childNode or childComponent
- * @param startNode the root Node
- * @param path childPath without root
- * @param component return component? if yes,input the type of component
- */
- public static findChild(startNode:cc.Node,path:string,component?:new()=>cc.Component):any{
- let childNames:string[] = path.split('/');
- let node:cc.Node = startNode;
- childNames.forEach(childName => {
- node = node.getChildByName(childName);
- });
- if(component){
- return node.getComponent(component);
- }else{
- return node;
- }
- };
- }
- export class Tool{
- /**time format for minute and second */
- public static timeFormatMS(millis:number):string{
- let minute = Math.floor(millis/1000/60);
- let second = Math.floor(millis/1000%60);
- return (minute<10?'0':'')+minute+':'+(second<10?'0':'')+second;
- }
- public static timeFormatHMS(millis:number):string{
- let hour = Math.floor(millis/1000/60/60);
- let minute = Math.floor(millis/1000/60%60);
- let second = Math.floor(millis/1000%60);
- return (hour<10?'0':'')+hour+':'+(minute<10?'0':'')+minute+':'+(second<10?'0':'')+second;
- }
- public static decimal(value:number,count:number):number {
- let str = value.toString();
- let pointIndex = str.indexOf('.');
- if(pointIndex>-1){
- return parseFloat(str.substring(0,pointIndex+count+1));
- }else{
- return value;
- }
- }
- public static openInWebview () {
- let ua = navigator.userAgent.toLowerCase()
- if (ua.match(/MicroMessenger/i) != null) { // 微信浏览器判断
- return false
- } else if (ua.match(/QQ/i) != null) { // QQ浏览器判断
- return false
- } else if (ua.match(/WeiBo/i) != null) {
- return false
- } else {
- if (ua.match(/Android/i) != null) {
- return ua.match(/browser/i) == null
- } else if (ua.match(/iPhone/i) != null) {
- return ua.match(/safari/i) == null
- } else {
- return (ua.match(/macintosh/i) == null && ua.match(/windows/i) == null)
- }
- }
- }
- }
|