protected override void OnEnable()
        {
            base.OnEnable();

            magneticSurfacesProperty            = serializedObject.FindProperty("magneticSurfaces");
            maxDistanceProperty                 = serializedObject.FindProperty("maxRaycastDistance");
            closestDistanceProperty             = serializedObject.FindProperty("closestDistance");
            surfaceNormalOffsetProperty         = serializedObject.FindProperty("surfaceNormalOffset");
            surfaceRayOffsetProperty            = serializedObject.FindProperty("surfaceRayOffset");
            currentRaycastDirectionModeProperty = serializedObject.FindProperty("currentRaycastDirectionMode");
            raycastModeProperty                 = serializedObject.FindProperty("raycastMode");
            boxRaysPerEdgeProperty              = serializedObject.FindProperty("boxRaysPerEdge");
            orthographicBoxCastProperty         = serializedObject.FindProperty("orthographicBoxCast");
            maximumNormalVarianceProperty       = serializedObject.FindProperty("maximumNormalVariance");
            sphereSizeProperty                  = serializedObject.FindProperty("sphereSize");
            volumeCastSizeOverrideProperty      = serializedObject.FindProperty("volumeCastSizeOverride");
            useLinkedAltScaleOverrideProperty   = serializedObject.FindProperty("useLinkedAltScaleOverride");
            currentRaycastDirectionModeProperty = serializedObject.FindProperty("currentRaycastDirectionMode");
            orientationModeProperty             = serializedObject.FindProperty("orientationMode");
            orientationBlendProperty            = serializedObject.FindProperty("orientationBlend");
            orientationVerticalProperty         = serializedObject.FindProperty("keepOrientationVertical");
            debugEnabledProperty                = serializedObject.FindProperty("debugEnabled");

            surfaceMagnetism = target as SurfaceMagnetism;
        }
Exemplo n.º 2
0
        public IEnumerator TestSurfaceMagnetism()
        {
            // Reset view to origin
            MixedRealityPlayspace.PerformTransformation(p =>
            {
                p.position = Vector3.zero;
                p.LookAt(Vector3.forward);
            });

            // Build wall to collide against
            var wall = GameObject.CreatePrimitive(PrimitiveType.Cube);

            wall.transform.localScale = new Vector3(25.0f, 25.0f, 0.2f);
            wall.transform.Rotate(Vector3.up, 180.0f); // Rotate wall so forward faces camera
            wall.transform.position = Vector3.forward * 10.0f;

            yield return(WaitForFrames(2));

            // Instantiate our test GameObject with solver.
            // Set layer to ignore raycast so solver doesn't raycast itself (i.e BoxCollider)
            var testObjects = InstantiateTestSolver <SurfaceMagnetism>();

            testObjects.target.layer = LayerMask.NameToLayer("Ignore Raycast");
            SurfaceMagnetism surfaceMag = testObjects.solver as SurfaceMagnetism;

            var targetTransform = testObjects.target.transform;
            var cameraTransform = CameraCache.Main.transform;

            yield return(WaitForFrames(2));

            // Confirm that the surfacemagnetic cube is about on the wall straight ahead
            Assert.LessOrEqual(Vector3.Distance(targetTransform.position, wall.transform.position), DistanceThreshold);

            // Rotate the camera
            Vector3 cameraDir = Vector3.forward + Vector3.right;

            MixedRealityPlayspace.PerformTransformation(p =>
            {
                p.position = Vector3.zero;
                p.LookAt(cameraDir);
            });

            // Calculate where our camera hits the wall
            RaycastHit hitInfo;

            Assert.IsTrue(UnityEngine.Physics.Raycast(Vector3.zero, cameraDir, out hitInfo), "Raycast from camera did not hit wall");

            // Let SurfaceMagnetism update
            yield return(WaitForFrames(2));

            // Confirm that the surfacemagnetic cube is on the wall with camera rotated
            Assert.LessOrEqual(Vector3.Distance(targetTransform.position, hitInfo.point), DistanceThreshold);

            // Default orientation mode is TrackedTarget, test object should be facing camera
            Assert.IsTrue(Mathf.Approximately(-1.0f, Vector3.Dot(targetTransform.forward.normalized, cameraTransform.forward.normalized)));

            // Change default orientation mode to surface normal
            surfaceMag.CurrentOrientationMode = SurfaceMagnetism.OrientationMode.SurfaceNormal;

            yield return(WaitForFrames(2));

            // Test object should now be facing into the wall (i.e Z axis)
            Assert.IsTrue(Mathf.Approximately(1.0f, Vector3.Dot(targetTransform.forward.normalized, Vector3.forward)));
        }