Advertisement
natmaxex

PlayerStateFactory

Aug 11th, 2022 (edited)
809
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.42 KB | None | 0 0
  1. //Warning script dosnt work
  2. using System.Collections.Generic;
  3.  
  4. enum PlayerStates{
  5.     idle,
  6.     walk,
  7.     run,
  8.     jump,
  9.     grounded,
  10.     fall
  11. }
  12.  
  13. public class PlayerStateFactory
  14. {
  15.     PlayerStateMachine _context;
  16.     Dictionary<PlayerStates, PlayerBaseState> _states = new Dictionary<PlayerStates, PlayerBaseState>();
  17.  
  18.     public PlayerStateFactory(PlayerStateMachine currentContext) {
  19.         _context = currentContext;
  20.         _states[PlayerStates.idle] = new PlayerIdleState(_context, this);
  21.         _states[PlayerStates.walk] = new PlayerIdleState(_context, this);
  22.         _states[PlayerStates.run] = new PlayerIdleState(_context, this);
  23.         _states[PlayerStates.jump] = new PlayerIdleState(_context, this);
  24.         _states[PlayerStates.grounded] = new PlayerIdleState(_context, this);
  25.         _states[PlayerStates.fall] = new PlayerIdleState(_context, this);
  26.     }
  27.  
  28.     public PlayerBaseState Idle() {
  29.         return _states[PlayerStates.idle];
  30.     }
  31.     public PlayerBaseState Walk() {
  32.         return _states[PlayerStates.walk];
  33.     }
  34.     public PlayerBaseState Run()
  35.     {
  36.         return _states[PlayerStates.run];
  37.     }
  38.     public PlayerBaseState Jump()
  39.     {
  40.         return _states[PlayerStates.jump];
  41.     }
  42.     public PlayerBaseState Grounded()
  43.     {
  44.         return _states[PlayerStates.grounded];
  45.     }
  46.     public PlayerBaseState Fall()
  47.     {
  48.         return _states[PlayerStates.fall];
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement