少年修仙传客户端代码仓库
client_linchunjie
2018-10-18 f93c57bfd57f97e78c3a00a29f302f5e8c83cdee
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
//--------------------------------------------------------
//   [Author]:           第二世界
//   [  Date ]:           Friday, September 22, 2017
//--------------------------------------------------------
using UnityEngine;
using TableConfig;
using System.Collections.Generic;
 
namespace Snxxz.UI
{
 
    public class UI3DShowHero
    {
        int weaponId;
        int clothesId;
        int wingsId;
        int secondaryId;
        int job;
 
        GameObject weaponModel;
        GameObject clothesModel;
        GameObject wingsModel;
        GameObject secondaryModel;
        Animator wingsAnimator;
        Animator clothesAnimator;
        RuntimeAnimatorController cacheClothedAC;
 
        Transform showPoint;
        List<SFXController> closthesSFXList = new List<SFXController>();
 
        public GameObject Show(int _job, int _clothes, int suitID, int _weaponId, int _wingsId, int _secondaryId, Transform _showPoint)
        {
            showPoint = _showPoint;
            job = _job;
            PutOnClothes(_job, _clothes, suitID);
            PutOnWeapon(_job, _weaponId);
            PutOnSecondary(_job, _secondaryId);
            PutOnWing(_wingsId);
 
            return clothesModel;
        }
 
        public void Dispose()
        {
            GameObject prefab = null;
            GameObjectPoolManager.GameObjectPool pool = null;
 
            if (weaponId != 0)
            {
                prefab = InstanceResourcesLoader.LoadModelRes(weaponId, true);
                if (prefab)
                {
                    pool = GameObjectPoolManager.Instance.RequestPool(prefab);
                    pool.Release(weaponModel);
                }
                weaponModel = null;
            }
 
            if (secondaryId != 0)
            {
                prefab = InstanceResourcesLoader.LoadModelRes(secondaryId, true);
                if (prefab)
                {
                    if (secondaryModel)
                    {
                        secondaryModel.SetActive(true);
                    }
                    pool = GameObjectPoolManager.Instance.RequestPool(prefab);
                    pool.Release(secondaryModel);
                }
                secondaryModel = null;
            }
 
            if (wingsId != 0)
            {
                prefab = InstanceResourcesLoader.LoadModelRes(wingsId, true);
                if (prefab)
                {
                    pool = GameObjectPoolManager.Instance.RequestPool(prefab);
                    pool.Release(wingsModel);
                }
                wingsModel = null;
                wingsAnimator = null;
            }
 
            if (clothesId != 0)
            {
                prefab = InstanceResourcesLoader.LoadModelRes(clothesId, true);
                if (prefab)
                {
                    pool = GameObjectPoolManager.Instance.RequestPool(prefab);
                    pool.Release(clothesModel);
                }
                clothesModel = null;
                if (clothesAnimator)
                {
                    if (cacheClothedAC)
                    {
                        clothesAnimator.runtimeAnimatorController = cacheClothedAC;
                        cacheClothedAC = null;
                    }
                    clothesAnimator = null;
                }
            }
 
            clothesId = 0;
            weaponId = 0;
            wingsId = 0;
            secondaryId = 0;
 
            UnloadClothedEffect();
        }
 
        public void StandUp()
        {
            if (clothesModel != null)
            {
                var animator = clothesModel.GetComponent<Animator>();
                if (animator)
                {
                    animator.Play(GAStaticDefine.State_IdleHash);
                }
            }
        }
 
        public void SitDown()
        {
            if (clothesModel != null)
            {
                var animator = clothesModel.GetComponent<Animator>();
                if (animator)
                {
                    animator.Play(GAStaticDefine.State_SitDown);
                }
            }
 
            if (weaponModel)
            {
                GameObject prefab = InstanceResourcesLoader.LoadModelRes(weaponId, true);
                if (prefab)
                {
                    GameObjectPoolManager.Instance.ReleaseGameObject(prefab, weaponModel);
                }
                weaponModel = null;
            }
 
            if (job == 2)
            {
                if (secondaryModel)
                {
                    secondaryModel.SetActive(false);
                }
            }
        }
 
