Advertisement
mDiyo

Untitled

Jan 21st, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEngine.Tilemaps;
  3.  
  4. [CreateAssetMenu]
  5. public class PrefabTile : UnityEngine.Tilemaps.TileBase
  6. {
  7. public Sprite Sprite; //The sprite of tile in the palette
  8. public GameObject Prefab; //The gameobject to spawn
  9.  
  10.  
  11. public override void GetTileData(Vector3Int position, ITilemap tilemap, ref TileData tileData)
  12. {
  13. // Assign variables
  14. if (!Application.isPlaying) tileData.sprite = Sprite;
  15. else tileData.sprite = null;
  16.  
  17. if (Prefab) tileData.gameObject = Prefab;
  18. }
  19.  
  20. public override bool StartUp(Vector3Int position, ITilemap tilemap, GameObject go)
  21. {
  22. // Streangly the position of gameobject starts at Left Bottom point of cell and not at it center
  23. // TODO need to add anchor points (vertical and horisontal (left,centre,right)(top,centre,bottom))
  24. go.transform.position += Vector3.up * 0.5f + Vector3.right * 0.5f;
  25. return true;
  26. }
  27.  
  28. public override bool GetTileAnimationData(Vector3Int location, ITilemap tileMap, ref TileAnimationData tileAnimationData)
  29. {
  30. // Make sprite of tile invisiable
  31. tileAnimationData.animatedSprites = new Sprite[] { null};
  32. tileAnimationData.animationSpeed = 0;
  33. tileAnimationData.animationStartTime = 0;
  34. return true;
  35. }
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement