-
Notifications
You must be signed in to change notification settings - Fork 0
/
AbilityBehavior.cs
63 lines (50 loc) · 2.04 KB
/
AbilityBehavior.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System.Collections;
using UnityEngine;
namespace RPG.Personagem
{
public abstract class AbilityBehavior : MonoBehaviour
{
protected AbilityConfig config;
const float PARTICLE_DELAY = 10f;
const string DEFAULT_ATTACK = "DEFAULT ATTACK";
const string ATTACK_TRIGGER = "Attack";
public abstract void Use(GameObject target = null);
public void SetConfig(AbilityConfig configToSet)
{
config = configToSet;
}
protected void PlayParticleEffect()
{
var particlePrefab = config.GetParticlePrefab();
var particleObject = Instantiate(particlePrefab,
transform.position,
particlePrefab.transform.rotation);
particleObject.transform.parent = transform;
particleObject.GetComponent<ParticleSystem>().Play();
StartCoroutine(DestroyParticleWhenFinished(particleObject));
}
IEnumerator DestroyParticleWhenFinished(GameObject particlePrefab)
{
while (particlePrefab.GetComponent<ParticleSystem>().isPlaying)
{
yield return new WaitForSeconds(PARTICLE_DELAY);
}
Destroy(particlePrefab);
yield return new WaitForEndOfFrame();
}
protected void PlaySpecialAbilityAudio()
{
var abilitySound = config.GetAudioClip();
var audioSource = GetComponent<AudioSource>();
audioSource.PlayOneShot(abilitySound);
}
protected void PlayAnimationClip()
{
var animatorOverrideController = GetComponent<Character>().GetOverrideController();
var animator = GetComponent<Animator>();
animator.runtimeAnimatorController = animatorOverrideController;
animatorOverrideController[DEFAULT_ATTACK] = config.GetAnimationClip();
animator.SetTrigger(ATTACK_TRIGGER);
}
}
}