版本 |
作者 |
参与者 |
完成日期 |
备注 |
UnityAPI_Input_V01_1.0 |
严立钻 |
|
2020.06.18 |
|
|
|
|
|
|
立钻哥哥:Unity是一个入门快、提高难的游戏引擎,想要提升能力,至少需要越过3道坎:API+Shader+综合能力;++1、API的积累:对API的合理利用不仅可以减轻自己的编码负担,而且往往可以提高程序的运行效率;这也是钻哥开始“Unity API”独立打造分类的初衷; ++2、Shader编程:想要做出一款精品游戏往往需要有高效的Shader的支持;Unity提供了一套改良的“Shader Lab”系统,优化了繁杂的“Open GL”编程; ++3、综合能力(技术+业务+管理):一款产品的制作除了功能编程外,往往会涉及很多其他领域,例如产品架构、UI交互设计、模型制作等,作为主要的编程人员,对其他相关领域的了解程序往往会影响到产品制作直至最后的产品体验; ++++立钻哥哥一直在推动【VR云游戏=Unity+SteamVR+云技术+5G+AI】,这个只是一个引子,抛砖引玉让大家对整个知识体系有一个明确的落地方向,宝宝们可以根据自己的兴趣方向进行拓展:比如Unity这里是指一种“3D游戏引擎”,也可拓展至“UE4、Cocos2dx”等游戏引擎;SteamVR是一种跨硬件解决方案,也可拓展至“VRTK”等第三方插件;“云技术+5G”是一种跨平台解决方案的核心技术,同样可拓展至其他平台解决方案;AI也是一种先进技术的举例,也可以拓展至任何一种前沿技术; |
++++【Unity API】分类:https://blog.csdn.net/vrunsoftyanlz/category_7637520.html
++++【Unity开发基础】分类:https://blog.csdn.net/vrunsoftyanlz/category_7309057.html
++++【Linux系统编程】分类:https://blog.csdn.net/vrunsoftyanlz/category_9694767.html
++++【C++C铸就生存利器】分类:https://blog.csdn.net/vrunsoftyanlz/category_9325802.html
++++【人工智能AI2026】分类:https://blog.csdn.net/vrunsoftyanlz/category_9212024.html
++++【立钻哥哥CSDN空间】:https://blog.csdn.net/VRunSoftYanlz/
#Input输入 |
#Input输入++A1、Description描述++B2、Variables变量++C3、Public Function共有函数++D4、Message消息 |
#A1、Description描述 |
++++使用这个类能够读取输入管理器设置的按键,以及访问移动设备的多点触控或加速感应数据;
++++想要读取轴向使用Input.GetAxis方法获取默认值:“Horizontal”和“Vertical”映射于控制杆、A、W、S、D和箭头键(方向键);“Mouse X”和“Mouse Y”映射于鼠标,“Fire1”,“Fire2”,“Fire3”映射于键盘的Ctrl、Alt、Cmd键和鼠标中键或控制器的按钮;新的输入设置可以使用输入管理器来添加;
++++如果使用Input制作某种运动作为可以使用Input.GetAxis方法,它能够返回来自键盘、控制器或鼠标平缓并且可以设置的输入结果;使用Input.GetButton方法只用于像事件之类的动作;不要将它用于移动动作;Input.GetAxis方法可以使脚本代码更简洁;
++++注意:每次输入的“Update()”之前不会再更新,所以建议将所有的输入调用都写在Update方法中;(Update循环中);
++++[移动设备(Mobile Devices)]:iOS和Android设备能够支持多点触控;可以通过Input.touches属性集合访问在最近一帧中触摸在屏幕上的每一根手指的状态数据;
++++当设备移动时,它们的加速感应器硬件将报告它们在三维空间中沿着三个主轴的线性加速变化数据;可以使用这些数据检测设备当前的移动方向(相对于地面)和突然间的方向改变;
++++硬件沿着某感应一轴加速就会立即返回重力值;如果值为1.0代表沿着给定轴的方向+1g的重力加速度,如果值为-1.0代表-1g的重力加速度;如果保持设备垂直(主页键在下方)在正前方,那么X轴就是指向右侧的方向,Y轴指向正上方,Z轴就是所面向的方向;
++++可以读取Input.acceleration属性获得设备的加速度信息;也可以使用Input.deviceOrientation属性获取设备在三维空间中的方位偏移;检测方位变化在想要制作游戏行为中会非常有用,当用户转动设备或拿着设备时它是不同的;
++++注意:速度感应装置在每一帧中能够轮询多次,想访问上一帧的所有速度样本可以读取Input.accelerationEvents属性集合;这在重组玩家动作中会非常有用;例如将加速数据放入一个预测器中或者实现其他一些精确的动作捕捉;
#B2、Static Variables静态变量 |
++B2、Static Variables静态变量++++B2.1、acceleration++++B2.2、accelerationEventCount++++B2.3、accelerationEvents++++B2.4、anyKey++++B2.5、anyKeyDown++++B2.6、compass++++B2.7、compensateSensors++++B2.8、compositionCursorPos++++B2.9、compositionString++++B2.10、deviceOrientation++++B2.11、gyro++++B2.12、imeCompositionMode++++B2.13、imeIsSelected++++B2.14、inputString++++B2.15、location++++B2.16、mousePosition++++B2.17、mouseScrollDelta++++B2.18、multiTouchEnabled++++B2.19、simulateMouseWithTouches++++B2.20、touchCount++++B2.21、touches++++B2.22、touchSupported++++B2.23、YanlzXREngine.Input.StaticVariables |
++B2.1、acceleration |
public static Vector3 acceleration; |
++++上一次测量的设备在三维空间中的线性加速度(只读);
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzInput : MonoBehaviour{ public float speed = 10.0F;
void Update(){ Vector3 dir = Vector3.zero; dir.x = -Input.acceleration.y; dir.z = Input.acceleration.x;
if(dir.sqrMagnitude > 1){ dir.Normalize(); }
dir *= Time.deltaTime; transform.Translate(dir * speed);
} //立钻哥哥:void Update(){}
} //立钻哥哥:public class YanlzInput{} |
++B2.2、accelerationEventCount |
public static int accelerationEventCount; |
++++上一帧发生的所测量的加速度次数;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzInput : MonoBehaviour{
void Update(){ if(Input.accelerationEventCount > 0){ Debug.Log(“立钻哥哥:We got new acceleration measurements.”); } //立钻哥哥:if(){} } //立钻哥哥:void Update(){}
} //立钻哥哥:public class YanlzInput{} |
++B2.3、accelerationEvents |
public static AccelerationEvent[] accelerationEvents; |
++++返回上一帧测量的加速度数据列表(只读)(分配临时变量);
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzInput : MonoBehaviour{
void Update(){ Vector3 acceleration = Vector3.zero;
foreach(AccelerationEvent accEvent in Input.accelerationEvents){ acceleration += accEvent.acceleration * accEvent.deltaTime; } //立钻哥哥:foreach(){}
Debug.Log(acceleration);
} //立钻哥哥:void Update(){}
} //立钻哥哥:public class YanlzInput{} |
++B2.4、anyKey |
public static bool anyKey; |
++++当前是否有任意键或鼠标键被按下(只读)?
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzInput : MonoBehaviour{
void Update(){ if(Input.anyKey){ Debug.Log(“立钻哥哥:A key or mouse click has been detected.”); } //立钻哥哥:if(){} } //立钻哥哥:void Update(){}
} //立钻哥哥:public class YanlzInput{} |
++B2.5、anyKeyDown |
public static bool anyKeyDown; |
++++在用户按下任意按键或鼠标按键首帧返回true(只读);
++++可以在Update方法中轮流检测这个变量,该状态在每帧会得到复位;除非松开(释放)所有的按键/按钮然后再按下某个按键/按钮,否则不会返回true;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzInput : MonoBehaviour{
void Update(){ //if(Input.anyKey){ if(Input.anyKeyDown){ Debug.Log(“立钻哥哥:A key or mouse click has been detected.”); } //立钻哥哥:if(){} } //立钻哥哥:void Update(){}
} //立钻哥哥:public class YanlzInput{} |
++B2.6、compass |
public static Compass compass; |
++++访问指南针的属性(仅手持设备);
++B2.7、compensateSensors |
public static bool compensateSensors; |
++++该属性控制输入传感器在屏幕方向的补偿;
++++补偿传感器是加速度计、指南针、陀螺仪;注意:影响iOS全平台和部分Android平台(Android补偿目前无法关闭);
++B2.8、compositionCursorPos |
public static Vector2 compositionCursorPos; |
++++当前文本输入位置,使用于IME来打开窗口;
++++某些语言IME,例如日语,在用户输入文本时,将打开窗口,以帮助用户选择正确的输入字符串;这些窗口在当前光标位置弹出,因此输入法需要知道在哪里显示输入;当使用Unity内置GUI系统为文本输入,Unity将考虑为IME设置鼠标位置;然而,如果想要实现自己的图像用户界面用来文本输入,必须设置这个到当前文本输入位置,为使IME窗口正确显示;
++B2.9、compositionString |
public static string compositionString; |
++++当前用户正在输入的IME组合字符串;
++++在某些语言如中文,日文或韩文,文本是通过键入多个键输入来生成一个或多个字符;这些字符在屏幕上可视化组合,由用户键入;当使用Unity内置的GUI系统用于文本输入,Unity将考虑显示组合字符串,由用户键入;如果想实现自己的图形用户界面,必须考虑显示字符串在当前鼠标位置;当IME组合使用时,该组合字符串才更新;
++B2.10、deviceOrientation |
public static DeviceOrientation deviceOrientation; |
++++由操作系统所报告的设备的物理方向(只读);
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzInput : MonoBehaviour{
void Update(){ if(Input.deviceOrientation == DeviceOrientation.FaceDown){ audio.Play(); } //立钻哥哥:if(){} } //立钻哥哥:void Update(){}
} //立钻哥哥:public class YanlzInput{} |
++B2.11、gyro |
public static Gyroscope gyro; |
++++返回默认的陀螺仪;
++B2.12、imeCompositionMode |
public static IMECompositionMode imeCompositionMode; |
++++控制IME输入组合的启用和禁用;
++++一些语言使用复杂的输入方法,其中涉及到打开窗户插入字符;通常,玩游戏时这是不理想的,对于游戏可能只是解释按键作为游戏输入,而不是文本;默认,当在文本字段,Unity启用IME组合,并禁用其他的;然而,当想实现自己的输入图形用户界面,来替代这个控制,要使用到imeCompositionMode属性;可以设置为自动(默认行为),或开或关,明确地启用或禁用输入法组成;
++B2.13、imeIsSelected |
public static bool imeIsSelected; |
++++用户是否已选择IME键盘输入源?
++++如果用户键盘是当前配置的IME输入返回true,否则返回false;由于亚洲语言的用户通常可以把IME打开或关闭,这个用来提供IME启用的可视化提示,像这样做Input.imeIsSelected;
++B2.14、inputString |
public static string inputString; |
++++返回在这一帧的键盘输入(只读);
++++inputString中只包含ASCII码中的字符;
++++这个字符串中可以包含两个需要处理的特殊字符:字符“\b”代表回退键;字符“\n”代表返回或回车键;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzInput : MonoBehaviour{ public GUIText gt;
void Start(){ gt = GetComponent<GUIText>(); } //立钻哥哥:void Start(){}
void Update(){ foreach(char c in Input.inputString){ if(c == “\b”[0]){ if(gt.text.Length != 0){ gt.text = gt.text.Substring(0, gt.text.Length - 1); } //立钻哥哥:if(gt.text.Length != 0){} }else{ if(c == “\n”[0] || c == “\r”[0]){ Debug.Log(“立钻哥哥:User entered his name: ” + gt.text); }else{ gt.text += c; } //立钻哥哥:if(){}else{} } //立钻哥哥:if(){}else{} } //立钻哥哥:foreach(){} } //立钻哥哥:void Update(){}
} //立钻哥哥:public class YanlzInput{} |
++B2.15、location |
public static LocationService location; |
++++用于访问设备位置信息(仅手持设备)(只读);
++B2.16、mousePosition |
public static Vector3 mousePosition; |
++++在屏幕坐标空间当前鼠标的位置(只读);
++++屏幕或窗口的左下角是坐标系的(0,0)坐标;右上角的坐标是(屏幕宽度值,屏幕高度值);
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzInput : MonoBehaviour{ public GameObject particle;
void Update(){ if(Input.GetButtonDown(“Fire1”)){ Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if(Physics.Raycast(ray)){ Instantiate(particle, transform.position, transform.rotation) as GameObject; } //立钻哥哥:if(Physics.Raycast()){} } //立钻哥哥:if(Input.GetButtonDown()){} } //立钻哥哥:void Update(){}
} //立钻哥哥:public class YanlzInput{} |
++B2.17、mouseScrollDelta |
public static Vector2 mouseScrollDelta; |
++++当前鼠标滚动增量(只读);
++B2.18、multiTouchEnabled |
public static bool multiTouchEnabled; |
++++指示系统是否启用多点触控;
++B2.19、simulateMouseWithTouches |
public static bool simulateMouseWithTouches; |
++++启用/禁用鼠标模拟触摸;默认情况下启用此项;
++++如果启用,多达三个并发触摸转换到各自的鼠标按钮(例如:两指点击等于鼠标右键点击);
++B2.20、touchCount |
public static int touchCount; |
++++触摸的数量;每一帧之内都一定不会改变(只读);
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzInput : MonoBehaviour{
void Update(){ if(Input.touchCount > 0){ Debug.Log(Input.touchCount); } //立钻哥哥:if(){} } //立钻哥哥:void Update(){}
} //立钻哥哥:public class YanlzInput{} |
++B2.21、touches |
public static Touch[] touches; |
++++返回代表上一帧所有的触摸状态的对象列表(只读)(分配临时变量);
++++每个记录都代表着一个手指在屏幕上的触碰状态;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzInput : MonoBehaviour{
void Update(){ int fingerCount = 0;
foreach(Touch touch in Input.touches){ if(touch.phase != TouchPhase.Ended && touch.phase != TouchPhase.Canceled){ fingerCount++; } //立钻哥哥:if(){} } //立钻哥哥:foreach(){}
if(fingerCount > 0){ Debug.Log(“立钻哥哥:User has ” + fingerCount + “ finger(s) touching the screen.”); } //立钻哥哥:if(){}
} //立钻哥哥:void Update(){}
} //立钻哥哥:public class YanlzInput{} |
++B2.22、touchSupported |
public static bool touchSupported; |
++++返回设备是否在当前运行的应用程序支持触摸输入;
++++并不是检查平台,使用此属性确定是否游戏应该触摸输入,有的平台可以支持多种输入方式;
#C3、Static Functions静态函数 |
++C3、Static Functions静态函数++++C3.1、GetAccelerationEvent++++C3.2、GetAxis++++C3.3、GetAxisRaw++++C3.4、GetButton++++C3.5、GetButtonDown++++C3.6、GetButtonUp++++C3.7、GetJoystickNames++++C3.8、GetKey++++C3.9、GetKeyDown++++C3.10、GetKeyUp++++C3.11、GetMouseButton++++C3.12、GetMouseButtonDown++++C3.13、GetMouseButtonUp++++C3.14、GetTouch++++C3.15、IsJoystickPreconfigured++++C3.16、ResetInputAxes++++C3.17、YanlzXREngine.Input.StaticFunctions |
++C3.1、GetAccelerationEvent |
public static AccelerationEvent GetAccelerationEvent(int index); |
++++返回上一帧发生的指定的加速度测量(不允许分配临时变量);
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzInput : MonoBehaviour{
void Update(){ Vector3 acceleration = Vector3.zero;
int i = 0; while(i < Input.accelerationEventCount){ AccelerationEvent accEvent = Input.GetAccelerationEvent(i); acceleration += accEvent.acceleration * accEvent.deltaTime; ++i; } //立钻哥哥:while(){}
Debug.Log(acceleration);
} //立钻哥哥:void Update(){}
} //立钻哥哥:public class YanlzInput{} |
++C3.2、GetAxis |
public static float GetAxis(string axisName); |
++++根据axisName名称返回虚拟输入轴中的值;
++++使用键盘和键盘输入时此值范围在-1到1之间;如果坐标轴设置为鼠标运动增量,鼠标增量乘以坐标轴灵敏度的范围将不是-1到1;
++++该值和帧率无关;使用此值时,不需要关心不同的帧速率;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzInput : MonoBehaviour{ public float speed = 10.0F; public float rotationSpeed = 100.0F;
void Update(){ float translation = Input.GetAxis(“Vertical”) * speed; float rotation = Input.GetAxis(“Horizontal”) * rotationSpeed; translation *= Time.deltaTime; rotation *= Time.deltaTime; transform.Translate(0, 0, translation); transform.Rotate(0, rotation, 0); } //立钻哥哥:void Update(){}
} //立钻哥哥:public class YanlzInput{}
|
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzInput : MonoBehaviour{ public float horizontalSpeed = 2.0F; public float verticalSpeed = 2.0F;
void Update(){ float h = horizontalSpeed * Input.GetAxis(“Mouse X”); float v = verticalSpeed * Input.GetAxis(“Mouse Y”); transform.Rotate(v, h, 0); } //立钻哥哥:void Update(){}
} //立钻哥哥:public class YanlzInput{} |
++C3.3、GetAxisRaw |
public static float GetAxisRaw(string axisName); |
++++通过axisName名称返回一个不使用平滑滤波器的虚拟轴值;
++++键盘和摇杆取值范围在-1...1之间,此输入没有使用平滑;键盘输入必然会是-1、0、1;这一点在想自己处理键盘平滑输入时很实用;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzInput : MonoBehaviour{
void Update(){ float speed = Input.GetAxisRaw(“Horizontal”) * Time.deltaTime; transform.Rotate(0, speed, 0); } //立钻哥哥:void Update(){}
} //立钻哥哥:public class YanlzInput{} |
++C3.4、GetButton |
public static bool GetButton(string buttonName); |
++++当由“buttonName”确定的虚拟按键被按下时,返回true;
++++想象一下自动开火:如果按钮一直被按住此方法将永远返回true;
++++只有当执行像武器射击这样的事件时才可用此方法,Input.GetAxis适用于各种运动行为;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzInput : MonoBehaviour{ public GameObject projectile; public float fireRate = 0.5F; private float nextFire = 0.0F;
void Update(){ if(Input.GetButton(“Fire1”) && Time.time > nextFire){ nextFire = Time.time + fireRate; GameObject clone = Instantiate(projectile, transform.position, transform.rotation) as GameObject; } //立钻哥哥:if(Input.GetButton()){} } //立钻哥哥:void Update(){}
} //立钻哥哥:public class YanlzInput{} |
++C3.5、GetButtonDown |
public static bool GetButtonDown(string buttonName); |
++++当用户按下由buttonName名称确定的虚拟按钮的那一帧返回true;
++++需要在Update方法中调用这个方法,此后每一帧重置状态时,它将不会返回true,除非用户释放此按键然后重新按下;
++++只有当执行像武器射击这样的事件时才可用此方法,Input.GetAxis适用于各种运动行为;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzInput : MonoBehaviour{ public GameObject projectile;
void Update(){ if(Input.GetButtonDown(“Fire1”)){ Instantiate(projectile, transform.position, transform.rotation) as GameObject; } //立钻哥哥:if(){} } //立钻哥哥:void Update(){}
} //立钻哥哥:public class YanlzInput{} |
++C3.6、GetButtonUp |
public static bool GetButtonUp(string buttonName); |
++++在用户释放根据buttonName名称的虚拟按钮时返回true;
++++需要在Update方法中调用这个方法,此后每一帧重置状态时,它将不会返回true,除非用户按下这个按钮然后重新释放它;
++++只有当执行像武器射击这样的事件时才可用此方法,Input.GetAxis适用于各种运动行为;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzInput : MonoBehaviour{ public GameObject projectile;
void Update(){ //if(Input.GetButtonDown(“Fire1”)){ if(Input.GetButtonUp(“Fire1”)){ Instantiate(projectile, transform.position, transform.rotation) as GameObject; } //立钻哥哥:if(){} } //立钻哥哥:void Update(){}
} //立钻哥哥:public class YanlzInput{} |
++C3.7、GetJoystickNames |
public static string[] GetJoystickNames(); |
++++返回一个用来描述已连接的摇杆的字符串数组;
++++可用用在用户输入配置界面,这样就可以把显示的标签“Joystick1”换成意义更明确的名字,读取不同控制器的值,需要分别为各个摇杆在输入管理器中分配轴;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzInput : MonoBehaviour{
void Update(){ int i = 0; while(i < 4){ if(Mathf.Abs(Input.GetAxis(“Joy” + i + “X”)) > 0.2F || Mathf.Abs(Input.GetAxis(“Joy” + i + “Y”)) > 0.2F){ Debug.Log(Input.GetJoystickNames()[i] + “ is moved.”); } //立钻哥哥:if(){}
i++; } //立钻哥哥:while(){} } //立钻哥哥:void Update(){}
} //立钻哥哥:public class YanlzInput{} |
++C3.8、GetKey |
public static bool GetKey(string name);public static bool GetKey(KeyCode key); |
++++当用户按下由name名称确定的按键时,然后true;想想自动开火;
++++当用户按下由KeyCode枚举确定的按键时,然后true;
++++按键的标识符列表可以在输入管理器中找到,当处理输入时推荐使用Input.GetAxis和Input.GetButton,它们允许最终用户自定义按键;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzInput : MonoBehaviour{
void Update(){ if(Input.GetKey(“up”)){ Debug.Log(“立钻哥哥:up arrow key is held down.”); } //立钻哥哥:if(Input.GetKey(“up”)){}
if(Input.GetKey(“down”)){ Debug.Log(“立钻哥哥:down arrow key is held down.”); } //立钻哥哥:if(Input.GetKey(“down”)){} } //立钻哥哥:void Update(){}
} //立钻哥哥:public class YanlzInput{}
|
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzInput : MonoBehaviour{
void Update(){ //if(Input.GetKey(“up”)){ if(Input.GetKey(KeyCode.UpArrow)){ Debug.Log(“立钻哥哥:up arrow key is held down.”); } //立钻哥哥:if(Input.GetKey(KeyCode.UpArrwo)){}
//if(Input.GetKey(“down”)){ if(Input.GetKey(KeyCode.DownArrow)){ Debug.Log(“立钻哥哥:down arrow key is held down.”); } //立钻哥哥:if(Input.GetKey(“down”)){} } //立钻哥哥:void Update(){}
} //立钻哥哥:public class YanlzInput{} |
++C3.9、GetKeyDown |
public static bool GetKeyDown(string name);public static bool GetKeyDown(KeyCode key); |
++++当用户按下指定名称的按键时的那一帧返回true;
++++当用户按下映射到指定枚举参数的按键时的那一帧返回true;
++++需要在Update方法中调用这个方法,因为该状态每帧获得重置;除非用户释放这个按钮然后重新按下它,否则将不会返回true;
++++按键的标识符列表可以在输入管理器中找到,当处理输入时推荐使用Input.GetAxis和Input.GetButton,它们允许最终用户自定义按键;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzInput : MonoBehaviour{
void Update(){ if(Input.GetKeyDown(“space”)){ Debug.Log(“立钻哥哥:space key was pressed.”); } } //立钻哥哥:void Update(){}
} //立钻哥哥:public class YanlzInput{}
|
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzInput : MonoBehaviour{
void Update(){ //if(Input.GetKeyDown(“space”)){ if(Input.GetKeyDown(KeyCode.Space)){ Debug.Log(“立钻哥哥:space key was pressed.”); } } //立钻哥哥:void Update(){}
} //立钻哥哥:public class YanlzInput{} |
++C3.10、GetKeyUp |
public static bool GetKeyUp(string name);public static bool GetKeyUp(KeyCode key); |
++++当用户释放给定名称的按键时的那一帧返回true;
++++当用户释放给定键值的按键的那一帧返回true;
++++需要在Update方法中调用这个方法,因为该状态每帧获得重置;除非用户释放这个按钮然后重新按下它,否则将不会返回true;
++++按键的标识符列表可以在输入管理器中找到,当处理输入时推荐使用Input.GetAxis和Input.GetButton,它们允许最终用户自定义按键;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzInput : MonoBehaviour{
void Update(){ //if(Input.GetKeyDown(“space”)){ if(Input.GetKeyUp(“space”)){ Debug.Log(“立钻哥哥:space key was released.”); } } //立钻哥哥:void Update(){}
} //立钻哥哥:public class YanlzInput{}
|
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzInput : MonoBehaviour{
void Update(){ //if(Input.GetKeyDown(KeyCode.Space)){ if(Input.GetKeyUp(KeyCode.Space)){ Debug.Log(“立钻哥哥:space key was released.”); } } //立钻哥哥:void Update(){}
} //立钻哥哥:public class YanlzInput{} |
++C3.11、GetMouseButton |
public static bool GetMouseButton(int button); |
++++当指定的鼠标按钮被按下时返回true;
++++button值设定为:0对应左键,1对应右键,2对应中键;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzInput : MonoBehaviour{
void Update(){ if(Input.GetMouseButton(0)){ Debug.Log(“立钻哥哥:Pressed left click.”); } //立钻哥哥:if(Input.GetMouseButton(0)){}
if(Input.GetMouseButton(1)){ Debug.Log(“立钻哥哥:Pressed right click.”); } //立钻哥哥:if(Input.GetMouseButton(1)){}
if(Input.GetMouseButton(2)){ Debug.Log(“立钻哥哥:Pressed middle click.”); } //立钻哥哥:if(Input.GetMouseButton(2)){}
} //立钻哥哥:void Update(){}
} //立钻哥哥:public class YanlzInput{} |
++C3.12、GetMouseButtonDown |
public static bool GetMouseButtonDown(int button); |
++++在用户按下指定鼠标按键的那一帧返回true;
++++需要在Update方法中调用这个方法,此后每一帧重置状态时,它将不会返回true,除非用户释放这个鼠标按钮然后重新按下它;按钮值设定为:0对应左键,1对应右键,2对应中键;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzInput : MonoBehaviour{
void Update(){ //if(Input.GetMouseButton(0)){ if(Input.GetMouseButtonDown(0)){ Debug.Log(“立钻哥哥:Pressed left click.”); } //立钻哥哥:if(Input.GetMouseButtonDown(0)){}
//if(Input.GetMouseButton(1)){ if(Input.GetMouseButtonDown(1)){ Debug.Log(“立钻哥哥:Pressed right click.”); } //立钻哥哥:if(Input.GetMouseButtonDown(1)){}
//if(Input.GetMouseButton(2)){ if(Input.GetMouseButtonDown(2)){ Debug.Log(“立钻哥哥:Pressed middle click.”); } //立钻哥哥:if(Input.GetMouseButtonDown(2)){}
} //立钻哥哥:void Update(){}
} //立钻哥哥:public class YanlzInput{} |
++C3.13、GetMouseButtonUp |
public static bool GetMouseButtonUp(int button); |
++++在用户释放指定鼠标按键的那一帧返回true;
++++需要在Update方法中调用这个方法,此后每一帧重置状态时,它将不会返回true;除非用户释放这个鼠标按钮然后重新按下它;按钮值设定为:0对应左键,1对应右键,2对应中键;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzInput : MonoBehaviour{
void Update(){ //if(Input.GetMouseButtonDown(0)){ if(Input.GetMouseButtonUp(0)){ Debug.Log(“立钻哥哥:Pressed left click.”); } //立钻哥哥:if(Input.GetMouseButtonUp(0)){}
//if(Input.GetMouseButtonDown(1)){ if(Input.GetMouseButtonUp(1)){ Debug.Log(“立钻哥哥:Pressed right click.”); } //立钻哥哥:if(Input.GetMouseButtonUp(1)){}
//if(Input.GetMouseButtonDown(2)){ if(Input.GetMouseButtonUp(2)){ Debug.Log(“立钻哥哥:Pressed middle click.”); } //立钻哥哥:if(Input.GetMouseButtonUp(2)){}
} //立钻哥哥:void Update(){}
} //立钻哥哥:public class YanlzInput{} |
++C3.14、GetTouch |
public static Touch GetTouch(int index); |
++++返回一个存放触摸信息的对象(不允许分配临时变量);
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzInput : MonoBehaviour{ public float speed = 0.1F;
void Update(){ if(Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved){ //Get movement of the finger since last frame Vector2 touchDeltaPosition = Input.GetTouch(0).deltaPosition;
//Move object across XY plane transform.Translate(-touchDeltaPosition.x * speed, -touchDeltaPosition.y * speed, 0); } //立钻哥哥:if(){} } //立钻哥哥:void Update(){}
} //立钻哥哥:public class YanlzInput{}
|
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzInput : MonoBehaviour{ public GameObject projectile; public GameObject clone;
void Update(){ for(var i = 1; i < Input.touchCount; ++i){ if(Input.GetTouch(i).phase == TouchPhase.Began){ clone = Instantiate(projectile, transform.position, transform.rotation) as GameObject; } //立钻哥哥:if(){} } //立钻哥哥:for(){} } //立钻哥哥:void Update(){}
} //立钻哥哥:public class YanlzInput{}
|
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzInput : MonoBehaviour{ public GameObject particle;
void Update(){ for(var i = 1; i < Input.touchCount; ++i){ if(Input.GetTouch(i).phase == TouchPhase.Began){ //Construct a ray from the current touch coordinates Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(i).position);
//Create a particle if hit if(Physics.Raycast(ray)){ Instantiate(particle, transform.position, transform.rotation) as GameObject; } //立钻哥哥:if(Physics.Raycast()){} } //立钻哥哥:if(Input.GetTouch(i).phase == TouchPhase.Began){} } //立钻哥哥:for(){} } //立钻哥哥:void Update(){}
} //立钻哥哥:public class YanlzInput{} |
++C3.15、IsJoystickPreconfigured |
public static bool IsJoystickPreconfigured(string joystickName); |
++++[joystickName]:检测摇杆的名称(由Input.GetJoystickNames返回);
++++返回值:如果该摇杆已经配置返回true,否则返回false;
++++确定Unity是否一个特定的操纵杆模型已预先配置(仅Linux);
++++预配置的摇杆报告索引,对应按键和输入轴按下面的顺序;按键:A,B,X,Y,left,bumper,right bumper,select,start,guide,left stick press,right stick press;输入轴:left stick x,left stick y,left trigger,right stick x,right stick y,right trigger,dpad horizontal,dpad vertical;
++C3.16、ResetInputAxes |
public static void ResetInputAxes(); |
++++在一帧中重置所有的输入,重置输入指令之后所有的方向轴都被设置为0并且所有的按键都被设置为0;
++++可以用在当在复活角色时,不想接受任何可能仍有按下的按键输入时;(当玩家复活的瞬间并不应该接受用户控制时);
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzInput : MonoBehaviour{
void MyTestFunc(){ Input.ResetInputAxes(); } //立钻哥哥:void MyTestFunc(){}
} //立钻哥哥:public class YanlzInput{} |
#D4、立钻哥哥对Input类的拓展 |
++++【Unity API】分类:https://blog.csdn.net/vrunsoftyanlz/category_7637520.html
++++【Unity开发基础】分类:https://blog.csdn.net/vrunsoftyanlz/category_7309057.html
++++【Linux系统编程】分类:https://blog.csdn.net/vrunsoftyanlz/category_9694767.html
++++【C++C铸就生存利器】分类:https://blog.csdn.net/vrunsoftyanlz/category_9325802.html
++++【人工智能AI2026】分类:https://blog.csdn.net/vrunsoftyanlz/category_9212024.html
++++【立钻哥哥CSDN空间】:https://blog.csdn.net/VRunSoftYanlz/
立钻哥哥推荐的拓展学习链接(Link_Url) |
++++立钻哥哥Unity 学习空间: http://blog.csdn.net/VRunSoftYanlz/
++++虚拟现实VR资讯: https://blog.csdn.net/VRunSoftYanlz/article/details/89165846
++++HTC_VIVE开发基础:https://blog.csdn.net/VRunSoftYanlz/article/details/81989970
++++Oculus杂谈:https://blog.csdn.net/VRunSoftYanlz/article/details/82469850
++++Oculus安装使用:https://blog.csdn.net/VRunSoftYanlz/article/details/82718982
++++Unity+SteamVR=>VR:https://blog.csdn.net/VRunSoftYanlz/article/details/88809370
++++Unity减少VR晕眩症:https://blog.csdn.net/VRunSoftYanlz/article/details/89115518
++++SteamVR简介:https://blog.csdn.net/VRunSoftYanlz/article/details/86484254
++++SteamVR脚本功能分析:https://blog.csdn.net/VRunSoftYanlz/article/details/86531480
++++SteamVR2.0开发指南:https://blog.csdn.net/VRunSoftYanlz/article/details/86618187
++++SteamVR2.2.0开发指南:https://blog.csdn.net/VRunSoftYanlz/article/details/88784527
++++SteamVR2.2.0快速入门:https://blog.csdn.net/VRunSoftYanlz/article/details/88833579
++++SteamVR2.2.0交互系统:https://blog.csdn.net/VRunSoftYanlz/article/details/89199778
++++SteamVR2.2.0传送机制:https://blog.csdn.net/VRunSoftYanlz/article/details/89390866
++++SteamVR2.2.0教程(一):https://blog.csdn.net/VRunSoftYanlz/article/details/89324067
++++SteamVR2.2.0教程(二):https://blog.csdn.net/VRunSoftYanlz/article/details/89894097
++++SteamVR_Skeleton_Poser:https://blog.csdn.net/VRunSoftYanlz/article/details/89931725
++++SteamVR实战之PMCore:https://blog.csdn.net/VRunSoftYanlz/article/details/89463658
++++SteamVR/Extras:https://blog.csdn.net/VRunSoftYanlz/article/details/86584108
++++SteamVR/Input:https://blog.csdn.net/VRunSoftYanlz/article/details/86601950
++++OpenXR简介:https://blog.csdn.net/VRunSoftYanlz/article/details/85726365
++++VRTK杂谈:https://blog.csdn.net/VRunSoftYanlz/article/details/82562993
++++VRTK快速入门(杂谈):https://blog.csdn.net/VRunSoftYanlz/article/details/82955267
++++VRTK官方示例(目录):https://blog.csdn.net/VRunSoftYanlz/article/details/82955410
++++VRTK代码结构(目录):https://blog.csdn.net/VRunSoftYanlz/article/details/82780085
++++VRTK(SceneResources):https://blog.csdn.net/VRunSoftYanlz/article/details/82795400
++++VRTK_ControllerEvents:https://blog.csdn.net/VRunSoftYanlz/article/details/83099512
++++VRTK_InteractTouch:https://blog.csdn.net/VRunSoftYanlz/article/details/83120220
++++虚拟现实行业应用:https://blog.csdn.net/VRunSoftYanlz/article/details/88360157
++++Steam平台上的VR:https://blog.csdn.net/VRunSoftYanlz/article/details/88960085
++++Steam平台热销VR:https://blog.csdn.net/VRunSoftYanlz/article/details/89007741
++++VR实验:以太网帧的构成:https://blog.csdn.net/VRunSoftYanlz/article/details/82598140
++++实验四:存储器扩展实验:https://blog.csdn.net/VRunSoftYanlz/article/details/87834434
++++FrameVR示例V0913:https://blog.csdn.net/VRunSoftYanlz/article/details/82808498
++++FrameVR示例V1003:https://blog.csdn.net/VRunSoftYanlz/article/details/83066516
++++SwitchMachineV1022:https://blog.csdn.net/VRunSoftYanlz/article/details/83280886
++++PlaySceneManagerV1022:https://blog.csdn.net/VRunSoftYanlz/article/details/83280886
++++Unity5.x用户手册:https://blog.csdn.net/VRunSoftYanlz/article/details/81712741
++++Unity面试题ABC:https://blog.csdn.net/vrunsoftyanlz/article/details/78630687
++++Unity面试题D:https://blog.csdn.net/VRunSoftYanlz/article/details/78630838
++++Unity面试题E:https://blog.csdn.net/vrunsoftyanlz/article/details/78630913
++++Unity面试题F:https://blog.csdn.net/VRunSoftYanlz/article/details/78630945
++++Cocos2dx面试题:https://blog.csdn.net/VRunSoftYanlz/article/details/78630967
++++禅道[zentao]:https://blog.csdn.net/VRunSoftYanlz/article/details/83964057
++++Lua快速入门篇(Xlua拓展):https://blog.csdn.net/VRunSoftYanlz/article/details/81173818
++++Lua快速入门篇(XLua教程):https://blog.csdn.net/VRunSoftYanlz/article/details/81141502
++++Lua快速入门篇(基础概述):https://blog.csdn.net/VRunSoftYanlz/article/details/81041359
++++框架知识点:https://blog.csdn.net/VRunSoftYanlz/article/details/80862879
++++游戏框架(UI框架夯实篇):https://blog.csdn.net/vrunsoftyanlz/article/details/80781140
++++游戏框架(初探篇):https://blog.csdn.net/VRunSoftYanlz/article/details/80630325
++++.Net框架设计:https://blog.csdn.net/VRunSoftYanlz/article/details/87401225
++++从零开始学架构:https://blog.csdn.net/VRunSoftYanlz/article/details/88095895
++++设计模式简单整理:https://blog.csdn.net/vrunsoftyanlz/article/details/79839641
++++专题:设计模式(精华篇):https://blog.csdn.net/VRunSoftYanlz/article/details/81322678
++++U3D小项目参考:https://blog.csdn.net/vrunsoftyanlz/article/details/80141811
++++Unity小游戏算法分析:https://blog.csdn.net/VRunSoftYanlz/article/details/87908365
++++Unity案例(Vehicle):https://blog.csdn.net/VRunSoftYanlz/article/details/82355876
++++UML类图:https://blog.csdn.net/vrunsoftyanlz/article/details/80289461
++++PowerDesigner简介:https://blog.csdn.net/VRunSoftYanlz/article/details/86500084
++++Unity知识点0001:https://blog.csdn.net/vrunsoftyanlz/article/details/80302012
++++Unity知识点0008:https://blog.csdn.net/VRunSoftYanlz/article/details/81153606
++++U3D_Shader编程(第一篇:快速入门篇):https://blog.csdn.net/vrunsoftyanlz/article/details/80372071
++++U3D_Shader编程(第二篇:基础夯实篇):https://blog.csdn.net/vrunsoftyanlz/article/details/80372628
++++Unity引擎基础:https://blog.csdn.net/vrunsoftyanlz/article/details/78881685
++++Unity面向组件开发:https://blog.csdn.net/vrunsoftyanlz/article/details/78881752
++++Unity物理系统:https://blog.csdn.net/vrunsoftyanlz/article/details/78881879
++++Unity2D平台开发:https://blog.csdn.net/vrunsoftyanlz/article/details/78882034
++++UGUI基础:https://blog.csdn.net/vrunsoftyanlz/article/details/78884693
++++UGUI进阶:https://blog.csdn.net/vrunsoftyanlz/article/details/78884882
++++UGUI综合:https://blog.csdn.net/vrunsoftyanlz/article/details/78885013
++++Unity动画系统基础:https://blog.csdn.net/vrunsoftyanlz/article/details/78886068
++++Unity动画系统进阶:https://blog.csdn.net/vrunsoftyanlz/article/details/78886198
++++Navigation导航系统:https://blog.csdn.net/vrunsoftyanlz/article/details/78886281
++++Unity特效渲染:https://blog.csdn.net/vrunsoftyanlz/article/details/78886403
++++Unity数据存储:https://blog.csdn.net/vrunsoftyanlz/article/details/79251273
++++Unity中Sqlite数据库:https://blog.csdn.net/vrunsoftyanlz/article/details/79254162
++++WWW类和协程:https://blog.csdn.net/vrunsoftyanlz/article/details/79254559
++++Unity网络:https://blog.csdn.net/vrunsoftyanlz/article/details/79254902
++++Unity资源加密:https://blog.csdn.net/VRunSoftYanlz/article/details/87644514
++++PhotonServer简介:https://blog.csdn.net/VRunSoftYanlz/article/details/86652770
++++编写Photon游戏服务器:https://blog.csdn.net/VRunSoftYanlz/article/details/86682935
++++C#事件:https://blog.csdn.net/vrunsoftyanlz/article/details/78631267
++++C#委托:https://blog.csdn.net/vrunsoftyanlz/article/details/78631183
++++C#集合:https://blog.csdn.net/vrunsoftyanlz/article/details/78631175
++++C#泛型:https://blog.csdn.net/vrunsoftyanlz/article/details/78631141
++++C#接口:https://blog.csdn.net/vrunsoftyanlz/article/details/78631122
++++C#静态类:https://blog.csdn.net/vrunsoftyanlz/article/details/78630979
++++C#中System.String类:https://blog.csdn.net/vrunsoftyanlz/article/details/78630945
++++C#数据类型:https://blog.csdn.net/vrunsoftyanlz/article/details/78630913
++++Unity3D默认的快捷键:https://blog.csdn.net/vrunsoftyanlz/article/details/78630838
++++游戏相关缩写:https://blog.csdn.net/vrunsoftyanlz/article/details/78630687
++++UnityAPI.Rigidbody刚体:https://blog.csdn.net/VRunSoftYanlz/article/details/81784053
++++UnityAPI.Material材质:https://blog.csdn.net/VRunSoftYanlz/article/details/81814303
++++UnityAPI.Android安卓:https://blog.csdn.net/VRunSoftYanlz/article/details/81843193
++++UnityAPI.AndroidJNI安卓JNI:https://blog.csdn.net/VRunSoftYanlz/article/details/81879345
++++UnityAPI.Transform变换:https://blog.csdn.net/VRunSoftYanlz/article/details/81916293
++++UnityAPI.WheelCollider轮碰撞器:https://blog.csdn.net/VRunSoftYanlz/article/details/82356217
++++UnityAPI.Resources资源:https://blog.csdn.net/VRunSoftYanlz/article/details/83155518
++++JSON数据结构:https://blog.csdn.net/VRunSoftYanlz/article/details/82026644
++++CocosStudio快速入门:https://blog.csdn.net/VRunSoftYanlz/article/details/82356839
++++Unity企业内训(目录):https://blog.csdn.net/VRunSoftYanlz/article/details/82634668
++++Unity企业内训(第1讲):https://blog.csdn.net/VRunSoftYanlz/article/details/82634733
++++Unity企业内训(第2讲):https://blog.csdn.net/VRunSoftYanlz/article/details/82861180
++++Unity企业内训(第3讲):https://blog.csdn.net/VRunSoftYanlz/article/details/82927699
++++Unity企业内训(第4讲):https://blog.csdn.net/VRunSoftYanlz/article/details/83479776
++++Unity企业内训(第5讲):https://blog.csdn.net/VRunSoftYanlz/article/details/83963811
++++Unity企业内训(第6讲):https://blog.csdn.net/VRunSoftYanlz/article/details/84207696
++++钻哥带您了解产品原型:https://blog.csdn.net/VRunSoftYanlz/article/details/87303828
++++插件
++++计算机组成原理(教材篇):https://blog.csdn.net/VRunSoftYanlz/article/details/82719129
++++5G接入:云计算和雾计算:https://blog.csdn.net/VRunSoftYanlz/article/details/88372718
++++云计算通俗讲义:https://blog.csdn.net/VRunSoftYanlz/article/details/88652803
++++立钻哥哥Unity 学习空间: http://blog.csdn.net/VRunSoftYanlz
--_--VRunSoft:lovezuanzuan--_--