|
|
@ -14,23 +14,23 @@ namespace D2D.Gameplay
|
|
|
|
[Header("Hit Flash")]
|
|
|
|
[Header("Hit Flash")]
|
|
|
|
[SerializeField] private Gradient gradient;
|
|
|
|
[SerializeField] private Gradient gradient;
|
|
|
|
private Color originalColor;
|
|
|
|
private Color originalColor;
|
|
|
|
|
|
|
|
|
|
|
|
[SerializeField] private float _maxPoints;
|
|
|
|
[SerializeField] private float _maxPoints;
|
|
|
|
[SerializeField] private HealthData _healthData;
|
|
|
|
[SerializeField] private HealthData _healthData;
|
|
|
|
[SerializeField] private SkinnedMeshRenderer _meshRenderer;
|
|
|
|
[SerializeField] private SkinnedMeshRenderer _meshRenderer;
|
|
|
|
|
|
|
|
|
|
|
|
[SerializeField] private GameObject _hitEffect;
|
|
|
|
[SerializeField] private GameObject _hitEffect;
|
|
|
|
[SerializeField] private GameObject _deathEffect;
|
|
|
|
[SerializeField] private GameObject _deathEffect;
|
|
|
|
|
|
|
|
|
|
|
|
[SerializeField] private bool _isGrayFadeout;
|
|
|
|
[SerializeField] private bool _isGrayFadeout;
|
|
|
|
[SerializeField] private bool _isPlayer;
|
|
|
|
[SerializeField] private bool _isPlayer;
|
|
|
|
|
|
|
|
|
|
|
|
public event Action Died;
|
|
|
|
public event Action Died;
|
|
|
|
public event Action<float> Damaged;
|
|
|
|
public event Action<float> Damaged;
|
|
|
|
public event Action PointsChanged;
|
|
|
|
public event Action PointsChanged;
|
|
|
|
|
|
|
|
|
|
|
|
private Tween flashTween;
|
|
|
|
private Tween flashTween;
|
|
|
|
|
|
|
|
|
|
|
|
public GameObject LastAttacker { get; private set; }
|
|
|
|
public GameObject LastAttacker { get; private set; }
|
|
|
|
|
|
|
|
|
|
|
|
private void OnEnable()
|
|
|
|
private void OnEnable()
|
|
|
@ -59,11 +59,11 @@ namespace D2D.Gameplay
|
|
|
|
private set => _maxPoints = value;
|
|
|
|
private set => _maxPoints = value;
|
|
|
|
get
|
|
|
|
get
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!isHealthDataMode)
|
|
|
|
if (!isHealthDataMode)
|
|
|
|
return _maxPoints;
|
|
|
|
return _maxPoints;
|
|
|
|
|
|
|
|
|
|
|
|
// If health data:
|
|
|
|
// If health data:
|
|
|
|
|
|
|
|
|
|
|
|
if (_healthData == null)
|
|
|
|
if (_healthData == null)
|
|
|
|
throw new Exception("Health data is not attached!");
|
|
|
|
throw new Exception("Health data is not attached!");
|
|
|
|
|
|
|
|
|
|
|
@ -132,7 +132,7 @@ namespace D2D.Gameplay
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
InitiateDeathSequence();
|
|
|
|
InitiateDeathSequence();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -155,7 +155,7 @@ namespace D2D.Gameplay
|
|
|
|
InitiateDeathSequence();
|
|
|
|
InitiateDeathSequence();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
IEnumerator DeathCoroutine()
|
|
|
|
IEnumerator DeathCoroutine()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
yield return new WaitForSeconds(6f);
|
|
|
|
yield return new WaitForSeconds(6f);
|
|
|
@ -167,9 +167,14 @@ namespace D2D.Gameplay
|
|
|
|
private void InitiateDeathSequence()
|
|
|
|
private void InitiateDeathSequence()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Died?.Invoke();
|
|
|
|
Died?.Invoke();
|
|
|
|
if(!_isPlayer)
|
|
|
|
if (!_isPlayer)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_enemySpawn.EnemyDeathAudio.Play();
|
|
|
|
float pitch = UnityEngine.Random.Range(0.8f, 1.2f);
|
|
|
|
|
|
|
|
if (_enemySpawn.EnemyDeathAudio != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_enemySpawn.EnemyDeathAudio.pitch = pitch;
|
|
|
|
|
|
|
|
_enemySpawn.EnemyDeathAudio.Play();
|
|
|
|
|
|
|
|
}
|
|
|
|
HapticPatterns.PlayPreset(HapticPatterns.PresetType.MediumImpact);
|
|
|
|
HapticPatterns.PlayPreset(HapticPatterns.PresetType.MediumImpact);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (_isGrayFadeout)
|
|
|
|
if (_isGrayFadeout)
|
|
|
@ -181,13 +186,13 @@ namespace D2D.Gameplay
|
|
|
|
ImmediateDeath();
|
|
|
|
ImmediateDeath();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void ImmediateDeath()
|
|
|
|
private void ImmediateDeath()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Spawn(_deathEffect);
|
|
|
|
Spawn(_deathEffect);
|
|
|
|
Destroy(gameObject);
|
|
|
|
Destroy(gameObject);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void GrayFadeoutDeath()
|
|
|
|
private void GrayFadeoutDeath()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
this.ChildrenGets<MeshRenderer>(renderer =>
|
|
|
|
this.ChildrenGets<MeshRenderer>(renderer =>
|
|
|
@ -205,13 +210,13 @@ namespace D2D.Gameplay
|
|
|
|
material.DOColor(_gameData.grayDeathColor, _gameData.grayDeathDuration);
|
|
|
|
material.DOColor(_gameData.grayDeathColor, _gameData.grayDeathDuration);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
_gameData.grayCorpseLifetime.AfterCall(() => transform.DOScale(0, .3f).onComplete += ImmediateDeath);
|
|
|
|
_gameData.grayCorpseLifetime.AfterCall(() => transform.DOScale(0, .3f).onComplete += ImmediateDeath);
|
|
|
|
|
|
|
|
|
|
|
|
/*var rb = this.Get<Rigidbody>();
|
|
|
|
/*var rb = this.Get<Rigidbody>();
|
|
|
|
rb.isKinematic = false;
|
|
|
|
rb.isKinematic = false;
|
|
|
|
rb.freezeRotation = false;*/
|
|
|
|
rb.freezeRotation = false;*/
|
|
|
|
|
|
|
|
|
|
|
|
/*.1f.AfterCall(() => rb.angularVelocity *= DMath.Random(1, 2f));*/
|
|
|
|
/*.1f.AfterCall(() => rb.angularVelocity *= DMath.Random(1, 2f));*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -219,8 +224,8 @@ namespace D2D.Gameplay
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (prefab == null)
|
|
|
|
if (prefab == null)
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
GameObject instance = Instantiate(prefab, transform.position,
|
|
|
|
GameObject instance = Instantiate(prefab, transform.position,
|
|
|
|
transform.rotation, null);
|
|
|
|
transform.rotation, null);
|
|
|
|
|
|
|
|
|
|
|
|
Destroy(instance, 2f);
|
|
|
|
Destroy(instance, 2f);
|
|
|
@ -231,7 +236,7 @@ namespace D2D.Gameplay
|
|
|
|
if (healPoints <= 0)
|
|
|
|
if (healPoints <= 0)
|
|
|
|
throw new Exception("Heal points should be positive!");
|
|
|
|
throw new Exception("Heal points should be positive!");
|
|
|
|
|
|
|
|
|
|
|
|
CurrentPoints = Math.Min(CurrentPoints+healPoints, _maxPoints);
|
|
|
|
CurrentPoints = Math.Min(CurrentPoints + healPoints, _maxPoints);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void SetMaxPoints(float newMaxPoints, bool needRefill = false)
|
|
|
|
public void SetMaxPoints(float newMaxPoints, bool needRefill = false)
|
|
|
@ -240,7 +245,7 @@ namespace D2D.Gameplay
|
|
|
|
throw new Exception("Max points should be positive!");
|
|
|
|
throw new Exception("Max points should be positive!");
|
|
|
|
|
|
|
|
|
|
|
|
MaxPoints = newMaxPoints;
|
|
|
|
MaxPoints = newMaxPoints;
|
|
|
|
|
|
|
|
|
|
|
|
if (needRefill)
|
|
|
|
if (needRefill)
|
|
|
|
CurrentPoints = MaxPoints;
|
|
|
|
CurrentPoints = MaxPoints;
|
|
|
|
}
|
|
|
|
}
|
|
|
|