void Update() { if (TargetManager.Instance.Target != null) { // get flower controller MainController mc = Camera.main.GetComponent <MainController>(); SBController sbc = mc.surfaceBookPlaceholder.GetComponent <SBController>(); FlowerController fc = sbc.flowerBox.GetComponent <FlowerController>(); // set manipulator position Vector3 pos = sbc.flowerBox.transform.position; pos.y += fc.FlowerBound.size.y / 2; gameObject.transform.position = pos; // scale by target bound Vector3 scale = Vector3.Scale(sbc.flowerBox.transform.localScale, fc.FlowerBound.size); gameObject.transform.localScale = scale; // rotation Quaternion rotation = sbc.flowerBox.transform.localRotation; rotation.x = 0; rotation.z = 0; gameObject.transform.localRotation = rotation; } }
void OnSelect() { // get flower controller MainController mc = Camera.main.GetComponent <MainController>(); SBController sbc = mc.surfaceBookPlaceholder.GetComponent <SBController>(); FlowerController fc = sbc.flowerBox.GetComponent <FlowerController>(); // axis is in world space and not transformed, so we need transform it // with camera y roation first, then convert it to flower space Quaternion axisRotate = Quaternion.Euler(new Vector3(0, Camera.main.transform.localRotation.eulerAngles.y, 0)); Vector3 globalPoint = axisRotate * axis; globalPoint += sbc.flowerBox.transform.position; Vector3 localAxis = sbc.flowerBox.transform.InverseTransformPoint(globalPoint); // calculate rotation by local axis Quaternion startRotation = sbc.flowerBox.transform.localRotation; Quaternion endRotation = startRotation * Quaternion.AngleAxis(angle, localAxis); // call flower controller method fc.Rotate(startRotation, endRotation); // rotate fixed duplication also // neobox uses right-hand coordinate fc.RotateFixedDup(axis, -angle); }
public void Print() { // play start animation MainController mc = Camera.main.GetComponent <MainController>(); SBController sbc = mc.surfaceBookPlaceholder.GetComponent <SBController>(); FlowerController fc = sbc.flowerBox.GetComponent <FlowerController>(); fc.PlayPrintAnimation(); }
void OnDestroy() { // remove self from delegate list MainController mc = Camera.main.GetComponent <MainController>(); SBController sbc = mc.surfaceBookPlaceholder.GetComponent <SBController>(); FlowerController fc = sbc.flowerBox.GetComponent <FlowerController>(); fc.PrintAnimationEnd -= NeoboxController_PrintAnimationEnd; }
private void MainController_onPlacingEnd() { // place switch (state) { case OpState.LOCATE_SURFACE_BOOK: { // fade out body PlaceholderController pc = surfaceBookPlaceholder.GetComponent <PlaceholderController>(); pc.FadeOutBody(); // flag IsSBLocated = true; // to idle state SetState(OpState.IDLE); break; } case OpState.LOCATE_NEOBOX: { // fade out body PlaceholderController pc = neoboxPlaceholder.GetComponent <PlaceholderController>(); pc.FadeOutBody(); // flag IsNeoboxLocated = true; // to idle state SetState(OpState.IDLE); break; } } // if end, hide locate panel if (IsSBLocated && IsNeoboxLocated) { // remove TapToPlace to disable placing function Destroy(surfaceBookPlaceholder.GetComponent <TapToPlace>()); // remove TapToPlace to disable placing function Destroy(neoboxPlaceholder.GetComponent <TapToPlace>()); // enable grow button SBController sbc = surfaceBookPlaceholder.GetComponent <SBController>(); sbc.EnableGrowButton(); // hide locate panel locatePanel.gameObject.SetActive(false); } }
public void OnSelect() { // grow the flower MainController mc = Camera.main.GetComponent <MainController>(); GameObject sb = mc.surfaceBookPlaceholder; SBController sbc = sb.GetComponent <SBController>(); sbc.GrowFlower(); // hide button gameObject.SetActive(false); }
void OnSelect() { // get flower controller MainController mc = Camera.main.GetComponent <MainController>(); SBController sbc = mc.surfaceBookPlaceholder.GetComponent <SBController>(); FlowerController fc = sbc.flowerBox.GetComponent <FlowerController>(); // calculate start and end scale Vector3 startScale = sbc.flowerBox.transform.localScale; Vector3 endScale = startScale * percent; // call flower controller method fc.Scale(startScale, endScale); }
void Start() { // init hintTitle.text = ""; // place hint canvas RectTransform tf = hintCanvas.GetComponent <RectTransform>(); hintCanvas.transform.localPosition = new Vector3(0, tf.rect.height / 2 + 0.01f, 0); // listen print animation event MainController mc = Camera.main.GetComponent <MainController>(); SBController sbc = mc.surfaceBookPlaceholder.GetComponent <SBController>(); FlowerController fc = sbc.flowerBox.GetComponent <FlowerController>(); fc.PrintAnimationEnd += NeoboxController_PrintAnimationEnd; }
void Update() { if (IsManipulating) { // get surface book controller MainController mc = Camera.main.GetComponent <MainController>(); SBController sbc = mc.surfaceBookPlaceholder.GetComponent <SBController>(); // get hand delta Vector3 currentHandPosition = Camera.main.transform.InverseTransformPoint(GestureManager.Instance.ManipulationHandPosition); Vector3 handDelta = currentHandPosition - lastHandPosition; // save current position as last position lastHandPosition = currentHandPosition; // convert delta length to angle by a ratio float angle = handDelta.magnitude * 300 * (handDelta.x > 0 ? -1 : 1); // calculate rotation axis in flower space Vector3 globalPoint = Vector3.up + sbc.flowerBox.transform.position; Vector3 axis = sbc.flowerBox.transform.InverseTransformPoint(globalPoint); // calculate final rotation Quaternion startRotation = sbc.flowerBox.transform.localRotation; Quaternion endRotation = startRotation * Quaternion.AngleAxis(angle, axis); // If the object has an interpolator we should use it, otherwise just move the transform directly if (targetInterpolator != null) { targetInterpolator.SetTargetRotation(endRotation); } else { target.transform.localRotation = endRotation; } } }