Inputs.Player
This is the global interface for a player. It may be your main physic player class or just used by your main player class. In this case, just name it Player
.
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using EODE.Wonderland;
using UnityEngine;
namespace MyProject {
public class InputsPlayer : Player<ActionType> {
public short Num {
get { return (short) base.Number; }
}
// for external uses
public System.Action<Vector2> DirectionChanged = delegate { };
public InputsPlayer() : base() {
// Smoothing direction limits the chaos. Useful on network applications. But adds latency.
OnControllerChange += () => {
if (Controller != null && Controller.ControllerType == typeof(Joystick)) {
SmoothingDirection = 5; // 6 = 0.1 s react
} else {
SmoothingDirection = 0;
}
};
}
#region Events from controllers
public override void StartMove() {
ChangeMove();
}
public override void ChangeMove() {
DirectionChanged.Invoke(Move);
}
public override void StopMove() {
DirectionChanged.Invoke(Move);
}
public override void Action(ActionType type) {
// manage your actions here or inherit Action directly
base.Action(type);
}
public override void ActionRelease(ActionType type) {
base.ActionRelease(type);
}
#endregion
public override void SetAction(ActionType type, IAction<ActionType> act) {
if (act != null || Controller != null) { // action cant be removed without Controller
base.SetAction(type, act);
}
}
public async void ReleaseAllActions() {
await new WaitForEndOfFrame();
foreach (var act in _actions) {
act.Value.StopIt();
}
}
}
}