| | 1 | | using UnityEngine; |
| | 2 | |
|
| | 3 | | namespace Builder.Gizmos |
| | 4 | | { |
| | 5 | | public class DCLBuilderTranslateGizmo : DCLBuilderGizmo |
| | 6 | | { |
| 14 | 7 | | public override void SetSnapFactor(DCLBuilderGizmoManager.SnapInfo snapInfo) { snapFactor = snapInfo.position; } |
| | 8 | |
|
| | 9 | | public override float TransformEntity(Transform entityTransform, DCLBuilderGizmoAxis axis, float axisValue) |
| | 10 | | { |
| 0 | 11 | | Vector3 initialEntityPosition = entityTransform.position; |
| 0 | 12 | | if (snapFactor > 0) |
| 0 | 13 | | initialEntityPosition = GetPositionRoundedToSnapFactor(entityTransform.position, axisValue); |
| | 14 | |
|
| 0 | 15 | | Vector3 move = activeAxis.transform.forward * axisValue; |
| 0 | 16 | | Vector3 position = initialEntityPosition + move; |
| | 17 | |
|
| 0 | 18 | | entityTransform.position = position; |
| | 19 | |
|
| 0 | 20 | | return axisValue; |
| | 21 | | } |
| | 22 | |
|
| | 23 | | private Vector3 GetPositionRoundedToSnapFactor(Vector3 position, float axisValue) |
| | 24 | | { |
| 0 | 25 | | Vector3 activeAxisVector = GetActiveAxisVector(); |
| | 26 | |
|
| 0 | 27 | | position = new Vector3( |
| | 28 | | activeAxisVector == Vector3.right ? (axisValue >= 0 ? Mathf.Floor(position.x / snapFactor) : Mathf.Ceil( |
| | 29 | | activeAxisVector == Vector3.up ? (axisValue >= 0 ? Mathf.Floor(position.y / snapFactor) : Mathf.Ceil(pos |
| | 30 | | activeAxisVector == Vector3.back ? (axisValue >= 0 ? Mathf.Floor(position.z / snapFactor) : Mathf.Ceil(p |
| | 31 | |
|
| 0 | 32 | | return position; |
| | 33 | | } |
| | 34 | | } |
| | 35 | | } |