Post by britannis on Mar 24, 2016 18:32:14 GMT
Hi,
I'm trying to modify your event-based input controller to work with horizontal/vertical movement instead of points. I created a MovementDirs enum that specifies Left, Right, Up, Down. This is my update function in my InputController:
You'll notice the only major change from your code is the following:
However, I'm getting stuck in my usage. In my PlayerController that inherits from the InputController, I'm a little lost on how to use the MovementDirs to move my character:
Specifically, I'm lost at the OnMoveEvent function. How should I be doing this?
I'm trying to modify your event-based input controller to work with horizontal/vertical movement instead of points. I created a MovementDirs enum that specifies Left, Right, Up, Down. This is my update function in my InputController:
// Instead of handling input every frame, we handle it according to events within the main loop for performance.
void Update()
{
// Set axis variables to update according to the Repeater instead of general Update() loop.
int x = _hor.Update();
int y = _ver.Update();
// If we have movement input, then execute the movement input event at the appropriate time.
if (x != 0 || y != 0)
{
if (moveEvent != null)
{
if (x > 0)
moveEvent(this, new InfoEventArgs<MovementDirs>(MovementDirs.Left));
if (x < 0)
moveEvent(this, new InfoEventArgs<MovementDirs>(MovementDirs.Right));
if (y > 0)
moveEvent(this, new InfoEventArgs<MovementDirs>(MovementDirs.Up));
if (y < 0)
moveEvent(this, new InfoEventArgs<MovementDirs>(MovementDirs.Down));
}
}
// Loop through each of our firing inputs.
for (int i = 0; i < _fires.Length; ++i)
{
// We specify button up since the firing button release is considered confirmation.
if (CrossPlatformInputManager.GetButtonUp(_fires[i]))
{
if (fireEvent != null)
fireEvent(this, new InfoEventArgs<int>(i));
}
}
}
You'll notice the only major change from your code is the following:
// If we have movement input, then execute the movement input event at the appropriate time.
if (x != 0 || y != 0)
{
if (moveEvent != null)
{
if (x > 0)
moveEvent(this, new InfoEventArgs<MovementDirs>(MovementDirs.Left));
if (x < 0)
moveEvent(this, new InfoEventArgs<MovementDirs>(MovementDirs.Right));
if (y > 0)
moveEvent(this, new InfoEventArgs<MovementDirs>(MovementDirs.Up));
if (y < 0)
moveEvent(this, new InfoEventArgs<MovementDirs>(MovementDirs.Down));
}
}
However, I'm getting stuck in my usage. In my PlayerController that inherits from the InputController, I'm a little lost on how to use the MovementDirs to move my character:
void OnEnable()
{
moveEvent += OnMoveEvent;
//fireEvent += OnFireEvent;
}
void OnDisable()
{
moveEvent -= OnMoveEvent;
//fireEvent -= OnFireEvent;
}
void OnMoveEvent(object sender, InfoEventArgs<MovementDirs> e)
{
Debug.Log("Move " + e.info.ToString());
}
Specifically, I'm lost at the OnMoveEvent function. How should I be doing this?