55
66using ARgorithm . Structure . Typing ;
77
8+ interface IArrow
9+ {
10+ ContentType faceValue
11+ {
12+ get ; set ;
13+ }
14+
15+ Vector3 position
16+ {
17+ get ; set ;
18+ }
19+
20+ Vector3 scale
21+ {
22+ get ; set ;
23+ }
24+
25+ Quaternion rotation
26+ {
27+ get ; set ;
28+ }
29+
30+ GameObject arrow
31+ {
32+ get ; set ;
33+ }
34+ }
35+
836namespace ARgorithm . Animations
937{
38+
1039 public class QueueAnimator : MonoBehaviour
1140 {
12- public void Declare ( string name , List < ContentType > body , GameObject placeholder )
41+ class VariableArrow : IArrow
1342 {
43+ private ContentType _faceValue ;
44+ private Vector3 _position ;
45+ private Vector3 _scale ;
46+ private GameObject _arrow ;
47+ private Quaternion _rotation ;
48+ public ContentType faceValue
49+ {
50+ get
51+ {
52+ return _faceValue ;
53+ }
54+ set
55+ {
56+ _faceValue = value ;
57+ for ( int i = 0 ; i < this . arrow . transform . childCount ; i ++ )
58+ {
59+ var child = this . arrow . transform . GetChild ( i ) . gameObject ;
60+ string text = _faceValue . Value . ToString ( ) ;
61+ child . GetComponent < TextMeshPro > ( ) . SetText ( text ) ;
62+ }
63+ }
64+ }
65+
66+ public VariableArrow ( ContentType value )
67+ {
68+ this . arrow = ( GameObject ) Instantiate ( Resources . Load ( "Arrow" ) as GameObject ) ;
69+ var cubeRenderer = this . arrow . GetComponent < Renderer > ( ) ;
70+ cubeRenderer . material . SetColor ( "_Color" , Color . magenta ) ;
71+ this . _scale = this . arrow . transform . localScale ;
72+ this . faceValue = value ;
73+ }
1474
75+ public Vector3 position
76+ {
77+ get
78+ {
79+ return _position ;
80+ }
81+ set
82+ {
83+ this . arrow . transform . localPosition = value ;
84+ this . _position = value ;
85+ }
86+ }
87+
88+ public Vector3 scale
89+ {
90+ get
91+ {
92+ return _scale ;
93+ }
94+
95+ set
96+ {
97+ this . arrow . transform . localScale = value ;
98+ this . _scale = value ;
99+ }
100+ }
101+
102+ public Quaternion rotation
103+ {
104+ get
105+ {
106+ return _rotation ;
107+ }
108+ set
109+ {
110+ this . arrow . transform . rotation = value ;
111+ this . _rotation = value ;
112+ }
113+ }
114+
115+ public GameObject arrow
116+ {
117+ get
118+ {
119+ return this . _arrow ;
120+ }
121+
122+ set
123+ {
124+ this . _arrow = value ;
125+ }
126+ }
127+ }
128+ private GameObject placeholder ;
129+ private LinkedList < IArrow > queueOfArrows ;
130+ public void Declare ( string name , List < ContentType > body , GameObject placeHolder )
131+ {
132+ this . placeholder = placeHolder ;
133+ this . queueOfArrows = new LinkedList < IArrow > ( ) ;
134+ if ( body . Count == 0 )
135+ return ;
136+ var back = new VariableArrow ( body [ 0 ] ) ;
137+ back . position = placeHolder . transform . position ;
138+ back . arrow . transform . SetParent ( placeHolder . transform ) ;
139+ this . queueOfArrows . AddLast ( back ) ;
140+ for ( int i = 1 ; i < body . Count ; i ++ )
141+ {
142+ var arrowObj = new VariableArrow ( body [ i ] ) ;
143+ arrowObj . arrow . transform . SetParent ( placeHolder . transform ) ;
144+ arrowObj . position = this . queueOfArrows . Last . Value . position ;
145+ arrowObj . position -= new Vector3 ( arrowObj . scale . x * 1.25f , 0 , 0 ) ;
146+ this . queueOfArrows . AddLast ( arrowObj ) ;
147+ }
15148 }
16149
17150 public void Pop ( )
18151 {
19-
152+ if ( this . queueOfArrows . Count == 0 )
153+ return ;
154+ foreach ( var arrow in queueOfArrows )
155+ {
156+ arrow . position += new Vector3 ( arrow . scale . x * 1.25f , 0 , 0 ) ;
157+ }
158+ var arrowFirst = queueOfArrows . First . Value ;
159+ Destroy ( arrowFirst . arrow ) ;
160+ queueOfArrows . RemoveFirst ( ) ;
20161 }
21162
22163 public void Push ( ContentType element )
23164 {
24-
165+ var arrow = new VariableArrow ( element ) ;
166+ if ( queueOfArrows . Count == 0 )
167+ {
168+ arrow . position = this . placeholder . transform . position ;
169+ arrow . arrow . transform . SetParent ( placeholder . transform ) ;
170+ queueOfArrows . AddLast ( arrow ) ;
171+ return ;
172+ }
173+ arrow . position = this . queueOfArrows . Last . Value . arrow . transform . position ;
174+ arrow . position -= new Vector3 ( arrow . scale . x * 1.25f , 0 , 0 ) ;
175+ arrow . arrow . transform . SetParent ( placeholder . transform ) ;
176+ queueOfArrows . AddLast ( arrow ) ;
25177 }
26178
27179 public void Front ( )
28180 {
29-
181+ if ( this . queueOfArrows . Count == 0 )
182+ return ;
183+ Color targetColor = new Color ( 1 , 1 , 1 , 1 ) ;
184+ Material materialToChange ;
185+ materialToChange = this . queueOfArrows . First . Value . arrow . GetComponent < Renderer > ( ) . material ;
186+ StartCoroutine ( LerpFunctionHighlight ( materialToChange , targetColor , Constants . ITER_TIMER ) ) ;
30187 }
31188
32189 public void Back ( )
33190 {
191+ if ( this . queueOfArrows . Count == 0 )
192+ return ;
193+ Color targetColor = new Color ( 1 , 1 , 1 , 1 ) ;
194+ Material materialToChange ;
195+ materialToChange = this . queueOfArrows . Last . Value . arrow . GetComponent < Renderer > ( ) . material ;
196+ StartCoroutine ( LerpFunctionHighlight ( materialToChange , targetColor , Constants . ITER_TIMER ) ) ;
197+ }
198+
199+ IEnumerator LerpFunctionHighlight ( Material materialToChange , Color endValue , float duration )
200+ {
201+ float time = 0 ;
202+ Color startValue = materialToChange . color ;
203+
204+ while ( time < duration )
205+ {
206+ materialToChange . color = Color . Lerp ( startValue , endValue , time / duration ) ;
207+
208+ time += Time . deltaTime ;
209+ yield return null ;
210+ }
211+ materialToChange . color = endValue ;
212+
213+ time = 0 ;
214+ while ( time < duration )
215+ {
216+ materialToChange . color = Color . Lerp ( endValue , startValue , time / duration ) ;
34217
218+ time += Time . deltaTime ;
219+ yield return null ;
220+ }
221+ materialToChange . color = startValue ;
35222 }
36223 }
37224}
0 commit comments