少年修仙传客户端代码仓库
client_linchunjie
2018-09-14 a0ede150686a218c92b901b1f20aef12a9913890
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
using System;
using System.Collections.Generic;
using UnityEngine;
public class GuardPickupItem : MonoBehaviour
{
    public GA_Guard guard;
 
    public List<SFXController> sfxCtrlList = new List<SFXController>();
 
    private void OnEnable()
    {
        DropItemManager.guardPickupCallBack += GuardPickupCallBack;
    }
 
    private void GuardPickupCallBack(List<Vector3> list)
    {
        if (guard == null || !guard.IsStateActive)
        {
            return;
        }
        for (int i = 0; i < list.Count; i++)
        {
            var fx = SFXPlayUtility.Instance.PlayBattleEffect(guard.guardEffects[2], list[i], guard.Root.position - list[i]);
            if (fx != null)
            {
                fx.duration = 0;
                sfxCtrlList.Add(fx);
            }
        }
    }
 
    private void LateUpdate()
    {
        if (guard == null || !guard.IsStateActive)
        {
            return;
        }
        for (int i = 0; i < sfxCtrlList.Count; i++)
        {
            if (sfxCtrlList[i] == null)
            {
                sfxCtrlList.RemoveAt(i);
                i--;
                continue;
            }
            Transform tr = sfxCtrlList[i].gameObject.transform;
            var dis = Vector3.Distance(tr.position, guard.Root.position);
            if (guard.GuardianPickFxSpeed == 0)
            {
                guard.GuardianPickFxSpeed = 4.0f;
            }
            var duration = dis / guard.GuardianPickFxSpeed;
            if (duration > Time.deltaTime)
            {
                tr.position = Vector3.MoveTowards(tr.position, guard.Root.position, Time.deltaTime * guard.GuardianPickFxSpeed);
            }
            else
            {
                tr.position = guard.Root.position;
                SFXPlayUtility.Instance.Release(sfxCtrlList[i]);
                sfxCtrlList.RemoveAt(i);
                i--;
            }
        }
    }
 
    private void OnDisable()
    {
        DropItemManager.guardPickupCallBack -= GuardPickupCallBack;
        ClearFx();
    }
 
    public void ClearFx()
    {
        for (int i = 0; i < sfxCtrlList.Count; i++)
        {
            if (sfxCtrlList[i] == null)
            {
                sfxCtrlList.RemoveAt(i);
                i--;
                continue;
            }
            SFXPlayUtility.Instance.Release(sfxCtrlList[i]);
            sfxCtrlList.RemoveAt(i);
            i--;
        }
    }
}