Unity获取鼠标滚轮信息

2023-11-07

Unity获取鼠标滚轮信息

UGUI获取滚轮信息

UGUI关于鼠标滚轮信息的获取有一个专门的接口IScrollHandler用于接收滚轮事件。继承该事件之后便需要实现函数OnScroll
如下:

public virtual void OnScroll(PointerEventData eventData)
{
    
}

该函数接收的参数PointerEventData,如下:

using System;
using System.Collections.Generic;

namespace UnityEngine.EventSystems
{
    //
    // 摘要:
    //     Event payload associated with pointer (mouse / touch) events.
    public class PointerEventData : BaseEventData
    {
        //
        // 摘要:
        //     List of objects in the hover stack.
        public List<GameObject> hovered;

        public PointerEventData(EventSystem eventSystem);

        //
        // 摘要:
        //     The GameObject that received the OnPointerDown.
        public GameObject pointerPress { get; set; }
        //
        // 摘要:
        //     The camera associated with the last OnPointerPress event.
        public Camera pressEventCamera { get; }
        //
        // 摘要:
        //     The camera associated with the last OnPointerEnter event.
        public Camera enterEventCamera { get; }
        //
        // 摘要:
        //     The EventSystems.PointerEventData.InputButton for this event.
        public InputButton button { get; set; }
        //
        // 摘要:
        //     Determines whether the user is dragging the mouse or trackpad.
        public bool dragging { get; set; }
        //
        // 摘要:
        //     Should a drag threshold be used?
        public bool useDragThreshold { get; set; }
        //
        // 摘要:
        //     The amount of scroll since the last update.
        public Vector2 scrollDelta { get; set; }
        //
        // 摘要:
        //     Number of clicks in a row.
        public int clickCount { get; set; }
        //
        // 摘要:
        //     The last time a click event was sent.
        public float clickTime { get; set; }
        [Obsolete("Use either pointerCurrentRaycast.worldNormal or pointerPressRaycast.worldNormal")]
        public Vector3 worldNormal { get; set; }
        [Obsolete("Use either pointerCurrentRaycast.worldPosition or pointerPressRaycast.worldPosition")]
        public Vector3 worldPosition { get; set; }
        //
        // 摘要:
        //     The screen space coordinates of the last pointer click.
        public Vector2 pressPosition { get; set; }
        //
        // 摘要:
        //     Pointer delta since last update.
        public Vector2 delta { get; set; }
        //
        // 摘要:
        //     Current pointer position.
        public Vector2 position { get; set; }
        //
        // 摘要:
        //     Identification of the pointer.
        public int pointerId { get; set; }
        public bool eligibleForClick { get; set; }
        //
        // 摘要:
        //     RaycastResult associated with the pointer press.
        public RaycastResult pointerPressRaycast { get; set; }
        //
        // 摘要:
        //     RaycastResult associated with the current event.
        public RaycastResult pointerCurrentRaycast { get; set; }
        //
        // 摘要:
        //     The object that is receiving OnDrag.
        public GameObject pointerDrag { get; set; }
        //
        // 摘要:
        //     The object that the press happened on even if it can not handle the press event.
        public GameObject rawPointerPress { get; set; }
        //
        // 摘要:
        //     The GameObject for the last press event.
        public GameObject lastPress { get; }
        //
        // 摘要:
        //     The object that received 'OnPointerEnter'.
        public GameObject pointerEnter { get; set; }

        //
        // 摘要:
        //     Is the pointer moving.
        //
        // 返回结果:
        //     Moving.
        public bool IsPointerMoving();
        //
        // 摘要:
        //     Is scroll being used on the input device.
        //
        // 返回结果:
        //     Scrolling.
        public bool IsScrolling();
        public override string ToString();

        //
        // 摘要:
        //     Input press tracking.
        public enum InputButton
        {
            //
            // 摘要:
            //     Left button.
            Left = 0,
            //
            // 摘要:
            //     Right button.
            Right = 1,
            //
            // 摘要:
            //     Middle button.
            Middle = 2
        }
        //
        // 摘要:
        //     The state of a press for the given frame.
        public enum FramePressState
        {
            //
            // 摘要:
            //     Button was pressed this frame.
            Pressed = 0,
            //
            // 摘要:
            //     Button was released this frame.
            Released = 1,
            //
            // 摘要:
            //     Button was pressed and released this frame.
            PressedAndReleased = 2,
            //
            // 摘要:
            //     Same as last frame.
            NotChanged = 3
        }
    }
}

其中,Vector2类型的字段scrollDelta中的y,便是滚轮滚动的信息具体数值信息:上滑滚轮为正1,下滑滚轮为负1

Input获取滚轮信息

通过Input获取滚轮信息的方式为Input.GetAxis("Mouse ScrollWheel")

public void OnUpdate()
{
    Debug.Log(Input.GetAxis("Mouse ScrollWheel"));
}

通过测试便可得到如下效果:
结果
滚轮上滑为正,下滑为负;且滚轮的每个小格卡顿,其数值信息表示为0.1,快速连续滚动时其数值会直接出现对应的数值,不会一格一格出现。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Unity获取鼠标滚轮信息 的相关文章

