A 2D Farming RPG
This is just a simple 2D farming RPG game
Loading...
Searching...
No Matches
TilemapGridProperties.cs
Go to the documentation of this file.
1using UnityEditor;
2using UnityEngine;
3using UnityEngine.Tilemaps;
4
5[ExecuteAlways]
9public class TilemapGridProperties : MonoBehaviour
10{
11 private Tilemap m_Tilemap;
12 [SerializeField] private SO_GridProperties m_GridProperties = null;
13 [SerializeField] private GridBoolProperty m_GridBoolProperty = GridBoolProperty.Diggable;
14
19 private void OnEnable()
20 {
21 if( !Application.IsPlaying( gameObject ) )
22 {
23 m_Tilemap = GetComponent<Tilemap>();
24
25 if( m_GridProperties != null )
26 {
28 }
29 }
30 }
31
37 private void OnDisable()
38 {
39 if( !Application.IsPlaying( gameObject ) )
40 {
42
43 if( m_GridProperties != null )
44 {
45 EditorUtility.SetDirty(m_GridProperties);
46 }
47 }
48 }
49
53 private void UpdateGridProperties()
54 {
55 // Compress Tilemap Bounds.
56 m_Tilemap.CompressBounds();
57
58 if( !Application.IsPlaying( gameObject ) )
59 {
60 if( m_GridProperties != null )
61 {
62 Vector3Int startCell = m_Tilemap.cellBounds.min;
63 Vector3Int endCell = m_Tilemap.cellBounds.max;
64
65 for( int x = startCell.x; x < endCell.x; x++ )
66 {
67 for( int y = startCell.y; y < endCell.y; y++ )
68 {
69 TileBase tile = m_Tilemap.GetTile( new Vector3Int( x, y, 0) );
70
71 if( tile != null )
72 {
74 }
75 }
76 }
77 }
78 }
79 }
80
81 private void Update()
82 {
83 if( !Application.IsPlaying( gameObject ) )
84 {
85 Debug.Log("DISABLE PROPERTY TILEMAPS");
86 }
87 }
88}
GridBoolProperty
Describes the Grid bool property. Each grid holds following information.
Definition: Enums.cs:95
Holds grid information x and y coordinate.
Holds information about grid of every scene.
Definition: GridProperty.cs:6
This ScriptableObject object asset will contain all the information of each scene.
List< GridProperty > m_GridPropertyList
For every grid, we read our tilemap and add to this list.
This script by default will execute on both editor and runtime.
SO_GridProperties m_GridProperties
void OnDisable()
Only populate in the editor time. Upon disable, it will capture all the details of tilemap and save i...
void UpdateGridProperties()
Goes through the tilemap and captures everything on there.
void OnEnable()
Only populate in the editor time. Clear the grid property list allowing it to store new values.
GridBoolProperty m_GridBoolProperty