future 1 anno fa
parent
commit
4c05604ae4
3 ha cambiato i file con 91 aggiunte e 118 eliminazioni
  1. 1 1
      assets/scene/game.scene
  2. 1 1
      assets/script/config.ts
  3. 89 116
      assets/script/sdkUtil.ts

+ 1 - 1
assets/scene/game.scene

@@ -178,7 +178,7 @@
     "_priority": 0,
     "_fov": 45,
     "_fovAxis": 0,
-    "_orthoHeight": 961.1111111111111,
+    "_orthoHeight": 960,
     "_near": 0,
     "_far": 1000,
     "_color": {

+ 1 - 1
assets/script/config.ts

@@ -3,7 +3,7 @@ import { scene_item_data, widget_item_data } from '../data/data';
 const { ccclass, property } = _decorator;
 
 export class config {
-    static debug = true;
+    static debug = false;
     static is_zb = false; //是否是主播模式
     static gameName = "神秘的笔记";
     static select_res_and_control_type = {

+ 89 - 116
assets/script/sdkUtil.ts

@@ -1,4 +1,4 @@
-import { _decorator, SpriteFrame, sys } from "cc";
+import { _decorator, error, SpriteFrame, sys } from "cc";
 import { gameManager } from "./run/gameManager";
 import { config } from "./config";
 import { statisticsManager } from "./statisticsManager";
@@ -31,12 +31,15 @@ export class SdkUtil {
     private static tt_totalRecord:number = 300;     //抖音总录制时间
     private static tt_isRecording:boolean = false;  //抖音是否录制中
 
+    //------------------------------  公共  ------------------------------//
+
     public static init() {
         this.ttGetSystemInfo(()=> {
-            this.ttRegisterSidebar()
+            this.ttRegisterInfo()
         })
     }
 
+    // 苹果手机是否有灵动岛
     public static iPhoneIsLingdongdao():boolean {
         if(sys.platform==sys.Platform.BYTEDANCE_MINI_GAME) {
             if(SdkUtil.tt_systemInfo !=null) {
@@ -54,28 +57,18 @@ export class SdkUtil {
         return false
     }
 
-    /**
-       * 自定义事件统计
-       *
-       * @param {string} eventType
-       * @param {object} objParams
-       */
+    // 自定义事件统计
     public static customEventStatistics(eventType: string, objParams?: any) {
         eventType = eventType.toString();
-        if (!objParams) {
-            objParams = {};
-        }
-
+        if (!objParams) { objParams = {}; }
         // console.log({'eventType': eventType},{'objParams': objParams});
-
         if (this.platform === 'wx') {
             //@ts-ignore
             if (window['wx'] && window['wx']['aldSendEvent']) {
-                //@ts-ignore
+                //@ts-ignore 
                 window.wx['aldSendEvent'](eventType, objParams);
             }
         }
-
         //@ts-ignore
         if (this.platform === 'cocos' && window.cocosAnalytics && window.cocosAnalytics.isInited()) {
             console.log("###统计", eventType, objParams);
@@ -84,17 +77,17 @@ export class SdkUtil {
         }
     }
 
+    // 检测显示添加桌面
+    public static checkIsShowAddDesktop():boolean {
+        if(sys.platform == sys.Platform.BYTEDANCE_MINI_GAME) {
+            if(SdkUtil.tt_systemInfo.appName=='Douyin' || SdkUtil.tt_systemInfo.appName=='douyin_lite') {
+                return true
+            }
+        }
+        return false
+    }
 
-    /**
-     * 抖音/微信分享
-     * 
-     * @static
-     * @param {string} title
-     * @param {string} imageUrl
-     * @param {string} videoPath
-     * @returns
-     * @memberof SdkUtil
-     */
+    // 分享游戏
     public static shareGame(title: string, imageUrl: string, videoPath: string) {
         if(sys.platform == sys.Platform.BYTEDANCE_MINI_GAME) {
             if(videoPath!="") {
@@ -106,78 +99,7 @@ export class SdkUtil {
         }
     }
 
-    /**
-     * 微信分享
-     * 
-     * @static
-     * @param {string} title
-     * @param {string} imageUrl
-     * @returns
-     * @memberof SdkUtil
-     */
-    public static wxShare(title: string, imageUrl: string) {
-        // console.log('微信分享=',title, 'imageUrl=',imageUrl)
-        wx.showShareMenu({
-            withShareTicket: true,
-            // shareAppMessage(可以删除):显示分享给好友选项,shareTimeline(可以删除):显示分享至朋友圈选项
-		    // 可以只开启前者。如果要开启后者,则两者必须都开启才能生效。
-            // menus: ['shareAppMessage', 'shareTimeline'],
-            menus: ['shareAppMessage'],
-            complete: () => {}
-        });
-
-        // 主动分享
-        wx.shareAppMessage({
-            title: title,
-            imageUrl: imageUrl
-        });
-
-        // 被动分享
-        // wx.onShareAppMessage( () => {
-        //     return {
-        //         // 标题,不传则默认使用小游戏的名称
-        //         title: title,
-        //         // 转发链接所显示的图片,比例5:4,资源可以是本地或远程。不传则默认使用游戏截图。           
-        //         imageUrl: imageUrl,
-        //     }
-        // });
-
-        //@ts-ignore
-        // if (!window.wx) {
-        //     return;
-        // }
-        // 
-        //@ts-ignore
-        // wx.showShareMenu({
-        //     withShareTicket: true,
-        //     complete: () => {
-        //         console.log('')
-        //     }
-        // }
-        //
-        //@ts-ignore
-        // if (wx.aldOnShareAppMessage) {
-        //     //@ts-ignore 被动分享
-        //     wx.aldOnShareAppMessage(function () {
-        //         // 用户点击了“转发”按钮
-        //         return {
-        //             title: title,
-        //             imageUrl: imageUrl,
-
-        //         };
-        //     });
-        // } else {
-        //     //@ts-ignore
-        //     wx.onShareAppMessage(function () {
-        //         // 用户点击了“转发”按钮
-        //         return {
-        //             title: title,
-        //             imageUrl: imageUrl,
-        //         };
-        //     });
-        // }
-    }
-
+    // 获取广告id
     public static getAdId(ad_type = config.AD_TYPE.UNKNOWN):string {
         let ad_id = ""
         if(sys.platform == sys.Platform.BYTEDANCE_MINI_GAME) {
@@ -212,15 +134,7 @@ export class SdkUtil {
         return ad_id
     }
     
-    /**
-     * 抖音/微信激励视频
-     * 
-     * @static
-     * @param {string} _adUnitId
-     * @param {Function} call_back
-     * @returns
-     * @memberof SdkUtil
-     */
+    // 显示激励视频广告
     public static showVideoAd(_adUnitId: string, call_back) {
         if(gameManager.isFreeAds()) {
             call_back({"isEnded":true})
@@ -264,9 +178,30 @@ export class SdkUtil {
         }
     }
 
-    /**
-     * 抖音获取系统信息
-     */
+    //------------------------------  微信相关  ------------------------------//
+
+    // 微信分享
+    public static wxShare(title: string, imageUrl: string) {
+        // console.log('微信分享=',title, 'imageUrl=',imageUrl)
+        wx.showShareMenu({
+            withShareTicket: true,
+            // shareAppMessage(可以删除):显示分享给好友选项,shareTimeline(可以删除):显示分享至朋友圈选项
+		    // 可以只开启前者。如果要开启后者,则两者必须都开启才能生效。
+            // menus: ['shareAppMessage', 'shareTimeline'],
+            menus: ['shareAppMessage'],
+            complete: () => {}
+        });
+        // 主动分享
+        wx.shareAppMessage({
+            title: title,
+            imageUrl: imageUrl
+        });
+    }
+
+
+    //------------------------------  抖音相关  ------------------------------//
+
+    // 抖音获取系统信息
     public static ttGetSystemInfo(callback) {
         if(sys.platform == sys.Platform.BYTEDANCE_MINI_GAME) {
             tt.getSystemInfo({
@@ -280,13 +215,51 @@ export class SdkUtil {
         }
     }
 
-    /**
-     * 抖音侧边栏
-     * 
-     * @static
-     * @memberof SdkUtil
-     */
-    public static ttRegisterSidebar() {
+    // 抖音添加快捷键(目前仅支持:抖音(Douyin) 和 抖音极速版(douyin_lite))
+    public static ttAddShortcut(onSuccess:Function = null, onFail:Function = null) {
+        if(sys.platform == sys.Platform.BYTEDANCE_MINI_GAME) {
+            if(SdkUtil.tt_systemInfo.appName=='Douyin'||SdkUtil.tt_systemInfo.appName=='douyin_lite') {
+                if(SdkUtil.tt_systemInfo.brand=='Apple') {
+                    tt.addShortcut({
+                        success() {
+                            console.log("添加桌面成功");
+                            onSuccess && onSuccess(null)
+                        },
+                        fail(err) {
+                            console.log("添加桌面失败", err.errMsg);
+                            onFail && onFail(err)
+                        },
+                    });
+                } else if(SdkUtil.tt_systemInfo.brand=='Android') {
+                    // 检测只支持安卓
+                    tt.checkShortcut({
+                        success(res) {
+                            console.log("检查快捷方式", res.status);
+                            if(res.status.exist==false||res.status.needUpdate==true) {
+                                tt.addShortcut({
+                                    success() {
+                                        console.log("添加桌面成功");
+                                        onSuccess && onSuccess(null)
+                                    },
+                                    fail(err) {
+                                        console.log("添加桌面失败", err.errMsg);
+                                        onFail && onFail(err)
+                                    },
+                                });
+                            }
+                        },
+                        fail(err) {
+                            console.log("检查快捷方式失败", err.errMsg);
+                            onFail && onFail(err)
+                        },
+                    });
+                }   
+            }
+        }
+    }
+
+    // 抖音注册信息
+    public static ttRegisterInfo() {
         if(sys.platform == sys.Platform.BYTEDANCE_MINI_GAME) {
             tt.onShow((res) => {
                 console.log('tt.onShow =', res)