JSBinding + SharpKit / Important Notes
2015-06-20 23:21
639 查看
Serialization of List<T> is not supported.
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.
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.
Array is now treated as 'input' (readonly) when calling C# function from JavaScript.
Only 1 demension array is supported (JS <-> CS).
Debug.Log(): Explicitly call ToString() for string parameter.
Generic Type including another Generic Type is not supported.
For example,
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
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.
using UnityEngine; using System.Collections; using SharpKit.JavaScript; [JsType(JsMode.Clr,"../../StreamingAssets/JavaScript/SharpKitGenerated/2DPlatformer/Scripts/Gun.javascript")] public class Gun : MonoBehaviour { public GameObject rocketGO; // Prefab of the rocket. public float speed = 20f; // The speed the rocket will fire at. //........ }
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.
UnityEngine.Object obj = ...; GameObject go = obj as GameObject; // DON'T do this GameObject go = (GameObject)obj; // GREAT
Array is now treated as 'input' (readonly) when calling C# function from JavaScript.
// C# void ModifyArray(int[] arr) { for (var i = 0; i < arr.Length; i++) arr[i] = i; } // JS var arr = [5,2,3,2]; ModifyArray(arr); // call C# function // // arr is still [5,2,3,2] !! //
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
相关文章推荐
- javascript学习笔记(一)--初识javascript
- 欢迎使用CSDN-markdown编辑器
- 黑马day06 jsp错误页面&九大隐式对象
- JSBinding + SharpKit / Home
- JavaScript入门-第1章 请做好准备
- json 是个什么东西?
- json_encode详解,转义
- js中this的指向
- js加载器动态加载外部Javascript文件
- json_encode
- json跨域
- json最简单的跨域
- 使用debug.js调试手机网页
- C#.NET序列化XML、JSON、二进制微软自带DLL与newtonsoft(json.net)
- 背景渐变 兼容IE
- 多行文本超出 JS省略号...
- HTML页面交互(JavaScript、PHP)
- Javascript的一个生产PDF的库: unicode和中文问题的解决
- javascript的内置对象
- [LeetCode][JavaScript]Copy List with Random Pointer