public override void Triangulate(HexMesh mesh) { Vector3 v1 = beginCorner; Vector3 v2 = beginCorner; Color c1 = beginCell.Color; Color c2 = beginCell.Color; for (int step = 1; step < HexMetrics.terraceSteps + 1; ++step) { Vector3 v3 = HexMetrics.TerraceLerp(beginCorner, leftCorner, step); Vector3 v4 = HexMetrics.TerraceLerp(beginCorner, rightCorner, step); Color c3 = HexMetrics.ColorLerp(beginCell.Color, leftCell.Color, step); Color c4 = HexMetrics.ColorLerp(beginCell.Color, rightCell.Color, step); if (step == 1) { mesh.AddTriangle(v1, v3, v4); mesh.AddTriangleColor(c1, c3, c4); } else { mesh.AddQuad(v1, v2, v3, v4); mesh.AddQuadColor(c1, c2, c3, c4); } v1 = v3; v2 = v4; c1 = c3; c2 = c4; } }
void Awake() { SetParentCell(); hexMesh = GetComponentInChildren <HexMesh>(); // rnd = new System.Random(); UnityEngine.Random.InitState(seed); }
private void Awake() { _hexMesh = GetComponentInChildren <HexMesh>(); _toucher = Instantiate(_toucher); _toucher.TouchedCell += OnCellTouched; _cells = new HexCell[_width * _height]; for (int z = 0; z < _height; z++) { for (int x = 0; x < _width; x++) { _cells[x + z * _height] = CreateCell(x, z); SetNeigbor(x, z); } } for (int z = 0; z < _height; z++) { for (int x = 0; x < _width; x++) { var cell = _cells[x + z * _height]; cell.SetMarkText(cell.GetRealNeigborCount().ToString()); } } }
void InitializeHexCells() { gridCanvas = GetComponentInChildren <Canvas>(); hexMesh = GetComponentInChildren <HexMesh>(); cellArray = new HexCell[width * height]; for (int z = 0, i = 0; z < height; z++) { for (int x = 0; x < width; x++, i++) { Vector3 position; position.x = (x + z * 0.5f - z / 2) * HexMetrices.InnerRadius * 2; position.z = z * HexMetrices.OuterRadius * 1.5f; position.y = 0f; HexCell cell = cellArray[i] = Instantiate <HexCell>(CellPrefab); cell.HexCellColor = Color.white; cell.transform.SetParent(transform, false); cell.transform.localPosition = position; Text label = Instantiate <Text>(cellLabelPrefab); label.rectTransform.SetParent(gridCanvas.transform, false); label.rectTransform.anchoredPosition = new Vector2(position.x, position.z); label.text = (x - z / 2).ToString() + "\n" + z.ToString(); } } hexMesh.Triangulate(cellArray); }
public void Triangulate(HexMesh mesh) { for (HexDirection direction = HexDirection.NE; direction <= HexDirection.NW; direction++) { Vector3 center = Position; EdgeVertices edge = new EdgeVertices( Position + HexMetrics.GetFirstSolidCorner(direction), Position + HexMetrics.GetSecondSolidCorner(direction) ); mesh.AddTriangle(Position, edge.v1, edge.v2); mesh.AddTriangleColor(Color, Color, Color); mesh.AddTriangle(Position, edge.v2, edge.v3); mesh.AddTriangleColor(Color, Color, Color); mesh.AddTriangle(Position, edge.v3, edge.v4); mesh.AddTriangleColor(Color, Color, Color); mesh.AddTriangle(Position, edge.v4, edge.v5); mesh.AddTriangleColor(Color, Color, Color); HexCell neighbor = GetNeighbor(direction); if (direction <= HexDirection.SE && neighbor != null) { edges[(int)direction] = HexEdge.Build(this, neighbor, direction); edges[(int)direction].Triangulate(mesh); HexCell nextNeighbor = GetNeighbor(direction.Next()); if (direction <= HexDirection.E && nextNeighbor != null) { corners[(int)direction] = Corner.Build(this, neighbor, nextNeighbor, direction); corners[(int)direction].Triangulate(mesh); } } } }
public HexMapGenerator(IMap map, HexMesh hexMesh, Transform cellParent) { _map = map; _hexMesh = hexMesh; _hexCellViewFactory = new HexCellViewFactory(_settings.CellViewPrefab, cellParent); _hexCellPresenterFactory = new HexCellPresenterFactory(); }
void Awake() { gridCanvas = GetComponentInChildren <Canvas>(); hexMesh = GetComponentInChildren <HexMesh>(); cells = new HexCell[height * width]; objectiveCells = new List <HexCell>(); //for (int z = 0, i = 0; z < height; z++) //{ // for (int x = 0; x < width; x++) // { // CreateCell(x, z, i++); // } //} for (int z = 0; z < height; z++) { int w; if (z % 2 == 1) { w = width - 1; } else { w = width; } for (int x = 0; x < w; x++) { CreateCell(x, z, z * width + x); } } }
public void AddBridge(HexDirection direction, HexMesh hex) { HexMesh neighbor = GetNeighbor(direction, hex); if (neighbor == null) { return; } hex.AddNeighbor(direction, neighbor); Vector3[] vertices = new Vector3[4]; vertices[0] = hex.GetCorner(direction); vertices[1] = hex.GetCorner(direction.Next()); vertices[2] = neighbor.GetCorner(direction.Opposite()); vertices[3] = neighbor.GetCorner(direction.Opposite().Next()); int[] triangles = { lVertices.IndexOf(vertices[0]), lVertices.IndexOf(vertices[2]), lVertices.IndexOf(vertices[1]), lVertices.IndexOf(vertices[2]), lVertices.IndexOf(vertices[0]), lVertices.IndexOf(vertices[3]) }; if (!ExistsInList(triangles, lTriangles)) //double check to not add duplicate triangles { lTriangles.AddRange(triangles); } else { Debug.Log("!!Trying to add duplicate triangles!!"); } }
private void Awake() { gridCanvas = GetComponentInChildren <Canvas>(); hexMesh = GetComponentInChildren <HexMesh>(); cells = new HexCell[HexMetrics.CHUNK_SIZE_X * HexMetrics.CHUNK_SIZE_Z]; }
void Awake() { gridCanvas = GetComponentInChildren <Canvas>(); hexMesh = GetComponentInChildren <HexMesh>(); attackSprite = GameObject.Find("Attack"); healthSprite = GameObject.Find("Health"); reachSprite = GameObject.Find("Reach"); enemySprite = GameObject.Find("Enemy"); attackText = GameObject.Find("AttackText").GetComponent <Text>(); healthText = GameObject.Find("HealthText").GetComponent <Text>(); reachText = GameObject.Find("ReachText").GetComponent <Text>(); enemyText = GameObject.Find("EnemyText").GetComponent <Text>(); gameState = new GameState(); gameState.setup(); attackText.text = gameState.levelStarter.attack.ToString(); healthText.text = gameState.levelStarter.health.ToString(); reachText.text = gameState.levelStarter.reach.ToString(); enemyText.text = gameState.levelStarter.enemyPower.ToString(); cells = new HexCell[height * width]; for (int z = 0, i = 0; z < height; z++) { for (int x = 0; x < width; x++) { CreateCell(x, z, i++); } } musicPlayerScriptUsageTimeline = GameObject.Find("MusicPlayer").GetComponent <ScriptUsageTimeline>(); }
public void CreateGrid(int width, int height) { mWidth = width; mHeight = height; lVertices = new List <Vector3>(); lTriangles = new List <int>(); hexMeshes = new HexMesh[width, height]; int hexIndex = 0; int vOffset = 0; for (int x = 0; x < width; ++x) { for (int z = 0; z < height; ++z) { hexMeshes[x, z] = new HexMesh(x, z, hexIndex * 7 + vOffset); lVertices.AddRange(hexMeshes[x, z].GetVertices()); lTriangles.AddRange(hexMeshes[x, z].GetTriangles()); ++hexIndex; Debug.Log("Vertices for hex " + x + ", " + z + ": " + lVertices.Count); Debug.Log("Triangles for hex " + x + ", " + z + ": " + lTriangles.Count); HexMesh currentHex = hexMeshes[x, z]; for (HexDirection dir = HexDirection.SE; dir <= HexDirection.NW; ++dir) { if (GetNeighbor(dir, currentHex) != null) { AddBridge(dir, currentHex); AddTriangle(dir, currentHex); } } Debug.Log("Vertices after bridges and tris: " + lVertices.Count); Debug.Log("Triangles after bridges and tris: " + lTriangles.Count); } } }
void CreateCell(int x, int z, int i) { Debug.Log(x + " " + z + " = " + i + " = " + landList [z, x]); Vector3 position; position.x = (x + z * 0.5f - z / 2) * (HexMetrics.innerRadius * 2f); //position.y = heightList[x,z]* 20; position.y = 0; position.z = z * (HexMetrics.outerRadius * 1.5f); HexMesh hex = Instantiate <HexMesh>(hexMesh); hex.transform.SetParent(transform, false); hex.transform.localPosition = position; hex.GetComponent <HexMesh> ().countryNo = landList [z, x]; //countries.Add (new Countries(int [0,0])); hex.GetComponent <Renderer> ().material = material_list[landList[z, x] % material_list.Length]; //HexCell cell = cells[i] = Instantiate<HexCell>(cellPrefab); //cell.transform.SetParent(transform, false); //cell.transform.localPosition = position; /* * Text label = Instantiate<Text>(cellLabelPrefab); * label.rectTransform.SetParent(gridCanvas.transform, false); * label.rectTransform.anchoredPosition3D = new Vector3(position.x, position.z, (position.y *-1)); * label.text = landList[z,x].ToString(); */ }
void Start() { gridCanvas = GetComponentInChildren <Canvas>(); hexMesh = GetComponentInChildren <HexMesh>(); //Calculate grid position and scale according to the aspect ratio. Vector3 worldPos = Camera.main.ScreenToWorldPoint(-Camera.main.transform.localPosition); Vector3 outerRadius = new Vector3(HexMetrics.outerRadius, HexMetrics.outerRadius, 0f); transform.localScale = transform.localScale * Camera.main.aspect / (200f / 300f); transform.position = worldPos + Vector3.Scale(outerRadius, transform.lossyScale); //Adapt the grid size to fit the screen. Vector3 maxWorldPos = Camera.main.ViewportToWorldPoint(new Vector3(Camera.main.rect.width - Camera.main.rect.x, Camera.main.rect.height - Camera.main.rect.y, 0f)); Vector3 maxLocalPos = transform.InverseTransformPoint(maxWorldPos); HexCoordinates maxCoordinates = HexCoordinates.FromPosition(maxLocalPos); width = maxCoordinates.X; height = maxCoordinates.Y - 1; //Remove 1 to keep one extra line for the score display. cells = new HexCell[width, height]; for (int y = 0; y < height; ++y) { for (int x = 0; x < width; ++x) { CreateCell(x, y); } } if (Debug.isDebugBuild) { hexMesh.Triangulate(cells); } }
public ChunkDataset GetChunkDataset(int xP, int zP) { ChunkDataset dataset = new ChunkDataset(); dataset.xPos = xP; dataset.xPos = zP; for (int x = 0; x < MapMetrics.chunkSize; ++x) { for (int z = 0; z < MapMetrics.chunkSize; ++z) { HexMesh currentMesh = hexMeshes[x + xP, z + zP]; dataset.verts.AddRange(currentMesh.GetVertices()); int minTri = int.MaxValue; int[] newTris = currentMesh.GetTriangles(); for (int i = 0; i < newTris.Length; ++i) { if (newTris[i] < minTri) { minTri = newTris[i]; } } for (int i = 0; i < newTris.Length; ++i) { newTris[i] -= minTri; } dataset.tris.AddRange(newTris); } } return(dataset); }
// Life Cycle private void Awake() { _gridCanvas = GetComponentInChildren <Canvas>(); _hexMesh = GetComponentInChildren <HexMesh>(); _hexCells = CreateCellGrid(width, height); CreateCellLabels(); }
public void AddBridgeOutside(HexDirection dir, HexMesh from, HexMesh to, Vector3 fromT, Vector3 toT) { if (translationVector == null) { return; } int vStart = lVertices.Count; Vector3[] vertices = new Vector3[4]; vertices[0] = from.GetCorner(dir) + fromT; vertices[1] = from.GetCorner(dir.Next()) + fromT; vertices[2] = to.GetCorner(dir.Opposite()) + toT; vertices[3] = to.GetCorner(dir.Next().Opposite()) + toT; if (!ExistsInList(vertices, lVertices)) { lVertices.AddRange(vertices); } int[] triangles = { vStart + 1, vStart, vStart + 2, vStart + 2, vStart, vStart + 3 }; if (!ExistsInList(triangles, lTriangles)) { lTriangles.AddRange(triangles); } }
void Awake() { gridCanvas = GetComponentInChildren <Canvas>(); hexMesh = GetComponentInChildren <HexMesh>(); cells = new HexCell[HexMetrics.chunkSizeX * HexMetrics.chunkSizeZ]; }
void Awake() { gridCanvas = GetComponentInChildren <Canvas>(); hexMesh = GetComponentInChildren <HexMesh>(); cells = new HexCell[HexMetrics.chunkSizeX * HexMetrics.chunkSizeZ]; // standart 5 x 5 ShowUI(false); }
private void Awake() { _gridCanvas = GetComponentInChildren <Canvas>(); _hexMesh = GetComponentInChildren <HexMesh>(); _cells = new HexCell[HexMetrics.CHUNK_SIZE_X * HexMetrics.CHUNK_SIZE_Z]; ShowUI(false); }
public void AddNeighbor(HexDirection dir, HexMesh n) { if (n != null) { this.neighbors[(int)dir] = n; n.neighbors[(int)dir.Opposite()] = this; } }
private void Awake() { _gridCanvas = GetComponentInChildren <Canvas>(); _terrain = GetComponentInChildren <HexMesh>(); _meshCollider = gameObject.AddComponent <MeshCollider>(); _cells = new HexCell[HexMetrics.ChunkSizeX * HexMetrics.ChunkSizeZ]; }
//grid must be created first void Awake() { gridCanvas = GetComponentInChildren <Canvas>(); hexMesh = GetComponentInChildren <HexMesh>(); cells = new Cell[width * height]; CreateGrid(); }
void Awake() { gridCanvas = GetComponentInChildren <Canvas>(); terrain = GetComponentInChildren <HexMesh>(); cells = new HexCell[HexMetrics.chunkSizeX * HexMetrics.chunkSizeZ]; ShowUI(false); }
void Awake() { instance = this; gridCanvas = GetComponentInChildren <Canvas>(); hexMesh = GetComponentInChildren <HexMesh>(); gridCanvas = GetComponentInChildren <Canvas>(); cells = new HexCell[height * width]; }
public MeshModifier(HexMesh mesh, MeshModPoint[] modPoints) { this.mesh = mesh; this.modPoints = modPoints; vertices = new NativeArray <Vector3>(mesh.Vertices, Allocator.Persistent); velocities = new NativeArray <float>(vertices.Length, Allocator.Persistent); modVertices = new Vector3[vertices.Length]; modVelocities = new float[vertices.Length]; }
void GenerateMesh() { if (hexMesh != null) { hexMesh.Clear(); Debug.Log("Clearing the mesh!"); } hexMesh = new HexMesh(cellsArray, GetComponent <MeshFilter>(), GetComponent <MeshRenderer>(), GetComponent <MeshCollider>()); }
protected static void TriangulateQuad(HexMesh mesh, EdgeVertices e1, EdgeVertices e2, Color c1, Color c2) { mesh.AddQuad(e1.v1, e1.v2, e2.v1, e2.v2); mesh.AddQuadColor(c1, c1, c2, c2); mesh.AddQuad(e1.v2, e1.v3, e2.v2, e2.v3); mesh.AddQuadColor(c1, c1, c2, c2); mesh.AddQuad(e1.v3, e1.v4, e2.v3, e2.v4); mesh.AddQuadColor(c1, c1, c2, c2); mesh.AddQuad(e1.v4, e1.v5, e2.v4, e2.v5); mesh.AddQuadColor(c1, c1, c2, c2); }
// This function is used to create a HexGrid from the predefined gridColouringStr public void createHexGridFromString(int gridId) { if (gridColouringStr.Length != height * width) { Debug.LogError("gridColouringStr not set correctly for this HexGrid!"); return; } gridCanvas = GetComponentInChildren <Canvas>(); hexMesh = GetComponentInChildren <HexMesh>(); cells = new HexCell[height * width]; this.id = gridId; for (int z = 0, i = 0; z < height; z++) { for (int x = 0; x < width; x++) { Color c = colors[0]; if (gridColouringStr[i] == 'W') { c = colors[0]; } else if (gridColouringStr[i] == 'B') { c = colors[1]; } else if (gridColouringStr[i] == 'G') { c = colors[2]; } else if (gridColouringStr[i] == 'Y') { c = colors[3]; } else if (gridColouringStr[i] == 'K') { c = colors[4]; } CreateCell(x, z, i++, c); } } hexMesh.Triangulate(cells); hexMesh.disableMesh(); gridCanvas.gameObject.SetActive(false); BoxCollider collider = GetComponent <BoxCollider>(); collider.center = new Vector3(47.6f, 0f, 37.8f); collider.size = new Vector3(112.7f, 0f, 95.6f); }
/* * Pre-Start, initialize the array of cells, drawing each to this component's child mesh. */ private void Awake() { this.hexMesh = GetComponentInChildren <HexMesh>(); this.hexCells = new HexCell[this.height * this.width]; for (int z = 0, i = 0; z < this.height; z++) { for (int x = 0; x < this.width; x++) { InitHexCell(x, z, i++); } } }
private void Awake() { _gridCanvas = GetComponentInChildren<Canvas>(); _hexMesh = GetComponentInChildren<HexMesh>(); _cells = new HexCell[width * height]; for(int z = 0, i = 0; z < height; z++) { for(int x = 0; x < width; x++) { CreateCell(x, z, i++); } } }
void Awake() { mesh = GetComponentInChildren <HexMesh>(); cells = new HexCell[height * width]; for (int z = 0, i = 0; z < height; z++) { for (int x = 0; x < height; x++) { CreateHex(z, x, i++); } } }