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