| | 1 | | using System.Collections; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using UnityEngine; |
| | 4 | |
|
| | 5 | | public class BIWGizmosRotate : BIWGizmos |
| | 6 | | { |
| | 7 | | internal Plane raycastPlane; |
| | 8 | |
|
| 12 | 9 | | public override void SetSnapFactor(BIWGizmosController.SnapInfo snapInfo) { snapFactor = snapInfo.rotation; } |
| | 10 | |
|
| | 11 | | public override float TransformEntity(Transform entityTransform, BIWGizmosAxis axis, float axisValue) |
| | 12 | | { |
| 1 | 13 | | Space space = worldOrientedGizmos ? Space.World : Space.Self; |
| 1 | 14 | | Vector3 rotationVector = activeAxis.transform.forward; |
| | 15 | |
|
| 1 | 16 | | float amount = axisValue * Mathf.Rad2Deg; |
| 1 | 17 | | entityTransform.Rotate(rotationVector, amount, space); |
| 1 | 18 | | return amount; |
| | 19 | | } |
| | 20 | |
|
| | 21 | | public override void OnBeginDrag(BIWGizmosAxis axis, Transform entityTransform) |
| | 22 | | { |
| 1 | 23 | | base.OnBeginDrag(axis, entityTransform); |
| 1 | 24 | | raycastPlane = new Plane(activeAxis.transform.forward, transform.position); |
| 1 | 25 | | } |
| | 26 | |
|
| | 27 | | public override bool RaycastHit(Ray ray, out Vector3 hitPoint) |
| | 28 | | { |
| 0 | 29 | | float raycastHitDistance = 0.0f; |
| | 30 | |
|
| 0 | 31 | | if (raycastPlane.Raycast(ray, out raycastHitDistance)) |
| | 32 | | { |
| 0 | 33 | | hitPoint = ray.GetPoint(raycastHitDistance); |
| 0 | 34 | | return true; |
| | 35 | | } |
| 0 | 36 | | hitPoint = Vector3.zero; |
| 0 | 37 | | return false; |
| | 38 | | } |
| | 39 | |
|
| | 40 | | internal override float GetHitPointToAxisValue(BIWGizmosAxis axis, Vector3 hitPoint, Vector2 mousePosition) |
| | 41 | | { |
| 1 | 42 | | Vector3 hitDir = (hitPoint - transform.position).normalized; |
| 1 | 43 | | return Vector3.SignedAngle(axis.transform.up, hitDir, axis.transform.forward) * Mathf.Deg2Rad; |
| | 44 | | } |
| | 45 | |
|
| 2 | 46 | | internal override void SetPreviousAxisValue(float axisValue, float transformValue) { previousAxisValue = axisValue; |
| | 47 | | } |