public TransformHandleParam(
     PositionHandleParam position,
     RotationHandleParam rotation,
     ScaleHandleParam scale,
     PositionHandleParam cameraAlignedPosition,
     RotationHandleParam cameraAlignedRotation,
     ScaleHandleParam cameraAlignedScale,
     PositionHandleParam localPosition,
     RotationHandleParam localRotation,
     ScaleHandleParam localScale,
     PositionHandleParam vertexSnappingPosition,
     RotationHandleParam vertexSnappingRotation,
     ScaleHandleParam vertexSnappingScale)
 {
     this.position = position;
     this.rotation = rotation;
     this.scale    = scale;
     this.cameraAlignedPosition  = cameraAlignedPosition;
     this.cameraAlignedRotation  = cameraAlignedRotation;
     this.cameraAlignedScale     = cameraAlignedScale;
     this.localPosition          = localPosition;
     this.localRotation          = localRotation;
     this.localScale             = localScale;
     this.vertexSnappingPosition = vertexSnappingPosition;
     this.vertexSnappingRotation = vertexSnappingRotation;
     this.vertexSnappingScale    = vertexSnappingScale;
 }
Example #2
0
        internal static Quaternion DoRotationHandle(RotationHandleIds ids, Quaternion rotation, Vector3 position, RotationHandleParam param)
        {
            var evt        = Event.current;
            var camForward = Handles.inverseMatrix.MultiplyVector(Camera.current != null ? Camera.current.transform.forward : Vector3.forward);

            var size     = HandleUtility.GetHandleSize(position);
            var temp     = color;
            var isStatic = (!Tools.s_Hidden && EditorApplication.isPlaying && GameObjectUtility.ContainsStatic(Selection.gameObjects));

            var isHot = ids.Has(GUIUtility.hotControl);

            // Draw freerotation first to give it the lowest priority
            if (!isStatic &&
                param.ShouldShow(RotationHandleParam.Handle.XYZ) &&
                (isHot && ids.xyz == GUIUtility.hotControl || !isHot))
            {
                color    = centerColor;
                rotation = UnityEditorInternal.FreeRotate.Do(ids.xyz, rotation, position, size * param.xyzSize, param.displayXYZCircle);
            }

            var radiusOfAxesHandles = -1f;

            for (var i = 0; i < 3; ++i)
            {
                if (!param.ShouldShow(i))
                {
                    continue;
                }

                var axisColor = GetColorByAxis(i);
                color = isStatic ? Color.Lerp(axisColor, staticColor, staticBlend) : axisColor;
                color = ToActiveColorSpace(color);
                var axisDir = GetAxisVector(i);

                var radius = size * param.axisSize[i];
                radiusOfAxesHandles = Mathf.Max(radius, radiusOfAxesHandles);

                rotation = UnityEditorInternal.Disc.Do(ids[i], rotation, position, rotation * axisDir, radius, true, SnapSettings.rotation, param.enableRayDrag, true, k_RotationPieColor);
            }

            if (radiusOfAxesHandles > 0 && evt.type == EventType.Repaint)
            {
                Handles.color = new Color(0, 0, 0, 0.2f);
                Handles.DrawWireDisc(position, camForward, radiusOfAxesHandles);
            }

            if (isHot && evt.type == EventType.Repaint)
            {
                color = ToActiveColorSpace(s_DisabledHandleColor);
                Handles.DrawWireDisc(position, camForward, size * param.axisSize[0]);
            }

            if (!isStatic &&
                param.ShouldShow(RotationHandleParam.Handle.CameraAxis) &&
                (isHot && ids.cameraAxis == GUIUtility.hotControl || !isHot))
            {
                color    = ToActiveColorSpace(centerColor);
                rotation = UnityEditorInternal.Disc.Do(ids.cameraAxis, rotation, position, camForward, size * param.cameraAxisSize, false, 0, param.enableRayDrag, true, k_RotationPieColor);
            }

            color = temp;
            return(rotation);
        }
            static RotationHandleParam CopyDefaultSize(RotationHandleParam r)
            {
                var d = RotationHandleParam.Default;

                return(new RotationHandleParam(r.handles, d.axisSize, d.xyzSize, d.cameraAxisSize, r.enableRayDrag, r.displayXYZCircle));
            }
 static RotationHandleParam RemoveHandles(RotationHandleParam r, RotationHandleParam.Handle handles)
 {
     return(new RotationHandleParam(r.handles & ~handles, r.axisSize, r.xyzSize, r.cameraAxisSize, r.enableRayDrag, r.displayXYZCircle));
 }
Example #5
0
        internal static Quaternion DoRotationHandle(RotationHandleIds ids, Quaternion rotation, Vector3 position, RotationHandleParam param)
        {
            var evt        = Event.current;
            var camForward = Handles.inverseMatrix.MultiplyVector(Camera.current != null ? Camera.current.transform.forward : Vector3.forward);

            var  size       = HandleUtility.GetHandleSize(position);
            var  temp       = color;
            bool isDisabled = !GUI.enabled;

            var isHot = ids.Has(GUIUtility.hotControl);

            VertexSnapping.HandleMouseMove(ids.xyz);

            // Draw free rotation first to give it the lowest priority
            if (!isDisabled &&
                param.ShouldShow(RotationHandleParam.Handle.XYZ) &&
                (ids.xyz == GUIUtility.hotControl || !isHot))
            {
                color    = new Color(0, 0, 0, 0.3f);
                rotation = UnityEditorInternal.FreeRotate.Do(ids.xyz, rotation, position, size * param.xyzSize, param.displayXYZCircle);
            }

            for (var i = 0; i < 3; ++i)
            {
                if (!param.ShouldShow(i))
                {
                    continue;
                }

                var axisColor = GetColorByAxis(i);
                color = isDisabled ? Color.Lerp(axisColor, staticColor, staticBlend) : axisColor;
                color = ToActiveColorSpace(color);
                var axisDir = GetAxisVector(i);

                var radius = size * param.axisSize[i];
                rotation = UnityEditorInternal.Disc.Do(ids[i], rotation, position, rotation * axisDir, radius, true, EditorSnapSettings.rotate, param.enableRayDrag, true, k_RotationPieColor);
            }

            // while dragging any rotation handles, draw a gray disc outline
            if (isHot && evt.type == EventType.Repaint)
            {
                color = ToActiveColorSpace(s_DisabledHandleColor);
                Handles.DrawWireDisc(position, camForward, size * param.axisSize[0], Handles.lineThickness);
            }

            if (!isDisabled &&
                param.ShouldShow(RotationHandleParam.Handle.CameraAxis) &&
                (ids.cameraAxis == GUIUtility.hotControl || !isHot))
            {
                color    = ToActiveColorSpace(centerColor);
                rotation = UnityEditorInternal.Disc.Do(ids.cameraAxis, rotation, position, camForward, size * param.cameraAxisSize, false, 0, param.enableRayDrag, true, k_RotationPieColor);
            }

            color = temp;
            return(rotation);
        }