コード例 #1
0
        private void MigrateProximityEffect(BoundsControl control, BoundingBox box)
        {
            ProximityEffectConfiguration config = EnsureConfiguration(control.HandleProximityEffectConfig);

            config.ProximityEffectActive = box.ProximityEffectActive;
            config.ObjectMediumProximity = box.HandleMediumProximity;
            config.ObjectCloseProximity  = box.HandleCloseProximity;
            config.FarScale       = box.FarScale;
            config.MediumScale    = box.MediumScale;
            config.CloseScale     = box.CloseScale;
            config.FarGrowRate    = box.FarGrowRate;
            config.MediumGrowRate = box.MediumGrowRate;
            config.CloseGrowRate  = box.CloseGrowRate;
            control.HandleProximityEffectConfig = config;
        }
コード例 #2
0
        /// <summary>
        /// This tests far, medium and close proximity scaling on scale handles by moving the test hand in the corresponding distance ranges
        /// </summary>
        /// <param name="boundsControl">Bounds Control to test on</param>
        /// <param name="hand">Test hand to use for testing proximity to handle</param>
        private IEnumerator TestCurrentProximityConfiguration(BoundsControl boundsControl, TestHand hand, string testDescription)
        {
            // get config and scaling handle
            ScaleHandlesConfiguration scaleHandleConfig = boundsControl.ScaleHandlesConfiguration;
            Vector3   defaultHandleSize     = Vector3.one * scaleHandleConfig.HandleSize;
            Transform scaleHandle           = boundsControl.gameObject.transform.Find("rigRoot/corner_3");
            Transform proximityScaledVisual = scaleHandle.GetChild(0)?.GetChild(0);
            var       frontRightCornerPos   = scaleHandle.position;
            // check far scale applied
            ProximityEffectConfiguration proximityConfig = boundsControl.HandleProximityEffectConfiguration;
            Vector3 expectedFarScale = defaultHandleSize * proximityConfig.FarScale;

            Assert.AreEqual(proximityScaledVisual.localScale, expectedFarScale, testDescription + " - Proximity far scale wasn't applied to handle");

            // move into medium range and check if scale was applied
            Vector3 mediumProximityTestDist = frontRightCornerPos;

            mediumProximityTestDist.x += proximityConfig.ObjectMediumProximity;
            yield return(hand.MoveTo(mediumProximityTestDist));

            Vector3 expectedMediumScale = defaultHandleSize * proximityConfig.MediumScale;

            Assert.AreEqual(proximityScaledVisual.localScale, expectedMediumScale, testDescription + " - Proximity medium scale wasn't applied to handle");

            // move into close scale range and check if scale was applied
            Vector3 closeProximityTestDir = frontRightCornerPos;

            closeProximityTestDir.x += proximityConfig.ObjectCloseProximity;
            yield return(hand.MoveTo(closeProximityTestDir));

            Vector3 expectedCloseScale = defaultHandleSize * proximityConfig.CloseScale;

            Assert.AreEqual(proximityScaledVisual.localScale, expectedCloseScale, testDescription + " - Proximity close scale wasn't applied to handle");

            // move out of close scale again - should fall back to medium proximity
            closeProximityTestDir = mediumProximityTestDist;
            yield return(hand.MoveTo(closeProximityTestDir));

            Assert.AreEqual(proximityScaledVisual.localScale, expectedMediumScale, testDescription + " - Proximity medium scale wasn't applied to handle");

            // move out of medium proximity and check if far scaling is applied
            mediumProximityTestDist = Vector3.zero;
            yield return(hand.MoveTo(mediumProximityTestDist));

            Assert.AreEqual(proximityScaledVisual.localScale, expectedFarScale, testDescription + " - Proximity far scale wasn't applied to handle");

            yield return(null);
        }
        private void MigrateProximityEffect(BoundsControl control, BoundingBox box, string configAssetDirectory)
        {
            ProximityEffectConfiguration config = ScriptableObject.CreateInstance <ProximityEffectConfiguration>();

            config.ProximityEffectActive = box.ProximityEffectActive;
            config.ObjectMediumProximity = box.HandleMediumProximity;
            config.ObjectCloseProximity  = box.HandleCloseProximity;
            config.FarScale       = box.FarScale;
            config.MediumScale    = box.MediumScale;
            config.CloseScale     = box.CloseScale;
            config.FarGrowRate    = box.FarGrowRate;
            config.MediumGrowRate = box.MediumGrowRate;
            config.CloseGrowRate  = box.CloseGrowRate;
            AssetDatabase.CreateAsset(config, GenerateUniqueConfigName(configAssetDirectory, box.gameObject, "ProximityEffectConfiguration"));

            control.HandleProximityEffectConfig = config;
        }
        private void MigrateProximityEffect(BoundsControl control, BoundingBox box)
        {
            List <string> propertyPaths = new List <string> {
                "proximityEffectActive", "handleMediumProximity", "handleCloseProximity", "farScale",
                "mediumScale", "closeScale", "farGrowRate", "mediumGrowRate", "closeGrowRate"
            };
            ProximityEffectConfiguration config = EnsureConfiguration(control.gameObject, control.HandleProximityEffectConfig, HasPropertyOverrides(box, propertyPaths));

            config.ProximityEffectActive = box.ProximityEffectActive;
            config.ObjectMediumProximity = box.HandleMediumProximity;
            config.ObjectCloseProximity  = box.HandleCloseProximity;
            config.FarScale       = box.FarScale;
            config.MediumScale    = box.MediumScale;
            config.CloseScale     = box.CloseScale;
            config.FarGrowRate    = box.FarGrowRate;
            config.MediumGrowRate = box.MediumGrowRate;
            config.CloseGrowRate  = box.CloseGrowRate;
            control.HandleProximityEffectConfig = config;
        }
