zoukankan      html  css  js  c++  java
  • 鼠标拖动

    //鼠标拖动
    private float previousPositionX;
    private float offset;
    private bool startReduceSpeed = false;
    private bool startAddSpeed = false;
    private bool startAddSpeed_reduce = false;
    private float reduceSpeed = 10.0f;
    private Vector3 mouseCurrentPos = Vector3.zero;
    private void checkMouseDragChangeSpeed()
    {
    #if UNITY_EDITOR
    if (Input.GetMouseButtonDown(0))
    {
    previousPositionX = Input.mousePosition.x;
    startAddSpeed = false;
    startAddSpeed_reduce = false;
    startReduceSpeed = false;
    roatSpeed = 15f;
    }
    if (Input.GetMouseButton(0)) //按下(状态)
    {
    offset = Input.mousePosition.x - previousPositionX;
    if (offset > 0)
    {
    roatSpeed = 55f;
    }
    else if (offset < 0)
    {
    roatSpeed = -30f;
    }
    previousPositionX = Input.mousePosition.x;
    }
    if (Input.GetMouseButtonUp(0)) //抬起(瞬间)
    {
    if (roatSpeed < 15)
    {
    startAddSpeed = true;
    startAddSpeed_reduce = true;
    }
    else if (roatSpeed > 15)
    {
    startReduceSpeed = true;
    }
    mouseCurrentPos = Input.mousePosition;
    }
    #elif UNITY_IOS || UNITY_ANDROID
    if(Input.touchCount <= 0)
    {
    return;
    }
    if (Input.GetTouch(0).phase == TouchPhase.Began)
    {
    startAddSpeed = false;
    startAddSpeed_reduce = false;
    startReduceSpeed = false;
    roatSpeed = 15f;
    }
    if (Input.GetTouch(0).phase == TouchPhase.Moved)
    {
    if (Input.GetTouch(0).deltaPosition.x > 0)
    {
    roatSpeed = 55f;
    }
    else if (Input.GetTouch(0).deltaPosition.x < 0)
    {
    roatSpeed = -30f;
    }
    }
    if (Input.GetTouch(0).phase == TouchPhase.Ended)
    {
    if (roatSpeed < 15)
    {
    startAddSpeed = true;
    startAddSpeed_reduce = true;
    }
    else if (roatSpeed > 15)
    {
    startReduceSpeed = true;
    }
    }
    #else
    if (Input.GetMouseButtonDown(0))
    {
    previousPositionX = Input.mousePosition.x;
    startAddSpeed = false;
    startAddSpeed_reduce = false;
    startReduceSpeed = false;
    roatSpeed = 15f;
    }
    if (Input.GetMouseButton(0)) //按下(状态)
    {
    offset = Input.mousePosition.x - previousPositionX;
    if (offset > 0)
    {
    roatSpeed = 55f;
    }
    else if (offset < 0)
    {
    roatSpeed = -30f;
    }
    previousPositionX = Input.mousePosition.x;
    }
    if (Input.GetMouseButtonUp(0)) //抬起(瞬间)
    {
    if (roatSpeed < 15)
    {
    startAddSpeed = true;
    startAddSpeed_reduce = true;
    }
    else if (roatSpeed > 15)
    {
    startReduceSpeed = true;
    }
    mouseCurrentPos = Input.mousePosition;
    //mouseIsMove = false;
    }
    #endif
    }

  • 相关阅读:
    web.xml中<web-app>报错
    groovy初体验:groovy在java中的应用
    Mac安装JMeter时Unable to access jarfile ./ApacheJMeter.jar 解决方法
    intellij idea中解决java.lang.VerifyError: Expecting a stackmap frame at branch target的方法
    关于go get无法安装国内被墙软件解决办法
    Oracle 序列
    无锁并发框架Disruptor学习入门
    vsftp服务器部署
    FinalShell 推荐
    supperset (python 2.7.12 + mysql)记录
  • 原文地址:https://www.cnblogs.com/Study088/p/7146322.html
Copyright © 2011-2022 走看看