2019-05-22

简介

  • Input
  • IPointerEnterHandler等接口
  • 键盘,鼠标,操作杆

Input

  1. GetAxis:返回float,对应的name为InputSetting对应的
  2. GetButton:返回bool,对应的name为InputSetting对应的
  3. GetKey:返回bool
-   KeyCode:对应键值
-   string:对应InputSetting对应的每一个下面的NegativeButton等Button
if (Input.GetButton("Horizontal"))
{
    Debug.LogError("GetButton");
}

float h = Input.GetAxis("Horizontal");
if (0!=h)
{
    Debug.LogError("GetAxis");
}

if (Input.GetKey(KeyCode.A))
{
    Debug.LogError("GetKey_keycode");
}

if (Input.GetKey("a"))
{
    Debug.LogError("GetKey_name");
}
  1. mousePresent:检测鼠标设备,官方文档中解释在各个平台会有很大出入
  2. mouseScrollDelta:返回(0,0,1)或者(0,0,-1)
  3. mousePosition:返回鼠标在屏幕坐标系坐标
if (Input.mousePresent)
{
    Debug.LogError("______mousepresent");
}
Debug.LogError(Input.mouseScrollDelta+"______scroll");
Debug.LogError(Input.mousePosition+"_____position");
  1. touchSupported:触控支持
  2. touchPressureSupported:触控按压支持
  3. multiTouchEnabled:多个触控支持
  4. stylusTouchSupported:触控板支持
  5. simulateMouseWithTouches:通过触摸启用/禁用鼠标模拟。默认情况下,此选项已启用。如果启用,最多三个并发触摸将转换为相应鼠标按钮上的状态(例如:双指点击将等于鼠标右键单击)。
  6. touchCount:
  7. GetTouch:
  8. touches:
Touch[] to = Input.touches;
if (to.Length>0)
{
    Debug.LogError(to.Length);
    if (to[0].phase==TouchPhase.Began)
    {
        Debug.LogError("begin");
    }
    else if (to[0].phase == TouchPhase.Moved)
    {
        Debug.LogError("move");
    }
    else if (to[0].phase == TouchPhase.Stationary)
    {
        Debug.LogError("station");
    }
    else if (to[0].phase == TouchPhase.Ended)
    {
        Debug.LogError("end");
    }
}

Touch
  1. position:触控的当前屏幕坐标
  2. rawPosition:触控的开始移动坐标
  3. deltaPosition:触控的每次移动方向坐标
  4. TouchPhase:触控状态Begin,Move,Stationary,End
  5. TouchType:触控类型,直接触控,远程的,还是触控笔那种
  6. fingerId:开始:手指放上,依次0123;移开1号,其他不变;再放上一个,从0开始分配空着的1


Regular Update Events

GUI events

Physics events

Initialization Events

    • 鼠标进入:IPointerEnterHandler,OnPointerEnter
  • 鼠标退出:IPointerExitHandler,OnPointerExit
双击
  • UI:

    IPointerClickHandler 
    public void OnPointerClick(PointerEventData eventData)
        {
            if (eventData.clickCount == 2)
            {
                Debug.log("双击");
            }
        }
  • 物体:

    void Update(){  
        if(Event.current.isMouse && Event.current.type == EventType.MouseDown && Event.current.clickCount == 2){  
            if(b){  
                print("double click " + transform.name);  
            }  
        }  
    }  
    void OnMouseEnter(){  
        b = true;  
    }  
    void OnMouseExit(){  
        b =false;  
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值