Ejemplo n.º 1
0
        private void RenderAngleLimits
        (
            Vector2 origin,
            float lineLength,
            Vector2 pivotSpaceVector,
            AngleLimits angleLimits,
            Color limitColor
        )
        {
            Inspector3DRenderer.DrawArrow(origin, new Vector2(origin.x, origin.y + lineLength), Color.gray);

            System.Func <float, Vector2> getLimitEndPoint = degrees =>
            {
                var minRadians = Mathf.Deg2Rad * degrees;
                var offset     = new Vector2(Mathf.Sin(minRadians), Mathf.Cos(minRadians));
                return(origin + lineLength * offset);
            };

            if (!angleLimits.active)
            {
                limitColor = Color.grey;
            }
            var minPosition = getLimitEndPoint(angleLimits.min);

            Inspector3DRenderer.DrawArrow(origin, minPosition, limitColor);
            var maxPosition = getLimitEndPoint(angleLimits.max);

            Inspector3DRenderer.DrawArrow(origin, maxPosition, limitColor);

            if (Application.isPlaying)
            {
                Inspector3DRenderer.DrawArrow(origin, origin + lineLength * pivotSpaceVector, Color.white);
            }
        }
        // private

        private static AngleLimitSerializer AngleLimitsToSerializer(AngleLimits sourceLimits)
        {
            return(new AngleLimitSerializer
            {
                enabled = sourceLimits.active,
                min = sourceLimits.min,
                max = sourceLimits.max
            });
        }
Ejemplo n.º 3
0
 public void DrawAngleLimits(AngleLimits angleLimits, float drawScale)
 {
     if (angleLimits.active)
     {
         var pivot   = GetPivotTransform();
         var forward = -pivot.right;
         var side    = (angleLimits == yAngleLimits) ? -pivot.up : -pivot.forward;
         angleLimits.DrawLimits(transform.position, side, forward, drawScale);
     }
 }
        public void DrawGizmos(Color drawColor)
        {
            const int PointCount = 16;

            UnityEditor.Handles.color = drawColor;

            if (ringPoints == null || ringPoints.Length != PointCount)
            {
                ringPoints    = new Vector3[PointCount];
                endRingPoints = new Vector3[PointCount];
            }

            var worldRadius = transform.TransformDirection(radius, 0f, 0f).magnitude;

            var startCapOrigin = transform.position;
            var endCapOrigin   = transform.TransformPoint(0f, height, 0f);

            AngleLimits.DrawAngleLimit(startCapOrigin, transform.up, transform.forward, -180f, worldRadius);
            AngleLimits.DrawAngleLimit(startCapOrigin, transform.up, transform.right, -180f, worldRadius);
            AngleLimits.DrawAngleLimit(endCapOrigin, transform.up, transform.forward, 180f, worldRadius);
            AngleLimits.DrawAngleLimit(endCapOrigin, transform.up, transform.right, 180f, worldRadius);

            GetRingPoints(startCapOrigin, transform.right, transform.forward, worldRadius, ref ringPoints);
            var startToEnd = endCapOrigin - startCapOrigin;

            for (int pointIndex = 0; pointIndex < PointCount; pointIndex++)
            {
                endRingPoints[pointIndex] = ringPoints[pointIndex] + startToEnd;
            }

            for (int pointIndex = 1; pointIndex < PointCount; pointIndex++)
            {
                UnityEditor.Handles.DrawLine(ringPoints[pointIndex - 1], ringPoints[pointIndex]);
                UnityEditor.Handles.DrawLine(endRingPoints[pointIndex - 1], endRingPoints[pointIndex]);
            }

            for (int pointIndex = 0; pointIndex < PointCount; pointIndex++)
            {
                UnityEditor.Handles.DrawLine(ringPoints[pointIndex], endRingPoints[pointIndex]);
            }

            if (m_colliderDebugger != null)
            {
                m_colliderDebugger.DrawGizmosAndClear();
            }
        }
Ejemplo n.º 5
0
 public void CopyTo(AngleLimits target)
 {
     target.active = active;
     target.min    = min;
     target.max    = max;
 }