5 files modified
2 files renamed
4 files added
New file |
| | |
| | | fileFormatVersion: 2 |
| | | guid: 4ac220fd0e1536641a480531bbb38c65 |
| | | folderAsset: yes |
| | | DefaultImporter: |
| | | externalObjects: {} |
| | | userData: |
| | | assetBundleName: |
| | | assetBundleVariant: |
New file |
| | |
| | | fileFormatVersion: 2 |
| | | guid: dd3098fe15f11cf41b0623e380a01529 |
| | | folderAsset: yes |
| | | DefaultImporter: |
| | | externalObjects: {} |
| | | userData: |
| | | assetBundleName: |
| | | assetBundleVariant: |
| | |
| | | m_GameObject: {fileID: 519420028} |
| | | serializedVersion: 2 |
| | | m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} |
| | | m_LocalPosition: {x: -6.15, y: -24.87, z: -10} |
| | | m_LocalPosition: {x: 62, y: -22.89, z: -10} |
| | | m_LocalScale: {x: 1, y: 1, z: 1} |
| | | m_ConstrainProportionsScale: 0 |
| | | m_Children: [] |
| | |
| | | m_Script: {fileID: 11500000, guid: e4d1fabb0e4577b4d987741f664e3d68, type: 3} |
| | | m_Name: |
| | | m_EditorClassIdentifier: |
| | | items: |
| | | - {fileID: 7215668260114684477, guid: ead8eea59ce41c244814a994365e1129, type: 3} |
| | | --- !u!1 &1190838619 |
| | | GameObject: |
| | | m_ObjectHideFlags: 0 |
| | |
| | | m_GameObject: {fileID: 1624236510} |
| | | serializedVersion: 2 |
| | | m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} |
| | | m_LocalPosition: {x: -6.15, y: -24.87, z: -10} |
| | | m_LocalPosition: {x: 62, y: -22.89, z: -10} |
| | | m_LocalScale: {x: 1, y: 1, z: 1} |
| | | m_ConstrainProportionsScale: 0 |
| | | m_Children: |
| | |
| | | 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 |
| | |
| | | objectReference: {fileID: 0} |
| | | - target: {fileID: 2368348636056148999, guid: c220ec455fce341408d66d880b464cad, type: 3} |
| | | propertyPath: m_LocalPosition.x |
| | | value: -6.15 |
| | | value: 62 |
| | | objectReference: {fileID: 0} |
| | | - target: {fileID: 2368348636056148999, guid: c220ec455fce341408d66d880b464cad, type: 3} |
| | | propertyPath: m_LocalPosition.y |
| | | value: -24.87 |
| | | value: -22.89 |
| | | objectReference: {fileID: 0} |
| | | - target: {fileID: 2368348636056148999, guid: c220ec455fce341408d66d880b464cad, type: 3} |
| | | propertyPath: m_LocalPosition.z |
| | |
| | | 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 |
| | | { |
| | |
| | | Tilemap tilemap; |
| | | public CustomRuleTile forestRuleTile; |
| | | public TileBase borderTile; |
| | | public List<Ore> ores; |
| | | public List<Generateable> generateables; |
| | | //public List<TileBase> tiles; |
| | | |
| | | private void Awake() |
| | |
| | | } |
| | | } |
| | | |
| | | 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); |
| | | // Check potential cluster size before placing |
| | | int clusterSize = CountPotentialClusterSize(x, y, generateable.weight, generateable.clusterWeight); |
| | | if (clusterSize >= generateable.minClusterSize) |
| | | { |
| | | tilemap.SetTile(tileSpawnCoord, generateable.tile); |
| | | } |
| | | //tilemap.SetTile(tileSpawnCoord, generateable.tile); |
| | | } |
| | | } |
| | | |
| | |
| | | yield return null; |
| | | finishedCallback(); |
| | | } |
| | | private int CountPotentialClusterSize(int startX, int startY, int weight, int clusterWeight) |
| | | { |
| | | int size = 0; |
| | | Queue<Vector2Int> toCheck = new Queue<Vector2Int>(); |
| | | HashSet<Vector2Int> checked_positions = new HashSet<Vector2Int>(); |
| | | |
| | | toCheck.Enqueue(new Vector2Int(startX, startY)); |
| | | checked_positions.Add(new Vector2Int(startX, startY)); |
| | | |
| | | while (toCheck.Count > 0) |
| | | { |
| | | Vector2Int current = toCheck.Dequeue(); |
| | | size++; |
| | | |
| | | // Check all 8 neighboring tiles |
| | | for (int dx = -1; dx <= 1; dx++) |
| | | { |
| | | for (int dy = -1; dy <= 1; dy++) |
| | | { |
| | | if (dx == 0 && dy == 0) continue; |
| | | |
| | | Vector2Int neighbor = new Vector2Int(current.x + dx, current.y + dy); |
| | | if (checked_positions.Contains(neighbor)) continue; |
| | | |
| | | float xPerlin = ((float)neighbor.x / maxWidth) * clusterWeight + offsetX; |
| | | float yPerlin = ((float)neighbor.y / maxHeight) * clusterWeight + offsetY; |
| | | float perlinNoise = Mathf.PerlinNoise(xPerlin, yPerlin); |
| | | |
| | | if (perlinNoise <= (1f / (float)weight)) |
| | | { |
| | | toCheck.Enqueue(neighbor); |
| | | checked_positions.Add(neighbor); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | return size; |
| | | } |
| | | } |
| | |
| | | { |
| | | public static ItemDatabase Instance { get; private set; } |
| | | |
| | | [SerializeField] |
| | | private List<Item> items = new List<Item>(); |
| | | |
| | | private Dictionary<string, Item> itemDictionary = new Dictionary<string, Item>(); |
| | | private Dictionary<int, Item> itemIdDictionary = new Dictionary<int, Item>(); |
| | | |
| | |
| | | if (Instance == null) |
| | | { |
| | | Instance = this; |
| | | LoadItemsFromResources(); |
| | | InitializeItemDictionary(); |
| | | } |
| | | else |
| | |
| | | } |
| | | } |
| | | |
| | | private void LoadItemsFromResources() |
| | | { |
| | | // Load all Item prefabs from the "Resources/Items" folder |
| | | GameObject[] itemPrefabs = Resources.LoadAll<GameObject>("Items"); |
| | | |
| | | foreach (GameObject prefab in itemPrefabs) |
| | | { |
| | | Item item = prefab.GetComponent<Item>(); |
| | | if (item != null) |
| | | { |
| | | items.Add(item); |
| | | } |
| | | else |
| | | { |
| | | Debug.LogWarning($"Prefab {prefab.name} does not have an Item component"); |
| | | } |
| | | } |
| | | |
| | | if (items.Count == 0) |
| | | { |
| | | Debug.LogWarning("No items found in Resources/Items folder"); |
| | | } |
| | | } |
| | | |
| | | private void InitializeItemDictionary() |
| | | { |
| | | itemDictionary.Clear(); |
New file |
| | |
| | | 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; |
| | | } |
New file |
| | |
| | | fileFormatVersion: 2 |
| | | guid: 6b939c0393f507f4fb9e91dfb683f869 |
| | | MonoImporter: |
| | | externalObjects: {} |
| | | serializedVersion: 2 |
| | | defaultReferences: [] |
| | | executionOrder: 0 |
| | | icon: {instanceID: 0} |
| | | userData: |
| | | assetBundleName: |
| | | assetBundleVariant: |
| | |
| | | - component: {fileID: 8973229189939374991} |
| | | - component: {fileID: -776302461885629690} |
| | | - component: {fileID: 3926666667628910059} |
| | | - component: {fileID: 5943816882416256805} |
| | | m_Layer: 6 |
| | | m_Name: DrillIronOre |
| | | m_TagString: Untagged |
| | |
| | | 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: 30 |
| | | minClusterSize: 8 |
| | | tile: {fileID: 11400000, guid: bbc5a3964d8331546a4dbc880f8ae9fc, type: 2} |
| | | maxSpawnHeight: 250 |
| | | minSpawnHeight: 150 |
| | |
| | | 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: |
| | |
| | | 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: |
| | |
| | | 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} |
| | |
| | | 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: |
| | |
| | | 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 |