private List <HeightmapHandle> UpdateHoveredHandlesSimpleSelection(RaycastHit raycast) { GridMesh gridMesh = GameManager.Instance.Map.SurfaceGridMesh; List <HeightmapHandle> hoveredHandles = new List <HeightmapHandle>(); TileSelectionHit hit = TileSelection.PositionToTileSelectionHit(raycast.point, TileSelectionMode.Everything); switch (hit.Target) { case TileSelectionTarget.InnerTile: hoveredHandles.Add(gridMesh.GetHandle(hit.X, hit.Y)); hoveredHandles.Add(gridMesh.GetHandle(hit.X + 1, hit.Y)); hoveredHandles.Add(gridMesh.GetHandle(hit.X, hit.Y + 1)); hoveredHandles.Add(gridMesh.GetHandle(hit.X + 1, hit.Y + 1)); break; case TileSelectionTarget.Corner: hoveredHandles.Add(gridMesh.GetHandle(hit.X, hit.Y)); break; case TileSelectionTarget.BottomBorder: hoveredHandles.Add(gridMesh.GetHandle(hit.X, hit.Y)); hoveredHandles.Add(gridMesh.GetHandle(hit.X + 1, hit.Y)); break; case TileSelectionTarget.LeftBorder: hoveredHandles.Add(gridMesh.GetHandle(hit.X, hit.Y)); hoveredHandles.Add(gridMesh.GetHandle(hit.X, hit.Y + 1)); break; } return(hoveredHandles); }
// private List<House3D> houses = new List<House3D>(); private void Awake() { gridCanvas = GetComponentInChildren <Canvas>(); gridMesh = GetComponentInChildren <GridMesh>(); // CreateCells(); }
public Pathfinding(int width, int height, float cellSize, Vector3 origin) { Instance = this; _grid = new GridMesh <PathNode>(width, height, cellSize, origin, //Width, height, cell size and start point (GridMesh <PathNode> grid, int x, int y) => new PathNode(grid, x, y)); //Constructor func for TObject in gridMesh }
private void Update() { Random.seed = 15; int w = 10; int h = 10; float[,] heights = new float[w, h]; for (int x = 0; x < w; x++) { for (int y = 0; y < h; y++) { heights[x, y] = 0; } } heights = RandomDifference(heights, weight, 2, 1); heights = RandomDifference(heights, weighta, 2, 0); heights = RandomDifference(heights, weightb, 2, 1); Mesh mesh = GetComponent <MeshFilter>().mesh; mesh.Clear(); GridMesh meshgrid = new GridMesh(heights); mesh.vertices = meshgrid.Points; mesh.triangles = meshgrid.Triangles; mesh.RecalculateNormals(); }
void Awake() { xsize = Metrics.chunkSizeX; zsize = Metrics.chunkSizeZ; heights = new int[xsize, zsize]; mesh = GetComponentInChildren <GridMesh>(); enabled = false; }
// Start is called before the first frame update void Start() { _gridMesh = new GridMesh <PathNode>(_width, _height, _cellSize, _origin, //Width, height, cell size and start point (GridMesh <PathNode> grid, int x, int y) => new PathNode(grid, x, y), _showMesh); Pathfinding pathfinding = new Pathfinding(_gridMesh); }
/// <summary> /// Instantiates an instance of the controller. /// </summary> /// <param name="terrain">The terrain to edit.</param> public SelectingTerrainController(GridMesh terrain) { _terrain = terrain; _cursor = GridCursor.Create(terrain, ResourceLoader.Load <Material>(ResourceType.Materials, ResourceCategory.Terrain, "cursor_terrain")); _cursor.Deactivate(); OnTerrainSelectionUpdate += SelectionUpdate; OnTerrainClicked += Clicked; }
/// <summary> /// Instantiates an instance of the controller. /// </summary> /// <param name="terrain">The terrain to place construction on.</param> public SelectingPathController(GridMesh terrain) { _terrain = terrain; _validMaterial = ResourceLoader.Load <Material>(ResourceType.Materials, ResourceCategory.Terrain, "cursor_valid"); _invalidMaterial = ResourceLoader.Load <Material>(ResourceType.Materials, ResourceCategory.Terrain, "cursor_invalid"); _cursor = GridCursor.Create(terrain, _validMaterial); OnTerrainSelectionUpdate += PlacementUpdate; OnTerrainClicked += Clicked; }
void MakeCornerBridge(GridMesh mesh, Vector3 v0, GridDirection bridgeDirection) { Vector3 b0 = GridMetrics.GetBridge(bridgeDirection.Previous()); Vector3 b1 = GridMetrics.GetBridge(bridgeDirection.Next()); mesh.AddQuad(v0, v0 + b0, v0 + b0 + b1, v0 + b1); if (mesh.useUVCoordinates) { mesh.AddQuadUV(0f, 0f, 0f, 1f); } }
public override void OnInspectorGUI() { DrawDefaultInspector(); GridMesh myScript = (GridMesh)target; if (GUILayout.Button("Generate Grid")) { myScript.CreateGridMesh(); } }
/// <summary> /// Instantiates an instance of the controller. /// </summary> /// <param name="terrain">The terrain to place construction on.</param> public PlacingPathController(GridMesh terrain) { _terrain = terrain; _cursors = new LineCursor( terrain, ResourceLoader.Load <Material>(ResourceType.Materials, ResourceCategory.Terrain, "cursor_valid"), ResourceLoader.Load <Material>(ResourceType.Materials, ResourceCategory.Terrain, "cursor_invalid")); OnTerrainSelectionUpdate += PlacementUpdate; OnTerrainClicked += Clicked; }
/// <summary> /// Instantiates an instance of the controller. /// </summary> /// <param name="terrain">The terrain to place construction on.</param> public PlacingConstructionController(GridMesh terrain) { _terrain = terrain; _building = null; _cursors = new FootprintCursor( terrain, ResourceLoader.Load <Material>(ResourceType.Materials, ResourceCategory.Terrain, "cursor_valid"), ResourceLoader.Load <Material>(ResourceType.Materials, ResourceCategory.Terrain, "cursor_invalid")); OnTerrainSelectionUpdate += PlacementUpdate; OnTerrainClicked += Build; }
void MakeBridge(GridMesh mesh, Vector3 v0, Vector3 v1, GridDirection bridgeDirection) { Vector3 bridge = GridMetrics.GetBridge(bridgeDirection); Vector3 e0 = v0 + bridge; Vector3 e1 = v1 + bridge; mesh.AddQuad(v0, e0, e1, v1); if (mesh.useUVCoordinates) { mesh.AddQuadUV(0f, 0f, 0f, 1f); } }
public void Initialize(int gridWidth, int gridHeight) { this.gridMesh = gameObject.GetComponent <GridMesh>(); this.gridWidth = (int)(gridWidth / tileWidth); this.gridHeight = (int)(gridHeight / tileHeight); this.gridSize = this.gridWidth * this.gridHeight; this.grid = new TileEnum[this.gridSize]; this.durationGrid = new float[this.gridSize]; for (int ii = 0; ii < this.gridSize; ii++) { this.grid[ii] = TileEnum.empty; this.durationGrid[ii] = 0; } }
// Use this for initialization void Start() { //Create an empty parent GameObject to control the scale of the entire layout. mapScaler = GameObject.Find("MapScaler"); if (mapScaler == null) { mapScaler = new GameObject("MapScaler"); } //Create an empty parent for the grid. gridLayout = GameObject.Find("GridLayout"); if (gridLayout == null) { gridLayout = new GameObject("GridLayout"); gridLayout.transform.SetParent(mapScaler.transform); } //Create an empty parent for the Player Character pieces. playerLayout = GameObject.Find("PlayerLayout"); if (playerLayout == null) { playerLayout = new GameObject("PlayerLayout"); playerLayout.transform.SetParent(mapScaler.transform); } //Create an empty parent for the NPC pieces. npcLayout = GameObject.Find("NPCLayout"); if (npcLayout == null) { npcLayout = new GameObject("NPCLayout"); npcLayout.transform.SetParent(mapScaler.transform); } //Create an empty parent for the Tile pieces. tileLayout = GameObject.Find("TileLayout"); if (tileLayout == null) { tileLayout = new GameObject("TileLayout"); tileLayout.transform.SetParent(mapScaler.transform); } MapItem grid = JsonUtility.FromJson <MapItem> (JSONSTRING); Vector3 gridVector = new Vector3(-0.5f, 0, -0.5f); GridMesh gridMaker = Instantiate(gridPrefab, gridVector, Quaternion.identity).GetComponent <GridMesh>(); gridMaker.transform.SetParent(gridLayout.transform); gridMaker.setSize(grid.width); buildMap(grid); }
/// <summary> /// Instantiates a line cursor. /// </summary> /// <param name="terrain">The terrain to put cursors on.</param> /// <param name="validMaterial">The material to use when a footprint location is valid.</param> /// <param name="invalidMaterial">The material to use when a footprint location is invalid.</param> public LineCursor(GridMesh terrain, Material validMaterial, Material invalidMaterial) { _terrain = terrain; _validMaterial = validMaterial; _invalidMaterial = invalidMaterial; // just initialize the max possible and keep them inactive // https://answers.unity.com/questions/462942/does-inactive-objects-eat-up-performance.html _cursors = new GridCursor[Math.Max(terrain.CountX, terrain.CountZ)]; for (int i = 0; i < _cursors.Length; ++i) { _cursors[i] = GridCursor.Create(_terrain, _validMaterial); _cursors[i].Deactivate(); } }
private void Awake() { // Get GridMesh component _gridMesh = GetComponent <GridMesh>(); // How many cell you will get on the X axis _gridMesh.xSegments = 8; // How many cell you will get on the Y axis _gridMesh.ySegments = 16; // Cell width _gridMesh.xStep = 1f; // Cell height _gridMesh.yStep = 0.5f; // Sets a material. By default it's magenta _gridMesh.material = gridMat; // Centers the grid to the game object _gridMesh.isCentered = true; }
void CreateMeshes() { // Create a new mesh for the mesh filter and a grid mesh to reference it MeshFilter meshFilter = GetComponent<MeshFilter>(); meshFilter.sharedMesh = new Mesh(); renderMesh = new GridMesh(renderMeshSize, renderMeshSize, meshFilter.sharedMesh); //renderMesh.recreateMesh = true; renderMesh.update = new GridMesh.UpdateFunction(GridCallback); //renderMesh.updateNormal = new GridMesh.UpdateFunction(GridNormalCallback); renderMesh.Setup(); // Create a new mesh for the mesh collider and a grid mesh to reference it MeshCollider meshCollider = GetComponent<MeshCollider>(); meshCollider.sharedMesh = new Mesh(); collisionMesh = new GridMesh(collisionMeshSize, collisionMeshSize, meshCollider.sharedMesh); //collisionMesh.recreateMesh = true; collisionMesh.update = new GridMesh.UpdateFunction(GridCallback); collisionMesh.Setup(); print ("Initialized: "); PrintVerts(); }
/// <summary> /// Instantiates the campus terrain game object. /// </summary> /// <param name="parent">Parent of the terrain.</param> /// <param name="args">GridMesh arguments to generate a terrain.</param> /// <param name="mesh">Returns the grid mesh that manages the terrain.</param> /// <returns>The terrain game object.</returns> public static GameObject GenerateTerrain(Transform parent, GridMeshArgs args, out GridMesh mesh) { var terrainObject = new GameObject("Campus Terrain"); terrainObject.transform.SetParent(parent, false); var filter = terrainObject.AddComponent <MeshFilter>(); var collider = terrainObject.AddComponent <MeshCollider>(); var renderer = terrainObject.AddComponent <MeshRenderer>(); var selectable = terrainObject.AddComponent <SelectableTerrain>(); filter.mesh = new Mesh(); filter.mesh.name = "grid-mesh"; renderer.receiveShadows = true; mesh = new GridMesh(filter.mesh, collider, renderer, args); selectable.Terrain = mesh; mesh.Selectable = selectable; return(terrainObject); }
/// <summary> /// Instantiates an instance of the controller. /// </summary> /// <param name="terrain">The terrain to edit.</param> public EditingTerrainController(GridMesh terrain) { _terrain = terrain; _cursor = GridCursor.Create(terrain, ResourceLoader.Load <Material>(ResourceType.Materials, ResourceCategory.Terrain, "cursor_terrain2")); _cursor.Deactivate(); }
public Pathfinding(GridMesh <PathNode> gridMesh) { Instance = this; _grid = gridMesh; }
Vector3 GridCallback(int x, int y, GridMesh mesh) { float wx = (x - mesh.halfWidth) * meshScale; float wy = (y - mesh.halfDepth) * meshScale; return new Vector3(wx, HillFunction(wx + transform.position.x, wy + transform.position.z), wy); }
Vector3 GridNormalCallback(int x, int z, GridMesh mesh) { float wx = (x - mesh.halfWidth) * meshScale; float wz = (z - mesh.halfDepth) * meshScale; return HillNormal(wx + transform.position.x, wz + transform.position.z); }
public CampusBuildings(GridMesh terrain) { _terrain = terrain; }
// TODO: this script should be caching as much data as possible - we can add and remove a single row // from the mesh at a time. We can probably do something with the meshes to make them triangle // strips from the get-go, rather than relying on Unity to do it. One option is to use multiple game objects // with this script attached. void UpdateTerrainMesh(GridMesh gridMesh) { // Calculate the number of terrain units the grid has shifted along the x-z plane IPoint dp = new IPoint((int)(transform.position.x - oldPosition.x), (int)(transform.position.z - oldPosition.z)); gridMesh.Shift(dp); }
public CampusPaths(GridMesh terrain) { _terrain = terrain; _path = new bool[_terrain.CountX, _terrain.CountZ]; SetupPathMapping(); }
/// <summary> /// Instantiates a footprint cursor. /// </summary> /// <param name="terrain">The terrain to put cursors on.</param> /// <param name="validMaterial">The material to use when a footprint location is valid.</param> /// <param name="invalidMaterial">The material to use when a footprint location is invalid.</param> public FootprintCursor(GridMesh terrain, Material validMaterial, Material invalidMaterial) { _terrain = terrain; _validMaterial = validMaterial; _invalidMaterial = invalidMaterial; }