Skip to content

Commit

Permalink
Fixed MRTK3 so it can compile in Unity 2022 with no automated code ch…
Browse files Browse the repository at this point in the history
…anges. (#11668)

- Added code changes to handle `Handles.FreeMoveHandle` changes in Unity 2022
  - This required to removing `rotation` handles in the `VectorHandle` function, since the new version of `Handles.FreeMoveHandle` doesn't support rotation.  I think this ok.  Nothing is actually using the `VectorHandle` function, 
- Removed `ProjectAuditor` from test project, since the latest version is not compiling in latest Unity 2022.
  • Loading branch information
AMollis authored Jul 3, 2023
1 parent a8bb204 commit 4427460
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 18 deletions.
1 change: 0 additions & 1 deletion UnityProjects/MRTKDevTemplate/Packages/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"com.unity.inputsystem": "1.6.1",
"com.unity.mobile.android-logcat": "1.3.2",
"com.unity.performance.profile-analyzer": "1.2.2",
"com.unity.project-auditor": "https://github.com/Unity-Technologies/ProjectAuditor.git",
"com.unity.test-framework": "1.1.33",
"com.unity.textmeshpro": "3.0.6",
"com.unity.timeline": "1.6.4",
Expand Down
10 changes: 1 addition & 9 deletions UnityProjects/MRTKDevTemplate/Packages/packages-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -289,15 +289,7 @@
"dependencies": {},
"url": "https://packages.unity.com"
},
"com.unity.project-auditor": {
"version": "https://github.com/Unity-Technologies/ProjectAuditor.git",
"depth": 0,
"source": "git",
"dependencies": {
"com.unity.nuget.mono-cecil": "1.10.1"
},
"hash": "0fc705630268255b07f06dacd61f3205f5d5ff3c"
},

"com.unity.subsystemregistration": {
"version": "1.1.0",
"depth": 1,
Expand Down
28 changes: 21 additions & 7 deletions com.microsoft.mrtk.core/Editor/Utilities/InspectorUIUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,11 @@ public static float AxisMoveHandle(Object target, Vector3 origin, Vector3 direct

Handles.DrawDottedLine(origin, position, DottedLineScreenSpace);
Handles.ArrowHandleCap(0, position, Quaternion.LookRotation(direction), handleSize * 2, EventType.Repaint);
#if UNITY_2022_1_OR_NEWER
Vector3 newPosition = Handles.FreeMoveHandle(position, handleSize, Vector3.zero, Handles.CircleHandleCap);
#else
Vector3 newPosition = Handles.FreeMoveHandle(position, Quaternion.identity, handleSize, Vector3.zero, Handles.CircleHandleCap);
#endif

if (recordUndo)
{
Expand Down Expand Up @@ -788,7 +792,11 @@ public static Vector3 CircleMoveHandle(Object target, Vector3 position, float xS
handleSize = Mathf.Lerp(handleSize, HandleUtility.GetHandleSize(position) * handleSize, 0.75f);
}

#if UNITY_2022_1_OR_NEWER
Vector3 newPosition = Handles.FreeMoveHandle(position, handleSize, Vector3.zero, Handles.CircleHandleCap);
#else
Vector3 newPosition = Handles.FreeMoveHandle(position, Quaternion.identity, handleSize, Vector3.zero, Handles.CircleHandleCap);
#endif

if (recordUndo && position != newPosition)
{
Expand Down Expand Up @@ -824,7 +832,11 @@ public static Vector3 SquareMoveHandle(Object target, Vector3 position, float xS
}

// Multiply square handle to match other types
#if UNITY_2022_1_OR_NEWER
Vector3 newPosition = Handles.FreeMoveHandle(position, handleSize * 0.8f, Vector3.zero, Handles.RectangleHandleCap);
#else
Vector3 newPosition = Handles.FreeMoveHandle(position, Quaternion.identity, handleSize * 0.8f, Vector3.zero, Handles.RectangleHandleCap);
#endif

if (recordUndo && position != newPosition)
{
Expand Down Expand Up @@ -860,7 +872,11 @@ public static Vector3 SphereMoveHandle(Object target, Vector3 position, float xS
}

// Multiply sphere handle size to match other types
#if UNITY_2022_1_OR_NEWER
Vector3 newPosition = Handles.FreeMoveHandle(position, handleSize * 2, Vector3.zero, Handles.SphereHandleCap);
#else
Vector3 newPosition = Handles.FreeMoveHandle(position, Quaternion.identity, handleSize * 2, Vector3.zero, Handles.SphereHandleCap);
#endif

if (recordUndo && position != newPosition)
{
Expand Down Expand Up @@ -920,13 +936,11 @@ public static Vector3 VectorHandle(Object target, Vector3 origin, Vector3 vector
// Draw a line from origin to origin + direction
Handles.DrawLine(origin, handlePosition);

Quaternion rotation = Quaternion.identity;
if (vector != Vector3.zero)
{
rotation = Quaternion.LookRotation(vector);
}

Vector3 newPosition = Handles.FreeMoveHandle(handlePosition, rotation, handleSize, Vector3.zero, Handles.DotHandleCap);
#if UNITY_2022_1_OR_NEWER
Vector3 newPosition = Handles.FreeMoveHandle(handlePosition, handleSize, Vector3.zero, Handles.DotHandleCap);
#else
Vector3 newPosition = Handles.FreeMoveHandle(handlePosition, Quaternion.identity, handleSize, Vector3.zero, Handles.DotHandleCap);
#endif

if (recordUndo && handlePosition != newPosition)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,12 @@ private float DrawPlaneAndHandle(Vector3[] vertices, Vector2 halfExtents, float
Handles.ArrowHandleCap(0, vertices[1], Quaternion.LookRotation(planeNormal), handleSize * 2, EventType.Repaint);
Handles.ArrowHandleCap(0, vertices[1], Quaternion.LookRotation(-planeNormal), handleSize * 2, EventType.Repaint);

#if UNITY_2022_1_OR_NEWER
Vector3 newPosition = Handles.FreeMoveHandle(vertices[1], handleSize, Vector3.zero, Handles.SphereHandleCap);
#else
Vector3 newPosition = Handles.FreeMoveHandle(vertices[1], Quaternion.identity, handleSize, Vector3.zero, Handles.SphereHandleCap);
#endif

if (!newPosition.Equals(vertices[1]))
{
distance = button.GetDistanceAlongPushDirection(newPosition);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,32 @@ private void OnSceneGUI()
}

EditorGUI.BeginChangeCheck();


#if UNITY_2022_1_OR_NEWER
Vector3 newStartPosition = Handles.FreeMoveHandle(startPos,
handleSize,
Vector3.zero,
Handles.SphereHandleCap);
#else
Vector3 newStartPosition = Handles.FreeMoveHandle(startPos,
Quaternion.identity,
handleSize,
Vector3.zero,
Handles.SphereHandleCap);
#endif

#if UNITY_2022_1_OR_NEWER
Vector3 newEndPosition = Handles.FreeMoveHandle(endPos,
handleSize,
Vector3.zero,
Handles.SphereHandleCap);
#else
Vector3 newEndPosition = Handles.FreeMoveHandle(endPos,
Quaternion.identity,
handleSize,
Vector3.zero,
Handles.SphereHandleCap);
#endif

if (EditorGUI.EndChangeCheck())
{
Expand Down

0 comments on commit 4427460

Please sign in to comment.