public override void DrawInspectorGUI(object target)
        {
            IMixedRealitySpatialAwarenessSystem spatial            = (IMixedRealitySpatialAwarenessSystem)target;
            IMixedRealityDataProviderAccess     dataProviderAccess = (IMixedRealityDataProviderAccess)spatial;

            EditorGUILayout.LabelField("Observers", EditorStyles.boldLabel);
            int observerIndex = 0;

            var dataProviders = dataProviderAccess?.GetDataProviders();

            if (dataProviders != null)
            {
                foreach (IMixedRealitySpatialAwarenessObserver observer in dataProviders)
                {
                    GUI.color = observer.IsRunning ? enabledColor : disabledColor;

                    using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox))
                    {
                        GUI.color = GetObserverColor(observerIndex);
                        GUILayout.Button(observer.Name);
                        GUI.color = observer.IsRunning ? enabledColor : disabledColor;

                        EditorGUILayout.Toggle("Running", observer.IsRunning);
                        EditorGUILayout.LabelField("Source", observer.SourceName);
                        EditorGUILayout.Toggle("Is Stationary", observer.IsStationaryObserver);
                        EditorGUILayout.FloatField("Update Interval", observer.UpdateInterval);

                        EditorGUILayout.Space();
                        EditorGUILayout.LabelField("Volume Properties", EditorStyles.boldLabel);
                        EditorGUILayout.EnumPopup("Volume Type", observer.ObserverVolumeType);
                        EditorGUILayout.Vector3Field("Origin", observer.ObserverOrigin);
                        EditorGUILayout.Vector3Field("Rotation", observer.ObserverRotation.eulerAngles);
                        EditorGUILayout.Vector3Field("Extents", observer.ObservationExtents);
                    }
                    observerIndex++;
                }
            }

            GUI.color = enabledColor;

            if (!Application.isPlaying)
            {
                EditorGUILayout.HelpBox("Observers will be populated once you enter play mode.", MessageType.Info);
            }
            else if (observerIndex == 0)
            {
                EditorGUILayout.LabelField("(None found)", EditorStyles.miniLabel);
            }

            EditorGUILayout.Space();

            EditorGUILayout.LabelField("Editor Options", EditorStyles.boldLabel);
            ShowObserverBoundary = SessionState.GetBool(ShowObserverBoundaryKey, false);
            ShowObserverBoundary = EditorGUILayout.Toggle("Show Observer Boundaries", ShowObserverBoundary);
            SessionState.SetBool(ShowObserverBoundaryKey, ShowObserverBoundary);

            ShowObserverOrigin = SessionState.GetBool(ShowObserverOriginKey, false);
            ShowObserverOrigin = EditorGUILayout.Toggle("Show Observer Origins", ShowObserverOrigin);
            SessionState.SetBool(ShowObserverOriginKey, ShowObserverOrigin);
        }
        public override void DrawGizmos(object target)
        {
            if (!(ShowObserverBoundary || ShowObserverOrigin))
            {
                return;
            }

            IMixedRealitySpatialAwarenessSystem spatial            = (IMixedRealitySpatialAwarenessSystem)target;
            IMixedRealityDataProviderAccess     dataProviderAccess = (IMixedRealityDataProviderAccess)spatial;

            var dataProviders = dataProviderAccess?.GetDataProviders();

            if (dataProviders != null)
            {
                int observerIndex = 0;

                foreach (IMixedRealitySpatialAwarenessObserver observer in dataProviders)
                {
                    Gizmos.color = GetObserverColor(observerIndex);

                    if (ShowObserverBoundary)
                    {
                        switch (observer.ObserverVolumeType)
                        {
                        case VolumeType.None:
                            break;

                        case VolumeType.AxisAlignedCube:
                            Gizmos.DrawWireCube(observer.ObserverOrigin, observer.ObservationExtents);
                            break;

                        case VolumeType.Sphere:
                            Gizmos.DrawWireSphere(observer.ObserverOrigin, observer.ObservationExtents.x);
                            break;

                        case VolumeType.UserAlignedCube:
                            Gizmos.DrawWireCube(observer.ObserverOrigin, observer.ObservationExtents);
                            break;
                        }
                    }

                    Gizmos.matrix = Matrix4x4.identity;

                    if (ShowObserverOrigin)
                    {
                        Gizmos.DrawSphere(observer.ObserverOrigin, 0.1f);
                    }

                    observerIndex++;
                }
            }
        }
