/// <summary> /// Adds either an ocean or island tile at a specified location /// </summary> /// <param name="node">The node</param> /// <param name="islandSize">The islandSize</param> /// <param name="tileSize">The tileSize</param> /// <param name="parent">The parent</param> /// <returns>The created tile</returns> private Tile AddIslandTile(BaseNode node, IslandTile.IslandSize islandSize, int tileSize, Transform parent) { Vector3 position = new Vector3(node.transform.position.x, node.transform.position.y, node.transform.position.z); GameObject obj = Instantiate(Resources.Load("Tiles/IslandTile"), position, Quaternion.identity) as GameObject; IslandTile islandTile = obj.GetComponent <IslandTile>(); islandTile.Size = islandSize; islandTile.GenerateIsland(); SetUpIsland(node, obj, tileSize, parent); obj.transform.SetParent(parent); return(obj.GetComponent <Tile>()); }
/// <summary> /// Returns true if there are no conflicts with generating the specifed size of island /// </summary> /// <param name="node">The node</param> /// <param name="size">The specified size</param> /// <returns>Whether or not the specified size can be generated at node's location</returns> private bool CanGenerate(BaseNode node, IslandTile.IslandSize size) { switch (size) { case IslandTile.IslandSize.Regular: return(true); case IslandTile.IslandSize.Long: if (node.RightEmpty != null) { if (node.RightEmpty.isAvailable) { return(true); } } return(false); case IslandTile.IslandSize.Tall: if (node.TopEmpty != null) { if (node.TopEmpty.isAvailable) { return(true); } } return(false); case IslandTile.IslandSize.Large: if (node.RightEmpty != null && node.TopEmpty != null && node.TopEmpty.RightEmpty != null) { if (node.RightEmpty.isAvailable && node.TopEmpty.isAvailable && node.TopEmpty.RightEmpty.isAvailable) { return(true); } } return(false); } Debug.Log("Something went wrong with island generation"); return(true); }
/// <summary> /// Generates the ocean /// </summary> /// <param name="nodes">The nodes</param> /// <param name="addIslands">True if want to include islands</param> /// <param name="removeNodes">True if nodes should be removed</param> /// <param name="tileSize">The tileSize</param> /// <param name="parent">The parent</param> public void GenerateOceanTiles(List <BaseNode> nodes, bool addIslands, bool removeNodes, int tileSize, Transform parent) { Tile createdTile = null; foreach (BaseNode node in nodes) { if (node.isAvailable) { float num = Random.Range(0f, 1f); if (addIslands && num <= islandSpawnChance) { IslandTile.IslandSize size = IslandTile.DetermineIslandSize(); if (CanGenerate(node, size)) { createdTile = AddIslandTile(node, size, tileSize, parent); //AddAnyTile(nameof(OceanTile), node, tileSize/10, parent, forIsland: true); } else { createdTile = AddAnyTile(nameof(OceanTile), node, tileSize / 10, parent, WorldController.Instance.oceanTileOffset); } } else { createdTile = AddAnyTile(nameof(OceanTile), node, tileSize / 10, parent, WorldController.Instance.oceanTileOffset); } } if (removeNodes) { Destroy(node.gameObject); } else { createdTile.transform.SetParent(node.transform); } } }