├── .editorconfig
├── .gitattributes
├── .gitignore
├── CONTRIBUTING.md
├── Documentation
└── MRE-Unity-Runtime-Documentation.chm
├── INTEGRATING.md
├── LICENSE
├── Libraries
├── GLTFSerialization.dll
├── GLTFSerialization.pdb
├── LIBRARIES.md
├── Newtonsoft.Json.dll
├── Newtonsoft.Json.pdb
├── Newtonsoft.Json.xml
├── UnityGLTF.dll
└── UnityGLTF.pdb
├── MREUnityProjects.default.xml
├── MREUnityRuntime.shfbproj
├── MREUnityRuntime.sln
├── MREUnityRuntimeLib
├── API
│ └── MREApi.cs
├── Animation
│ ├── Animation.cs
│ ├── AnimationEvent.cs
│ ├── AnimationKeyframe.cs
│ ├── AnimationManager.cs
│ ├── AnimationState.cs
│ ├── AnimationWrapMode.cs
│ ├── BaseAnimation.cs
│ ├── Definitions.cs
│ ├── Interpolations.cs
│ ├── JTokenPool.cs
│ ├── MWSetAnimationStateOptions.cs
│ ├── NativeAnimation.cs
│ └── TargetPath.cs
├── App
│ ├── AppManifest.cs
│ ├── IMixedRealityExtensionApp.cs
│ └── MixedRealityExtensionApp.cs
├── Assets
│ ├── AssetCache.cs
│ ├── AssetFetcher.cs
│ ├── AssetGroup.cs
│ ├── AssetLoadThrottling.cs
│ ├── AssetLoader.cs
│ ├── AssetManager.cs
│ ├── AssetSource.cs
│ ├── Definitions.cs
│ └── PrefabAnimationTargets.cs
├── Behaviors
│ ├── ActionData
│ │ ├── BaseActionData.cs
│ │ ├── BaseToolData.cs
│ │ ├── ButtonData.cs
│ │ ├── PenData.cs
│ │ ├── PointData.cs
│ │ └── TargetData.cs
│ ├── Actions
│ │ ├── Action.cs
│ │ └── BehaviorActionHandler.cs
│ ├── Behaviors.cs
│ └── Contexts
│ │ ├── BehaviorContextBase.cs
│ │ ├── BehaviorContextFactory.cs
│ │ ├── ButtonBehaviorContext.cs
│ │ ├── PenBehaviorContext.cs
│ │ ├── PhysicalToolBehaviorContext.cs
│ │ └── TargetBehaviorContext.cs
├── Constants.cs
├── Core
│ ├── Actor.cs
│ ├── ActorCommandQueue.cs
│ ├── ActorManager.cs
│ ├── Attachment.cs
│ ├── Collider.cs
│ ├── ColliderGeometry.cs
│ ├── Collision
│ │ ├── ColliderEventType.cs
│ │ ├── CollisionData.cs
│ │ └── ContactPoint.cs
│ ├── CollisionLayers.cs
│ ├── Components
│ │ ├── ActorComponentBase.cs
│ │ ├── AnimationComponent.cs
│ │ ├── BehaviorComponent.cs
│ │ ├── LookAtComponent.cs
│ │ └── MREAttachmentComponent.cs
│ ├── Interfaces
│ │ ├── IActor.cs
│ │ ├── ICollider.cs
│ │ ├── ILight.cs
│ │ ├── IMixedRealityExtensionObject.cs
│ │ ├── IRigidBody.cs
│ │ ├── IText.cs
│ │ └── IUser.cs
│ ├── Light.cs
│ ├── MediaCommand.cs
│ ├── MediaStateOptions.cs
│ ├── MixedRealityExtensionObject.cs
│ ├── Permissions.cs
│ ├── Physics
│ │ ├── IPrediction.cs
│ │ ├── JitterBuffer.cs
│ │ └── PredictionInterpolation.cs
│ ├── PhysicsBridge.cs
│ ├── PrimitiveDefinition.cs
│ ├── RigidBody.cs
│ ├── SoundManager.cs
│ ├── Text.cs
│ ├── Types
│ │ ├── MWColor.cs
│ │ ├── MWQuaternion.cs
│ │ ├── MWTransform.cs
│ │ ├── MWVector2.cs
│ │ └── MWVector3.cs
│ ├── User.cs
│ ├── UserManager.cs
│ └── VideoStreamDescription.cs
├── Factories
│ ├── DefaultMaterialPatcher.cs
│ ├── GLTFImporterFactory.cs
│ ├── MWPrimitiveFactory.cs
│ ├── MWTextFactory.cs
│ ├── SimpleLayerApplicator.cs
│ └── SimplePermissionsManager.cs
├── IPC
│ ├── Connections
│ │ └── WebSocket.cs
│ └── IConnection.cs
├── LookAtMode.cs
├── MREUnityRuntimeLib.csproj
├── Messaging
│ ├── Commands
│ │ ├── Command.cs
│ │ ├── CommandHandler.cs
│ │ ├── CommandManager.cs
│ │ ├── ICommand.cs
│ │ ├── ICommandHandlerContext.cs
│ │ ├── ICommandManager.cs
│ │ └── ICommandPayload.cs
│ ├── Events
│ │ ├── IMWEvent.cs
│ │ ├── MWEventBase.cs
│ │ ├── MWEventManager.cs
│ │ └── Types
│ │ │ ├── ActorChangedEvent.cs
│ │ │ ├── ActorCorrectionEvent.cs
│ │ │ ├── BehaviorEvent.cs
│ │ │ ├── ColliderEvent.cs
│ │ │ ├── PhysicsBridgeUpdated.cs
│ │ │ ├── ResponseEvent.cs
│ │ │ ├── SetAnimationStateEvent.cs
│ │ │ ├── TriggerEvent.cs
│ │ │ └── UserEvent.cs
│ ├── Message.cs
│ ├── Payloads
│ │ ├── AssetCommandPayloads.cs
│ │ ├── Converters
│ │ │ ├── CollisionGeometryConverter.cs
│ │ │ ├── DashFormattedEnumConverter.cs
│ │ │ └── UnsignedConverter.cs
│ │ ├── IPayload.cs
│ │ ├── NetworkCommandPayloads.cs
│ │ ├── Payload.cs
│ │ ├── PayloadConverter.cs
│ │ ├── PayloadTypeRegistry.cs
│ │ └── Payloads.cs
│ ├── Protocols
│ │ ├── Execution.cs
│ │ ├── Handshake.cs
│ │ ├── IProtocol.cs
│ │ ├── Idle.cs
│ │ ├── Protocol.cs
│ │ └── Sync.cs
│ └── Tracing.cs
├── Patching
│ ├── IPatchable.cs
│ ├── PatchProperty.cs
│ ├── Patchable.cs
│ ├── PatchingUtils.cs
│ └── Types
│ │ ├── ActorPatch.cs
│ │ ├── ActorTransformPatch.cs
│ │ ├── AnimationPatch.cs
│ │ ├── AppearancePatch.cs
│ │ ├── AttachmentPatch.cs
│ │ ├── ColliderPatch.cs
│ │ ├── ColorPatch.cs
│ │ ├── LightPatch.cs
│ │ ├── LookAtPatch.cs
│ │ ├── PhysicsBridgePatch.cs
│ │ ├── QuaternionPatch.cs
│ │ ├── RigidBodyPatch.cs
│ │ ├── ScaledTransformPatch.cs
│ │ ├── TextPatch.cs
│ │ ├── TransformPatch.cs
│ │ ├── UserPatch.cs
│ │ ├── Vector2Patch.cs
│ │ └── Vector3Patch.cs
├── PluginInterfaces
│ ├── Behaviors
│ │ ├── IBehavior.cs
│ │ ├── IBehaviorFactory.cs
│ │ ├── IButtonBehavior.cs
│ │ ├── IPenBehavior.cs
│ │ ├── ITargetBehavior.cs
│ │ └── IToolBehavior.cs
│ ├── IAssetCache.cs
│ ├── IDialogFactory.cs
│ ├── IGltfImporterFactory.cs
│ ├── IHostAppUser.cs
│ ├── ILayerApplicator.cs
│ ├── ILibraryResourceFactory.cs
│ ├── IMRELogger.cs
│ ├── IMaterialPatcher.cs
│ ├── IPermissionManager.cs
│ ├── IPrimitiveFactory.cs
│ ├── ITextFactory.cs
│ ├── IVideoPlayer.cs
│ └── IVideoPlayerFactory.cs
├── ProceduralToolkit
│ ├── ArrayE.cs
│ ├── CompoundMeshDraft.cs
│ ├── Directions.cs
│ ├── Geometry
│ │ ├── Circle2.cs
│ │ ├── Circle3.cs
│ │ ├── Closest2D.cs
│ │ ├── Closest3D.cs
│ │ ├── Distance2D.cs
│ │ ├── Distance3D.cs
│ │ ├── Geometry.cs
│ │ ├── Intersect2D.cs
│ │ ├── Intersect3D.cs
│ │ ├── IntersectionType.cs
│ │ ├── Intersections
│ │ │ ├── IntersectionCircleCircle.cs
│ │ │ ├── IntersectionLineCircle.cs
│ │ │ ├── IntersectionLineLine2.cs
│ │ │ ├── IntersectionLineRay2.cs
│ │ │ ├── IntersectionLineSegment2.cs
│ │ │ ├── IntersectionLineSphere.cs
│ │ │ ├── IntersectionRayCircle.cs
│ │ │ ├── IntersectionRayRay2.cs
│ │ │ ├── IntersectionRaySegment2.cs
│ │ │ ├── IntersectionRaySphere.cs
│ │ │ ├── IntersectionSegmentCircle.cs
│ │ │ ├── IntersectionSegmentSegment2.cs
│ │ │ ├── IntersectionSegmentSphere.cs
│ │ │ └── IntersectionSphereSphere.cs
│ │ ├── Line2.cs
│ │ ├── Line3.cs
│ │ ├── Segment2.cs
│ │ ├── Segment3.cs
│ │ ├── Sphere.cs
│ │ └── StraightSkeleton
│ │ │ ├── Plan.cs
│ │ │ ├── StraightSkeleton.cs
│ │ │ └── StraightSkeletonGenerator.cs
│ ├── LICENSE.txt
│ ├── MeshDraft.cs
│ ├── MeshDraftPrimitives.cs
│ ├── PTUtils.cs
│ ├── README.md
│ ├── RendererProperties.cs
│ └── VectorE.cs
├── Properties
│ └── AssemblyInfo.cs
├── RPC
│ ├── RPCChannelInterface.cs
│ ├── RPCHandler.cs
│ └── RPCInterface.cs
├── Util
│ ├── CubicBezier.cs
│ ├── DeterministicGuids.cs
│ ├── Logging
│ │ ├── ConsoleLogger.cs
│ │ └── UnityLogger.cs
│ ├── ObjectManager.cs
│ ├── TransformLerper.cs
│ ├── Unity
│ │ ├── MWContinuation.cs
│ │ ├── MWGOTreeWalker.cs
│ │ ├── MWUnityHelpers.cs
│ │ └── MWUnityTypeExtensions.cs
│ └── UtilMethods.cs
└── link.xml
├── PostBuildTool.exe
├── PostBuildTool.exe.config
├── PostBuildTool.pdb
├── README.md
├── ThirdPartyNotices.txt
├── VSO
└── UnityEngine.dll
└── tools
├── PostBuildTool
├── PostBuildTool.sln
└── PostBuildTool
│ ├── App.config
│ ├── PostBuildTool.csproj
│ ├── Program.cs
│ └── Properties
│ └── AssemblyInfo.cs
├── VSCodeAnalysis
└── MRESDK_Ruleset.ruleset
├── add-copyright-headers.ps1
└── vswhere.exe
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*.{cs,ts}]
4 | indent_style = tab
5 | indent_size = 4
6 | insert_final_newline = true
7 | trim_trailing_whitespace = true
8 |
9 | [*.json]
10 | indent_style = space
11 | indent_size = 2
12 | insert_final_newline = true
13 | trim_trailing_whitespace = true
14 |
15 | [*.md]
16 | indent_style = tab
17 | insert_final_newline = true
18 | trim_trailing_whitespace = true
19 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/Documentation/MRE-Unity-Runtime-Documentation.chm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/mixed-reality-extension-unity/4afe6af76284ec15fcb01fd6fbd7616ad2a7e442/Documentation/MRE-Unity-Runtime-Documentation.chm
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) Microsoft Corporation. All rights reserved.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE
22 |
--------------------------------------------------------------------------------
/Libraries/GLTFSerialization.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/mixed-reality-extension-unity/4afe6af76284ec15fcb01fd6fbd7616ad2a7e442/Libraries/GLTFSerialization.dll
--------------------------------------------------------------------------------
/Libraries/GLTFSerialization.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/mixed-reality-extension-unity/4afe6af76284ec15fcb01fd6fbd7616ad2a7e442/Libraries/GLTFSerialization.pdb
--------------------------------------------------------------------------------
/Libraries/LIBRARIES.md:
--------------------------------------------------------------------------------
1 | # Library Dependencies for the Mixed Reality Extension Unity Runtime Library
2 |
3 | ## UnityGLTF.dll and GLTFSerialization.dll
4 |
5 | * Repo: https://github.com/KhronosGroup/UnityGLTF
6 | * SHA of included builds: cfd1eba ([unmerged PR](https://github.com/KhronosGroup/UnityGLTF/pull/585))
7 | * Commit date: May 29, 2020
8 |
9 | ## Newtonsoft.Json.dll, Newtonsoft.Json.pdb and Newtonsoft.Json.xml
10 |
11 | * Repo: https://github.com/AltspaceVR/Newtonsoft.Json
12 | * SHA of included builds: 3e8f1da
13 | * Commit date: January 4, 2019
14 |
--------------------------------------------------------------------------------
/Libraries/Newtonsoft.Json.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/mixed-reality-extension-unity/4afe6af76284ec15fcb01fd6fbd7616ad2a7e442/Libraries/Newtonsoft.Json.dll
--------------------------------------------------------------------------------
/Libraries/Newtonsoft.Json.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/mixed-reality-extension-unity/4afe6af76284ec15fcb01fd6fbd7616ad2a7e442/Libraries/Newtonsoft.Json.pdb
--------------------------------------------------------------------------------
/Libraries/UnityGLTF.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/mixed-reality-extension-unity/4afe6af76284ec15fcb01fd6fbd7616ad2a7e442/Libraries/UnityGLTF.dll
--------------------------------------------------------------------------------
/Libraries/UnityGLTF.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/mixed-reality-extension-unity/4afe6af76284ec15fcb01fd6fbd7616ad2a7e442/Libraries/UnityGLTF.pdb
--------------------------------------------------------------------------------
/MREUnityProjects.default.xml:
--------------------------------------------------------------------------------
1 |
2 | ..\MRETestBed\Assets\Assemblies
3 | ..\MRETestBed_MRTK\Assets\Assemblies
4 |
5 |
--------------------------------------------------------------------------------
/MREUnityRuntime.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.30204.135
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MREUnityRuntime", "MREUnityRuntimeLib\MREUnityRuntimeLib.csproj", "{4D8EA76B-B56F-405E-96BD-15E15B0F3A6A}"
7 | EndProject
8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7F212CBE-229F-457B-89A5-2BE49B856428}"
9 | ProjectSection(SolutionItems) = preProject
10 | ..\.editorconfig = ..\.editorconfig
11 | EndProjectSection
12 | EndProject
13 | Global
14 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
15 | Debug|Any CPU = Debug|Any CPU
16 | Release|Any CPU = Release|Any CPU
17 | EndGlobalSection
18 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
19 | {4D8EA76B-B56F-405E-96BD-15E15B0F3A6A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
20 | {4D8EA76B-B56F-405E-96BD-15E15B0F3A6A}.Debug|Any CPU.Build.0 = Debug|Any CPU
21 | {4D8EA76B-B56F-405E-96BD-15E15B0F3A6A}.Release|Any CPU.ActiveCfg = Release|Any CPU
22 | {4D8EA76B-B56F-405E-96BD-15E15B0F3A6A}.Release|Any CPU.Build.0 = Release|Any CPU
23 | EndGlobalSection
24 | GlobalSection(SolutionProperties) = preSolution
25 | HideSolutionNode = FALSE
26 | EndGlobalSection
27 | GlobalSection(ExtensibilityGlobals) = postSolution
28 | SolutionGuid = {2BD8F979-4D20-454D-B305-EF1F1CEFD7BF}
29 | EndGlobalSection
30 | EndGlobal
31 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Animation/AnimationEvent.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace MixedRealityExtension.Animation
10 | {
11 | ///
12 | /// Animation Event
13 | ///
14 | public class MWAnimationEvent
15 | {
16 | ///
17 | /// The animation event name
18 | ///
19 | public string Name;
20 |
21 | ///
22 | /// The animation event value
23 | ///
24 | public string Value;
25 |
26 | ///
27 | /// The time offset (in seconds) when the animation event should be raised
28 | ///
29 | public float Time;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Animation/AnimationKeyframe.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using MixedRealityExtension.Patching.Types;
4 |
5 | namespace MixedRealityExtension.Animation
6 | {
7 | ///
8 | /// Animation Keyframe
9 | ///
10 | public class MWAnimationKeyframe
11 | {
12 | ///
13 | /// The time offset (in seconds) from the start of the animation when this keyframe should be applied
14 | ///
15 | public float Time;
16 |
17 | ///
18 | /// The value of this keyframe
19 | ///
20 | public ActorPatch Value;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Animation/AnimationState.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace MixedRealityExtension.Animation
10 | {
11 | ///
12 | /// Class that represents the state of an animation.
13 | ///
14 | public class MWActorAnimationState
15 | {
16 | ///
17 | /// The id of the actor of the animation.
18 | ///
19 | public Guid ActorId;
20 |
21 | ///
22 | /// The name of the animation.
23 | ///
24 | public string AnimationName;
25 |
26 | ///
27 | /// All the state options.
28 | ///
29 | public MWSetAnimationStateOptions State;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Animation/AnimationWrapMode.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace MixedRealityExtension.Animation
10 | {
11 | ///
12 | /// Animation Wrap Mode
13 | ///
14 | public enum MWAnimationWrapMode
15 | {
16 | ///
17 | /// At the end of the animation, stop playing and reset time to zero.
18 | ///
19 | Once,
20 |
21 | ///
22 | /// At the end of the animation, restart at the beginning.
23 | ///
24 | Loop,
25 |
26 | ///
27 | /// At the end of the animation, run the animation backward to the beginning, and vice versa.
28 | ///
29 | PingPong,
30 | }
31 |
32 | ///
33 | /// Extension methods for MWAnimationWrapMode enumeration.
34 | ///
35 | public static class MWAnimationWrapModeExtensions
36 | {
37 | ///
38 | /// Returns true if the mode is a looping mode.
39 | ///
40 | ///
41 | ///
42 | public static bool IsLooping(this MWAnimationWrapMode wrapMode)
43 | {
44 | return (wrapMode == MWAnimationWrapMode.Loop || wrapMode == MWAnimationWrapMode.PingPong);
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Animation/JTokenPool.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using Newtonsoft.Json.Linq;
4 | using System.Collections.Generic;
5 |
6 | namespace MixedRealityExtension.Animation
7 | {
8 | internal class JTokenPool
9 | {
10 | public enum TokenPoolType
11 | {
12 | Value = 0,
13 | Vector3,
14 | Quaternion
15 | }
16 |
17 | private readonly Dictionary> TokenPool = new Dictionary>(3)
18 | {
19 | {TokenPoolType.Value, new Stack(5) },
20 | {TokenPoolType.Vector3, new Stack(5) },
21 | {TokenPoolType.Quaternion, new Stack(5) }
22 | };
23 |
24 | ///
25 | /// Produce a JToken of the requested shape
26 | ///
27 | /// The produced token will have the same fields as this token
28 | ///
29 | public JToken Lease(JToken matchingType)
30 | {
31 | return Lease(DetermineType(matchingType));
32 | }
33 |
34 | public JToken Lease(TokenPoolType type)
35 | {
36 | var pool = TokenPool[type];
37 | return pool.Count > 0 ? pool.Pop() : GenerateType(type);
38 | }
39 |
40 | public void Return(JToken token)
41 | {
42 | TokenPool[DetermineType(token)].Push(token);
43 | }
44 |
45 | private TokenPoolType DetermineType(JToken token)
46 | {
47 | if (token.Type == JTokenType.Object)
48 | {
49 | var Token = (JObject)token;
50 | if (Token.ContainsKey("w"))
51 | {
52 | return TokenPoolType.Quaternion;
53 | }
54 | else
55 | {
56 | return TokenPoolType.Vector3;
57 | }
58 | }
59 | else
60 | {
61 | return TokenPoolType.Value;
62 | }
63 | }
64 |
65 | private JToken GenerateType(TokenPoolType type)
66 | {
67 | switch (type)
68 | {
69 | case TokenPoolType.Quaternion:
70 | return new JObject()
71 | {
72 | {"x", new JValue(0) },
73 | {"y", new JValue(0) },
74 | {"z", new JValue(0) },
75 | {"w", new JValue(0) }
76 | };
77 | case TokenPoolType.Vector3:
78 | return new JObject()
79 | {
80 | {"x", new JValue(0) },
81 | {"y", new JValue(0) },
82 | {"z", new JValue(0) }
83 | };
84 | case TokenPoolType.Value:
85 | return new JValue(0);
86 | default:
87 | throw new System.NotSupportedException("Cannot allocate token of unknown type");
88 | }
89 | }
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Animation/MWSetAnimationStateOptions.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace MixedRealityExtension.Animation
10 | {
11 | /**
12 | * Parameters to the `actor.setAnimationState` call. All values are optional. Only supplied value will be applied.
13 | */
14 | public class MWSetAnimationStateOptions
15 | {
16 | /**
17 | * The current animation time (in seconds).
18 | */
19 | public float? Time { get; set; }
20 | /**
21 | * The speed of animation playback. Negative values go backward. Zero is stopped. Animations stopped this way still
22 | * influence the actor transform according to their weight. To remove this animation's influence, set its weight to
23 | * zero using the `actor.setAnimationState` call, or disable it using the `actor.disableAnimation` call.
24 | */
25 | public float? Speed { get; set; }
26 | /**
27 | * Whether or not to enable this animation.
28 | */
29 | public bool? Enabled { get; set; }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Animation/TargetPath.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using TokenPoolType = MixedRealityExtension.Animation.JTokenPool.TokenPoolType;
4 | using ITokenLookup = System.Collections.Generic.IReadOnlyDictionary;
5 | using TokenLookup = System.Collections.Generic.Dictionary;
6 | using System;
7 | using System.Text.RegularExpressions;
8 | using UnityEngine;
9 |
10 | namespace MixedRealityExtension.Animation
11 | {
12 | public class TargetPath
13 | {
14 | internal static readonly ITokenLookup TypeOfPath = new TokenLookup()
15 | {
16 | {"transform/local/position", TokenPoolType.Vector3 },
17 | {"transform/local/position/x", TokenPoolType.Value },
18 | {"transform/local/position/y", TokenPoolType.Value },
19 | {"transform/local/position/z", TokenPoolType.Value },
20 | {"transform/local/rotation", TokenPoolType.Quaternion },
21 | {"transform/local/scale", TokenPoolType.Vector3 },
22 | {"transform/local/scale/x", TokenPoolType.Value },
23 | {"transform/local/scale/y", TokenPoolType.Value },
24 | {"transform/local/scale/z", TokenPoolType.Value },
25 | {"transform/app/position", TokenPoolType.Vector3 },
26 | {"transform/app/position/x", TokenPoolType.Value },
27 | {"transform/app/position/y", TokenPoolType.Value },
28 | {"transform/app/position/z", TokenPoolType.Value },
29 | {"transform/app/rotation", TokenPoolType.Quaternion },
30 | };
31 |
32 | private static Regex PathRegex = new Regex("^(?actor|animation|material):(?[^/]+)/(?.+)$");
33 |
34 | public string TargetPathString { get; }
35 |
36 | public string AnimatibleType { get; }
37 |
38 | public string Placeholder { get; }
39 |
40 | public string Path { get; }
41 |
42 | public string[] PathParts { get; }
43 |
44 | public TargetPath(string pathString)
45 | {
46 | TargetPathString = pathString;
47 | var match = PathRegex.Match(TargetPathString);
48 | try
49 | {
50 | AnimatibleType = match.Groups["type"].ToString();
51 | Placeholder = match.Groups["placeholder"].ToString();
52 | Path = match.Groups["path"].ToString();
53 | PathParts = Path.Split('/');
54 | }
55 | catch (System.Exception e)
56 | {
57 | throw new System.ArgumentException($"{pathString} is not a valid path string.", e);
58 | }
59 | }
60 |
61 | public TargetPath ResolvePlaceholder(Guid id)
62 | {
63 | return new TargetPath($"{AnimatibleType}:{id}/{Path}");
64 | }
65 |
66 | public override int GetHashCode()
67 | {
68 | return TargetPathString.GetHashCode();
69 | }
70 |
71 | public override bool Equals(object obj)
72 | {
73 | return obj != null && GetType() == obj.GetType() && TargetPathString == ((TargetPath)obj).TargetPathString;
74 | }
75 |
76 | public override string ToString()
77 | {
78 | return TargetPathString;
79 | }
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/App/AppManifest.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using MixedRealityExtension.Core;
4 | using Newtonsoft.Json;
5 | using System;
6 | using System.Collections.Generic;
7 | using System.Linq;
8 | using System.Net.Http;
9 | using System.Text;
10 | using System.Threading.Tasks;
11 |
12 | namespace MixedRealityExtension.Core
13 | {
14 | ///
15 | /// Class containing author-provided metadata about an MRE instance
16 | ///
17 | public class AppManifest
18 | {
19 | ///
20 | /// A human-readable name for this MRE
21 | ///
22 | public string Name;
23 |
24 | ///
25 | /// A human readable description of this MRE's behavior
26 | ///
27 | public string Description;
28 |
29 | ///
30 | /// The MRE's author name and/or contact information
31 | ///
32 | public string Author;
33 |
34 | ///
35 | /// The license for the MRE's source code
36 | ///
37 | public string License;
38 |
39 | ///
40 | /// The location of the MRE's public source code
41 | ///
42 | public string RepositoryUrl;
43 |
44 | ///
45 | /// A list of permissions required for this MRE to run
46 | ///
47 | public Permissions[] Permissions;
48 |
49 | ///
50 | /// A list of permissions that this MRE can use, but are not required
51 | ///
52 | public Permissions[] OptionalPermissions;
53 |
54 | internal static async Task DownloadManifest(Uri manifestUri)
55 | {
56 | var webClient = new HttpClient();
57 | var response = await webClient.GetAsync(manifestUri, HttpCompletionOption.ResponseContentRead);
58 | response.EnsureSuccessStatusCode();
59 |
60 | var manifestString = await response.Content.ReadAsStringAsync();
61 | return JsonConvert.DeserializeObject(manifestString, Constants.SerializerSettings);
62 | }
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Assets/AssetGroup.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using System;
4 | using System.Collections.Generic;
5 |
6 | namespace MixedRealityExtension.Assets
7 | {
8 | ///
9 | /// Contains the assets loaded from a particular container.
10 | ///
11 | public struct AssetGroup
12 | {
13 | ///
14 | /// The origin of these assets.
15 | ///
16 | public AssetSource Source;
17 |
18 | ///
19 | /// The loaded assets.
20 | ///
21 | public Dictionary Assets;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Assets/AssetLoadThrottling.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using System;
4 | using System.Threading.Tasks;
5 | using UnityEngine;
6 |
7 | namespace MixedRealityExtension.Assets
8 | {
9 | ///
10 | /// Global asset load web request throttler.
11 | ///
12 | internal static class AssetLoadThrottling
13 | {
14 | // Global: Keep track of the number of active asset fetch web requests.
15 | const int MaxActiveLoads = 4;
16 | private static int ActiveLoads = 0;
17 |
18 | public static bool WouldThrottle()
19 | {
20 | return ActiveLoads >= MaxActiveLoads;
21 | }
22 |
23 | public static async Task AcquireLoadScope()
24 | {
25 | // Spin asynchronously until there is room for this load scope.
26 | while (WouldThrottle())
27 | {
28 | await Task.Delay(10);
29 | }
30 |
31 | return new AssetLoadScope();
32 | }
33 |
34 | public class AssetLoadScope : IDisposable
35 | {
36 | public AssetLoadScope()
37 | {
38 | ++ActiveLoads;
39 | }
40 |
41 | private bool disposedValue = false;
42 |
43 | protected virtual void Dispose(bool disposing)
44 | {
45 | if (!disposedValue)
46 | {
47 | if (disposing)
48 | {
49 | --ActiveLoads;
50 | }
51 | disposedValue = true;
52 | }
53 | }
54 |
55 | public void Dispose()
56 | {
57 | Dispose(true);
58 | }
59 | }
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Assets/AssetSource.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using System;
4 |
5 | namespace MixedRealityExtension.Assets
6 | {
7 | ///
8 | /// Documents the origin of an asset.
9 | /// NOTE: The InternalId is not used for equality testing.
10 | ///
11 | public class AssetSource
12 | {
13 | ///
14 | /// The type of container the asset came from.
15 | ///
16 | public AssetContainerType ContainerType { get; set; }
17 |
18 | ///
19 | /// The URL of the asset's container.
20 | ///
21 | public string Uri { get; set; }
22 |
23 | ///
24 | /// The version of the resource at the Uri that this asset came from. Will typically be an HTTP ETag.
25 | ///
26 | [Newtonsoft.Json.JsonIgnore]
27 | public string Version { get; set; }
28 |
29 | private Uri parsedUri;
30 | ///
31 | /// The parsed URI of the asset's container.
32 | ///
33 | [Newtonsoft.Json.JsonIgnore]
34 | public Uri ParsedUri
35 | {
36 | get => parsedUri = parsedUri ?? new Uri(Uri, UriKind.RelativeOrAbsolute);
37 | set {
38 | parsedUri = value;
39 | Uri = parsedUri.ToString();
40 | }
41 | }
42 |
43 | ///
44 | /// The location of the asset within the container. Type-dependent.
45 | ///
46 | public string InternalId { get; set; }
47 |
48 | public AssetSource() { }
49 |
50 | public AssetSource(
51 | AssetContainerType containerType = AssetContainerType.GLTF,
52 | string uri = null,
53 | string internalId = null,
54 | string version = null)
55 | {
56 | ContainerType = containerType;
57 | Uri = uri;
58 | InternalId = internalId;
59 | Version = version;
60 | }
61 |
62 | public override bool Equals(object other)
63 | {
64 | return other != null &&
65 | other is AssetSource otherSource &&
66 | this.ContainerType == otherSource.ContainerType &&
67 | this.Uri == otherSource.Uri;
68 | }
69 |
70 | public override int GetHashCode()
71 | {
72 | return 313
73 | ^ 317 * ContainerType.GetHashCode()
74 | ^ 317 * Uri.GetHashCode();
75 | }
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Behaviors/ActionData/BaseActionData.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 |
4 | namespace MixedRealityExtension.Behaviors.ActionData
5 | {
6 | ///
7 | /// Abstract class that represents the base class for action data.
8 | ///
9 | public abstract class BaseActionData
10 | {
11 |
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Behaviors/ActionData/BaseToolData.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 |
4 | namespace MixedRealityExtension.Behaviors.ActionData
5 | {
6 | ///
7 | /// Abstract class that is the base class for any tool behavior action data.
8 | ///
9 | public abstract class BaseToolData : BaseActionData
10 | {
11 | ///
12 | /// Gets whether the tool data is empty and shouldn't be synchronized.
13 | ///
14 | public abstract bool IsEmpty { get; }
15 |
16 | ///
17 | /// Reset the action data to a initial state.
18 | ///
19 | public abstract void Reset();
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Behaviors/ActionData/ButtonData.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 |
4 | namespace MixedRealityExtension.Behaviors.ActionData
5 | {
6 | internal class ButtonData : BaseActionData
7 | {
8 | public PointData[] targetedPoints;
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Behaviors/ActionData/PenData.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using MixedRealityExtension.Core.Types;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 |
7 | namespace MixedRealityExtension.Behaviors.ActionData
8 | {
9 | ///
10 | /// Class that represents the discrete draw data for a single from of the pen tool.
11 | ///
12 | public class DrawData
13 | {
14 | ///
15 | /// The transform for the collected draw position.
16 | ///
17 | public MWTransform Transform { get; set; }
18 | }
19 |
20 | ///
21 | /// Class that represents the pen tool action data.
22 | ///
23 | public class PenData : BaseToolData
24 | {
25 | public override bool IsEmpty => !DrawData.Any();
26 |
27 | ///
28 | /// The list of draw data entries from the pen tool.
29 | ///
30 | public IList DrawData { get; set; } = new List();
31 |
32 | ///
33 | public override void Reset()
34 | {
35 | DrawData.Clear();
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Behaviors/ActionData/PointData.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using MixedRealityExtension.Core.Types;
4 | using MixedRealityExtension.Util.Unity;
5 | using UnityEngine;
6 |
7 | namespace MixedRealityExtension.Behaviors.ActionData
8 | {
9 | internal class PointData
10 | {
11 | public MWVector3 appSpacePoint;
12 | public MWVector3 localSpacePoint;
13 |
14 | public static PointData CreateFromUnityVector3(Vector3 point, Transform localRoot, Transform appRoot)
15 | {
16 | return new PointData()
17 | {
18 | localSpacePoint = new MWVector3().ToLocalMWVector3(point, localRoot),
19 | appSpacePoint = new MWVector3().ToLocalMWVector3(point, appRoot)
20 | };
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Behaviors/ActionData/TargetData.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 |
4 | namespace MixedRealityExtension.Behaviors.ActionData
5 | {
6 | internal class TargetData : BaseActionData
7 | {
8 | public PointData[] targetedPoints;
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Behaviors/Actions/BehaviorActionHandler.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using MixedRealityExtension.App;
4 | using MixedRealityExtension.Behaviors.ActionData;
5 | using MixedRealityExtension.Core.Interfaces;
6 | using MixedRealityExtension.Messaging.Events.Types;
7 | using MixedRealityExtension.Messaging.Payloads;
8 | using System;
9 |
10 | namespace MixedRealityExtension.Behaviors.Actions
11 | {
12 | internal sealed class BehaviorActionHandler
13 | {
14 | private readonly string _actionName;
15 | private readonly BehaviorType _behaviorType;
16 | private readonly WeakReference _appRef;
17 | private readonly Guid _attachedActorId;
18 |
19 | internal BehaviorActionHandler(
20 | BehaviorType behaviorType,
21 | string actionName,
22 | WeakReference appRef,
23 | Guid attachedActorId)
24 | {
25 | _actionName = actionName;
26 | _behaviorType = behaviorType;
27 | _appRef = appRef;
28 | _attachedActorId = attachedActorId;
29 | }
30 |
31 | internal void HandleActionPerforming(IUser user, BaseActionData actionData)
32 | {
33 | HandleActionStateChanged(user, ActionState.Performing, ActionState.Performing, actionData);
34 | }
35 |
36 | internal void HandleActionStateChanged(
37 | IUser user,
38 | ActionState oldState,
39 | ActionState newState,
40 | BaseActionData actionData)
41 | {
42 | MixedRealityExtensionApp app;
43 | if (!_appRef.TryGetTarget(out app))
44 | {
45 | return;
46 | }
47 |
48 | if (!app.IsInteractableForUser(user))
49 | {
50 | return;
51 | }
52 |
53 | var actionPerformed = new ActionPerformed()
54 | {
55 | UserId = user.Id,
56 | TargetId = _attachedActorId,
57 | BehaviorType = _behaviorType,
58 | ActionName = _actionName,
59 | ActionState = newState,
60 | ActionData = actionData
61 | };
62 |
63 | app.EventManager.QueueLateEvent(new BehaviorEvent(actionPerformed));
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Behaviors/Behaviors.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using MixedRealityExtension.Behaviors.Contexts;
4 | using System;
5 |
6 | namespace MixedRealityExtension.Behaviors
7 | {
8 | ///
9 | /// The type of behavior as a flag supported enum value.
10 | ///
11 | [Flags]
12 | public enum BehaviorType
13 | {
14 | ///
15 | /// None behavior.
16 | ///
17 | None = 0,
18 |
19 | ///
20 | /// The target behavior type.
21 | ///
22 | [BehaviorContextType(typeof(TargetBehaviorContext))]
23 | Target = 1,
24 |
25 | ///
26 | /// The button behavior type.
27 | ///
28 | [BehaviorContextType(typeof(ButtonBehaviorContext))]
29 | Button = 2,
30 |
31 | ///
32 | /// The pen behavior type.
33 | ///
34 | [BehaviorContextType(typeof(PenBehaviorContext))]
35 | Pen = 4
36 | }
37 |
38 | [AttributeUsage(AttributeTargets.Field, AllowMultiple = false)]
39 | internal class BehaviorContextType : Attribute
40 | {
41 | internal Type ContextType { get; }
42 |
43 | public BehaviorContextType(Type behaviorContextType)
44 | {
45 | ContextType = behaviorContextType;
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Behaviors/Contexts/BehaviorContextBase.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using MixedRealityExtension.App;
4 | using MixedRealityExtension.Behaviors.Actions;
5 | using MixedRealityExtension.Core.Interfaces;
6 | using MixedRealityExtension.PluginInterfaces.Behaviors;
7 | using System;
8 | using System.Linq;
9 |
10 | namespace MixedRealityExtension.Behaviors.Contexts
11 | {
12 | public abstract class BehaviorContextBase
13 | {
14 | private WeakReference _appRef;
15 | private Guid _attachedActorId;
16 | private BehaviorType? _behaviorType;
17 |
18 | public bool IsInteractableForUser(IUser user)
19 | {
20 | var app = App;
21 | if (app != null)
22 | {
23 | return app.IsInteractableForUser(user);
24 | }
25 |
26 | return false;
27 | }
28 |
29 | internal MixedRealityExtensionApp App
30 | {
31 | get
32 | {
33 | if (_appRef.TryGetTarget(out MixedRealityExtensionApp app))
34 | {
35 | return app;
36 | }
37 |
38 | return null;
39 | }
40 | }
41 |
42 | internal IBehavior Behavior { get; private set; }
43 |
44 | internal BehaviorType BehaviorType
45 | {
46 | get
47 | {
48 | _behaviorType = _behaviorType ?? GetBehaviorType();
49 | return _behaviorType.Value;
50 | }
51 | }
52 |
53 | internal BehaviorContextBase()
54 | {
55 |
56 | }
57 |
58 | internal void Initialize(
59 | IBehavior behavior,
60 | WeakReference appRef,
61 | IActor attachedActor)
62 | {
63 | Behavior = behavior;
64 | _appRef = appRef;
65 | _attachedActorId = attachedActor.Id;
66 |
67 | Behavior.Actor = attachedActor;
68 |
69 | OnInitialized();
70 | }
71 |
72 | internal virtual void FixedUpdate()
73 | {
74 |
75 | }
76 |
77 | internal virtual void SynchronizeBehavior()
78 | {
79 |
80 | }
81 |
82 | internal virtual void CleanUp()
83 | {
84 | var behavior = Behavior;
85 | Behavior = null;
86 |
87 | behavior.CleanUp();
88 | }
89 |
90 | protected void RegisterActionHandler(MWActionBase action, string name)
91 | {
92 | if (Behavior == null) throw new InvalidOperationException("Cannot register action handlers to an uninitialized behavior context.");
93 | var handler = new BehaviorActionHandler(BehaviorType, name, _appRef, _attachedActorId);
94 | action.Handler = handler;
95 | }
96 |
97 | protected abstract void OnInitialized();
98 |
99 | private BehaviorType GetBehaviorType()
100 | {
101 | var behaviorEnumType = typeof(BehaviorType);
102 | foreach (var name in behaviorEnumType.GetEnumNames())
103 | {
104 | var behaviorContextTypeAttr = behaviorEnumType.GetField(name)
105 | .GetCustomAttributes(false)
106 | .OfType()
107 | .SingleOrDefault();
108 |
109 | if (this.GetType() == behaviorContextTypeAttr?.ContextType)
110 | {
111 | return (BehaviorType)Enum.Parse(typeof(BehaviorType), name);
112 | }
113 | }
114 |
115 | return BehaviorType.None;
116 | }
117 | }
118 | }
119 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Behaviors/Contexts/PenBehaviorContext.cs:
--------------------------------------------------------------------------------
1 | using MixedRealityExtension.Behaviors.ActionData;
2 |
3 | namespace MixedRealityExtension.Behaviors.Contexts
4 | {
5 | public class PenBehaviorContext : PhysicalToolBehaviorContext
6 | {
7 | internal PenBehaviorContext()
8 | {
9 |
10 | }
11 |
12 | internal override void FixedUpdate()
13 | {
14 | base.FixedUpdate();
15 | if (IsUsing)
16 | {
17 | ToolData.DrawData.Add(new DrawData() { Transform = Behavior.Actor.AppTransform });
18 | }
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Behaviors/Contexts/PhysicalToolBehaviorContext.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using MixedRealityExtension.Behaviors.ActionData;
4 | using MixedRealityExtension.Behaviors.Actions;
5 | using MixedRealityExtension.Core.Interfaces;
6 |
7 | namespace MixedRealityExtension.Behaviors.Contexts
8 | {
9 | public abstract class PhysicalToolBehaviorContext : TargetBehaviorContext
10 | where ToolDataT : BaseToolData, new()
11 | {
12 | private ToolDataT _queuedToolData;
13 | private MWAction _holding = new MWAction();
14 | private MWAction _using = new MWAction();
15 |
16 | public void StartHolding(IUser user)
17 | {
18 | _holding.StartAction(user);
19 | }
20 |
21 | public void EndHolding(IUser user)
22 | {
23 | _holding.StopAction(user);
24 | }
25 |
26 | public void StartUsing(IUser user)
27 | {
28 | IsUsing = true;
29 | _using.StartAction(user);
30 | }
31 |
32 | public void EndUsing(IUser user)
33 | {
34 | IsUsing = false;
35 | _using.StopAction(user);
36 | }
37 |
38 | internal ToolDataT ToolData { get; private set; }
39 |
40 | internal bool IsUsing { get; private set; }
41 |
42 |
43 | internal PhysicalToolBehaviorContext()
44 | {
45 | ToolData = new ToolDataT();
46 | }
47 |
48 | internal override sealed void SynchronizeBehavior()
49 | {
50 | if (IsUsing)
51 | {
52 | PerformUsingAction();
53 | }
54 | }
55 |
56 | protected override void OnInitialized()
57 | {
58 | RegisterActionHandler(_holding, "holding");
59 | RegisterActionHandler(_using, "using");
60 | }
61 |
62 | private void OnUsingStateChanging(object sender, ActionStateChangedArgs args)
63 | {
64 | var wasUsing = IsUsing;
65 | IsUsing = args.NewState == ActionState.Started || args.NewState == ActionState.Performing;
66 | if (!IsUsing && wasUsing)
67 | {
68 | // We are stopping use and should send the remaining tool data up the remaining tool data from the last bit of use.
69 | PerformUsingAction();
70 | }
71 | }
72 |
73 | private void PerformUsingAction()
74 | {
75 | if (!ToolData.IsEmpty)
76 | {
77 | _queuedToolData = ToolData;
78 | ToolData = new ToolDataT();
79 | _using.PerformActionUpdate(_queuedToolData);
80 | }
81 | }
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Behaviors/Contexts/TargetBehaviorContext.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using MixedRealityExtension.Behaviors.ActionData;
4 | using MixedRealityExtension.Behaviors.Actions;
5 | using MixedRealityExtension.Core.Interfaces;
6 | using System.Collections.Generic;
7 | using System.Linq;
8 | using UnityEngine;
9 |
10 | namespace MixedRealityExtension.Behaviors.Contexts
11 | {
12 | public class TargetBehaviorContext : BehaviorContextBase
13 | {
14 | private List _currentTargetPoints = new List();
15 |
16 | internal MWAction TargetAction { get; } = new MWAction();
17 |
18 | internal MWAction GrabAction { get; } = new MWAction();
19 |
20 | public void StartTargeting(IUser user, Vector3 targetPoint)
21 | {
22 | var app = App;
23 | if (app == null)
24 | {
25 | return;
26 | }
27 |
28 | var targetData = new TargetData()
29 | {
30 | targetedPoints = new PointData[1]
31 | {
32 | PointData.CreateFromUnityVector3(targetPoint, Behavior.Actor.GameObject.transform, app.SceneRoot.transform)
33 | }
34 | };
35 |
36 | TargetAction.StartAction(user, targetData);
37 | }
38 |
39 | public void EndTargeting(IUser user, Vector3 targetPoint)
40 | {
41 | var app = App;
42 | if (app == null)
43 | {
44 | return;
45 | }
46 |
47 | var targetData = new TargetData()
48 | {
49 | targetedPoints = new PointData[1]
50 | {
51 | PointData.CreateFromUnityVector3(targetPoint, Behavior.Actor.GameObject.transform, app.SceneRoot.transform)
52 | }
53 | };
54 |
55 | TargetAction.StopAction(user, targetData);
56 | }
57 |
58 | public void UpdateTargetPoint(IUser user, Vector3 targetPoint)
59 | {
60 | _currentTargetPoints.Add(targetPoint);
61 | OnTargetPointUpdated(targetPoint);
62 | }
63 |
64 | public void StartGrab(IUser user)
65 | {
66 | GrabAction.StartAction(user);
67 | }
68 |
69 | public void EndGrab(IUser user)
70 | {
71 | GrabAction.StopAction(user);
72 | }
73 |
74 | internal TargetBehaviorContext()
75 | {
76 |
77 | }
78 |
79 | internal override void SynchronizeBehavior()
80 | {
81 | base.SynchronizeBehavior();
82 |
83 | var app = App;
84 | if (app == null)
85 | {
86 | return;
87 | }
88 |
89 | if (_currentTargetPoints.Any())
90 | {
91 | TargetAction.PerformActionUpdate(new TargetData()
92 | {
93 | targetedPoints = _currentTargetPoints.Select((point) =>
94 | {
95 | return PointData.CreateFromUnityVector3(point, Behavior.Actor.GameObject.transform, App.SceneRoot.transform);
96 | }).ToArray()
97 | });
98 |
99 | _currentTargetPoints.Clear();
100 | }
101 | }
102 |
103 | protected virtual void OnTargetPointUpdated(Vector3 point)
104 | {
105 |
106 | }
107 |
108 | protected override void OnInitialized()
109 | {
110 | RegisterActionHandler(TargetAction, "target");
111 | RegisterActionHandler(GrabAction, "grab");
112 | }
113 | }
114 | }
115 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Constants.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using MixedRealityExtension.Messaging.Payloads;
4 | using MixedRealityExtension.Messaging.Payloads.Converters;
5 | using Newtonsoft.Json;
6 |
7 | namespace MixedRealityExtension
8 | {
9 | internal static class Constants
10 | {
11 | internal static readonly JsonSerializerSettings SerializerSettings;
12 |
13 | static Constants()
14 | {
15 | SerializerSettings = new JsonSerializerSettings
16 | {
17 | ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver(),
18 | FloatParseHandling = FloatParseHandling.Double,
19 | Formatting = Formatting.None,
20 | NullValueHandling = NullValueHandling.Ignore,
21 | };
22 |
23 | SerializerSettings.Converters.Add(new DashFormattedEnumConverter());
24 | SerializerSettings.Converters.Add(new PayloadConverter());
25 | SerializerSettings.Converters.Add(new CollisionGeometryConverter());
26 | }
27 |
28 | /*
29 | * Headers passed in MRE connect requests.
30 | */
31 | internal const string SessionHeader = "x-ms-mixed-reality-extension-sessionid";
32 | internal const string PlatformHeader = "x-ms-mixed-reality-extension-platformid";
33 | internal const string LegacyProtocolVersionHeader = "x-ms-mixed-reality-extension-protocol-version";
34 | internal const string CurrentClientVersionHeader = "x-ms-mixed-reality-extension-client-version";
35 | internal const string MinimumSupportedSDKVersionHeader = "x-ms-mixed-reality-extension-min-sdk-version";
36 |
37 | /*
38 | * Legacy Protocol Version - Left over from the old protocol versioning scheme.
39 | * Keeping in for now to allow a smoother transition to the new system.
40 | * TODO: Remove after a few releases.
41 | */
42 | internal const int LegacyProtocolVersion = 1;
43 |
44 | /*
45 | * Current Client Version
46 | * This matches major.minor from the package version number, and is updated as part of the manual
47 | * SDK release procedures.
48 | */
49 | internal const string CurrentClientVersion = "0.20";
50 |
51 | /*
52 | * Minimum Supported SDK version
53 | * The oldest SDK version that runs. Since compatibility with older MREs is essential, changing
54 | * this *is* a big deal, and requires discussion and signoff from the dev team.
55 | */
56 | internal const string MinimumSupportedSDKVersion = "0.13";
57 |
58 | /*
59 | * Enable physics bridge
60 | * Work in progress feature to improve shared physics synchronization.
61 | * It is NOT compatibile with SDK versions older than 0.19.
62 | */
63 | internal const bool UsePhysicsBridge = true;
64 |
65 | ///
66 | /// If we load an asset, and the server response does not contain an ETag, this is the asset's version
67 | ///
68 | internal const string UnversionedAssetVersion = "unversioned";
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Core/ActorCommandQueue.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using MixedRealityExtension.App;
4 | using MixedRealityExtension.Core.Interfaces;
5 | using MixedRealityExtension.Messaging.Payloads;
6 | using MixedRealityExtension.Util;
7 | using System;
8 | using System.Collections.Generic;
9 | using System.Linq;
10 | using System.Text;
11 | using System.Threading.Tasks;
12 |
13 | namespace MixedRealityExtension.Core
14 | {
15 | internal class ActorCommandQueue
16 | {
17 | #region Public Accessors
18 |
19 | public int Count => queue.Count;
20 |
21 | #endregion
22 |
23 | #region Constructor
24 |
25 | public ActorCommandQueue(Guid actorId, MixedRealityExtensionApp app)
26 | {
27 | this.actorId = actorId;
28 | this.app = app;
29 | }
30 |
31 | #endregion
32 |
33 | #region Public Methods
34 |
35 | public void Clear()
36 | {
37 | queue.Clear();
38 | }
39 |
40 | public void Enqueue(NetworkCommandPayload payload, Action onCompleteCallback)
41 | {
42 | queue.Enqueue(new QueuedCommand()
43 | {
44 | Payload = payload,
45 | OnCompleteCallback = onCompleteCallback
46 | });
47 | }
48 |
49 | public void Update()
50 | {
51 | if (activeCommand != null || queue.Count == 0)
52 | {
53 | return;
54 | }
55 |
56 | if (actor == null)
57 | {
58 | actor = app.FindActor(actorId) as Actor;
59 | }
60 |
61 | if (actor != null)
62 | {
63 | activeCommand = queue.Dequeue();
64 | try
65 | {
66 | app.ExecuteCommandPayload(actor, activeCommand.Payload, () =>
67 | {
68 | activeCommand?.OnCompleteCallback?.Invoke();
69 | activeCommand = null;
70 | Update();
71 | });
72 | }
73 | catch
74 | {
75 | // In case of error, clear activeCommand so that queue processing isn't stalled forever.
76 | activeCommand = null;
77 | throw;
78 | }
79 | }
80 | }
81 |
82 | #endregion
83 |
84 | #region Private Types
85 |
86 | private class QueuedCommand
87 | {
88 | public NetworkCommandPayload Payload { get; set; }
89 | public Action OnCompleteCallback { get; set; }
90 | }
91 |
92 | #endregion
93 |
94 | #region Private Fields
95 |
96 | private QueuedCommand activeCommand;
97 | private Actor actor;
98 | private readonly Guid actorId;
99 | private readonly MixedRealityExtensionApp app;
100 | private readonly Queue queue = new Queue();
101 |
102 | #endregion
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Core/Attachment.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using MixedRealityExtension.Patching.Types;
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Linq;
7 | using System.Text;
8 | using System.Threading.Tasks;
9 |
10 | namespace MixedRealityExtension.Core
11 | {
12 | public class Attachment : IEquatable
13 | {
14 | internal string AttachPoint { get; set; } = "none";
15 | internal Guid UserId { get; set; } = Guid.Empty;
16 |
17 | public bool Equals(Attachment other)
18 | {
19 | return other != null && AttachPoint == other.AttachPoint && UserId == other.UserId;
20 | }
21 |
22 | public override bool Equals(object obj)
23 | {
24 | return Equals(obj as Attachment);
25 | }
26 |
27 | // This class is not suitable for use as a hash key or dictionary key.
28 | public override int GetHashCode()
29 | {
30 | return base.GetHashCode();
31 | }
32 |
33 | internal void ApplyPatch(AttachmentPatch patch)
34 | {
35 | if (patch != null)
36 | {
37 | if (patch.AttachPoint != null)
38 | {
39 | AttachPoint = patch.AttachPoint;
40 | }
41 | if (patch.UserId.HasValue)
42 | {
43 | UserId = patch.UserId.Value;
44 | }
45 | }
46 | }
47 |
48 | internal AttachmentPatch GeneratePatch(Attachment other)
49 | {
50 | if (!this.Equals(other))
51 | {
52 | return new AttachmentPatch()
53 | {
54 | AttachPoint = AttachPoint,
55 | UserId = UserId
56 | };
57 | }
58 | return null;
59 | }
60 |
61 | internal void CopyFrom(Attachment other)
62 | {
63 | AttachPoint = other.AttachPoint;
64 | UserId = other.UserId;
65 | }
66 |
67 | internal void Clear()
68 | {
69 | AttachPoint = "none";
70 | UserId = Guid.Empty;
71 | }
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Core/Collision/ColliderEventType.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 |
4 | using System;
5 |
6 | namespace MixedRealityExtension.Core.Collision
7 | {
8 | [Flags]
9 | public enum ColliderEventType
10 | {
11 | ///
12 | /// No collider events.
13 | ///
14 | None = 0,
15 |
16 | ///
17 | /// Event fired when a trigger volume is entered by an actor.
18 | ///
19 | TriggerEnter = 1,
20 |
21 | ///
22 | /// Event fired when a trigger volume is exited by an actor.
23 | ///
24 | TriggerExit = 2,
25 |
26 | ///
27 | /// Event fired when a collision has entered between the attached actor and another actor.
28 | ///
29 | CollisionEnter = 4,
30 |
31 | ///
32 | /// Event fired when a collision has exited between the attached actor and another actor.
33 | ///
34 | CollisionExit = 8
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Core/Collision/CollisionData.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 |
4 | using MixedRealityExtension.Core.Types;
5 | using System;
6 | using System.Collections.Generic;
7 |
8 | namespace MixedRealityExtension.Core.Collision
9 | {
10 | ///
11 | /// Class that contains all of the data that is provided during a collision.
12 | ///
13 | public class CollisionData
14 | {
15 | ///
16 | /// Gets the id of the other actor we have collided with.
17 | ///
18 | public Guid otherActorId { get; internal set; }
19 |
20 | ///
21 | /// Gets the enumerable of contact points that happened during the collision.
22 | ///
23 | public IEnumerable Contacts { get; internal set; }
24 |
25 | ///
26 | /// Gets the impulse of the collision.
27 | ///
28 | public MWVector3 Impulse { get; internal set; }
29 |
30 | ///
31 | /// Gets the relative velocity of the collision.
32 | ///
33 | public MWVector3 RelativeVelocity { get; internal set; }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Core/Collision/ContactPoint.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 |
4 | using MixedRealityExtension.Core.Types;
5 |
6 | namespace MixedRealityExtension.Core.Collision
7 | {
8 | ///
9 | /// Class that contains the data from a contact point in a collision.
10 | ///
11 | public class ContactPoint
12 | {
13 | ///
14 | /// Gets the normal of the collision contact point.
15 | ///
16 | public MWVector3 Normal { get; internal set; }
17 |
18 | ///
19 | /// Gets the point of the collision contact point.
20 | ///
21 | public MWVector3 Point { get; internal set; }
22 |
23 | ///
24 | /// Gets the separation of the collision contact point.
25 | ///
26 | public float Separation { get; internal set; }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Core/CollisionLayers.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 |
4 | namespace MixedRealityExtension.Core
5 | {
6 | ///
7 | /// The layers available for MRE colliders.
8 | ///
9 | public enum CollisionLayer
10 | {
11 | ///
12 | /// Good for most actors. These will collide with all "physical" things: other default actors,
13 | /// navigation actors, and the non-MRE environment. It also blocks the UI cursor and receives press/grab events.
14 | ///
15 | Default,
16 | ///
17 | /// For actors considered part of the environment. Can move/teleport onto these colliders,
18 | /// but cannot click or grab them. For example, the floor, an invisible wall, or an elevator platform.
19 | ///
20 | Navigation,
21 | ///
22 | /// For "non-physical" actors. Only interact with the cursor (with press/grab events) and other holograms.
23 | /// For example, if you wanted a group of actors to behave as a separate physics simulation
24 | /// from the main scene.
25 | ///
26 | Hologram,
27 | ///
28 | /// Actors in this layer do not collide with anything but the UI cursor.
29 | ///
30 | UI
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Core/Components/ActorComponentBase.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using System;
4 | using UnityEngine;
5 |
6 | namespace MixedRealityExtension.Core.Components
7 | {
8 | internal class ActorComponentBase : MonoBehaviour
9 | {
10 | internal Actor AttachedActor { get; set; }
11 |
12 | internal virtual void CleanUp()
13 | {
14 |
15 | }
16 |
17 | internal virtual void SynchronizeComponent()
18 | {
19 |
20 | }
21 |
22 | private void Start()
23 | {
24 | if (AttachedActor == null)
25 | {
26 | AttachedActor = gameObject.GetComponent() ??
27 | throw new NullReferenceException("Game object must have an actor script on it if it is going to have an actor component on it.");
28 | }
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Core/Components/BehaviorComponent.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using MixedRealityExtension.Behaviors;
4 | using MixedRealityExtension.Behaviors.Contexts;
5 | using MixedRealityExtension.PluginInterfaces.Behaviors;
6 |
7 | namespace MixedRealityExtension.Core.Components
8 | {
9 | internal class BehaviorComponent : ActorComponentBase
10 | {
11 | private BehaviorContextBase _behaviorContext;
12 |
13 | internal IBehavior Behavior => _behaviorContext?.Behavior;
14 |
15 | internal BehaviorContextBase Context => _behaviorContext;
16 |
17 | internal void SetBehaviorContext(BehaviorContextBase behaviorContext)
18 | {
19 | if (_behaviorContext != null && _behaviorContext.BehaviorType != behaviorContext.BehaviorType)
20 | {
21 | ClearBehaviorContext();
22 | }
23 |
24 | _behaviorContext = behaviorContext;
25 | }
26 |
27 | internal void ClearBehaviorContext()
28 | {
29 | if (_behaviorContext != null)
30 | {
31 | _behaviorContext.CleanUp();
32 | _behaviorContext = null;
33 | }
34 | }
35 |
36 | internal bool ContainsBehaviorContext()
37 | {
38 | return _behaviorContext != null;
39 | }
40 |
41 | internal override void CleanUp()
42 | {
43 | base.CleanUp();
44 | ClearBehaviorContext();
45 | }
46 |
47 | internal override void SynchronizeComponent()
48 | {
49 | _behaviorContext?.SynchronizeBehavior();
50 | }
51 |
52 | private void FixedUpdate()
53 | {
54 | _behaviorContext?.FixedUpdate();
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Core/Components/LookAtComponent.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 |
4 | using MixedRealityExtension.Core.Interfaces;
5 | using MixedRealityExtension.Patching.Types;
6 | using MixedRealityExtension.Util.Unity;
7 | using System;
8 | using UnityEngine;
9 |
10 | namespace MixedRealityExtension.Core.Components
11 | {
12 | ///
13 | /// Unity Behaviour to face toward a given target object
14 | ///
15 | [DisallowMultipleComponent]
16 | internal class LookAtComponent : ActorComponentBase
17 | {
18 | private GameObject _targetObject;
19 | private LookAtMode _lookAtMode;
20 | private bool _backward;
21 |
22 | internal void ApplyPatch(LookAtPatch patch)
23 | {
24 | if (patch.ActorId.HasValue)
25 | {
26 | IActor targetActor = AttachedActor.App.FindActor(patch.ActorId.Value);
27 | if (targetActor != null)
28 | {
29 | _targetObject = targetActor.GameObject;
30 | }
31 | else
32 | {
33 | _targetObject = null;
34 | }
35 | }
36 | if (patch.Mode.HasValue)
37 | {
38 | _lookAtMode = patch.Mode.Value;
39 | }
40 | if (patch.Backward.HasValue)
41 | {
42 | _backward = patch.Backward.Value;
43 | }
44 | }
45 |
46 | void Update()
47 | {
48 | if (_lookAtMode != LookAtMode.None && _targetObject != null)
49 | {
50 | var rotation = CalcRotation();
51 | if (rotation.HasValue)
52 | {
53 | transform.rotation = rotation.Value;
54 | }
55 | }
56 | }
57 |
58 | private Quaternion? CalcRotation()
59 | {
60 | Vector3 pos = _targetObject.transform.position;
61 | Vector3 delta = pos - transform.position;
62 |
63 | if (delta == Vector3.zero)
64 | {
65 | // In case of zero-length, don't change our rotation.
66 | return null;
67 | }
68 |
69 | if (_backward)
70 | {
71 | delta *= -1;
72 | }
73 |
74 | Quaternion look = Quaternion.LookRotation(delta, Vector3.up);
75 |
76 | if (_lookAtMode == LookAtMode.TargetY)
77 | {
78 | look = Quaternion.Euler(0, look.eulerAngles.y, look.eulerAngles.z);
79 | }
80 |
81 | return look;
82 | }
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Core/Components/MREAttachmentComponent.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 | using UnityEngine;
9 |
10 | namespace MixedRealityExtension.Core.Components
11 | {
12 | internal class MREAttachmentComponent : MonoBehaviour
13 | {
14 | public Guid UserId { get; set; }
15 |
16 | public Actor Actor { get; set; }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Core/Interfaces/IActor.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using MixedRealityExtension.App;
4 | using MixedRealityExtension.Core.Types;
5 |
6 | namespace MixedRealityExtension.Core.Interfaces
7 | {
8 | ///
9 | /// The interface that represents an actor within the mixed reality extension runtime.
10 | ///
11 | public interface IActor : IMixedRealityExtensionObject
12 | {
13 | ///
14 | /// Gets the ID of the actor's parent.
15 | ///
16 | IActor Parent { get; }
17 |
18 | ///
19 | /// Gets and sets the name of the actor.
20 | ///
21 | new string Name { get; set; }
22 |
23 | ///
24 | /// Gets the app that the actor is owned by.
25 | ///
26 | IMixedRealityExtensionApp App { get; }
27 |
28 | ///
29 | /// Gets the local space transform of the actor.
30 | ///
31 | MWScaledTransform LocalTransform { get; }
32 |
33 | ///
34 | /// The app space transform of this mixed reality extension object.
35 | ///
36 | MWTransform AppTransform { get; }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Core/Interfaces/ICollider.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 |
4 | namespace MixedRealityExtension.Core.Interfaces
5 | {
6 | // public enum CollisionLayer
7 | // {
8 | // Object,
9 | // Environment,
10 | // Hologram
11 | // }
12 |
13 | ///
14 | /// The interface that represents a collider within the mixed reality extension runtime.
15 | ///
16 | public interface ICollider
17 | {
18 | ///
19 | /// Whether the collider is enabled.
20 | ///
21 | bool IsEnabled { get; }
22 |
23 | ///
24 | /// Whether the collider is a trigger.
25 | ///
26 | bool IsTrigger { get; }
27 |
28 | //CollisionLayer CollisionLayer { get; }
29 |
30 | ///
31 | /// The shape of the collider.
32 | ///
33 | ColliderType Shape { get; }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Core/Interfaces/ILight.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using MixedRealityExtension.Core.Types;
4 |
5 | namespace MixedRealityExtension.Core.Interfaces
6 | {
7 | ///
8 | /// The type of light.
9 | ///
10 | public enum LightType
11 | {
12 | ///
13 | /// Spot light.
14 | ///
15 | Spot,
16 |
17 | ///
18 | /// Point light.
19 | ///
20 | Point,
21 |
22 | ///
23 | /// Directional light.
24 | ///
25 | Directional
26 | }
27 |
28 | ///
29 | /// The interface that represents a light within the mixed reality extension runtime.
30 | ///
31 | public interface ILight
32 | {
33 | ///
34 | /// Gets whether the light is enabled.
35 | ///
36 | bool Enabled { get; }
37 |
38 | ///
39 | /// Gets the type of light it is.
40 | ///
41 | LightType Type { get; }
42 |
43 | ///
44 | /// Gets the color of the light.
45 | ///
46 | MWColor Color { get; }
47 |
48 | ///
49 | /// Gets the range of the light.
50 | ///
51 | float Range { get; }
52 |
53 | ///
54 | /// Gets the intensity of the light.
55 | ///
56 | float Intensity { get; }
57 |
58 | ///
59 | /// Gets the spot angle of the light.
60 | ///
61 | float SpotAngle { get; }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Core/Interfaces/IMixedRealityExtensionObject.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using MixedRealityExtension.Core.Types;
4 | using System;
5 | using UnityEngine;
6 |
7 | namespace MixedRealityExtension.Core.Interfaces
8 | {
9 | ///
10 | /// The interface that represents a basic mixed reality extension object within the mixed reality extension runtime.
11 | ///
12 | public interface IMixedRealityExtensionObject
13 | {
14 | ///
15 | /// The id of the mixed reality object.
16 | ///
17 | Guid Id { get; }
18 |
19 | ///
20 | /// Gets the name of the actor.
21 | ///
22 | string Name { get; }
23 |
24 | ///
25 | /// The instance id of the app that is the owner of this mixed reality extension object.
26 | ///
27 | Guid AppInstanceId { get; }
28 |
29 | ///
30 | /// The unity game object that the actor is associated with.
31 | ///
32 | GameObject GameObject { get; }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Core/Interfaces/IUser.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using MixedRealityExtension.PluginInterfaces;
4 | using System;
5 |
6 | namespace MixedRealityExtension.Core.Interfaces
7 | {
8 | ///
9 | /// The interface that represents a user within the mixed reality extension runtime.
10 | ///
11 | public interface IUser : IMixedRealityExtensionObject, IEquatable
12 | {
13 | ///
14 | /// Host-provided host app user instance.
15 | ///
16 | IHostAppUser HostAppUser { get; }
17 |
18 | ///
19 | /// The group mask for this user.
20 | ///
21 | UInt32 Groups { get; }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Core/Light.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using System;
4 |
5 | using MixedRealityExtension.Core.Interfaces;
6 | using MixedRealityExtension.Core.Types;
7 | using MixedRealityExtension.Patching;
8 | using MixedRealityExtension.Patching.Types;
9 | using MixedRealityExtension.Util.Unity;
10 | using UnityEngine;
11 | using MRELightType = MixedRealityExtension.Core.Interfaces.LightType;
12 | using UnityLight = UnityEngine.Light;
13 |
14 | namespace MixedRealityExtension.Core
15 | {
16 | internal class Light : ILight
17 | {
18 | private readonly UnityLight _light;
19 |
20 | // Cached values
21 | private readonly MWColor _color = new MWColor();
22 |
23 | ///
24 | public bool Enabled => _light.enabled;
25 |
26 | ///
27 | public MRELightType Type => (MRELightType)Enum.Parse(typeof(MRELightType), _light.type.ToString());
28 |
29 | ///
30 | public MWColor Color => _color.FromUnityColor(_light.color);
31 |
32 | ///
33 | public float Range => _light.range;
34 |
35 | ///
36 | public float Intensity => _light.intensity;
37 |
38 | ///
39 | public float SpotAngle => _light.spotAngle * Mathf.Deg2Rad;
40 |
41 | ///
42 | /// Initializes a new instance of the class.
43 | ///
44 | /// The object to bind to.
45 | public Light(UnityLight light)
46 | {
47 | _light = light;
48 | }
49 |
50 | ///
51 | public void ApplyPatch(LightPatch patch)
52 | {
53 | _light.enabled = _light.enabled.GetPatchApplied(Enabled.ApplyPatch(patch.Enabled));
54 | _light.type = _light.type.GetPatchApplied(Type.ApplyPatch(patch.Type));
55 | _light.color = _light.color.GetPatchApplied(Color.ApplyPatch(patch.Color));
56 | _light.range = _light.range.GetPatchApplied(Range.ApplyPatch(patch.Range));
57 | _light.intensity = _light.intensity.GetPatchApplied(Intensity.ApplyPatch(patch.Intensity));
58 | if (patch.SpotAngle.HasValue)
59 | {
60 | _light.spotAngle = Mathf.Rad2Deg * patch.SpotAngle.Value;
61 | }
62 | }
63 |
64 | ///
65 | public void SynchronizeEngine(LightPatch patch)
66 | {
67 | ApplyPatch(patch);
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Core/MediaCommand.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | namespace MixedRealityExtension
4 | {
5 | ///
6 | /// Special commands to change the mode of the sound instance?
7 | ///
8 | public enum MediaCommand
9 | {
10 | ///
11 | /// Start a new sound instance
12 | ///
13 | Start,
14 |
15 | ///
16 | /// Modify an active sound instance
17 | ///
18 | Update,
19 |
20 | ///
21 | /// Destroy an active sound instance
22 | ///
23 | Stop
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Core/MediaStateOptions.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | namespace MixedRealityExtension
4 | {
5 | ///
6 | /// Modifiable Media Instance Options - shared between sounds and video streams
7 | ///
8 | public class MediaStateOptions
9 | {
10 | ///
11 | /// pitch offset in halftones (0=default, 12=one octave higher, -12=one octave lower)
12 | ///
13 | public float? Pitch;
14 |
15 | ///
16 | /// volume multiplier, (0.0-1.0, where 0.0=no sound, 1.0=maximum). Default to 1.0
17 | ///
18 | public float? Volume;
19 |
20 | ///
21 | /// repeat the sound when ended, or turn it off after playing once. Default to false
22 | /// This does not apply to video streams, only to sounds
23 | ///
24 | public bool? Looping;
25 |
26 | ///
27 | /// pause or unpause the media. Default to false
28 | ///
29 | public bool? paused;
30 |
31 | ///
32 | /// the amount that sound pitch is modified when moving towards/away from sound source.
33 | /// For music and speech, set this to 0, but for regular objects set to 1.0 or higher. Default to 1.0
34 | /// This does not apply to video streams, only to sounds
35 | /// ///
36 | public float? Doppler;
37 |
38 | ///
39 | /// Specify how much the sound is non-directional (playing the same volume in each speaker regardless of facing direction)
40 | /// vs directional (playing only in the speakers that are pointing towards the sound source).
41 | /// This can be used to make sounds seem more "wide".
42 | /// It is also useful for multi-channel sounds (such as music), because a fully directional sound will always sound like mono.
43 | /// Default to 0.0. For music and ambient looping sounds, set this between 0.5 and 1.0.
44 | ///
45 | public float? Spread;
46 |
47 | ///
48 | /// Sound will play at full volume until user is this many meters away, and then volume will decrease logarithmically
49 | /// Default to 1.0. For sound that needs to fill up a large space (like a concert), increase this number.
50 | ///
51 | public float? RolloffStartDistance;
52 |
53 | ///
54 | /// The media should start at, or seek this many seconds into the media.
55 | /// Time is in seconds relative to start of clip.
56 | ///
57 | public float? Time;
58 |
59 | ///
60 | /// Should the video stream be visible or invisible
61 | /// Does not apply to sounds, only to video streams.
62 | ///
63 | public bool? Visible;
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Core/MixedRealityExtensionObject.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using MixedRealityExtension.App;
4 | using MixedRealityExtension.Core.Interfaces;
5 | using MixedRealityExtension.Core.Types;
6 | using MixedRealityExtension.Patching;
7 | using MixedRealityExtension.Patching.Types;
8 | using MixedRealityExtension.Util.Unity;
9 | using System;
10 | using UnityEngine;
11 |
12 | namespace MixedRealityExtension.Core
13 | {
14 | internal abstract class MixedRealityExtensionObject : MonoBehaviour, IMixedRealityExtensionObject
15 | {
16 | ///
17 | public Guid Id { get; private set; }
18 |
19 | ///
20 | public Guid AppInstanceId => App.InstanceId;
21 |
22 | ///
23 | public virtual string Name => gameObject.name;
24 |
25 | ///
26 | public GameObject GameObject => this.gameObject;
27 |
28 | internal MixedRealityExtensionApp App { get; private set; }
29 |
30 | ///
31 | /// Gets the local user. Will be null if the local client has not joined as a user.
32 | ///
33 | public IUser LocalUser => App.LocalUser;
34 |
35 | public void Initialize(Guid id, MixedRealityExtensionApp app)
36 | {
37 | Id = id;
38 | App = app;
39 | }
40 |
41 | protected abstract void InternalUpdate();
42 |
43 | protected virtual void InternalFixedUpdate()
44 | {
45 |
46 | }
47 |
48 | protected virtual void OnStart()
49 | {
50 |
51 | }
52 |
53 | protected virtual void OnAwake()
54 | {
55 |
56 | }
57 |
58 | protected virtual void OnDestroyed()
59 | {
60 |
61 | }
62 |
63 | #region MonoBehaviour Methods
64 |
65 | private void Start()
66 | {
67 | OnStart();
68 | }
69 |
70 | private void Awake()
71 | {
72 | OnAwake();
73 | }
74 |
75 | private void Update()
76 | {
77 | InternalUpdate();
78 | }
79 |
80 | private void FixedUpdate()
81 | {
82 | InternalFixedUpdate();
83 | }
84 |
85 | private void OnDestroy()
86 | {
87 | OnDestroyed();
88 | }
89 |
90 | #endregion
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Core/Permissions.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using System;
4 | using System.Collections.Generic;
5 |
6 | namespace MixedRealityExtension.Core
7 | {
8 | // Note: Unity serialization will break with unsigned types, or types larger than 32 bits
9 | [Flags]
10 | public enum Permissions : int
11 | {
12 | None = 0,
13 | Execution = 1,
14 | UserTracking = 2,
15 | UserInteraction = 4
16 | }
17 |
18 | public static class PermissionsExtensions
19 | {
20 | ///
21 | /// Convenience method to convert an enumerable of permissions into a bitfield
22 | ///
23 | ///
24 | ///
25 | public static Permissions ToFlags(this IEnumerable enumerable)
26 | {
27 | var aggregate = Permissions.None;
28 | foreach (var perm in enumerable)
29 | {
30 | aggregate |= perm;
31 | }
32 | return aggregate;
33 | }
34 |
35 | ///
36 | /// Convenience method to convert a bitfield of Permissions into an enumerable
37 | ///
38 | ///
39 | ///
40 | public static IEnumerable ToEnumerable(this Permissions flags)
41 | {
42 | var allPerms = Enum.GetValues(typeof(Permissions));
43 | var aggregate = new List(allPerms.Length);
44 | foreach (Permissions perm in allPerms)
45 | {
46 | if ((flags & perm) != 0)
47 | {
48 | aggregate.Add(perm);
49 | }
50 | }
51 | return aggregate;
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Core/Physics/IPrediction.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using MixedRealityExtension.Core;
7 |
8 | namespace MixedRealityExtension.Core.Physics
9 | {
10 | /// interface struct to pass time step informations
11 | public class PredictionTimeParameters
12 | {
13 | public PredictionTimeParameters(float timeStep)
14 | {
15 | setFromDT(timeStep);
16 | }
17 |
18 | /// current time step of the frame
19 | public float DT = 0.0f;
20 | /// half of the time step for time tolerance
21 | public float halfDT = 0.0f;
22 | /// to avoid divisions the inverse of the delta time of this frame
23 | public float invDT = 0.0f;
24 | /// method to set all the fields from DT;
25 | /// time step of the current frame
26 | public void setFromDT(float timeStep)
27 | {
28 | DT = timeStep;
29 | halfDT = 0.5f * DT;
30 | invDT = (1.0f / DT);
31 | }
32 | }
33 |
34 | /// general interface to predict the remote bodies over multiple frames
35 | public interface IPrediction
36 | {
37 | /// this signals to the interface that we will now start streaming into the prediction
38 | /// the remote and owned body pairs for the current frame
39 | void StartBodyPredicitonForNextFrame();
40 |
41 | /// before a remote body gets stepped this needs to be called for all potentially
42 | /// predicted remote bodies for one frame
43 | void AddAndProcessRemoteBodyForPrediction(RigidBodyPhysicsBridgeInfo rb,
44 | RigidBodyTransform transform, UnityEngine.Vector3 keyFramedPos,
45 | UnityEngine.Quaternion keyFramedOrientation, float timeOfSnapshot,
46 | PredictionTimeParameters timeInfo);
47 |
48 | /// In the last step within the frame the owned bodies are added to the prediction
49 | void PredictAllRemoteBodiesWithOwnedBodies(ref SortedList allRigidBodiesOfThePhysicsBridge,
50 | PredictionTimeParameters timeInfo);
51 |
52 | /// reset internal state
53 | void Clear();
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Core/PrimitiveDefinition.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 |
4 | namespace MixedRealityExtension.Core.Types
5 | {
6 | ///
7 | /// Describes the general shape of a primitive. Specifics are described in a [[PrimitiveDefinition]] object.
8 | /// Docs for shape-specific stuff are in the SDK: https://microsoft.github.io/mixed-reality-extension-sdk/enums/primitiveshape.html
9 | ///
10 | public enum PrimitiveShape
11 | {
12 | Sphere,
13 | Box,
14 | Capsule,
15 | Cylinder,
16 | Plane
17 | }
18 |
19 | ///
20 | /// The size, shape, and description of a primitive.
21 | ///
22 | public struct PrimitiveDefinition
23 | {
24 | ///
25 | /// The general shape of the defined primitive.
26 | ///
27 | public PrimitiveShape Shape;
28 |
29 | ///
30 | /// The bounding box of the primitive.
31 | ///
32 | public MWVector3 Dimensions;
33 |
34 | ///
35 | /// The number of horizontal or radial segments of spheres, cylinders, capsules, and planes.
36 | ///
37 | public int? USegments;
38 |
39 | ///
40 | /// The number of vertical or axial segments of spheres, capsules, and planes.
41 | ///
42 | public int? VSegments;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Core/Types/MWColor.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using System;
4 |
5 | namespace MixedRealityExtension.Core.Types
6 | {
7 | ///
8 | /// Class that represents the color type in the Mixed Reality Extension runtime.
9 | ///
10 | public class MWColor : IEquatable
11 | {
12 | ///
13 | /// Gets or sets the red value of the color.
14 | ///
15 | public float R { get; set; }
16 |
17 | ///
18 | /// Gets or sets the green value of the color.
19 | ///
20 | public float G { get; set; }
21 |
22 | ///
23 | /// Gets or sets the blue value of the color.
24 | ///
25 | public float B { get; set; }
26 |
27 | ///
28 | /// Gets or sets the alpha value of the color.
29 | ///
30 | public float A { get; set; }
31 |
32 | ///
33 | /// Initializes a new instance of the class.
34 | ///
35 | public MWColor()
36 | { }
37 |
38 | ///
39 | /// Initializes a new instance of the class.
40 | ///
41 | /// The other to use for the initial value of the components for the new instance.
42 | public MWColor(MWColor color)
43 | {
44 | R = color.R;
45 | G = color.G;
46 | B = color.B;
47 | A = color.A;
48 | }
49 |
50 | ///
51 | /// Initializes a new instance of the class.
52 | ///
53 | /// The initial red value.
54 | /// The initial green value.
55 | /// The initial blue value.
56 | /// The initial alpha value.
57 | public MWColor(float r, float g, float b, float a)
58 | {
59 | R = r;
60 | G = g;
61 | B = b;
62 | A = a;
63 | }
64 |
65 | ///
66 | /// Tests for equality based on value comparisons of the color components.
67 | ///
68 | /// The other color to test equality of components against.
69 | /// Whether the two color are equal by component values.
70 | public bool Equals(MWColor other)
71 | {
72 | return
73 | R.Equals(other.R) &&
74 | G.Equals(other.G) &&
75 | B.Equals(other.B) &&
76 | A.Equals(other.A);
77 | }
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Core/Types/MWQuaternion.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using System;
4 |
5 | namespace MixedRealityExtension.Core.Types
6 | {
7 | ///
8 | /// Class that represents a quaternion in the mixed reality extension runtime.
9 | ///
10 | public class MWQuaternion : IEquatable
11 | {
12 | ///
13 | /// Gets or sets the X component of the quaternion.
14 | ///
15 | public float X { get; set; }
16 |
17 | ///
18 | /// Gets or sets the Y component of the quaternion.
19 | ///
20 | public float Y { get; set; }
21 |
22 | ///
23 | /// Gets or sets the Z component of the quaternion.
24 | ///
25 | public float Z { get; set; }
26 |
27 | ///
28 | /// Gets or sets the W component of the quaternion.
29 | ///
30 | public float W { get; set; }
31 |
32 | ///
33 | /// Initializes a new instance of the class.
34 | ///
35 | public MWQuaternion()
36 | {
37 | X = 0.0f;
38 | Y = 0.0f;
39 | Z = 0.0f;
40 | W = 1.0f;
41 | }
42 |
43 | ///
44 | /// Initializes a new instance of the class.
45 | ///
46 | /// The other to use for the initial value of the components for the new instance.
47 | public MWQuaternion(MWQuaternion quaternion)
48 | {
49 | X = quaternion.X;
50 | Y = quaternion.Y;
51 | Z = quaternion.Z;
52 | W = quaternion.W;
53 | }
54 |
55 | ///
56 | /// Initializes a new instance of the class.
57 | ///
58 | /// The initial value of the X component.
59 | /// The initial value of the Y component.
60 | /// The initial value of the Z component.
61 | /// The initial value of the W component.
62 | public MWQuaternion(float w, float x, float y, float z)
63 | {
64 | X = x;
65 | Y = y;
66 | Z = z;
67 | W = w;
68 | }
69 |
70 | ///
71 | /// Tests for equality based on value comparisons of the quaternion components.
72 | ///
73 | /// The other quaternion to test equality of components against.
74 | /// Whether the two quaternion are equal by component values.
75 | public bool Equals(MWQuaternion other)
76 | {
77 | return
78 | X.Equals(other.X) &&
79 | Y.Equals(other.Y) &&
80 | Z.Equals(other.Z) &&
81 | W.Equals(other.W);
82 | }
83 |
84 | ///
85 | /// Gets the string representation of a instance.
86 | ///
87 | /// The string representation.
88 | public override string ToString()
89 | {
90 | return $"{{ W: {W}, X: {X}, Y: {Y}, Z: {Z} }}";
91 | }
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Core/Types/MWVector2.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using System;
4 |
5 | namespace MixedRealityExtension.Core.Types
6 | {
7 | ///
8 | /// Class that represents a 2D vector within the Mixed Reality Extension runtime.
9 | ///
10 | public class MWVector2 : IEquatable
11 | {
12 | ///
13 | /// Get or sets the X component of the vector.
14 | ///
15 | public float X { get; set; }
16 |
17 | ///
18 | /// Get or sets the Y component of the vector.
19 | ///
20 | public float Y { get; set; }
21 |
22 | ///
23 | /// Initializes a new instance of the class.
24 | ///
25 | public MWVector2()
26 | {
27 | X = 0.0f;
28 | Y = 0.0f;
29 | }
30 |
31 | ///
32 | /// Initializes a new instance of the class.
33 | ///
34 | /// The other to use for the initial value of the components for the new instance.
35 | public MWVector2(MWVector2 vector)
36 | {
37 | X = vector.X;
38 | Y = vector.Y;
39 | }
40 |
41 | ///
42 | /// Initializes a new instance of the class.
43 | ///
44 | /// The initial value of the X component.
45 | /// The initial value of the Y component.
46 | public MWVector2(float x, float y)
47 | {
48 | X = x;
49 | Y = y;
50 | }
51 |
52 | ///
53 | /// Tests for equality based on value comparisons of the vector components.
54 | ///
55 | /// The other vector to test equality of components against.
56 | /// Whether the two vector are equal by component values.
57 | public bool Equals(MWVector2 other)
58 | {
59 | return
60 | X.Equals(other.X) &&
61 | Y.Equals(other.Y);
62 | }
63 |
64 | ///
65 | /// Gets the string representation of a instance.
66 | ///
67 | /// The string representation.
68 | public override string ToString()
69 | {
70 | return $"{{ X: {X}, Y: {Y} }}";
71 | }
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Core/Types/MWVector3.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using System;
4 |
5 | namespace MixedRealityExtension.Core.Types
6 | {
7 | ///
8 | /// Class that represents a 3D vector within the Mixed Reality Extension runtime.
9 | ///
10 | public class MWVector3 : IEquatable
11 | {
12 | ///
13 | /// Get or sets the X component of the vector.
14 | ///
15 | public float X { get; set; }
16 |
17 | ///
18 | /// Get or sets the Y component of the vector.
19 | ///
20 | public float Y { get; set; }
21 |
22 | ///
23 | /// Get or sets the Z component of the vector.
24 | ///
25 | public float Z { get; set; }
26 |
27 | ///
28 | /// Initializes a new instance of the class.
29 | ///
30 | public MWVector3()
31 | {
32 | X = 0.0f;
33 | Y = 0.0f;
34 | Z = 0.0f;
35 | }
36 |
37 | ///
38 | /// Initializes a new instance of the class.
39 | ///
40 | /// The other to use for the initial value of the components for the new instance.
41 | public MWVector3(MWVector3 vector)
42 | {
43 | X = vector.X;
44 | Y = vector.Y;
45 | Z = vector.Z;
46 | }
47 |
48 | ///
49 | /// Initializes a new instance of the class.
50 | ///
51 | /// The initial value of the X component.
52 | /// The initial value of the Y component.
53 | /// The initial value of the Z component.
54 | public MWVector3(float x, float y, float z)
55 | {
56 | X = x;
57 | Y = y;
58 | Z = z;
59 | }
60 |
61 | ///
62 | /// Tests for equality based on value comparisons of the vector components.
63 | ///
64 | /// The other vector to test equality of components against.
65 | /// Whether the two vector are equal by component values.
66 | public bool Equals(MWVector3 other)
67 | {
68 | return
69 | X.Equals(other.X) &&
70 | Y.Equals(other.Y) &&
71 | Z.Equals(other.Z);
72 | }
73 |
74 | ///
75 | /// Gets the string representation of a instance.
76 | ///
77 | /// The string representation.
78 | public override string ToString()
79 | {
80 | return $"{{ X: {X}, Y: {Y}, Z: {Z} }}";
81 | }
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Core/User.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using MixedRealityExtension.App;
4 | using MixedRealityExtension.Core.Interfaces;
5 | using MixedRealityExtension.Messaging.Commands;
6 | using MixedRealityExtension.Messaging.Payloads;
7 | using MixedRealityExtension.Patching;
8 | using MixedRealityExtension.Patching.Types;
9 | using MixedRealityExtension.PluginInterfaces;
10 | using System;
11 | using System.Collections.Generic;
12 | using UnityEngine;
13 |
14 | namespace MixedRealityExtension.Core
15 | {
16 | internal class User : MixedRealityExtensionObject, IUser
17 | {
18 | private IList _joinedApps = new List();
19 |
20 | public override string Name => HostAppUser.Name;
21 |
22 | public IHostAppUser HostAppUser { get; private set; }
23 |
24 | public UInt32 Groups { get; internal set; } = 1;
25 |
26 | public Guid EphemeralUserId { get; private set; }
27 |
28 | internal void Initialize(IHostAppUser hostAppUser, Guid userId, Guid ephemeralUserId, MixedRealityExtensionApp app)
29 | {
30 | HostAppUser = hostAppUser;
31 | base.Initialize(userId, app);
32 | EphemeralUserId = ephemeralUserId;
33 | }
34 |
35 | internal void JoinApp(MixedRealityExtensionApp app)
36 | {
37 | _joinedApps.Add(app);
38 | }
39 |
40 | internal void LeaveApp(MixedRealityExtensionApp app)
41 | {
42 | _joinedApps.Remove(app);
43 | }
44 |
45 | internal void SynchronizeApps()
46 | {
47 | foreach (var mreApp in _joinedApps)
48 | {
49 | var userPatch = new UserPatch(Id);
50 |
51 | // TODO: Write user changes to the patch.
52 |
53 | if (userPatch.IsPatched())
54 | {
55 | mreApp.SynchronizeUser(userPatch);
56 | }
57 | }
58 | }
59 |
60 | internal void SynchronizeEngine(UserPatch patch)
61 | {
62 | // no need to queue like with actors, just slap it right on there
63 | if (patch.Groups.HasValue)
64 | {
65 | Groups = patch.Groups.Value;
66 | }
67 | }
68 |
69 | public override int GetHashCode()
70 | {
71 | return Id.GetHashCode();
72 | }
73 |
74 | public override bool Equals(object obj)
75 | {
76 | return Equals(obj as IUser);
77 | }
78 |
79 | public bool Equals(IUser other)
80 | {
81 | return other != null && Id == other.Id;
82 | }
83 |
84 | protected override void InternalUpdate()
85 | {
86 | SynchronizeApps();
87 | }
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Core/UserManager.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using System;
4 | using System.Collections.Generic;
5 | using MixedRealityExtension.App;
6 |
7 | namespace MixedRealityExtension.Core
8 | {
9 | internal class UserManager
10 | {
11 | private MixedRealityExtensionApp _app;
12 | private Dictionary _userMapping = new Dictionary();
13 |
14 | internal Dictionary.ValueCollection Users => _userMapping.Values;
15 |
16 | internal UserManager(MixedRealityExtensionApp app)
17 | {
18 | _app = app;
19 | }
20 |
21 | internal void AddUser(User user)
22 | {
23 | _userMapping[user.Id] = user;
24 | _userMapping[user.EphemeralUserId] = user;
25 | user.JoinApp(_app);
26 | }
27 |
28 | internal void RemoveUser(User user)
29 | {
30 | user.LeaveApp(_app);
31 | _userMapping.Remove(user.Id);
32 | _userMapping.Remove(user.EphemeralUserId);
33 | }
34 |
35 | internal User FindUser(Guid userId)
36 | {
37 | _userMapping.TryGetValue(userId, out User value);
38 | return value;
39 | }
40 |
41 | internal bool HasUser(Guid userId)
42 | {
43 | return _userMapping.ContainsKey(userId);
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Core/VideoStreamDescription.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace MixedRealityExtension.Core
10 | {
11 | public class VideoStreamDescription : UnityEngine.ScriptableObject
12 | {
13 | //Duration in seconds
14 | public float Duration;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Factories/GLTFImporterFactory.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using System.IO;
4 | using GLTF.Schema;
5 | using MixedRealityExtension.Assets;
6 | using MixedRealityExtension.PluginInterfaces;
7 | using UnityGLTF;
8 | using UnityGLTF.Loader;
9 |
10 | namespace MixedRealityExtension.Factories
11 | {
12 | ///
13 | internal class GLTFImporterFactory : IGLTFImporterFactory
14 | {
15 | ///
16 | public GLTFSceneImporter CreateImporter(
17 | string gltfFileName,
18 | IDataLoader dataLoader,
19 | AsyncCoroutineHelper asyncCoroutineHelper)
20 | {
21 | return new GLTFSceneImporter(gltfFileName, new ImportOptions()
22 | {
23 | DataLoader = dataLoader,
24 | AsyncCoroutineHelper = asyncCoroutineHelper
25 | });
26 | }
27 |
28 | ///
29 | public GLTFSceneImporter CreateImporter(
30 | GLTFRoot rootNode,
31 | IDataLoader dataLoader,
32 | AsyncCoroutineHelper asyncCoroutineHelper,
33 | Stream gltfStream = null)
34 | {
35 | return new GLTFSceneImporter(rootNode, gltfStream, new ImportOptions()
36 | {
37 | DataLoader = dataLoader,
38 | AsyncCoroutineHelper = asyncCoroutineHelper
39 | });
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Factories/MWTextFactory.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using MixedRealityExtension.Core;
4 | using MixedRealityExtension.Core.Interfaces;
5 | using MixedRealityExtension.PluginInterfaces;
6 | using UnityEngine;
7 |
8 | namespace MixedRealityExtension.Factories
9 | {
10 | ///
11 | /// Implements the text component as a Unity Text Mesh
12 | ///
13 | public class MWTextFactory : ITextFactory
14 | {
15 | ///
16 | /// The Unity Font resource used for "serif" text
17 | ///
18 | public Font SerifFont { get; private set; }
19 |
20 | ///
21 | /// The Unity Font resource used for "sans serif" text
22 | ///
23 | public Font SansSerifFont { get; private set; }
24 |
25 | ///
26 | /// Initialize a text factory
27 | ///
28 | /// The Unity font resource for "serif" text
29 | /// The Unity font resource for "sans serif" text
30 | public MWTextFactory(Font serif, Font sansSerif)
31 | {
32 | SerifFont = serif;
33 | SansSerifFont = sansSerif;
34 | }
35 |
36 | ///
37 | public IText CreateText(IActor actor)
38 | {
39 | var actorGo = (Actor)actor;
40 | var textMesh = actorGo.gameObject.GetComponent();
41 | if (textMesh == null)
42 | {
43 | textMesh = actorGo.gameObject.AddComponent();
44 | textMesh.richText = false;
45 | textMesh.lineSpacing = 1.0f;
46 | }
47 | return actorGo.Text ?? new Text(textMesh);
48 | }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Factories/SimpleLayerApplicator.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 |
4 | using CollisionLayer = MixedRealityExtension.Core.CollisionLayer;
5 | using ILayerApplicator = MixedRealityExtension.PluginInterfaces.ILayerApplicator;
6 | using Collider = UnityEngine.Collider;
7 |
8 | namespace MixedRealityExtension.Factories
9 | {
10 | ///
11 | /// A simple implementation of ILayerApplicator that simply sets collision actors' `layer` properties.
12 | ///
13 | public class SimpleLayerApplicator : ILayerApplicator
14 | {
15 | protected readonly byte defaultLayer;
16 | protected readonly byte navigationLayer;
17 | protected readonly byte hologramLayer;
18 | protected readonly byte uiLayer;
19 |
20 | ///
21 | public byte DefaultLayer => defaultLayer;
22 |
23 | ///
24 | /// Apply the given Unity layers to MRE colliders.
25 | ///
26 | ///
27 | ///
28 | ///
29 | ///
30 | public SimpleLayerApplicator(byte defaultLayer, byte navigationLayer, byte hologramLayer, byte uiLayer)
31 | {
32 | this.defaultLayer = defaultLayer;
33 | this.navigationLayer = navigationLayer;
34 | this.hologramLayer = hologramLayer;
35 | this.uiLayer = uiLayer;
36 | }
37 |
38 | ///
39 | public virtual void ApplyLayerToCollider(CollisionLayer? layer, Collider collider)
40 | {
41 | if (!layer.HasValue) return;
42 |
43 | switch (layer)
44 | {
45 | case CollisionLayer.Default:
46 | collider.gameObject.layer = defaultLayer;
47 | break;
48 | case CollisionLayer.Navigation:
49 | collider.gameObject.layer = navigationLayer;
50 | break;
51 | case CollisionLayer.Hologram:
52 | collider.gameObject.layer = hologramLayer;
53 | break;
54 | case CollisionLayer.UI:
55 | collider.gameObject.layer = uiLayer;
56 | break;
57 | }
58 | }
59 |
60 | ///
61 | public virtual CollisionLayer DetermineLayerOfCollider(Collider collider)
62 | {
63 | if (collider.gameObject.layer == navigationLayer)
64 | {
65 | return CollisionLayer.Navigation;
66 | }
67 | else if (collider.gameObject.layer == hologramLayer)
68 | {
69 | return CollisionLayer.Hologram;
70 | }
71 | else if (collider.gameObject.layer == uiLayer)
72 | {
73 | return CollisionLayer.UI;
74 | }
75 | else
76 | {
77 | return CollisionLayer.Default;
78 | }
79 | }
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Factories/SimplePermissionsManager.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using MixedRealityExtension.Core;
4 | using MixedRealityExtension.PluginInterfaces;
5 | using System;
6 | using System.Collections.Generic;
7 | using System.Linq;
8 | using System.Text;
9 | using System.Threading;
10 | using System.Threading.Tasks;
11 |
12 | namespace MixedRealityExtension.Factories
13 | {
14 | ///
15 | /// Simple permission manager that grants a fixed set of permissions to all MREs
16 | ///
17 | public class SimplePermissionManager : IPermissionManager
18 | {
19 | ///
20 | /// The static set of permissions that this manager grants
21 | ///
22 | public Permissions GrantedPermissions { get; private set; }
23 |
24 | ///
25 | /// Set up the simple manager
26 | ///
27 | /// The permissions to grant to all MREs
28 | public SimplePermissionManager(Permissions grantedPermissions)
29 | {
30 | GrantedPermissions = grantedPermissions;
31 | }
32 |
33 | ///
34 | public event Action OnPermissionDecisionsChanged;
35 |
36 | ///
37 | public Task PromptForPermissions(
38 | Uri appLocation,
39 | IEnumerable permissionsNeeded,
40 | IEnumerable permissionsWanted,
41 | Permissions permissionFlagsNeeded,
42 | Permissions permissionFlagsWanted,
43 | AppManifest appManifest,
44 | CancellationToken cancellationToken)
45 | {
46 | return Task.FromResult(GrantedPermissions);
47 | }
48 |
49 | ///
50 | public Permissions CurrentPermissions(Uri appLocation)
51 | {
52 | return GrantedPermissions;
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/IPC/IConnection.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using MixedRealityExtension.Messaging;
4 | using System;
5 |
6 | namespace MixedRealityExtension.IPC
7 | {
8 | ///
9 | /// Event handler type with no arguments.
10 | ///
11 | public delegate void MWEventHandler();
12 |
13 | ///
14 | /// Event handler type with an argument.
15 | ///
16 | ///
17 | ///
18 | public delegate void MWEventHandler(ArgsT args);
19 |
20 | ///
21 | /// Event handler type with two arguments.
22 | ///
23 | ///
24 | ///
25 | ///
26 | ///
27 | public delegate void MWEventHandler(ArgsT arg1, ArgsU arg2);
28 |
29 | ///
30 | /// The set of possible reason codes passed to the OnConnectFailed event.
31 | ///
32 | public enum ConnectFailedReason
33 | {
34 | ///
35 | /// The connection failed to establish.
36 | ///
37 | ConnectionFailed,
38 |
39 | ///
40 | /// The connection was refused due to a protocol version mismatch.
41 | ///
42 | UnsupportedProtocol
43 | }
44 |
45 | ///
46 | /// Interface representing a connection.
47 | ///
48 | public interface IConnection : IDisposable
49 | {
50 | ///
51 | /// Invoked before the connection attempt is initiated.
52 | ///
53 | event MWEventHandler OnConnecting;
54 |
55 | ///
56 | /// Invoked after the connection attempt failed.
57 | ///
58 | event MWEventHandler OnConnectFailed;
59 |
60 | ///
61 | /// Invoked after the connection attempt succeeds.
62 | ///
63 | event MWEventHandler OnConnected;
64 |
65 | ///
66 | /// Invoked after the connection has been closed.
67 | ///
68 | event MWEventHandler OnDisconnected;
69 |
70 | ///
71 | /// Invoked after the connection receives a message;
72 | ///
73 | event MWEventHandler OnReceive;
74 |
75 | ///
76 | /// Invoked when an error occurred on the connection.
77 | ///
78 | event MWEventHandler OnError;
79 |
80 | ///
81 | /// Returns true if the connection is in an active state (i.e. if Open has been called).
82 | ///
83 | bool IsActive { get; }
84 |
85 | ///
86 | /// Opens the connection.
87 | ///
88 | void Open();
89 |
90 | ///
91 | /// Closes the connection.
92 | ///
93 | void Close();
94 |
95 | ///
96 | /// Sends a message to the remote endpoint.
97 | ///
98 | /// The message to send.
99 | void Send(Message message);
100 | }
101 |
102 | internal interface IConnectionInternal : IConnection
103 | {
104 | void Update();
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/LookAtMode.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | namespace MixedRealityExtension
4 | {
5 | ///
6 | /// What is the actor facing?
7 | ///
8 | public enum LookAtMode
9 | {
10 | ///
11 | /// The actor's orientation is determined entirely by its transform
12 | ///
13 | None,
14 |
15 | ///
16 | /// The actor rotates on its Y axis to point toward the target
17 | ///
18 | TargetY,
19 |
20 | ///
21 | /// The actor rotates on its X and Y axes to point toward the target
22 | ///
23 | TargetXY
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Messaging/Commands/Command.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using System;
4 | using System.Reflection;
5 |
6 | namespace MixedRealityExtension.Messaging.Commands
7 | {
8 | internal class Command : ICommand where T : ICommandPayload
9 | {
10 | private readonly T _commandPayload;
11 | private Action _onCompleteCallback;
12 |
13 | public Command(T commandPayload, Action onCompleteCallback)
14 | {
15 | _commandPayload = commandPayload;
16 | _onCompleteCallback = onCompleteCallback;
17 | }
18 |
19 | public void Execute(ICommandHandlerContext handlerContext, MethodInfo handlerMethod)
20 | {
21 | if (handlerMethod != null)
22 | {
23 | handlerMethod.Invoke(handlerContext, new object[] { _commandPayload, _onCompleteCallback });
24 | }
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Messaging/Commands/CommandHandler.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using System;
4 |
5 | namespace MixedRealityExtension.Messaging.Commands
6 | {
7 | [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
8 | internal class CommandHandler : Attribute
9 | {
10 | public Type CommandType { get; }
11 |
12 | public CommandHandler(Type commandType)
13 | {
14 | CommandType = commandType;
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Messaging/Commands/ICommand.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using System.Reflection;
4 |
5 | namespace MixedRealityExtension.Messaging.Commands
6 | {
7 | internal interface ICommand
8 | {
9 | void Execute(ICommandHandlerContext handlerContext, MethodInfo handlerMethod);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Messaging/Commands/ICommandHandlerContext.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | namespace MixedRealityExtension.Messaging.Commands
4 | {
5 | internal interface ICommandHandlerContext
6 | {
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Messaging/Commands/ICommandManager.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using System;
4 |
5 | namespace MixedRealityExtension.Messaging.Commands
6 | {
7 | internal interface ICommandManager
8 | {
9 | void ExecuteCommandPayload(ICommandHandlerContext handlerContext, ICommandPayload commandPayload, Action onCompleteCallback);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Messaging/Commands/ICommandPayload.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | namespace MixedRealityExtension.Messaging.Commands
4 | {
5 | public interface ICommandPayload
6 | {
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Messaging/Events/IMWEvent.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using MixedRealityExtension.App;
4 | using System;
5 |
6 | namespace MixedRealityExtension.Messaging.Events
7 | {
8 | internal interface IMWEvent
9 | {
10 | Guid ActorId { get; }
11 |
12 | void SendEvent(MixedRealityExtensionApp app);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Messaging/Events/MWEventBase.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using MixedRealityExtension.App;
4 | using System;
5 |
6 | namespace MixedRealityExtension.Messaging.Events
7 | {
8 | internal abstract class MWEventBase : IMWEvent
9 | {
10 | internal Guid ActorId { get; }
11 |
12 | internal MWEventBase(Guid actorId)
13 | {
14 | ActorId = actorId;
15 | }
16 |
17 | internal abstract void SendEvent(MixedRealityExtensionApp app);
18 |
19 | #region IMWEvent
20 |
21 | Guid IMWEvent.ActorId => this.ActorId;
22 |
23 | void IMWEvent.SendEvent(MixedRealityExtensionApp app)
24 | {
25 | this.SendEvent(app);
26 | }
27 |
28 | #endregion
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Messaging/Events/MWEventManager.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using MixedRealityExtension.App;
4 | using MixedRealityExtension.Messaging.Payloads;
5 | using System.Collections.Generic;
6 |
7 | namespace MixedRealityExtension.Messaging.Events
8 | {
9 | internal class MWEventManager
10 | {
11 | private readonly MixedRealityExtensionApp _app;
12 | private readonly Queue _eventsQueue;
13 | private readonly Queue _lateEventsQueue;
14 |
15 | internal MWEventManager(MixedRealityExtensionApp app)
16 | {
17 | _app = app;
18 | _eventsQueue = new Queue();
19 | _lateEventsQueue = new Queue();
20 | }
21 |
22 | internal void ProcessEvents()
23 | {
24 | ProcessQueue(_eventsQueue, _app);
25 | }
26 |
27 | internal void ProcessLateEvents()
28 | {
29 | ProcessQueue(_lateEventsQueue, _app);
30 | }
31 |
32 | internal void QueueEvent(IMWEvent networkEvent)
33 | {
34 | _eventsQueue.Enqueue(networkEvent);
35 | }
36 |
37 | internal void QueueLateEvent(IMWEvent networkEvent)
38 | {
39 | _lateEventsQueue.Enqueue(networkEvent);
40 | }
41 |
42 | private static void ProcessQueue(Queue eventQueue, MixedRealityExtensionApp app)
43 | {
44 | if (eventQueue.Count > 0)
45 | {
46 | var payloads = new List();
47 | while (eventQueue.Count != 0)
48 | {
49 | eventQueue.Dequeue().SendEvent(app);
50 | }
51 | }
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Messaging/Events/Types/ActorChangedEvent.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using MixedRealityExtension.App;
4 | using MixedRealityExtension.Messaging.Payloads;
5 | using MixedRealityExtension.Patching.Types;
6 | using System;
7 |
8 | namespace MixedRealityExtension.Messaging.Events.Types
9 | {
10 | internal class ActorChangedEvent : MWEventBase
11 | {
12 | private readonly ActorPatch _actor;
13 |
14 | internal ActorChangedEvent(Guid actorId, ActorPatch actor)
15 | : base(actorId)
16 | {
17 | _actor = actor;
18 | }
19 |
20 | internal override void SendEvent(MixedRealityExtensionApp app)
21 | {
22 | app.Protocol.Send(new ActorUpdate()
23 | {
24 | Actor = _actor
25 | });
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Messaging/Events/Types/ActorCorrectionEvent.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using MixedRealityExtension.App;
4 | using MixedRealityExtension.Messaging.Payloads;
5 | using System;
6 |
7 | namespace MixedRealityExtension.Messaging.Events.Types
8 | {
9 | class ActorCorrectionEvent: MWEventBase
10 | {
11 | private readonly ActorCorrection _actorCorrection;
12 |
13 | internal ActorCorrectionEvent(Guid actorId, ActorCorrection actorCorrection)
14 | : base(actorId)
15 | {
16 | _actorCorrection = actorCorrection;
17 | }
18 |
19 | internal override void SendEvent(MixedRealityExtensionApp app)
20 | {
21 | app.Protocol.Send(_actorCorrection);
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Messaging/Events/Types/BehaviorEvent.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using MixedRealityExtension.App;
4 | using MixedRealityExtension.Messaging.Payloads;
5 | using System;
6 |
7 | namespace MixedRealityExtension.Messaging.Events.Types
8 | {
9 | internal class BehaviorEvent : MWEventBase
10 | {
11 | private readonly ActionPerformed _actionPerformed;
12 |
13 | public BehaviorEvent(ActionPerformed actionPerformed)
14 | : base(actionPerformed.UserId)
15 | {
16 | _actionPerformed = actionPerformed;
17 | }
18 |
19 | internal override void SendEvent(MixedRealityExtensionApp app)
20 | {
21 | app.Protocol.Send(_actionPerformed);
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Messaging/Events/Types/ColliderEvent.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 |
4 | using System;
5 | using MixedRealityExtension.App;
6 | using MixedRealityExtension.Core.Collision;
7 | using MixedRealityExtension.Messaging.Payloads;
8 |
9 | namespace MixedRealityExtension.Messaging.Events.Types
10 | {
11 | internal class CollisionEvent: MWEventBase
12 | {
13 | private readonly ColliderEventType _eventType;
14 | private readonly CollisionData _collisionData;
15 |
16 | internal CollisionEvent(Guid actorId, ColliderEventType eventType, CollisionData collisionData)
17 | : base(actorId)
18 | {
19 | _eventType = eventType;
20 | _collisionData = collisionData;
21 | }
22 |
23 | internal override void SendEvent(MixedRealityExtensionApp app)
24 | {
25 | app.Protocol.Send(new CollisionEventRaised()
26 | {
27 | ActorId = ActorId,
28 | EventType = _eventType,
29 | CollisionData = _collisionData
30 | });
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Messaging/Events/Types/PhysicsBridgeUpdated.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using System;
4 | using MixedRealityExtension.App;
5 | using MixedRealityExtension.Messaging.Payloads;
6 | using MixedRealityExtension.Patching.Types;
7 |
8 | namespace MixedRealityExtension.Messaging.Events.Types
9 | {
10 | internal class PhysicsBridgeUpdated : MWEventBase
11 | {
12 | private readonly PhysicsBridgePatch _physicsBridgePatch;
13 |
14 | public PhysicsBridgeUpdated(Guid id, PhysicsBridgePatch physicsBridgePatch)
15 | : base(id)
16 | {
17 | _physicsBridgePatch = physicsBridgePatch;
18 | }
19 |
20 | internal override void SendEvent(MixedRealityExtensionApp app)
21 | {
22 | if (app.Protocol == null)
23 | {
24 | return;
25 | }
26 |
27 | app.Protocol.Send(new PhysicsBridgeUpdate()
28 | {
29 | PhysicsBridgePatch = _physicsBridgePatch
30 | });
31 | }
32 | }
33 |
34 | internal class PhysicsTranformServerUploadUpdated : MWEventBase
35 | {
36 | private readonly PhysicsTranformServerUploadPatch _physicsTransformUploadPatch;
37 |
38 | public PhysicsTranformServerUploadUpdated(Guid id, PhysicsTranformServerUploadPatch physicsServerUploadPatch)
39 | : base(id)
40 | {
41 | _physicsTransformUploadPatch = physicsServerUploadPatch;
42 | }
43 |
44 | internal override void SendEvent(MixedRealityExtensionApp app)
45 | {
46 | if (app.Protocol == null)
47 | {
48 | return;
49 | }
50 |
51 | app.Protocol.Send(new PhysicsTranformServerUpload()
52 | {
53 | PhysicsTranformServer = _physicsTransformUploadPatch
54 | });
55 | }
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Messaging/Events/Types/ResponseEvent.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using System;
4 | using MixedRealityExtension.App;
5 | using MixedRealityExtension.Messaging.Payloads;
6 |
7 | namespace MixedRealityExtension.Messaging.Events.Types
8 | {
9 | internal class ResponseEvent : MWEventBase
10 | {
11 | private string _responseId;
12 | private Payload _payload;
13 |
14 | internal ResponseEvent(Guid actorId, string responseId, Payload payload)
15 | : base(actorId)
16 | {
17 | _responseId = responseId;
18 | _payload = payload;
19 | }
20 |
21 | internal override void SendEvent(MixedRealityExtensionApp app)
22 | {
23 | app.Protocol.Send(_payload, _responseId);
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Messaging/Events/Types/SetAnimationStateEvent.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using MixedRealityExtension.Animation;
4 | using MixedRealityExtension.App;
5 | using MixedRealityExtension.Messaging.Payloads;
6 | using MixedRealityExtension.Patching.Types;
7 | using System;
8 | using System.Collections.Generic;
9 |
10 | namespace MixedRealityExtension.Messaging.Events.Types
11 | {
12 | internal class SetAnimationStateEvent : MWEventBase
13 | {
14 | private readonly string animationName;
15 | private readonly float? animationTime;
16 | private readonly float? animationSpeed;
17 | private readonly bool? animationEnabled;
18 |
19 | public SetAnimationStateEvent(
20 | Guid actorId,
21 | string animationName,
22 | float? animationTime,
23 | float? animationSpeed,
24 | bool? animationEnabled)
25 | : base(actorId)
26 | {
27 | this.animationName = animationName;
28 | this.animationTime = animationTime;
29 | this.animationSpeed = animationSpeed;
30 | this.animationEnabled = animationEnabled;
31 | }
32 |
33 | internal override void SendEvent(MixedRealityExtensionApp app)
34 | {
35 | app.Protocol.Send(new SetAnimationState
36 | {
37 | ActorId = this.ActorId,
38 | AnimationName = this.animationName,
39 | State = new MWSetAnimationStateOptions
40 | {
41 | Time = this.animationTime,
42 | Speed = this.animationSpeed,
43 | Enabled = this.animationEnabled
44 | }
45 | });
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Messaging/Events/Types/TriggerEvent.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 |
4 | using MixedRealityExtension.App;
5 | using MixedRealityExtension.Core.Collision;
6 | using MixedRealityExtension.Messaging.Payloads;
7 | using System;
8 |
9 | namespace MixedRealityExtension.Messaging.Events.Types
10 | {
11 | internal class TriggerEvent: MWEventBase
12 | {
13 | private readonly ColliderEventType _eventType;
14 | private readonly Guid _otherActor;
15 |
16 | internal TriggerEvent(Guid actorId, ColliderEventType eventType, Guid otherActor)
17 | : base(actorId)
18 | {
19 | _eventType = eventType;
20 | _otherActor = otherActor;
21 | }
22 |
23 | internal override void SendEvent(MixedRealityExtensionApp app)
24 | {
25 | app.Protocol.Send(new TriggerEventRaised()
26 | {
27 | ActorId = ActorId,
28 | EventType = _eventType,
29 | OtherActorId = _otherActor
30 | });
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Messaging/Events/Types/UserEvent.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using MixedRealityExtension.App;
4 | using MixedRealityExtension.Messaging.Payloads;
5 | using System;
6 |
7 | namespace MixedRealityExtension.Messaging.Events.Types
8 | {
9 | internal class UserEvent : MWEventBase
10 | {
11 | private Payload _payload;
12 |
13 | internal UserEvent(Guid userId, Payload payload)
14 | : base(userId)
15 | {
16 | _payload = payload;
17 | }
18 |
19 | internal override void SendEvent(MixedRealityExtensionApp app)
20 | {
21 | app.Protocol.Send(_payload);
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Messaging/Message.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using MixedRealityExtension.Messaging.Payloads;
4 |
5 | namespace MixedRealityExtension.Messaging
6 | {
7 | ///
8 | /// Represents a message sent and received over a connection.
9 | ///
10 | public class Message
11 | {
12 | ///
13 | /// The message unique id.
14 | ///
15 | public string Id { get; set; }
16 |
17 | ///
18 | /// If this message is a reply, this is the id of the message being replied to.
19 | ///
20 | public string ReplyToId { get; set; }
21 |
22 | ///
23 | /// The message payload.
24 | ///
25 | public Payload Payload { get; set; }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Messaging/Payloads/AssetCommandPayloads.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using System;
4 | using System.Collections.Generic;
5 | using MixedRealityExtension.Assets;
6 | using MixedRealityExtension.Core;
7 |
8 | namespace MixedRealityExtension.Messaging.Payloads
9 | {
10 | ///
11 | /// App => Engine
12 | /// Payload instructing the engine to preload the listed asset container.
13 | ///
14 | public class LoadAssets : NetworkCommandPayload
15 | {
16 | ///
17 | /// The logical container that the new assets should be assigned to.
18 | ///
19 | public Guid ContainerId;
20 |
21 | ///
22 | /// The asset container to load.
23 | ///
24 | public AssetSource Source;
25 |
26 | ///
27 | /// The type of collider to add to the actor upon creation.
28 | ///
29 | public ColliderType ColliderType;
30 | }
31 |
32 | ///
33 | /// Engine => App
34 | /// Replies to LoadAssetRequests with the contents of the loaded bundle.
35 | ///
36 | public class AssetsLoaded : NetworkCommandPayload
37 | {
38 | ///
39 | /// If the load failed, this string contains the reason why.
40 | ///
41 | public string FailureMessage { get; set; }
42 |
43 | ///
44 | /// The loaded assets.
45 | ///
46 | public Asset[] Assets { get; set; }
47 | }
48 |
49 | ///
50 | /// App => Engine
51 | /// An asset has updated.
52 | ///
53 | public class AssetUpdate : NetworkCommandPayload
54 | {
55 | ///
56 | /// The asset that was updated
57 | ///
58 | public Asset Asset;
59 | }
60 |
61 | ///
62 | /// App => Engine
63 | /// Instructs the engine to instantiate the prefab with the given ID.
64 | ///
65 | public class CreateFromPrefab : CreateActor
66 | {
67 | ///
68 | /// The ID of an already-loaded asset
69 | ///
70 | public Guid PrefabId;
71 |
72 | ///
73 | /// Assign all colliders in this prefab to this layer
74 | ///
75 | public CollisionLayer? CollisionLayer;
76 | }
77 |
78 | ///
79 | /// App => Engine
80 | /// Generate a new native asset with the included properties
81 | ///
82 | public class CreateAsset : NetworkCommandPayload
83 | {
84 | ///
85 | /// The logical container that the new assets should be assigned to.
86 | ///
87 | public Guid ContainerId;
88 |
89 | ///
90 | /// Initial properties of the newly created asset
91 | ///
92 | public Asset Definition;
93 | }
94 |
95 | ///
96 | /// App => Engine
97 | /// Destroy all assets in the given container
98 | ///
99 | public class UnloadAssets : NetworkCommandPayload
100 | {
101 | ///
102 | /// The container to unload
103 | ///
104 | public Guid ContainerId;
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Messaging/Payloads/Converters/CollisionGeometryConverter.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 |
4 | using MixedRealityExtension.API;
5 | using MixedRealityExtension.Core;
6 | using Newtonsoft.Json;
7 | using Newtonsoft.Json.Linq;
8 | using System;
9 |
10 | namespace MixedRealityExtension.Messaging.Payloads.Converters
11 | {
12 | ///
13 | /// Json converter for collision geometry serialization data.
14 | ///
15 | public class CollisionGeometryConverter : JsonConverter
16 | {
17 | ///
18 | public override bool CanConvert(Type objectType)
19 | {
20 | return objectType == typeof(ColliderGeometry);
21 | }
22 |
23 | ///
24 | public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
25 | {
26 | try
27 | {
28 | JObject jObject = JObject.Load(reader);
29 | var colliderType = jObject["shape"].ToObject();
30 |
31 | ColliderGeometry colliderGeometry = null;
32 | switch (colliderType)
33 | {
34 | case "sphere":
35 | colliderGeometry = new SphereColliderGeometry();
36 | break;
37 | case "box":
38 | colliderGeometry = new BoxColliderGeometry();
39 | break;
40 | case "capsule":
41 | colliderGeometry = new CapsuleColliderGeometry();
42 | break;
43 | case "mesh":
44 | colliderGeometry = new MeshColliderGeometry();
45 | break;
46 | case "auto":
47 | colliderGeometry = new AutoColliderGeometry();
48 | break;
49 | default:
50 | MREAPI.Logger.LogError($"Failed to deserialize collider geometry. Invalid collider type <{colliderType}>.");
51 | break;
52 | }
53 |
54 | serializer.Populate(jObject.CreateReader(), colliderGeometry);
55 |
56 | return colliderGeometry;
57 | }
58 | catch (Exception e)
59 | {
60 | MREAPI.Logger.LogError($"Failed to create collider geometry from json. Exception: {e.Message}\nStack Trace: {e.StackTrace}");
61 | throw;
62 | }
63 | }
64 |
65 | ///
66 | public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
67 | {
68 | writer.WriteValue(value);
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Messaging/Payloads/Converters/DashFormattedEnumConverter.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using System;
4 | using System.Text;
5 | using MixedRealityExtension.Util;
6 | using Newtonsoft.Json;
7 |
8 | namespace MixedRealityExtension.Messaging.Payloads.Converters
9 | {
10 | ///
11 | /// Json converter for dash-formatted enumerations.
12 | ///
13 | public class DashFormattedEnumConverter : JsonConverter
14 | {
15 | ///
16 | public override bool CanConvert(Type objectType)
17 | {
18 | return UtilMethods.GetActualType(objectType).IsEnum;
19 | }
20 |
21 | ///
22 | public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
23 | {
24 | var value = (string)reader.Value;
25 | value = value.Replace("-", "");
26 | return Enum.Parse(UtilMethods.GetActualType(objectType), value, true);
27 | }
28 |
29 | ///
30 | public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
31 | {
32 | var name = Enum.GetName(UtilMethods.GetActualType(value.GetType()), value);
33 |
34 | var sb = new StringBuilder();
35 |
36 | for (var i = 0; i < name.Length; ++i)
37 | {
38 | if (i > 0 && Char.IsUpper(name[i]))
39 | {
40 | sb.Append('-');
41 | }
42 | sb.Append(Char.ToLower(name[i]));
43 | }
44 |
45 | writer.WriteValue(sb.ToString());
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Messaging/Payloads/Converters/UnsignedConverter.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using System;
4 | using System.Text;
5 | using MixedRealityExtension.Util;
6 | using Newtonsoft.Json;
7 |
8 | namespace MixedRealityExtension.Messaging.Payloads.Converters
9 | {
10 | ///
11 | /// Converts signed integers into bit-equivalent unsigned integers,
12 | /// because JS doesn't have a concept of unsigned.
13 | ///
14 | public class UnsignedConverter : JsonConverter
15 | {
16 | ///
17 | public override bool CanConvert(Type objectType)
18 | {
19 | return UtilMethods.GetActualType(objectType) == typeof(UInt32);
20 | }
21 |
22 | ///
23 | public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
24 | {
25 | if (reader.TokenType == JsonToken.Integer)
26 | {
27 | Int32 signed = Convert.ToInt32((Int64)reader.Value);
28 | byte[] bytes = BitConverter.GetBytes(signed);
29 | UInt32 unsigned = BitConverter.ToUInt32(bytes, 0);
30 | return unsigned;
31 | }
32 | else
33 | {
34 | UnityEngine.Debug.Log($"Failed to deserialize {reader.ValueType} {reader.Value}");
35 | return null;
36 | }
37 | }
38 |
39 | ///
40 | public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
41 | {
42 | UInt32 unsigned = (UInt32)value;
43 | byte[] bytes = BitConverter.GetBytes(unsigned);
44 | Int32 signed = BitConverter.ToInt32(bytes, 0);
45 | writer.WriteValue(signed);
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Messaging/Payloads/IPayload.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using MixedRealityExtension.Messaging.Commands;
4 |
5 | namespace MixedRealityExtension.Messaging.Payloads
6 | {
7 | public interface IPayload
8 | {
9 | string Type { get; }
10 | }
11 |
12 | public interface INetworkCommandPayload : IPayload, ICommandPayload
13 | {
14 | string MessageId { get; set; }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Messaging/Payloads/Payload.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using MixedRealityExtension.API;
4 | using System;
5 | using System.Collections.Generic;
6 | using UnityEngine;
7 |
8 | namespace MixedRealityExtension.Messaging.Payloads
9 | {
10 | public class Payload
11 | {
12 | public string Type { get; private set; }
13 |
14 | public IList Traces { get; set; }
15 |
16 | public Payload()
17 | {
18 | Type = PayloadTypeRegistry.GetNetworkType(this.GetType());
19 |
20 | #if ANDROID_DEBUG
21 | MREAPI.Logger.LogDebug($"Creating payload of type {Type} for the payload class type {this.GetType()}");
22 | #endif
23 | }
24 |
25 | public void AddTrace(Trace trace)
26 | {
27 | Traces = Traces ?? new List();
28 | Traces.Add(trace);
29 | }
30 | }
31 |
32 | public class NetworkCommandPayload : Payload, INetworkCommandPayload
33 | {
34 | public string MessageId { get; set; }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Messaging/Payloads/PayloadConverter.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using MixedRealityExtension.API;
4 | using Newtonsoft.Json;
5 | using Newtonsoft.Json.Linq;
6 | using System;
7 |
8 | namespace MixedRealityExtension.Messaging.Payloads
9 | {
10 | public class PayloadConverter : JsonConverter
11 | {
12 | public override bool CanConvert(Type objectType)
13 | {
14 | return objectType == typeof(Payload);
15 | }
16 |
17 | public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
18 | {
19 | try
20 | {
21 | JObject jObject = JObject.Load(reader);
22 | var networkType = jObject["type"].ToObject();
23 | Payload payload = PayloadTypeRegistry.CreatePayloadFromNetwork(networkType);
24 | serializer.Populate(jObject.CreateReader(), payload);
25 |
26 | return payload;
27 | }
28 | catch (Exception e)
29 | {
30 | MREAPI.Logger.LogError($"Failed to create payload from json. Exception: {e.Message}\nStack Trace: {e.StackTrace}");
31 | throw;
32 | }
33 | }
34 |
35 | public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
36 | {
37 | JToken token = JToken.FromObject(value);
38 | token.WriteTo(writer);
39 | }
40 | }
41 |
42 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
43 | public class PayloadType : Attribute
44 | {
45 | public string NetworkType { get; }
46 |
47 | public Type ClassType { get; }
48 |
49 | public PayloadType(Type classType, string networkType)
50 | {
51 | ClassType = classType;
52 | NetworkType = networkType;
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Messaging/Protocols/Execution.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using System;
4 | using MixedRealityExtension.App;
5 |
6 | namespace MixedRealityExtension.Messaging.Protocols
7 | {
8 | internal class Execution : Protocol
9 | {
10 | internal Execution(MixedRealityExtensionApp app)
11 | : base(app)
12 | { }
13 |
14 | protected override void InternalStart()
15 | {
16 | }
17 |
18 | protected override void InternalComplete()
19 | {
20 | }
21 |
22 | protected override void InternalReceive(Message message)
23 | {
24 | Dispatch(message);
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Messaging/Protocols/Handshake.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using System;
4 | using MixedRealityExtension.API;
5 | using MixedRealityExtension.App;
6 | using MixedRealityExtension.IPC;
7 | using MixedRealityExtension.Messaging.Payloads;
8 |
9 | namespace MixedRealityExtension.Messaging.Protocols
10 | {
11 | internal class Handshake : Protocol
12 | {
13 | public event MWEventHandler OnOperatingModel;
14 |
15 | internal Handshake(MixedRealityExtensionApp app)
16 | : base(app)
17 | {
18 | }
19 |
20 | protected override void InternalStart()
21 | {
22 | var handshake = new Payloads.Handshake()
23 | {
24 | };
25 |
26 | Send(handshake);
27 | }
28 |
29 | protected override void InternalComplete()
30 | {
31 | foreach (var handler in OnOperatingModel?.GetInvocationList())
32 | {
33 | OnOperatingModel -= (MWEventHandler)handler;
34 | }
35 | }
36 |
37 | protected override void InternalReceive(Message message)
38 | {
39 | if (message.Payload is HandshakeReply handshakeReply)
40 | {
41 | OnOperatingModel?.Invoke(handshakeReply.OperatingModel);
42 |
43 | Send(new HandshakeComplete());
44 |
45 | Complete();
46 | }
47 | else
48 | {
49 | App.Logger.LogDebug("Unexpected message");
50 | }
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Messaging/Protocols/IProtocol.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using MixedRealityExtension.IPC;
4 | using MixedRealityExtension.Messaging.Payloads;
5 |
6 | namespace MixedRealityExtension.Messaging.Protocols
7 | {
8 | internal interface IProtocol
9 | {
10 | event MWEventHandler OnComplete;
11 |
12 | void Start();
13 |
14 | void Stop();
15 |
16 | void Complete();
17 |
18 | void Receive(Message message);
19 |
20 | void Send(Message message);
21 |
22 | void Send(Payload payload, string replyToId = null);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Messaging/Protocols/Idle.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using MixedRealityExtension.App;
4 | using MixedRealityExtension.IPC;
5 |
6 | // TODO: Objects should not be visible until synchronization is complete.
7 |
8 | namespace MixedRealityExtension.Messaging.Protocols
9 | {
10 | internal class Idle : Protocol
11 | {
12 | internal Idle(MixedRealityExtensionApp app)
13 | : base(app)
14 | { }
15 |
16 | protected override void InternalStart()
17 | {
18 | }
19 |
20 | protected override void InternalComplete()
21 | {
22 | }
23 |
24 | protected override void InternalReceive(Message message)
25 | {
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Messaging/Protocols/Sync.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using MixedRealityExtension.App;
4 |
5 | // TODO: Objects should not be visible until synchronization is complete.
6 |
7 | namespace MixedRealityExtension.Messaging.Protocols
8 | {
9 | internal class Sync : Protocol
10 | {
11 | internal Sync(MixedRealityExtensionApp app)
12 | : base(app)
13 | { }
14 |
15 | protected override void InternalStart()
16 | {
17 | Send(new Payloads.SyncRequest());
18 | }
19 |
20 | protected override void InternalComplete()
21 | {
22 | }
23 |
24 | protected override void InternalReceive(Message message)
25 | {
26 | if (message.Payload is Payloads.SyncComplete)
27 | {
28 | Complete();
29 | }
30 | else
31 | {
32 | Dispatch(message);
33 | }
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Messaging/Tracing.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | namespace MixedRealityExtension.Messaging
4 | {
5 | public enum TraceSeverity
6 | {
7 | Debug,
8 | Info,
9 | Warning,
10 | Error
11 | }
12 |
13 | public class Trace
14 | {
15 | public TraceSeverity Severity;
16 | public string Message;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Patching/IPatchable.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using MixedRealityExtension.Animation;
4 | using Newtonsoft.Json.Linq;
5 |
6 | namespace MixedRealityExtension.Patching
7 | {
8 | internal interface IPatchable
9 | {
10 | ///
11 | /// Returns whether this patch has any non-null properties
12 | ///
13 | ///
14 | bool IsPatched();
15 |
16 | ///
17 | /// Write a serialized patch part into the specified path
18 | ///
19 | ///
20 | ///
21 | ///
22 | void WriteToPath(TargetPath path, JToken value, int depth);
23 |
24 | ///
25 | /// Serialize a part of a patch
26 | ///
27 | ///
28 | ///
29 | ///
30 | ///
31 | bool ReadFromPath(TargetPath path, ref JToken value, int depth);
32 |
33 | ///
34 | /// Reset all patchable properties to null
35 | ///
36 | void Clear();
37 |
38 | ///
39 | /// Assign a saved patch instance to public property
40 | ///
41 | /// The path whose parts should be restored
42 | /// Which path part should be restored on this object
43 | void Restore(TargetPath path, int depth);
44 |
45 | ///
46 | /// Assign all saved patches to public properties
47 | ///
48 | void RestoreAll();
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Patching/PatchProperty.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using System;
4 |
5 | namespace MixedRealityExtension.Patching
6 | {
7 | [AttributeUsage(AttributeTargets.Property)]
8 | internal class PatchProperty : Attribute
9 | {
10 | public PatchProperty()
11 | {
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Patching/Patchable.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using MixedRealityExtension.Animation;
4 | using Newtonsoft.Json.Linq;
5 | using System.Collections.Generic;
6 | using System.Linq;
7 | using System.Reflection;
8 |
9 | namespace MixedRealityExtension.Patching
10 | {
11 | ///
12 | /// Statically caches reflection info for PatchProperty-tagged properties.
13 | /// Note it was necessary to duplicate some code in the ScaledTransform due
14 | /// to a lack of multiple inheritance or mixins in C#.
15 | ///
16 | public abstract class Patchable : IPatchable
17 | {
18 | private static PropertyInfo[] _patchProperties = null;
19 | static Patchable()
20 | {
21 | List patchProperties = new List();
22 | PropertyInfo[] properties = typeof(T).GetProperties();
23 | for (int i = 0; i < properties.Length; ++i)
24 | {
25 | if (properties[i].GetCustomAttributes(false).Any(attr => attr is PatchProperty))
26 | {
27 | patchProperties.Add(properties[i]);
28 | }
29 | }
30 | _patchProperties = patchProperties.ToArray();
31 | }
32 |
33 | public PropertyInfo[] GetPatchProperties()
34 | {
35 | return _patchProperties;
36 | }
37 |
38 | ///
39 | public bool IsPatched()
40 | {
41 | foreach (PropertyInfo property in GetPatchProperties())
42 | {
43 | var val = property.GetValue(this);
44 | if (val is IPatchable childPatch)
45 | {
46 | return childPatch.IsPatched();
47 | }
48 | else if (val != null)
49 | {
50 | return true;
51 | }
52 | }
53 |
54 | return false;
55 | }
56 |
57 | ///
58 | public virtual void WriteToPath(TargetPath path, JToken value, int depth)
59 | {
60 |
61 | }
62 |
63 | ///
64 | public virtual bool ReadFromPath(TargetPath path, ref JToken value, int depth)
65 | {
66 | return false;
67 | }
68 |
69 | ///
70 | public virtual void Clear()
71 | {
72 |
73 | }
74 |
75 | ///
76 | public virtual void Restore(TargetPath path, int depth)
77 | {
78 |
79 | }
80 |
81 | ///
82 | public virtual void RestoreAll()
83 | {
84 |
85 | }
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Patching/Types/AnimationPatch.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using MixedRealityExtension.Animation;
4 | using MixedRealityExtension.Messaging.Payloads.Converters;
5 | using System;
6 | using System.Collections.Generic;
7 | using Newtonsoft.Json.Linq;
8 |
9 | namespace MixedRealityExtension.Patching.Types
10 | {
11 | ///
12 | /// A serialized animation definition
13 | ///
14 | public class AnimationPatch : Patchable
15 | {
16 | ///
17 | /// Generated unique ID of this animation
18 | ///
19 | public Guid Id;
20 |
21 | ///
22 | /// Non-unique name of this animation
23 | ///
24 | [PatchProperty]
25 | public string Name { get; set; }
26 |
27 | ///
28 | /// The server time (milliseconds since the UNIX epoch) when the animation was started
29 | ///
30 | [PatchProperty]
31 | public long? BasisTime { get; set; }
32 |
33 | ///
34 | /// The current playback time, based on basis time and speed
35 | ///
36 | [PatchProperty]
37 | public float? Time { get; set; }
38 |
39 | ///
40 | /// Playback speed multiplier
41 | ///
42 | [PatchProperty]
43 | public float? Speed { get; set; }
44 |
45 | ///
46 | /// When multiple animations play together, this is the relative strength of this instance
47 | ///
48 | [PatchProperty]
49 | public float? Weight { get; set; }
50 |
51 | ///
52 | /// What happens when the animation hits the last frame
53 | ///
54 | [PatchProperty]
55 | public MWAnimationWrapMode? WrapMode { get; set; }
56 |
57 | ///
58 | /// Convenience property for setting Weight and Basis/Time
59 | ///
60 | [PatchProperty]
61 | public bool? IsPlaying { get; set; }
62 |
63 | ///
64 | /// What runtime objects are being animated
65 | ///
66 | public Guid[] TargetIds { get; set; }
67 |
68 | ///
69 | /// The ID of the AnimationData bound to this animation
70 | ///
71 | public Guid? DataId { get; set; }
72 |
73 | ///
74 | /// The length in seconds of the animation
75 | ///
76 | public float? Duration { get; set; }
77 |
78 | public void Merge(AnimationPatch other)
79 | {
80 | if (other.Name != null) Name = other.Name;
81 | if (other.BasisTime.HasValue) BasisTime = other.BasisTime;
82 | if (other.Time.HasValue) Time = other.Time;
83 | if (other.Speed.HasValue) Speed = other.Speed;
84 | if (other.Weight.HasValue) Weight = other.Weight;
85 | if (other.WrapMode.HasValue) WrapMode = other.WrapMode;
86 | }
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Patching/Types/AppearancePatch.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using System;
4 | using MixedRealityExtension.Animation;
5 | using MixedRealityExtension.Messaging.Payloads.Converters;
6 | using Newtonsoft.Json;
7 | using Newtonsoft.Json.Linq;
8 |
9 | namespace MixedRealityExtension.Patching.Types
10 | {
11 | public class AppearancePatch : Patchable
12 | {
13 | [PatchProperty]
14 | [JsonConverter(typeof(UnsignedConverter))]
15 | public uint? Enabled { get; set; }
16 |
17 | [PatchProperty]
18 | public Guid? MaterialId { get; set; }
19 |
20 | [PatchProperty]
21 | public Guid? MeshId { get; set; }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Patching/Types/AttachmentPatch.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using MixedRealityExtension.Animation;
4 | using Newtonsoft.Json.Linq;
5 | using System;
6 | using System.Collections.Generic;
7 | using System.Linq;
8 | using System.Text;
9 | using System.Threading.Tasks;
10 |
11 | namespace MixedRealityExtension.Patching.Types
12 | {
13 | ///
14 | /// Attachment patch.
15 | ///
16 | public class AttachmentPatch : Patchable, IEquatable
17 | {
18 | [PatchProperty]
19 | public string AttachPoint { get; set; }
20 |
21 | [PatchProperty]
22 | public Guid? UserId { get; set; }
23 |
24 | public bool Equals(AttachmentPatch other)
25 | {
26 | return other != null && AttachPoint == other.AttachPoint && UserId == other.UserId;
27 | }
28 |
29 | public override bool Equals(object obj)
30 | {
31 | return Equals(obj as AttachmentPatch);
32 | }
33 |
34 | // This class is not suitable for use as a hash key or dictionary key.
35 | public override int GetHashCode()
36 | {
37 | return base.GetHashCode();
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Patching/Types/ColliderPatch.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using MixedRealityExtension.Animation;
4 | using MixedRealityExtension.Core;
5 | using MixedRealityExtension.Core.Collision;
6 | using Newtonsoft.Json.Linq;
7 | using System.Collections.Generic;
8 |
9 | namespace MixedRealityExtension.Patching.Types
10 | {
11 | public class ColliderPatch : Patchable
12 | {
13 | [PatchProperty]
14 | public bool? Enabled { get; set; }
15 |
16 | [PatchProperty]
17 | public bool? IsTrigger { get; set; }
18 |
19 | [PatchProperty]
20 | public float? Bounciness { get; set; }
21 |
22 | [PatchProperty]
23 | public float? StaticFriction { get; set; }
24 |
25 | [PatchProperty]
26 | public float? DynamicFriction { get; set; }
27 |
28 | [PatchProperty]
29 | public CollisionLayer? Layer { get; set; }
30 |
31 | [PatchProperty]
32 | public ColliderGeometry Geometry { get; set; }
33 |
34 | [PatchProperty]
35 | public ColliderEventType[] EventSubscriptions { get; set; }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Patching/Types/ColorPatch.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using MixedRealityExtension.Animation;
4 | using MixedRealityExtension.Core.Types;
5 | using Newtonsoft.Json.Linq;
6 | using System;
7 |
8 | namespace MixedRealityExtension.Patching.Types
9 | {
10 | public class ColorPatch : Patchable, IEquatable
11 | {
12 | [PatchProperty]
13 | public float? R { get; set; }
14 |
15 | [PatchProperty]
16 | public float? G { get; set; }
17 |
18 | [PatchProperty]
19 | public float? B { get; set; }
20 |
21 | [PatchProperty]
22 | public float? A { get; set; }
23 |
24 | public ColorPatch()
25 | { }
26 |
27 | internal ColorPatch(MWColor color)
28 | {
29 | R = color.R;
30 | G = color.G;
31 | B = color.B;
32 | A = color.A;
33 | }
34 |
35 | internal ColorPatch(UnityEngine.Color color)
36 | {
37 | R = color.r;
38 | G = color.g;
39 | B = color.b;
40 | A = color.a;
41 | }
42 |
43 | public bool Equals(ColorPatch other)
44 | {
45 | if (other == null)
46 | {
47 | return false;
48 | }
49 | else
50 | {
51 | return
52 | R.Equals(other.R) &&
53 | G.Equals(other.G) &&
54 | B.Equals(other.B) &&
55 | A.Equals(other.A);
56 | }
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Patching/Types/LightPatch.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using MixedRealityExtension.Animation;
4 | using MixedRealityExtension.Core.Interfaces;
5 | using MixedRealityExtension.Util;
6 | using Newtonsoft.Json.Linq;
7 |
8 | namespace MixedRealityExtension.Patching.Types
9 | {
10 | public class LightPatch : Patchable
11 | {
12 | [PatchProperty]
13 | public bool? Enabled { get; set; }
14 |
15 | [PatchProperty]
16 | public LightType? Type { get; set; }
17 |
18 | [PatchProperty]
19 | public ColorPatch Color { get; set; }
20 |
21 | [PatchProperty]
22 | public float? Range { get; set; }
23 |
24 | [PatchProperty]
25 | public float? Intensity { get; set; }
26 |
27 | [PatchProperty]
28 | public float? SpotAngle { get; set; }
29 |
30 | public LightPatch()
31 | { }
32 |
33 | internal LightPatch(UnityEngine.Light light)
34 | {
35 | Enabled = light.enabled;
36 | Type = UtilMethods.ConvertEnum(light.type);
37 | Color = new ColorPatch(light.color);
38 | Range = light.range;
39 | Intensity = light.intensity;
40 | SpotAngle = light.spotAngle;
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Patching/Types/LookAtPatch.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using MixedRealityExtension.Animation;
4 | using Newtonsoft.Json.Linq;
5 | using System;
6 | using System.Collections.Generic;
7 | using System.Linq;
8 | using System.Text;
9 | using System.Threading.Tasks;
10 |
11 | namespace MixedRealityExtension.Patching.Types
12 | {
13 | public class LookAtPatch : Patchable
14 | {
15 | [PatchProperty]
16 | public Guid? ActorId { get; set; }
17 |
18 | [PatchProperty]
19 | public LookAtMode? Mode { get; set; }
20 |
21 | [PatchProperty]
22 | public bool? Backward { get; set; }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Patching/Types/QuaternionPatch.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using MixedRealityExtension.Animation;
4 | using MixedRealityExtension.Core.Types;
5 | using Newtonsoft.Json.Linq;
6 | using System;
7 | using UnityEngine;
8 |
9 | namespace MixedRealityExtension.Patching.Types
10 | {
11 | public class QuaternionPatch : Patchable, IEquatable
12 | {
13 | // TODO: Make X, Y, Z, and W fields non-optional, since you can't just specify one and maintain a valid unit quaternion
14 | [PatchProperty]
15 | public float? X { get; set; }
16 |
17 | [PatchProperty]
18 | public float? Y { get; set; }
19 |
20 | [PatchProperty]
21 | public float? Z { get; set; }
22 |
23 | [PatchProperty]
24 | public float? W { get; set; }
25 |
26 | public QuaternionPatch()
27 | {
28 |
29 | }
30 |
31 | internal QuaternionPatch(MWQuaternion quaternion)
32 | {
33 | X = quaternion.X;
34 | Y = quaternion.Y;
35 | Z = quaternion.Z;
36 | W = quaternion.W;
37 | }
38 |
39 | internal QuaternionPatch(Quaternion quaternion)
40 | {
41 | X = quaternion.x;
42 | Y = quaternion.y;
43 | Z = quaternion.z;
44 | W = quaternion.w;
45 | }
46 |
47 | internal QuaternionPatch(QuaternionPatch other)
48 | {
49 | if (other != null)
50 | {
51 | X = other.X;
52 | Y = other.Y;
53 | Z = other.Z;
54 | W = other.W;
55 | }
56 | }
57 |
58 | //public QuaternionPatch ToQuaternion()
59 | //{
60 | // return new Quaternion()
61 | // {
62 | // w = (W != null) ? (float)W : 0.0f,
63 | // x = (X != null) ? (float)X : 0.0f,
64 | // y = (Y != null) ? (float)Y : 0.0f,
65 | // z = (Z != null) ? (float)Z : 0.0f,
66 | // };
67 | //}
68 |
69 | public bool Equals(QuaternionPatch other)
70 | {
71 | if (other == null)
72 | {
73 | return false;
74 | }
75 | else
76 | {
77 | return
78 | X.Equals(other.X) &&
79 | Y.Equals(other.Y) &&
80 | Z.Equals(other.Z) &&
81 | W.Equals(other.W);
82 | }
83 | }
84 |
85 | public override string ToString()
86 | {
87 | return string.Format("({0}, {1}, {2}, {3})", X, Y, Z, W);
88 | }
89 |
90 | public override void WriteToPath(TargetPath path, JToken value, int depth)
91 | {
92 | if (depth == path.PathParts.Length)
93 | {
94 | X = value.Value("x");
95 | Y = value.Value("y");
96 | Z = value.Value("z");
97 | W = value.Value("w");
98 | }
99 | // else
100 | // an unrecognized path, do nothing
101 | }
102 |
103 | public override bool ReadFromPath(TargetPath path, ref JToken value, int depth)
104 | {
105 | if (depth == path.PathParts.Length && X.HasValue && Y.HasValue && Z.HasValue && W.HasValue)
106 | {
107 | var oValue = (JObject)value;
108 | oValue.SetOrAdd("x", X.Value);
109 | oValue.SetOrAdd("y", Y.Value);
110 | oValue.SetOrAdd("z", Z.Value);
111 | oValue.SetOrAdd("w", W.Value);
112 | return true;
113 | }
114 | return false;
115 | }
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Patching/Types/TextPatch.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using MixedRealityExtension.Animation;
4 | using MixedRealityExtension.Core.Interfaces;
5 | using Newtonsoft.Json.Linq;
6 |
7 | namespace MixedRealityExtension.Patching.Types
8 | {
9 | public class TextPatch : Patchable
10 | {
11 | [PatchProperty]
12 | public bool? Enabled { get; set; }
13 |
14 | [PatchProperty]
15 | public string Contents { get; set; }
16 |
17 | [PatchProperty]
18 | public float? Height { get; set; }
19 |
20 | [PatchProperty]
21 | public float? PixelsPerLine { get; set; }
22 |
23 | [PatchProperty]
24 | public TextAnchorLocation? Anchor { get; set; }
25 |
26 | [PatchProperty]
27 | public TextJustify? Justify { get; set; }
28 |
29 | [PatchProperty]
30 | public FontFamily? Font { get; set; }
31 |
32 | [PatchProperty]
33 | public ColorPatch Color { get; set; }
34 |
35 | public TextPatch() { }
36 |
37 | internal TextPatch(IText text)
38 | {
39 | Enabled = text.Enabled;
40 | Contents = text.Contents;
41 | Height = text.Height;
42 | PixelsPerLine = text.PixelsPerLine;
43 | Anchor = text.Anchor;
44 | Justify = text.Justify;
45 | Font = text.Font;
46 | Color = new ColorPatch(text.Color);
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Patching/Types/UserPatch.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 |
4 | using MixedRealityExtension.Core;
5 | using MixedRealityExtension.Messaging.Payloads.Converters;
6 | using Newtonsoft.Json;
7 | using System;
8 | using System.Collections.Generic;
9 | using System.Linq;
10 |
11 | namespace MixedRealityExtension.Patching.Types
12 | {
13 | public class UserPatch : Patchable
14 | {
15 | public Guid Id { get; set; }
16 |
17 | [PatchProperty]
18 | public string Name { get; set; }
19 |
20 | [PatchProperty]
21 | [JsonConverter(typeof(UnsignedConverter))]
22 | public UInt32? Groups { get; set; }
23 |
24 | [PatchProperty]
25 | public Permissions[] GrantedPermissions { get; set; }
26 |
27 | public Dictionary Properties { get; set; }
28 |
29 | public UserPatch()
30 | {
31 | }
32 |
33 | internal UserPatch(Guid id)
34 | {
35 | Id = id;
36 | }
37 |
38 | internal UserPatch(User user)
39 | : this(user.Id)
40 | {
41 | Name = user.Name;
42 | Groups = user.Groups;
43 | // the server doesn't need to care about the execution permission, it's assumed if you're connected
44 | GrantedPermissions = user.App.GrantedPermissions.ToEnumerable().Where(p => p != Permissions.Execution).ToArray();
45 | Properties = user.HostAppUser.Properties;
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Patching/Types/Vector2Patch.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using MixedRealityExtension.Animation;
4 | using MixedRealityExtension.Core.Types;
5 | using Newtonsoft.Json.Linq;
6 | using System;
7 | using UnityEngine;
8 |
9 | namespace MixedRealityExtension.Patching.Types
10 | {
11 | public class Vector2Patch : Patchable, IEquatable
12 | {
13 | [PatchProperty]
14 | public float? X { get; set; }
15 |
16 | [PatchProperty]
17 | public float? Y { get; set; }
18 |
19 | public Vector2Patch()
20 | {
21 |
22 | }
23 |
24 | public Vector2Patch(MWVector2 vector)
25 | {
26 | X = vector.X;
27 | Y = vector.Y;
28 | }
29 |
30 | public Vector2Patch(Vector2 vector2)
31 | {
32 | X = vector2.x;
33 | Y = vector2.y;
34 | }
35 |
36 | public Vector2Patch(Vector2Patch other)
37 | {
38 | if (other != null)
39 | {
40 | X = other.X;
41 | Y = other.Y;
42 | }
43 | }
44 |
45 | public bool Equals(Vector2Patch other)
46 | {
47 | if (other == null)
48 | {
49 | return false;
50 | }
51 | else
52 | {
53 | return
54 | X.Equals(other.X) &&
55 | Y.Equals(other.Y);
56 | }
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/PluginInterfaces/Behaviors/IBehavior.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using MixedRealityExtension.Core.Interfaces;
4 |
5 | namespace MixedRealityExtension.PluginInterfaces.Behaviors
6 | {
7 | ///
8 | /// The base interface for a behavior.
9 | ///
10 | public interface IBehavior
11 | {
12 | ///
13 | /// The actor that the behavior is attached to.
14 | ///
15 | IActor Actor { get; set; }
16 |
17 | ///
18 | /// Called to cleanup the behavior, as it is being removed from the actor by the app.
19 | ///
20 | void CleanUp();
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/PluginInterfaces/Behaviors/IBehaviorFactory.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using MixedRealityExtension.Behaviors.Contexts;
4 | using MixedRealityExtension.Core.Interfaces;
5 |
6 | namespace MixedRealityExtension.PluginInterfaces.Behaviors
7 | {
8 | ///
9 | /// This interface serves as the interface to a behavior factory that need to be implemented by the platform utilizing MWI Apps.
10 | ///
11 | public interface IBehaviorFactory
12 | {
13 | ///
14 | /// Create the concrete behavior that implements the interface.
15 | ///
16 | /// The actor that the behavior will be attached to.
17 | /// /// The target behavior context to operate on.
18 | /// The instance of the behavior implementing the interface.
19 | ITargetBehavior GetOrCreateTargetBehavior(IActor actor, TargetBehaviorContext context);
20 |
21 | ///
22 | /// Create the concrete behavior that implements the interface.
23 | ///
24 | /// The actor that the behavior will be attached to.
25 | /// The button behavior context to operate on.
26 | /// The instance of the behavior implementing the interface.
27 | IButtonBehavior GetOrCreateButtonBehavior(IActor actor, ButtonBehaviorContext context);
28 |
29 | ///
30 | /// Create the concrete behavior that implements the interface.
31 | ///
32 | /// The actor that the behavior will be attached to.
33 | /// /// The pen behavior context to operate on.
34 | /// The instance of the behavior implementing the interface.
35 | IPenBehavior GetOrCreatePenBehavior(IActor actor, PenBehaviorContext context);
36 |
37 | // TODO @tombu - This will be added to allow for a more override model for high level behaviors.
38 | //BehaviorTypeT CreatePrimaryBehaviorOverride(PrimaryBehaviorType type, IActor actor);
39 | //BehaviorTypeT CreateBackgroundBehaviorOverride(PrimaryBehaviorType type, IActor actor);
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/PluginInterfaces/Behaviors/IButtonBehavior.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using MixedRealityExtension.Behaviors.Actions;
4 |
5 | namespace MixedRealityExtension.PluginInterfaces.Behaviors
6 | {
7 | ///
8 | /// The interface that represents the button behavior in the target platform for MWI Apps.
9 | ///
10 | public interface IButtonBehavior : ITargetBehavior
11 | {
12 |
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/PluginInterfaces/Behaviors/IPenBehavior.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using MixedRealityExtension.Behaviors.ActionData;
4 |
5 | namespace MixedRealityExtension.PluginInterfaces.Behaviors
6 | {
7 | ///
8 | /// Interface that represents a pen behavior in the MRE runtime.
9 | ///
10 | public interface IPenBehavior : IToolBehavior
11 | {
12 |
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/PluginInterfaces/Behaviors/ITargetBehavior.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 |
4 | using MixedRealityExtension.Behaviors.Contexts;
5 |
6 | namespace MixedRealityExtension.PluginInterfaces.Behaviors
7 | {
8 | ///
9 | /// The interface that represents the target behavior in the target platform for MWI Apps.
10 | ///
11 | public interface ITargetBehavior : IBehavior
12 | {
13 | ///
14 | /// Whether the target is grabbable or not.
15 | ///
16 | bool Grabbable { get; set; }
17 |
18 | ///
19 | /// Whether the target behavior grab is active.
20 | ///
21 | bool IsGrabbed { get; set; }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/PluginInterfaces/Behaviors/IToolBehavior.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using MixedRealityExtension.Behaviors.ActionData;
4 | using MixedRealityExtension.Behaviors.Actions;
5 |
6 | namespace MixedRealityExtension.PluginInterfaces.Behaviors
7 | {
8 | ///
9 | /// The interface that represents a tool behavior in the MRE runtime.
10 | ///
11 | public interface IToolBehavior : IBehavior
12 | {
13 |
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/PluginInterfaces/IDialogFactory.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 |
4 | using System;
5 | using MixedRealityExtension.App;
6 |
7 | namespace MixedRealityExtension.PluginInterfaces
8 | {
9 | public interface IDialogFactory
10 | {
11 | void ShowDialog(IMixedRealityExtensionApp app, string text, bool acceptInput, Action callback);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/PluginInterfaces/IGltfImporterFactory.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using System.IO;
4 | using GLTF.Schema;
5 | using MixedRealityExtension.Assets;
6 | using UnityGLTF;
7 | using UnityGLTF.Loader;
8 |
9 | namespace MixedRealityExtension.PluginInterfaces
10 | {
11 | ///
12 | /// Used to generate new GLTFSceneImporter instances. Primarily used for inserting custom subclasses of this type.
13 | ///
14 | public interface IGLTFImporterFactory
15 | {
16 | ///
17 | /// Returns a new glTF importer to the MRE system. Will typically be a subclass instance, and not a direct instance.
18 | ///
19 | ///
20 | ///
21 | ///
22 | /// A new importer instance.
23 | GLTFSceneImporter CreateImporter(
24 | string gltfFileName,
25 | IDataLoader dataLoader,
26 | AsyncCoroutineHelper asyncCoroutineHelper);
27 |
28 | ///
29 | /// Returns a new glTF importer to the MRE system. Will typically be a subclass instance, and not a direct instance.
30 | ///
31 | ///
32 | ///
33 | ///
34 | ///
35 | ///
36 | GLTFSceneImporter CreateImporter(
37 | GLTFRoot rootNode,
38 | IDataLoader dataLoader,
39 | AsyncCoroutineHelper asyncCoroutineHelper,
40 | Stream gltfStream = null);
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/PluginInterfaces/IHostAppUser.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 |
4 | using MixedRealityExtension.IPC;
5 | using System;
6 | using System.Collections.Generic;
7 | using UnityEngine;
8 |
9 | namespace MixedRealityExtension.PluginInterfaces
10 | {
11 | ///
12 | /// Interface for providing information about a user.
13 | ///
14 | public interface IHostAppUser
15 | {
16 | ///
17 | /// The unobfuscated id of the user for the host app. Handle with care.
18 | ///
19 | string HostUserId { get; }
20 |
21 | ///
22 | /// The user's display name. Null if user not found.
23 | ///
24 | string Name { get; }
25 |
26 | ///
27 | /// Generic user properties. Usually informational only.
28 | ///
29 | Dictionary Properties { get; }
30 |
31 | ///
32 | /// Gets the transform of the specified attach point.
33 | ///
34 | /// The name of the attach point to retrieve.
35 | /// The attach point transform, or null if not found.
36 | Transform GetAttachPoint(string attachPointName);
37 |
38 | ///
39 | /// Called before the user's avatar is destroyed.
40 | ///
41 | event MWEventHandler BeforeAvatarDestroyed;
42 |
43 | ///
44 | /// Called after the user's avatar is recreated.
45 | ///
46 | event MWEventHandler AfterAvatarCreated;
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/PluginInterfaces/ILayerApplicator.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 |
4 | using CollisionLayer = MixedRealityExtension.Core.CollisionLayer;
5 | using Collider = UnityEngine.Collider;
6 |
7 | namespace MixedRealityExtension.PluginInterfaces
8 | {
9 | ///
10 | /// Apply an MRE collider layers to Unity colliders.
11 | ///
12 | public interface ILayerApplicator
13 | {
14 | ///
15 | /// The Unity layer new actors should be created on.
16 | ///
17 | byte DefaultLayer { get; }
18 |
19 | ///
20 | /// Apply a layer to a collider.
21 | ///
22 | /// An MRE collision layer
23 | /// A Unity collider
24 | void ApplyLayerToCollider(CollisionLayer? layer, Collider collider);
25 |
26 | ///
27 | /// Get a collider's layer.
28 | ///
29 | /// The collider.
30 | /// The layer the given collider is on.
31 | CollisionLayer DetermineLayerOfCollider(Collider collider);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/PluginInterfaces/ILibraryResourceFactory.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using System;
4 | using System.Runtime.ExceptionServices;
5 | using System.Threading.Tasks;
6 | using UnityEngine;
7 |
8 | namespace MixedRealityExtension.PluginInterfaces
9 | {
10 | ///
11 | /// A factory class that creates actors from host library resources
12 | ///
13 | public interface ILibraryResourceFactory
14 | {
15 | ///
16 | /// Instantiate a host-defined actor by resource ID. Will throw an ArgumentException if the resourceId is not recognized.
17 | ///
18 | /// A string that uniquely identifies a library resource to the host app
19 | /// The Unity GameObject to attach the library object to
20 | /// An async task that will resolve with the spawned GameObject
21 | Task CreateFromLibrary(string resourceId, GameObject parent);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/PluginInterfaces/IMRELogger.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | namespace MixedRealityExtension.PluginInterfaces
4 | {
5 | ///
6 | /// Interface that represents a logger for the MRE SDK.
7 | ///
8 | public interface IMRELogger
9 | {
10 | ///
11 | /// Log a debug message.
12 | ///
13 | /// The debug message.
14 | void LogDebug(string message);
15 |
16 | ///
17 | /// Log a warning.
18 | ///
19 | /// The warning message.
20 | void LogWarning(string message);
21 |
22 | ///
23 | /// Log an error.
24 | ///
25 | /// The error message.
26 | void LogError(string message);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/PluginInterfaces/IMaterialPatcher.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using MixedRealityExtension.App;
4 | using Texture = UnityEngine.Texture;
5 | using Material = UnityEngine.Material;
6 | using MWMaterial = MixedRealityExtension.Assets.Material;
7 |
8 | namespace MixedRealityExtension.PluginInterfaces
9 | {
10 | ///
11 | /// Responsible for translating between the host's material properties and the API properties
12 | ///
13 | public interface IMaterialPatcher
14 | {
15 | ///
16 | /// Apply the patch from the app to the material
17 | ///
18 | /// The app context of the material
19 | /// An instance of the default MRE material provided on load
20 | /// The update from the app. Unmodified properties will be null.
21 | void ApplyMaterialPatch(IMixedRealityExtensionApp app, Material material, MWMaterial patch);
22 |
23 | ///
24 | /// Generate an API patch from the Unity material's current state
25 | ///
26 | /// The app context of the material
27 | /// An instance of the default MRE material provided on load
28 | /// A full definition of the given material
29 | MWMaterial GeneratePatch(IMixedRealityExtensionApp app, Material material);
30 |
31 | ///
32 | /// Reports whether a particular Unity texture is in use by the given material
33 | ///
34 | /// The app context of the material
35 | /// The material to test
36 | /// The texture to test
37 | ///
38 | bool UsesTexture(IMixedRealityExtensionApp app, Material material, Texture texture);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/PluginInterfaces/IPermissionManager.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using MixedRealityExtension.Core;
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Threading;
7 | using System.Threading.Tasks;
8 |
9 | namespace MixedRealityExtension.PluginInterfaces
10 | {
11 | ///
12 | /// Permission management interface for MRE host apps. Supports both IEnumerable and bitfield-based permission lists.
13 | ///
14 | public interface IPermissionManager
15 | {
16 | ///
17 | /// Request permissions from the user, and return a Task that resolves with those permissions the user has granted.
18 | ///
19 | /// The URI of the MRE requesting permission.
20 | /// An enumerable of the permissions required for the MRE to run.
21 | /// An enumerable of the permissions the MRE can use, but are not required.
22 | /// Same as permissionsNeeded, but in a bitfield.
23 | /// Same as permissionsWanted, but in a bitfield.
24 | /// The full app manifest, which includes enumerations of the required and optional permissions.
25 | /// Used to cancel the request if it doesn't matter anymore.
26 | ///
27 | Task PromptForPermissions(
28 | Uri appLocation,
29 | IEnumerable permissionsNeeded,
30 | IEnumerable permissionsWanted,
31 | Permissions permissionFlagsNeeded,
32 | Permissions permissionFlagsWanted,
33 | AppManifest appManifest,
34 | CancellationToken cancellationToken);
35 |
36 | ///
37 | /// Get the currently granted permissions for the MRE origin without requesting new ones.
38 | ///
39 | /// The URI of the MRE that you want to know about.
40 | /// A bitfield of the currently granted permissions for the given MRE.
41 | Permissions CurrentPermissions(Uri appLocation);
42 |
43 | ///
44 | /// Event that is fired when any permissions are edited. Receives as arguments the app location URI, the old
45 | /// permission set, and the new permission set.
46 | ///
47 | event Action OnPermissionDecisionsChanged;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/PluginInterfaces/IPrimitiveFactory.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using MixedRealityExtension.Core.Interfaces;
4 | using MixedRealityExtension.Core.Types;
5 | using System;
6 | using UnityEngine;
7 |
8 | namespace MixedRealityExtension.PluginInterfaces
9 | {
10 | ///
11 | /// Classes that implement this interface can be used to generate engine primitives
12 | ///
13 | public interface IPrimitiveFactory
14 | {
15 | ///
16 | /// Create a new Unity mesh with a known shape
17 | ///
18 | /// The shape and size of the primitive to create
19 | /// The mesh of the newly created primitive
20 | Mesh CreatePrimitive(PrimitiveDefinition definition);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/PluginInterfaces/ITextFactory.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using MixedRealityExtension.Core.Interfaces;
4 |
5 | namespace MixedRealityExtension.PluginInterfaces
6 | {
7 | ///
8 | /// Classes that implement this interface can be used to generate engine instances of text components
9 | ///
10 | public interface ITextFactory
11 | {
12 | ///
13 | /// Generate engine text on the given actor with the given properties
14 | ///
15 | /// The actor acting as anchor
16 | /// An engine-specific reference to the created text
17 | IText CreateText(IActor actor);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/PluginInterfaces/IVideoPlayer.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 | using UnityEngine;
9 |
10 | using MixedRealityExtension.Core;
11 | namespace MixedRealityExtension.PluginInterfaces
12 | {
13 | public interface IVideoPlayer
14 | {
15 | void Play(VideoStreamDescription description, MediaStateOptions options);
16 | void Destroy();
17 | void ApplyMediaStateOptions(MediaStateOptions options);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/PluginInterfaces/IVideoPlayerFactory.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | using UnityEngine;
10 | using MixedRealityExtension.Core;
11 | using MixedRealityExtension.Core.Interfaces;
12 | using MixedRealityExtension.Assets;
13 | using MixedRealityExtension.Util.Unity;
14 |
15 | namespace MixedRealityExtension.PluginInterfaces
16 | {
17 |
18 | public struct FetchResult
19 | {
20 | public VideoStreamDescription Asset;
21 | public string FailureMessage;
22 | }
23 |
24 | ///
25 | /// A factory class that instantiates a video player
26 | ///
27 | public interface IVideoPlayerFactory
28 | {
29 | IVideoPlayer CreateVideoPlayer(IActor parent);
30 | FetchResult PreloadVideoAsset(string uri);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/ProceduralToolkit/Directions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace MixedRealityExtension.ProceduralToolkit
4 | {
5 | ///
6 | /// Specifies directions along thee axes
7 | ///
8 | [Flags]
9 | public enum Directions
10 | {
11 | None = 0,
12 | Left = 1,
13 | Right = 2,
14 | Down = 4,
15 | Up = 8,
16 | Back = 16,
17 | Forward = 32,
18 | XAxis = Left | Right,
19 | YAxis = Down | Up,
20 | ZAxis = Back | Forward,
21 | All = Left | Right | Down | Up | Back | Forward
22 | }
23 |
24 | public static class DirectionsExtensions
25 | {
26 | public static bool HasFlag(this Directions directions, Directions flag)
27 | {
28 | return (directions & flag) == flag;
29 | }
30 |
31 | public static Directions AddFlag(this Directions directions, Directions flag)
32 | {
33 | return directions | flag;
34 | }
35 |
36 | public static Directions RemoveFlag(this Directions directions, Directions flag)
37 | {
38 | return directions & ~flag;
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/ProceduralToolkit/Geometry/IntersectionType.cs:
--------------------------------------------------------------------------------
1 | namespace MixedRealityExtension.ProceduralToolkit
2 | {
3 | public enum IntersectionType : byte
4 | {
5 | None = 0,
6 | Point,
7 | TwoPoints,
8 | Line,
9 | Ray,
10 | Segment,
11 | Circle,
12 | Sphere,
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/ProceduralToolkit/Geometry/Intersections/IntersectionCircleCircle.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 |
3 | namespace MixedRealityExtension.ProceduralToolkit
4 | {
5 | public struct IntersectionCircleCircle
6 | {
7 | public IntersectionType type;
8 | public Vector2 pointA;
9 | public Vector2 pointB;
10 |
11 | public static IntersectionCircleCircle None()
12 | {
13 | return new IntersectionCircleCircle {type = IntersectionType.None};
14 | }
15 |
16 | public static IntersectionCircleCircle Point(Vector2 point)
17 | {
18 | return new IntersectionCircleCircle
19 | {
20 | type = IntersectionType.Point,
21 | pointA = point,
22 | };
23 | }
24 |
25 | public static IntersectionCircleCircle TwoPoints(Vector2 pointA, Vector2 pointB)
26 | {
27 | return new IntersectionCircleCircle
28 | {
29 | type = IntersectionType.TwoPoints,
30 | pointA = pointA,
31 | pointB = pointB,
32 | };
33 | }
34 |
35 | public static IntersectionCircleCircle Circle()
36 | {
37 | return new IntersectionCircleCircle {type = IntersectionType.Circle};
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/ProceduralToolkit/Geometry/Intersections/IntersectionLineCircle.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 |
3 | namespace MixedRealityExtension.ProceduralToolkit
4 | {
5 | public struct IntersectionLineCircle
6 | {
7 | public IntersectionType type;
8 | public Vector2 pointA;
9 | public Vector2 pointB;
10 |
11 | public static IntersectionLineCircle None()
12 | {
13 | return new IntersectionLineCircle {type = IntersectionType.None};
14 | }
15 |
16 | public static IntersectionLineCircle Point(Vector2 point)
17 | {
18 | return new IntersectionLineCircle
19 | {
20 | type = IntersectionType.Point,
21 | pointA = point,
22 | };
23 | }
24 |
25 | public static IntersectionLineCircle TwoPoints(Vector2 pointA, Vector2 pointB)
26 | {
27 | return new IntersectionLineCircle
28 | {
29 | type = IntersectionType.TwoPoints,
30 | pointA = pointA,
31 | pointB = pointB,
32 | };
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/ProceduralToolkit/Geometry/Intersections/IntersectionLineLine2.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 |
3 | namespace MixedRealityExtension.ProceduralToolkit
4 | {
5 | public struct IntersectionLineLine2
6 | {
7 | public IntersectionType type;
8 | public Vector2 point;
9 |
10 | public static IntersectionLineLine2 None()
11 | {
12 | return new IntersectionLineLine2 {type = IntersectionType.None};
13 | }
14 |
15 | public static IntersectionLineLine2 Point(Vector2 point)
16 | {
17 | return new IntersectionLineLine2
18 | {
19 | type = IntersectionType.Point,
20 | point = point,
21 | };
22 | }
23 |
24 | public static IntersectionLineLine2 Line(Vector2 point)
25 | {
26 | return new IntersectionLineLine2
27 | {
28 | type = IntersectionType.Line,
29 | point = point,
30 | };
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/ProceduralToolkit/Geometry/Intersections/IntersectionLineRay2.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 |
3 | namespace MixedRealityExtension.ProceduralToolkit
4 | {
5 | public struct IntersectionLineRay2
6 | {
7 | public IntersectionType type;
8 | public Vector2 point;
9 |
10 | public static IntersectionLineRay2 None()
11 | {
12 | return new IntersectionLineRay2 {type = IntersectionType.None};
13 | }
14 |
15 | public static IntersectionLineRay2 Point(Vector2 point)
16 | {
17 | return new IntersectionLineRay2
18 | {
19 | type = IntersectionType.Point,
20 | point = point,
21 | };
22 | }
23 |
24 | public static IntersectionLineRay2 Ray(Vector2 point)
25 | {
26 | return new IntersectionLineRay2
27 | {
28 | type = IntersectionType.Ray,
29 | point = point,
30 | };
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/ProceduralToolkit/Geometry/Intersections/IntersectionLineSegment2.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 |
3 | namespace MixedRealityExtension.ProceduralToolkit
4 | {
5 | public struct IntersectionLineSegment2
6 | {
7 | public IntersectionType type;
8 | public Vector2 pointA;
9 | public Vector2 pointB;
10 |
11 | public static IntersectionLineSegment2 None()
12 | {
13 | return new IntersectionLineSegment2 {type = IntersectionType.None};
14 | }
15 |
16 | public static IntersectionLineSegment2 Point(Vector2 pointA)
17 | {
18 | return new IntersectionLineSegment2
19 | {
20 | type = IntersectionType.Point,
21 | pointA = pointA,
22 | };
23 | }
24 |
25 | public static IntersectionLineSegment2 Segment(Vector2 pointA, Vector2 pointB)
26 | {
27 | return new IntersectionLineSegment2
28 | {
29 | type = IntersectionType.Segment,
30 | pointA = pointA,
31 | pointB = pointB,
32 | };
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/ProceduralToolkit/Geometry/Intersections/IntersectionLineSphere.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 |
3 | namespace MixedRealityExtension.ProceduralToolkit
4 | {
5 | public struct IntersectionLineSphere
6 | {
7 | public IntersectionType type;
8 | public Vector3 pointA;
9 | public Vector3 pointB;
10 |
11 | public static IntersectionLineSphere None()
12 | {
13 | return new IntersectionLineSphere {type = IntersectionType.None};
14 | }
15 |
16 | public static IntersectionLineSphere Point(Vector3 point)
17 | {
18 | return new IntersectionLineSphere
19 | {
20 | type = IntersectionType.Point,
21 | pointA = point,
22 | };
23 | }
24 |
25 | public static IntersectionLineSphere TwoPoints(Vector3 pointA, Vector3 pointB)
26 | {
27 | return new IntersectionLineSphere
28 | {
29 | type = IntersectionType.TwoPoints,
30 | pointA = pointA,
31 | pointB = pointB,
32 | };
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/ProceduralToolkit/Geometry/Intersections/IntersectionRayCircle.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 |
3 | namespace MixedRealityExtension.ProceduralToolkit
4 | {
5 | public struct IntersectionRayCircle
6 | {
7 | public IntersectionType type;
8 | public Vector2 pointA;
9 | public Vector2 pointB;
10 |
11 | public static IntersectionRayCircle None()
12 | {
13 | return new IntersectionRayCircle {type = IntersectionType.None};
14 | }
15 |
16 | public static IntersectionRayCircle Point(Vector2 point)
17 | {
18 | return new IntersectionRayCircle
19 | {
20 | type = IntersectionType.Point,
21 | pointA = point,
22 | };
23 | }
24 |
25 | public static IntersectionRayCircle TwoPoints(Vector2 pointA, Vector2 pointB)
26 | {
27 | return new IntersectionRayCircle
28 | {
29 | type = IntersectionType.TwoPoints,
30 | pointA = pointA,
31 | pointB = pointB,
32 | };
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/ProceduralToolkit/Geometry/Intersections/IntersectionRayRay2.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 |
3 | namespace MixedRealityExtension.ProceduralToolkit
4 | {
5 | public struct IntersectionRayRay2
6 | {
7 | public IntersectionType type;
8 | public Vector2 pointA;
9 | public Vector2 pointB;
10 |
11 | public static IntersectionRayRay2 None()
12 | {
13 | return new IntersectionRayRay2 {type = IntersectionType.None};
14 | }
15 |
16 | public static IntersectionRayRay2 Point(Vector2 point)
17 | {
18 | return new IntersectionRayRay2
19 | {
20 | type = IntersectionType.Point,
21 | pointA = point,
22 | };
23 | }
24 |
25 | public static IntersectionRayRay2 Ray(Vector2 origin, Vector2 direction)
26 | {
27 | return new IntersectionRayRay2
28 | {
29 | type = IntersectionType.Ray,
30 | pointA = origin,
31 | pointB = direction,
32 | };
33 | }
34 |
35 | public static IntersectionRayRay2 Segment(Vector2 pointA, Vector2 pointB)
36 | {
37 | return new IntersectionRayRay2
38 | {
39 | type = IntersectionType.Segment,
40 | pointA = pointA,
41 | pointB = pointB,
42 | };
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/ProceduralToolkit/Geometry/Intersections/IntersectionRaySegment2.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 |
3 | namespace MixedRealityExtension.ProceduralToolkit
4 | {
5 | public struct IntersectionRaySegment2
6 | {
7 | public IntersectionType type;
8 | public Vector2 pointA;
9 | public Vector2 pointB;
10 |
11 | public static IntersectionRaySegment2 None()
12 | {
13 | return new IntersectionRaySegment2 {type = IntersectionType.None};
14 | }
15 |
16 | public static IntersectionRaySegment2 Point(Vector2 pointA)
17 | {
18 | return new IntersectionRaySegment2
19 | {
20 | type = IntersectionType.Point,
21 | pointA = pointA,
22 | };
23 | }
24 |
25 | public static IntersectionRaySegment2 Segment(Vector2 pointA, Vector2 pointB)
26 | {
27 | return new IntersectionRaySegment2
28 | {
29 | type = IntersectionType.Segment,
30 | pointA = pointA,
31 | pointB = pointB,
32 | };
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/ProceduralToolkit/Geometry/Intersections/IntersectionRaySphere.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 |
3 | namespace MixedRealityExtension.ProceduralToolkit
4 | {
5 | public struct IntersectionRaySphere
6 | {
7 | public IntersectionType type;
8 | public Vector3 pointA;
9 | public Vector3 pointB;
10 |
11 | public static IntersectionRaySphere None()
12 | {
13 | return new IntersectionRaySphere {type = IntersectionType.None};
14 | }
15 |
16 | public static IntersectionRaySphere Point(Vector3 point)
17 | {
18 | return new IntersectionRaySphere
19 | {
20 | type = IntersectionType.Point,
21 | pointA = point,
22 | };
23 | }
24 |
25 | public static IntersectionRaySphere TwoPoints(Vector3 pointA, Vector3 pointB)
26 | {
27 | return new IntersectionRaySphere
28 | {
29 | type = IntersectionType.TwoPoints,
30 | pointA = pointA,
31 | pointB = pointB,
32 | };
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/ProceduralToolkit/Geometry/Intersections/IntersectionSegmentCircle.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 |
3 | namespace MixedRealityExtension.ProceduralToolkit
4 | {
5 | public struct IntersectionSegmentCircle
6 | {
7 | public IntersectionType type;
8 | public Vector2 pointA;
9 | public Vector2 pointB;
10 |
11 | public static IntersectionSegmentCircle None()
12 | {
13 | return new IntersectionSegmentCircle {type = IntersectionType.None};
14 | }
15 |
16 | public static IntersectionSegmentCircle Point(Vector2 point)
17 | {
18 | return new IntersectionSegmentCircle
19 | {
20 | type = IntersectionType.Point,
21 | pointA = point,
22 | };
23 | }
24 |
25 | public static IntersectionSegmentCircle TwoPoints(Vector2 pointA, Vector2 pointB)
26 | {
27 | return new IntersectionSegmentCircle
28 | {
29 | type = IntersectionType.TwoPoints,
30 | pointA = pointA,
31 | pointB = pointB,
32 | };
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/ProceduralToolkit/Geometry/Intersections/IntersectionSegmentSegment2.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 |
3 | namespace MixedRealityExtension.ProceduralToolkit
4 | {
5 | public struct IntersectionSegmentSegment2
6 | {
7 | public IntersectionType type;
8 | public Vector2 pointA;
9 | public Vector2 pointB;
10 |
11 | public static IntersectionSegmentSegment2 None()
12 | {
13 | return new IntersectionSegmentSegment2 {type = IntersectionType.None};
14 | }
15 |
16 | public static IntersectionSegmentSegment2 Point(Vector2 point)
17 | {
18 | return new IntersectionSegmentSegment2
19 | {
20 | type = IntersectionType.Point,
21 | pointA = point,
22 | };
23 | }
24 |
25 | public static IntersectionSegmentSegment2 Segment(Vector2 pointA, Vector2 pointB)
26 | {
27 | return new IntersectionSegmentSegment2
28 | {
29 | type = IntersectionType.Segment,
30 | pointA = pointA,
31 | pointB = pointB,
32 | };
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/ProceduralToolkit/Geometry/Intersections/IntersectionSegmentSphere.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 |
3 | namespace MixedRealityExtension.ProceduralToolkit
4 | {
5 | public struct IntersectionSegmentSphere
6 | {
7 | public IntersectionType type;
8 | public Vector3 pointA;
9 | public Vector3 pointB;
10 |
11 | public static IntersectionSegmentSphere None()
12 | {
13 | return new IntersectionSegmentSphere {type = IntersectionType.None};
14 | }
15 |
16 | public static IntersectionSegmentSphere Point(Vector3 point)
17 | {
18 | return new IntersectionSegmentSphere
19 | {
20 | type = IntersectionType.Point,
21 | pointA = point,
22 | };
23 | }
24 |
25 | public static IntersectionSegmentSphere TwoPoints(Vector3 pointA, Vector3 pointB)
26 | {
27 | return new IntersectionSegmentSphere
28 | {
29 | type = IntersectionType.TwoPoints,
30 | pointA = pointA,
31 | pointB = pointB,
32 | };
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/ProceduralToolkit/Geometry/Intersections/IntersectionSphereSphere.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 |
3 | namespace MixedRealityExtension.ProceduralToolkit
4 | {
5 | public struct IntersectionSphereSphere
6 | {
7 | public IntersectionType type;
8 | public Vector3 point;
9 | public Vector3 normal;
10 | public float radius;
11 |
12 | public static IntersectionSphereSphere None()
13 | {
14 | return new IntersectionSphereSphere {type = IntersectionType.None};
15 | }
16 |
17 | public static IntersectionSphereSphere Point(Vector3 point)
18 | {
19 | return new IntersectionSphereSphere
20 | {
21 | type = IntersectionType.Point,
22 | point = point,
23 | };
24 | }
25 |
26 | public static IntersectionSphereSphere Circle(Vector3 center, Vector3 normal, float radius)
27 | {
28 | return new IntersectionSphereSphere
29 | {
30 | type = IntersectionType.Circle,
31 | point = center,
32 | normal = normal,
33 | radius = radius,
34 | };
35 | }
36 |
37 | public static IntersectionSphereSphere Sphere(Vector3 center, float radius)
38 | {
39 | return new IntersectionSphereSphere
40 | {
41 | type = IntersectionType.Sphere,
42 | point = center,
43 | radius = radius,
44 | };
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/ProceduralToolkit/LICENSE.txt:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) Daniil Basmanov
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/ProceduralToolkit/RendererProperties.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using UnityEngine;
3 | using UnityEngine.Rendering;
4 |
5 | namespace MixedRealityExtension.ProceduralToolkit
6 | {
7 | ///
8 | /// Serializable Renderer properties
9 | ///
10 | [Serializable]
11 | public class RendererProperties
12 | {
13 | public LightProbeUsage lightProbeUsage = LightProbeUsage.BlendProbes;
14 | public GameObject lightProbeProxyVolumeOverride = null;
15 | public ReflectionProbeUsage reflectionProbeUsage = ReflectionProbeUsage.BlendProbes;
16 | public Transform probeAnchor = null;
17 | public ShadowCastingMode shadowCastingMode = ShadowCastingMode.On;
18 | public bool receiveShadows = true;
19 | public MotionVectorGenerationMode motionVectorGenerationMode = MotionVectorGenerationMode.Object;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/mixed-reality-extension-unity/4afe6af76284ec15fcb01fd6fbd7616ad2a7e442/MREUnityRuntimeLib/Properties/AssemblyInfo.cs
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/RPC/RPCChannelInterface.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using System;
4 | using System.Collections.Generic;
5 | using MixedRealityExtension.Messaging.Payloads;
6 |
7 | namespace MixedRealityExtension.RPC
8 | {
9 | public sealed class RPCChannelInterface
10 | {
11 | private readonly Dictionary _channelHandlers = new Dictionary();
12 | private RPCInterface _globalHandler;
13 |
14 | public void SetChannelHandler(string channelName, RPCInterface handler)
15 | {
16 | if (!string.IsNullOrEmpty(channelName))
17 | {
18 | if (handler != null)
19 | {
20 | _channelHandlers.Add(channelName, handler);
21 | }
22 | else
23 | {
24 | _channelHandlers.Remove(channelName);
25 | }
26 | }
27 | else
28 | {
29 | _globalHandler = handler;
30 | }
31 | }
32 |
33 | internal void ReceiveRPC(AppToEngineRPC payload)
34 | {
35 | RPCInterface handler;
36 | if (!string.IsNullOrEmpty(payload.ChannelName))
37 | {
38 | _channelHandlers.TryGetValue(payload.ChannelName, out handler);
39 | }
40 | else
41 | {
42 | handler = _globalHandler;
43 | }
44 |
45 | handler?.ReceiveRPC(payload);
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/MREUnityRuntimeLib/RPC/RPCInterface.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using MixedRealityExtension.App;
7 | using MixedRealityExtension.Messaging.Payloads;
8 |
9 | namespace MixedRealityExtension.RPC
10 | {
11 | ///
12 | /// Class that represents the remote procedure call interface for the MRE interop library.
13 | ///
14 | public sealed class RPCInterface
15 | {
16 | private readonly IMixedRealityExtensionApp _app;
17 | private MixedRealityExtensionApp app => (MixedRealityExtensionApp)_app;
18 | private Dictionary _handlers = new Dictionary();
19 |
20 | public RPCInterface(IMixedRealityExtensionApp app) => _app = app;
21 |
22 | ///
23 | /// Registers and RPC handler for the specific procedure name
24 | ///
25 | /// The name of the remote procedure.
26 | /// The handler to be called when an RPC call is received for the given procedure name.
27 | public void OnReceive(string procName, RPCHandlerBase handler)
28 | {
29 | _handlers[procName] = handler;
30 | }
31 |
32 | internal void ReceiveRPC(AppToEngineRPC payload)
33 | {
34 | if (_handlers.ContainsKey(payload.ProcName))
35 | {
36 | // Filter the message by userId, if present.
37 | // Message is also filtered on the server, so
38 | // this is just extra protection.
39 | if (!string.IsNullOrEmpty(payload.UserId))
40 | {
41 | Guid userId = new Guid(payload.UserId);
42 | if (app.FindUser(userId) == null)
43 | {
44 | return;
45 | }
46 | }
47 | _handlers[payload.ProcName].Execute(payload.Args.Children().ToArray());
48 | }
49 | }
50 |
51 | ///
52 | /// Sends an RPC message to the app with the given name and arguments.
53 | ///
54 | /// The name of the remote procedure call.
55 | /// The arguments for the remote procedure call.
56 | public void SendRPC(string procName, params object[] args)
57 | {
58 | app.Protocol.Send(new EngineToAppRPC()
59 | {
60 | ProcName = procName,
61 | Args = (new List