コード例 #5
0
        /// <summary>
        /// Tests configuring every property of bounds control in edit mode
        /// </summary>
        public void TestConfiguration()
        {
            GameObject testCube       = GameObject.CreatePrimitive(PrimitiveType.Cube);
            int        testInstanceId = testCube.GetInstanceID();
            GameObject childSphere    = GameObject.CreatePrimitive(PrimitiveType.Sphere);
            var        collider       = childSphere.AddComponent <BoxCollider>();
            GameObject textObj        = new GameObject();

            textObj.transform.parent = testCube.transform;
            var textMesh = textObj.AddComponent <TextMesh>();

            childSphere.transform.parent = testCube.transform;
            var boundsControl = testCube.AddComponent <BoundsControl>();

            boundsControl.Target                  = childSphere;
            boundsControl.BoundsOverride          = collider;
            boundsControl.CalculationMethod       = BoundsCalculationMethod.ColliderOverRenderer;
            boundsControl.BoundsControlActivation = BoundsControlActivationType.ActivateByProximityAndPointer;
            boundsControl.FlattenAxis             = FlattenModeType.FlattenAuto;
            boundsControl.BoxPadding              = Vector3.one;

            // debug properties
            boundsControl.DebugText = textMesh;
            boundsControl.HideElementsInInspector = false;

            // box display
            List <string>           assetsToDestroy  = new List <string>();
            BoxDisplayConfiguration boxDisplayConfig = ScriptableObject.CreateInstance <BoxDisplayConfiguration>();
            string path = GeneratePath("BoxDisplay", testInstanceId);

            assetsToDestroy.Add(path);
            AssetDatabase.CreateAsset(boxDisplayConfig, path);
            var testMaterial = new Material(Shader.Find("Specular"));

            boxDisplayConfig.BoxMaterial             = testMaterial;
            boxDisplayConfig.BoxGrabbedMaterial      = testMaterial;
            boxDisplayConfig.FlattenAxisDisplayScale = 5.0f;
            boundsControl.BoxDisplayConfig           = boxDisplayConfig;

            // links
            LinksConfiguration linksConfig = ScriptableObject.CreateInstance <LinksConfiguration>();

            path = GeneratePath("Links", testInstanceId);
            assetsToDestroy.Add(path);
            AssetDatabase.CreateAsset(linksConfig, path);
            linksConfig.WireframeMaterial   = testMaterial;
            linksConfig.WireframeEdgeRadius = 1.0f;
            linksConfig.WireframeShape      = WireframeType.Cylindrical;
            linksConfig.ShowWireFrame       = false;
            boundsControl.LinksConfig       = linksConfig;

            // scale handles
            ScaleHandlesConfiguration scaleConfig = ScriptableObject.CreateInstance <ScaleHandlesConfiguration>();

            path = GeneratePath("ScaleHandles", testInstanceId);
            assetsToDestroy.Add(path);
            AssetDatabase.CreateAsset(scaleConfig, path);

            scaleConfig.HandleSlatePrefab          = childSphere;
            scaleConfig.ShowScaleHandles           = true;
            scaleConfig.HandleMaterial             = testMaterial;
            scaleConfig.HandleGrabbedMaterial      = testMaterial;
            scaleConfig.HandlePrefab               = testCube;
            scaleConfig.HandleSize                 = 0.05f;
            scaleConfig.ColliderPadding            = Vector3.one;
            scaleConfig.DrawTetherWhenManipulating = false;
            scaleConfig.HandlesIgnoreCollider      = collider;

            boundsControl.ScaleHandlesConfig = scaleConfig;

            // rotation handles
            RotationHandlesConfiguration rotationHandles = ScriptableObject.CreateInstance <RotationHandlesConfiguration>();

            path = GeneratePath("RotationHandles", testInstanceId);
            assetsToDestroy.Add(path);
            AssetDatabase.CreateAsset(rotationHandles, path);

            rotationHandles.RotationHandlePrefabColliderType = HandlePrefabCollider.Box;
            rotationHandles.ShowRotationHandleForX           = false;
            rotationHandles.ShowRotationHandleForY           = true;
            rotationHandles.ShowRotationHandleForZ           = true;
            rotationHandles.HandleMaterial             = testMaterial;
            rotationHandles.HandleGrabbedMaterial      = testMaterial;
            rotationHandles.HandlePrefab               = childSphere;
            rotationHandles.HandleSize                 = 0.05f;
            rotationHandles.ColliderPadding            = Vector3.zero;
            rotationHandles.DrawTetherWhenManipulating = false;
            rotationHandles.HandlesIgnoreCollider      = collider;

            boundsControl.RotationHandlesConfig = rotationHandles;

            // proximity effect
            ProximityEffectConfiguration proximityConfig = ScriptableObject.CreateInstance <ProximityEffectConfiguration>();

            path = GeneratePath("ProximityEffect", testInstanceId);
            assetsToDestroy.Add(path);
            AssetDatabase.CreateAsset(proximityConfig, path);

            proximityConfig.ProximityEffectActive = true;
            proximityConfig.ObjectMediumProximity = 0.2f;
            proximityConfig.ObjectCloseProximity  = 0.02f;
            proximityConfig.FarScale       = 10.0f;
            proximityConfig.MediumScale    = 3.0f;
            proximityConfig.CloseScale     = 5.0f;
            proximityConfig.FarGrowRate    = 1.0f;
            proximityConfig.MediumGrowRate = 0.1f;
            proximityConfig.CloseGrowRate  = 0.5f;

            boundsControl.HandleProximityEffectConfig = proximityConfig;

            // clean up created assets
            foreach (string assetPath in assetsToDestroy)
            {
                AssetDatabase.DeleteAsset(assetPath);
            }

            // destroy test cube
            Object.DestroyImmediate(testCube);
        }
