public Event2.TYPE getEventType(GameObject event_go) { Event2.TYPE type = Event2.TYPE.NONE; if (event_go != null) { // 인수의 GameObject가 비어있지 않으면. if (event_go.tag == "Rocket") { type = Event2.TYPE.ROCKET; } } return(type); }
// 지정된 게임 오브젝트의 이벤트 타입 반환 public string getIgnitableMessage(GameObject event_go) { string message = ""; Event2.TYPE type = Event2.TYPE.NONE; if (event_go != null) { type = this.getEventType(event_go); } switch (type) { case Event2.TYPE.ROCKET: message = "굽는다"; break; } return(message); }
// 철광석이나 식물을 든 상태에서 우주선에 접촉했는지 확인 public bool isEventIgnitable(Item.TYPE carried_item, GameObject event_go) { bool ret = false; Event2.TYPE type = Event2.TYPE.NONE; if (event_go != null) { type = this.getEventType(event_go); // 이벤트 타입을 구한다. } switch (type) { case Event2.TYPE.ROCKET: if (carried_item == Item.TYPE.IRON) { // 가지고 있는 것이 철광석이라면. ret = true; // '이벤트할 수 있어요!'라고 응답한다. } break; } return(ret); }
// Update is called once per frame // 상태를 변화시키는 부분, 상태가 변화했을 때의 처리 부분, 각 상태에서의 동작 부분에 추가 void Update() { this.get_input(); // 입력 정보 취득. this.step_timer += Time.deltaTime; float eat_time = 0.01f; float repair_time = 0.5f; // 상태를 변화시킨다---------------------. if (this.next_step == STEP.NONE) { // 다음 예정이 없으면. switch (this.step) { case STEP.MOVE: // '이동 중' 상태의 처리. do { if (!this.key.action) { // 액션 키가 눌려있지 않다. break; // 루프 탈출. } // 주목하는 이벤트가 있을 때. if (this.closest_event != null) { if (!this.is_event_ignitable()) { // 이벤트를 시작할 수 없으면. break; // 아무 것도 하지 않는다. } // 이벤트 종류를 가져온다. Event2.TYPE ignitable_event = this.event_root.getEventType(this.closest_event); switch (ignitable_event) { case Event2.TYPE.ROCKET: // 이벤트의 종류가 ROCKET이면. // REPAIRING(수리) 상태로 이행. this.next_step = STEP.REPAIRING; break; } break; } if (this.carried_item != null) { // 가지고 있는 아이템 판별. Item.TYPE carried_item_type = this.item_root.getItemType(this.carried_item); switch (carried_item_type) { case Item.TYPE.APPLE: // 사과라면. // case Item.TYPE.PLANT: // 식물이라면. // '식사 중' 상태로 이행. this.next_step = STEP.EATING; break; } } } while (false); break; case STEP.EATING: // '식사 중' 상태의 처리. if (this.step_timer > eat_time) { // 2초 대기. this.next_step = STEP.MOVE; // '이동' 상태로 이행. } break; case STEP.REPAIRING: // '수리 중' 상태의 처리. if (this.step_timer > repair_time) { // 2초 대기. this.next_step = STEP.MOVE; // '이동' 상태로 이행. } break; } } // 상태가 변화했을 때------------. while (this.next_step != STEP.NONE) { // 상태가 NONE이외 = 상태가 변화했다. this.step = this.next_step; this.next_step = STEP.NONE; switch (this.step) { case STEP.MOVE: break; case STEP.EATING: // '식사 중' 상태의 처리. if (this.carried_item != null) { // 들고 있는 아이템의 '체력 회복 정도'를 가져와서 설정. this.game_status.addSatiety( this.item_root.getRegainSatiety(this.carried_item)); // 가지고 있던 아이템을 폐기. GameObject.Destroy(this.carried_item); this.carried_item = null; } break; case STEP.REPAIRING: // '수리 중'이 되면. if (this.carried_item != null) { // 들고 있는 아이템의 '수리 진척 상태'를 가져와서 설정. this.game_status.addRepairment( this.item_root.getGainRepairment(this.carried_item)); // 가지고 있는 아이템 삭제. GameObject.Destroy(this.carried_item); this.carried_item = null; this.closest_item = null; } break; } this.step_timer = 0.0f; } // 각 상황에서 반복할 것----------. switch (this.step) { case STEP.MOVE: this.move_control(); this.pick_or_drop_control(); // 이동 가능한 경우는 항상 배가 고파진다. this.game_status.alwaysSatiety(); break; case STEP.REPAIRING: // 우주선을 회전시킨다. //this.rocket_model.transform.localRotation *= //Quaternion.AngleAxis(360.0f / 10.0f * Time.deltaTime, //Vector3.up); break; } }