Пример #3
0
        private void Start()
        {
            // Get Core Spatial Awareness Services
            m_spatialAwarenessService = CoreServices.SpatialAwarenessSystem;
            if (m_spatialAwarenessService != null)
            {
                IMixedRealityDataProviderAccess dataProviderAccess = m_spatialAwarenessService as IMixedRealityDataProviderAccess;
                m_spatialAwarenessMeshObserver = dataProviderAccess.GetDataProvider <IMixedRealitySpatialAwarenessMeshObserver>();

                // Try to get "Spatial Awareness System" object (stores meshes)
                AcquireSpatailAwarenessObject();
            }
        }
Пример #4
0
        private IMixedRealitySpatialAwarenessMeshObserver TryToGetObserver()
        {
            IMixedRealitySpatialAwarenessMeshObserver retval = null;

            if (MixedRealityServiceRegistry.TryGetService <IMixedRealitySpatialAwarenessSystem>(out var service))
            {
                IMixedRealityDataProviderAccess dataProviderAccess = service as IMixedRealityDataProviderAccess;

                retval =
                    dataProviderAccess.GetDataProvider <IMixedRealitySpatialAwarenessMeshObserver>();
            }

            return(retval);
        }
Пример #5
0
        void Start()
        {
            handJointService = CoreServices.GetInputSystemDataProvider <IMixedRealityHandJointService>();
            if (handJointService == null)
            {
                Debug.LogError("Can't get IMixedRealityHandJointService.");
                return;
            }

            dataProviderAccess = CoreServices.InputSystem as IMixedRealityDataProviderAccess;
            if (dataProviderAccess == null)
            {
                Debug.LogError("Can't get IMixedRealityDataProviderAccess.");
                return;
            }

            // ハンドレイを非表示にする
            //PointerUtils.SetHandRayPointerBehavior(PointerBehavior.AlwaysOff);

            Initialize();
        }
        /// <summary>
        /// Update controller.
        /// </summary>
        public void Update()
        {
            if (!UInput.mousePresent)
            {
                return;
            }

            if (mouseDeviceManager == null)
            {
                // Get the instance of the mouse device manager.
                IMixedRealityDataProviderAccess dataProviderAccess = CoreServices.InputSystem as IMixedRealityDataProviderAccess;
                mouseDeviceManager = dataProviderAccess?.GetDataProvider <IMixedRealityMouseDeviceManager>();
            }

            // Bail early if our mouse isn't in our game window.
            if (UInput.mousePosition.x < 0 ||
                UInput.mousePosition.y < 0 ||
                UInput.mousePosition.x > Screen.width ||
                UInput.mousePosition.y > Screen.height)
            {
                return;
            }

            for (int i = 0; i < Interactions.Length; i++)
            {
                if ((Interactions[i].InputType == DeviceInputType.SpatialPointer) ||
                    (Interactions[i].InputType == DeviceInputType.PointerPosition))
                {
                    Vector3 mouseDelta = Vector3.zero;
                    mouseDelta.x = -UInput.GetAxis("Mouse Y");
                    mouseDelta.y = UInput.GetAxis("Mouse X");
                    if (mouseDeviceManager != null)
                    {
                        // Apply cursor speed.
                        mouseDelta *= mouseDeviceManager.CursorSpeed;
                    }

                    if (Interactions[i].InputType == DeviceInputType.SpatialPointer)
                    {
                        // Spatial pointer raises Pose events
                        controllerPose           = MixedRealityPose.ZeroIdentity;
                        controllerPose.Rotation  = Quaternion.Euler(mouseDelta);
                        Interactions[i].PoseData = controllerPose;

                        if (Interactions[i].Changed)
                        {
                            CoreServices.InputSystem?.RaisePoseInputChanged(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction, Interactions[i].PoseData);
                        }
                    }
                    else
                    {
                        // Pointer position raises position events
                        Interactions[i].Vector2Data = mouseDelta;

                        if (Interactions[i].Changed)
                        {
                            CoreServices.InputSystem?.RaisePositionInputChanged(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction, Interactions[i].Vector2Data);
                        }
                    }
                }

                if (Interactions[i].AxisType == AxisType.Digital)
                {
                    var keyButton = UInput.GetKey(Interactions[i].KeyCode);

                    // Update the interaction data source
                    Interactions[i].BoolData = keyButton;

                    // If our value changed raise it.
                    if (Interactions[i].Changed)
                    {
                        // Raise input system event if it's enabled
                        if (Interactions[i].BoolData)
                        {
                            CoreServices.InputSystem?.RaiseOnInputDown(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction);
                        }
                        else
                        {
                            CoreServices.InputSystem?.RaiseOnInputUp(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction);
                        }
                    }
                }

                if (Interactions[i].InputType == DeviceInputType.Scroll)
                {
                    Vector2 wheelDelta = UInput.mouseScrollDelta;
                    if (mouseDeviceManager != null)
                    {
                        // Apply wheel speed.
                        wheelDelta *= mouseDeviceManager.WheelSpeed;
                    }

                    Interactions[i].Vector2Data = wheelDelta;

                    if (Interactions[i].Changed)
                    {
                        CoreServices.InputSystem?.RaisePositionInputChanged(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction, Interactions[i].Vector2Data);
                    }
                }
            }
        }
        // Start is called before the first frame update
        void Start()
        {
            handJointService = CoreServices.GetInputSystemDataProvider <IMixedRealityHandJointService>();
            if (handJointService == null)
            {
                Debug.LogError("Can't get IMixedRealityHandJointService.");
                return;
            }

            dataProviderAccess = CoreServices.InputSystem as IMixedRealityDataProviderAccess;
            if (dataProviderAccess == null)
            {
                Debug.LogError("Can't get IMixedRealityDataProviderAccess.");
                return;
            }

            // ハンドレイを非表示にする
            PointerUtils.SetHandRayPointerBehavior(PointerBehavior.AlwaysOff);

            /*
             * Mesh mesh = new Mesh();
             *
             * // 頂点座標情報
             * mesh.vertices = new Vector3[] {
             *  new Vector3(   0f,  1f, 0f),
             *  new Vector3( 0.5f,  0f, 0f),
             *  new Vector3(-0.5f,  0f, 0f),
             *  new Vector3(   1f, -1f, 0f),
             *  new Vector3(   0f, -1f, 0f),
             *  new Vector3(  -1f, -1f, 0f)
             * };
             *
             * //各頂点にUV座標を設定する
             * mesh.uv = new Vector2[] {
             *  new Vector2 ( 0.5f,   1f),
             *  new Vector2 (0.75f, 0.5f),
             *  new Vector2 (0.25f, 0.5f),
             *  new Vector2 (   1f,   0f),
             *  new Vector2 ( 0.5f,   0f),
             *  new Vector2 (   0f,   0f)
             * };
             *
             * // 頂点を結ぶ順番情報
             * mesh.triangles = new int[] {
             *  0, 1, 2,
             *  1, 3, 4,
             *  2, 4, 5
             * };
             *
             * // 三角形と頂点からメッシュの法線を再計算する
             * mesh.RecalculateNormals();
             *
             * // バウンディングボリュームを再計算する
             * mesh.RecalculateBounds();
             *
             * // MeshRendererにメッシュ情報を渡すために必要
             * MeshFilter filter = GetComponent<MeshFilter>();
             * filter.sharedMesh = mesh;
             * filter.sharedMesh.name = "SampleMesh";
             *
             * // マテリアルを設定する
             * MeshRenderer renderer = GetComponent<MeshRenderer>();
             * renderer.material = mat;
             */
        }