miepzerino
2023-12-22 569f8efeca94146d3f863408cedb80ce6683e793
Added ruleTile and generate tileMap with perlinNoise
1 files modified
4 files added
403 ■■■■■ changed files
Assets/GenerateTileMap.cs 48 ●●●●● patch | view | raw | blame | history
Assets/GenerateTileMap.cs.meta 11 ●●●●● patch | view | raw | blame | history
Assets/TileSets/Palettes/ForestRuleTile.asset 312 ●●●●● patch | view | raw | blame | history
Assets/TileSets/Palettes/ForestRuleTile.asset.meta 8 ●●●●● patch | view | raw | blame | history
Assets/TileSets/Palettes/ForestTileset.prefab 24 ●●●● patch | view | raw | blame | history
Assets/GenerateTileMap.cs
New file
@@ -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);
                    }
                }
            }
        }
    }
}
Assets/GenerateTileMap.cs.meta
New file
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 000b2ca4a3c14d04e8c8a5c1084c700f
MonoImporter:
  externalObjects: {}
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData:
  assetBundleName:
  assetBundleVariant:
Assets/TileSets/Palettes/ForestRuleTile.asset
New file
@@ -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
Assets/TileSets/Palettes/ForestRuleTile.asset.meta
New file
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e77c00aec3ec74f4a9ec15ef63c3f9a7
NativeFormatImporter:
  externalObjects: {}
  mainObjectFileID: 11400000
  userData:
  assetBundleName:
  assetBundleVariant:
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}