Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Draft] Modified OnScreenControl to support a customisable update mode #1792

Draft
wants to merge 7 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Assets/Debugging.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Debugging : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{

}

// Update is called once per frame
void Update()
{

}
}
11 changes: 11 additions & 0 deletions Assets/Debugging.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 66 additions & 0 deletions Assets/Samples/OnScreenControls/OnScreenControlsSample.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// This example showcases how to use on-screen controls and showcases how to use
// OnScreenStick and OnScreenButton which are two types of on-screen controls included with the Input System.
// In this example, multiple OnScreenButton component instances and OnScreenStick component instances are
// attached to a Canvas to build an on-screen gamepad.
//
// The OnScreenControl game objects LeftStick, RightStick, A, B, X, Y have all been configured to associated
// with a gamepad layout. This implies that they generate input similar to a real hardware gamepad.
// Due to this, InputActions bound to gamepad controls such as the controls mentioned above will hence be
// triggered when the user interacts with the on-screen controls.
// This example uses actions defined in OnScreenControlsSampleActions.inputactions which are preconfigured to
// bind to gamepad controls. Hence this example will work the same way when using either the on-screen controls
// or a physical gamepad.
//
// Note that on-screen controls 1 and 2 on the other hand are bound to a keyboard control layout and therefore
// generates input events similar to a physical hardware keyboard.
//
// When actions defined for this sample are triggered, a log message is generated to show when the actions
// are performed.
//
// Note that actions for this example have been setup to allow either on-screen controls or physical gamepad/keyboard
// controls to be used interchangeably.

using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.OnScreen;

public sealed class OnScreenControlsSample : MonoBehaviour
{
public InputActionReference mode1, mode2, leftStick, rightStick, x, y, a, b;
public OnScreenControlUpdateMode updateMode;

void UpdateCurrentMode(OnScreenControlUpdateMode mode)
{
Debug.Log($"Switched to OnScreenControl Update Mode: {mode.ToString()}");
foreach (var onScreenControl in GetComponentsInChildren<OnScreenControl>())
onScreenControl.updateMode = mode;
}

void EnableAndLogPerformed(InputActionReference reference)
{
reference.action.Enable();
reference.action.performed += Performed;
}

void Start()
{
UpdateCurrentMode(updateMode);
EnableAndLogPerformed(mode1);
mode1.action.performed += (_) => UpdateCurrentMode(OnScreenControlUpdateMode.QueueEvents);
EnableAndLogPerformed(mode2);
mode2.action.performed += (_) => UpdateCurrentMode(OnScreenControlUpdateMode.ChangeState);

EnableAndLogPerformed(x);
EnableAndLogPerformed(y);
EnableAndLogPerformed(a);
EnableAndLogPerformed(b);

EnableAndLogPerformed(leftStick);
EnableAndLogPerformed(rightStick);
}

void Performed(InputAction.CallbackContext context)
{
Debug.Log($"Performed action={context.action.name}, Time.frameCount={Time.frameCount}, context.time={context.time}, Time.time={Time.time}");
}
}
11 changes: 11 additions & 0 deletions Assets/Samples/OnScreenControls/OnScreenControlsSample.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading