public virtual void OnBeginDrag(DCLBuilderGizmoAxis axis, Transform entityTransform)
 {
     startDragging   = true;
     targetTransform = entityTransform;
     activeAxis      = axis;
     axis.SetColorHighlight();
 }
        public override void TransformEntity(Transform entityTransform, DCLBuilderGizmoAxis axis, float axisValue)
        {
            Vector3 scaleDirection = activeAxis.transform.forward;

            if (axis == axisProportionalScale)
            {
                scaleDirection = Vector3.one;
                float inputDirection = lastMousePosition.y - initialMousePosition.y;
                if (inputDirection < 0)
                {
                    scaleDirection = -Vector3.one;
                }
                initialMousePosition = lastMousePosition;
                initialHitPoint      = lastHitPoint;
            }
            else if (worldOrientedGizmos)
            {
                scaleDirection   = entityTransform.rotation * activeAxis.transform.forward;
                scaleDirection.x = Mathf.Abs(scaleDirection.x);
                scaleDirection.y = Mathf.Abs(scaleDirection.y);
                scaleDirection.z = Mathf.Abs(scaleDirection.z);
            }

            Vector3 newScale = entityTransform.localScale + scaleDirection * axisValue;

            if (Mathf.Abs(newScale.x) < MINIMUN_SCALE_ALLOWED || Mathf.Abs(newScale.y) < MINIMUN_SCALE_ALLOWED || Mathf.Abs(newScale.y) < MINIMUN_SCALE_ALLOWED)
            {
                newScale += scaleDirection * MINIMUN_SCALE_ALLOWED;
            }

            entityTransform.localScale = newScale;
        }
        protected virtual float GetHitPointToAxisValue(DCLBuilderGizmoAxis axis, Vector3 hitPoint, Vector2 mousePosition)
        {
            Vector3 dir  = (hitPoint - axis.transform.position).normalized;
            float   sign = Vector3.Angle(dir, axis.transform.forward) == 180 ? -1 : 1;

            return(Vector3.Distance(activeAxis.transform.position, hitPoint) * sign);
        }
        public override void TransformEntity(Transform entityTransform, DCLBuilderGizmoAxis axis, float axisValue)
        {
            Space   space          = worldOrientedGizmos ? Space.World : Space.Self;
            Vector3 rotationVector = activeAxis.transform.forward;

            entityTransform.Rotate(rotationVector, axisValue * Mathf.Rad2Deg, space);
        }
Exemple #5
0
        public override void TransformEntity(Transform entityTransform, DCLBuilderGizmoAxis axis, float axisValue)
        {
            Vector3 move     = activeAxis.transform.forward * axisValue;
            Vector3 position = entityTransform.position + move;

            entityTransform.position = position;
        }
        private Vector3 GetScaleDirection(Transform entityTransform, DCLBuilderGizmoAxis axis)
        {
            Vector3 scaleDirection = activeAxis.transform.forward;

            if (axis == axisProportionalScale)
            {
                scaleDirection = Vector3.one;
                float inputDirection = (lastMousePosition.x - initialMousePosition.x) + (lastMousePosition.y - initialMousePosition.y);
                if (inputDirection < 0)
                {
                    scaleDirection = -Vector3.one;
                }

                initialMousePosition = lastMousePosition;
                initialHitPoint      = lastHitPoint;
            }
            else if (worldOrientedGizmos)
            {
                scaleDirection   = entityTransform.rotation * activeAxis.transform.forward;
                scaleDirection.x = Mathf.Abs(scaleDirection.x);
                scaleDirection.y = Mathf.Abs(scaleDirection.y);
                scaleDirection.z = Mathf.Abs(scaleDirection.z);
            }

            return(scaleDirection);
        }
Exemple #7
0
        private void OnBeginDrag(DCLBuilderGizmoAxis hittedAxis)
        {
            isTransformingObject = true;
            activeGizmo          = hittedAxis.GetGizmo();
            activeGizmo.OnBeginDrag(hittedAxis, selectedEntitiesParent);

            OnGizmoTransformObjectStart?.Invoke(activeGizmo.GetGizmoType());
        }
