Skip to content

Commit 83b7c1a

Browse files
Merge branch 'mrtk_development' into vNEXT-InputActionRules
2 parents 232510b + c3b493b commit 83b7c1a

File tree

9 files changed

+92
-163
lines changed

9 files changed

+92
-163
lines changed

Assets/MixedRealityToolkit-SDK/Features/UX/Scripts/Collections/BaseObjectCollection.cs

Lines changed: 15 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,28 @@
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 Microsoft.MixedReality.Toolkit.Internal.Definitions.Utilities;
45
using System;
56
using System.Collections.Generic;
67
using UnityEngine;
7-
using Microsoft.MixedReality.Toolkit.Internal.Definitions.Utilities;
88

99
namespace Microsoft.MixedReality.Toolkit.SDK.UX.Collections
1010
{
1111
public abstract class BaseObjectCollection : MonoBehaviour
1212
{
13-
#region public members
14-
protected Action<BaseObjectCollection> onCollectionUpdated;
15-
1613
/// <summary>
1714
/// Action called when collection is updated
1815
/// </summary>
19-
public Action<BaseObjectCollection> OnCollectionUpdated
20-
{
21-
get { return onCollectionUpdated; }
22-
set { onCollectionUpdated = value; }
23-
}
24-
25-
protected List<ObjectCollectionNode> nodeList = new List<ObjectCollectionNode>();
16+
public Action<BaseObjectCollection> OnCollectionUpdated { get; set; }
2617

2718
/// <summary>
2819
/// List of objects with generated data on the object.
2920
/// </summary>
30-
public List<ObjectCollectionNode> NodeList
31-
{
32-
get { return nodeList; }
33-
set { nodeList = value; }
34-
}
21+
protected List<ObjectCollectionNode> NodeList { get; } = new List<ObjectCollectionNode>();
3522

3623
[Tooltip("Whether to include space for inactive transforms in the layout")]
3724
[SerializeField]
38-
protected bool ignoreInactiveTransforms = true;
25+
private bool ignoreInactiveTransforms = true;
3926

4027
/// <summary>
4128
/// Whether to include space for inactive transforms in the layout
@@ -48,7 +35,7 @@ public bool IgnoreInactiveTransforms
4835

4936
[Tooltip("Type of sorting to use")]
5037
[SerializeField]
51-
protected CollationOrderType sortType = CollationOrderType.None;
38+
private CollationOrderType sortType = CollationOrderType.None;
5239

5340
/// <summary>
5441
/// Type of sorting to use.
@@ -58,7 +45,6 @@ public CollationOrderType SortType
5845
get { return sortType; }
5946
set { sortType = value; }
6047
}
61-
#endregion public members
6248

6349
/// <summary>
6450
/// Rebuilds / updates the collection layout.
@@ -67,11 +53,11 @@ public CollationOrderType SortType
6753
public virtual void UpdateCollection()
6854
{
6955
// Check for empty nodes and remove them
70-
List<ObjectCollectionNode> emptyNodes = new List<ObjectCollectionNode>();
56+
var emptyNodes = new List<ObjectCollectionNode>();
7157

7258
for (int i = 0; i < NodeList.Count; i++)
7359
{
74-
if (NodeList[i].transform == null || (IgnoreInactiveTransforms && !NodeList[i].transform.gameObject.activeSelf) || NodeList[i].transform.parent == null || !(NodeList[i].transform.parent.gameObject == gameObject))
60+
if (NodeList[i].Transform == null || (IgnoreInactiveTransforms && !NodeList[i].Transform.gameObject.activeSelf) || NodeList[i].Transform.parent == null || !(NodeList[i].Transform.parent.gameObject == gameObject))
7561
{
7662
emptyNodes.Add(NodeList[i]);
7763
}
@@ -92,45 +78,34 @@ public virtual void UpdateCollection()
9278

9379
if (!ContainsNode(child) && (child.gameObject.activeSelf || !IgnoreInactiveTransforms))
9480
{
95-
ObjectCollectionNode node = new ObjectCollectionNode();
96-
97-
node.Name = child.name;
98-
node.transform = child;
99-
NodeList.Add(node);
81+
NodeList.Add(new ObjectCollectionNode { Name = child.name, Transform = child });
10082
}
10183
}
10284

10385
switch (SortType)
10486
{
105-
case CollationOrderType.None:
106-
default:
107-
break;
108-
10987
case CollationOrderType.ChildOrder:
110-
NodeList.Sort((c1, c2) => (c1.transform.GetSiblingIndex().CompareTo(c2.transform.GetSiblingIndex())));
88+
NodeList.Sort((c1, c2) => (c1.Transform.GetSiblingIndex().CompareTo(c2.Transform.GetSiblingIndex())));
11189
break;
11290

11391
case CollationOrderType.Alphabetical:
114-
NodeList.Sort((c1, c2) => (String.CompareOrdinal(c1.Name, c2.Name)) );
92+
NodeList.Sort((c1, c2) => (string.CompareOrdinal(c1.Name, c2.Name)));
11593
break;
11694

11795
case CollationOrderType.AlphabeticalReversed:
118-
NodeList.Sort((c1, c2) => (String.CompareOrdinal(c1.Name, c2.Name)));
96+
NodeList.Sort((c1, c2) => (string.CompareOrdinal(c1.Name, c2.Name)));
11997
NodeList.Reverse();
12098
break;
12199

122100
case CollationOrderType.ChildOrderReversed:
123-
NodeList.Sort((c1, c2) => (c1.transform.GetSiblingIndex().CompareTo(c2.transform.GetSiblingIndex())));
101+
NodeList.Sort((c1, c2) => (c1.Transform.GetSiblingIndex().CompareTo(c2.Transform.GetSiblingIndex())));
124102
NodeList.Reverse();
125103
break;
126104
}
127105

128106
LayoutChildren();
129107

130-
if (OnCollectionUpdated != null)
131-
{
132-
OnCollectionUpdated.Invoke(this);
133-
}
108+
OnCollectionUpdated?.Invoke(this);
134109
}
135110

136111
/// <summary>
@@ -140,11 +115,12 @@ protected bool ContainsNode(Transform node)
140115
{
141116
for (int i = 0; i < NodeList.Count; i++)
142117
{
143-
if (NodeList[i].transform == node)
118+
if (NodeList[i].Transform == node)
144119
{
145120
return true;
146121
}
147122
}
123+
148124
return false;
149125
}
150126

Assets/MixedRealityToolkit-SDK/Features/UX/Scripts/Collections/GridObjectCollection.cs

Lines changed: 36 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
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;
85
using Microsoft.MixedReality.Toolkit.Internal.Definitions.Utilities;
9-
using Microsoft.MixedReality.Toolkit.Internal.Extensions;
6+
using UnityEngine;
107

118
namespace 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

Comments
 (0)