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. uitabbarcontroller中 在设置tab bar item的image属性后不显示问题

    开始使用ios中的UITabBarController,在给Tab Bar Item设置自定义图片的时候,遇到了问题 按照如下配置: 出来的结果确是: 实际上test24.png应该是: 纠结了很久, ...

  2. JSON.parse()和JSON.stringify() 的用法区别

    parse用于从一个字符串中解析出json对象,如 var str = '{"name":"huangxiaojian","age":&qu ...

  3. LeetCode----Word Ladder 2

    Given two words (start and end), and a dictionary, find all shortest transformation sequence(s) from ...

  4. 多数求和(java)

    实验题目:从命令行接受多个数字,求和之后输出结果. 设计思想:命令行输入的字符会赋值给args数组,所以在命令行输入数字后,直接取出args的数组长度,作为循环语句的终点判断,然后利用循环将字符型改为 ...

  5. win下隐藏任务栏

    C# 隐藏任务栏开始按钮 关闭shell 分类: .NET C# 2011-07-14 15:26 789人阅读 评论(1) 收藏 举报 shell任务c#stringnulluser 一.隐藏任务栏 ...

  6. 任意阶魔方阵(幻方)的算法及C语言实现

    写于2012.10: 本来这是谭浩强那本<C程序设计(第四版)>的一道课后习题,刚开始做得时候去网上找最优的算法,结果发现奇数和双偶数(4的倍数)的情况下算法都比较简单,但是单偶数(2的倍 ...

  7. ERP登录(八)

    登录的存储过程: ALTER PROCEDURE [dbo].[UserLogin] @userid int output, @LoginName nvarchar(50), @Password nv ...

  8. Bash简介

    Bash(GNU bourne-Again Shell)是一个为GNU计划编写的Unix shell,它是很多Linux平台默认的使用的shell. shell是一个命令解析器,是介于操作系统内核与用 ...

  9. 6、C#基础整理(for 语句经典习题--for循环嵌套、穷举)

    1.for循环嵌套----最基础题目:求阶乘的和 ; int n = int.Parse(Console.ReadLine()); ; i < n; i++) { ;//定义变量sum1,每次循 ...

  10. HDU 5067

    http://acm.hdu.edu.cn/showproblem.php?pid=5067 规定起点和终点的tsp问题,解法依然是状态压缩dp,在初始化和计算答案的时候略做改动即可 #include ...