csharp InControl的输入接口#Input #Pad #Control

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp InControl的输入接口#Input #Pad #Control相关的知识,希望对你有一定的参考价值。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public abstract class InputBase : MonoBehaviour
{
    //------------------------------------------------------------------------------------------------------------------
    public abstract Vector3 UpdateInput();
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class InputKeyboard : InputBase
{
 
    //------------------------------------------------------------------------------------------------------------------
    [Header("Input")] 
    [SerializeField]
    private KeyCode _leftInput;
    [SerializeField]
    private KeyCode _rightInput;
    [SerializeField]
    private KeyCode _upInput;
    [SerializeField]
    private KeyCode _downInput;
    [SerializeField] 
    private float _smoothFactor = .2f;
    
    
    Vector3 dir = Vector3.zero;
    
    //------------------------------------------------------------------------------------------------------------------
    public override Vector3 UpdateInput()
    {
        bool anyKey = false;
        
        if (Input.GetKey(_leftInput))
        {
            dir += Vector3.left * _smoothFactor;
            anyKey = true;
        }
        else if (Input.GetKey(_rightInput))
        {
            dir += Vector3.right * _smoothFactor;
            anyKey = true;
        }

        if (Input.GetKey(_upInput))
        {
            dir += Vector3.forward * _smoothFactor;
            anyKey = true;
        }
        else if (Input.GetKey(_downInput))
        {
            dir += Vector3.back * _smoothFactor;
            anyKey = true;
        }
        
        if(!anyKey)
        {
            dir = Vector3.zero;
        }

        dir.Normalize();
        return dir;
    }
}
using System.Collections;
using System.Collections.Generic;
using InControl;
using UnityEngine;

public class InputMouse : InputBase
{
    //------------------------------------------------------------------------------------------------------------------
    public override Vector3 UpdateInput()
    {
        Vector3 dir = Vector3.zero;

        if (Input.GetMouseButton(0))
        {
            dir = new Vector3(Input.GetAxis("Mouse X"), 0.0f, Input.GetAxis("Mouse Y"));
        }

        return dir;
    }
}
using System.Collections;
using System.Collections.Generic;
using InControl;
using UnityEngine;

public class InputVirtualJoystick : InputBase
{
    //------------------------------------------------------------------------------------------------------------------
    public override Vector3 UpdateInput()
    {
        Vector3 dir = Vector3.zero;
        // Use last device which provided input.
        var inputDevice = InputManager.ActiveDevice;

        // Disable and hide touch controls if we use a controller.
        // If "Enable Controls On Touch" is ticked in Touch Manager inspector,
        // controls will be enabled and shown again when the screen is touched.
        if (inputDevice != InputDevice.Null)
        {
            if (inputDevice != TouchManager.Device)
            {
                TouchManager.ControlsEnabled = false;
            }
            else
            {
                dir = new Vector3(inputDevice.Direction.X, 0.0f, inputDevice.Direction.Y);
            }
        }

        return dir;
    }
}
using System;
using InControl;
using Spectrum;
using UnityEngine;

public class InputVisibility : MonoBehaviour
{
    private TouchManager _touchManager;

    //------------------------------------------------------------------------------------------------------------------
    private void Awake()
    {
        _touchManager = GetComponent<TouchManager>();
    }

    //------------------------------------------------------------------------------------------------------------------
    private void Start()
    {
        God.GameLogic.OnGamePaused += OnGamePaused;
        God.GameLogic.OnGameResumed += OnGameResumed;
    }

    //------------------------------------------------------------------------------------------------------------------
    private void OnGameResumed()
    {
        _touchManager.controlsEnabled = true;
        _touchManager.enableControlsOnTouch = true;   
    }

    //------------------------------------------------------------------------------------------------------------------
    private void OnGamePaused()
    {
        _touchManager.controlsEnabled = false;
        _touchManager.enableControlsOnTouch = false;   
    }    
}

以上是关于csharp InControl的输入接口#Input #Pad #Control的主要内容,如果未能解决你的问题,请参考以下文章

输入输出&格式化

enumerate+range

Python在输入一串数字时删除尾随空格

小作业(用户登陆(三次机会重试))

jQuery datepicker 更改事件触发和输入的默认更改事件

如何控制input输入的数字最多有两位小数?