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

转载于:https://www.cnblogs.com/answerwinner/p/4591248.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值