void ChainCube(ref List <Vector2Int> chainList, Vector2Int IntPosition, ACCube.CubeType cubeType) { ACCube targetCube = GetCube(IntPosition); if (targetCube == null) { return; } if (targetCube.cubeType != cubeType) { return; } if (chainList.Count(c => c == IntPosition) > 0) { return; } chainList.Add(IntPosition); ChainCube(ref chainList, new Vector2Int(IntPosition.x - 1, IntPosition.y), cubeType); ChainCube(ref chainList, new Vector2Int(IntPosition.x + 1, IntPosition.y), cubeType); ChainCube(ref chainList, new Vector2Int(IntPosition.x, IntPosition.y - 1), cubeType); ChainCube(ref chainList, new Vector2Int(IntPosition.x, IntPosition.y + 1), cubeType); }
public void CreateCubes(Vector2Int cubeCount) { this.cubeCount = cubeCount; defaultCubes = new ACCube[cubeCount.x, cubeCount.y]; defenseCubes = new ACCube[cubeCount.x, cubeCount.y]; start.x = -(cubeCount.x / 2.0f - 0.5f); start.y = -(cubeCount.y / 2.0f - 0.5f); for (int row = 0; row < cubeCount.y; row++) { for (int col = 0; col < cubeCount.x; col++) { ACCube cube = ACCubeManager.Instance.CreateRandomCube(); cube.transform.position = new Vector3(start.x + col, 0, start.y + row); cube.transform.parent = transform; defaultCubes[col, row] = cube; } } }
public List <Vector2Int> GetChainCube(Vector2Int IntPosition) { List <Vector2Int> chainList = new List <Vector2Int>(); ACCube targetCube = GetCube(IntPosition); if (targetCube != null) { ChainCube(ref chainList, IntPosition, targetCube.cubeType); } // Debug ACGameManager.Instance.player.transform.DOMoveY(1f, 0.3f).SetRelative().SetLoops(2, LoopType.Yoyo); chainList.ForEach(_ => { ACCube cube = GetCube(_); cube.transform.DOMoveY(1f, 0.3f).SetRelative().SetLoops(2, LoopType.Yoyo); }); //~Debug return(chainList); }