InputSynchronizable Class

Synchronize inputs (255 buttons and 255 axis maximum) The input vales will update on this and other clients simultaneously.

Definition

Namespace: Alteruna
Assembly: Alteruna.Trinity (in Alteruna.Trinity.dll) Version: 1.3.4
C#
public class InputSynchronizable : CommunicationBridge, 
	IInput
Inheritance
Object    Object    Component    Behaviour    MonoBehaviour    CommunicationBridge    InputSynchronizable
Implements
IInput

Remarks

Example

Sync inputs and move transform based on those inputs. Note that this does not sync position, after a while the positions could become unsynced.
C#
using UnityEngine;
using Alteruna;

public class SyncedPlayerMovement : MonoBehaviour
{
    //reference to a InputSynchronizable object in the scene with a avatar.
    public InputSynchronizable InputSync;
    public float Speed = 5;

    private void Start() {
        InputSync.AddAxis(new[] {"Horizontal", "Vertical"});
    }

    private void Update() {
        float scaledSpeed = Speed * Time.deltaTime;
        transform.Translate(
            scaledSpeed * InputSync.AxesValues[0],
            scaledSpeed * InputSync.AxesValues[1],
            0);
    }
 }

Properties

AxesValues Get synced axes values by index
KeyValues Get synced button values by index
OnKeyUpdate Event for changes in key inputs. passes KeyCode and state.

Methods

AddAxis(String) Add a axis to the InputSynchronizable
AddAxis(String) Add a array of axes to the InputSynchronizable
AddKey(KeyCode) Add a key to the InputSynchronizable
AddKey(KeyCode) Add a array of keys to the InputSynchronizable
Awake 
GetIndexOfAxis Get index of a registered keyCode. If the target keyCode dos not exist it returns -1
GetIndexOfKey Get index of a registered keyCode. If the target keyCode dos not exist it returns -1
Possessed
(Overrides CommunicationBridgePossessed(Boolean, User))
TryGetIndexOfAxis Attempts to get index of a registered keyCode. If the target keyCode dos not exist, return false and index will be 0
TryGetIndexOfKey Attempts to get index of a registered keyCode. If the target keyCode dos not exist, return false and index will be 0
Unpossessed
(Overrides CommunicationBridgeUnpossessed)
Update 

Fields

UseLocalInput Whether to use local input or use reply as input. When false, all clients including the sender will receive inputs simultaneously. (assuming identical connection)

See Also