|
| 1 | +using NUnit.Framework; |
| 2 | +using Microsoft.MixedReality.Toolkit.Experimental.UI.BoundsControl; |
| 3 | +using Microsoft.MixedReality.Toolkit.Experimental.UI.BoundsControlTypes; |
| 4 | +using System.Collections.Generic; |
| 5 | +using UnityEngine; |
| 6 | +using UnityEditor; |
| 7 | + |
| 8 | +namespace Microsoft.MixedReality.Toolkit.Tests.Experimental |
| 9 | +{ |
| 10 | + /// <summary> |
| 11 | + /// Tests for edit mode behavior of bounds control |
| 12 | + /// </summary> |
| 13 | + public class BoundsControlTests |
| 14 | + { |
| 15 | + |
| 16 | + [Test] |
| 17 | + /// <summary> |
| 18 | + /// Tests configuring every property of bounds control in edit mode |
| 19 | + /// </summary> |
| 20 | + public void TestConfiguration() |
| 21 | + { |
| 22 | + GameObject testCube = GameObject.CreatePrimitive(PrimitiveType.Cube); |
| 23 | + int testInstanceId = testCube.GetInstanceID(); |
| 24 | + GameObject childSphere = GameObject.CreatePrimitive(PrimitiveType.Sphere); |
| 25 | + var collider = childSphere.AddComponent<BoxCollider>(); |
| 26 | + GameObject textObj = new GameObject(); |
| 27 | + textObj.transform.parent = testCube.transform; |
| 28 | + var textMesh = textObj.AddComponent<TextMesh>(); |
| 29 | + childSphere.transform.parent = testCube.transform; |
| 30 | + var boundsControl = testCube.AddComponent<BoundsControl>(); |
| 31 | + boundsControl.Target = childSphere; |
| 32 | + boundsControl.BoundsOverride = collider; |
| 33 | + boundsControl.CalculationMethod = BoundsCalculationMethod.ColliderOverRenderer; |
| 34 | + boundsControl.BoundsControlActivation = BoundsControlActivationType.ActivateByProximityAndPointer; |
| 35 | + boundsControl.DrawTetherWhenManipulating = false; |
| 36 | + boundsControl.HandlesIgnoreCollider = collider; |
| 37 | + boundsControl.FlattenAxis = FlattenModeType.FlattenAuto; |
| 38 | + boundsControl.BoxPadding = Vector3.one; |
| 39 | + |
| 40 | + // debug properties |
| 41 | + boundsControl.DebugText = textMesh; |
| 42 | + boundsControl.HideElementsInInspector = false; |
| 43 | + |
| 44 | + // box display |
| 45 | + List<string> assetsToDestroy = new List<string>(); |
| 46 | + BoxDisplayConfiguration boxDisplayConfig = ScriptableObject.CreateInstance<BoxDisplayConfiguration>(); |
| 47 | + string path = GeneratePath("BoxDisplay", testInstanceId); |
| 48 | + assetsToDestroy.Add(path); |
| 49 | + AssetDatabase.CreateAsset(boxDisplayConfig, path); |
| 50 | + var testMaterial = new Material(Shader.Find("Specular")); |
| 51 | + boxDisplayConfig.BoxMaterial = testMaterial; |
| 52 | + boxDisplayConfig.BoxGrabbedMaterial = testMaterial; |
| 53 | + boxDisplayConfig.FlattenAxisDisplayScale = 5.0f; |
| 54 | + boundsControl.BoxDisplayConfiguration = boxDisplayConfig; |
| 55 | + |
| 56 | + // links |
| 57 | + LinksConfiguration linksConfig = ScriptableObject.CreateInstance<LinksConfiguration>(); |
| 58 | + path = GeneratePath("Links", testInstanceId); |
| 59 | + assetsToDestroy.Add(path); |
| 60 | + AssetDatabase.CreateAsset(linksConfig, path); |
| 61 | + linksConfig.WireframeMaterial = testMaterial; |
| 62 | + linksConfig.WireframeEdgeRadius = 1.0f; |
| 63 | + linksConfig.WireframeShape = WireframeType.Cylindrical; |
| 64 | + linksConfig.ShowWireFrame = false; |
| 65 | + boundsControl.LinksConfiguration = linksConfig; |
| 66 | + |
| 67 | + // scale handles |
| 68 | + ScaleHandlesConfiguration scaleConfig = ScriptableObject.CreateInstance<ScaleHandlesConfiguration>(); |
| 69 | + path = GeneratePath("ScaleHandles", testInstanceId); |
| 70 | + assetsToDestroy.Add(path); |
| 71 | + AssetDatabase.CreateAsset(scaleConfig, path); |
| 72 | + |
| 73 | + scaleConfig.HandleSlatePrefab = childSphere; |
| 74 | + scaleConfig.ShowScaleHandles = true; |
| 75 | + scaleConfig.HandleMaterial = testMaterial; |
| 76 | + scaleConfig.HandleGrabbedMaterial = testMaterial; |
| 77 | + scaleConfig.HandlePrefab = testCube; |
| 78 | + scaleConfig.HandleSize = 0.05f ; |
| 79 | + scaleConfig.ColliderPadding = Vector3.one; |
| 80 | + |
| 81 | + boundsControl.ScaleHandlesConfiguration = scaleConfig; |
| 82 | + |
| 83 | + // rotation handles |
| 84 | + RotationHandlesConfiguration rotationHandles = ScriptableObject.CreateInstance<RotationHandlesConfiguration>(); |
| 85 | + path = GeneratePath("RotationHandles", testInstanceId); |
| 86 | + assetsToDestroy.Add(path); |
| 87 | + AssetDatabase.CreateAsset(rotationHandles, path); |
| 88 | + |
| 89 | + rotationHandles.RotationHandlePrefabColliderType = RotationHandlePrefabCollider.Box; |
| 90 | + rotationHandles.ShowRotationHandleForX = false; |
| 91 | + rotationHandles.ShowRotationHandleForY = true; |
| 92 | + rotationHandles.ShowRotationHandleForZ = true; |
| 93 | + rotationHandles.HandleMaterial = testMaterial; |
| 94 | + rotationHandles.HandleGrabbedMaterial = testMaterial; |
| 95 | + rotationHandles.HandlePrefab = childSphere; |
| 96 | + rotationHandles.HandleSize = 0.05f; |
| 97 | + rotationHandles.ColliderPadding = Vector3.zero; |
| 98 | + |
| 99 | + boundsControl.RotationHandles = rotationHandles; |
| 100 | + |
| 101 | + // proximity effect |
| 102 | + ProximityEffectConfiguration proximityConfig = ScriptableObject.CreateInstance<ProximityEffectConfiguration>(); |
| 103 | + path = GeneratePath("ProximityEffect", testInstanceId); |
| 104 | + assetsToDestroy.Add(path); |
| 105 | + AssetDatabase.CreateAsset(proximityConfig, path); |
| 106 | + |
| 107 | + proximityConfig.ProximityEffectActive = true; |
| 108 | + proximityConfig.ObjectMediumProximity = 0.2f; |
| 109 | + proximityConfig.ObjectCloseProximity = 0.02f; |
| 110 | + proximityConfig.FarScale = 10.0f; |
| 111 | + proximityConfig.MediumScale = 3.0f; |
| 112 | + proximityConfig.CloseScale = 5.0f; |
| 113 | + proximityConfig.FarGrowRate = 1.0f; |
| 114 | + proximityConfig.MediumGrowRate = 0.1f; |
| 115 | + proximityConfig.CloseGrowRate = 0.5f; |
| 116 | + |
| 117 | + boundsControl.HandleProximityEffectConfiguration = proximityConfig; |
| 118 | + |
| 119 | + // clean up created assets |
| 120 | + foreach (string assetPath in assetsToDestroy) |
| 121 | + { |
| 122 | + AssetDatabase.DeleteAsset(assetPath); |
| 123 | + } |
| 124 | + |
| 125 | + // destroy test cube |
| 126 | + Object.DestroyImmediate(testCube); |
| 127 | + } |
| 128 | + |
| 129 | + /// <summary> |
| 130 | + /// Generates an asset path out of the given configname and test instance id |
| 131 | + /// </summary> |
| 132 | + /// <param name="configName">name of the config to be saved</param> |
| 133 | + /// <param name="testInstanceId">test instance id that makes sure this path is unique</param> |
| 134 | + /// <returns></returns> |
| 135 | + private string GeneratePath(string configName, int testInstanceId) |
| 136 | + { |
| 137 | + return "Assets/" + configName + testInstanceId + ".asset"; |
| 138 | + } |
| 139 | + } |
| 140 | +} |
0 commit comments