Unity—Input

Unity Input常用类&函数:

 TouchScreenKeyboard.Open("", TouchScreenKeyboardType.Default, false, false, true);

        Input.GetKey(KeyCode.A);

        Touch [] touch =Input.touches;


       if( Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began) { }

1.Input.touches 触摸列表

JavaScript ⇒ public static var touches: Touch[];
C# ⇒ public static Touch[] touches;

Description 描述

Returns list of objects representing status of all touches during last frame. (Read Only) (Allocates temporary variables).

返回代表上一帧所有的触摸状态的对象列表(只读)(分配临时变量)

Each entry represents a status of a finger touching the screen.

每个记录都代表着一个手指在屏幕上的触碰状态。

using UnityEngine;
using System.Collections;
 
public class ExampleClass : MonoBehaviour {
    void Update() {
        int fingerCount = 0;
        foreach (Touch touch in Input.touches) {
            if (touch.phase != TouchPhase.Ended && touch.phase != TouchPhase.Canceled)
                fingerCount++;
 
        }
        if (fingerCount > 0)
            print("User has " + fingerCount + " finger(s) touching the screen");
 
    }
}

2.TouchScreenKeyboard 触摸屏键盘

class in UnityEngine

Description 描述

Interface into the native iPhone, Android, Windows Phone and Windows Store Apps on-screen keyboards - it is not available on other platforms.

连接到本机iPhone、 Android、 Windows Phone 和 Windows 应用商店应用程序屏幕键盘-不是在其他平台上可用。

This interface allows to display different types of the keyboard: ASCII, Numbers, URL, Email, and others.

此接口允许显示不同类型的键盘︰ ASCII、 数字、 URL、 电子邮件,和其他的符号。

Because the appearance of the keyboard has the potential to obscure portions of your user interface, it is up to you to make sure that parts of your user interface are not obscured when the keyboard is being displayed.

因为键盘的外形有可能掩盖你的用户界面部分,它是由你来确保您的用户界面部分的键盘在显示时不会被遮盖。

TouchScreenKeyboard.visible and TouchScreenKeyboard.area should be used to determine if the keyboard is being shown (activated) and what portion of the screen is using.

TouchScreenKeyboard.visible和TouchScreenKeyboard.area应该用于决定是否显示(激活)该键盘并且使用屏幕的哪部分。

Static Variables 静态变量

area Returns portion of the screen which is covered by the keyboard.
返回键盘覆盖的屏幕部分。
hideInput Will text input field above the keyboard be hidden when the keyboard is on screen?
当键盘在屏幕上时,该属性将会决定是否隐藏键盘上的文本输入区域。
isSupported Is touch screen keyboard supported.
是否支持触摸屏键盘。
visible Returns true whenever any keyboard is completely visible on the screen.
无论任何键盘在屏幕上完全可见都返回true。

Variables 变量

active Is the keyboard visible or sliding into the position on the screen?
是否键盘可见或滑动到屏幕上的位置吗?
done Specifies if input process was finished. (Read Only)
指定是否输入的过程结束。(只读)
targetDisplay Specified on which display the software keyboard will appear.
指定显示的键盘将会出现。
text Returns the text displayed by the input field of the keyboard.
返回显示键盘输入区域的文本。
wasCanceled Specifies if input process was canceled. (Read Only)
指定是否取消输入进程(只读)。

Static Functions 静态函数

Open Opens the native keyboard provided by OS on the screen.
打开操作系统提供的本地键盘。
余生很长,愿我们都活成自己喜欢的样子
原文地址:https://www.cnblogs.com/bananana/p/8867492.html