유니티 게임 매니저 관련 글

|
  1. public class GameManager {
  2.     private static GameMananger instance;
  3.  
  4.     private GameMananger() {
  5.         // initialize your game manager here. Do not reference to GameObjects here (i.e. GameObject.Find etc.)
  6.         // because the game manager will be created before the objects
  7.     }    
  8.  
  9.     public static GameManager Instance {
  10.         get {
  11.             if(instance==null) {
  12.                 instance = new GameManager();
  13.             }
  14.  
  15.             return instance;
  16.         }
  17.     }
  18.  
  19.     // Add your game mananger members here
  20.     public void Pause(bool paused) {
  21.     }
  22. ...
  23. }



사용할때


  1. // Always use the .Instance Property to get the current instance of the GameMananger)
  2. GameManager.Instance.Pause(true);








FSM관리

유한상태기계


게임의 흐름을 제어하는​​ 데 열거형을 사용한다.


  1. public enum StateType
  2. {
  3.     DEFAULT,      //Fall-back state, should never happen
  4.     WAITING,      //waiting for other player to finish his turn
  5.     STARTTURN,    //Once, on start of each player's turn
  6.     PLAYING,      //My turn
  7.     PLACING,      //placing a new obstacle
  8.     BUYING,       //Buying something new
  9.     SHOOTING,     //aiming to shoot
  10.     BALLWAIT,     //Waiting for ball to stop
  11.     TURNOVER,
  12.     GAMEOVER,
  13.     GAMESTART,
  14.     LOBBY,        //Player is in the lobby
  15.     MENU,         //Player is viewing in-game menu
  16.     OPTIONS       //player is adjusting game options
  17. };

Update() function 에 아래와 같이 정의해서 사용합니다.

  1. switch (state)
  2.         {
  3.             case StateType.PLACING:
  4.                 if (objectToPlace != null)
  5.                     PlaceObject();
  6.                 else
  7.                     Debug.Log("ERROR: No object to place.");
  8.                 break;
  9.             case StateType.BUYING:
  10.                 break;
  11.             case StateType.BALLWAIT:
  12.                 //StopBouncing();
  13.                 break;
  14.             case StateType.STARTTURN:
  15.                 print("New Turn by: " + nowPlaying);
  16.                 IEvent startTurn = new StartTurn();
  17.                 EventManager.instance.QueueEvent(startTurn);
  18.                 AddEnergy();
  19.                 SetState(StateType.PLAYING, this);
  20.                 break;
  21.             case StateType.PLAYING:
  22.                 //check for numActions > MaxActions
  23.                 break;
  24.             case StateType.SHOOTING:
  25.                 break;
  26.             case StateType.TURNOVER:
  27.                 ChangePlayer(); //Do this last (from server!)
  28.                 SetState(StateType.STARTTURN, this);
  29.                 print("Turn is over!");
  30.                 break;
  31.             default:
  32.                 Debug.Log("ERROR: Unknown game state: " + state);
  33.                 break;
  34.         }


Trackback 0 And Comment 0
prev | 1 | ··· | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | next