少年修仙传客户端代码仓库
client_Zxw
2018-12-20 0bbc8595fdc2cc2c06b9d461cf4d7d9db4ce2f8b
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
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Monday, April 09, 2018
//--------------------------------------------------------
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System;
using System.Collections.Generic;
using TableConfig;
 
namespace Snxxz.UI
{
 
    public class CrossServerCyclicScroll : CyclicScroll
    {
        const float fadeOutTime = 0.3f;
        const float relocationTime = 0.4f;
 
        CrossSeverDayAwardCell showAchievementBehaviour;
 
        bool m_Showing = false;
        public bool showing
        {
            get { return m_Showing; }
            private set { m_Showing = value; }
        }
 
        List<CrossServerModel.AwardType> dayAwards;
 
        CrossServerModel crossServerModel { get { return ModelCenter.Instance.GetModel<CrossServerModel>(); } }
 
        public void ShowTreasures(bool _stepByStep)
        {
            crossServerModel.SortDayAwardsList();
            dayAwards = crossServerModel.sortDayAwardslist;
            Init(dayAwards, _stepByStep);
        }
 
        public override void Init<T>(List<T> _datas, bool _stepByStep = false)
        {
            for (int i = 0; i < infiniteItems.Count; i++)
            {
                var item = infiniteItems[i] as CrossSeverDayAwardCell;
                item.alphaTween.SetStartState();
                item.linerMove.Stop();
            }
 
            showing = false;
            base.Init(_datas, _stepByStep);
 
            showing = true;
            this.enabled = false;
            Clock.Create(DateTime.Now + new TimeSpan((long)(0.5f * TimeSpan.TicksPerSecond)), OnUnfoldShowEnd);
        }
 
        private void OnUnfoldShowEnd()
        {
            showing = false;
            this.enabled = true;
        }
 
        public void ShowBegin(CrossSeverDayAwardCell _showItem)
        {
            this.enabled = false;
            showing = true;
            showAchievementBehaviour = _showItem;
            showAchievementBehaviour.alphaTween.from = 1f;
            showAchievementBehaviour.alphaTween.to = 0f;
            showAchievementBehaviour.alphaTween.duration = fadeOutTime;
            showAchievementBehaviour.alphaTween.SetStartState();
            showAchievementBehaviour.alphaTween.Play();
            var endTime = DateTime.Now + new TimeSpan((long)(fadeOutTime * TimeSpan.TicksPerSecond));
            Clock.Create(endTime, ReLocateItems);
        }
 
        void ReLocateItems()
        {
            showAchievementBehaviour.alphaTween.SetStartState();
            crossServerModel.SortDayAwardsList();
            dayAwards = crossServerModel.sortDayAwardslist;
            ReLocateAllItems(showAchievementBehaviour);
 
            var endTime = DateTime.Now + new TimeSpan((long)(relocationTime * TimeSpan.TicksPerSecond));
            Clock.Create(endTime, ShowEnd);
        }
 
        void ShowEnd()
        {
            this.enabled = true;
            showing = false;
        }
 
        private void ReLocateAllItems(ScrollItem _scrollItem)
        {
            var index = infiniteItems.IndexOf(_scrollItem);
            if (index != -1)
            {
                var showBehaviour = _scrollItem as CrossSeverDayAwardCell;
                var lastItem = infiniteItems[infiniteItems.Count - 1];
 
                showBehaviour.rectTransform.anchoredPosition = lastItem.rectTransform.anchoredPosition.SetY(lastItem.rectTransform.anchoredPosition.y - cellSize.y - spacing.y);
                showBehaviour.gameObject.SetActive(false);
                infiniteItems.Remove(_scrollItem);
                infiniteItems.Add(_scrollItem);
 
                for (int i = 0; i < infiniteItems.Count; i++)
                {
                    var item = infiniteItems[i] as CrossSeverDayAwardCell;
                    if (item != null && preIndex + i < datas.Count)
                    {
                        item.Display(datas[preIndex + i]);
                    }
                }
 
                for (int i = index; i < infiniteItems.Count; i++)
                {
                    var item = infiniteItems[i];
                    var achievementBehaviour = item as CrossSeverDayAwardCell;
 
                    achievementBehaviour.linerMove.from = achievementBehaviour.rectTransform.anchoredPosition;
                    var toY = achievementBehaviour.rectTransform.anchoredPosition.y + cellSize.y + spacing.y;
                    achievementBehaviour.linerMove.to = achievementBehaviour.rectTransform.anchoredPosition.SetY(toY);
                    achievementBehaviour.linerMove.duration = relocationTime;
                    if (achievementBehaviour.linerMove.gameObject.activeInHierarchy)
                    {
                        achievementBehaviour.linerMove.Begin();
                    }
                    else
                    {
                        achievementBehaviour.linerMove.Stop();
                    }
                }
            }
        }
 
        public void ResetScrollItemName()
        {
            for (int i = 0; i < infiniteItems.Count; i++)
            {
                infiniteItems[i].name = string.Format("Achievement_{0}", i);
            }
        }
 
    }
 
}