private void _InstantiateHexagon(Vector3Int coords) { Vector3 worldSpacePos = HexMath.HexCoordsToWorldSpace(coords); GameObject HexagonGO = Instantiate(HexagonPrefab, worldSpacePos, Quaternion.identity, gameObject.transform); HexagonGO.name = "Hex " + coords.ToString(); Hexagon hexagon = HexagonGO.AddComponent <Hexagon>(); hexagon.Initialise(coords, 1); HexDict.Add(coords, hexagon); }
//---------------------------------------------------------------------------- // Get Path Value //---------------------------------------------------------------------------- /// <summary> /// GetPathValue checks if a hex has been visited before. <para/> /// If it has, return the original PathValue <para/> /// Otherwise, construct a new PathValue /// /// </summary> public IPathValue GetPathValue(IHexagon hex) { if (PathValueDict.ContainsKey(hex)) { return(PathValueDict[hex]); } else { Vector3 centre = (Destination.HexTransform.position + Start.HexTransform.position) / 2; IPathValue myPath = new PathValue(400000, HexMath.FindDistance(hex, Destination), centre, hex, null); PathValueDict.Add(hex, myPath); return(myPath); } }
//---------------------------------------------------------------------------- // ConnectContentsToHex //---------------------------------------------------------------------------- #region ConnectContentsToHex /// <summary> /// Initialise the IHexContents subsystem <para /> /// This allows objects/map to interact /// </summary> public void ConnectContentsToHex() { IContentMarker[] hexContentMarkers = GameObject.FindObjectsOfType <IContentMarker>(); foreach (IContentMarker hexContentMarker in hexContentMarkers) { GameObject go = hexContentMarker.gameObject; IContents contents = go.GetComponent <IContents>(); //object told about hex contents.Location = HexDict[HexMath.CalculateHexCoords(contents.ContentTransform.position)]; //hex told about object contents.Location.Contents = contents; //Move the object to the centre of the hex contents.ContentTransform.position = HexMath.HexCoordsToWorldSpace(contents.Location.MyHexMap.CoOrds); contents.Initialise(); } }