11// Copyright (c) Microsoft Corporation. All rights reserved.
22// Licensed under the MIT License. See LICENSE in the project root for license information.
33
4- using System ;
5- using System . Collections . Generic ;
6- using System . Linq ;
7- using UnityEngine ;
4+ using Microsoft . MixedReality . Toolkit . Core . Extensions ;
85using Microsoft . MixedReality . Toolkit . Internal . Definitions . Utilities ;
9- using Microsoft . MixedReality . Toolkit . Internal . Extensions ;
6+ using UnityEngine ;
107
118namespace Microsoft . MixedReality . Toolkit . SDK . UX . Collections
129{
@@ -17,8 +14,6 @@ namespace Microsoft.MixedReality.Toolkit.SDK.UX.Collections
1714 /// </summary>
1815 public class GridObjectCollection : BaseObjectCollection
1916 {
20- #region public accessors
21-
2217 [ Tooltip ( "Type of surface to map the collection to" ) ]
2318 [ SerializeField ]
2419 private ObjectOrientationSurfaceType surfaceType = ObjectOrientationSurfaceType . Plane ;
@@ -128,57 +123,26 @@ public float CellHeight
128123 /// <summary>
129124 /// Total Width of collection
130125 /// </summary>
131- public float Width
132- {
133- get
134- {
135- return columns * CellWidth ;
136- }
137- }
126+ public float Width => Columns * CellWidth ;
138127
139128 /// <summary>
140129 /// Total Height of collection
141130 /// </summary>
142- public float Height
143- {
144- get
145- {
146- return rows * CellHeight ;
147- }
148- }
149-
150-
151- private Mesh sphereMesh ;
131+ public float Height => rows * CellHeight ;
152132
153133 /// <summary>
154134 /// Reference mesh to use for rendering the sphere layout
155135 /// </summary>
156- public Mesh SphereMesh
157- {
158- get ;
159- set ;
160- }
161-
162- private Mesh cylinderMesh ;
136+ public Mesh SphereMesh { get ; set ; }
163137
164138 /// <summary>
165139 /// Reference mesh to use for rendering the cylinder layout
166140 /// </summary>
167- public Mesh CylinderMesh
168- {
169- get ;
170- set ;
171- }
172-
173- #endregion public accessors
174-
175- #region private fields
141+ public Mesh CylinderMesh { get ; set ; }
176142
177- protected int columns ;
178-
179- protected Vector2 halfCell ;
143+ protected int Columns ;
180144
181- #endregion private fields
145+ protected Vector2 HalfCell ;
182146
183147 /// <summary>
184148 /// Overriding base function for laying out all the children when UpdateCollection is called.
@@ -187,14 +151,14 @@ protected override void LayoutChildren()
187151 {
188152 float startOffsetX ;
189153 float startOffsetY ;
190- Vector3 [ ] nodeGrid = new Vector3 [ NodeList . Count ] ;
191- Vector3 newPos = Vector3 . zero ;
154+ var nodeGrid = new Vector3 [ NodeList . Count ] ;
155+ Vector3 newPos ;
192156
193157 // Now lets lay out the grid
194- columns = Mathf . CeilToInt ( ( float ) NodeList . Count / rows ) ;
195- startOffsetX = ( columns * 0.5f ) * CellWidth ;
158+ Columns = Mathf . CeilToInt ( ( float ) NodeList . Count / rows ) ;
159+ startOffsetX = ( Columns * 0.5f ) * CellWidth ;
196160 startOffsetY = ( rows * 0.5f ) * CellHeight ;
197- halfCell = new Vector2 ( CellWidth * 0.5f , CellHeight * 0.5f ) ;
161+ HalfCell = new Vector2 ( CellWidth * 0.5f , CellHeight * 0.5f ) ;
198162
199163 // First start with a grid then project onto surface
200164 ResolveGridLayout ( nodeGrid , startOffsetX , startOffsetY , layout ) ;
@@ -207,7 +171,7 @@ protected override void LayoutChildren()
207171 ObjectCollectionNode node = NodeList [ i ] ;
208172 newPos = nodeGrid [ i ] ;
209173 //Debug.Log(newPos);
210- node . transform . localPosition = newPos ;
174+ node . Transform . localPosition = newPos ;
211175 UpdateNodeFacing ( node ) ;
212176 NodeList [ i ] = node ;
213177 }
@@ -218,7 +182,7 @@ protected override void LayoutChildren()
218182 {
219183 ObjectCollectionNode node = NodeList [ i ] ;
220184 newPos = VectorExtensions . CylindricalMapping ( nodeGrid [ i ] , radius ) ;
221- node . transform . localPosition = newPos ;
185+ node . Transform . localPosition = newPos ;
222186 UpdateNodeFacing ( node ) ;
223187 NodeList [ i ] = node ;
224188 }
@@ -230,7 +194,7 @@ protected override void LayoutChildren()
230194 {
231195 ObjectCollectionNode node = NodeList [ i ] ;
232196 newPos = VectorExtensions . SphericalMapping ( nodeGrid [ i ] , radius ) ;
233- node . transform . localPosition = newPos ;
197+ node . Transform . localPosition = newPos ;
234198 UpdateNodeFacing ( node ) ;
235199 NodeList [ i ] = node ;
236200 }
@@ -243,9 +207,9 @@ protected override void LayoutChildren()
243207 for ( int i = 0 ; i < NodeList . Count ; i ++ )
244208 {
245209 ObjectCollectionNode node = NodeList [ i ] ;
246- newPos = VectorExtensions . RadialMapping ( nodeGrid [ i ] , radialRange , radius , curRow , rows , curColumn , columns ) ;
210+ newPos = VectorExtensions . RadialMapping ( nodeGrid [ i ] , radialRange , radius , curRow , rows , curColumn , Columns ) ;
247211
248- if ( curColumn == ( columns - 1 ) )
212+ if ( curColumn == ( Columns - 1 ) )
249213 {
250214 curColumn = 0 ;
251215 ++ curRow ;
@@ -255,7 +219,7 @@ protected override void LayoutChildren()
255219 ++ curColumn ;
256220 }
257221
258- node . transform . localPosition = newPos ;
222+ node . Transform . localPosition = newPos ;
259223 UpdateNodeFacing ( node ) ;
260224 NodeList [ i ] = node ;
261225 }
@@ -272,11 +236,11 @@ protected void ResolveGridLayout(Vector3[] grid, float offsetX, float offsetY, L
272236 if ( order == LayoutOrderType . RowThenColumn )
273237 {
274238 iMax = Rows ;
275- jMax = columns ;
239+ jMax = Columns ;
276240 }
277241 else
278242 {
279- iMax = columns ;
243+ iMax = Columns ;
280244 jMax = Rows ;
281245 }
282246
@@ -286,10 +250,9 @@ protected void ResolveGridLayout(Vector3[] grid, float offsetX, float offsetY, L
286250 {
287251 if ( cellCounter < NodeList . Count )
288252 {
289- grid [ cellCounter ] . Set ( ( ( i * CellWidth ) - offsetX + halfCell . x ) + NodeList [ cellCounter ] . Offset . x ,
290- ( - ( j * CellHeight ) + offsetY - halfCell . y ) + NodeList [ cellCounter ] . Offset . y ,
291- 0.0f
292- ) ;
253+ grid [ cellCounter ] . Set ( ( ( i * CellWidth ) - offsetX + HalfCell . x ) + NodeList [ cellCounter ] . Offset . x ,
254+ ( - ( j * CellHeight ) + offsetY - HalfCell . y ) + NodeList [ cellCounter ] . Offset . y ,
255+ 0.0f ) ;
293256 }
294257 cellCounter ++ ;
295258 }
@@ -300,48 +263,46 @@ protected void ResolveGridLayout(Vector3[] grid, float offsetX, float offsetY, L
300263 /// Update the facing of a node given the nodes new position for facing orign with node and orientation type
301264 /// </summary>
302265 /// <param name="node"></param>
303- /// <param name="orientType"></param>
304- /// <param name="newPos"></param>
305266 protected void UpdateNodeFacing ( ObjectCollectionNode node )
306267 {
307268 Vector3 centerAxis ;
308269 Vector3 pointOnAxisNearestNode ;
309270 switch ( OrientType )
310271 {
311272 case OrientationType . FaceOrigin :
312- node . transform . rotation = Quaternion . LookRotation ( node . transform . position - transform . position , transform . up ) ;
273+ node . Transform . rotation = Quaternion . LookRotation ( node . Transform . position - transform . position , transform . up ) ;
313274 break ;
314275
315276 case OrientationType . FaceOriginReversed :
316- node . transform . rotation = Quaternion . LookRotation ( transform . position - node . transform . position , transform . up ) ;
277+ node . Transform . rotation = Quaternion . LookRotation ( transform . position - node . Transform . position , transform . up ) ;
317278 break ;
318279
319280 case OrientationType . FaceCenterAxis :
320- centerAxis = Vector3 . Project ( node . transform . position - transform . position , transform . up ) ;
281+ centerAxis = Vector3 . Project ( node . Transform . position - transform . position , transform . up ) ;
321282 pointOnAxisNearestNode = transform . position + centerAxis ;
322- node . transform . rotation = Quaternion . LookRotation ( node . transform . position - pointOnAxisNearestNode , transform . up ) ;
283+ node . Transform . rotation = Quaternion . LookRotation ( node . Transform . position - pointOnAxisNearestNode , transform . up ) ;
323284 break ;
324285
325286 case OrientationType . FaceCenterAxisReversed :
326- centerAxis = Vector3 . Project ( node . transform . position - transform . position , transform . up ) ;
287+ centerAxis = Vector3 . Project ( node . Transform . position - transform . position , transform . up ) ;
327288 pointOnAxisNearestNode = transform . position + centerAxis ;
328- node . transform . rotation = Quaternion . LookRotation ( pointOnAxisNearestNode - node . transform . position , transform . up ) ;
289+ node . Transform . rotation = Quaternion . LookRotation ( pointOnAxisNearestNode - node . Transform . position , transform . up ) ;
329290 break ;
330291
331292 case OrientationType . FaceParentFoward :
332- node . transform . forward = transform . rotation * Vector3 . forward ;
293+ node . Transform . forward = transform . rotation * Vector3 . forward ;
333294 break ;
334295
335296 case OrientationType . FaceParentForwardReversed :
336- node . transform . forward = transform . rotation * Vector3 . back ;
297+ node . Transform . forward = transform . rotation * Vector3 . back ;
337298 break ;
338299
339300 case OrientationType . FaceParentUp :
340- node . transform . forward = transform . rotation * Vector3 . up ;
301+ node . Transform . forward = transform . rotation * Vector3 . up ;
341302 break ;
342303
343304 case OrientationType . FaceParentDown :
344- node . transform . forward = transform . rotation * Vector3 . down ;
305+ node . Transform . forward = transform . rotation * Vector3 . down ;
345306 break ;
346307
347308 case OrientationType . None :
@@ -363,11 +324,11 @@ protected virtual void OnDrawGizmosSelected()
363324 break ;
364325 case ObjectOrientationSurfaceType . Cylinder :
365326 Gizmos . color = Color . green ;
366- Gizmos . DrawWireMesh ( cylinderMesh , transform . position , transform . rotation , scale ) ;
327+ Gizmos . DrawWireMesh ( CylinderMesh , transform . position , transform . rotation , scale ) ;
367328 break ;
368329 case ObjectOrientationSurfaceType . Sphere :
369330 Gizmos . color = Color . green ;
370- Gizmos . DrawWireMesh ( sphereMesh , transform . position , transform . rotation , scale ) ;
331+ Gizmos . DrawWireMesh ( SphereMesh , transform . position , transform . rotation , scale ) ;
371332 break ;
372333 }
373334 }
0 commit comments