private void LinkGrabEvent(LinearDriveFacade linerJointFacade, Transform interactable) { // Connects the linerJointFacade with the interactableFacade so the position of the normaliser object is correct InteractableFacade interactableFacade = interactable.GetComponent <InteractableFacade>(); UnityAction action = (_) => linerJointFacade.SetTargetValueByStepValue(); interactableFacade.LastUngrabbed.AddListener(action); }
private void ConfigLinerJointFacade(LinearDriveFacade linerJointFacade, bool isMax) { // All drive axes are the same as they are rotated by a parent object to the specific axis linerJointFacade.DriveAxis = Tilia.Interactions.Controllables.Driver.DriveAxis.Axis.YAxis; linerJointFacade.MoveToTargetValue = true; linerJointFacade.TargetValue = isMax ? 1f : 0f; linerJointFacade.SetStepRangeMaximum(100f); }
/// <summary> /// Wraps a given normaliser handle in a Tilia 'LinearJointDrive' and configures the Linear Joint based on a axis direction /// </summary> /// <param name="handle">The GameObject to wrap</param> /// <param name="axisDirection">X=1, Y=2, Z=3</param> /// <param name="isMax">True if the normaliser is the maximum filter</param> private void ConvertToLinearJointDrive(GameObject handle, int axisDirection, bool isMax) { handle.SetActive(true); GameObject newLinerJointPrefab = Instantiate(linearJointDrivePrefab); GameObject linerJoint = WrapObject(handle, newLinerJointPrefab, linearJointSuffix); LinearDriveFacade linerJointFacade = linerJoint.GetComponent <LinearDriveFacade>(); ConfigNormaliserSlider(handle, axisDirection); ConfigLinerJoint(linerJoint.transform, axisDirection); ConfigLinerJointFacade(linerJointFacade, isMax); }
private void LinkScalingEvent(LinearDriveFacade linerJointFacade, int axisDirection, bool isMax) { // Connects the linerJoint to the corresponding min/max axis UnityAction <float> setScaleAction = (axisDirection, isMax) switch { (1, false) => SetScaleBuilder(x => xDimension.minScale = x), (1, true) => SetScaleBuilder(x => xDimension.maxScale = x), (2, false) => SetScaleBuilder(x => yDimension.minScale = x), (2, true) => SetScaleBuilder(x => yDimension.maxScale = x), (3, false) => SetScaleBuilder(x => zDimension.minScale = x), (3, true) => SetScaleBuilder(x => zDimension.maxScale = x), _ => throw new Exception("Invalid Axis Direction") }; linerJointFacade.NormalizedValueChanged.AddListener(setScaleAction); }
void Update() { if (enableVisualisationScaling && transform.hasChanged) { transform.hasChanged = false; Axis[] axes = GetComponentsInChildren <Axis>(); axes?.ForEach(axis => { Transform minLinerJoint = axis.transform.Find("MinAxisHandle" + " " + linearJointSuffix); LinearDriveFacade minLinerJointFacade = minLinerJoint.GetComponent <LinearDriveFacade>(); minLinerJointFacade.Drive.SetUp(); Transform maxLinerJoint = axis.transform.Find("MaxAxisHandle" + " " + linearJointSuffix); LinearDriveFacade maxLinerJointFacade = maxLinerJoint.GetComponent <LinearDriveFacade>(); maxLinerJointFacade.Drive.SetUp(); }); } }
private void ConfigureHandle(Axis axis, string handleName, bool isMax) { int axisDirection = axis.AxisDirection; GameObject handle = axis.transform.Find(handleName)?.gameObject; // Runs once the first time the scene is played after the visualisation is created if (handle != null) { ConvertToLinearJointDrive(handle, axisDirection, isMax); } // Config LinearJointEvents Transform linerJoint = axis.transform.Find(handleName + " " + linearJointSuffix); Transform interactable = RecursiveFindChild(linerJoint, "Interactions.Interactable"); LinearDriveFacade linerJointFacade = linerJoint.GetComponent <LinearDriveFacade>(); LinkGrabEvent(linerJointFacade, interactable); LinkScalingEvent(linerJointFacade, axisDirection, isMax); }