偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

Unity3D 游戲引擎之回饋iOS高級(jí)界面消息

移動(dòng)開(kāi)發(fā) iOS 游戲開(kāi)發(fā)
上一章介紹了IOS高級(jí)界面向Unity3D 發(fā)送消息與Unity3D 接收消息的過(guò)程,有去的消息當(dāng)然要有回的消息這樣的過(guò)程才算完美,本章MOMO向大家介紹Unity3D消息的回饋。

 上一章介紹了IOS高級(jí)界面向Unity3D 發(fā)送消息與Unity3D 接收消息的過(guò)程,有去的消息當(dāng)然要有回的消息這樣的過(guò)程才算完美,本章MOMO向大家介紹Unity3D消息的回饋。

 

如下圖所示,本章我們的目標(biāo)是在Unity3D 界面中添加兩個(gè)GUI按鈕,并且在iPhone上點(diǎn)擊這兩個(gè)按鈕后分別彈出兩個(gè)IOS 高級(jí)界面的對(duì)話框。相信盆友們對(duì)GUI應(yīng)該不會(huì)太陌生,在這里我在前調(diào)一下GUI就是Unity3D 提供的一套UI系統(tǒng)。圖中的兩個(gè)UI 按鈕我就是用GUI做出來(lái)的。

 

 

 

 

 

 

Project欄目中創(chuàng)建一個(gè)c#腳本,命名為Main.cs ,之前沒(méi)有使用過(guò) C#寫腳本,今天我用C#來(lái)寫這個(gè)腳本,哇咔咔~~~ 如下圖所示將腳本拖動(dòng)在攝像機(jī)上,腳本中聲明兩個(gè)Texture 類型變量用來(lái)保存按鈕繪制的圖片資源。

 

 

 

 

 

 

Main.cs 代碼 

 

[代碼]c#/cpp/oc代碼:

01 using UnityEngine; 
02 using System.Collections; 
03    
04 public class Main : MonoBehaviour { 
05    
06 //聲明兩個(gè)Texture變量,圖片資源在外面連線賦值 
07 public Texture Button0; 
08 public Texture Button1; 
09    
10     // Use this for initialization 
11     void Start () { 
12        
13     } 
14        
15     // Update is called once per frame 
16     void Update () { 
17        
18     } 
19        
20     //這個(gè)方法用于繪制 
21     void OnGUI() { 
22         //繪制兩個(gè)按鈕 
23         if(GUI.Button(new Rect(0,44,120,120),Button0)) 
24         { 
25             //返回值為ture說(shuō)明這個(gè)按鈕被點(diǎn)擊 
26             SDK.ActivateButton0(); 
27         }    
28            
29         //繪制兩個(gè)按鈕 
30         if(GUI.Button(new Rect(200,44,120,120),Button1)) 
31         { 
32             //返回值為ture說(shuō)明這個(gè)按鈕被點(diǎn)擊 
33             SDK.ActivateButton1(); 
34         }    
35     } 
36 }

這里詳細(xì)說(shuō)一下SDK這個(gè)類,這個(gè)類我們看作它是一個(gè)管理類,它不賦值在任意對(duì)象身上,只接受調(diào)用管理,點(diǎn)擊兩個(gè)按鈕后將分別調(diào)用下面方法中的_ActivateButton0() 與 _ActivateButton1(),而這兩個(gè)方法則是去調(diào)用xcode 我們自己實(shí)現(xiàn)的方法_pressButton0() 與 _pressButton1(), 前提上須下面代碼中的注冊(cè),這樣子導(dǎo)出項(xiàng)目的時(shí)候xcode會(huì)幫我們 生成注冊(cè)信息,我們只須要實(shí)現(xiàn)這兩個(gè)方法就可以了。

 

SDK.cs 代碼

 

[代碼]c#/cpp/oc代碼:

