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. Oracle 中批量导入大量测试数据的方法

    执行如下批处理命令: declare  maxrecords constant int := 100000;  i int := 1;begin  for i in 1 .. 20000 loop   ...

  2. objectARX获取当前图层所有文字样式

    void GetAllTextStyle(std::vector<CString> &textStyle) { textStyle.clear(); AcDbTextStyleTa ...

  3. aspx页面图片用作html中img的url

    背景:如果无法直接访问保存图片的服务器,我们可以先制作一个aspx页面用来接受服务器发送过来的图片,然后html页面请求aspx页面.对图片服务器起一定的缓冲保护作用,预防对黑客攻击造成危害. 注意: ...

  4. css 设置样式

    前台div <div id="DIV1" runat="server" > </div> 后台: this.DIV1.Style.Val ...

  5. HDU 4927

    http://acm.hdu.edu.cn/showproblem.php?pid=4927 直接模拟会超时,要在纸上写写推公式 A[n]*C(0,n-1)  - A[n-1]*C(1,n-1) + ...

  6. Fix VNC Desktop Sharing on Ubuntu Desktop 14.04

    Solution 1 sudo apt-get -y install dconf-tools dconf write /org/gnome/desktop/remote-access/require- ...

  7. ci总结

    1.创建模型,在模型中加载$this->load->database();2.在模型中写入想实现的功能方法3.在控制器中加载辅助函数和模型,$this->load->model ...

  8. 【题解】【直方图】【Leetcode】Trapping Rain Water

    Given n non-negative integers representing an elevation map where the width of each bar is 1, comput ...

  9. 数组右移(C++)

    数组A,右移k位,要求在线性时间内完成. #include <iostream> using namespace std; template <typename T> void ...

  10. HOG 梯度方向直方图简介(转载)

    一.基本HOG算法 HOG特征最早出现在SIFT算法中,由于其极强的图像特征描述能力,逐渐被人们熟知和广泛运用,其在目标检测方面表现尤为突出. HOG特征提取过程 步骤一:遍历图像每个像素点,以其为中 ...