unity针对iphone的屏幕旋转

屏幕旋转可以在引擎里设置:

依次点开 Edit——Project Setting——Player 即可设置如图:

unity针对iphone的屏幕旋转

 

接下来的是 雨松大神的 代码控制,本屌是安卓机器,没能测试。

C#

using UnityEngine;

using System.Collections;

 

public class Main : MonoBehaviour {

 

    //键盘输入

    private iPhoneKeyboard keyboard;

 

    //字体皮肤

    public GUISkin fontSkin;  

 

    // Use this for initialization

    void Start () {

    }

 

    // Update is called once per frame

    void Update () {

    }

 

    void OnGUI() {

        //设置皮肤

        GUI.skin = fontSkin;  

 

        //强制屏幕纵向

        if (GUI.Button(new Rect(10, 10, 300, 100), "change LandscapeLeft"))  {  

                  Screen.orientation = ScreenOrientation.LandscapeLeft;

        }else if (GUI.Button(new Rect(10, 110, 300, 100), "change LandscapeRight"))  {  

                Screen.orientation = ScreenOrientation.LandscapeRight;

        }else 

 

        //强制屏幕横向

        if (GUI.Button(new Rect(10, 210, 300, 100), "change Portrait"))  {  

                Screen.orientation = ScreenOrientation.Portrait;

        }else if (GUI.Button(new Rect(10, 310, 300, 100), "change PortraitUpsideDown"))  {  

                  Screen.orientation = ScreenOrientation.PortraitUpsideDown;

        }   

 

        if (GUI.Button(new Rect(320, 10, 300, 100), "open Keyboard"))  { 

              //打开iphone输入框

              //第一个参数 默认显示 test

              //第二个参数 设置输入框类型,这里为默认,什么都可以输入

              keyboard = iPhoneKeyboard.Open("test",iPhoneKeyboardType.Default);

 

        }

 

        if(keyboard != null){

 

            if (keyboard.done){

                //输入完毕后 点击done 输入输入内容

                Debug.Log( keyboard.text)    ;

            }    

        }

 

    }

}

前辈还提供了 键盘的一些常用属性:

iPhoneKeyboardType.Default 默认键盘

iPhoneKeyboardType.NumbersAndPunctuation : 输入标点符号与数字

iPhoneKeyboardType.URL:输入网址

iPhoneKeyboardType.PhonePad:输入电话

iPhoneKeyboardType.NumberPad:输入数字

iPhoneKeyboardType.EmailAddress:输入Email

你可能感兴趣的:(iPhone)