wangguan
2020-10-27 1cc976d33bfbe7488c85df9d35f28aa6e4360294
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
using Core.Health;
using Core.Utilities;
using System.Collections;
using System.Collections.Generic;
using TowerDefense.Agents;
using UnityEngine;
 
public class AgentRegenEffect : AgentEffect
{
    protected GameObject m_RegenFx;
 
    /// <summary>
    /// Initializes the slower with the parameters configured in the SlowAffector
    /// </summary>
    /// <param name="slowFactor">Normalized float that represents the % slowdown applied to the agent</param>
    /// <param name="slowfxPrefab">The instantiated object to visualize the slow effect</param>
    /// <param name="position"></param>
    /// <param name="scale"></param>
    public void Initialize( GameObject slowfxPrefab = null,
                           Vector3 position = default(Vector3),
                           float scale = 1)
    {
        LazyLoad();
 
        if (m_RegenFx == null && slowfxPrefab != null)
        {
            m_RegenFx = Poolable.TryGetPoolable(slowfxPrefab);
            m_RegenFx.transform.parent = transform;
            m_RegenFx.transform.localPosition = position;
            m_RegenFx.transform.localScale *= scale;
        }
 
        m_Agent.removed += OnRemoved;
    }
 
    /// <summary>
    /// Agent has died, remove affect
    /// </summary>
    void OnRemoved( DamageableBehaviour targetable)
    {
        m_Agent.removed -= OnRemoved;
        ResetAgent();
    }
 
    void ResetAgent()
    {
        if ( m_RegenFx != null)
        {
            Poolable.TryPool(m_RegenFx);
            m_RegenFx.transform.localScale = Vector3.one;
            m_RegenFx = null;
        }
        Destroy(this);
    }
}