Advertisement
Guest User

wAEGWEG

a guest
Sep 19th, 2023
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.83 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.Threading;
  4. using UnityEditor;
  5. using UnityEngine;
  6. using UnityEngine.Tilemaps;
  7. using static UnityEditor.FilePathAttribute;
  8.  
  9. public class WaterTile : Tile
  10. {
  11.     public Sprite shallowWater;
  12.     public Sprite shallowOcean;
  13.     public Sprite deepOcean;
  14.     [HideInInspector]
  15.     public float altitude;
  16.     [HideInInspector]
  17.     public Tile[] neighbours = new Tile[8];
  18.  
  19.  
  20.     public override void GetTileData(Vector3Int position, ITilemap tilemap, ref TileData tileData)
  21.     {
  22.         if (altitude > 0.33f)
  23.         {
  24.             tileData.sprite = shallowWater;
  25.         }
  26.         else if (altitude < 0.24f)
  27.         {
  28.             tileData.sprite = deepOcean;
  29.         }
  30.         else
  31.         {
  32.             tileData.sprite = shallowOcean;
  33.         }
  34.  
  35.         neighbours[0] = GetNeighbours(position + new Vector3Int(0, 1, 0), tilemap);
  36.         neighbours[1] = GetNeighbours(position + new Vector3Int(1, 0, 0), tilemap);
  37.         neighbours[2] = GetNeighbours(position + new Vector3Int(0, -1, 0), tilemap);
  38.         neighbours[3] = GetNeighbours(position + new Vector3Int(-1, 0, 0), tilemap);
  39.     }
  40.  
  41.     private Tile GetNeighbours(Vector3Int position, ITilemap tilemap)
  42.     {
  43.         return tilemap.GetTile(position) as Tile;
  44.     }
  45.     private bool HasWaterTile(Vector3Int position, ITilemap tilemap)
  46.     {
  47.         return tilemap.GetTile(position) == this;
  48.     }
  49.  
  50. #if UNITY_EDITOR
  51.     [MenuItem("Assets/Create/WaterTile")]
  52.     public static void CreateWaterTile()
  53.     {
  54.         string path = EditorUtility.SaveFilePanelInProject("Save Water Tile", "New Water Tile", "Asset", "Save Water Tile", "Assets/Tiles");
  55.         if (path == "")
  56.             return;
  57.         AssetDatabase.CreateAsset(ScriptableObject.CreateInstance<WaterTile>(), path);
  58.     }
  59. #endif
  60. }
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement