少年修仙传客户端代码仓库
lcy
2024-12-16 a39c35fc6449430cd02bccb681c4a0a880e46cd9
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
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
using UnityEngine.UI;
using System;
using DG.Tweening;
namespace vnxbqy.UI
{
    
    public class UI3DTreasureSelectStage : MonoBehaviour
    {
        [SerializeField] Transform m_CenterStage;
        [SerializeField] Transform m_TreasureRoot;
        [SerializeField] Camera m_Camera;
        [SerializeField] Camera m_RenderCamera;
        [SerializeField] Camera m_TreasureUICamera;
        [SerializeField] Transform m_CameraControl;
        [SerializeField] GameObject[] m_TreasureSkys;
        [SerializeField] GameObject[] m_TreasureTitles;
        [SerializeField] GameObject[] m_TreasureFogs;
        public Camera showCamera { get { return m_Camera; } }
        public Camera renderCamera { get { return m_RenderCamera; } }
        public Camera treasureUICamera { get { return m_TreasureUICamera; } }
        public Transform center
        {
            get
            {
                return m_CenterStage;
            }
        }
        public Transform treasureRoot
        {
            get
            {
                return m_TreasureRoot;
            }
        }
        [SerializeField] float m_Radius = 10.0f;
        public float radius
        {
            get
            {
                return m_Radius;
            }
        }
        [SerializeField] float m_IntervalAngle = 20.0f;
        public float intervalAngle
        {
            get
            {
                return m_IntervalAngle;
            }
        }
 
        public int forward
        {
            get
            {
                return intervalAngle > 0 ? -1 : 1;
            }
        }
        [SerializeField, Header("最大允许偏移")] float m_Offset = 30f;
        [SerializeField, Header("法宝一页个数")] int m_PageCount = 5;
        public int pageCount { get { return m_PageCount; } }
#if UNITY_EDITOR
        [SerializeField, Header("法宝个数")] int m_TreasureCount = 5;
        public int treasureCount { get { return m_TreasureCount; } }
        public Vector3 normal
        {
            get
            {
                var _x = 0;
                var _y = Mathf.Sin(Mathf.Deg2Rad * 90);
                var _z = Mathf.Cos(Mathf.Deg2Rad * 90);
                return new Vector3(_x, _y, _z);
            }
        }
        [NonSerialized] public float angle = 360;
#endif
        [SerializeField, Header("移动时长")] float m_Duration = 1.0f;
        public float duration { get { return m_Duration; } }
        [SerializeField, Header("Left")] int m_StartIndex = 3;
        public int startIndex { get { return m_StartIndex; } }
        [SerializeField, Header("灵敏系数")] float m_Sensitive = 0.1f;
        public float sensitive
        {
            get
            {
                return m_Sensitive <= 0 ? 1 : m_Sensitive;
            }
        }
        [SerializeField, Header("平静速度")] float m_SmoothVeiocity = 5.0f;
        public float smoothVeiocity { get { return m_SmoothVeiocity; } }
        [SerializeField, Header("是否处于滑动的角度范围")] float m_JudgeDrag = 0.1f;
 
        [SerializeField, Header("起始位置")] Vector3 m_StartPosition = Vector3.zero;
        //[SerializeField, Header("结束位置")] Vector3 m_EndPosition = Vector3.zero;
        [SerializeField, Header("法宝拉近时间")] float m_TweenDuration = 1.0f;
        [SerializeField, Header("法宝左移时间")] float m_TweenLeftDuration = 0.35f;
 
        [SerializeField] Treasure3DConfig.TreasureParam m_ChallengeSfxParam;
        public Treasure3DConfig.TreasureParam challengeSfxParam
        {
            get
            {
                return m_ChallengeSfxParam;
            }
        }
 
        [SerializeField] Treasure3DConfig.TreasureParam m_PotentialParam;
        public Treasure3DConfig.TreasureParam potentialParam
        {
            get { return m_PotentialParam; }
        }
 
        [SerializeField] Treasure3DConfig.TreasureParam m_AchievementParam;
        public Treasure3DConfig.TreasureParam achievementParam
        {
            get { return m_AchievementParam; }
        }
 
        [SerializeField] Treasure3DConfig.TreasureParam m_StageUpParam;
        public Treasure3DConfig.TreasureParam stageUpParam
        {
            get { return m_StageUpParam; }
        }
 
        TreasureModel m_Model;
        TreasureModel model
        {
            get { return m_Model ?? (m_Model = ModelCenter.Instance.GetModel<TreasureModel>()); }
        }
 
        static UI3DTreasureSelectStage m_Instance = null;
        public static UI3DTreasureSelectStage Instance
        {
            get
            {
                if (m_Instance == null)
                {
                    var gameObject = Instantiate(UILoader.LoadTreasure("Misc","UI3DTreasureSelectStage"));
                    m_Instance = gameObject.GetComponent<UI3DTreasureSelectStage>();
                    m_Instance.transform.position = new Vector3(0, 3000, 4000);
                    m_Instance.name = "UI3DTreasureSelectStage";
                    m_Instance.SetActive(true);
                    m_Instance.showCamera.enabled = false;
                    m_Instance.renderCamera.enabled = false;
                    DontDestroyOnLoad(gameObject);
                }
 
                return m_Instance;
            }
        }
 
        public TreasureCategory currentCategory { get; private set; }
        public bool IsCloser { get; private set; }
        public bool IsOpen { get; private set; }
        public bool CloserComplete { get; private set; }
        public int jumpTreasure { get; private set; }
        public bool UnlockShowing { get; set; }
        public bool Preloading { get; private set; }
 
        public GameObject currentTreasureTitle
        {
            get
            {
                if((int)currentCategory-1< m_TreasureTitles.Length)
                {
                    return m_TreasureTitles[(int)currentCategory - 1];
                }
                return null;
            }
        }
 
        public GameObject currentTreasureBackGround
        {
            get
            {
                if ((int)currentCategory - 1 < m_TreasureSkys.Length)
                {
                    return m_TreasureSkys[(int)currentCategory - 1];
                }
                return null;
            }
        }
 
        public GameObject currentTreasureFog
        {
            get
            {
                if ((int)currentCategory - 1 < m_TreasureFogs.Length)
                {
                    return m_TreasureFogs[(int)currentCategory - 1];
                }
                return null;
            }
        }
 
        public int selectTreasure
        {
            get
            {
                if (m_Treasures.ContainsKey(currentCategory)
                    && presentSelectIndex < m_Treasures[currentCategory].Count)
                {
                    return m_Treasures[currentCategory][presentSelectIndex].treasureId;
                }
                return 0;
            }
        }
 
        [NonSerialized]
        public int presentSelectIndex = 0;
        public event Action OnCameraBackComplete;
        public event Action OnCameraStartEvent;
        public event Action OnCameraCloserComplete;
        public event Action OnCameraBackEvent;
        public event Action OnUnlockComplete;
        public event Action startAnimation;
 
        Dictionary<TreasureCategory, List<TreasureComponent>> m_Treasures = new Dictionary<TreasureCategory, List<TreasureComponent>>();
        Dictionary<TreasureCategory, bool> m_PreloadDict = new Dictionary<TreasureCategory, bool>();
        List<int> displayTreasures = new List<int>();
 
        Coroutine preloadCoroutine = null;
 
        public static float sync_normalizedTime = 0f;
        const float effect_duration = 4f;
        float sync_timer = 0f;
        private void InitTreasure()
        {
            Load(TreasureCategory.Human);
            Load(TreasureCategory.Demon);
            Load(TreasureCategory.Fairy);
            Load(TreasureCategory.King);
        }
 
        void Load(TreasureCategory _type)
        {
            if (m_Treasures.ContainsKey(_type))
            {
                return;
            }
 
            var list = new List<TreasureComponent>();
            m_Treasures.Add(_type, list);
 
            List<int> _list = new List<int>();
            if (_type == TreasureCategory.King)
            {
                var model = ModelCenter.Instance.GetModel<KingTreasureModel>();
                _list = model.GetDisplayList();
            }
            else
            { 
                _list = model.GetTreasureCategory(_type);
            }
 
            if (_list != null)
            {
                for (int i = 0; i < _list.Count; i++)
                {
                    var _component = new TreasureComponent()
                    {
                        treasureId = _list[i],
                        root = (new GameObject("TreasureComponent")).transform,
                        treasureRoot = (new GameObject("TreasureRoot")).transform,
                    };
                    _component.SetLayer(LayerUtility.UILayer);
                    _component.root.position = GetPosition(i + startIndex);
                    _component.treasureRoot.position = GetPosition(i + startIndex);
                    _component.root.SetParent(center);
                    _component.treasureRoot.SetParent(treasureRoot);
                    _component.root.LookAt(showCamera.transform);
                    _component.treasureRoot.LookAt(showCamera.transform);
                    TreasureInteractProcessor _interactProcessor = _component.root.AddMissingComponent<TreasureInteractProcessor>();
                    _interactProcessor.treasureId = _list[i];
                    _component.interactProcessor = _interactProcessor;
                    _component.paramConfig = ScriptableObjectLoader.LoadSoTreasure3DConfig(_list[i]);
                    var _treasureConfig = TreasureConfig.Get(_list[i]);
                    _component.category = (TreasureCategory)_treasureConfig.Category;
                    list.Add(_component);
                }
            }
        }
 
        public void Open(bool _closer = false, TreasureCategory _type = TreasureCategory.Human)
        {
            InitTreasure();
 
            CameraController.Instance.CameraObject.SetActive(false);
            m_Camera.enabled = true;
            WindowCenter.Instance.uiRoot.baseCanvas.SetActive(false);
 
            SelectTreasureCategory(_type, _closer);
            IsOpen = true;
 
            jumpTreasure = 0;
 
            if (_closer)
            {
                var _config = ScriptableObjectLoader.LoadSoTreasure3DConfig(selectTreasure);
                m_CameraControl.localPosition = _config.cameraTweenParam.position;
                IsCloser = true;
                CloserComplete = true;
                OpenRenderCamera();
                HideTreasuresExcept(presentSelectIndex);
                m_Treasures[currentCategory][presentSelectIndex].SetActive(true);
                m_Treasures[currentCategory][presentSelectIndex].CloserState();
                m_Treasures[currentCategory][presentSelectIndex].SetLayer(LayerUtility.DefaultLayer);
                SetCloserState();
            }
            else
            {
                var _list = m_Treasures[currentCategory];
                for (int i = 0; i < _list.Count; i++)
                {
                    _list[i].SetLayer(LayerUtility.UILayer);
                }
            }
 
            model.treasureStateChangeEvent += TreasureStateChangeEvent;
            model.treasureStageUpEvent += TreasureStageUpEvent;
        }
 
        IEnumerator Co_PreLoad(TreasureCategory _category, Action callback)
        {
            var _list = m_Treasures[currentCategory];
            for (int i = 0; i < _list.Count; i++)
            {
                _list[i].SetActive(true);
                _list[i].SetActive(false);
                yield return null;
            }
            if (callback != null)
            {
                callback();
                callback = null;
            }
        }
 
        public void Close()
        {
            HideAllTreasure();
            CloseRenderCamera();
 
            IsCloser = false;
            CloserComplete = false;
            UnlockShowing = false;
            IsOpen = false;
            jumping = false;
            Preloading = false;
            jumpTreasure = 0;
 
            var movecomponent = m_CameraControl.GetComponent<SmoothMove>();
            if (movecomponent != null)
            {
                DestroyImmediate(movecomponent);
            }
            m_CameraControl.localPosition = m_StartPosition;
 
            CameraController.Instance.CameraObject.SetActive(true);
            m_Camera.enabled = false;
            WindowCenter.Instance.uiRoot.baseCanvas.SetActive(true);
 
            model.treasureStateChangeEvent -= TreasureStateChangeEvent;
            model.treasureStageUpEvent -= TreasureStageUpEvent;
            model.SetUnlockAnim(currentCategory, 0);
 
            if (currentTreasureTitle != null)
            {
                currentTreasureTitle.SetActive(false);
            }
            if (currentTreasureBackGround != null)
            {
                currentTreasureBackGround.SetActive(false);
            }
            if (currentTreasureFog != null)
            {
                currentTreasureFog.SetActive(false);
            }
        }
 
        private void TreasureStateChangeEvent(int _id)
        {
            var _list = m_Treasures[currentCategory];
            var _component = _list.Find((x) =>
            {
                return x.treasureId == _id;
            });
            if (_component != null && _component.display)
            {
                _component.UpdateTreasureState();
                _component.SetLayer(CloserComplete ? LayerUtility.DefaultLayer : LayerUtility.UILayer);
            }
        }
 
        private void TreasureStageUpEvent(int _id)
        {
            var _list = m_Treasures[currentCategory];
            var _component = _list.Find((x) =>
            {
                return x.treasureId == _id;
            });
            if (_component != null && _component.display)
            {
                _component.SetLayer(CloserComplete ? LayerUtility.DefaultLayer : LayerUtility.UILayer);
            }
        }
 
        public void SelectTreasureCategory(TreasureCategory _type, bool _closer = false)
        {
            RefreshDisplayTreasures(_type);
 
            presentSelectIndex = 0;
            UnlockShowing = false;
 
            currentCategory = _type;
            model.currentCategory = currentCategory;
 
            min_angle = startIndex * Mathf.Abs(intervalAngle);
            max_angle = (displayTreasures.Count + startIndex) * Mathf.Abs(intervalAngle);
 
            var _index = -1;
            if (!_closer)
            {
                _index = CheckOpenSelectTreasure();
            }
            if (_index == -1)
            {
                var _treasureCount = displayTreasures.Count;
                _index = _treasureCount < pageCount / 2 ? 0 : pageCount / 2;
            }
 
            HideAllTreasure();
            InitScene();
 
            if (preloadCoroutine != null)
            {
                StopCoroutine(preloadCoroutine);
                preloadCoroutine = null;
                Preloading = false;
            }
 
            if (!m_PreloadDict.ContainsKey(currentCategory) && !_closer)
            {
                Preloading = true;
                center.localEulerAngles = Vector3.zero;
                current_angle = 0;
                before_angle = 0;
                before_drag_angle = current_angle;
                preloadCoroutine = StartCoroutine(Co_PreLoad(currentCategory, () =>
                  {
                      if (!m_PreloadDict.ContainsKey(currentCategory))
                      {
                          m_PreloadDict.Add(currentCategory, true);
                      }
                      GoTreasureFromHeader(_index);
                      Preloading = false;
                      preloadCoroutine = null;
                  }));
            }
            else
            {
                if (!m_PreloadDict.ContainsKey(currentCategory))
                {
                    m_PreloadDict.Add(currentCategory, true);
                }
                GoTreasureFromHeader(_index);
            }
        }
 
        private void InitScene()
        {
            for (int i = 0; i < m_TreasureSkys.Length; i++)
            {
                m_TreasureSkys[i].SetActive((int)currentCategory - 1 == i);
            }
            for (int i = 0; i < m_TreasureTitles.Length; i++)
            {
                m_TreasureTitles[i].SetActive((int)currentCategory - 1 == i);
            }
            for (int i = 0; i < m_TreasureFogs.Length; i++)
            {
                m_TreasureFogs[i].SetActive((int)currentCategory - 1 == i);
            }
        }
 
        private int CheckOpenSelectTreasure()
        {
            var _treasure = 0;
            int _index = -1;
            if (model.IsRequireUnlockAnim(currentCategory) != 0)
            {
                _treasure = model.IsRequireUnlockAnim(currentCategory);
                model.treasureGotoId = _treasure;
                UnlockShowing = true;
            }
            else if (model.treasureGotoId == 0)
            {
                List<int> compares = new List<int>();
                List<int> _list = new List<int>();
                if (currentCategory == TreasureCategory.King)
                {
                    var model = ModelCenter.Instance.GetModel<KingTreasureModel>();
                    _list = model.GetDisplayList();
                }
                else
                { 
                    _list = model.GetTreasureCategory(currentCategory);
                }
                compares.AddRange(_list);
                compares.Sort(Compare);
                _treasure = compares[0];
            }
            else
            {
                _treasure = model.treasureGotoId;
                model.treasureGotoId = 0;
            }
            if (_treasure != 0)
            {
                _index = m_Treasures[currentCategory].FindIndex((x) =>
                {
                    return x.treasureId == _treasure;
                });
            }
            return _index;
        }
 
        int Compare(int x, int y)
        {
            Treasure treasure_x;
            Treasure treasure_y;
            if (!model.TryGetTreasure(x, out treasure_x) || !model.TryGetTreasure(y, out treasure_y))
            {
                return x.CompareTo(y);
            }
            bool collect_x = treasure_x.state == TreasureState.Collecting;
            bool collect_y = treasure_y.state == TreasureState.Collecting;
            if (collect_x != collect_y)
            {
                return -collect_x.CompareTo(collect_y);
            }
 
            TreasureDungeon treasureDungeonx;
            TreasureDungeon treasureDungeony;
            if (model.TryGetTreasureDungeon(x, out treasureDungeonx)
                && model.TryGetTreasureDungeon(y, out treasureDungeony))
            {
                bool redpointx = treasureDungeonx.challengeRedpoint.state == RedPointState.Simple;
                bool redpointy = treasureDungeony.challengeRedpoint.state == RedPointState.Simple;
                if (redpointx != redpointy)
                {
                    return -redpointx.CompareTo(redpointy);
                }
            }
 
            bool lock_x = treasure_x.state == TreasureState.Locked;
            bool lock_y = treasure_y.state == TreasureState.Locked;
            if (lock_x != lock_y)
            {
                return -lock_x.CompareTo(lock_y);
            }
            bool up = true;
            bool collected_x = treasure_x.state == TreasureState.Collected;
            bool collected_y = treasure_y.state == TreasureState.Collected;
            if (collected_x && collected_y)
            {
                up = false;
            }
            return x.CompareTo(y) * (up ? 1 : -1);
        }
 
        public Vector3 GetPosition(int _index)
        {
            var _y = center.position.y;
            var _z = center.position.z + radius * Mathf.Cos(Mathf.Deg2Rad * (intervalAngle * _index));
            var _x = center.position.x + radius * Mathf.Sin(Mathf.Deg2Rad * (intervalAngle * _index));
            return new Vector3(_x, _y, _z);
        }
 
        #region 选择法宝
        public void GoTreasureFromHeader(int _index)
        {
            center.localEulerAngles = Vector3.zero;
            current_angle = 0;
            before_angle = 0;
            before_drag_angle = current_angle;
            Goto(_index, true);
        }
 
        public void Goto(int _index, bool _force = false)
        {
            var _list = m_Treasures[currentCategory];
            if (_index < 0 || _index >= _list.Count)
            {
                _index = 0;
            }
            jumpTreasure = _list[_index].treasureId;
            if (!_force && _index == presentSelectIndex)
            {
                jumpTreasure = 0;
                return;
            }
            if (_index < _list.Count)
            {
                jumping = true;
                float _angle = (_index + 3) * Mathf.Abs(intervalAngle) * forward;
                target_angle = _angle;
                dragStarted = false;
                veiocity = 0;
            }
        }
 
        public void GotoImmediatly(int _index)
        {
            List<TreasureComponent> _list;
            if (m_Treasures.TryGetValue(currentCategory, out _list))
            {
                if (_index >= _list.Count)
                {
                    return;
                }
                float _angle = (_index + 3) * Mathf.Abs(intervalAngle) * forward;
                target_angle = _angle;
                center.Rotate(center.up, _angle - current_angle);
                current_angle = _angle;
                before_angle = current_angle;
                if (IsCloser)
                {
                    _list[presentSelectIndex].OutCloserState();
                    _list[presentSelectIndex].SetLayer(LayerUtility.UILayer);
                    _list[presentSelectIndex].SetActive(false);
                    _list[_index].SetActive(true);
                    _list[_index].UpdateParam();
                    _list[_index].CloserState();
                    _list[_index].SetLayer(LayerUtility.DefaultLayer);
                    var _config = ScriptableObjectLoader.LoadSoTreasure3DConfig(_list[_index].treasureId);
                    m_CameraControl.localPosition = _config.cameraTweenParam.position;
                }
                presentSelectIndex = _index;
            }
        }
 
        public bool AllowPointClick()
        {
            if (IsCloser || UnlockShowing || jumping
                || draging || BossShowModel.Instance.BossShowing)
            {
                return false;
            }
            return true;
        }
 
        public void OnPointDownTreasure(int _treasureId)
        {
            if (!AllowPointClick())
            {
                return;
            }
            switch (currentCategory)
            {
                case TreasureCategory.King:
                    {
                        var model = ModelCenter.Instance.GetModel<KingTreasureModel>();
                        if (model.GetSeasonState(_treasureId) == 0)
                        {
                            SysNotifyMgr.Instance.ShowTip("TreasureOneVsOneSeasonNotStart");
                            return;
                        }
                    }
                    break;
            }
            var _list = m_Treasures[currentCategory];
            var _index = _list.FindIndex((x) =>
            {
                return x.treasureId == _treasureId;
            });
            if (_index != -1)
            {
                model.openFromTreasureList = true;
                Goto(_index);
                StartCloser();
            }
        }
 
        private void OnJumpComplete()
        {
            if (UnlockShowing)
            {
                var _component = m_Treasures[currentCategory][presentSelectIndex];
                _component.PlayUnlockShow();
            }
            else
            {
                TreasureDungeon treasureDungeon;
                if (model.TryGetTreasureDungeon(selectTreasure, out treasureDungeon))
                {
                    if (treasureDungeon.challengeRedpoint.state == RedPointState.Simple)
                    {
                        OnPointDownTreasure(selectTreasure);
                    }
                }
            }
            jumpTreasure = 0;
        }
        #endregion
 
        #region 滑动
        bool draging = false;
        bool dragStarted = false;
        public bool jumping = false;
        float veiocity = 0;
        float min_angle = 0;
        float max_angle = 0;
        float target_angle = 0;
        float drag_angle = 0;
        float before_drag_angle = 0;
        float current_angle = 0;
        float before_angle = 0;
 
        public void BegineDrag()
        {
            if (IsCloser || UnlockShowing)
            {
                return;
            }
            jumping = false;
            dragStarted = true;
            drag_angle = 0;
            veiocity = 0;
            before_drag_angle = current_angle;
        }
 
        public void Drag(float _delta)
        {
            if (IsCloser || jumping || !dragStarted)
            {
                return;
            }
            drag_angle += _delta * sensitive;
            var _angle = before_drag_angle + drag_angle;
            _angle = Mathf.Clamp(_angle * forward, min_angle - Mathf.Abs(intervalAngle),
                max_angle + Mathf.Abs(intervalAngle)) * forward;
            target_angle = _angle;
        }
 
        public void DragEnd()
        {
            dragStarted = false;
        }
        #endregion
 
        private void LateUpdate()
        {
            Tick();
            if (!IsOpen || Preloading)
            {
                return;
            }
            if (m_Treasures.ContainsKey(currentCategory))
            {
                current_angle = Mathf.SmoothDamp(current_angle, target_angle, ref veiocity, duration);
                var _deltaAngle = current_angle - before_angle;
                if (Mathf.Abs(_deltaAngle) > m_Offset)
                {
                    _deltaAngle = _deltaAngle > 0 ? m_Offset : -m_Offset;
                    current_angle = _deltaAngle + before_angle;
                }
                before_angle = current_angle;
                center.Rotate(center.up, _deltaAngle);
 
                if (!CloserComplete)
                {
                    CheckDisplay();
                }
 
                if (!jumping)
                {
                    CheckElastic();
                }
 
                draging = Mathf.Abs(target_angle - current_angle) > m_JudgeDrag;
                if (!draging && jumping)
                {
                    jumping = false;
                    OnJumpComplete();
                    jumpTreasure = 0;
                }
            }
        }
 
        private void Tick()
        {
            sync_normalizedTime = Mathf.Clamp01(sync_timer / effect_duration);
            if (sync_timer >= effect_duration)
            {
                sync_timer = 0f;
            }
            else
            {
                sync_timer += Time.deltaTime;
            }
        }
 
        #region 滑动
        private void CheckDisplay()
        {
            var _list = m_Treasures[currentCategory];
            for (int i = 0; i < _list.Count; i++)
            {
                _list[i].root.LookAt(center);
#if UNITY_EDITOR
                if (_list[i].display)
                {
                    _list[i].UpdateParam();
                }
#endif
                float _angle = Vector3.Angle(_list[i].root.position - center.position, GetPosition(0) - center.position);
                if (Mathf.Abs(_angle) <= Mathf.Abs(intervalAngle) - 10
                    && (_list[i].display || IsCloser))
                {
                    presentSelectIndex = i;
                }
 
                if (IsCloser)
                {
                    continue;
                }
 
                if (Mathf.Abs(i - presentSelectIndex) > startIndex
                    || !displayTreasures.Contains(_list[i].treasureId))
                {
                    if (_list[i].display)
                    {
                        OutOfView(i, true);
                    }
                }
                else if (!_list[i].display)
                {
                    OutOfView(i, false);
                }
            }
        }
 
        private void CheckElastic()
        {
            if (target_angle * forward > max_angle)
            {
                float _angle = (displayTreasures.Count - 1 + startIndex) * Mathf.Abs(intervalAngle);
                target_angle = _angle * forward;
            }
            else if (target_angle * forward < min_angle)
            {
                float _angle = startIndex * Mathf.Abs(intervalAngle);
                target_angle = _angle * forward;
            }
            else if (Mathf.Abs(veiocity) < smoothVeiocity)
            {
                float _angle = (presentSelectIndex + startIndex) * Mathf.Abs(intervalAngle);
                target_angle = _angle * forward;
            }
        }
        #endregion
 
        #region 显示或隐藏法宝
        private void OutOfView(int _index, bool _out)
        {
            var _list = m_Treasures[currentCategory];
            if (_out && _list[_index].display)
            {
                _list[_index].SetActive(false);
            }
            else if (!_out && !_list[_index].display)
            {
                _list[_index].SetActive(true);
            }
        }
 
        private void ResetTreasureCategory()
        {
            foreach (var _key in m_Treasures.Keys)
            {
                var _list = m_Treasures[_key];
                for (int i = 0; i < _list.Count; i++)
                {
                    if (_key != currentCategory)
                    {
                        _list[i].SetActive(false);
                    }
                    else
                    {
                        bool _display = Mathf.Abs(i - presentSelectIndex) < startIndex
                            && displayTreasures.Contains(_list[i].treasureId);
                        _list[i].SetActive(_display);
                    }
                }
            }
        }
 
        private void HideTreasuresExcept(int _index)
        {
            var _list = m_Treasures[currentCategory];
            for (int i = 0; i < _list.Count; i++)
            {
                if (i != _index && _list[i].display)
                {
                    _list[i].SetActive(false);
                }
            }
        }
 
        private void HideAllTreasure()
        {
            foreach (var _key in m_Treasures.Keys)
            {
                var _list = m_Treasures[_key];
                for (int i = 0; i < _list.Count; i++)
                {
                    _list[i].OutCloserState();
                    _list[i].SetActive(false);
                    _list[i].SetLayer(LayerUtility.UILayer);
                }
            }
        }
 
        private void ShowNearTreasure(int _index)
        {
            var _list = m_Treasures[currentCategory];
            for (int i = 0; i < _list.Count; i++)
            {
                if (!displayTreasures.Contains(_list[i].treasureId))
                {
                    continue;
                }
                if (Mathf.Abs(i - _index) <= startIndex
                    && !_list[i].display)
                {
                    _list[i].SetActive(true);
                }
            }
        }
        #endregion
 
        #region 摄像机移动事件
        public void StartCloser()
        {
            IsCloser = true;
            CloserComplete = false;
            if (OnCameraStartEvent != null)
            {
                OnCameraStartEvent();
            }
            var _index = m_Treasures[currentCategory].FindIndex((x) =>
            {
                return x.treasureId == jumpTreasure;
            });
            _index = _index != -1 ? _index : presentSelectIndex;
            HideTreasuresExcept(_index);
            m_Treasures[currentCategory][_index].CloserState();
            var _config = ScriptableObjectLoader.LoadSoTreasure3DConfig(m_Treasures[currentCategory][_index].treasureId);
            SmoothMove.MoveTo(m_CameraControl.gameObject, _config.cameraTweenParam.position, m_TweenDuration, true, OnCloserComplete);
            SetCloserState();
        }
 
        private void SetCloserState()
        {
            if (currentTreasureTitle != null)
            {
                currentTreasureTitle.SetActive(false);
            }
        }
 
        private void OnCloserComplete()
        {
            if (!IsOpen)
            {
                return;
            }
            CloserComplete = true;
            OpenRenderCamera();
            m_Treasures[currentCategory][presentSelectIndex].SetLayer(LayerUtility.DefaultLayer);
            if (OnCameraCloserComplete != null)
            {
                OnCameraCloserComplete();
            }
        }
 
        public void StartBack()
        {
            CloserComplete = false;
            SmoothMove.MoveTo(m_CameraControl.gameObject, m_StartPosition, m_TweenDuration, true, CameraBackComplete);
            ShowNearTreasure(presentSelectIndex);
            CloseRenderCamera();
            m_Treasures[currentCategory][presentSelectIndex].OutCloserState();
            m_Treasures[currentCategory][presentSelectIndex].SetLayer(LayerUtility.UILayer);
            if (currentTreasureTitle != null)
            {
                currentTreasureTitle.SetActive(true);
            }
            if (OnCameraBackEvent != null)
            {
                OnCameraBackEvent();
            }
        }
 
        private void CameraBackComplete()
        {
            IsCloser = false;
            if (OnCameraBackComplete != null)
            {
                OnCameraBackComplete();
            }
            if (!IsOpen)
            {
                return;
            }
            var _list = m_Treasures[currentCategory];
            for (int i = 0; i < _list.Count; i++)
            {
                _list[i].SetLayer(LayerUtility.UILayer);
            }
 
            ReCheckTreasureHighest();
        }
        #endregion
 
        #region 法宝专用摄像机
        public void OpenRenderCamera()
        {
            renderCamera.enabled = true;
        }
 
        public void CloseRenderCamera()
        {
            renderCamera.enabled = false;
        }
 
        public void Tween(Action callback)
        {
            SetStartState();
            StartCoroutine(Co_RenderCameraTween(callback, m_TweenLeftDuration));
            var config = ScriptableObjectLoader.LoadSoTreasure3DConfig(selectTreasure);
            var _tweener = renderCamera.transform.DOLocalMove(config.renderCameraParam.position, m_TweenLeftDuration);
            _tweener.SetEase(Ease.Linear);
        }
 
        IEnumerator Co_RenderCameraTween(Action callback, float _duration)
        {
            var _timer = 0f;
            while (_timer < _duration && IsOpen && IsCloser)
            {
                var offset = currentCategory == TreasureCategory.Human ? -0.4f : -0.62f;
                var _target = offset * _timer / _duration;
                renderCamera.rect = new Rect(_target, 0, 1, 1);
                yield return null;
                _timer += Time.deltaTime;
            }
            SetEndState();
            if (callback != null)
            {
                callback();
                callback = null;
            }
        }
 
        public void SetStartState()
        {
            renderCamera.rect = new Rect(0, 0, 1, 1);
            renderCamera.transform.localPosition = Vector3.zero;
        }
 
        public void SetEndState()
        {
            var offset = currentCategory == TreasureCategory.Human ? -0.4f : -0.62f;
            renderCamera.rect = new Rect(offset, 0, 1, 1);
            var config = ScriptableObjectLoader.LoadSoTreasure3DConfig(selectTreasure);
            renderCamera.transform.localPosition = config.renderCameraParam.position;
        }
        #endregion
 
        public void CompleteUnlock()
        {
            if (OnUnlockComplete != null)
            {
                OnUnlockComplete();
            }
        }
 
        public void ReCheckTreasureHighest()
        {
            if (!IsOpen)
            {
                return;
            }
            var treasureId = 0;
            if (model.IsRequireUnlockAnim(currentCategory) != 0)
            {
                UnlockShowing = true;
                treasureId = model.IsRequireUnlockAnim(currentCategory);
                model.treasureGotoId = treasureId;
            }
            if (treasureId != 0)
            {
                var _index = m_Treasures[currentCategory].FindIndex((x) =>
                 {
                     return x.treasureId == treasureId;
                 });
                if (_index == presentSelectIndex)
                {
                    var _component = m_Treasures[currentCategory][presentSelectIndex];
                    if (UnlockShowing)
                    {
                        _component.PlayUnlockShow();
                    }
                }
                else
                {
                    Goto(_index);
                }
                if (startAnimation != null)
                {
                    startAnimation();
                }
            }
        }
 
        void RefreshDisplayTreasures(TreasureCategory category)
        {
            displayTreasures.Clear();
            switch (category)
            {
                case TreasureCategory.King:
                    {
                        var model = ModelCenter.Instance.GetModel<KingTreasureModel>();
                        var displays = model.GetDisplayList();
                        displayTreasures.AddRange(displays);
                    }
                    break;
                default:
                    var list = model.GetTreasureCategory(category);
                    displayTreasures.AddRange(list);
                    break;
            }
        }
    }
}