//////////////////////////////////////////////////////////////////////// private void CheckSelection() { // Send a ray and find if anything is being selected. Ray ray = UnityUtilities.GenerateCameraRay(); if (Physics.Raycast(ray.origin, ray.direction, out this.hitGaze)) { #if DEBUG2 Debug.Log("Interaction Manager: Gaze hit gameObject: " + this.hit.transform.gameObject.name); #endif this.flagHitGaze = true; } else { this.flagHitGaze = false; // If nothing hit - reset history. } ray = UnityUtilities.GenerateSelectionRay(); if (Physics.Raycast(ray.origin, ray.direction, out this.hitSelect)) { #if DEBUG2 Debug.Log("Interaction Manager: Selection hit gameObject: " + this.hit.transform.gameObject.name); #endif this.flagHitSelect = true; } else { this.flagHitSelect = false; // If nothing hit - reset history. } }
private Vector3 CurrentProjectedPlanePoint(out bool _flagHit) { Ray cameraMouseRay = UnityUtilities.GenerateSelectionRay(); //Camera.main.ScreenPointToRay(Input.mousePosition); // NB! Isn't it the same as mouse Ray if (this.activeMovable.orientationPlane.Raycast(cameraMouseRay, out float rayDistance)) { _flagHit = true; return(cameraMouseRay.GetPoint(rayDistance)); } _flagHit = false; return(Vector3.zero); }
public static Ray GenerateSelectionRay() { #if WINDOWS_UWP return(UnityUtilities.GenerateCameraRay()); #else // If a mouse present - generate mouse ray, else - camera ray. if (Input.touchCount > 0) { return(UnityUtilities.GenerateTouchRay()); } else //if (Input.GetMouseButton(0)) // Special case for editor - use mouse but only if pressed { return(UnityUtilities.GenerateMouseRay()); } //else // return UnityUtilities.GenerateCameraRay(); #endif }
// float dist; // Transform target; // GameObject Z; // public Transform camTransform; // bool open; // Unity Functions. void Update() { Ray mouseRay = UnityUtilities.GenerateMouseRay(); RaycastHit hit; if (Input.GetMouseButtonDown(0)) { if (Physics.Raycast(mouseRay.origin, mouseRay.direction, out hit)) { gObj = hit.transform.gameObject; m0 = hit.transform.position - hit.point; // dist = hit.transform.position.y - hit.point.y; // Debug.Log(gObj.tag); if ((gObj.tag == "CPlaneXY") || (gObj.tag == "Point3DPlaneXY")) { gObj = gObj.transform.parent.parent.gameObject; objPlane = new Plane(gObj.transform.up, gObj.transform.position); xyMove = true; rotationMode = false; zMove = false; } else if (gObj.tag == "CPlaneXYR") { gObj = gObj.transform.parent.parent.gameObject; objPlane = new Plane(gObj.transform.up, gObj.transform.position); xyMove = false; rotationMode = true; zMove = false; Ray mRay = Camera.main.ScreenPointToRay(Input.mousePosition); if (objPlane.Raycast(mRay, out float rayDistance)) { r0 = mRay.GetPoint(rayDistance) - gObj.transform.position; } } else if (gObj.tag == "CPlaneZ") { gObj = gObj.transform.parent.parent.gameObject; objPlane = new Plane(Camera.main.transform.forward, gObj.transform.position); xyMove = false; rotationMode = false; zMove = true; } else if (gObj.tag == "Point3DToggle") { gObj.GetComponentInParent <Point3DController>().ToggleState(); } else { zMove = false; rotationMode = false; xyMove = false; gObj = null; } } } else if (Input.GetMouseButton(0) && gObj) { Ray mRay = Camera.main.ScreenPointToRay(Input.mousePosition); if (objPlane.Raycast(mRay, out float rayDistance)) { if (xyMove) { float currentZ = gObj.transform.position.y; gObj.transform.position = mRay.GetPoint(rayDistance) + m0; gObj.transform.position = new Vector3(gObj.transform.position.x, currentZ, gObj.transform.position.z); } else if (rotationMode) { Vector3 r = mRay.GetPoint(rayDistance) - gObj.transform.position; Vector3 rt = Quaternion.AngleAxis(1, objPlane.normal) * r0; float a1 = Vector3.Angle(r0, r); float a2 = Vector3.Angle(rt, r); if (a2 > a1) { a1 *= -1; } gObj.transform.RotateAroundLocal(objPlane.normal, Mathf.Deg2Rad * a1); r0 = r; } else if (zMove) { float currentX = gObj.transform.position.x; float currentY = gObj.transform.position.z; gObj.transform.position = mRay.GetPoint(rayDistance) + m0; gObj.transform.position = new Vector3(currentX, gObj.transform.position.y, currentY); } } } else if (Input.GetMouseButtonUp(0) && gObj) { zMove = false; rotationMode = false; xyMove = false; gObj = null; } }