JSBinding + SharpKit / Important Notes

Serialization of List<T> is not supported.

public List<int> lst; // NOT supported, use int[] instead

About menu: JSB | Add SharpKit JsType Attribute for all Structs and Classes.

If you execute this menu more than once, only one JsType will be added. this is good.

 1 using UnityEngine;
 2  using System.Collections;
 3
 4  using SharpKit.JavaScript;
 5
 6  [JsType(JsMode.Clr,"../../StreamingAssets/JavaScript/SharpKitGenerated/2DPlatformer/Scripts/Gun.javascript")]
 7  public class Gun : MonoBehaviour
 8  {
 9     public GameObject rocketGO;                // Prefab of the rocket.
10     public float speed = 20f;                // The speed the rocket will fire at.
11
12     //........
13 }

Coroutine is not supported.

you have to re-write yield code before compilint C# script to JavaScript. NOTE. JavaScript itself does support yield instruction, but can not work seamless with SharpKit.

Better not use ‘as‘ operator.

Check the JavaScript generated, you will know why. It will cause additional cost.

1 UnityEngine.Object obj = ...;
2
3 GameObject go = obj as GameObject; // DON‘T do this
4 GameObject go = (GameObject)obj; // GREAT

[] is now treated as ‘input‘, or ‘readonly‘ when calling C# function from JavaScript.

 1 // C#
 2 void ModifyArray(int[] arr)
 3 {
 4     for (var i = 0; i < arr.Length; i++)
 5         arr[i] = i;
 6 }
 7
 8 // JS
 9 var arr = [5,2,3,2];
10 ModifyArray(arr); // call C# function
11
12 //
13 // arr is still [5,2,3,2] !!
14 //

back to

JSBinding + SharpKit / Home

时间: 2024-10-12 21:10:14

JSBinding + SharpKit / Important Notes的相关文章

JSBinding + SharpKit / Home

Description JSBinding is a great tool enabling you to run actual JavaScript in Unity3D. It contains Mozilla SpiderMonkey JavaScript engine version 33 library. New version is expected to work with SharpKit (sharpkit.net). SharpKit is an open source to

JSBinding+SharpKit / 菜单介绍

[JSB | Generate JS and CS Bindings] 生成绑定,即让 Js 和 Cs 互通.详情请看 JSBinding+SharpKit / 生成 JavaScript 绑定 [JSB | Add SharpKit JsType Attribute for all Structs and Classes] 在所有逻辑代码中,所有类的定义前面加上 [JsType(JsMode.Clr, "~/Assets/StreamingAssets/JavaScript/SharpKitG

JSBinding + SharpKit / 编译 Cs 成 Js

轻轻一点菜单:[JSB | Compile Cs to Js] 主要产出:StreamingAssets/JavaScript/SharpkitGeneratedFiles.javascript,你的所有逻辑代码都在这里 其他产出: Temp/AllInvocations.txt:记录所有逻辑代码对框架代码的调用 (1) Temp/AllInvocationsWithLocation.txt:同上,但同时记录每个调用的文件名和行号 (2) Temp/YieldReturnTypes.txt:记录

JSBinding + SharpKit / 初体验:下载代码及运行Demo

QQ群:189738580 git地址:https://github.com/qcwgithub/qjsbunitynew.git插件源码地址(不包含SpiderMonkey源代码):https://github.com/qcwgithub/qjsbmozillajswrap.git 首先用 Unity 打开代码目录下的 proj 工程 由于使用的插件存在依赖,请将 Assets/Plugins/x86/mozjs-28.dll 拷贝于 Unity 安装目录下.如图所示. 如果没有做这个步骤,运

JSBinding+SharpKit / 更新的原理

首先,其实不是热更新,而是更新. 热更新意思是不重启游戏,但只要你脚本里有存储数据,就不可能.所以只能叫更新. 但大家都这么说,所以... 先举个具体的例子: 如果是C#:在 Prefab 的 GameObject 上绑定 C# 脚本,这个 Prefab 会被打包成 AssetBundle,然后通过 AssetBundle.Load 加载到游戏中. 因为C#本身不可能更新,所以就无法修改. JSB的方案是,将这些 C# 的 MonoBehaviour 都替换成 JSComponent_xxx.这

JSBinding + SharpKit / 常见问题

运行时出现: 1 Return a "System.Xml.XmlIteratorNodeList" to JS failed. Did you forget to export that class? 答:将这个类加入到 JSBindingSettings.classes 数组后运行一下菜单 JSB | Generate JS and CS Bindings. 特殊情况1:如果这个类并不存在,或者是被 DLL 隐藏了,导致无法添加,那么请添加他的基类.比如上面的 System.Xml

JSBinding + SharpKit / To JavaScript-Only users

This plugin is mainly desined to work with SharpKit. You are expected to write C# and get JavaScript code with help of SharpKit. If you don't like C# and would like to write JavaScrtipt only, Yes, you can do this, in version 1.5. But it will be a lit

JSBinding + SharpKit / 原理篇:Delegate

以 NGUI 的 UIEventListener 为例: 有一个类: 1 using SharpKit.JavaScript; 2 using UnityEngine; 3 using System.Collections; 4 5 [JsType(JsMode.Clr,"../StreamingAssets/JavaScript/SharpKitGenerated/z_temp/test0610.javascript")] 6 public class test0610 : Mono

Unity代码热更新方案 JSBinding + SharpKit 介绍

目前Unity的代码更新方案有很多,主要以lua为主. JSBinding + SharpKit 是一种新的技术,他做了两件事情: JSBinding将C#导出到JS中,让你可以用JS写代码,就好像 lua 一样 SharpKit(sharpkit.net)将C#代码翻译成JS代码. 因此,他可以让你使用C#编译代码,之后一键转换成JS代码并正常运行.如果你的项目已经使用C#开发并希望能够更新代码,欢迎尝试使用. 本文先做简介,后续本博客将做详细介绍. 完全支持序列化功能.即可以在 Inspec