Esempio n. 1
0
        private void MigrateRotationHandles(BoundsControl control, BoundingBox box, string configAssetDirectory)
        {
            RotationHandlesConfiguration config = ScriptableObject.CreateInstance <RotationHandlesConfiguration>();

            config.RotationHandlePrefabColliderType = MigrateRotationHandleColliderType(box.RotationHandlePrefabColliderType);
            config.ShowRotationHandleForX           = box.ShowRotationHandleForX;
            config.ShowRotationHandleForY           = box.ShowRotationHandleForY;
            config.ShowRotationHandleForZ           = box.ShowRotationHandleForZ;
            config.HandleMaterial        = box.HandleMaterial;
            config.HandleGrabbedMaterial = box.HandleGrabbedMaterial;
            config.HandlePrefab          = box.RotationHandleSlatePrefab;
            config.HandleSize            = box.RotationHandleSize;
            config.ColliderPadding       = box.RotateHandleColliderPadding;
            AssetDatabase.CreateAsset(config, GenerateUniqueConfigName(configAssetDirectory, box.gameObject, "RotationHandlesConfiguration"));

            control.RotationHandles = config;
        }
Esempio n. 2
0
        private void MigrateRotationHandles(BoundsControl control, BoundingBox box)
        {
            RotationHandlesConfiguration config = EnsureConfiguration(control.RotationHandlesConfig);

            config.HandlePrefabColliderType = MigrateRotationHandleColliderType(box.RotationHandlePrefabColliderType);
            config.ShowHandleForX           = box.ShowRotationHandleForX;
            config.ShowHandleForY           = box.ShowRotationHandleForY;
            config.ShowHandleForZ           = box.ShowRotationHandleForZ;
            config.HandleMaterial           = box.HandleMaterial;
            config.HandleGrabbedMaterial    = box.HandleGrabbedMaterial;
            config.HandlePrefab             = box.RotationHandlePrefab;
            config.HandleSize                 = box.RotationHandleSize;
            config.ColliderPadding            = box.RotateHandleColliderPadding;
            config.DrawTetherWhenManipulating = box.DrawTetherWhenManipulating;
            config.HandlesIgnoreCollider      = box.HandlesIgnoreCollider;
            control.RotationHandlesConfig     = config;
        }
        private void MigrateRotationHandles(BoundsControl control, BoundingBox box)
        {
            List <string> propertyPaths = new List <string> {
                "rotationHandlePrefabColliderType", "showRotationHandleForX", "showRotationHandleForY",
                "showRotationHandleForZ", "handleMaterial", "handleGrabbedMaterial", "rotationHandlePrefab", "rotationHandleSize", "rotateHandleColliderPadding",
                "drawTetherWhenManipulating", "handlesIgnoreCollider"
            };
            RotationHandlesConfiguration config = EnsureConfiguration(control.gameObject, control.RotationHandlesConfig, HasPropertyOverrides(box, propertyPaths));

            config.HandlePrefabColliderType = MigrateRotationHandleColliderType(box.RotationHandlePrefabColliderType);
            config.ShowHandleForX           = box.ShowRotationHandleForX;
            config.ShowHandleForY           = box.ShowRotationHandleForY;
            config.ShowHandleForZ           = box.ShowRotationHandleForZ;
            config.HandleMaterial           = box.HandleMaterial;
            config.HandleGrabbedMaterial    = box.HandleGrabbedMaterial;
            config.HandlePrefab             = box.RotationHandlePrefab;
            config.HandleSize                 = box.RotationHandleSize;
            config.ColliderPadding            = box.RotateHandleColliderPadding;
            config.DrawTetherWhenManipulating = box.DrawTetherWhenManipulating;
            config.HandlesIgnoreCollider      = box.HandlesIgnoreCollider;
            control.RotationHandlesConfig     = 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);
        }