01 using UnityEngine; 
02 using System.Runtime.InteropServices; 
03    
04 public class SDK 
05
06         
07      //導(dǎo)出按鈕以后將在xcode項(xiàng)目中生成這個(gè)按鈕的注冊(cè), 
08      //這樣就可以在xocde代碼中實(shí)現(xiàn)這個(gè)按鈕點(diǎn)擊后的事件。 
09      [DllImport("__Internal")] 
10      private static extern void _PressButton0 (); 
11         
12      public static void ActivateButton0 () 
13      { 
14            
15         if (Application.platform != RuntimePlatform.OSXEditor)  
16         { 
17             //點(diǎn)擊按鈕后調(diào)用xcode中的 _PressButton0 ()方法, 
18             //方法中的內(nèi)容須要我們自己來(lái)添加 
19             _PressButton0 (); 
20         } 
21      } 
22         
23      //和上面一樣 
24      [DllImport("__Internal")] 
25      private static extern void _PressButton1 (); 
26         
27      public static void ActivateButton1 () 
28      { 
29         if (Application.platform != RuntimePlatform.OSXEditor)  
30         { 
31             _PressButton1 (); 
32         } 
33      } 
34    
35 }

這樣子Unity3D 部分已經(jīng)完成,將Untiy3D項(xiàng)目導(dǎo)出成Xcode項(xiàng)目,我們用Xcode打開(kāi)它。添加Unit3D中GUI按鈕點(diǎn)擊后的響應(yīng)事件。創(chuàng)建一個(gè)類命名為 MyView.h 、MyView.m,用它來(lái)接收Unity3D 回饋回來(lái)的消息,_PressButton0 與 _PressButton1 這兩個(gè)方法在Unity3D中已經(jīng)注冊(cè)過(guò),所以在這個(gè)類中我們須要對(duì)它進(jìn)行Xcode中的實(shí)現(xiàn)。

 

 

MyView.m

 

[代碼]c#/cpp/oc代碼:

01 #import "MyView.h"   
02    
03    
04 @implementation MyView   
05    
06 //接收Unity3D 傳遞過(guò)來(lái)的信息 
07    
08 void _PressButton0() 
09
10     UIAlertView *alert = [[UIAlertView alloc] init]; 
11     [alert setTitle:@"雨松MOMO程序世界"]; 
12     [alert setMessage:@"點(diǎn)擊了第一個(gè)按鈕"]; 
13     [alert addButtonWithTitle:@"確定"]; 
14     [alert  show];   
15     [alert release]; 
16
17    
18 void _PressButton1() 
19
20        
21     UIAlertView *alert = [[UIAlertView alloc] init]; 
22     [alert setTitle:@"雨松MOMO程序世界"]; 
23     [alert setMessage:@"點(diǎn)擊了第二個(gè)按鈕"]; 
24     [alert addButtonWithTitle:@"確定"]; 
25     [alert  show];   
26     [alert release]; 
27
28 @end

OK大功告成,連上真機(jī)運(yùn)行我們的項(xiàng)目,我們?cè)趇Phone中點(diǎn)擊了Unity3D 中GUI這兩個(gè)按鈕后,通過(guò)消息的回饋?lái)樌膹棾鯥OS高級(jí)界面 的對(duì)話框,哇咔咔~


 

 

 

 

責(zé)任編輯:冰凝兒
相關(guān)推薦

2012-12-24 08:56:15

iOSUnity3D

2012-12-24 08:40:12

2012-12-24 08:46:50

iOSUnity3D

2012-12-24 09:01:41

iOSUnity3D

2012-12-24 08:48:25

iOSUnity3D

2012-12-24 08:50:21

iOSUnity3D

2012-12-24 09:04:04

iOSUnity3D

2012-12-24 08:52:44

iOSUnity3D

2012-12-24 08:59:13

iOSUnity3D

2012-12-24 08:45:19

iOSUnity3D

2012-12-24 08:51:23

iOSUnity3D

2012-12-24 08:54:47

iOSUnity3D

2012-12-24 09:06:14

iOSUnity3D

2012-12-24 09:07:09

iOSUnity3D

2013-04-25 00:06:06

unity3D手機(jī)游戲引擎

2012-12-24 09:11:58

iOSUnity3D

2012-12-24 09:00:31

iOSUnity3D

2012-12-24 09:09:27

AndoidUnity3D

2012-12-24 09:02:48

iOSUnity3D

2013-04-25 09:56:24

unity3D手機(jī)游戲引擎
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)