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的更多相关文章

  1. JSBinding+SharpKit / 菜单介绍

  2. JSBinding + SharpKit / 编译 Cs 成 Js

    轻轻一点菜单:[JSB | Compile Cs to Js] 主要产出:StreamingAssets/JavaScript/SharpkitGeneratedFiles.javascript,你的 ...

  3. JSBinding+SharpKit / 更新的原理

    首先,其实不是热更新,而是更新. 热更新意思是不重启游戏,但只要你脚本里有存储数据,就不可能.所以只能叫更新. 但大家都这么说,所以... 先举个具体的例子: 如果是C#:在 Prefab 的 Gam ...

  4. JSBinding+SharpKit / JavaScript调试

    注意: 1 Firefox 的版本用41 2 我发现调试很难用的,现在我都用打印 步骤参考图:

  5. JSBinding + SharpKit / 实战:转换 Survival Shooter

    从 asset store 下载 Survival Shooter (商店里有2个版本,一种是给Unity5用的,一个是给Unity4.6用的,我们这个实验用的是后者,版本是2.2.如果) 1 删除多 ...

  6. JSBinding + SharpKit / JavaScript 加载流程

    首先,现在的方案是游戏启动就加载全部的 JavaScript 代码. 先看下 StreamingAssets/JavaScript/ 文件夹下的目录结构:

  7. JSBinding + SharpKit / 常见问题

    运行时出现: Return a "System.Xml.XmlIteratorNodeList" to JS failed. Did you forget to export th ...

  8. JSBinding + SharpKit / Coroutine支持

    首先得深入了解协程的原理.如果还没有完全理解,建议看这篇: http://wiki.unity3d.com/index.php/CoroutineScheduler 另外还要对 JavaScript ...

  9. JSBinding + SharpKit / 原理篇:内存管理与垃圾回收

    C# 和 JS 都有垃圾回收机制,需要保证 2 者能够分工协作. 类对象 类在C#中是引用类型.我们在 C# 中维护了2个map,保存 C# 对象和 JS 对象的一一对应关系. 举一个例子,看以下代码 ...

随机推荐

  1. hadoop启动jobhistoryserver

    hadoop启动jobhistoryserver来实现web查看作业的历史运行情况,由于在启动hdfs和Yarn进程之后,jobhistoryserver进程并没有启动,需要手动启动,启动的方法是通过 ...

  2. Ubuntu 14.10 下SSH执行远程命令

    有些时候需要在远程机器上执行命令,如果每次都等进去挺麻烦的,所以用脚本执行会方便很多.下面介绍一下在shell脚本中执行远程命令. 1,首先写好要运行的脚本 run-command.sh, 加上执行权 ...

  3. AFNetworking vs ASIHTTPRequest vs MKNetworkKit

    AFNetworking vs ASIHTTPRequest vs MKNetworkKit

  4. Chapter 4: Tomcat Default Connector

    一.概述 第三章介绍的connector是一个很好的学习工具,但是我们还可以做的更多.这一章介绍的是Tomcat4默认的connector. 一个Tomcat的connector是一个独立的模块,能够 ...

  5. SQL Server LEFT Functions

    LEFT(string, n)函数,是处理字符数据获取子字符串.第一个参数是将要处理的字符串,第二个参数,是从字符串的左边开始截取的字符个数. 例子: DECLARE @string NVARCHAR ...

  6. C# Rhino Mocks

    Mock和Stub的区别: 1,Stub是一个在你的测试代码中需要用到的object,你可以为它设置expectations,然后它就会按其运行,但是这些expectations不会被核对. 2,Mo ...

  7. webservice basics

    =====================Quote starts================== JAX-WS (JavaTM API for XML-Based Web Services)规范 ...

  8. 【LeetCode】Rotate Array

    Rotate Array Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = ...

  9. Arrays Multi

    <!DOCTYPE html><html><body><?php$cars = array   (   array("Volvo",22, ...

  10. HDU5619 (费用流)

    Problem Jam's Store (HDU5619) 题目大意 有m个服务员,和n个顾客,给出每个服务员招待每个顾客的时间,每个服务员在同一时间只能服务一个顾客,询问所有顾客完成服务的最少时间. ...