Our project has the goal to publish at the mobile platform. To achieve the goal, the input should be changed into joystick, not WASD on keyboard. Searching the lecture on the youtube, also try to investigate via asset, I conclude the joystick should be implemented via user interaction with UI. The component with script for that was already exist on input system;On-Screen Stick
. The codes inside of script has large portion of my style for UI development. Since UI has been taken by team member, the priority of this changed to be lower.
In the quiz to measure our programming level, there are an example to fill the blank on FSM code script. Through the structure, I conceive the structure of player behaviour; Grouping the input - state - behaviour. However, I should consider the exceptional case of state which is not requires input. To organize the concept, I write list of my development.
To implement those on the project, I made code connection like below.
Consequently, I moved to make it on the script. the example classes by using that sequence can be seen in below.
public abstract class BehaviourBase : MonoBehaviour
{
protected InputBase input;
protected StateBase state;
protected Action action;
protected abstract void Init();
}
public class BehaviourMove : BehaviourBase
{
Rigidbody2D rb2D;
StateMachine stateMachine;
public UnityAction moveEvent;
public UnityAction stopEvent;
void Start() => Init();
protected override void Init()
{
input = new InputMove();
stateMachine = <Get StateMachine from Player Stat Handler>
state = <Get Move state from handler>
rb2D = GetComponent<Rigidbody2D>();
// subscribe methods on input action
...<InputHandler>...<InputAction>.performed += Move;
...<InputHandler>...<InputAction>.canceled += Stop;
}
void Move(InputAction.CallbackContext obj)
{
stateMachine.ChangeState(state)
moveEvent?.Invoke();
}
void Stop(InputAction.CallbackContext obj)
{
stateMachine.ChangeState(<StateIdle>)
stopEvent?.Invoke();
}
}