68 lines
2.1 KiB
C#
68 lines
2.1 KiB
C#
using UnityEngine;
|
|
|
|
namespace BumpCombat.Enemies
|
|
{
|
|
public sealed class AttackWarningVisual : MonoBehaviour
|
|
{
|
|
private static Material sharedMaterial;
|
|
private static Sprite circleSprite;
|
|
private SpriteRenderer circle;
|
|
|
|
private void Awake()
|
|
{
|
|
circle = gameObject.AddComponent<SpriteRenderer>();
|
|
circle.sharedMaterial = GetSharedMaterial();
|
|
circle.sortingLayerName = "EnemyWarning";
|
|
circle.color = new Color(1f, 1f, 1f, .15f);
|
|
if (circleSprite == null)
|
|
circleSprite = Resources.Load<Sprite>("Enemies/Warning-v3/Necromancer-Warning-Circle");
|
|
circle.sprite = circleSprite;
|
|
circle.enabled = false;
|
|
gameObject.SetActive(false);
|
|
}
|
|
|
|
public void Show(EnemyController controller, Vector2 origin,
|
|
Vector2 direction, Vector2 targetPosition)
|
|
{
|
|
if (controller.AttackShape == EnemyAttackShape.TargetCircle)
|
|
ShowTargetCircle(targetPosition, controller.AttackRadius);
|
|
else
|
|
Hide();
|
|
}
|
|
|
|
public void SetActivePhase(bool active)
|
|
{
|
|
if (active) Hide();
|
|
}
|
|
|
|
public void ShowTargetCircle(Vector2 center, float radius)
|
|
{
|
|
gameObject.SetActive(true);
|
|
// Gameplay range is already scaled; only the captured landing point is shown.
|
|
transform.SetParent(null, true);
|
|
transform.position = center;
|
|
transform.rotation = Quaternion.identity;
|
|
transform.localScale = new Vector3(radius, radius, 1f);
|
|
circle.enabled = true;
|
|
}
|
|
|
|
public void Hide()
|
|
{
|
|
transform.localScale = Vector3.one;
|
|
gameObject.SetActive(false);
|
|
}
|
|
|
|
public void CollapseAndHide() => Hide();
|
|
|
|
private static Material GetSharedMaterial()
|
|
{
|
|
if (sharedMaterial == null)
|
|
sharedMaterial = new Material(Shader.Find("Sprites/Default"))
|
|
{
|
|
name = "Attack Warning Material",
|
|
};
|
|
return sharedMaterial;
|
|
}
|
|
}
|
|
}
|