Skip to content
This repository has been archived by the owner on Jun 10, 2022. It is now read-only.

[Unity] Permission system #203

Merged
merged 8 commits into from
Jun 30, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions MRETestBed/Assets/Scenes/HelloWorld.unity
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ MonoBehaviour:
UserProperties: []
AutoStart: 0
AutoJoin: 1
GrantedPermissions: -1
SceneRoot: {fileID: 1141388990}
PlaceholderObject: {fileID: 0}
UserGameObject: {fileID: 276664683}
Expand Down
3 changes: 2 additions & 1 deletion MRETestBed/Assets/Scenes/Standalone.unity
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ RenderSettings:
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 1966163892}
m_IndirectSpecularColor: {r: 0.45135534, g: 0.5009366, b: 0.5727883, a: 1}
m_IndirectSpecularColor: {r: 0.45135576, g: 0.500937, b: 0.57278883, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
Expand Down Expand Up @@ -234,6 +234,7 @@ MonoBehaviour:
UserProperties: []
AutoStart: 0
AutoJoin: 1
GrantedPermissions: -1
SceneRoot: {fileID: 1141388990}
PlaceholderObject: {fileID: 0}
UserGameObject: {fileID: 276664683}
Expand Down
2 changes: 2 additions & 0 deletions MRETestBed/Assets/Scenes/SynchronizationTest-localhost.unity
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ MonoBehaviour:
UserProperties: []
AutoStart: 0
AutoJoin: 1
GrantedPermissions: -1
SceneRoot: {fileID: 368773028}
PlaceholderObject: {fileID: 164408130}
UserGameObject: {fileID: 1767571516}
Expand Down Expand Up @@ -517,6 +518,7 @@ MonoBehaviour:
UserProperties: []
AutoStart: 0
AutoJoin: 1
GrantedPermissions: -1
SceneRoot: {fileID: 1141388990}
PlaceholderObject: {fileID: 582437838}
UserGameObject: {fileID: 1767571516}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ RenderSettings:
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0.44657874, g: 0.49641258, b: 0.5748172, a: 1}
m_IndirectSpecularColor: {r: 0.44657898, g: 0.4964133, b: 0.5748178, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
Expand Down Expand Up @@ -435,6 +435,7 @@ MonoBehaviour:
UserProperties: []
AutoStart: 0
AutoJoin: 1
GrantedPermissions: -1
SceneRoot: {fileID: 18576793}
PlaceholderObject: {fileID: 0}
UserGameObject: {fileID: 365627181}
Expand Down
16 changes: 10 additions & 6 deletions MRETestBed/Assets/TestBed Assets/Scripts/MREComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using MixedRealityExtension.API;
using MixedRealityExtension.App;
using MixedRealityExtension.Assets;
using MixedRealityExtension.Core.Interfaces;
using MixedRealityExtension.Core;
using MixedRealityExtension.Factories;
using MixedRealityExtension.PluginInterfaces;
using MixedRealityExtension.RPC;
Expand Down Expand Up @@ -62,6 +62,9 @@ public class UserProperty

public bool AutoJoin = true;

[SerializeField]
private Permissions GrantedPermissions;

public Transform SceneRoot;

public GameObject PlaceholderObject;
Expand Down Expand Up @@ -131,7 +134,6 @@ void Start()
defaultMaterial: DefaultPrimMaterial,
layerApplicator: new SimpleLayerApplicator(0, 9, 10, 5),
assetCache: assetCache,
behaviorFactory: new BehaviorFactory(),
textFactory: new TmpTextFactory()
{
DefaultFont = DefaultFont,
Expand All @@ -140,12 +142,14 @@ void Start()
MonospaceFont = MonospaceFont,
CursiveFont = CursiveFont
},
libraryFactory: new ResourceFactory(),
userInfoProvider: new UserInfoProvider(),
permissionManager: new SimplePermissionManager(GrantedPermissions),
behaviorFactory: new BehaviorFactory(),
dialogFactory: DialogFactory,
logger: new MRELogger(),
libraryFactory: new ResourceFactory(),
gltfImporterFactory: new VertexShadedGltfImporterFactory(),
materialPatcher: new VertexMaterialPatcher(),
gltfImporterFactory: new VertexShadedGltfImporterFactory()
userInfoProvider: new UserInfoProvider(),
logger: new MRELogger()
);
_apiInitialized = true;
}
Expand Down
2 changes: 2 additions & 0 deletions MRETestBed_MRTK/Assets/Scenes/HelloWorld_2D.unity
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ MonoBehaviour:
UserProperties: []
AutoStart: 0
AutoJoin: 1
GrantedPermissions: -1
SceneRoot: {fileID: 1141388990}
PlaceholderObject: {fileID: 0}
UserGameObject: {fileID: 276664683}
Expand All @@ -252,6 +253,7 @@ MonoBehaviour:
DefaultPrimMaterial: {fileID: 2100000, guid: 265cb5b418966a64ea212597d469fa33, type: 2}
DialogFactory: {fileID: 114153473817070278, guid: f1f77a0b742ec0841858c35dc9348515,
type: 3}
EnableMRTK: 0
--- !u!114 &1141388992
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down
1 change: 1 addition & 0 deletions MRETestBed_MRTK/Assets/Scenes/Localhost_MRTK.unity
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ MonoBehaviour:
UserProperties: []
AutoStart: 0
AutoJoin: 1
GrantedPermissions: -1
SceneRoot: {fileID: 1141388990}
PlaceholderObject: {fileID: 0}
UserGameObject: {fileID: 276568010}
Expand Down
4 changes: 3 additions & 1 deletion MRETestBed_MRTK/Assets/Scenes/Standalone_2D.unity
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ RenderSettings:
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 1966163892}
m_IndirectSpecularColor: {r: 0.45135534, g: 0.5009366, b: 0.5727883, a: 1}
m_IndirectSpecularColor: {r: 0.45135576, g: 0.500937, b: 0.57278883, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
Expand Down Expand Up @@ -234,6 +234,7 @@ MonoBehaviour:
UserProperties: []
AutoStart: 0
AutoJoin: 1
GrantedPermissions: -1
SceneRoot: {fileID: 1141388990}
PlaceholderObject: {fileID: 0}
UserGameObject: {fileID: 276664683}
Expand All @@ -244,6 +245,7 @@ MonoBehaviour:
CursiveFont: {fileID: 11400000, guid: b31d2923d654c0e49b3e196355c7878e, type: 2}
DefaultPrimMaterial: {fileID: 2100000, guid: 265cb5b418966a64ea212597d469fa33, type: 2}
DialogFactory: {fileID: 36258468}
EnableMRTK: 0
--- !u!114 &1141388992
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ MonoBehaviour:
UserProperties: []
AutoStart: 0
AutoJoin: 1
GrantedPermissions: -1
SceneRoot: {fileID: 368773028}
PlaceholderObject: {fileID: 164408130}
UserGameObject: {fileID: 1767571516}
Expand All @@ -304,6 +305,7 @@ MonoBehaviour:
DefaultPrimMaterial: {fileID: 2100000, guid: 265cb5b418966a64ea212597d469fa33, type: 2}
DialogFactory: {fileID: 114153473817070278, guid: f1f77a0b742ec0841858c35dc9348515,
type: 3}
EnableMRTK: 0
--- !u!4 &368773028
Transform:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -517,6 +519,7 @@ MonoBehaviour:
UserProperties: []
AutoStart: 0
AutoJoin: 1
GrantedPermissions: -1
SceneRoot: {fileID: 1141388990}
PlaceholderObject: {fileID: 582437838}
UserGameObject: {fileID: 1767571516}
Expand All @@ -528,6 +531,7 @@ MonoBehaviour:
DefaultPrimMaterial: {fileID: 2100000, guid: 265cb5b418966a64ea212597d469fa33, type: 2}
DialogFactory: {fileID: 114153473817070278, guid: f1f77a0b742ec0841858c35dc9348515,
type: 3}
EnableMRTK: 0
--- !u!1 &1256608368
GameObject:
m_ObjectHideFlags: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ RenderSettings:
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0.44657874, g: 0.49641258, b: 0.5748172, a: 1}
m_IndirectSpecularColor: {r: 0.44657898, g: 0.4964133, b: 0.5748178, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
Expand Down Expand Up @@ -435,6 +435,7 @@ MonoBehaviour:
UserProperties: []
AutoStart: 0
AutoJoin: 1
GrantedPermissions: -1
SceneRoot: {fileID: 18576793}
PlaceholderObject: {fileID: 0}
UserGameObject: {fileID: 365627181}
Expand All @@ -446,6 +447,7 @@ MonoBehaviour:
DefaultPrimMaterial: {fileID: 2100000, guid: 265cb5b418966a64ea212597d469fa33, type: 2}
DialogFactory: {fileID: 114153473817070278, guid: f1f77a0b742ec0841858c35dc9348515,
type: 3}
EnableMRTK: 0
--- !u!1 &2044912625
GameObject:
m_ObjectHideFlags: 0
Expand Down
15 changes: 10 additions & 5 deletions MRETestBed_MRTK/Assets/TestBed Assets/Scripts/MREComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using MixedRealityExtension.API;
using MixedRealityExtension.App;
using MixedRealityExtension.Assets;
using MixedRealityExtension.Core;
using MixedRealityExtension.Core.Interfaces;
using MixedRealityExtension.Factories;
using MixedRealityExtension.PluginInterfaces;
Expand Down Expand Up @@ -63,6 +64,9 @@ public class UserProperty

public bool AutoJoin = true;

[SerializeField]
private Permissions GrantedPermissions;

public Transform SceneRoot;

public GameObject PlaceholderObject;
Expand Down Expand Up @@ -135,7 +139,6 @@ void Start()
defaultMaterial: DefaultPrimMaterial,
layerApplicator: new SimpleLayerApplicator(0, 9, 10, 5),
assetCache: assetCache,
behaviorFactory: new MRTKBehaviorFactory(),
textFactory: new TmpTextFactory()
{
DefaultFont = DefaultFont,
Expand All @@ -144,12 +147,14 @@ void Start()
MonospaceFont = MonospaceFont,
CursiveFont = CursiveFont
},
libraryFactory: new ResourceFactory(),
userInfoProvider: new UserInfoProvider(),
permissionManager: new SimplePermissionManager(GrantedPermissions),
behaviorFactory: new BehaviorFactory(),
dialogFactory: DialogFactory,
logger: new MRELogger(),
libraryFactory: new ResourceFactory(),
gltfImporterFactory: new VertexShadedGltfImporterFactory(),
materialPatcher: new VertexMaterialPatcher(),
gltfImporterFactory: new VertexShadedGltfImporterFactory()
userInfoProvider: new UserInfoProvider(),
logger: new MRELogger()
);
_apiInitialized = true;
}
Expand Down
35 changes: 24 additions & 11 deletions MREUnityRuntime/MREUnityRuntimeLib/API/MREApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,43 +26,54 @@ public static class MREAPI
/// <param name="defaultMaterial">The material template used for all SDK-spawned meshes.</param>
/// <param name="layerApplicator">The class used to apply MRE layers to Unity colliders.</param>
/// <param name="assetCache">The class responsible for long-term asset caching.</param>
/// <param name="behaviorFactory">The behavior factory to use within the runtime.</param>
/// <param name="textFactory">The text factory to use within the runtime.</param>
/// <param name="primitiveFactory">The primitive factory to use within the runtime.</param>
/// <param name="permissionManager">The instance responsible for presenting users with permission requests.</param>
/// <param name="behaviorFactory">The behavior factory to use within the runtime.</param>
/// <param name="dialogFactory"></param>
/// <param name="libraryFactory">The library resource factory to use within the runtime.</param>
/// <param name="videoPlayerFactory"></param>
/// <param name="primitiveFactory">The primitive factory to use within the runtime.</param>
/// <param name="gltfImporterFactory">The glTF loader factory. Uses default GLTFSceneImporter if omitted.</param>
/// <param name="materialPatcher">Overrides default material property map (color and mainTexture only).</param>
/// <param name="videoPlayerFactory"></param>
/// <param name="userInfoProvider">Provides appId/sessionId scoped IUserInfo instances.</param>
/// <param name="dialogFactory"></param>
/// <param name="logger">The logger to be used by the MRE SDK.</param>
public static void InitializeAPI(
// required properties
UnityEngine.Material defaultMaterial,
ILayerApplicator layerApplicator,
IAssetCache assetCache,
ITextFactory textFactory,
IPermissionManager permissionManager,
// missing features if omitted
IBehaviorFactory behaviorFactory = null,
ITextFactory textFactory = null,
IPrimitiveFactory primitiveFactory = null,
IDialogFactory dialogFactory = null,
ILibraryResourceFactory libraryFactory = null,
IVideoPlayerFactory videoPlayerFactory = null,
// reasonable defaults provided
IPrimitiveFactory primitiveFactory = null,
IGLTFImporterFactory gltfImporterFactory = null,
IMaterialPatcher materialPatcher = null,
IVideoPlayerFactory videoPlayerFactory = null,
IUserInfoProvider userInfoProvider = null,
IDialogFactory dialogFactory = null,
IMRELogger logger = null)
{
// required properties
AppsAPI.DefaultMaterial = defaultMaterial;
AppsAPI.LayerApplicator = layerApplicator;
AppsAPI.AssetCache = assetCache;
AppsAPI.TextFactory = textFactory;
AppsAPI.PermissionManager = permissionManager;

// missing features if omitted
AppsAPI.BehaviorFactory = behaviorFactory;
AppsAPI.TextFactory = textFactory ?? throw new ArgumentException($"{nameof(textFactory)} cannot be null");
AppsAPI.PrimitiveFactory = primitiveFactory ?? new MWPrimitiveFactory();
AppsAPI.DialogFactory = dialogFactory;
AppsAPI.LibraryResourceFactory = libraryFactory;
AppsAPI.VideoPlayerFactory = videoPlayerFactory;

// reasonable defaults provided
AppsAPI.PrimitiveFactory = primitiveFactory ?? new MWPrimitiveFactory();
AppsAPI.GLTFImporterFactory = gltfImporterFactory ?? new GLTFImporterFactory();
AppsAPI.MaterialPatcher = materialPatcher ?? new DefaultMaterialPatcher();
AppsAPI.UserInfoProvider = userInfoProvider ?? new NullUserInfoProvider();
AppsAPI.DialogFactory = dialogFactory;

#if ANDROID_DEBUG
Logger = logger ?? new UnityLogger(null);
Expand Down Expand Up @@ -128,6 +139,8 @@ public class MREAppsAPI

internal IDialogFactory DialogFactory { get; set; }

internal IPermissionManager PermissionManager { get; set; }

/// <summary>
/// Creates a new mixed reality extension app and adds it to the MRE runtime.
/// </summary>
Expand Down
69 changes: 69 additions & 0 deletions MREUnityRuntime/MREUnityRuntimeLib/App/AppManifest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using MixedRealityExtension.Core;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace MixedRealityExtension.Core
{
/// <summary>
/// Class containing author-provided metadata about an MRE instance
/// </summary>
public class AppManifest
{
/// <summary>
/// A human-readable name for this MRE
/// </summary>
public string Name;

/// <summary>
/// A human readable description of this MRE's behavior
/// </summary>
public string Description;

/// <summary>
/// The MRE's author name and/or contact information
/// </summary>
public string Author;

/// <summary>
/// The license for the MRE's source code
/// </summary>
public string License;

/// <summary>
/// The location of the MRE's public source code
/// </summary>
public string RepositoryUri;
Copy link
Member

@tombuMS tombuMS Jun 29, 2020

Choose a reason for hiding this comment

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

Uri [](start = 26, length = 3)

Url #Resolved


/// <summary>
/// A list of permissions required for this MRE to run
/// </summary>
public Permissions[] Permissions;

/// <summary>
/// A list of permissions that this MRE can use, but are not required
/// </summary>
public Permissions[] OptionalPermissions;

internal static async Task<AppManifest> DownloadManifest(Uri manifestUri)
{
var webClient = new HttpClient();
var response = await webClient.GetAsync(manifestUri, HttpCompletionOption.ResponseContentRead);
if (response.IsSuccessStatusCode)
{
var manifestString = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<AppManifest>(manifestString, Constants.SerializerSettings);
}
else
{
return new AppManifest();
}
}
}
}
Loading