JSBinding + SharpKit / Important Notes

Serialization of List<T> is not supported.

public List<int> lst; // NOT supported, use int[] instead

 

About menu: 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 }

 

Coroutine is not supported.

you have to re-write yield code before compilint C# script to JavaScript. NOTE. JavaScript itself does support yield instruction, but can not work seamless with SharpKit.

 

Better not 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

 

[] is now treated as 'input', or '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 //

 

Limited supported to 'SendMessage'

Member functions of JSComponent 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.

Commonly sent messages

  • OnCollisionEnter
  • OnCollisionExit
  • OnCollisionStay
  • OnTriggerEnter
  • OnTriggerExit
  • OnTriggerStay
  • OnCollisionEnter2D
  • OnCollisionExit2D
  • OnCollisionStay2D
  • OnTriggerEnter2D
  • OnTriggerExit2D
  • OnTriggerStay2D

For a full list, see Messages section in http://docs.unity3d.com/ScriptReference/MonoBehaviour.html

 

InvokeRepeating is not supported

mmm 

 

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

你可能感兴趣的:(import)