private void MigrateScaleHandles(BoundsControl control, BoundingBox box) { ScaleHandlesConfiguration config = EnsureConfiguration(control.ScaleHandlesConfig); config.HandleSlatePrefab = box.ScaleHandleSlatePrefab; config.ShowScaleHandles = box.ShowScaleHandles; config.HandleMaterial = box.HandleMaterial; config.HandleGrabbedMaterial = box.HandleGrabbedMaterial; config.HandlePrefab = box.ScaleHandlePrefab; config.HandleSize = box.ScaleHandleSize; config.ColliderPadding = box.ScaleHandleColliderPadding; config.DrawTetherWhenManipulating = box.DrawTetherWhenManipulating; config.HandlesIgnoreCollider = box.HandlesIgnoreCollider; control.ScaleHandlesConfig = config; }
private void MigrateScaleHandles(BoundsControl control, BoundingBox box, string configAssetDirectory) { ScaleHandlesConfiguration config = ScriptableObject.CreateInstance <ScaleHandlesConfiguration>(); config.HandleSlatePrefab = box.ScaleHandleSlatePrefab; config.ShowScaleHandles = box.ShowScaleHandles; config.HandleMaterial = box.HandleMaterial; config.HandleGrabbedMaterial = box.HandleGrabbedMaterial; config.HandlePrefab = box.ScaleHandlePrefab; config.HandleSize = box.ScaleHandleSize; config.ColliderPadding = box.ScaleHandleColliderPadding; AssetDatabase.CreateAsset(config, GenerateUniqueConfigName(configAssetDirectory, box.gameObject, "ScaleHandlesConfiguration")); control.ScaleHandlesConfiguration = config; }
/// <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 MigrateScaleHandles(BoundsControl control, BoundingBox box) { List <string> propertyPaths = new List <string> { "scaleHandleSlatePrefab", "showScaleHandles", "handleMaterial", "handleGrabbedMaterial", "scaleHandlePrefab", "scaleHandleSize", "scaleHandleColliderPadding", "drawTetherWhenManipulating", "handlesIgnoreCollider" }; ScaleHandlesConfiguration config = EnsureConfiguration(control.gameObject, control.ScaleHandlesConfig, HasPropertyOverrides(box, propertyPaths)); config.HandleSlatePrefab = box.ScaleHandleSlatePrefab; config.ShowScaleHandles = box.ShowScaleHandles; config.HandleMaterial = box.HandleMaterial; config.HandleGrabbedMaterial = box.HandleGrabbedMaterial; config.HandlePrefab = box.ScaleHandlePrefab; config.HandleSize = box.ScaleHandleSize; config.ColliderPadding = box.ScaleHandleColliderPadding; config.DrawTetherWhenManipulating = box.DrawTetherWhenManipulating; config.HandlesIgnoreCollider = box.HandlesIgnoreCollider; control.ScaleHandlesConfig = config; }
/// <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); }
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")); }