少年修仙传客户端代码仓库
hch
2025-01-08 dbb7a55e47da81a8c7c2b4bff7e053ff36af3d5a
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
using vnxbqy.UI;
using System;
using System.Collections.Generic;
using UnityEngine;
public class GuardPickupItem : MonoBehaviour
{
    public GA_Guard guard;
 
    List<SFXController> m_SFXControllers = new List<SFXController>();
 
    GuardModel model { get { return ModelCenter.Instance.GetModel<GuardModel>(); } }
 
    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.pickEffectIds[2], list[i], guard.Root.position - list[i]);
            if (fx != null)
            {
                fx.duration = 0;
                m_SFXControllers.Add(fx);
            }
        }
    }
 
    private void LateUpdate()
    {
        if (guard == null || !guard.IsStateActive)
        {
            return;
        }
        for (int i = 0; i < m_SFXControllers.Count; i++)
        {
            if (m_SFXControllers[i] == null)
            {
                m_SFXControllers.RemoveAt(i);
                i--;
                continue;
            }
            Transform tr = m_SFXControllers[i].gameObject.transform;
            var dis = Vector3.Distance(tr.position, guard.Root.position);
            var duration = dis / (model.pickUpSfxSpeed == 0f ? 4f : model.pickUpSfxSpeed);
            if (duration > Time.deltaTime)
            {
                tr.position = Vector3.MoveTowards(tr.position, guard.Root.position, Time.deltaTime * model.pickUpSfxSpeed);
            }
            else
            {
                tr.position = guard.Root.position;
                SFXPlayUtility.Instance.Release(m_SFXControllers[i]);
                m_SFXControllers.RemoveAt(i);
                i--;
            }
        }
    }
 
    private void OnDisable()
    {
        DropItemManager.guardPickupCallBack -= GuardPickupCallBack;
        ReleaseSfx();
    }
 
    public void ReleaseSfx()
    {
        for (int i = 0; i < m_SFXControllers.Count; i++)
        {
            if (m_SFXControllers[i] == null)
            {
                m_SFXControllers.RemoveAt(i);
                i--;
                continue;
            }
            SFXPlayUtility.Instance.Release(m_SFXControllers[i]);
            m_SFXControllers.RemoveAt(i);
            i--;
        }
    }
}