清理各个 Component 里的判断以及调用规范
This commit is contained in:
@@ -14,13 +14,13 @@ namespace SepCore.HPBar
|
||||
private const float KeepSeconds = 0.4f;
|
||||
private const float FadeOutSeconds = 0.3f;
|
||||
|
||||
[FormerlySerializedAs("m_HPBar")] [SerializeField] private Slider _hPBar = null;
|
||||
[FormerlySerializedAs("m_HPBar")] [SerializeField] private Slider _hpBar = null;
|
||||
|
||||
private Canvas _parentCanvas = null;
|
||||
private RectTransform _cachedTransform = null;
|
||||
private CanvasGroup _cachedCanvasGroup = null;
|
||||
private EntityBase _owner = null;
|
||||
private int m_OwnerId = 0;
|
||||
private int _ownerId = 0;
|
||||
|
||||
public EntityBase Owner => _owner;
|
||||
|
||||
@@ -38,11 +38,11 @@ namespace SepCore.HPBar
|
||||
StopAllCoroutines();
|
||||
|
||||
_cachedCanvasGroup.alpha = 1f;
|
||||
if (_owner != owner || m_OwnerId != owner.Id)
|
||||
if (_owner != owner || _ownerId != owner.Id)
|
||||
{
|
||||
_hPBar.value = fromHPRatio;
|
||||
_hpBar.value = fromHPRatio;
|
||||
_owner = owner;
|
||||
m_OwnerId = owner.Id;
|
||||
_ownerId = owner.Id;
|
||||
}
|
||||
|
||||
Refresh();
|
||||
@@ -57,7 +57,7 @@ namespace SepCore.HPBar
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_owner != null && Owner.Available && Owner.Id == m_OwnerId)
|
||||
if (_owner != null && Owner.Available && Owner.Id == _ownerId)
|
||||
{
|
||||
Vector3 worldPosition = _owner.CachedTransform.position + Vector3.forward;
|
||||
Vector3 screenPosition = GameEntry.Scene.MainCamera.WorldToScreenPoint(worldPosition);
|
||||
@@ -78,7 +78,7 @@ namespace SepCore.HPBar
|
||||
{
|
||||
StopAllCoroutines();
|
||||
_cachedCanvasGroup.alpha = 1f;
|
||||
_hPBar.value = 1f;
|
||||
_hpBar.value = 1f;
|
||||
_owner = null;
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
@@ -86,23 +86,12 @@ namespace SepCore.HPBar
|
||||
private void Awake()
|
||||
{
|
||||
_cachedTransform = GetComponent<RectTransform>();
|
||||
if (_cachedTransform == null)
|
||||
{
|
||||
Log.Error("RectTransform is invalid.");
|
||||
return;
|
||||
}
|
||||
|
||||
_cachedCanvasGroup = GetComponent<CanvasGroup>();
|
||||
if (_cachedCanvasGroup == null)
|
||||
{
|
||||
Log.Error("CanvasGroup is invalid.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator HPBarCo(float value, float animationDuration, float keepDuration, float fadeOutDuration)
|
||||
{
|
||||
yield return _hPBar.SmoothValue(value, animationDuration);
|
||||
yield return _hpBar.SmoothValue(value, animationDuration);
|
||||
yield return new WaitForSeconds(keepDuration);
|
||||
yield return _cachedCanvasGroup.FadeToAlpha(0f, fadeOutDuration);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user