根据提供的code differences信息,由于没有具体的代码变更内容,我将生成一个通用的commit message模板:
``` docs(readme): 更新文档说明 - 添加项目使用指南 - 完善API接口说明 - 修正错误的配置示例 ``` 注意:由于您提供的code differences部分为空,以上是一个示例模板。当您有具体的代码变更时,请提供详细的变更内容以便生成更准确的commit message。
This commit is contained in:
1 parent
8d58c2223c
commit
11f1af357d
191 files changed
+2315
-1539
No files matched your search
@@ -0,0 +1,138 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class ShieldBarrier : MonoBehaviour
|
||||
{
|
||||
[Header("盾牌状态")]
|
||||
[Min(0f)]
|
||||
public float maxDurability = 220f;
|
||||
|
||||
[Min(0f)]
|
||||
public float currentDurability;
|
||||
|
||||
[Min(0f)]
|
||||
public float duration = 6f;
|
||||
|
||||
[Range(-1f, 1f)]
|
||||
public float frontDotThreshold = 0.15f;
|
||||
|
||||
private UnitBase owner;
|
||||
private Collider barrierCollider;
|
||||
private float remainingTime;
|
||||
|
||||
public UnitBase Owner => owner;
|
||||
|
||||
public float CurrentDurability => currentDurability;
|
||||
|
||||
public bool IsActive =>
|
||||
isActiveAndEnabled &&
|
||||
barrierCollider != null &&
|
||||
barrierCollider.enabled &&
|
||||
currentDurability > 0f &&
|
||||
remainingTime > 0f;
|
||||
|
||||
public void Configure(UnitBase shieldOwner, Collider shieldCollider)
|
||||
{
|
||||
owner = shieldOwner;
|
||||
barrierCollider = shieldCollider;
|
||||
}
|
||||
|
||||
public void Refresh(float durability, float activeDuration, Vector3 localPosition, Vector3 localSize)
|
||||
{
|
||||
if (barrierCollider == null)
|
||||
{
|
||||
barrierCollider = GetComponent<Collider>();
|
||||
}
|
||||
|
||||
if (owner == null)
|
||||
{
|
||||
owner = GetComponentInParent<UnitBase>();
|
||||
}
|
||||
|
||||
transform.localPosition = localPosition;
|
||||
transform.localRotation = Quaternion.identity;
|
||||
|
||||
BoxCollider boxCollider = barrierCollider as BoxCollider;
|
||||
if (boxCollider != null)
|
||||
{
|
||||
boxCollider.center = Vector3.zero;
|
||||
boxCollider.size = localSize;
|
||||
boxCollider.isTrigger = true;
|
||||
}
|
||||
|
||||
maxDurability = Mathf.Max(0.01f, durability);
|
||||
currentDurability = maxDurability;
|
||||
duration = Mathf.Max(0.01f, activeDuration);
|
||||
remainingTime = duration;
|
||||
|
||||
gameObject.SetActive(true);
|
||||
if (barrierCollider != null)
|
||||
{
|
||||
barrierCollider.enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
public bool TryBlock(GameObject attacker, float damage)
|
||||
{
|
||||
if (!IsActive || damage <= 0f)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (attacker != null && !IsIncomingFromFront(attacker))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
currentDurability -= damage;
|
||||
if (currentDurability <= 0f)
|
||||
{
|
||||
DisableBarrier();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void DisableBarrier()
|
||||
{
|
||||
currentDurability = 0f;
|
||||
remainingTime = 0f;
|
||||
|
||||
if (barrierCollider != null)
|
||||
{
|
||||
barrierCollider.enabled = false;
|
||||
}
|
||||
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (!IsActive)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
remainingTime -= Time.deltaTime;
|
||||
if (remainingTime <= 0f)
|
||||
{
|
||||
DisableBarrier();
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsIncomingFromFront(GameObject attacker)
|
||||
{
|
||||
if (owner == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
Vector3 direction = attacker.transform.position - owner.transform.position;
|
||||
direction.y = 0f;
|
||||
if (direction.sqrMagnitude <= 0.0001f)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return Vector3.Dot(owner.transform.forward, direction.normalized) >= frontDotThreshold;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user