au lieu d'ajouter une classe data intermédiaire. l'idée est que ça rend les modifications complexes d'avoir un intermédiaire. Autant ajouter la tuile direct.
34 lines
1.3 KiB
C#
34 lines
1.3 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Tilemaps;
|
|
|
|
|
|
[CreateAssetMenu(menuName = "Gather And Defend/Resource Tile")]
|
|
public class ResourceTile : TileBase, ILevelObject
|
|
{
|
|
[SerializeField]
|
|
[Tooltip("the prefab of the currency that will be spawned when mining this resource")]
|
|
private GameObject _yieldPrefab;
|
|
[SerializeField]
|
|
private Sprite _sprite;
|
|
public Vector3 Position { get; private set; }
|
|
|
|
public Sprite Sprite { get => _sprite; set => _sprite = value; }
|
|
public override bool StartUp(Vector3Int position, ITilemap tilemap, GameObject go)
|
|
{
|
|
if (!Application.isPlaying) return base.StartUp(position, tilemap, go);
|
|
|
|
//need to create an instance of the tile, otherwise the position will change for all tiles instead of only this one.
|
|
var instance = Instantiate(this);
|
|
instance.Position = position;
|
|
LevelManager.Instance.Add(instance);
|
|
return base.StartUp(position, tilemap, go);
|
|
}
|
|
public override void GetTileData(Vector3Int position, ITilemap tilemap, ref TileData tileData)
|
|
{
|
|
tileData.sprite = _sprite;
|
|
tileData.transform.SetTRS(Vector3.zero, Quaternion.identity, Vector3.one);
|
|
tileData.color = Color.white;
|
|
}
|
|
} |