2025-09-28 15:02:57 +08:00
|
|
|
using Data;
|
|
|
|
|
using TMPro;
|
2025-08-19 20:22:10 +08:00
|
|
|
using UnityEngine;
|
2025-10-10 14:08:23 +08:00
|
|
|
using Utils;
|
2025-08-19 20:22:10 +08:00
|
|
|
|
|
|
|
|
namespace Entity
|
|
|
|
|
{
|
2025-08-28 16:20:24 +08:00
|
|
|
public class BuildingOutline : Outline
|
2025-08-19 20:22:10 +08:00
|
|
|
{
|
|
|
|
|
public BoxCollider2D boxCollider;
|
2025-09-28 15:02:57 +08:00
|
|
|
public CircleCollider2D trigger;
|
|
|
|
|
|
|
|
|
|
public TMP_Text tip;
|
|
|
|
|
public bool PlayerOnGround { get; private set; }
|
|
|
|
|
|
2025-10-10 14:08:23 +08:00
|
|
|
private void OnTriggerEnter2D(Collider2D other)
|
|
|
|
|
{
|
|
|
|
|
if (other.gameObject.CompareTag("Player"))
|
|
|
|
|
{
|
|
|
|
|
tip.gameObject.SetActive(true);
|
|
|
|
|
PlayerOnGround = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnTriggerExit2D(Collider2D other)
|
|
|
|
|
{
|
|
|
|
|
tip.gameObject.SetActive(false);
|
|
|
|
|
PlayerOnGround = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Init()
|
2025-08-19 20:22:10 +08:00
|
|
|
{
|
2025-09-28 15:02:57 +08:00
|
|
|
var textureSize = GetBodyTextureSize();
|
|
|
|
|
outlineRenderer.size = textureSize;
|
|
|
|
|
var colliderSize = GetColliderSize();
|
|
|
|
|
boxCollider.size = colliderSize;
|
|
|
|
|
boxCollider.offset = GetOffset();
|
2025-08-19 20:22:10 +08:00
|
|
|
if (progressBarPrefab)
|
|
|
|
|
{
|
2025-09-28 15:02:57 +08:00
|
|
|
progressBarPrefab.transform.localPosition += new Vector3(0f, textureSize.y * 2 / 3, 0f);
|
|
|
|
|
progressBarPrefab.transform.localScale = new Vector3(textureSize.x, 1f / 10f, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (entity.entityDef is not BuildingDef buildingDef || buildingDef.triggerEvents == null)
|
|
|
|
|
{
|
|
|
|
|
trigger.enabled = false;
|
|
|
|
|
return;
|
2025-08-19 20:22:10 +08:00
|
|
|
}
|
2025-09-28 15:02:57 +08:00
|
|
|
|
|
|
|
|
trigger.radius = buildingDef.detectionRadius;
|
|
|
|
|
if (!string.IsNullOrEmpty(buildingDef.triggerPosition))
|
|
|
|
|
{
|
2025-10-10 14:08:23 +08:00
|
|
|
var position = StringUtils.StringToVector2(buildingDef.triggerPosition);
|
2025-09-28 15:02:57 +08:00
|
|
|
trigger.offset = position;
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-03 00:31:34 +08:00
|
|
|
// tip.transform.localPosition += new Vector3(0f, textureSize.y * 2 / 3, 0f);
|
2025-09-28 15:02:57 +08:00
|
|
|
tip.text = $"按{buildingDef.activateKey}打开{buildingDef.label}\n{buildingDef.description}";
|
|
|
|
|
tip.gameObject.SetActive(false);
|
2025-08-19 20:22:10 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|