コード例 #6
0
        public IEnumerator ProximityOnScaleHandles()
        {
            var boundsControl = InstantiateSceneAndDefaultBoundsControl();

            yield return(VerifyInitialBoundsCorrect(boundsControl));

            // 1. test no proximity scaling active per default
            ScaleHandlesConfiguration scaleHandleConfig = boundsControl.ScaleHandlesConfiguration;
            Vector3 defaultHandleSize = Vector3.one * scaleHandleConfig.HandleSize;

            Vector3 initialHandPosition = new Vector3(0, 0, 0f);
            // this is specific to scale handles
            Transform scaleHandle           = boundsControl.gameObject.transform.Find("rigRoot/corner_3");
            Transform proximityScaledVisual = scaleHandle.GetChild(0)?.GetChild(0);
            var       frontRightCornerPos   = scaleHandle.position; // front right corner is corner

            Assert.IsNotNull(proximityScaledVisual, "Couldn't get visual gameobject for scale handle");
            Assert.IsTrue(proximityScaledVisual.name == "visuals", "scale visual has unexpected name");

            yield return(null);

            // verify no proximity scaling applied per default
            Assert.AreEqual(proximityScaledVisual.localScale, defaultHandleSize, "Handle was scaled even though proximity effect wasn't active");
            TestHand hand         = new TestHand(Handedness.Left);
            Vector3  initialScale = boundsControl.transform.localScale;

            // Hands grab object at initial position
            yield return(hand.Show(initialHandPosition));

            yield return(hand.SetGesture(ArticulatedHandPose.GestureId.OpenSteadyGrabPoint));

            yield return(hand.MoveTo(frontRightCornerPos));

            yield return(null);

            // we're in poximity scaling range - check if proximity scaling wasn't applied
            Assert.AreEqual(proximityScaledVisual.localScale, defaultHandleSize, "Handle was scaled even though proximity effect wasn't active");

            //// reset hand
            yield return(hand.MoveTo(initialHandPosition));

            // 2. enable proximity scaling and test defaults
            ProximityEffectConfiguration proximityConfig = boundsControl.HandleProximityEffectConfiguration;

            proximityConfig.ProximityEffectActive = true;
            proximityConfig.CloseGrowRate         = 1.0f;
            proximityConfig.MediumGrowRate        = 1.0f;
            proximityConfig.FarGrowRate           = 1.0f;
            boundsControl.CreateRig();
            yield return(null); // wait so rig gameobjects get recreated

            yield return(TestCurrentProximityConfiguration(boundsControl, hand, "Defaults"));

            // reset hand
            yield return(hand.MoveTo(initialHandPosition));

            // 3. now test custom configuration is applied during runtime
            proximityConfig.CloseScale  = 4.0f;
            proximityConfig.MediumScale = 3.0f;
            proximityConfig.FarScale    = 2.0f;

            proximityConfig.ObjectMediumProximity = 0.2f;
            proximityConfig.ObjectCloseProximity  = 0.1f;

            boundsControl.CreateRig();
            yield return(null); // wait so rig gameobjects get recreated

            yield return(TestCurrentProximityConfiguration(boundsControl, hand, "Custom runtime config max"));
        }