• InputAction的使用


    感觉Unity中InputAction的使用,步步都是坑。

    需求点介绍

    当用户长按0.5s 键盘X或者VR left controller primaryButton (即X键)时,显示下一个图片。

    步骤总览

    1. 创建InputAction资产
    2. 将该InputAction资产绑定到某个GameObject上
    3. 在对应的script中,接收InputAction触发的事件,完成“显示下一个图片”的逻辑

    细节

    1. 创建InputAction资产
      在这里插入图片描述

    2. 将该InputAction资产绑定到某个GameObject上。

    如果Behaviour是send messages或者broadcast messages,那这个GameObject或者其子GameObject包含Component,这个Component有需要检测InputAction输入的function。

    如果Behaviour是Invoke Unity Event,那好像绑定在哪个GameObject都没有关系,只要Player Input这个component能在function之前被初始化就行。

    至于Behavior如何设置,见官网, 不过官网说得也不明不白的。
    在这里插入图片描述
    在我的例子中,我需要设置成Invoke Unity Events,然后像对待UI控件一样,显性绑定才能触发function的运行。Send/Broadcast Messages都不行。

    在这里插入图片描述

    1. 在对应的script中,接收InputAction触发的事件,完成“显示下一个图片”的逻辑
        public void ChangeStrokeImage(InputAction.CallbackContext context)
        {   if (context.action.name == "DrawNext") {
                if (context.performed) // Otherwise this will be triggered three times. 
                {
                    if (textures != null && textures.Length > 0)
                    {
                        currentIndex = currentIndex  % textures.Length;
                        strokeRawImage.texture = textures[currentIndex];
                        currentIndex = currentIndex + 1;
                    }
                }
            }
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
  • 相关阅读:
    抖音返利分销模式及代理系统开发
    Redis
    uniapp实现全局悬浮框
    29岁才转行软件测试,目前32了,我的一些经历跟感受
    Aspose.PSD for .NET 22.11.0 Crack
    # DWD层及DIM层构建## ,220801 ,
    Spark使用scala语言连接hive数据库
    MMML-CMU 学习笔记_No.1 Multimodal Introduction
    flink 技术总结待续
    数据结构 - 红黑树
  • 原文地址:https://blog.csdn.net/qq_35153254/article/details/133054081