GameMapTile.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using UnityEngine;
  2. /// <summary> A tile definition. The map/grid consist of an array of these tiles. </summary>
  3. [System.Serializable]
  4. public class GameMapTile
  5. {
  6. // the tile needs a way to be identifiable in the editor. this can be done with either a sprite, colour, or value.
  7. // simply add the [GameMapTilePreview] attribute above any Sprite, Color, String, or Int properties below.
  8. // for String an empty value will be ignored. For Int negative numbers will be ignored.
  9. /// <summary> Unique identifier for tile. This is the value stored in GameMap.grid[] (-1 is used for empty tiles in the grid) </summary>
  10. public int id;
  11. /// <summary> Sprite representing the tile. </summary>
  12. [GameMapTilePreview] public Sprite sprite; // You may choose not to use this but do not remove it since it is required by auto-tiles system.
  13. public int _aid = -1; // helper for auto-tiles; do not remove.
  14. // *** extra properties related to this tile definition
  15. // add any addition serializable types here and they will appear
  16. // for editing in asset properties section of the map editor
  17. // Note:
  18. // Any of the fields following may be removed if you do not need/use them. They are here as an example.
  19. // (of course the demo script makes use of them so update it too)
  20. // Remember to add/remove fields to CopyTo() function too
  21. public enum Type { Null = 0, Player = 1, Tower=2, EnemyTower=3, Enemy=4 }
  22. public Type type = Type.Null; // the runtime might use something like this to identify what the placed tile means
  23. public int opt1 = 0; // this value could depend on the chosen type. For example, if NPC then this could indicate which NPC prefab to spawn from an array of NPC prefabs.
  24. [GameMapTilePreview] public Color color = Color.white;
  25. public int num = 1;
  26. public int startTime = 0;
  27. // ----------------------------------------------------------------------------------------------------------------
  28. /// <summary> Copies this tile's data into target. </summary>
  29. public void CopyTo(GameMapTile t)
  30. {
  31. t.id = id;
  32. t.sprite = sprite;
  33. t.type = type;
  34. t.opt1 = opt1;
  35. t.color = color;
  36. t.num = num;
  37. }
  38. // ----------------------------------------------------------------------------------------------------------------
  39. }