        public void PutOnClothes(int _job, int itemID, int suitID)
        {
            var newClothes = 0;
            var config = Config.Instance.Get<JobSetupConfig>(_job);
 
            if (itemID == 0)
            {
                newClothes = config.BaseEquip[0];
            }
            else
            {
                var item = Config.Instance.Get<ItemConfig>(itemID);
                newClothes = item == null ? newClothes = config.BaseEquip[0] : item.ChangeOrd;
            }
 
            var oldClothes = clothesId;
            if (oldClothes == newClothes)
            {
                return;
            }
 
            if (oldClothes != 0)
            {
                UnloadClothes();
            }
 
            var _prefab = InstanceResourcesLoader.LoadModelRes(newClothes, true);
            if (!_prefab)
            {
                newClothes = config.BaseEquip[0];
            }
 
            LoadClothes(newClothes);
            clothesId = newClothes;
 
            if (clothesModel)
            {
                if (weaponModel)
                {
                    var parent = clothesModel.transform.GetChildTransformDeeply(GAStaticDefine.WeaponBindBoneName);
                    weaponModel.transform.SetParentEx(parent, Vector3.zero, Quaternion.identity, Vector3.one);
                }
 
                if (wingsModel)
                {
                    var parent = clothesModel.transform.GetChildTransformDeeply(GAStaticDefine.WingBindBoneName);
                    wingsModel.transform.SetParentEx(parent, Vector3.zero, Quaternion.identity, Vector3.one);
                }
 
                if (secondaryModel)
                {
                    var parent = clothesModel.transform.GetChildTransformDeeply(GAStaticDefine.SecondaryBindBoneName[job - 1]);
                    wingsModel.transform.SetParentEx(parent, Vector3.zero, Quaternion.identity, Vector3.one);
                }
 
                LoadClothesEffect(itemID, suitID);
            }
        }
 
        private void LoadClothes(int resID)
        {
            var prefab = InstanceResourcesLoader.LoadModelRes(resID, true);
            if (prefab)
            {
                var pool = GameObjectPoolManager.Instance.RequestPool(prefab);
                clothesModel = pool.Request();
 
                LayerUtility.SetLayer(clothesModel, LayerUtility.Player, false);
                var skinnedMeshRenderer = clothesModel.GetComponentInChildren<SkinnedMeshRenderer>(true);
                LayerUtility.SetLayer(skinnedMeshRenderer.gameObject, LayerUtility.Player, false);
                clothesModel.SetActive(true);
                clothesModel.transform.SetParentEx(showPoint, Vector3.zero, Quaternion.identity, Vector3.one);
                clothesAnimator = clothesModel.GetComponent<Animator>();
 
                // 动画状态机修改
                if (clothesAnimator)
                {
                    cacheClothedAC = clothesAnimator.runtimeAnimatorController;
                    RuntimeAnimatorController _controller = AnimatorControllerLoader.Load(AnimatorControllerLoader.controllerUISuffix, resID);
                    clothesAnimator.runtimeAnimatorController = _controller;
                    clothesAnimator.enabled = true;
                }
                else
                {
                    DebugEx.LogErrorFormat("角色资源: {0} 没有动画控制器", resID);
                }
            }
        }
 
        private void UnloadClothes()
        {
            if (clothesModel == null)
            {
                return;
            }
 
            var prefab = InstanceResourcesLoader.LoadModelRes(clothesId, true);
            var pool = GameObjectPoolManager.Instance.RequestPool(prefab);
            pool.Release(clothesModel);
            clothesModel = null;
            if (clothesAnimator != null)
            {
                if (cacheClothedAC)
                {
                    clothesAnimator.runtimeAnimatorController = cacheClothedAC;
                    cacheClothedAC = null;
                }
                clothesAnimator.enabled = false;
                clothesAnimator = null;
            }
        }
 
