public void SetMap() { FieldEventlistener mapListener = map.AddComponent <FieldEventlistener> (); mapListener.BeginDragEvent += delegate(GameObject gb, Vector3 dragDir) { isMovingMap = true; isContinueMovingMap = false; toMove = mainCamera.transform.localPosition; }; mapListener.OnDragEvent += delegate(GameObject gb, Vector3 dragDir) { moveMap(dragDir); }; mapListener.EndDragEvent += delegate(GameObject gb, Vector3 dragDir) { isContinueMovingMap = true; isMovingMap = false; }; }
// Use this for initialization public void initGrid() { nowIndex = PlayerData.getInstance().playerPos[1] + GRID_WIDTH * PlayerData.getInstance().playerPos[0]; PlayerData.getInstance().grids[nowIndex / GRID_WIDTH] [nowIndex % GRID_WIDTH].isFinish = true; //grids[nowIndex].reveal(); if (grids != null) { for (int i = 0; i < GRID_HEIGHT; i++) { for (int j = 0; j < GRID_WIDTH; j++) { if (grids[i * GRID_WIDTH + j] != null) { GameObject.Destroy(grids[i * GRID_WIDTH + j].gameObject); } } } } Vector2 picSize = gridPrefab.transform.GetChild(0).GetComponent <SpriteRenderer> ().sprite.bounds.size; for (int i = 0; i < GRID_HEIGHT; i++) { for (int j = 0; j < GRID_WIDTH; j++) { if (PlayerData.getInstance().grids[i][j] != null) { GameObject o = GameObject.Instantiate(gridPrefab, tr); ExploreGrid exploreGrid = o.GetComponent <ExploreGrid> (); o.transform.localPosition = new Vector3(j * GRID_INTERVAL_WIDTH, -i * GRID_INTERVAL_HEIGHT, 0); grids[i * GRID_WIDTH + j] = exploreGrid; int finalI = i; int finalJ = j; if (PlayerData.getInstance().grids [i] [j].isFinish) { exploreGrid.reveal(); } FieldEventlistener tListener = o.AddComponent <FieldEventlistener> (); tListener.ClickEvent += delegate(GameObject gb, Vector3 clickpos) { chooseEncounter(finalI * GRID_WIDTH + finalJ); }; } } } playerSymbol.transform.localPosition = new Vector3(PlayerData.getInstance().playerPos[1] * GRID_INTERVAL_WIDTH, -PlayerData.getInstance().playerPos[0] * GRID_INTERVAL_HEIGHT, 0); markGO.transform.localPosition = playerSymbol.transform.localPosition; initCameraControl(); SetMap(); Vector3 startPos = playerSymbol.transform.position; //startPos.x = 0; startPos.z = mainCamera.transform.position.z; { if (startPos.y < (cameraBound [1] + cameraHalfHeight)) { startPos.y = (cameraBound [1] + cameraHalfHeight); } if (startPos.y > (cameraBound [3] - cameraHalfHeight)) { startPos.y = (cameraBound [3] - cameraHalfHeight); } if (startPos.x < (cameraBound [0] + cameraHalfWidth)) { startPos.x = (cameraBound [0] + cameraHalfWidth); } if (startPos.x > (cameraBound [2] - cameraHalfWidth)) { startPos.x = (cameraBound [2] - cameraHalfWidth); } } mainCamera.transform.position = startPos; isMovingMap = false; isContinueMovingMap = false; }