随机推荐

  • 2023蓝桥杯考前整理

    目录 python接收数据的方法 python内置方法 python字符串方法 python模块 python接收数据的方法 接收一个元素 s input 接收一个字符串 n int input 接收一个整数 接收两个或三个元素 以空格隔开
  • 【软考】-高项-质量管理-子过程ITTO记忆技巧

    质量管理 贵管控 规划质量管理 1 记忆口诀 需求 干系 风险记住清 组织质量体系 策略盈 标杆成本质量流 思维测试 计划留 质量测量指标出 管理计划 记心头 2 故事 在一个叫做 需求城 的地方 有三个重要的公民 需求文件先生 干系人登记
  • Markdown中图片对齐方式及尺寸设置

    在markdown编辑模式下导入图片默认尺寸会很大 不符合预期效果 有时候需要对图片的对齐方式和尺寸大小进行调整 1 直接上传图片的原始效果 添加图片后默认尺寸很大 会占满整个宽度 2 图片尺寸及对齐方式调整 添加图片之后 图片底部 CSD
  • java对于Excel进行快速处理的框架EasyExcel(SpringBoot集成)

    一 EasyExcel介绍 EasyExcel是阿里巴巴开源的一个excel处理框架 以使用简单 节省内存著称 EasyExcel能大大减少占用内存的主要原因是在解析Excel时没有将文件数据一次性全部加载到内存中 而是从磁盘上一行行读取数
  • Anchor-Free based目标检测

    CornerNet 预测左上角和右下角来得到最后的bounding boxes 所以最基本的需要两个feature map表示对应的Corner 称为heatmap top left 和 bottom right 将属于同一个object的
  • C++中template(模版)的使用

    我们在编程的时候总是会遇到一些类似的模块 只是模块中的形参的数据类型不同 导致我们要不断的去更改模块的 这里就涉及到重载的知识点了 例如以下的几种情况 函数1 int max int x int y return x gt y x y 函数
  • 分布式监控系统——Zabbix(3)配置

    文章目录 分布式监控系统 Zabbix 3 配置 一 监控项 1 定义一个不带参数的监控项 2 定义一个带参数的监控项 3 删除监控项 4 监控项存储的值 二 触发器 1 简介 2 触发器表达式 3 定义一个触发器 4 触发器的依赖关系 5
  • 项目4总结:MySQL数据表的检索

    目录 任务4 1 查询时选择列 1 基本查询语句 2 检索所有列 3 检索指定列 任务4 2 查询时选择行 1 查询指定记录 2 带IN关键字的查询 3 带BETWEEN AND的范围查询 4 带LIKE的字符匹配查询 5 查询空值 6 带
  • truncate和delete的区别

    两者都可以删除表中的数据 但是本质上是有区别的 两者使用方法如下 删除表中所有数据 DELETE FROM table name 删除表中部分符合条件的数据 DELETE FROM table name WHERE 删除表中所有数据 TRU
  • Google reCAPTCHA ----------验证码

    现有验证码的产品形态调研范围如下 基本涵盖了比较主流的验证码平台 Google reCAPTCHA 极验 阿里云 腾讯云 点触 网易易盾 螺丝帽 FunCaptcha 产品背景 reCAPTCHA起初是由CMU 卡耐基梅隆大学 设计 将OC
  • pip安装地址--清华源(国内常用镜像源)

    国内常用镜像源 清华大学 https pypi tuna tsinghua edu cn simple 阿里云 http mirrors aliyun com pypi simple 中国科学技术大学 http pypi mirrors u
  • Linux服务器在线扩容内存,redhat linux 在线扩容磁盘空间

    在惠普Proliant服务器上在线扩容Linux ext3类型的文件系统 服务器集成SA5i 内置硬盘 加SA532挂MSA500 划了一个阵列 全部做一个逻辑盘 设备名为 dev cciss c1d0 全部空间建立分区为 dev ccis
  • 箭头函数和普通函数的区别

    箭头函数 1 只有一个参数的时候 参数可以不加小括号 没有参数或2个及以上参数的 必须加上小括号 2 返回语句只有一条的时候可以不写 和return 会自动加上return的 返回多条语句时必须加上 和return 3 箭头函数在返回对象的
  • Mysql添加新用户,并设置数据库权限

    首先进入mysql mysql u root p 然后在数据库中使用 create DATABASE my test db 创建数据库 CREATE USER test user IDENTIFIED BY test pass 创建一个用户
  • 5种很牛的两位数乘法速算方法

    5种很牛的两位数乘法速算方法 第一种 十几乘以任意两位数 公式推导 10 b 10c d 100c 10 bc d bd 10 10c bc d bd 10 10c d bc bd 方法 如果c 1 公式是 10 b 10 d 10 10
  • 16款ChatGPT工具,太炸裂了,收藏!

    因公众号更改推送规则 请点 在看 并加 星标 第一时间获取精彩技术分享 点击关注 互联网架构师公众号 领取架构师全套资料 都在这里 0 2T架构师学习资料干货分 上一篇 ChatGPT研究框架 80页PPT 附下载 大家好 我是互联网架构师
  • ug装配绕轴旋转_UG绘制小吊扇模型,建模装配还能运动起来

    夏天来了 吾思小编来教大家用UG做一个小风扇给夏日带来一丝凉意吧 根据图纸建模 整体建模难度 简单 装配难度 简单 模型效果图如下 一共由五个零件组成 建模过程 先画零件1底座 1 绘制一个直径为120mm的圆拉伸10mm 2 倒斜角5mm
  • Scanner读取文件(按行读入)

    public class ScannerTest public static void main String args 其实 Scanner在使用结束之后 也是需要进行关闭的 调用close方法 try Scanner scanner n
  • 使用注解从AOP面对方法进行逻辑判断

    今天360文8热8凉1汤 不好意思走错了 需求 根据不同的登录设备对xxController层中的方法是否禁用 AOP解释 切面编程 灵魂画图 代码 1 建立一个注解SuiteDisable import java lang annotat
  • Unity获取鼠标滚轮信息

    Unity获取鼠标滚轮信息 UGUI获取滚轮信息 Input获取滚轮信息 UGUI获取滚轮信息 UGUI关于鼠标滚轮信息的获取有一个专门的接口IScrollHandler用于接收滚轮事件 继承该事件之后便需要实现函数OnScroll 如下