| | 1 | | using System.Collections; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using UnityEngine; |
| | 4 | |
|
| | 5 | | public class BIWTranslateGizmos : BIWGizmos |
| | 6 | | { |
| | 7 | | // Start is called before the first frame update |
| 198 | 8 | | public override void SetSnapFactor(BIWGizmosController.SnapInfo snapInfo) { snapFactor = snapInfo.position; } |
| | 9 | |
|
| | 10 | | public override float TransformEntity(Transform entityTransform, BIWGizmosAxis axis, float axisValue) |
| | 11 | | { |
| 1 | 12 | | Vector3 initialEntityPosition = entityTransform.position; |
| 1 | 13 | | if (snapFactor > 0) |
| 1 | 14 | | initialEntityPosition = GetPositionRoundedToSnapFactor(entityTransform.position, axisValue); |
| | 15 | |
|
| 1 | 16 | | Vector3 move = activeAxis.transform.forward * axisValue; |
| 1 | 17 | | Vector3 position = initialEntityPosition + move; |
| | 18 | |
|
| 1 | 19 | | entityTransform.position = position; |
| | 20 | |
|
| 1 | 21 | | return axisValue; |
| | 22 | | } |
| | 23 | |
|
| | 24 | | private Vector3 GetPositionRoundedToSnapFactor(Vector3 position, float axisValue) |
| | 25 | | { |
| 1 | 26 | | Vector3 activeAxisVector = GetActiveAxisVector(); |
| | 27 | |
|
| 1 | 28 | | position = new Vector3( |
| | 29 | | activeAxisVector == Vector3.right ? (axisValue >= 0 ? Mathf.Floor(position.x / snapFactor) : Mathf.Ceil(posi |
| | 30 | | activeAxisVector == Vector3.up ? (axisValue >= 0 ? Mathf.Floor(position.y / snapFactor) : Mathf.Ceil(positio |
| | 31 | | activeAxisVector == Vector3.back ? (axisValue >= 0 ? Mathf.Floor(position.z / snapFactor) : Mathf.Ceil(posit |
| | 32 | |
|
| 1 | 33 | | return position; |
| | 34 | | } |
| | 35 | | } |