在接入友盟sdk的时候,发现要在微信小游戏开发者工具中接入。估研究此招!
废话不多说:

        步骤1:在微信中放入自己写的 js库     

     

        步骤2:写c#调用脚本

        

步骤3:加入JS代码,这个文件在导出微信小游戏的时候会一起导出。

步骤4: 修改game.js

最后贴一些的代码方便复制:

c#:

    [DllImport("__Internal")]
    private static extern void TestNormal(bool val);
    [DllImport("__Internal")]
    private static extern void TestString(string str);
    [DllImport("__Internal")]
    private static extern float TestReturn();
    [DllImport("__Internal")]
    private static extern void CallFunc(string className, string str);

    public static KiwiSDK Instance;

    
    public void Awake()
    {
        Instance = this;
    }

    public void Test(bool val, string str)
    {
        TestNormal(val);
        TestString(str);
    }

MyLib.jslib(改个名吧谢谢)

var MyLib = {

  TestNormal: function (val) {
    window.CallJS.TestNormal(val);
  },
  TestString: function (str) {
    window.CallJS.TestString(Pointer_stringify(str));
  },
  TestReturn: function () {
    return window.CallJS.TestReturn();
  },
  CallFunc: function(className, str) {
    return window.CallJS.CallFunc(Pointer_stringify(className), Pointer_stringify(str));
  }
};
mergeInto(LibraryManager.library, MyLib);

 CallJS.js
 

export const CallJS = {
  TestNormal(val) {
    
  },
  TestString(str) {
      console.log("caole" + str)
  },
  TestReturn() {
      return 1;
  },
  CallFunc(className, str) {
  }
};

问题咨询,小游戏开发问题请 私我

更多推荐