SyncedKey Class

Alternative way of implementing InputSynchronizable.

Definition

Namespace: Alteruna
Assembly: Alteruna.Trinity (in Alteruna.Trinity.dll) Version: 1.3.4
C#
[SerializableAttribute]
public class SyncedKey
Inheritance
Object    SyncedKey

Example

Setup to sync the A key and listen to related event. You can also just as easy get the value directly from the SyncedKey.Value.
C#
using UnityEngine;
using UnityEngine.Events;
using Alteruna;

public class MyInputClass : MonoBehaviour
{
    // Reference to a InputSynchronizable.
    public InputSynchronizable Input;
    // Key field.
    private SyncedKey _myKey;

    void Awake()
    {
        // Setup key.
        _myKey = new SyncedKey(Input, KeyCode.A);

        // Listen to key event.
        _myKey.OnInputChanged.AddListener(KeyChange);
    }

    void KeyChange(SyncedKey key) {
        // This is the same value as _myKey.Value.
        Debug.Log(key.Value);
    }
}

SyncedKeys can also be set up by the inspector. but to work, they still need to be registered.
C#
using UnityEngine;
using Alteruna;

public class MyJumpClass : MonoBehaviour
{
    // Reference to a InputSynchronizable.
    public InputSynchronizable Input;
    // Jump input that we can setup in the inspector.
    public SyncedKey Jump;
    // Jump force.
    public float jumpForce = 10f;

    void Awake()
    {
        Jump.Register(Input);
    }

    private void Update()
    {
        if (Jump)
        {
            transform.Translate(0, Time.deltaTime * jumpForce, 0);
        }
    }
}
Inspector setup of SyncedAxis

Properties

Key Registered Keycode input. On set, reregister if already registered.
Value Value of target input key.

Methods

Deregister Deregister from IInput.
Register Register key to a previously set IInput.
Register(IInput) Register key to target IInput.
Register(IInput, KeyCode) Register key to target IInput.

Operators

(SyncedKey to Boolean) Get value of key.
(SyncedKey to Int32) Get value of key.
(SyncedKey to Single) Get value of key.

Fields

DoubleTapTime Max time between taps for a valid double tap for the key mode doubleTap
InputManager Connected IInput.
KeyState The raw value of target key unaffected by mode.
mode key mode.
OnInputChanged Invokes when value get changed.

See Also