private void LoadGrid() { string mapName; if (Vaults.mapName != null) { mapName = Vaults.mapName; } else { mapName = Config.defaultMapName; } TextAsset map = (TextAsset)Resources.Load(Config.mapLocation + mapName, typeof(TextAsset)); string[] hexDescriptions = map.text.Split(new string[] { Environment.NewLine }, StringSplitOptions.None); foreach (string description in hexDescriptions) { try { //Parse file input string desc; string q = description.Substring(0, description.IndexOf(',')); desc = description.Substring(description.IndexOf(',') + 1, description.Length - description.IndexOf(',') - 1); string r = desc.Substring(0, desc.IndexOf(',')); desc = desc.Substring(desc.IndexOf(',') + 1, desc.Length - desc.IndexOf(',') - 1); string t = desc; int qVal; int rVal; qVal = int.Parse(q); rVal = int.Parse(r); Terrain terrain = (Terrain)Enum.Parse(typeof(Terrain), t); //Instantiate in-game hexes Vector2 hexCoords = new Vector2(qVal, rVal); Vector2 worldCoords = HexVectorUtil.worldPositionOfHexCoord(hexCoords); GameObject hex = Instantiate(basicHex, new Vector3(worldCoords.x, worldCoords.y, 1), Quaternion.identity); hex.transform.SetParent(hexContainer); HexEntry newHex = new HexEntry(hex, hexCoords, terrain); HexGrid.Add(hexCoords, newHex); hexesByUniqueID.Add(newHex); //Text stuff: GameObject hexText = Instantiate(textPrefab, Vector2.Scale(worldCoords, Config.worldToCanvasCoordScaler), Quaternion.identity); hexText.GetComponent <UnityEngine.UI.Text>().text = hexCoords.ToString(); //hexText.GetComponent<UnityEngine.UI.Text>().text = "[_ _]"; hexText.transform.SetParent(worldCanvas.transform, false); newHex.debugText = hexText.GetComponent <UnityEngine.UI.Text>(); if (terrain == Terrain.Goal) { turnsRemainingText.transform.position = new Vector3(worldCoords.x, worldCoords.y + 0.23f, 0); turnsRemainingText.gameObject.SetActive(true); } } catch { } } }
private void OrientArrow(HexEntry start, HexEntry dest, GameObject arrow) { Vector2 startWorldPos = HexVectorUtil.worldPositionOfHexCoord(start.BoardPos); Vector2 destWorldPos = HexVectorUtil.worldPositionOfHexCoord(dest.BoardPos); arrow.transform.position = new Vector3(startWorldPos.x, startWorldPos.y, -3) + (Config.hitArrowPosScaler) * Vector3.Normalize(destWorldPos - startWorldPos); arrow.transform.rotation = Quaternion.FromToRotation(Vector2.right, destWorldPos - startWorldPos); }
private void OrientSegment(HexEntry start, HexEntry dest, GameObject segment) { Vector2 startWorldPos = HexVectorUtil.worldPositionOfHexCoord(start.BoardPos); Vector2 destWorldPos = HexVectorUtil.worldPositionOfHexCoord(dest.BoardPos); segment.transform.position = new Vector3(startWorldPos.x, startWorldPos.y, 2); segment.transform.rotation = Quaternion.FromToRotation(Vector2.right, destWorldPos - startWorldPos); }
public void CreateFriendlyFireWarning(HexEntry hex) { GameObject newFFWarning = Instantiate(friendlyFireWarning, HexVectorUtil.worldPositionOfHexCoord(hex.BoardPos), Quaternion.identity); newFFWarning.GetComponent <SpriteRenderer>().color = Config.Palette.attack; newFFWarning.transform.SetParent(hitArrowContainer.transform); ffWarnings.Add(newFFWarning); }
public void SnapToHexCoords(Vector2 hexCoords) { Vector2 newCameraSpot = HexVectorUtil.worldPositionOfHexCoord(hexCoords); newCameraSpot = ConformToBounds(newCameraSpot); mainCamera.transform.position = new Vector3(newCameraSpot.x, newCameraSpot.y, -10); cameraLerp = false; }
public void LerpToHexCoords(Vector2 hexCoords) { Vector2 newCameraSpot = HexVectorUtil.worldPositionOfHexCoord(hexCoords); newCameraSpot = ConformToBounds(newCameraSpot); cameraLerpTarget = new Vector3(newCameraSpot.x, newCameraSpot.y, -10); cameraLerp = true; }
public List <IUnitController> permittedUnits; // If null, not checked public void Initialize() { gameManager = GetComponent <GameManager>(); selectionManager = GetComponent <SelectionManager>(); scenarioLoader = GetComponent <ScenarioLoader>(); cameraHandler = GetComponent <CameraHandler>(); EnableInputs(); cameraHandler.Initialize(scenarioLoader.HexGrid.Values .Select(x => HexVectorUtil.worldPositionOfHexCoord(x.BoardPos)).ToList(), new Vector2(0, 0), new Vector2(1, 1)); }
private Vector2 FindCorner(HexEntry hex, float angle) { return(HexVectorUtil.worldPositionOfHexCoord(hex.BoardPos) + (Vector2)(Quaternion.AngleAxis(angle, Vector3.back) * Vector3.right * (Config.hexSize))); }