Exemple #8
0
 private void SetAxisHover(DCLBuilderGizmoAxis axis)
 {
     if (hoveredAxis != null && hoveredAxis != axis)
     {
         hoveredAxis.SetColorDefault();
     }
     else if (axis != null)
     {
         axis.SetColorHighlight();
     }
     hoveredAxis = axis;
 }
Exemple #9
0
        private void CheckGizmoHover(Vector3 mousePosition)
        {
            RaycastHit hit;

            if (builderRaycast.RaycastToGizmos(mousePosition, out hit))
            {
                DCLBuilderGizmoAxis gizmoAxis = hit.collider.gameObject.GetComponent <DCLBuilderGizmoAxis>();
                SetAxisHover(gizmoAxis);
            }
            else
            {
                SetAxisHover(null);
            }
        }
 protected override float GetHitPointToAxisValue(DCLBuilderGizmoAxis axis, Vector3 hitPoint, Vector2 mousePosition)
 {
     if (axis == axisProportionalScale)
     {
         if (startDragging)
         {
             initialMousePosition = mousePosition;
             initialHitPoint      = hitPoint;
         }
         lastMousePosition = mousePosition;
         lastHitPoint      = hitPoint;
         return(Vector3.Distance(initialHitPoint, hitPoint));
     }
     return(axis.transform.InverseTransformPoint(hitPoint).z);
 }
        public override float TransformEntity(Transform entityTransform, DCLBuilderGizmoAxis axis, float axisValue)
        {
            Vector3 initialEntityPosition = entityTransform.position;

            if (snapFactor > 0)
            {
                initialEntityPosition = GetPositionRoundedToSnapFactor(entityTransform.position, axisValue);
            }

            Vector3 move     = activeAxis.transform.forward * axisValue;
            Vector3 position = initialEntityPosition + move;

            entityTransform.position = position;

            return(axisValue);
        }
        public override float TransformEntity(Transform entityTransform, DCLBuilderGizmoAxis axis, float axisValue)
        {
            Vector3 scaleDirection = GetScaleDirection(entityTransform, axis);

            // In order to avoid to make the scale of each selected entity dependent of the 'entityTransform' parent,
            // we temporally move all entities to the same position as 'entityTransform' before calculate the new scale.
            foreach (Transform entity in entityTransform)
            {
                entitiesOriginalPositions.Add(entity, entity.transform.position);
                entity.transform.position = entityTransform.position;
            }

            if (axis == axisProportionalScale)
            {
                // New scale calculation (for proportional scale gizmo)
                entityTransform.localScale = GetNewScale(entityTransform, axisValue, scaleDirection, false);
            }
            else
            {
                // New scale calculation (for XYZ-axis scale gizmo)
                foreach (var originalEntity in entitiesOriginalPositions)
                {
                    Transform entity = originalEntity.Key;
                    entity.transform.SetParent(null);
                    entity.localScale = GetNewScale(entity.transform, axisValue, scaleDirection, true);
                    entity.SetParent(entityTransform);
                }
            }

            // Once the new scale has been calculated, we restore the original positions of all the selected entities.
            foreach (var originalEntity in entitiesOriginalPositions)
            {
                Transform entity           = originalEntity.Key;
                Vector3   originalPosition = originalEntity.Value;

                entity.position = originalPosition;
            }

            entitiesOriginalPositions.Clear();

            return(axisValue);
        }
 public abstract float TransformEntity(Transform targetTransform, DCLBuilderGizmoAxis axis, float axisValue);
Exemple #14
0
 private void OnGizmosAxisPressed(DCLBuilderGizmoAxis pressedAxis)
 {
     OnBeginDrag(pressedAxis);
 }
        protected override float GetHitPointToAxisValue(DCLBuilderGizmoAxis axis, Vector3 hitPoint, Vector2 mousePosition)
        {
            Vector3 hitDir = (hitPoint - transform.position).normalized;

            return(Vector3.SignedAngle(axis.transform.up, hitDir, axis.transform.forward) * Mathf.Deg2Rad);
        }
 public override void OnBeginDrag(DCLBuilderGizmoAxis axis, Transform entityTransform)
 {
     base.OnBeginDrag(axis, entityTransform);
     raycastPlane = new Plane(activeAxis.transform.forward, transform.position);
 }