public class GameManager { private static GameMananger instance; private GameMananger() { // initialize your game manager here. Do not reference to GameObjects here (i.e. GameObject.Find etc.) // because the game manager will be created before the objects } public static GameManager Instance { get { if(instance==null) { instance = new GameManager(); } return instance; } } // Add your game mananger members here } ... }
사용할때
// Always use the .Instance Property to get the current instance of the GameMananger)
FSM관리
유한상태기계
게임의 흐름을 제어하는 데 열거형을 사용한다.
public enum StateType { DEFAULT, //Fall-back state, should never happen WAITING, //waiting for other player to finish his turn STARTTURN, //Once, on start of each player's turn PLAYING, //My turn PLACING, //placing a new obstacle BUYING, //Buying something new SHOOTING, //aiming to shoot BALLWAIT, //Waiting for ball to stop TURNOVER, GAMEOVER, GAMESTART, LOBBY, //Player is in the lobby MENU, //Player is viewing in-game menu OPTIONS //player is adjusting game options };Update() function 에 아래와 같이 정의해서 사용합니다.
{ case StateType.PLACING: if (objectToPlace != null) PlaceObject(); else break; case StateType.BUYING: break; case StateType.BALLWAIT: //StopBouncing(); break; case StateType.STARTTURN: IEvent startTurn = new StartTurn(); EventManager.instance.QueueEvent(startTurn); AddEnergy(); SetState(StateType.PLAYING, this); break; case StateType.PLAYING: //check for numActions > MaxActions break; case StateType.SHOOTING: break; case StateType.TURNOVER: ChangePlayer(); //Do this last (from server!) SetState(StateType.STARTTURN, this); break; default: break; }
'잡다한것들전부 > 팁' 카테고리의 다른 글
| [펌] 유니티 러너 게임 질문 (0) | 2013.12.06 |
|---|---|
| [펌] 유니티 메모리 관리 (0) | 2013.12.05 |
| 유니티 게임 매니저 관련 글 (0) | 2013.12.05 |
| 유니티 가로 세로 모드 설정 (0) | 2013.12.05 |
| 유니티 해상도 대응하기 (0) | 2013.12.04 |
| 까페에서 공부하는 느낌이 나는 분위기를 조성하는 사이트 (0) | 2013.11.28 |
Trackback 0 And
Comment 0