        public void PutOnWeapon(int _job, int itemID)
        {
            var newWeapon = 0;
            var config = Config.Instance.Get<JobSetupConfig>(_job);
 
            if (itemID == 0)
            {
                newWeapon = config.BaseEquip[1];
            }
            else
            {
                var item = Config.Instance.Get<ItemConfig>(itemID);
                newWeapon = item == null ? config.BaseEquip[1] : item.ChangeOrd;
            }
 
            var oldWeapon = weaponId;
            if (oldWeapon == newWeapon)
            {
                return;
            }
 
            GameObject prefab = null;
            GameObjectPoolManager.GameObjectPool pool = null;
 
            if (oldWeapon != 0)
            {
                prefab = InstanceResourcesLoader.LoadModelRes(oldWeapon, true);
                pool = GameObjectPoolManager.Instance.RequestPool(prefab);
                pool.Release(weaponModel);
                weaponModel = null;
            }
 
            prefab = InstanceResourcesLoader.LoadModelRes(newWeapon, true);
 
            if (!prefab)
            {
                newWeapon = config.BaseEquip[1];
                prefab = InstanceResourcesLoader.LoadModelRes(newWeapon, true);
            }
 
            if (prefab)
            {
                pool = GameObjectPoolManager.Instance.RequestPool(prefab);
                weaponModel = pool.Request();
 
                LayerUtility.SetLayer(weaponModel, LayerUtility.Player, false);
                if (clothesModel)
                {
                    var parent = clothesModel.transform.GetChildTransformDeeply(GAStaticDefine.WeaponBindBoneName);
                    weaponModel.transform.SetParentEx(parent, Vector3.zero, Quaternion.identity, Vector3.one);
                }
            }
 
            weaponId = newWeapon;
        }
 
        public void PutOnSecondary(int _job, int itemID)
        {
            var newSecondary = 0;
            var config = Config.Instance.Get<JobSetupConfig>(_job);
 
            if (itemID == 0)
            {
                if (job == 1)
                {
                    // 这里不再读取默认的副手装备,而是根据套装读取默认的手臂装备
                    newSecondary = clothesId + 2900;
                }
                else
                {
                    newSecondary = config.BaseEquip[2];
                }
            }
            else
            {
                var item = Config.Instance.Get<ItemConfig>(itemID);
                newSecondary = item == null ? config.BaseEquip[2] : item.ChangeOrd;
            }
 
            var oldSecondary = secondaryId;
            if (oldSecondary == newSecondary)
            {
                return;
            }
 
            GameObject prefab = null;
            GameObjectPoolManager.GameObjectPool pool = null;
 
            if (oldSecondary != 0)
            {
                prefab = InstanceResourcesLoader.LoadModelRes(oldSecondary, true);
                pool = GameObjectPoolManager.Instance.RequestPool(prefab);
                pool.Release(secondaryModel);
                secondaryModel = null;
            }
 
            if (newSecondary != 0)
            {
                prefab = InstanceResourcesLoader.LoadModelRes(newSecondary, true);
                if (!prefab)
                {
                    newSecondary = config.BaseEquip[2];
                    prefab = InstanceResourcesLoader.LoadModelRes(newSecondary, true);
                }
 
                if (prefab)
                {
                    pool = GameObjectPoolManager.Instance.RequestPool(prefab);
                    secondaryModel = pool.Request();
 
                    var parent = clothesModel.transform.GetChildTransformDeeply(GAStaticDefine.SecondaryBindBoneName[job - 1]);
                    secondaryModel.transform.SetParentEx(parent, Vector3.zero, Quaternion.identity, Vector3.one);
                }
            }
 
            secondaryId = newSecondary;
        }
 
        public void PutOnWing(int itemID)
        {
            var newWings = 0;
            if (itemID != 0)
            {
                var item = Config.Instance.Get<ItemConfig>(itemID);
                newWings = item == null ? 0 : item.ChangeOrd;
            }
 
            var config = Config.Instance.Get<JobSetupConfig>(job);
 
            var oldWings = wingsId;
            if (newWings == oldWings)
            {
                return;
            }
 
            GameObject prefab = null;
            GameObjectPoolManager.GameObjectPool pool = null;
 
            if (oldWings != 0)
            {
                prefab = InstanceResourcesLoader.LoadModelRes(oldWings, true);
                pool = GameObjectPoolManager.Instance.RequestPool(prefab);
                pool.Release(wingsModel);
                wingsModel = null;
            }
 
            if (newWings != 0)
            {
                prefab = InstanceResourcesLoader.LoadModelRes(newWings, true);
 
                if (!prefab)
                {
                    newWings = config.BaseEquip[3];
                    prefab = InstanceResourcesLoader.LoadModelRes(newWings, true);
                }
 
                if (prefab)
                {
                    pool = GameObjectPoolManager.Instance.RequestPool(prefab);
                    wingsModel = pool.Request();
 
                    wingsModel.layer = LayerUtility.Player;
                    SkinnedMeshRenderer _renderer = wingsModel.GetComponentInChildren<SkinnedMeshRenderer>();
                    if (_renderer)
                    {
                        _renderer.gameObject.layer = LayerUtility.Player;
                    }
 
                    var parent = clothesModel.transform.GetChildTransformDeeply(GAStaticDefine.WingBindBoneName);
                    wingsModel.transform.SetParentEx(parent, Vector3.zero, Quaternion.identity, Vector3.one);
 
                    wingsAnimator = wingsModel.GetComponent<Animator>();
                    if (wingsAnimator == null)
                    {
                        DebugEx.LogErrorFormat("翅膀资源{0}没有动画控制器", itemID);
                    }
                    wingsAnimator.enabled = true;
                    wingsAnimator.Play("UI_Idle", 0);
                }
            }
 
            wingsId = newWings;
        }
 
