/// <summary> /// Create all necessary resources. /// </summary> private void SetupManipulation() { TakeDownManipulation(); if (userOriented) { boundingBox = owner.gameObject.AddComponent <BoundingBox>(); boundingBox.HideElementsInInspector = false; boundingBox.BoundingBoxActivation = BoundingBox.BoundingBoxActivationType.ActivateByProximityAndPointer; boundingBox.RotateStarted.AddListener(BeginManipulation); boundingBox.RotateStopped.AddListener(FinishManipulation); boundingBox.ScaleStarted.AddListener(BeginManipulation); boundingBox.ScaleStopped.AddListener(FinishManipulation); float maxScaleFactor = 8.0f; float minScaleFactor = 0.2f; MinMaxScaleConstraint scaleHandler = owner.GetComponent <MinMaxScaleConstraint>(); if (scaleHandler == null) { scaleHandler = owner.gameObject.AddComponent <MinMaxScaleConstraint>(); } scaleHandler.RelativeToInitialState = true; scaleHandler.ScaleMaximum = maxScaleFactor; scaleHandler.ScaleMinimum = minScaleFactor; } manipulationHandler = owner.gameObject.AddComponent <ManipulationHandler>(); manipulationHandler.OneHandRotationModeFar = ManipulationHandler.RotateInOneHandType.MaintainOriginalRotation; manipulationHandler.OneHandRotationModeNear = ManipulationHandler.RotateInOneHandType.MaintainOriginalRotation; manipulationHandler.ConstraintOnRotation = Toolkit.Utilities.RotationConstraintType.None; manipulationHandler.OnManipulationStarted.AddListener(BeginManipulation); manipulationHandler.OnManipulationEnded.AddListener(FinishManipulation); nearGrabbable = owner.gameObject.AddComponent <NearInteractionGrabbable>(); }
/// <inheritdoc /> public void Migrate(GameObject gameObject) { #if UNITY_EDITOR var boundingBox = gameObject.GetComponent <BoundingBox>(); var boundsControl = gameObject.AddComponent <BoundsControl>(); { Undo.RecordObject(gameObject, "BoundsControl migration: swapping BoundingBox with BoundsControl."); // migrate logic settings boundsControl.Target = boundingBox.Target; boundsControl.BoundsOverride = boundingBox.BoundsOverride; boundsControl.CalculationMethod = MigrateCalculationMethod(boundingBox.CalculationMethod); boundsControl.BoundsControlActivation = MigrateActivationFlag(boundingBox.BoundingBoxActivation); // only carry over min max scaling values if user hasn't attached min max scale constraint component yet if (gameObject.GetComponent <MinMaxScaleConstraint>() == null) { #pragma warning disable 0618 // create a minmaxscaleconstraint in case there's a min max scale set up if (boundingBox.ScaleMinimum != 0.0f || boundingBox.ScaleMaximum != 0.0f) { MinMaxScaleConstraint scaleConstraint = gameObject.AddComponent <MinMaxScaleConstraint>(); scaleConstraint.ScaleMinimum = boundingBox.ScaleMinimum; scaleConstraint.ScaleMaximum = boundingBox.ScaleMaximum; } #pragma warning restore 0618 } // migrate visuals boundsControl.FlattenAxis = MigrateFlattenAxis(boundingBox.FlattenAxis); boundsControl.BoxPadding = boundingBox.BoxPadding; string configDir = GetBoundsControlConfigDirectory(boundingBox); MigrateBoxDisplay(boundsControl, boundingBox, configDir); MigrateLinks(boundsControl, boundingBox, configDir); MigrateScaleHandles(boundsControl, boundingBox, configDir); MigrateRotationHandles(boundsControl, boundingBox, configDir); MigrateProximityEffect(boundsControl, boundingBox, configDir); // debug properties boundsControl.DebugText = boundingBox.debugText; boundsControl.HideElementsInInspector = boundingBox.HideElementsInInspector; // events boundsControl.RotateStarted = boundingBox.RotateStarted; boundsControl.RotateStopped = boundingBox.RotateStopped; boundsControl.ScaleStarted = boundingBox.ScaleStarted; boundsControl.ScaleStopped = boundingBox.ScaleStopped; } // look in the scene for app bars and upgrade them too to point to the new component MigrateAppBar(boundingBox, boundsControl); { Undo.RecordObject(gameObject, "Removing obsolete BoundingBox component"); // destroy obsolete component Object.DestroyImmediate(boundingBox); } #endif }
public void MinMaxScale(GameObject wwwwwww) { wwwwwww.gameObject.AddComponent <MinMaxScaleConstraint>(); MinMaxScaleConstraint scaleConstraint = wwwwwww.gameObject.GetComponent <MinMaxScaleConstraint>(); scaleConstraint.ScaleMinimum = 0.0000000005f; scaleConstraint.ScaleMaximum = 2f; }
/// <summary> /// Create all necessary resources. /// </summary> private void SetupManipulation() { TakeDownManipulation(); if (userOriented) { boundingBox = owner.gameObject.AddComponent <BoundingBox>(); boundingBox.HideElementsInInspector = false; boundingBox.BoundingBoxActivation = BoundingBox.BoundingBoxActivationType.ActivateByProximityAndPointer; boundingBox.RotateStarted.AddListener(BeginManipulation); boundingBox.RotateStopped.AddListener(FinishManipulation); boundingBox.ScaleStarted.AddListener(BeginManipulation); boundingBox.ScaleStopped.AddListener(FinishManipulation); float maxScaleFactor = 8.0f; float minScaleFactor = 0.2f; MinMaxScaleConstraint scaleHandler = owner.GetComponent <MinMaxScaleConstraint>(); if (scaleHandler == null) { scaleHandler = owner.gameObject.AddComponent <MinMaxScaleConstraint>(); } scaleHandler.RelativeToInitialState = true; scaleHandler.ScaleMaximum = maxScaleFactor; scaleHandler.ScaleMinimum = minScaleFactor; } manipulationHandler = owner.gameObject.AddComponent <ObjectManipulator>(); var rotationAxisConstraint = owner.gameObject.AddComponent <RotationAxisConstraint>(); rotationAxisConstraint.HandType = Toolkit.Utilities.ManipulationHandFlags.OneHanded | Toolkit.Utilities.ManipulationHandFlags.TwoHanded; rotationAxisConstraint.ProximityType = Toolkit.Utilities.ManipulationProximityFlags.Near | Toolkit.Utilities.ManipulationProximityFlags.Far; rotationAxisConstraint.ConstraintOnRotation = 0; var fixedRotationToWorldConstraint = owner.gameObject.AddComponent <FixedRotationToWorldConstraint>(); fixedRotationToWorldConstraint.HandType = Toolkit.Utilities.ManipulationHandFlags.OneHanded; fixedRotationToWorldConstraint.ProximityType = Toolkit.Utilities.ManipulationProximityFlags.Near | Toolkit.Utilities.ManipulationProximityFlags.Far; manipulationHandler.OnManipulationStarted.AddListener(BeginManipulation); manipulationHandler.OnManipulationEnded.AddListener(FinishManipulation); nearGrabbable = owner.gameObject.AddComponent <NearInteractionGrabbable>(); }
/// <summary> /// Register a transform scale handler to bounding box to limit the scaling range /// This is useful for adding/switching your scale handler during runtime /// </summary> /// <param name="transformScaleHandler">scale handler you want to switch to - can be null if scaling shouldn't be constrained</param> public void RegisterTransformScaleHandler(MinMaxScaleConstraint transformScaleHandler) { scaleConstraint = transformScaleHandler; }