少年修仙传客户端代码仓库
hch
2025-03-03 28785d6ddf9c08e49527ede9405c7b6c93c6ed32
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
using UnityEngine;
 
using System.Collections;
 
public class MapArea : MonoBehaviour
{
    public enum E_Type
    {
        RebornSafe = 1,// 重生安全区域
        Safe = 2,// 安全区域
        Union = 4,// 帮会区域
        Normal = 8,// 普通区域
        Neutral = 16,// 中立区域(自由PK) 主动切换为强制
        Alliance = 32,// 同盟区域
        Dazuo = 64,// 打坐区域
        Boss = 128,
    }
 
    public Vector3 startPosition;
    public Vector3 endPosition;
 
    int _type;
 
    int m_MapID;
    int m_AreaID;
 
    bool m_IsHeroInside;
 
    public static MapArea CreateMapArea(mapAreaConfig config)
    {
        GameObject _go = new GameObject();
        BoxCollider _collider = _go.AddComponent<BoxCollider>();
        _go.layer = LayerUtility.MapTrigger;
#if UNITY_EDITOR
        _go.name = "MapArea_" + config.AreaID;
#endif
        MapArea _area = _go.AddMissingComponent<MapArea>();
 
        _area.startPosition = new Vector3((config.StartPosX - GA_Hero.MapOffset.x) * .5f,
                                           0,
                                          (config.StartPosY - GA_Hero.MapOffset.z) * .5f);
        _area.endPosition = new Vector3((config.EndPosX - GA_Hero.MapOffset.x) * .5f,
                                        0,
                                        (config.EndPosY - GA_Hero.MapOffset.z) * .5f);
 
        int _width;
        int _height;
 
        if (config.StartPosX > config.EndPosX)
        {
            _width = (int)((config.StartPosX - config.EndPosX) * .5f);
        }
        else
        {
            _width = (int)((config.EndPosX - config.StartPosX) * .5f);
        }
 
        if (config.StartPosY > config.EndPosY)
        {
            _height = (int)((config.StartPosY - config.EndPosY) * .5f);
        }
        else
        {
            _height = (int)((config.EndPosY - config.StartPosY) * .5f);
        }
 
        _collider.transform.localScale = new Vector3(_width + 1, 50, _height + 1);
        _collider.isTrigger = true;
 
        Vector3 _position = (_area.endPosition + _area.startPosition) * .5f;
        float _groundHeight;
        if (CollisionUtility.TryGetGroundHeight(_position, out _groundHeight))
        {
            _position.y = _groundHeight;
        }
        _go.transform.position = _position;
        _area._type = config.AreaName;
        _area.m_MapID = config.MapID;
        _area.m_AreaID = config.AreaID;
 
        return _area;
    }
 
    private void OnTriggerEnter(Collider other)
    {
        if (GA_Hero.s_MapSwitching)
        {
            return;
        }
 
        if (_type >= 3000)
        {
            SnxxzGame.Instance.MovingCamera(false, _type);
            SnxxzGame.Instance.ResetCamera(false);
            SnxxzGame.Instance.MovingCamera(true, _type);
        }
 
        if (PlayerDatas.Instance.hero != null)
        {
            if (_type >= 3000)
            {
                PlayerDatas.Instance.hero.EnterArea((int)E_Type.Boss);
                PlayerDatas.Instance.hero.currentBossArea = this;
                //SoundPlayer.Instance.PlayBackGroundMusic(GeneralDefine.BossSound);
            }
            else
            {
                PlayerDatas.Instance.hero.EnterArea(_type);
            }
        }
    }
 
    private void OnTriggerExit(Collider other)
    {
        // if (GA_Hero.s_MapSwitching)
        // {
        //     return;
        // }
 
        if (_type >= 3000)
        {
            SnxxzGame.Instance.MovingCamera(false, _type);
            SnxxzGame.Instance.ResetCamera(true);
        }
 
        if (PlayerDatas.Instance.hero != null)
        {
            if (_type >= 3000)
            {
                PlayerDatas.Instance.hero.ExitArea((int)E_Type.Boss);
                PlayerDatas.Instance.hero.currentBossArea = null;
                //MapConfig _mapConfig = MapConfig.Get(PlayerDatas.Instance.baseData.MapID);
                //SoundPlayer.Instance.PlayBackGroundMusic(_mapConfig.Music);
            }
            else
            {
                PlayerDatas.Instance.hero.ExitArea(_type);
            }
        }
    }
 
 
#if UNITY_EDITOR
    private void OnDrawGizmos()
    {
        switch ((E_Type)_type)
        {
            case E_Type.Normal:
                Gizmos.color = Color.white;
                break;
            case E_Type.RebornSafe:
                Gizmos.color = new Color(.6f, 1, .6f);
                break;
            case E_Type.Safe:
                Gizmos.color = Color.green;
                break;
            case E_Type.Union:
                Gizmos.color = Color.blue;
                break;
            case E_Type.Neutral:
                Gizmos.color = Color.red;
                break;
            case E_Type.Alliance:
                Gizmos.color = new Color(.4f, .2f, 1);
                break;
            case E_Type.Dazuo:
                Gizmos.color = Color.yellow;
                break;
            default:
                if (_type >= 3000)
                {
                    Gizmos.color = Color.black;
                }
                break;
        }
 
 
        if (m_IsHeroInside)
        {
            Gizmos.DrawWireCube(transform.position, new Vector3(endPosition.x - startPosition.x, 10, endPosition.z - startPosition.z));
        }
        else
        {
            Gizmos.DrawWireCube(transform.position, new Vector3(endPosition.x - startPosition.x, 1, endPosition.z - startPosition.z));
        }
 
    }
#endif
 
    public static bool IsInMapArea(int types, E_Type type)
    {
        return (types & (byte)type) != 0;
    }
 
    public static bool IsOutMapArea(int types, E_Type type)
    {
        return !IsInMapArea(types, type);
    }
 
    public bool IsPosIn(Vector3 pos)
    {
        return pos.x > startPosition.x
            && pos.x < endPosition.x
            && pos.z > startPosition.z
            && pos.z < endPosition.z;
    }
 
    public bool IsPosOut(Vector3 pos)
    {
        return pos.x < startPosition.x
            || pos.x > endPosition.x
            || pos.z < startPosition.z
            || pos.z > endPosition.z;
    }
}