2021-02-26 19:01:47 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
public class ShieldManager : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
public Prototype ShieldPrototype;
|
|
|
|
|
public float CollisionHitDuration = 3;
|
2026-06-21 09:37:54 +01:00
|
|
|
public float LootInteractionCooldown = 0.25f;
|
|
|
|
|
public float ShieldCollisionCooldown = 0.1f;
|
2021-02-26 19:01:47 +00:00
|
|
|
|
|
|
|
|
public Entity Entity { get; set; }
|
|
|
|
|
|
2026-06-21 09:37:54 +01:00
|
|
|
private bool IsShieldActive()
|
2021-02-26 19:01:47 +00:00
|
|
|
{
|
2026-06-21 09:37:54 +01:00
|
|
|
return Entity?.Shield != null && Entity.Shield.Item.Active.Value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Bounds ShieldBounds()
|
|
|
|
|
{
|
|
|
|
|
var renderers = GetComponentsInChildren<Renderer>();
|
|
|
|
|
if (renderers.Length == 0)
|
|
|
|
|
return new Bounds(transform.position, Vector3.one);
|
|
|
|
|
|
|
|
|
|
var bounds = renderers[0].bounds;
|
|
|
|
|
for (var i = 1; i < renderers.Length; i++)
|
|
|
|
|
bounds.Encapsulate(renderers[i].bounds);
|
2021-02-26 19:01:47 +00:00
|
|
|
|
2026-06-21 09:37:54 +01:00
|
|
|
return bounds;
|
2021-02-26 19:01:47 +00:00
|
|
|
}
|
|
|
|
|
|
2026-06-21 09:37:54 +01:00
|
|
|
private static float ShieldPlanarRadius(Bounds bounds)
|
2021-02-26 19:01:47 +00:00
|
|
|
{
|
2026-06-21 09:37:54 +01:00
|
|
|
return Mathf.Max(bounds.extents.x, bounds.extents.z, 0.001f);
|
2021-02-26 19:01:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ShowHit(Vector3 point, float duration)
|
|
|
|
|
{
|
|
|
|
|
var shield = ShieldPrototype.Instantiate<ShieldAnimation>();
|
2026-06-21 09:37:54 +01:00
|
|
|
shield.Direction = shield.transform.InverseTransformPoint(point).normalized;
|
2021-02-26 19:01:47 +00:00
|
|
|
shield.Duration = duration;
|
|
|
|
|
}
|
|
|
|
|
}
|