// Update is called once per frame void Update() { Vector2 pos = Vector2.zero; mySettings.RaycastToCanvasSpace(Camera.main.ScreenPointToRay(Input.mousePosition), out pos); this.transform.localPosition = pos; }
/// <summary> /// drag the transform along the mouse. We use raycast to determine its position on curved canvas. /// </summary> /// <param name="data"></param> public void OnDrag(PointerEventData data) { CurvedUISettings myCurvedCanvas = GetComponentInParent <CurvedUISettings>(); Ray ray3d = Camera.main.ScreenPointToRay(new Vector2(Screen.width / 2.0f, Screen.height / 2.0f)); if (CurvedUIInputModule.ControlMethod == CurvedUIInputModule.CUIControlMethod.MOUSE) { //position when using mouse ray3d = Camera.main.ScreenPointToRay(Input.mousePosition); } else if (CurvedUIInputModule.ControlMethod == CurvedUIInputModule.CUIControlMethod.GAZE) { //position when using gaze ray3d = Camera.main.ScreenPointToRay(new Vector2(Screen.width / 2.0f, Screen.height / 2.0f)); } //find a canvas underneath the pointer. RaycastHit hit; if (Physics.Raycast(ray3d, out hit)) { CurvedUISettings curvedCanvasUnderPointer = hit.collider.GetComponentInParent <CurvedUISettings>(); Vector2 newPos = Vector2.zero; if (curvedCanvasUnderPointer != null) { //change canvas if we moved it to the other one. if (curvedCanvasUnderPointer != myCurvedCanvas) { //move this panel to the other canvas and resets its position. this.transform.SetParent(curvedCanvasUnderPointer.transform); this.transform.ResetTransform(); //force the panel and each of its children to update their parent CurvedUISettings. //This will ensure they will rebuild with proper angle and stuff. foreach (CurvedUIVertexEffect eff in GetComponentsInChildren <CurvedUIVertexEffect>()) { eff.FindParentSettings(true); } } //find the raycast position in flat canvas units. curvedCanvasUnderPointer.RaycastToCanvasSpace(ray3d, out newPos); //set the new position of the panel. Add the drag point so we're still holding the object in the same spot. (transform as RectTransform).localPosition = newPos + dragPoint; } } }
#pragma warning restore 0649 // Update is called once per frame void Update() { Vector3 worldSpaceMousePosInWorldSpace = MouseCanvas.CanvasToCurvedCanvas(WorldSpaceMouse.localPosition); Ray ControllerRay = new Ray(Camera.main.transform.position, worldSpaceMousePosInWorldSpace - Camera.main.transform.position); CurvedUIInputModule.CustomControllerRay = ControllerRay; if (Input.GetButton("Fire2")) { Vector2 newPos = Vector2.zero; MouseCanvas.RaycastToCanvasSpace(new Ray(Camera.main.transform.position, Camera.main.transform.forward), out newPos); CurvedUIInputModule.Instance.WorldSpaceMouseInCanvasSpace = newPos; } Debug.DrawRay(ControllerRay.GetPoint(0), ControllerRay.direction * 1000, Color.cyan); }