Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Windows API Contract Checker #1308

Merged
merged 10 commits into from
Nov 10, 2017
1,180 changes: 1,180 additions & 0 deletions Assets/HoloToolkit-Examples/Utilities/Scenes/CheckAPI.unity

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions Assets/HoloToolkit-Examples/Utilities/Scripts/CheckApiTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using UnityEngine;
using UnityEngine.UI;

public class CheckApiTest : MonoBehaviour
{
[SerializeField]
private Text text;

public void CheckV5Api()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pressing the buttons with a motion controller doesn't seem to call this code (voice "select" works). Is that something that'll be fixed with your uGUI fixes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is correct. Will be fixed by the uGUI raycast PR

{
text.text = "UniversalApiContract\nVersion 5 available? " + HoloToolkit.WindowsApiChecker.UniversalApiContractV5_IsAvailable;
Debug.Log(text.text);
}

public void CheckV4Api()
{
text.text = "UniversalApiContract\nVersion 4 available? " + HoloToolkit.WindowsApiChecker.UniversalApiContractV4_IsAvailable;
Debug.Log(text.text);
}

public void CheckV3Api()
{
text.text = "UniversalApiContract\nVersion 3 available? " + HoloToolkit.WindowsApiChecker.UniversalApiContractV3_IsAvailable;
Debug.Log(text.text);
}
}
13 changes: 13 additions & 0 deletions Assets/HoloToolkit-Examples/Utilities/Scripts/CheckApiTest.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace HoloToolkit.Unity
/// </summary>
public class BuildDeployTools
{
public static readonly string DefaultMSBuildVersion = "14.0";
public static readonly string DefaultMSBuildVersion = "15.0";

public static bool CanBuild()
{
Expand Down
36 changes: 9 additions & 27 deletions Assets/HoloToolkit/BuildAndDeploy/Editor/BuildDeployWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public class BuildDeployWindow : EditorWindow

private enum BuildPlatformEnum
{
AnyCPU = 0,
x86 = 1,
x64 = 2
}
Expand Down Expand Up @@ -299,11 +298,9 @@ private void OnGUI()
GUILayout.BeginHorizontal();

// SDK and MS Build Version(and save setting, if it's changed)
string curMSBuildVer = BuildDeployPrefs.MsBuildVersion;
string currentSDKVersion = EditorUserBuildSettings.wsaUWPSDK;

int currentSDKVersionIndex = 0;
int defaultMSBuildVersionIndex = -1;

for (var i = 0; i < windowsSdkPaths.Length; i++)
{
Expand All @@ -313,19 +310,19 @@ private void OnGUI()
}
else
{
if (windowsSdkPaths[i].Equals(currentSDKVersion))
if (windowsSdkPaths[i].Equals("10.0.16299.0"))
{
currentSDKVersionIndex = i;
}

if (windowsSdkPaths[i].Equals("10.0.14393.0"))
{
defaultMSBuildVersionIndex = i;
}
}
}

currentSDKVersionIndex = EditorGUILayout.Popup(GUIHorizontalSpacer + "SDK Version", currentSDKVersionIndex, windowsSdkPaths);
if (currentSDKVersionIndex == 0)
{
Debug.LogError("Unable to find the required Windows 10 SDK Target!\nPlease be sure to install the 10.0.16299.0 SDK from Visual Studio Installer.");
}

EditorGUILayout.LabelField(GUIHorizontalSpacer + "Required SDK Version: 10.0.16299.0");

var curScriptingBackend = PlayerSettings.GetScriptingBackend(BuildTargetGroup.WSA);
var newScriptingBackend = (ScriptingImplementation)EditorGUILayout.IntPopup(
Expand All @@ -346,14 +343,6 @@ private void OnGUI()
EditorUserBuildSettings.wsaUWPSDK = newSDKVersion;
}

string newMSBuildVer = currentSDKVersionIndex <= defaultMSBuildVersionIndex ? BuildDeployTools.DefaultMSBuildVersion : "15.0";

if (!newMSBuildVer.Equals(curMSBuildVer))
{
BuildDeployPrefs.MsBuildVersion = newMSBuildVer;
curMSBuildVer = newMSBuildVer;
}

GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();

Expand Down Expand Up @@ -386,7 +375,7 @@ private void OnGUI()

// Build Platform (and save setting, if it's changed)
string curBuildPlatformString = BuildDeployPrefs.BuildPlatform;
BuildPlatformEnum buildPlatformOption;
BuildPlatformEnum buildPlatformOption = BuildPlatformEnum.x86;

if (curBuildPlatformString.ToLower().Equals("x86"))
{
Expand All @@ -396,20 +385,13 @@ private void OnGUI()
{
buildPlatformOption = BuildPlatformEnum.x64;
}
else
{
buildPlatformOption = BuildPlatformEnum.AnyCPU;
}

buildPlatformOption = (BuildPlatformEnum)EditorGUILayout.EnumPopup(GUIHorizontalSpacer + "Build Platform", buildPlatformOption);

string newBuildPlatformString;

switch (buildPlatformOption)
{
case BuildPlatformEnum.AnyCPU:
newBuildPlatformString = "Any CPU";
break;
case BuildPlatformEnum.x86:
case BuildPlatformEnum.x64:
newBuildPlatformString = buildPlatformOption.ToString();
Expand Down Expand Up @@ -472,7 +454,7 @@ private void OnGUI()
EditorApplication.delayCall += () =>
BuildDeployTools.BuildAppxFromSLN(
PlayerSettings.productName,
curMSBuildVer,
BuildDeployTools.DefaultMSBuildVersion,
curForceRebuildAppx,
curBuildConfigString,
curBuildPlatformString,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ public static void StartHaptics(this InteractionSource interactionSource, float

public static void StartHaptics(this InteractionSource interactionSource, float intensity, float durationInSeconds)
{
if (!WindowsApiChecker.UniversalApiContractV4_IsAvailable)
{
return;
}

#if !UNITY_EDITOR && UNITY_2017_2_OR_NEWER
UnityEngine.WSA.Application.InvokeOnUIThread(() =>
{
Expand Down Expand Up @@ -69,6 +74,11 @@ public static void StartHaptics(this InteractionSource interactionSource, float

public static void StopHaptics(this InteractionSource interactionSource)
{
if (!WindowsApiChecker.UniversalApiContractV4_IsAvailable)
{
return;
}

#if !UNITY_EDITOR && UNITY_2017_2_OR_NEWER
UnityEngine.WSA.Application.InvokeOnUIThread(() =>
{
Expand All @@ -90,18 +100,21 @@ public static IAsyncOperation<IRandomAccessStreamWithContentType> TryGetRenderab
{
IAsyncOperation<IRandomAccessStreamWithContentType> returnValue = null;

UnityEngine.WSA.Application.InvokeOnUIThread(() =>
if (WindowsApiChecker.UniversalApiContractV5_IsAvailable)
{
IReadOnlyList<SpatialInteractionSourceState> sources = SpatialInteractionManager.GetForCurrentView().GetDetectedSourcesAtTimestamp(PerceptionTimestampHelper.FromHistoricalTargetTime(DateTimeOffset.Now));

foreach (SpatialInteractionSourceState sourceState in sources)
UnityEngine.WSA.Application.InvokeOnUIThread(() =>
{
if (sourceState.Source.Id.Equals(interactionSource.id))
IReadOnlyList<SpatialInteractionSourceState> sources = SpatialInteractionManager.GetForCurrentView().GetDetectedSourcesAtTimestamp(PerceptionTimestampHelper.FromHistoricalTargetTime(DateTimeOffset.Now));

foreach (SpatialInteractionSourceState sourceState in sources)
{
returnValue = sourceState.Source.Controller.TryGetRenderableModelAsync();
if (sourceState.Source.Id.Equals(interactionSource.id))
{
returnValue = sourceState.Source.Controller.TryGetRenderableModelAsync();
}
}
}
}, true);
}, true);
}

return returnValue;
}
Expand Down
41 changes: 41 additions & 0 deletions Assets/HoloToolkit/Utilities/Scripts/WindowsApiChecker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

namespace HoloToolkit
{
/// <summary>
/// Helper class for determining if a Windows API contract is available.
/// <remarks> See https://docs.microsoft.com/en-us/uwp/extension-sdks/windows-universal-sdk
/// for a full list of contracts.</remarks>
/// </summary>
public static class WindowsApiChecker
{
static WindowsApiChecker()
{
#if !UNITY_EDITOR && UNITY_WSA
UniversalApiContractV5_IsAvailable = Windows.Foundation.Metadata.ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 5);
UniversalApiContractV4_IsAvailable = Windows.Foundation.Metadata.ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 4);
UniversalApiContractV3_IsAvailable = Windows.Foundation.Metadata.ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 3);
#else
UniversalApiContractV5_IsAvailable = false;
UniversalApiContractV4_IsAvailable = false;
UniversalApiContractV3_IsAvailable = false;
#endif
}

/// <summary>
/// Is the Universal API Contract v5.0 Available?
/// </summary>
public static bool UniversalApiContractV5_IsAvailable { get; private set; }

/// <summary>
/// Is the Universal API Contract v4.0 Available?
/// </summary>
public static bool UniversalApiContractV4_IsAvailable { get; private set; }

/// <summary>
/// Is the Universal API Contract v3.0 Available?
/// </summary>
public static bool UniversalApiContractV3_IsAvailable { get; private set; }
}
}
13 changes: 13 additions & 0 deletions Assets/HoloToolkit/Utilities/Scripts/WindowsApiChecker.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 11 additions & 10 deletions GettingStarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@ Be sure to enable Developer mode for Windows 10 via:

If you have not already, download and install [Visual Studio 2017](https://www.visualstudio.com/vs/) and these required components:

- Windows Universal Platform Development Workload
- Windows SDK 10.16299.10
- Visual Studio Tools for Unity
- msbuild
- Nuget Package Manager

![Visual Studio Components](/External/ReadMeImages/VisualStudioComponents.PNG)

You can install more components and UWP SDK's as you wish.

Make sure you are running the appropriate version of Unity 3D on your machine. You should [download and install the latest version](https://unity3d.com/get-unity/download/archive) this project says it supports on the [main readme page](/README.md).

[unity-release]: https://unity3d.com/unity/whats-new/unity-2017.1.2
[unity-version-badge]: https://img.shields.io/badge/Latest%20Release%20For%20HoloLens-2017.1.2-blue.svg

[unity-beta-release]: http://beta.unity3d.com/download/b1565bfe4a0c/download.html
[unity-beta-version-badge]: https://img.shields.io/badge/Latest%20Mixed%20Reality%20Technical%20Preview-2017.2.0p1%20MRTP4-green.svg
[unity-release]: http://beta.unity3d.com/download/b1565bfe4a0c/download.html
[unity-version-badge]: https://img.shields.io/badge/Latest%20Mixed%20Reality%20Technical%20Preview-2017.2.0p1%20MRTP4-green.svg

> The Mixed Reality Toolkit now supports the following Unity 3D versions:
>
> The Mixed Reality Toolkit now recommends the following Unity 3D version:
> [![Github Release][unity-version-badge]][unity-release]
>
> [![Github Release][unity-beta-version-badge]][unity-beta-release]

_Note: Be sure to include the Windows Store .NET scripting backend components._

Expand All @@ -49,7 +49,7 @@ You can download the latest unity package from [Releases](https://github.com/Mic

_Note: The latest release should work for both HoloLens and Windows Mixed Reality development._

[unity-release1]: https://github.com/Microsoft/MixedRealityToolkit-Unity/releases/latest
[unity-release1]: https://github.com/Microsoft/MixedRealityToolkit-Unity/releases/latest
[mrtk-version-badge]: https://img.shields.io/github/tag/microsoft/MixedRealityToolkit-unity.svg?style=flat-square&label=Latest%20Master%20Branch%20Release&colorB=007ec6
[![Github Release][mrtk-version-badge]][unity-release1]

Expand Down Expand Up @@ -143,6 +143,7 @@ This window offers many quick options to be able to:

![Build Window](/External/ReadMeImages/BuildWindow.PNG)

_Note: You should always target the lastest Windows SDK in all builds._

## 5.1 Running your project for **Immersive Headsets**
Unity supports running your Immersive solution direct from the editor **BUT** Only when the Mixed Reality Portal is running.
Expand Down
12 changes: 2 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,9 @@ _Note: The latest release should work for both HoloLens and Windows Mixed Realit
[unity-version-badge]: https://img.shields.io/badge/Current%20Unity%20Editor%20Version-2017.2.0p1%20MRTP4-green.svg
[![Github Release][unity-version-badge]][unity-download]

[unity-release]: https://unity3d.com/unity/whats-new/unity-2017.1.2
[hololens-rel-badge]: https://img.shields.io/badge/Unity%20Editor%20HoloLens%20Version-2017.1.2f1-blue.svg

Check out the updates from the [Fall Creators update](/FallCreatorsUpdate.md) for Windows Mixed Reality

> ## HoloLens Developers
> Currently we are waiting on a fix for HoloLens development from Unity, for now you should use the 2017.1.2 version of Unity and the "Release" version of the MRTK Asset:
>
> [![Github Release][hololens-rel-badge]][unity-release]
> Check out the updates from the [Fall Creators update](/FallCreatorsUpdate.md) for Windows Mixed Reality.
>
> ### For existing HoloLens developers, also check out the [Breaking Changes](/BreakingChanges.md) information from the previous release.
> Check out the [Breaking Changes](/BreakingChanges.md) from the previous release.

Looking to upgrade your projects to Windows Mixed Reality? [Follow the Upgrade Guide](/UpgradeGuide.md).

Expand Down