45 lines
1.0 KiB
C#
45 lines
1.0 KiB
C#
using Cryville.EEW.Core.Map;
|
|
using UnityEngine;
|
|
|
|
namespace Cryville.EEW.Unity.Map {
|
|
[RequireComponent(typeof(SpriteRenderer))]
|
|
sealed class MapTile : MonoBehaviour {
|
|
[SerializeField] Transform _idView;
|
|
|
|
public MapTileIndex Index { get; set; }
|
|
|
|
SpriteRenderer _renderer;
|
|
|
|
void Awake() {
|
|
_renderer = GetComponent<SpriteRenderer>();
|
|
}
|
|
|
|
public void Init(MapTileIndex index) {
|
|
Index = index;
|
|
float z = 1 << index.Z;
|
|
transform.localPosition = new(index.X / z, -(index.Y + 1) / z, -index.Z / 100f);
|
|
transform.localScale = new Vector3(1 / z, 1 / z, 1);
|
|
_idView.gameObject.SetActive(true);
|
|
byte e = SharedSettings.Instance.IdBytes[((index.X << 2) + index.Y) & 0x1f];
|
|
int ex = e >> 4, ey = e & 0xf;
|
|
_idView.localPosition = new(ex / 16f, 1 - ey / 16f, -1 / 200f);
|
|
}
|
|
|
|
public void Set(Sprite sprite) {
|
|
if (_renderer) {
|
|
_renderer.sprite = sprite;
|
|
}
|
|
}
|
|
|
|
bool _isDestroyed;
|
|
public void Destroy() {
|
|
_isDestroyed = true;
|
|
}
|
|
void Update() {
|
|
if (_isDestroyed) {
|
|
Destroy(gameObject);
|
|
}
|
|
}
|
|
}
|
|
}
|