        private PlayerSuitModel SuitModel { get { return ModelCenter.Instance.GetModel<PlayerSuitModel>(); } }
        private PlayerPackModel PlayerBackModel { get { return ModelCenter.Instance.GetModel<PlayerPackModel>(); } }
 
        public void LoadClothesEffect(int clothedID, int suitLevel)
        {
            UnloadClothedEffect();
 
            var _equipModel = PlayerBackModel.GetSinglePackModel(PackType.rptEquip);
            if (_equipModel == null)
            {
                if (DTC0309_tagPlayerLoginInfo.equipSuitID > 0)
                {
                    PutOnEffect(DTC0309_tagPlayerLoginInfo.equipSuitID);
                }
                return;
            }
 
            int _suitCount = 0;
 
            int _start = (int)RoleEquipType.retHat;
            int _end = (int)RoleEquipType.retShoes;
 
            ItemModel _itemModel = null;
 
            _itemModel = _equipModel.GetItemModelByIndex((int)RoleEquipType.retClothes);
 
            if (_itemModel == null)
            {
                return;
            }
 
            int _rank = _itemModel.chinItemModel.LV;
 
            for (int i = _start; i <= _end; ++i)
            {
                _itemModel = _equipModel.GetItemModelByIndex(i);
 
                if (_itemModel == null)
                {
                    continue;
                }
 
                if (_itemModel.chinItemModel.SuiteiD <= 0)
                {
                    continue;
                }
 
                if (i == (int)RoleEquipType.retClothes)
                {
                    _rank = _itemModel.chinItemModel.LV;
                }
 
                if (SuitModel.suitModelDict.ContainsKey(i))
                {
                    if (SuitModel.suitModelDict[i].ContainsKey(1)
                     || SuitModel.suitModelDict[i].ContainsKey(2))
                    {
                        if (_itemModel.chinItemModel.LV >= _rank)
                        {
                            _suitCount += 1;
                        }
                    }
                }
            }
 
            if (_suitCount == 5)
            {
                int _type = 1;
 
                int _suitEffectID = _type * 1000 + job * 100 + _rank;
 
                PutOnEffect(_suitEffectID);
            }
        }
 
        public void PutOnEffect(int id)
        {
            SuitEffectConfig _suitEffect = Config.Instance.Get<SuitEffectConfig>(id);
 
            // 上特效
            if (_suitEffect != null)
            {
                Transform _parent = null;
                SFXController _sfx = null;
                for (int i = 0; _suitEffect.bindbones != null && i < _suitEffect.bindbones.Length; ++i)
                {
                    if (string.IsNullOrEmpty(_suitEffect.bindbones[i])
                        || _suitEffect.effectIds[i] == 0)
                    {
                        continue;
                    }
 
                    _parent = clothesModel.transform.GetChildTransformDeeply(_suitEffect.bindbones[i]);
 
                    if (_parent == null)
                    {
                        Debug.LogErrorFormat("套装: {0} 配置的骨骼节点: {1} 不存在", id, _suitEffect.bindbones[i]);
                        continue;
                    }
 
                    _sfx = SFXPlayUtility.Instance.PlayBattleEffect(_suitEffect.effectIds[i], _parent);
                    closthesSFXList.Add(_sfx);
                }
            }
        }
 
        public void UnloadClothedEffect()
        {
            for (int i = 0; i < closthesSFXList.Count; ++i)
            {
                SFXPlayUtility.Instance.Release(closthesSFXList[i]);
            }
            closthesSFXList.Clear();
        }
    }
 
}