// 보드 초기화 public void InitializeBoard() { int iBoardRow = GameData.iBoardRow, iBoardCol = GameData.iBoardCol; // 생성된 Dot이 있다면 제거 if (objBoardArray.transform.childCount > 0) { for (int i = 0; i < objBoardArray.transform.childCount; ++i) { Destroy(objBoardArray.transform.GetChild(i).gameObject); } } // 생성된 LinkLine이 있다면 제거 if (objLinkLines.transform.childCount > 0) { RemoveLinkLineAll(); } // 보드 데이터 생성 boardData = new DotObject[iBoardRow, iBoardCol]; Vector3 pos = Vector3.zero; // Dot의 위치 // 좌상 우하 순서로 Dot 생성 for (int i = 0; i < iBoardRow; ++i) { for (int j = 0; j < iBoardCol; ++j) { pos = new Vector3(-GameData.fBoardHalfWidth + j * GameData.fWidthDist, GameData.fBoardHalfHeight - i * GameData.fHeightDist, 0.00f); DotObject.CreateDot(pos, i, j, true, objBoardArray.transform, boardData); } } }
public void DrawDot(Vector2D Origin, DotObject ScreenObject) { if (!HudInit) { return; } switch (ScreenObject) { case DotObject.Center: CenterDot.Origin = Origin; return; case DotObject.Translate: TargetDot.Origin = Origin; return; case DotObject.Rotate: AlignmentDot.Origin = Origin; return; case DotObject.Tracker: TrackingDot.Origin = Origin; return; } }
// 링크 라인 생성 private void CreateLinkLine(DotObject dot) { // 생성 GameObject objLine = Instantiate(GameData.pfabLine, dot.transform.position, Quaternion.identity, objLinkLines.transform) as GameObject; LineRenderer lineRenderer = objLine.GetComponent <LineRenderer>(); DotObject lastDot = selectedDotList[selectedDotList.Count - 2]; Vector3 posOrigin = new Vector3(lastDot.transform.position.x, lastDot.transform.position.y, 0.20f), posFinal = new Vector3(dot.transform.position.x, dot.transform.position.y, 0.20f); Vector3[] posAry = { posOrigin, posFinal }; Color dotColor = dot.GetDotColor(); if (dot.enColor == DotObject.DotColor.DOT_COLOR_RAINBOW) { dotColor = lastDot.GetDotColor(); } lineRenderer.SetPositions(posAry); lineRenderer.startColor = dotColor; lineRenderer.endColor = dotColor; // 사운드 재생 GameObject objSound = Instantiate(GameData.pfabSoundEft, dot.transform.position, Quaternion.identity, objSounds.transform) as GameObject; AudioSource sound = objSound.GetComponent <AudioSource>(); sound.volume = (PlayerData.iSoundMultiply / 100.00f); sound.PlayOneShot(GameData.OctaveAudio[++iLastOctave % 7]); sound.pitch = (((objLinkLines.transform.childCount - 1) / 7) * 0.10f) + 1.00f; Destroy(objSound, 0.65f); }
// Dot을 선택 하는 메서드 private void SelectDot(DotObject dot) { if (dot != null) { dot.SelectDot(); selectedDotList.Add(dot); } }
public Vector2D DrawOtherDot(MatrixD _Matrix, Vector3D TargetPos, DotObject ScreenObject) { MatrixD ViewMatrix = MatrixD.Invert(_Matrix); MatrixD ViewProjectionMatrix = ViewMatrix * MyAPIGateway.Session.Camera.ProjectionMatrix; Vector3D Screenpos = Vector3D.Transform(TargetPos, ViewProjectionMatrix) * 3; var dotpos = new Vector2D(MathHelper.Clamp(Screenpos.Y, -0.98, 0.98), MathHelper.Clamp(Screenpos.X, -0.98, 0.98)); DrawDot(dotpos, ScreenObject); return(dotpos); }
// 스크린 드래그 public void ScrDragUpdate() { if (bScrClicked) { DotObject dot = GetDotInTouchPos(); if (CheckDot(dot)) { // 드래그중인 지점의 점 업데이트 SelectDot(dot); // 링크 라인 생성 CreateLinkLine(dot); } } }
// Dot링크 처리 메서드 private void UpdateLink() { if (selectedDotList.Count > 1) { for (int i = 0; i < selectedDotList.Count; ++i) { DotObject linkedDot = selectedDotList[i]; linkedDot.enState = DotObject.DotState.DOT_STATE_DELETING; linkedDot.transform.position += Vector3.forward; boardData[linkedDot.iRow, linkedDot.iCol] = null; } selectedDotList.Clear(); UpdateDataBoard(); FillDataBoard(); } else if (selectedDotList.Count == 1) { selectedDotList[0].enState = DotObject.DotState.DOT_STATE_NORMAL; selectedDotList.Clear(); } }
// Databoard의 빈 공간 채우기 private void FillDataBoard() { Vector3 pos; for (int i = 0; i < GameData.iBoardRow; ++i) { for (int j = 0; j < GameData.iBoardCol; ++j) { if (boardData[i, j] == null) { switch (enGravityDir) { default: case GravityDirection.GRAVITY_DOWN: pos = new Vector3(-GameData.fBoardHalfWidth + j * GameData.fWidthDist, GameData.fBoardHeight - i * GameData.fHeightDist, 0.00f); break; case GravityDirection.GRAVITY_UP: pos = new Vector3(-GameData.fBoardHalfWidth + j * GameData.fWidthDist, -GameData.fBoardHeight - i * GameData.fHeightDist, 0.00f); break; case GravityDirection.GRAVITY_LEFT: pos = new Vector3(GameData.fBoardWidth + j * GameData.fWidthDist, GameData.fBoardHalfHeight - i * GameData.fHeightDist, 0.00f); break; case GravityDirection.GRAVITY_RIGHT: pos = new Vector3(-GameData.fBoardWidth + j * GameData.fWidthDist, GameData.fBoardHalfHeight - i * GameData.fHeightDist, 0.00f); break; case GravityDirection.GRAVITY_OUTWARDS: pos = new Vector3(-GameData.fBoardHalfWidth + j * GameData.fWidthDist, GameData.fBoardHalfHeight - i * GameData.fHeightDist, 0.00f); break; } DotObject.CreateDot(pos, i, j, true, objBoardArray.transform, boardData); } } } }
// 올바른 조건의 Dot인지 확인하는 메서드 private bool CheckDot(DotObject dot) { // 현재 선택된 Dot이 있는지 확인 if (dot == null) { return(false); } // 기존에 선택된 Dot이 있는지 확인 int iDotCount = selectedDotList.Count; if (iDotCount <= 0) { return(false); } // 선택된 Dot이 Normal상태의 Dot인지 확인 if (dot.enState != DotObject.DotState.DOT_STATE_NORMAL) { return(false); } // 기존에 선택된 Dot과 십자(+)로 인접한 Dot인지 확인 DotObject lastDot = selectedDotList[iDotCount - 1]; int iCol = lastDot.iCol, iRow = lastDot.iRow; bool bDotAdjacent = false; if (iRow - 1 > -1) // 기존에 선택된 Dot위치에서 상하좌우를 비교하여 새로 선택된 Dot이 인접한지 확인 { if (boardData[iRow - 1, iCol] == dot) { bDotAdjacent = true; // 상단 } } if (iRow + 1 < GameData.iBoardRow) { if (boardData[iRow + 1, iCol] == dot) { bDotAdjacent = true; // 하단 } } if (iCol - 1 > -1) { if (boardData[iRow, iCol - 1] == dot) { bDotAdjacent = true; // 좌측 } } if (iCol + 1 < GameData.iBoardCol) { if (boardData[iRow, iCol + 1] == dot) { bDotAdjacent = true; // 우측 } } if (!bDotAdjacent) { return(false); } // 색상 비교 if (dot.enColor != DotObject.DotColor.DOT_COLOR_RAINBOW && lastDot.enColor != DotObject.DotColor.DOT_COLOR_RAINBOW) { if (lastDot.enColor != dot.enColor) { return(false); } } // 모든 조건을 충족한 경우 true반환 return(true); }