From f0315bea6acee2316665d6ca5c945da84f22c1ee Mon Sep 17 00:00:00 2001 From: miepzerino <o.skotnik@gmail.com> Date: Wed, 02 Apr 2025 08:40:46 +0000 Subject: [PATCH] #35 added generateable script to ore --- Assets/Scripts/Prefab/Drilling/Generateable.cs | 29 +++++++++ Assets/Scripts/Prefab/Drilling/Generateable.cs.meta | 11 +++ Assets/TileSets/Palettes/ForestRuleTileCustom.asset | 17 ++--- Assets/Scenes/GameplayScene.unity | 9 -- Assets/Scripts/GenerateTileMap.cs | 60 ++++++++++---------- Assets/TileSets/Palettes/DrillIronOre.prefab | 20 ++++++ 6 files changed, 98 insertions(+), 48 deletions(-) diff --git a/Assets/Scenes/GameplayScene.unity b/Assets/Scenes/GameplayScene.unity index 58e123e..e90f5a2 100644 --- a/Assets/Scenes/GameplayScene.unity +++ b/Assets/Scenes/GameplayScene.unity @@ -4871,13 +4871,8 @@ m_EditorClassIdentifier: forestRuleTile: {fileID: 11400000, guid: 3999614e192b37546a6b710bf5ceb30c, type: 2} borderTile: {fileID: 11400000, guid: dcef846474e534b45ab3b175559c19a2, type: 2} - ores: - - name: Iron - weight: 7 - clusterWeight: 40 - tile: {fileID: 11400000, guid: bbc5a3964d8331546a4dbc880f8ae9fc, type: 2} - maxSpawnHeight: 250 - minSpawnHeight: 150 + generateables: + - {fileID: 5943816882416256805, guid: 858e9987645c29748a5b0990923da82f, type: 3} --- !u!1 &1955008394 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/GenerateTileMap.cs b/Assets/Scripts/GenerateTileMap.cs index 156ebab..46b27b8 100644 --- a/Assets/Scripts/GenerateTileMap.cs +++ b/Assets/Scripts/GenerateTileMap.cs @@ -6,28 +6,28 @@ using UnityEngine.Tilemaps; using UnityEngine.UIElements; -[Serializable] -public class Ore -{ - public string name; - /// <summary> - /// The lower the numer the higher the amount of ores that will spawn - /// Higher number means less ore - /// </summary> - [Tooltip("The lower the numer the higher the amount of ores that will spawn. Higher number means less ore.")] - [Range(1, 100000)] - public int weight; - /// <summary> - /// The lower the number the more dense the ore will spawn (big clusters - /// Higher number means little clusters (more spread) - /// </summary> - [Tooltip("The lower the number the more dense the ore will spawn (big clusters. Higher number means little clusters (more spread).")] - [Range(10, 100000)] - public int clusterWeight; - public CustomRuleTile tile; - public int maxSpawnHeight; - public int minSpawnHeight; -} +//[Serializable] +//public class Ore +//{ +// public string name; +// /// <summary> +// /// The lower the numer the higher the amount of ores that will spawn +// /// Higher number means less ore +// /// </summary> +// [Tooltip("The lower the numer the higher the amount of ores that will spawn. Higher number means less ore.")] +// [Range(1, 100000)] +// public int weight; +// /// <summary> +// /// The lower the number the more dense the ore will spawn (big clusters +// /// Higher number means little clusters (more spread) +// /// </summary> +// [Tooltip("The lower the number the more dense the ore will spawn (big clusters. Higher number means little clusters (more spread).")] +// [Range(10, 100000)] +// public int clusterWeight; +// public CustomRuleTile tile; +// public int maxSpawnHeight; +// public int minSpawnHeight; +//} public class GenerateTileMap : MonoBehaviour { @@ -41,7 +41,7 @@ Tilemap tilemap; public CustomRuleTile forestRuleTile; public TileBase borderTile; - public List<Ore> ores; + public List<Generateable> generateables; //public List<TileBase> tiles; private void Awake() @@ -114,24 +114,24 @@ } } - if (ores != null) + if (generateables != null) { - foreach (Ore ore in ores) + foreach (Generateable generateable in generateables) { for (int x = 0; x < maxWidth; x++) { - for (int y = ore.minSpawnHeight; y < ore.maxSpawnHeight; y++) + for (int y = generateable.minSpawnHeight; y < generateable.maxSpawnHeight; y++) { - float xPerlin = ((float)x / maxWidth) * (float)ore.clusterWeight + offsetX; - float yPerlin = ((float)y / maxHeight) * (float)ore.clusterWeight + offsetY; + float xPerlin = ((float)x / maxWidth) * (float)generateable.clusterWeight + offsetX; + float yPerlin = ((float)y / maxHeight) * (float)generateable.clusterWeight + offsetY; float perlinNoise = Mathf.PerlinNoise(xPerlin, yPerlin); - if (perlinNoise <= (1f / (float)ore.weight)) + if (perlinNoise <= (1f / (float)generateable.weight)) { Vector3Int tileSpawnCoord = new Vector3Int(x, y); if (!destroyedTiles.Contains(tileSpawnCoord) && tilemap.HasTile(tileSpawnCoord)) { - tilemap.SetTile(tileSpawnCoord, ore.tile); + tilemap.SetTile(tileSpawnCoord, generateable.tile); } } diff --git a/Assets/Scripts/Prefab/Drilling/Generateable.cs b/Assets/Scripts/Prefab/Drilling/Generateable.cs new file mode 100644 index 0000000..64190ea --- /dev/null +++ b/Assets/Scripts/Prefab/Drilling/Generateable.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +[Serializable] +public class Generateable : MonoBehaviour +{ + public bool isGenerateable = true; + //public string nameKey; + /// <summary> + /// The lower the numer the higher the amount of ores that will spawn + /// Higher number means less ore + /// </summary> + [Tooltip("The lower the numer the higher the amount of ores that will spawn. Higher number means less ore.")] + [Range(1, 100000)] + public int weight; + /// <summary> + /// The lower the number the more dense the ore will spawn (big clusters + /// Higher number means little clusters (more spread) + /// </summary> + [Tooltip("The lower the number the more dense the ore will spawn (big clusters. Higher number means little clusters (more spread).")] + [Range(10, 100000)] + public int clusterWeight; + public int minClusterSize; + public CustomRuleTile tile; + public int maxSpawnHeight; + public int minSpawnHeight; +} diff --git a/Assets/Scripts/Prefab/Drilling/Generateable.cs.meta b/Assets/Scripts/Prefab/Drilling/Generateable.cs.meta new file mode 100644 index 0000000..f21d750 --- /dev/null +++ b/Assets/Scripts/Prefab/Drilling/Generateable.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6b939c0393f507f4fb9e91dfb683f869 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/TileSets/Palettes/DrillIronOre.prefab b/Assets/TileSets/Palettes/DrillIronOre.prefab index 2c04462..ef4d998 100644 --- a/Assets/TileSets/Palettes/DrillIronOre.prefab +++ b/Assets/TileSets/Palettes/DrillIronOre.prefab @@ -11,6 +11,7 @@ - component: {fileID: 8973229189939374991} - component: {fileID: -776302461885629690} - component: {fileID: 3926666667628910059} + - component: {fileID: 5943816882416256805} m_Layer: 6 m_Name: DrillIronOre m_TagString: Untagged @@ -61,3 +62,22 @@ isDropable: 1 dropable: {fileID: 7215668260114684477, guid: ead8eea59ce41c244814a994365e1129, type: 3} dropAmount: 2 +--- !u!114 &5943816882416256805 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 3549545049718014148} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 6b939c0393f507f4fb9e91dfb683f869, type: 3} + m_Name: + m_EditorClassIdentifier: + isGenerateable: 1 + weight: 7 + clusterWeight: 40 + minClusterSize: 4 + tile: {fileID: 11400000, guid: bbc5a3964d8331546a4dbc880f8ae9fc, type: 2} + maxSpawnHeight: 250 + minSpawnHeight: 150 diff --git a/Assets/TileSets/Palettes/ForestRuleTileCustom.asset b/Assets/TileSets/Palettes/ForestRuleTileCustom.asset index fb7e48d..b336577 100644 --- a/Assets/TileSets/Palettes/ForestRuleTileCustom.asset +++ b/Assets/TileSets/Palettes/ForestRuleTileCustom.asset @@ -12,7 +12,7 @@ m_Script: {fileID: 11500000, guid: 4f32125565481304cbcd5f6e6cefa637, type: 3} m_Name: ForestRuleTileCustom m_EditorClassIdentifier: - m_DefaultSprite: {fileID: 0} + m_DefaultSprite: {fileID: 1962712664, guid: 42962cf14c23fee4baaaea0cd52d52e0, type: 3} m_DefaultGameObject: {fileID: 3549545049718014148, guid: c82bc431abdeded4ab41cfdd19459501, type: 3} m_DefaultColliderType: 1 m_TilingRules: @@ -108,14 +108,12 @@ m_Output: 0 m_ColliderType: 1 m_RandomTransform: 0 - m_Neighbors: 010000000200000001000000010000000100000001000000 + m_Neighbors: 01000000020000000100000001000000 m_NeighborPositions: - {x: 0, y: 1, z: 0} - {x: 0, y: -1, z: 0} - {x: -1, y: 0, z: 0} - {x: 1, y: 0, z: 0} - - {x: -1, y: 1, z: 0} - - {x: 1, y: 1, z: 0} m_RuleTransform: 0 - m_Id: 6 m_Sprites: @@ -242,13 +240,12 @@ m_Output: 0 m_ColliderType: 1 m_RandomTransform: 0 - m_Neighbors: 0100000001000000010000000100000001000000010000000200000001000000 + m_Neighbors: 01000000010000000100000001000000010000000200000001000000 m_NeighborPositions: - {x: 0, y: 1, z: 0} - {x: 1, y: 0, z: 0} - {x: -1, y: 0, z: 0} - {x: 0, y: -1, z: 0} - - {x: -1, y: -1, z: 0} - {x: 1, y: -1, z: 0} - {x: -1, y: 1, z: 0} - {x: 1, y: 1, z: 0} @@ -263,16 +260,15 @@ m_Output: 0 m_ColliderType: 1 m_RandomTransform: 0 - m_Neighbors: 0100000001000000010000000100000001000000010000000200000001000000 + m_Neighbors: 01000000010000000100000001000000020000000100000001000000 m_NeighborPositions: - {x: 0, y: 1, z: 0} - {x: 1, y: 0, z: 0} - {x: -1, y: 0, z: 0} - {x: 0, y: -1, z: 0} - - {x: -1, y: -1, z: 0} - - {x: 1, y: -1, z: 0} - {x: 1, y: 1, z: 0} - {x: -1, y: 1, z: 0} + - {x: 1, y: -1, z: 0} m_RuleTransform: 0 - m_Id: 14 m_Sprites: @@ -284,14 +280,13 @@ m_Output: 0 m_ColliderType: 1 m_RandomTransform: 0 - m_Neighbors: 0100000001000000010000000200000001000000020000000100000001000000 + m_Neighbors: 01000000010000000100000002000000010000000100000001000000 m_NeighborPositions: - {x: 0, y: 1, z: 0} - {x: 1, y: 0, z: 0} - {x: -1, y: 0, z: 0} - {x: -1, y: 1, z: 0} - {x: 1, y: 1, z: 0} - - {x: 1, y: -1, z: 0} - {x: 0, y: -1, z: 0} - {x: -1, y: -1, z: 0} m_RuleTransform: 0 -- Gitblit v1.9.3