From 569f8efeca94146d3f863408cedb80ce6683e793 Mon Sep 17 00:00:00 2001
From: miepzerino <o.skotnik@gmail.com>
Date: Fri, 22 Dec 2023 19:40:50 +0000
Subject: [PATCH] Added ruleTile and generate tileMap with perlinNoise
---
Assets/TileSets/Palettes/ForestTileset.prefab | 24 ++
Assets/GenerateTileMap.cs | 48 ++++++
Assets/TileSets/Palettes/ForestRuleTile.asset | 312 ++++++++++++++++++++++++++++++++++++++++++++
Assets/TileSets/Palettes/ForestRuleTile.asset.meta | 8 +
Assets/GenerateTileMap.cs.meta | 11 +
5 files changed, 397 insertions(+), 6 deletions(-)
diff --git a/Assets/GenerateTileMap.cs b/Assets/GenerateTileMap.cs
new file mode 100644
index 0000000..4239562
--- /dev/null
+++ b/Assets/GenerateTileMap.cs
@@ -0,0 +1,48 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+using UnityEngine.Tilemaps;
+
+public class GenerateTileMap : MonoBehaviour
+{
+ public int width = 256;
+ public int height = 256;
+ public float scale = 20f;
+ public float offsetX = 0f;
+ public float offsetY = 0f;
+ Tilemap tilemap;
+ public RuleTile ruleTile;
+ //public List<TileBase> tiles;
+ // Start is called before the first frame update
+ void Start()
+ {
+ tilemap = GetComponent<Tilemap>();
+ GenerateTiles();
+ }
+
+
+ public void GenerateTiles()
+ {
+ for (int x = 0; x < width; x++)
+ {
+ for(int y = 0; y < height; y++)
+ {
+ float xPerlin = ((float)x / width) * scale + offsetX;
+ float yPerlin = ((float)y / height) * scale + offsetY;
+ float perlinNoise = Mathf.PerlinNoise(xPerlin, yPerlin);
+
+ if (perlinNoise >= 0.3f)
+ {
+ if (!tilemap.HasTile(new Vector3Int(x,y+1))) {
+ tilemap.SetTile(new Vector3Int(x, y), ruleTile);
+ }
+ else
+ {
+ tilemap.SetTile(new Vector3Int(x, y), ruleTile);
+ }
+ }
+
+ }
+ }
+ }
+}
diff --git a/Assets/GenerateTileMap.cs.meta b/Assets/GenerateTileMap.cs.meta
new file mode 100644
index 0000000..a67ddf8
--- /dev/null
+++ b/Assets/GenerateTileMap.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 000b2ca4a3c14d04e8c8a5c1084c700f
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/TileSets/Palettes/ForestRuleTile.asset b/Assets/TileSets/Palettes/ForestRuleTile.asset
new file mode 100644
index 0000000..ecfeae9
--- /dev/null
+++ b/Assets/TileSets/Palettes/ForestRuleTile.asset
@@ -0,0 +1,312 @@
+%YAML 1.1
+%TAG !u! tag:unity3d.com,2011:
+--- !u!114 &11400000
+MonoBehaviour:
+ m_ObjectHideFlags: 0
+ m_CorrespondingSourceObject: {fileID: 0}
+ m_PrefabInstance: {fileID: 0}
+ m_PrefabAsset: {fileID: 0}
+ m_GameObject: {fileID: 0}
+ m_Enabled: 1
+ m_EditorHideFlags: 0
+ m_Script: {fileID: 11500000, guid: 9d1514134bc4fbd41bb739b1b9a49231, type: 3}
+ m_Name: ForestRuleTile
+ m_EditorClassIdentifier:
+ m_DefaultSprite: {fileID: -1554015212, guid: 42962cf14c23fee4baaaea0cd52d52e0, type: 3}
+ m_DefaultGameObject: {fileID: 0}
+ m_DefaultColliderType: 1
+ m_TilingRules:
+ - m_Id: 0
+ m_Sprites:
+ - {fileID: -1200237691, guid: 42962cf14c23fee4baaaea0cd52d52e0, type: 3}
+ m_GameObject: {fileID: 0}
+ m_MinAnimationSpeed: 1
+ m_MaxAnimationSpeed: 1
+ m_PerlinScale: 0.5
+ m_Output: 0
+ m_ColliderType: 1
+ m_RandomTransform: 0
+ m_Neighbors: 020000000200000001000000
+ m_NeighborPositions:
+ - {x: -1, y: 0, z: 0}
+ - {x: 0, y: 1, z: 0}
+ - {x: 1, y: 0, z: 0}
+ m_RuleTransform: 0
+ - m_Id: 1
+ m_Sprites:
+ - {fileID: -1554015212, guid: 42962cf14c23fee4baaaea0cd52d52e0, type: 3}
+ m_GameObject: {fileID: 0}
+ m_MinAnimationSpeed: 1
+ m_MaxAnimationSpeed: 1
+ m_PerlinScale: 0.5
+ m_Output: 0
+ m_ColliderType: 1
+ m_RandomTransform: 0
+ m_Neighbors: 020000000100000001000000
+ m_NeighborPositions:
+ - {x: 0, y: 1, z: 0}
+ - {x: 1, y: 0, z: 0}
+ - {x: -1, y: 0, z: 0}
+ m_RuleTransform: 0
+ - m_Id: 2
+ m_Sprites:
+ - {fileID: 952801214, guid: 42962cf14c23fee4baaaea0cd52d52e0, type: 3}
+ m_GameObject: {fileID: 0}
+ m_MinAnimationSpeed: 1
+ m_MaxAnimationSpeed: 1
+ m_PerlinScale: 0.5
+ m_Output: 0
+ m_ColliderType: 1
+ m_RandomTransform: 0
+ m_Neighbors: 020000000200000001000000
+ m_NeighborPositions:
+ - {x: 0, y: 1, z: 0}
+ - {x: 1, y: 0, z: 0}
+ - {x: -1, y: 0, z: 0}
+ m_RuleTransform: 0
+ - m_Id: 3
+ m_Sprites:
+ - {fileID: -1701200628, guid: 42962cf14c23fee4baaaea0cd52d52e0, type: 3}
+ m_GameObject: {fileID: 0}
+ m_MinAnimationSpeed: 1
+ m_MaxAnimationSpeed: 1
+ m_PerlinScale: 0.5
+ m_Output: 0
+ m_ColliderType: 1
+ m_RandomTransform: 0
+ m_Neighbors: 02000000010000000100000001000000
+ m_NeighborPositions:
+ - {x: -1, y: 0, z: 0}
+ - {x: 1, y: 0, z: 0}
+ - {x: 0, y: 1, z: 0}
+ - {x: 0, y: -1, z: 0}
+ m_RuleTransform: 0
+ - m_Id: 4
+ m_Sprites:
+ - {fileID: 1210147125, guid: 42962cf14c23fee4baaaea0cd52d52e0, type: 3}
+ m_GameObject: {fileID: 0}
+ m_MinAnimationSpeed: 1
+ m_MaxAnimationSpeed: 1
+ m_PerlinScale: 0.5
+ m_Output: 0
+ m_ColliderType: 1
+ m_RandomTransform: 0
+ m_Neighbors: 01000000020000000200000001000000
+ 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}
+ m_RuleTransform: 0
+ - m_Id: 5
+ m_Sprites:
+ - {fileID: -603009601, guid: 42962cf14c23fee4baaaea0cd52d52e0, type: 3}
+ m_GameObject: {fileID: 0}
+ m_MinAnimationSpeed: 1
+ m_MaxAnimationSpeed: 1
+ m_PerlinScale: 0.5
+ m_Output: 0
+ m_ColliderType: 1
+ m_RandomTransform: 0
+ m_Neighbors: 010000000200000001000000010000000100000001000000
+ 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:
+ - {fileID: -1438444955, guid: 42962cf14c23fee4baaaea0cd52d52e0, type: 3}
+ m_GameObject: {fileID: 0}
+ m_MinAnimationSpeed: 1
+ m_MaxAnimationSpeed: 1
+ m_PerlinScale: 0.5
+ m_Output: 0
+ m_ColliderType: 1
+ m_RandomTransform: 0
+ m_Neighbors: 01000000010000000200000002000000
+ m_NeighborPositions:
+ - {x: -1, y: 0, z: 0}
+ - {x: 0, y: 1, z: 0}
+ - {x: 1, y: 0, z: 0}
+ - {x: 0, y: -1, z: 0}
+ m_RuleTransform: 0
+ - m_Id: 7
+ m_Sprites:
+ - {fileID: -1608621674, guid: 42962cf14c23fee4baaaea0cd52d52e0, type: 3}
+ m_GameObject: {fileID: 0}
+ m_MinAnimationSpeed: 1
+ m_MaxAnimationSpeed: 1
+ m_PerlinScale: 0.5
+ m_Output: 0
+ m_ColliderType: 1
+ m_RandomTransform: 0
+ m_Neighbors: 02000000010000000100000001000000
+ m_NeighborPositions:
+ - {x: 1, y: 0, z: 0}
+ - {x: 0, y: -1, z: 0}
+ - {x: 0, y: 1, z: 0}
+ - {x: -1, y: 0, z: 0}
+ m_RuleTransform: 0
+ - m_Id: 8
+ m_Sprites:
+ - {fileID: 68800321, guid: 42962cf14c23fee4baaaea0cd52d52e0, type: 3}
+ - {fileID: 1328409926, guid: 2dece116af0ca9145ae459928df1a55f, type: 3}
+ m_GameObject: {fileID: 0}
+ m_MinAnimationSpeed: 1
+ m_MaxAnimationSpeed: 1
+ m_PerlinScale: 0.703
+ m_Output: 1
+ m_ColliderType: 1
+ m_RandomTransform: 0
+ m_Neighbors: 0100000001000000010000000100000001000000010000000100000001000000
+ m_NeighborPositions:
+ - {x: 0, y: 1, z: 0}
+ - {x: -1, y: 0, z: 0}
+ - {x: 0, y: -1, 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: -1, y: -1, z: 0}
+ m_RuleTransform: 0
+ - m_Id: 9
+ m_Sprites:
+ - {fileID: 1984530201, guid: 42962cf14c23fee4baaaea0cd52d52e0, type: 3}
+ m_GameObject: {fileID: 0}
+ m_MinAnimationSpeed: 1
+ m_MaxAnimationSpeed: 1
+ m_PerlinScale: 0.5
+ m_Output: 0
+ m_ColliderType: 1
+ m_RandomTransform: 0
+ m_Neighbors: 0100000002000000010000000100000001000000
+ m_NeighborPositions:
+ - {x: 1, y: 0, z: 0}
+ - {x: 1, y: -1, z: 0}
+ - {x: 0, y: -1, z: 0}
+ - {x: -1, y: 0, z: 0}
+ - {x: 0, y: 1, z: 0}
+ m_RuleTransform: 0
+ - m_Id: 10
+ m_Sprites:
+ - {fileID: -58827736, guid: 42962cf14c23fee4baaaea0cd52d52e0, type: 3}
+ m_GameObject: {fileID: 0}
+ m_MinAnimationSpeed: 1
+ m_MaxAnimationSpeed: 1
+ m_PerlinScale: 0.5
+ m_Output: 0
+ m_ColliderType: 1
+ m_RandomTransform: 0
+ m_Neighbors: 0100000001000000010000000100000002000000
+ m_NeighborPositions:
+ - {x: 1, y: 0, z: 0}
+ - {x: 0, y: -1, z: 0}
+ - {x: -1, y: 0, z: 0}
+ - {x: 0, y: 1, z: 0}
+ - {x: -1, y: -1, z: 0}
+ m_RuleTransform: 0
+ - m_Id: 11
+ m_Sprites:
+ - {fileID: 1943074245, guid: 42962cf14c23fee4baaaea0cd52d52e0, type: 3}
+ m_GameObject: {fileID: 0}
+ m_MinAnimationSpeed: 1
+ m_MaxAnimationSpeed: 1
+ m_PerlinScale: 0.5
+ m_Output: 0
+ m_ColliderType: 1
+ m_RandomTransform: 0
+ m_Neighbors: 02000000020000000200000002000000
+ m_NeighborPositions:
+ - {x: -1, y: 0, z: 0}
+ - {x: 0, y: 1, z: 0}
+ - {x: 1, y: 0, z: 0}
+ - {x: 0, y: -1, z: 0}
+ m_RuleTransform: 0
+ - m_Id: 12
+ m_Sprites:
+ - {fileID: -1325585479, guid: 2dece116af0ca9145ae459928df1a55f, type: 3}
+ m_GameObject: {fileID: 0}
+ m_MinAnimationSpeed: 1
+ m_MaxAnimationSpeed: 1
+ m_PerlinScale: 0.5
+ m_Output: 0
+ m_ColliderType: 1
+ m_RandomTransform: 0
+ m_Neighbors: 0100000001000000020000000100000001000000010000000100000001000000
+ m_NeighborPositions:
+ - {x: 0, y: 1, z: 0}
+ - {x: 1, y: 0, z: 0}
+ - {x: 1, y: 1, 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}
+ m_RuleTransform: 0
+ - m_Id: 13
+ m_Sprites:
+ - {fileID: 1290617244, guid: 2dece116af0ca9145ae459928df1a55f, type: 3}
+ m_GameObject: {fileID: 0}
+ m_MinAnimationSpeed: 1
+ m_MaxAnimationSpeed: 1
+ m_PerlinScale: 0.5
+ m_Output: 0
+ m_ColliderType: 1
+ m_RandomTransform: 0
+ m_Neighbors: 0100000001000000010000000100000001000000010000000200000001000000
+ 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_RuleTransform: 0
+ - m_Id: 14
+ m_Sprites:
+ - {fileID: 1623399786, guid: 2dece116af0ca9145ae459928df1a55f, type: 3}
+ m_GameObject: {fileID: 0}
+ m_MinAnimationSpeed: 1
+ m_MaxAnimationSpeed: 1
+ m_PerlinScale: 0.5
+ m_Output: 0
+ m_ColliderType: 1
+ m_RandomTransform: 0
+ m_Neighbors: 0100000001000000010000000200000002000000020000000100000002000000
+ 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_RuleTransform: 0
+ - m_Id: 15
+ m_Sprites:
+ - {fileID: -889089113, guid: 2dece116af0ca9145ae459928df1a55f, type: 3}
+ m_GameObject: {fileID: 0}
+ m_MinAnimationSpeed: 1
+ m_MaxAnimationSpeed: 1
+ m_PerlinScale: 0.5
+ m_Output: 0
+ m_ColliderType: 1
+ m_RandomTransform: 0
+ m_Neighbors: 0100000001000000010000000200000002000000020000000100000002000000
+ 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_RuleTransform: 0
diff --git a/Assets/TileSets/Palettes/ForestRuleTile.asset.meta b/Assets/TileSets/Palettes/ForestRuleTile.asset.meta
new file mode 100644
index 0000000..3c293d3
--- /dev/null
+++ b/Assets/TileSets/Palettes/ForestRuleTile.asset.meta
@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: e77c00aec3ec74f4a9ec15ef63c3f9a7
+NativeFormatImporter:
+ externalObjects: {}
+ mainObjectFileID: 11400000
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/TileSets/Palettes/ForestTileset.prefab b/Assets/TileSets/Palettes/ForestTileset.prefab
index d43f9b3..a032388 100644
--- a/Assets/TileSets/Palettes/ForestTileset.prefab
+++ b/Assets/TileSets/Palettes/ForestTileset.prefab
@@ -42,6 +42,16 @@
m_GameObject: {fileID: 3278050954428335906}
m_Enabled: 1
m_Tiles:
+ - first: {x: -5, y: -1, z: 0}
+ second:
+ serializedVersion: 2
+ m_TileIndex: 75
+ m_TileSpriteIndex: 0
+ m_TileMatrixIndex: 0
+ m_TileColorIndex: 0
+ m_TileObjectToInstantiateIndex: 65535
+ dummyAlignment: 0
+ m_AllTileFlags: 1073741826
- first: {x: -7, y: 2, z: 0}
second:
serializedVersion: 2
@@ -944,8 +954,10 @@
m_Data: {fileID: 11400000, guid: 9b08cbd851e61d440ab3bbec430551d0, type: 2}
- m_RefCount: 1
m_Data: {fileID: 11400000, guid: a6d768d37412b75439e62ced7c847ce1, type: 2}
- m_TileSpriteArray:
- m_RefCount: 1
+ m_Data: {fileID: 11400000, guid: e77c00aec3ec74f4a9ec15ef63c3f9a7, type: 2}
+ m_TileSpriteArray:
+ - m_RefCount: 2
m_Data: {fileID: -1200237691, guid: 42962cf14c23fee4baaaea0cd52d52e0, type: 3}
- m_RefCount: 1
m_Data: {fileID: -1554015212, guid: 42962cf14c23fee4baaaea0cd52d52e0, type: 3}
@@ -1096,7 +1108,7 @@
- m_RefCount: 1
m_Data: {fileID: 1265893066, guid: 118553c8864a2bf4abaf757c357494e5, type: 3}
m_TileMatrixArray:
- - m_RefCount: 75
+ - m_RefCount: 76
m_Data:
e00: 1
e01: 0
@@ -1115,13 +1127,13 @@
e32: 0
e33: 1
m_TileColorArray:
- - m_RefCount: 75
+ - m_RefCount: 76
m_Data: {r: 1, g: 1, b: 1, a: 1}
m_TileObjectToInstantiateArray: []
m_AnimationFrameRate: 1
m_Color: {r: 1, g: 1, b: 1, a: 1}
- m_Origin: {x: -7, y: 2, z: 0}
- m_Size: {x: 21, y: 7, z: 1}
+ m_Origin: {x: -7, y: -1, z: 0}
+ m_Size: {x: 21, y: 10, z: 1}
m_TileAnchor: {x: 0.5, y: 0.5, z: 0}
m_TileOrientation: 0
m_TileOrientationMatrix:
@@ -1235,7 +1247,7 @@
m_CellGap: {x: 0, y: 0, z: 0}
m_CellLayout: 0
m_CellSwizzle: 0
---- !u!114 &6877429595757718357
+--- !u!114 &6290011975362041633
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
--
Gitblit v1.10.0