2025-10-09 04:03:32 +08:00
|
|
|
using System;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
public class MapBuildableCell : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
private Vector2Int grid_position;
|
2025-10-09 22:33:05 +08:00
|
|
|
private Transform sprite_render_container;
|
2025-10-09 04:03:32 +08:00
|
|
|
|
|
|
|
|
private void Start()
|
|
|
|
|
{
|
2025-10-09 22:33:05 +08:00
|
|
|
sprite_render_container = transform.GetChild(0);
|
2025-10-09 04:03:32 +08:00
|
|
|
}
|
|
|
|
|
|
2025-10-09 22:33:05 +08:00
|
|
|
public void m_set_grid_position(Vector2Int position)
|
2025-10-09 04:03:32 +08:00
|
|
|
{
|
|
|
|
|
grid_position = position;
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-09 22:33:05 +08:00
|
|
|
public Vector3 m_get_grid_position_with_vector3()
|
2025-10-09 04:03:32 +08:00
|
|
|
{
|
|
|
|
|
return new Vector3(grid_position.y, grid_position.x, 0);
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-09 22:33:05 +08:00
|
|
|
private void self_set_sprite_render_enable(Collider2D other)
|
2025-10-09 04:03:32 +08:00
|
|
|
{
|
|
|
|
|
if (other.gameObject.layer == LayerMask.NameToLayer("UseBuild"))
|
|
|
|
|
{
|
2025-10-09 22:33:05 +08:00
|
|
|
sprite_render_container.gameObject.SetActive(!other.GetComponent<MapBuildPlacer>().m_get_placer_is_snap());
|
2025-10-09 04:03:32 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnTriggerEnter2D(Collider2D other)
|
|
|
|
|
{
|
2025-10-09 22:33:05 +08:00
|
|
|
this.self_set_sprite_render_enable(other);
|
2025-10-09 04:03:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnTriggerStay2D(Collider2D other)
|
|
|
|
|
{
|
2025-10-09 22:33:05 +08:00
|
|
|
this.self_set_sprite_render_enable(other);
|
2025-10-09 04:03:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnTriggerExit2D(Collider2D other)
|
|
|
|
|
{
|
2025-10-09 22:33:05 +08:00
|
|
|
sprite_render_container.gameObject.SetActive(true);
|
2025-10-09 04:03:32 +08:00
|
|
|
}
|
|
|
|
|
}
|