public DebugItem AddAxisLines(float length, float thickness, bool isBasic = true, Component relativeToComponent = null, GameObject relativeToGameObject = null) { GameObject parent = new GameObject(); parent.name = PREFIX + "axis lines"; var children = new List <GameObject>(); if (isBasic) { children.Add(GetNewBasicLine(new[] { new Vector3(0, 0, 0), new Vector3(length, 0, 0) }, thickness, UtilityUnity.ColorFromHex(AXISCOLOR_X), 0, 4, false, parent)); children.Add(GetNewBasicLine(new[] { new Vector3(0, 0, 0), new Vector3(0, length, 0) }, thickness, UtilityUnity.ColorFromHex(AXISCOLOR_Y), 0, 4, false, parent)); children.Add(GetNewBasicLine(new[] { new Vector3(0, 0, 0), new Vector3(0, 0, length) }, thickness, UtilityUnity.ColorFromHex(AXISCOLOR_Z), 0, 4, false, parent)); } else { children.Add(GetNewPipeLine(new Vector3(0, 0, 0), new Vector3(length, 0, 0), thickness, UtilityUnity.ColorFromHex(AXISCOLOR_X), parent)); children.Add(GetNewPipeLine(new Vector3(0, 0, 0), new Vector3(0, length, 0), thickness, UtilityUnity.ColorFromHex(AXISCOLOR_Y), parent)); children.Add(GetNewPipeLine(new Vector3(0, 0, 0), new Vector3(0, 0, length), thickness, UtilityUnity.ColorFromHex(AXISCOLOR_Z), parent)); } var retVal = new DebugItem(NextToken(), parent, children.ToArray(), new Vector3(), relativeToComponent, relativeToGameObject); AddItem(retVal); return(retVal); }
/// <summary> /// Orbits around a point that is OrbitRadius away. If they are holding in shift, it will /// fire a cone ray and orbit around what they are looking at /// </summary> /// <remarks> /// Got this here /// http://wiki.unity3d.com/index.php?title=MouseOrbitImproved#Code_C.23 /// </remarks> private void OrbitCamera(bool isRightDown, bool isShiftDown, float mouseX, float mouseY) { if (isRightDown) { float deltaTime = Math.Min(Time.deltaTime, MAXDELTA); _eulerX += mouseX * MouseSensitivity_Orbit * deltaTime; // the example multiplies this by orbit radius, but not Y _eulerY -= mouseY * MouseSensitivity_Orbit * deltaTime; _eulerY = UtilityMath.ClampAngle(_eulerY, MinAngle_Y, MaxAngle_Y); Quaternion rotation = Quaternion.Euler(_eulerY, _eulerX, 0); Vector3 lookAtPoint; float radius; if (_isLookAtPointSet) { lookAtPoint = _lookAtPoint; radius = (transform.position - lookAtPoint).magnitude; } else { lookAtPoint = transform.position + (transform.forward * OrbitRadius); radius = OrbitRadius; } if (isShiftDown && !_isLookAtPointSet) { Ray lookRay = new Ray(transform.position, transform.forward); var coneHits = UtilityUnity.ConeCastAll(lookRay, radius, MaxOrbitRadius, 12). Select(o => new { hit = o, //intersect = Math3D.GetClosestPoint_Line_Point(lookRay, o.point), // this finds the closest point on the look ray, perpendicular to the look ray intersect = Math3D.GetIntersection_Plane_Line(new Plane(lookRay.origin - o.point, o.point), lookRay), // this finds a point on the look ray, perpendicular to the cone match ray (using this because it gives a better indication of what is "closest". something that is closer to the camera, but higher angle from the look ray could project to be farther away than something that is lower angle, but slightly farther from the camera) }). Where(o => o.intersect != null). // it should never be null Select(o => new { o.hit, intersect = o.intersect.Value, distance = (o.intersect.Value - lookRay.origin).sqrMagnitude, }). ToArray(); if (coneHits.Length > 0) { var closest = coneHits. OrderBy(o => o.distance). First(); radius = (float)Math.Sqrt(closest.distance); lookAtPoint = closest.intersect; _lookAtPoint = lookAtPoint; _isLookAtPointSet = true; } } Vector3 negRadius = new Vector3(0.0f, 0.0f, -radius); Vector3 position = rotation * negRadius + lookAtPoint; transform.rotation = rotation; transform.position = position; } else { _isLookAtPointSet = false; } }