public void beginSlide(Vector3 offset) { this.position_offset_initial = offset; this.position_offset = this.position_offset_initial; // 상태를 SLIDE로 변경. this.next_step = Tile.STEP.SLIDE; }
void Update() { Vector3 mouse_position; // 마우스 위치. this.tile_root.unprojectMousePosition(out mouse_position, Input.mousePosition); // 획득한 마우스 위치를 X와 Y만으로 한다. Vector2 mouse_position_xy = new Vector2(mouse_position.x, mouse_position.y); this.step_timer += Time.deltaTime; float slide_time = 0.2f; if (this.next_step == Tile.STEP.NONE) { // '상태정보 없음'의 경우. switch (this.step) { case Tile.STEP.SLIDE: if (this.step_timer >= slide_time) { // vanish_timer(사라질 때까지의 시간)이 0이면 VACANT(사라지는)상태로 이행. if (this.vanish_timer == 0.0f) { this.next_step = Tile.STEP.VACANT; // vanish_timer가 0이 아니면 IDLE(대기) 상태로 이행. } else { this.next_step = Tile.STEP.IDLE; } } break; } } // 다음 블록 상태가 정보 없음 이외인 동안 -> 다음 블록 상태가 변경된 경우 while (this.next_step != Tile.STEP.NONE) { this.step = this.next_step; this.next_step = Tile.STEP.NONE; switch (this.step) { case Tile.STEP.IDLE: // 대기 상태 this.position_offset = Vector3.zero; this.transform.localScale = Vector3.one * 1.0f; break; case Tile.STEP.GRABBED: // 잡힌 상태 this.transform.localScale = Vector3.one * 1.2f; break; case Tile.STEP.RELEASED: // 떨어져 있는 상태 this.position_offset = Vector3.zero; this.transform.localScale = Vector3.one * 1.0f; break; case Tile.STEP.VACANT: this.position_offset = Vector3.zero; break; } this.step_timer = 0.0f; } switch (this.step) { case Tile.STEP.GRABBED: // 잡힌 상태. // 잡힌 상태일 때는 항상 슬라이드 방향을 체크. this.slide_dir = this.calcSlideDir(mouse_position_xy); break; case Tile.STEP.SLIDE: // 슬라이드(교체) 중. // 블록을 서서히 이동하는 처리. float rate = this.step_timer / slide_time; rate = Mathf.Min(rate, 1.0f); rate = Mathf.Sin(rate * Mathf.PI / 2.0f); this.position_offset = Vector3.Lerp(this.position_offset_initial, Vector3.zero, rate); break; } //그리드 좌표를 실제 좌표로 변환 Vector3 position = GamePlay.calcTilePosition(this.i_pos) + this.position_offset; // 실제 위치를 새로운 위치로 변경. this.transform.position = position; }
public float step_timer = 0.0f; // 블록이 교체된 때의 이동시간 void Start() { this.setColor(this.color); // 색칠 this.next_step = Tile.STEP.IDLE; // 다음 블록을 대기중으로 }
public void endGrab() { this.next_step = Tile.STEP.IDLE; }
public void beginGrab() { this.next_step = Tile.STEP.GRABBED; }