public void OnBeginDrag(PointerEventData eventData) { ZPointerEventData pointerEventData = eventData as ZPointerEventData; if (pointerEventData == null || pointerEventData.button != PointerEventData.InputButton.Left) { return; } Pose pose = pointerEventData.Pointer.EndPointWorldPose; // Cache the initial grab state. this._initialGrabOffset = Quaternion.Inverse(this.transform.rotation) * (this.transform.position - pose.position); this._initialGrabRotation = Quaternion.Inverse(pose.rotation) * this.transform.rotation; // If the grabbable object has a rigidbody component, // mark it as kinematic during the grab. var rigidbody = this.GetComponent <Rigidbody>(); if (rigidbody != null) { this._isKinematic = rigidbody.isKinematic; rigidbody.isKinematic = true; } // Capture pointer events. pointerEventData.Pointer.CapturePointer(this.gameObject); }
public override void Raycast( PointerEventData eventData, List <RaycastResult> resultAppendList) { ZPointerEventData e = eventData as ZPointerEventData; if (e != null) { this.Raycast( e.Pointer.PointerRay, resultAppendList, float.PositiveInfinity, ~0); } else { base.Raycast(eventData, resultAppendList); } }
public void OnDrag(PointerEventData eventData) { ZPointerEventData pointerEventData = eventData as ZPointerEventData; if (pointerEventData == null || pointerEventData.button != PointerEventData.InputButton.Left) { return; } Pose pose = pointerEventData.Pointer.EndPointWorldPose; // Update the grab object's rotation. this.transform.rotation = pose.rotation * this._initialGrabRotation; // Update the grab object's position. this.transform.position = pose.position + (this.transform.rotation * this._initialGrabOffset); }
public void OnEndDrag(PointerEventData eventData) { ZPointerEventData pointerEventData = eventData as ZPointerEventData; if (pointerEventData == null || pointerEventData.button != PointerEventData.InputButton.Left) { return; } // Release the pointer. pointerEventData.Pointer.CapturePointer(null); // If the grabbable object has a rigidbody component, // restore its original isKinematic state. var rigidbody = this.GetComponent <Rigidbody>(); if (rigidbody != null) { rigidbody.isKinematic = this._isKinematic; } }
public void OnDrag(PointerEventData eventData) { ZPointerEventData pointerEventData = eventData as ZPointerEventData; if (pointerEventData == null || pointerEventData.button != PointerEventData.InputButton.Left) { return; } Pose pose = pointerEventData.Pointer.EndPointWorldPose; // commenting out rotation from the original draggable script // to maintain a fixed orientation relative to the drag plane // // Update the grab object's rotation. //this.transform.rotation = // pose.rotation * this._initialGrabRotation; // Update the grab object's position. this.transform.position = pose.position + (this.transform.rotation * this._initialGrabOffset); }