JSBinding + SharpKit / Important Notes
Serialization of List<T> is not supported.

1 public int v; // SUPPORTED
2 public GameObject go; // SUPPORTED
3 public Transform trans; // SUPPORTED
4 public int[] arrInt; // SUPPORTED
5 public Vector3 v; // SUPPORTED
6 [Serializable]
7 public struct HandsomeGuyInfo {
8 public int jjLength;
9 public Vector3 jjDirection;
10 public string[] girlFriendNames;
11 };
12 public HandsomeGuyInfo[] infos; // SUPPORTED
13 public List<int> lst; // NOT SUPPORTED, Use int[] instead

About menu: Assets | 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 }
InvokeRepeating is supported
Coroutine is supported.
read JSBinding + SharpKit / Supporting Coroutine for more information.
DON'T 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
Array is now treated as 'input' (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 //
Only 1 demension array is supported (JS <-> CS).
int[] arr; // OK
int[,] arr; // NO
Debug.Log(): Explicitly call ToString() for string parameter.
Vector3 v = Vector3.one;
Debug.Log("v is " + v); // NO
Debug.Log("v is " + v.ToString()); // GOOD!
Generic Type including another Generic Type is not supported.
For example,
Dictionary<string, List<int>> dict; // NOT SUPPORTED
// But you can use this:
Dictionary<string, object> dict; // OK
DON'T use Reflection!
There is no type information in JavaScript, most functions of reflection are not available in JavaScript.
Unsafe code is not supported!
For example, char*, SharpKit doesn't support it.
Better not operate binary data in JavaScript.
For example, int[], byte[]. Operating binary data in JavaScript will have very very low performance, and get many bugs!
As an alternative, you can wrap these operations in C#, and expose interfaces to JavaScript.
Limited supported to 'SendMessage'
Member functions of JSComponent (and his derived classes) are fixed. You can not add member functions to JSComponent after game release. So if you want JSComponent to receive some message, for example, OnEnemyAttacked, you'll have to add OnEnemyAttacked to JSComponent beforehand.
BTW, JSComponent and his derived classes support ALL predefined methods, for a full list, see Messages section in http://docs.unity3d.com/ScriptReference/MonoBehaviour.html
Add as many as possible classes to JSBindingSettings.classes array
If you want to delta-update scripts after game release, you better add as many as possible classes to JSBindingSettings.classes array.
Because you can use classes in that array after game release!
back to
JSBinding + SharpKit / Home
JSBinding + SharpKit / Important Notes的更多相关文章
- JSBinding+SharpKit / 菜单介绍
- JSBinding + SharpKit / 编译 Cs 成 Js
轻轻一点菜单:[JSB | Compile Cs to Js] 主要产出:StreamingAssets/JavaScript/SharpkitGeneratedFiles.javascript,你的 ...
- JSBinding+SharpKit / 更新的原理
首先,其实不是热更新,而是更新. 热更新意思是不重启游戏,但只要你脚本里有存储数据,就不可能.所以只能叫更新. 但大家都这么说,所以... 先举个具体的例子: 如果是C#:在 Prefab 的 Gam ...
- JSBinding+SharpKit / JavaScript调试
注意: 1 Firefox 的版本用41 2 我发现调试很难用的,现在我都用打印 步骤参考图:
- JSBinding + SharpKit / 实战:转换 Survival Shooter
从 asset store 下载 Survival Shooter (商店里有2个版本,一种是给Unity5用的,一个是给Unity4.6用的,我们这个实验用的是后者,版本是2.2.如果) 1 删除多 ...
- JSBinding + SharpKit / JavaScript 加载流程
首先,现在的方案是游戏启动就加载全部的 JavaScript 代码. 先看下 StreamingAssets/JavaScript/ 文件夹下的目录结构:
- JSBinding + SharpKit / 常见问题
运行时出现: Return a "System.Xml.XmlIteratorNodeList" to JS failed. Did you forget to export th ...
- JSBinding + SharpKit / Coroutine支持
首先得深入了解协程的原理.如果还没有完全理解,建议看这篇: http://wiki.unity3d.com/index.php/CoroutineScheduler 另外还要对 JavaScript ...
- JSBinding + SharpKit / 原理篇:内存管理与垃圾回收
C# 和 JS 都有垃圾回收机制,需要保证 2 者能够分工协作. 类对象 类在C#中是引用类型.我们在 C# 中维护了2个map,保存 C# 对象和 JS 对象的一一对应关系. 举一个例子,看以下代码 ...
随机推荐
- java应用程序和虚拟机实例之间的关系
每一个java程序都会产生一个java虚拟机的实例.并不是说一个物理机上,运行多个java应用程序就只有一个java虚拟机实例,多少个java应用程序就有多少个java虚拟机实例.
- 高效的iOS宏定义
iOS开发过程中使用一些常用的宏可以提高开发效率,提高代码的重用性:将这些宏放到一个头文件里然后再放到工程中的-Prefix.pch文件中(或者直接放到-Prefix.pch中)直接可以使用,灰常方便 ...
- c++高质量编程手册
怡化主管强烈要求我读这本书.... 笔记尚未完成,持续更新呗.. 第1章 高质量软件开发之道 1.1 软件质量基本概念 1.1.1 如何理解软件的质量:功能性和非公能性 1.1.2 提高软件质量的基本 ...
- unity3d打包和包的使用
打包: ①Assets下新建文件夹Editor和steamingAssets ②对选定文件打包: using UnityEngine; using UnityEditor; using System. ...
- C++除法取整
使用floor函数.floor(x)返回的是小于或等于x的最大整数.如: floor(2.5) = 2 floor(-2.5) = -3 使用ceil函数.ceil(x)返回的是大于x的最小整 ...
- GSM BTS Hacking: 利用BladeRF和开源BTS 5搭建基站
引文 如果你已经购买了Nuand(官方)BladeRF x40,那么就可以在上面运行OpenBTS并可以输入一些指令来完成一些任务.一般来说HackRF,是一款覆盖频率最宽的SDR板卡.它几乎所有的信 ...
- python3爬虫初探(四)之文件保存
接着上面的写,抓取到网址之后,我们要把图片保存到本地,这里有几种方法都是可以的. #-----urllib.request.urlretrieve----- import urllib.request ...
- BZOJ3261 最大异或和 (可持久化Trie)
; len=; var x,y,z,n,m,tot,lx,i:longint; sum:..maxn] of longint; rt:..maxn] of longint; time,l,r:..ma ...
- WPF中ListView如何改变选中条背景颜色
先上图 解决方法: <ListView ...> <ListView.ItemContainerStyle> <Style TargetType="{x:Typ ...
- linux定时
linux怎样启动定时任务 crontab -e进入以后的,定时任务写入 */1 * * * * /usr/bin/python /root/lianxi/time_1.py ,每一分钟定时执行tim ...