- 1、本文档共6页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
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)