JSBinding + SharpKit / 实战:转换 Survival Shooter
从 asset store 下载 Survival Shooter
(商店里有2个版本,一种是给Unity5用的,一个是给Unity4.6用的,我们这个实验用的是后者,版本是2.2。如果)
1 删除多余的代码及文件夹
- /Scripts/ <-- 因为没有用
- /Scenes/ <-- 因为是空的
- /Animation/ <-- 因为是空的
- /Prefabs/Hellephant.prefab <-- 因为没有用
- /Prefabs/ZomBear.prefab <-- 因为没有用
删完后应该是这样的:
2 【JSB | Generate CS and JS Bindings】
这里给出的是 Survival Shooter 所有到的类型,可以将这个数组替换掉代码中的 JSBindingSettings.classes 数组。
应该是不改也可以,因为代码里 JSBindingSettings.classes 数组已经包含下面这些类了。
public static Type[] classes = new Type[] { typeof(PerTest), typeof(PerTest.RefObject), typeof(Debug), typeof(Input), typeof(GameObject), typeof(Transform), typeof(Vector2), typeof(Vector3), typeof(MonoBehaviour), typeof(Behaviour), typeof(Component), typeof(UnityEngine.Object), typeof(YieldInstruction), typeof(WaitForSeconds), typeof(WWW), typeof(Application), typeof(UnityEngine.Time), typeof(Resources), typeof(TextAsset), typeof(IEnumerator), typeof(List<>), typeof(List<>.Enumerator), typeof(Dictionary<,>), typeof(Dictionary<,>.KeyCollection), typeof(Dictionary<,>.ValueCollection), typeof(Dictionary<,>.Enumerator), typeof(KeyValuePair<,>), typeof(System.Diagnostics.Stopwatch), typeof(UnityEngine.Random), typeof(StringBuilder), typeof(System.Xml.XmlNode), typeof(System.Xml.XmlDocument), typeof(System.Xml.XmlNodeList), typeof(System.Xml.XmlElement), typeof(System.Xml.XmlLinkedNode), typeof(System.Xml.XmlAttributeCollection), typeof(System.Xml.XmlNamedNodeMap), typeof(System.Xml.XmlAttribute), typeof(UnityEngine.Camera), typeof(UnityEngine.Light), typeof(UnityEngine.Color), typeof(UnityEngine.Ray), typeof(UnityEngine.LayerMask), typeof(UnityEngine.RaycastHit), typeof(UnityEngine.AudioClip), typeof(UnityEngine.AudioSource), typeof(UnityEngine.Rigidbody), typeof(UnityEngine.Animator), typeof(UnityEngine.Renderer), typeof(UnityEngine.LineRenderer), typeof(UnityEngine.ParticleSystem), typeof(UnityEngine.Physics), typeof(UnityEngine.Quaternion), typeof(UnityEngine.Collider), typeof(UnityEngine.CapsuleCollider), typeof(UnityEngine.NavMeshAgent), typeof(UnityEngine.MeshCollider), typeof(UnityEngine.BoxCollider), typeof(UnityEngine.SphereCollider), // // Unity 4_6 // typeof(UnityEngine.EventSystems.IEventSystemHandler), typeof(UnityEngine.EventSystems.IPointerEnterHandler), typeof(UnityEngine.EventSystems.IPointerExitHandler), typeof(UnityEngine.EventSystems.IPointerDownHandler), typeof(UnityEngine.EventSystems.IPointerUpHandler), typeof(UnityEngine.EventSystems.IPointerClickHandler), typeof(UnityEngine.EventSystems.IBeginDragHandler), typeof(UnityEngine.EventSystems.IInitializePotentialDragHandler), typeof(UnityEngine.EventSystems.IDragHandler), typeof(UnityEngine.EventSystems.IEndDragHandler), typeof(UnityEngine.EventSystems.IDropHandler), typeof(UnityEngine.EventSystems.IScrollHandler), typeof(UnityEngine.EventSystems.IUpdateSelectedHandler), typeof(UnityEngine.EventSystems.ISelectHandler), typeof(UnityEngine.EventSystems.IDeselectHandler), typeof(UnityEngine.EventSystems.IMoveHandler), typeof(UnityEngine.EventSystems.ISubmitHandler), typeof(UnityEngine.EventSystems.ICancelHandler), typeof(UnityEngine.UI.ICanvasElement), typeof(UnityEngine.UI.IMask), typeof(UnityEngine.UI.IMaskable), typeof(UnityEngine.UI.ILayoutElement), typeof(UnityEngine.UI.ILayoutController), typeof(UnityEngine.UI.ILayoutGroup), typeof(UnityEngine.UI.ILayoutSelfController), typeof(UnityEngine.UI.ILayoutIgnorer), typeof(UnityEngine.UI.IMaterialModifier), typeof(UnityEngine.UI.IVertexModifier), typeof(UnityEngine.EventSystems.UIBehaviour), typeof(UnityEngine.Events.UnityEventBase), typeof(UnityEngine.Events.UnityEvent<>), typeof(UnityEngine.Canvas), typeof(UnityEngine.Events.UnityEvent), typeof(UnityEngine.UI.AnimationTriggers), typeof(UnityEngine.UI.Button), typeof(UnityEngine.UI.Button.ButtonClickedEvent), typeof(UnityEngine.UI.CanvasUpdateRegistry), typeof(UnityEngine.UI.FontUpdateTracker), typeof(UnityEngine.UI.Graphic), // typeof(UnityEngine.UI.GraphicRaycaster), typeof(UnityEngine.UI.GraphicRebuildTracker), typeof(UnityEngine.UI.GraphicRegistry), typeof(UnityEngine.UI.Image), typeof(UnityEngine.UI.InputField), typeof(UnityEngine.UI.InputField.SubmitEvent), typeof(UnityEngine.UI.InputField.OnChangeEvent), typeof(UnityEngine.UI.MaskableGraphic), typeof(UnityEngine.UI.RawImage), typeof(UnityEngine.UI.Scrollbar), typeof(UnityEngine.UI.Scrollbar.ScrollEvent), typeof(UnityEngine.UI.ScrollRect), typeof(UnityEngine.UI.ScrollRect.ScrollRectEvent), typeof(UnityEngine.UI.Selectable), typeof(UnityEngine.UI.Slider), typeof(UnityEngine.UI.Slider.SliderEvent), typeof(UnityEngine.UI.StencilMaterial), typeof(UnityEngine.UI.Text), typeof(UnityEngine.UI.Toggle), typeof(UnityEngine.UI.Toggle.ToggleEvent), typeof(UnityEngine.UI.ToggleGroup), typeof(UnityEngine.UI.AspectRatioFitter), typeof(UnityEngine.UI.CanvasScaler), typeof(UnityEngine.UI.ContentSizeFitter), typeof(UnityEngine.UI.GridLayoutGroup), typeof(UnityEngine.UI.HorizontalLayoutGroup), typeof(UnityEngine.UI.HorizontalOrVerticalLayoutGroup), typeof(UnityEngine.UI.LayoutElement), typeof(UnityEngine.UI.LayoutGroup), typeof(UnityEngine.UI.LayoutUtility), typeof(UnityEngine.UI.VerticalLayoutGroup), typeof(UnityEngine.UI.Mask), typeof(UnityEngine.UI.BaseVertexEffect), typeof(UnityEngine.UI.Outline), typeof(UnityEngine.UI.PositionAsUV1), typeof(UnityEngine.UI.Shadow), };
3 执行菜单:Mobile Input | Disable
4 添加 Coroutine-Update 的代码到文件中
// 文件
- EnemyManager.cs
// 要添加的代码
void LateUpdate() { jsimp.Coroutine.UpdateCoroutineAndInvoke(this); }
5 Joystick.cs 类定义改成:(之前逗号有问题导致不能正确添加 JsType 标签)
public class Joystick : MonoBehaviour, IPointerUpHandler, IPointerDownHandler, IDragHandler
6 BeautyShot.cs 去掉所有在 #if UNITY_EDITOR 里面的代码
7 往 JSComponent.cs 添加代码 (因为 他使用了 SendMessage 往 EnemyHealth.cs 发送消息,我们这段代码临时加):
// 添加这2个变量定义到类中 int idStartSinking; int idRestartLevel; // 添加这2个成员初始化到函数 initMemberFunction 中 idStartSinking = JSApi.getObjFunction(jsObjID, "StartSinking"); idRestartLevel = JSApi.getObjFunction(jsObjID, "RestartLevel"); // 添加这2个函数到类中 void StartSinking() { callIfExist(idStartSinking); } void RestartLevel() { callIfExist(idRestartLevel); }
8 执行菜单:【JSB | Add SharpKit JsType Attribute for all Structs and Classes】
这一步是往需要的类前面加上 [JsType] 标签。
9 编译 SharpKit 工程
如果还没有安装 SharpKit 及配置 SharpKit,请参考 http://www.cnblogs.com/answerwinner/p/4469073.html
10 【JSB | Replace All Monos for all Prefabs and Scenes】
_CompletedAssets/Prefabs/Hellephant.prefab _CompletedAssets/Prefabs/Player.prefab _CompletedAssets/Prefabs/ZomBear.prefab _CompletedAssets/Prefabs/ZomBunny.prefab Prefabs/Environment.prefab Prefabs/GunParticles.prefab Prefabs/Hellephant.prefab Prefabs/HitParticles.prefab Prefabs/Lights.prefab Prefabs/ZomBear.prefab _CompletedAssets/Scenes/Level 01.unity
11 【JSB | Correct JavaScript Yield code】
12 【JSB | Generate MonoBehaviour to JSComponent_XX】
posted on 2015-07-29 21:51 AnswerWinner 阅读(794) 评论(0) 编辑 收藏 举报