少年修仙传客户端代码仓库
client_Hale
2019-04-15 7b2e8fc55e50b9f1f94364426e71288b32edd15f
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class ClientDropItemUtility : Singleton<ClientDropItemUtility>
{
    public static UnityEngine.Events.UnityAction<int> OnItemPickup;
    private const float OFFSET = 1;
    private int m_TotalDropCount;
    private int m_DropedCount;
    private Vector3 m_DropPos;
    private Vector3 m_Dir;
    private List<int> m_IndexList = new List<int>();
 
    private List<DropItem> m_DropItemList = new List<DropItem>();
 
    public void Update()
    {
        var _hero = PlayerDatas.Instance.hero;
        if (_hero == null)
        {
            return;
        }
 
        float _dis;
        DropItem _item;
        for (int i = m_DropItemList.Count - 1; i >= 0; --i)
        {
            _item = m_DropItemList[i];
            _dis = MathUtility.DistanceSqrtXZ(_item.transform.position, _hero.Pos);
            if (_dis < .25f)
            {
                if (OnItemPickup != null)
                {
                    OnItemPickup(_item.itemId);
                }
 
                Release(_item);
            }
        }
    }
 
    public void ReleaseAll()
    {
        for (int i = m_DropItemList.Count - 1; i >= 0; --i)
        {
            Release(m_DropItemList[i]);
        }
    }
 
    public void Release(DropItem item)
    {
        DropItem.Reycle(item);
        m_DropItemList.Remove(item);
    }
 
    public void Drop(Vector3 center, int[] itemIds)
    {
        if (itemIds == null || itemIds.Length == 0)
        {
            return;
        }
 
        RaycastHit _hit;
        if (!Physics.Raycast(center + new Vector3(0, 50, 0),
                             Vector3.down,
                             out _hit,
                             80,
                             LayerUtility.WalkbleMask))
        {
            return;
        }
 
        m_IndexList.Clear();
        m_DropPos = center;
        m_DropedCount = 0;
        m_TotalDropCount = itemIds.Length;
        m_Dir = Vector3.forward;
 
        DropItem _item = DropItem.Drop(itemIds[m_DropedCount],
                         _hit.point,
                         CameraController.Instance.CameraObject);
        m_DropItemList.Add(_item);
        m_DropedCount += 1;
 
        int _x = Mathf.CeilToInt(m_DropPos.x * 100000);
        int _z = Mathf.CeilToInt(m_DropPos.z * 10);
        m_IndexList.Add(_x + _z);
 
        DropNext(itemIds);
    }
 
    public void DropNext(int[] itemIds)
    {
        if (m_DropedCount < m_TotalDropCount)
        {
            var _nextDir = MathUtility.Rotate90_XZ_CW(m_Dir);
            var _nextPos = m_DropPos + _nextDir * OFFSET;
            int _x = Mathf.CeilToInt(_nextPos.x * 100000);
            int _z = Mathf.CeilToInt(_nextPos.z * 10);
            int _index = _x + _z;
 
            if (m_IndexList.Contains(_index))
            {
                m_DropPos = m_DropPos + m_Dir * OFFSET;
 
                _x = Mathf.CeilToInt(m_DropPos.x * 100000);
                _z = Mathf.CeilToInt(m_DropPos.z * 10);
                _index = _x + _z;
            }
            else
            {
                m_Dir = _nextDir;
                m_DropPos = _nextPos;
            }
 
            m_IndexList.Add(_index);
 
            RaycastHit _hit;
            if (Physics.Raycast(m_DropPos + new Vector3(0, 50, 0),
                                 Vector3.down,
                                 out _hit,
                                 80,
                                 LayerUtility.WalkbleMask))
            {
                DropItem _item = DropItem.Drop(itemIds[m_DropedCount],
                                 _hit.point,
                                 CameraController.Instance.CameraObject);
                m_DropItemList.Add(_item);
                m_DropedCount += 1;
            }
 
            DropNext(itemIds);
        }
    }
}