unity3d游戏开发之回馈IOS高等界面消息.docVIP

  • 1
  • 0
  • 约2.66千字
  • 约 6页
  • 2018-05-25 发布于贵州
  • 举报

unity3d游戏开发之回馈IOS高等界面消息.doc

unity3d游戏开发之回馈IOS高等界面消息

上一章介绍了IOS高级界面向? ? ?? ? Project栏目中创建一个c#脚本,命名为Main.cs ,之前没有使用过 C#写脚本,今天我用C#来写这个脚本,哇咔咔~~~ 如下图所示将脚本拖动在摄像机上,脚本中声明两个Texture 类型变量用来保存按钮绘制的图片资源。 ? ? ? ?? ?? ?? ?? ?? ?? ?? ?? ?? ??? ? ?? ? Main.cs 代码? using UnityEngine; using System.Collections; ?? public class Main : MonoBehaviour { ?? //声明两个Texture变量,图片资源在外面连线赋值 public Texture Button0; public Texture Button1; ?? ? ? // Use this for initialization ? ? void Start () { ?? ? ? } ?? ? ? // Update is called once per frame ? ? void Update () { ?? ? ? } ?? ? ? //这个方法用于绘制 ? ? void OnGUI() { ? ?? ???//绘制两个按钮 ? ?? ???if(GUI.Button(new Rect(0,44,120,120),Button0)) ? ?? ???{ ? ?? ?? ?? ?//返回值为ture说明这个按钮被点击 ? ?? ?? ?? ?SDK.ActivateButton0(); ? ?? ???}? ? ?? ? ?? ???//绘制两个按钮 ? ?? ???if(GUI.Button(new Rect(200,44,120,120),Button1)) ? ?? ???{ ? ?? ?? ?? ?//返回值为ture说明这个按钮被点击 ? ?? ?? ?? ?SDK.ActivateButton1(); ? ?? ???}? ? ? ? } } using UnityEngine; using System.Runtime.InteropServices; ?? public class SDK { ?? ? ???//导出按钮以后将在xcode项目中生成这个按钮的注册, ? ???//这样就可以在xocde代码中实现这个按钮点击后的事件。 ? ???[DllImport(__Internal)] ? ???private static extern void _PressButton0 (); ?? ? ???public static void ActivateButton0 () ? ???{ ?? ? ?? ???if (Application.platform != RuntimePlatform.OSXEditor) ? ?? ???{ ? ?? ?? ?? ?//点击按钮后调用xcode中的 _PressButton0 ()方法, ? ?? ?? ?? ?//方法中的内容须要我们自己来添加 ? ?? ?? ?? ?_PressButton0 (); ? ?? ???} ? ???} ?? ? ???//和上面一样 ? ???[DllImport(__Internal)] ? ???private static extern void _PressButton1 (); ?? ? ???public static void ActivateButton1 () ? ???{ ? ?? ?? ?if (Application.platform != RuntimePlatform.OSXEditor) ? ?? ???{ ? ?? ?? ?? ?_PressButton1 (); ? ?? ???} ? ???} ?? } 复制代码 ? ?? ? 这样子Unity3D 部分已经完成,将Untiy3D项目导出成Xcode项目,我们用Xcode打开它。添加Unit3D中GUI按钮点击后的响应事件。创建一个类命名为MyView.h 、MyView.m,用它来接收Unity3D 回馈回来的消息,_PressButton0 与 _PressButton1 这两个方法在Unity3D中已经注册过,所以在这个类中我们须要对它进行Xcode中的实现。 ? ?? ? MyView.m #import MyView.h?? ?? @implementation MyView?? ?? //接收Unity3D 传递过来的信息 ?? void _PressButton0() { ? ? UIAlertView *alert = [[UIAlertView alloc]

文档评论(0)

1亿VIP精品文档

相关文档