示例#1
0
        /// <summary>
        /// On GUI
        /// </summary>
        public void OnGUI()
        {
            Handles.color = Color.yellow;
            Handles.DrawDottedLine(lightPosition, anchorPosition, 2f);

            anchorPosition = Handles.PositionHandle(anchorPosition, Quaternion.identity);
        }
示例#2
0
        public static void DrawDottedLineWithShadow(Color shadowColor, Vector2 screenOffset, Vector3 p1, Vector3 p2, float screenSpaceSize)
        {
            Camera current = Camera.current;

            if ((current != null) && (Event.current.type == EventType.Repaint))
            {
                Color color = Handles.color;
                shadowColor.a *= color.a;
                Handles.color  = shadowColor;
                Handles.DrawDottedLine(current.ScreenToWorldPoint(current.WorldToScreenPoint(p1) + screenOffset), current.ScreenToWorldPoint(current.WorldToScreenPoint(p2) + screenOffset), screenSpaceSize);
                Handles.color = color;
                Handles.DrawDottedLine(p1, p2, screenSpaceSize);
            }
        }
示例#3
0
        /// <summary>
        /// On GUI
        /// </summary>
        public void OnGUI()
        {
            Handles.color = Color.yellow;
            Handles.DrawDottedLine(lightPosition, anchorPosition, 2f);

            // Orient the handle rotation depending on the editor pivot rotation mode
            var handleRotation = Quaternion.identity;

            if (Tools.pivotRotation == PivotRotation.Local && target != null)
            {
                handleRotation = target.transform.rotation;
            }

            anchorPosition = Handles.PositionHandle(anchorPosition, handleRotation);
        }
        public void OnGUI(Rect windowRect, float pixelTime)
        {
            float   fixedWidth  = this.m_Style.fixedWidth;
            float   fixedHeight = this.m_Style.fixedHeight;
            Vector2 vector      = new Vector2(pixelTime, windowRect.yMin);

            TimeCursorManipulator.Alignment alignment = this.alignment;
            if (alignment != TimeCursorManipulator.Alignment.Center)
            {
                if (alignment != TimeCursorManipulator.Alignment.Left)
                {
                    if (alignment == TimeCursorManipulator.Alignment.Right)
                    {
                        this.rect = new Rect(vector.x, vector.y, fixedWidth, fixedHeight);
                    }
                }
                else
                {
                    this.rect = new Rect(vector.x - fixedWidth, vector.y, fixedWidth, fixedHeight);
                }
            }
            else
            {
                this.rect = new Rect(vector.x - fixedWidth / 2f, vector.y, fixedWidth, fixedHeight);
            }
            Vector3 p  = new Vector3(vector.x, vector.y + fixedHeight, 0f);
            Vector3 p2 = new Vector3(vector.x, windowRect.height, 0f);

            if (this.drawLine)
            {
                Handles.color = this.lineColor;
                if (this.dottedLine)
                {
                    Handles.DrawDottedLine(p, p2, 5f);
                }
                else
                {
                    Handles.DrawLine(p, p2);
                }
            }
            if (this.drawHead)
            {
                Color color = GUI.color;
                GUI.color = this.headColor;
                GUI.Box(this.rect, GUIContent.none, this.m_Style);
                GUI.color = color;
            }
        }
示例#5
0
        private void ShowPrismaticLimits(ArticulationBody body, ArticulationBody parentBody, Matrix4x4 parentAnchorSpace)
        {
            // if prismatic and unlocked - nothing to visualise
            if (body.linearLockX == ArticulationDofLock.FreeMotion || body.linearLockY == ArticulationDofLock.FreeMotion || body.linearLockZ == ArticulationDofLock.FreeMotion)
            {
                return;
            }

            float dashSize = 5;

            // compute the primary axis of the prismatic
            Vector3           primaryAxis = Vector3.zero;
            ArticulationDrive drive       = body.xDrive;

            if (body.linearLockX == ArticulationDofLock.LimitedMotion)
            {
                primaryAxis = Vector3.right;
                drive       = body.xDrive;
            }
            else if (body.linearLockY == ArticulationDofLock.LimitedMotion)
            {
                primaryAxis = Vector3.up;
                drive       = body.yDrive;
            }
            else if (body.linearLockZ == ArticulationDofLock.LimitedMotion)
            {
                primaryAxis = Vector3.forward;
                drive       = body.zDrive;
            }

            // now show the valid movement along the axis as well as limits
            using (new Handles.DrawingScope(parentAnchorSpace))
            {
                Vector3 lowerPoint = primaryAxis * drive.lowerLimit;
                Vector3 upperPoint = primaryAxis * drive.upperLimit;

                Quaternion orientation = Quaternion.LookRotation(primaryAxis);

                Handles.color = Color.red;
                Handles.CylinderHandleCap(0, lowerPoint, orientation, CapScale, EventType.Repaint);

                Handles.color = Color.green;
                Handles.CylinderHandleCap(0, upperPoint, orientation, CapScale, EventType.Repaint);

                Handles.color = Color.white;
                Handles.DrawDottedLine(lowerPoint, upperPoint, dashSize);
            }
        }
示例#6
0
        public static void DrawDottedLineWithShadow(Color shadowColor, Vector2 screenOffset, Vector3 p1, Vector3 p2, float screenSpaceSize)
        {
            Camera current = Camera.current;

            if (!(bool)((Object)current) || Event.current.type != EventType.Repaint)
            {
                return;
            }
            Color color = Handles.color;

            shadowColor.a = shadowColor.a * color.a;
            Handles.color = shadowColor;
            Handles.DrawDottedLine(current.ScreenToWorldPoint(current.WorldToScreenPoint(p1) + (Vector3)screenOffset), current.ScreenToWorldPoint(current.WorldToScreenPoint(p2) + (Vector3)screenOffset), screenSpaceSize);
            Handles.color = color;
            Handles.DrawDottedLine(p1, p2, screenSpaceSize);
        }
示例#7
0
        public void OnGUI(Rect windowRect, float pixelTime)
        {
            float widgetWidth  = m_Style.fixedWidth;
            float widgetHeight = m_Style.fixedHeight;

            Vector2 windowCoordinate = new Vector2(pixelTime, windowRect.yMin);

            switch (alignment)
            {
            case Alignment.Center:
                rect = new Rect((windowCoordinate.x - widgetWidth / 2.0f), windowCoordinate.y, widgetWidth, widgetHeight);
                break;

            case Alignment.Left:
                rect = new Rect(windowCoordinate.x - widgetWidth, windowCoordinate.y, widgetWidth, widgetHeight);
                break;

            case Alignment.Right:
                rect = new Rect(windowCoordinate.x, windowCoordinate.y, widgetWidth, widgetHeight);
                break;
            }

            Vector3 p1 = new Vector3(windowCoordinate.x, windowCoordinate.y + widgetHeight, 0.0f);
            Vector3 p2 = new Vector3(windowCoordinate.x, windowRect.height, 0.0f);

            if (drawLine)
            {
                Handles.color = lineColor;
                if (dottedLine)
                {
                    Handles.DrawDottedLine(p1, p2, 5.0f);
                }
                else
                {
                    Handles.DrawLine(p1, p2);
                }
            }

            if (drawHead)
            {
                Color c = GUI.color;
                GUI.color = headColor;
                GUI.Box(rect, GUIContent.none, m_Style);
                GUI.color = c;
            }
        }
        private static void DrawSideArc(PlatformEffector2D effector)
        {
            // Calculate the surface angle in local-space.
            var rotation  = -Mathf.Deg2Rad * (90.0f + effector.rotationalOffset);
            var localSide = effector.transform.TransformVector(new Vector3(Mathf.Sin(rotation), Mathf.Cos(rotation), 0.0f)).normalized;

            // If the transform has created a degenerate local then we cannot draw the gizmo!
            if (localSide.sqrMagnitude < Mathf.Epsilon)
            {
                return;
            }

            // Calculate the side angles.
            var sideAngleLeft  = Mathf.Atan2(localSide.x, localSide.y);
            var sideAngleRight = sideAngleLeft + Mathf.PI;

            // Fetch the side arc.
            var sideArc            = Mathf.Clamp(effector.sideArc, 0.5f, 180.0f);
            var halfSideArcRadians = sideArc * 0.5f * Mathf.Deg2Rad;

            var fromAngleLeft  = new Vector3(Mathf.Sin(sideAngleLeft - halfSideArcRadians), Mathf.Cos(sideAngleLeft - halfSideArcRadians), 0.0f);
            var toAngleLeft    = new Vector3(Mathf.Sin(sideAngleLeft + halfSideArcRadians), Mathf.Cos(sideAngleLeft + halfSideArcRadians), 0.0f);
            var fromAngleRight = new Vector3(Mathf.Sin(sideAngleRight - halfSideArcRadians), Mathf.Cos(sideAngleRight - halfSideArcRadians), 0.0f);
            var toAngleRight   = new Vector3(Mathf.Sin(sideAngleRight + halfSideArcRadians), Mathf.Cos(sideAngleRight + halfSideArcRadians), 0.0f);

            // Fetch all the effector-collider bounds.
            foreach (var collider in effector.gameObject.GetComponents <Collider2D>().Where(collider => collider.enabled && collider.usedByEffector))
            {
                var center    = collider.bounds.center;
                var arcRadius = HandleUtility.GetHandleSize(center) * 0.8f;

                // arc background
                Handles.color = new Color(0, 1, 0.7f, 0.07f);
                Handles.DrawSolidArc(center, Vector3.back, fromAngleLeft, sideArc, arcRadius);
                Handles.DrawSolidArc(center, Vector3.back, fromAngleRight, sideArc, arcRadius);

                // arc frame
                Handles.color = new Color(0, 1, 0.7f, 0.7f);
                Handles.DrawWireArc(center, Vector3.back, fromAngleLeft, sideArc, arcRadius);
                Handles.DrawWireArc(center, Vector3.back, fromAngleRight, sideArc, arcRadius);
                Handles.DrawDottedLine(center, center + fromAngleLeft * arcRadius, 5.0f);
                Handles.DrawDottedLine(center, center + toAngleLeft * arcRadius, 5.0f);
                Handles.DrawDottedLine(center, center + fromAngleRight * arcRadius, 5.0f);
                Handles.DrawDottedLine(center, center + toAngleRight * arcRadius, 5.0f);
            }
        }
        public void OnGUI(Rect windowRect, float pixelTime)
        {
            float   fixedWidth  = this.m_Style.fixedWidth;
            float   fixedHeight = this.m_Style.fixedHeight;
            Vector2 vector      = new Vector2(pixelTime, windowRect.yMin);

            switch (this.alignment)
            {
            case Alignment.Center:
                base.rect = new Rect(vector.x - (fixedWidth / 2f), vector.y, fixedWidth, fixedHeight);
                break;

            case Alignment.Left:
                base.rect = new Rect(vector.x - fixedWidth, vector.y, fixedWidth, fixedHeight);
                break;

            case Alignment.Right:
                base.rect = new Rect(vector.x, vector.y, fixedWidth, fixedHeight);
                break;
            }
            Vector3 vector2 = new Vector3(vector.x, vector.y + fixedHeight, 0f);
            Vector3 vector3 = new Vector3(vector.x, windowRect.height, 0f);

            if (this.drawLine)
            {
                Handles.color = this.lineColor;
                if (this.dottedLine)
                {
                    Handles.DrawDottedLine(vector2, vector3, 5f);
                }
                else
                {
                    Handles.DrawLine(vector2, vector3);
                }
            }
            if (this.drawHead)
            {
                Color color = GUI.color;
                GUI.color = this.headColor;
                GUI.Box(base.rect, GUIContent.none, this.m_Style);
                GUI.color = color;
            }
        }
示例#10
0
        public void OnSceneGUI()
        {
            if (!target)
            {
                return;
            }
            var targetJoint2D = (TargetJoint2D)target;

            // Ignore disabled joint.
            if (!targetJoint2D.enabled)
            {
                return;
            }

            // Fetch the anchor/target.
            var jointAnchor = TransformPoint(targetJoint2D.transform, targetJoint2D.anchor);
            var jointTarget = (Vector3)targetJoint2D.target;

            // Draw a line between the bodies.
            Handles.color = Color.green;
            Handles.DrawDottedLine(jointAnchor, jointTarget, 5.0f);

            // Draw the anchor point.
            if (HandleAnchor(ref jointAnchor, false))
            {
                Undo.RecordObject(targetJoint2D, "Move Anchor");
                targetJoint2D.anchor = InverseTransformPoint(targetJoint2D.transform, jointAnchor);
            }

            // Draw the target point.
            var targetScale = HandleUtility.GetHandleSize(jointTarget) * 0.3f;
            var horzTarget  = Vector3.left * targetScale;
            var vertTarget  = Vector3.up * targetScale;

            DrawAALine(jointTarget - horzTarget, jointTarget + horzTarget);
            DrawAALine(jointTarget - vertTarget, jointTarget + vertTarget);
            if (HandleAnchor(ref jointTarget, true))
            {
                Undo.RecordObject(targetJoint2D, "Move Target");
                targetJoint2D.target = jointTarget;
            }
        }
        private static void DrawSurfaceArc(PlatformEffector2D effector)
        {
            float num  = 0.0174532924f * (effector.surfaceArc * 0.5f + effector.transform.eulerAngles.z);
            float num2 = Mathf.Clamp(effector.surfaceArc, 0.5f, 360f);
            float num3 = num2 * 0.0174532924f;

            foreach (Collider2D current in from collider in effector.gameObject.GetComponents <Collider2D>()
                     where collider.enabled && collider.usedByEffector
                     select collider)
            {
                Vector3 center     = current.bounds.center;
                float   handleSize = HandleUtility.GetHandleSize(center);
                Vector3 vector     = new Vector3(-Mathf.Sin(num), Mathf.Cos(num), 0f);
                Vector3 a          = new Vector3(-Mathf.Sin(num - num3), Mathf.Cos(num - num3), 0f);
                Handles.color = new Color(0f, 1f, 1f, 0.03f);
                Handles.DrawSolidArc(center, Vector3.back, vector, num2, handleSize);
                Handles.color = new Color(0f, 1f, 1f, 0.7f);
                Handles.DrawWireArc(center, Vector3.back, vector, num2, handleSize);
                Handles.DrawDottedLine(center, center + vector * handleSize, 5f);
                Handles.DrawDottedLine(center, center + a * handleSize, 5f);
            }
        }
        public static void DrawDottedLineWithShadow(Color shadowColor, Vector2 screenOffset, Vector3 p1, Vector3 p2, float screenSpaceSize)
        {
            Camera cam = Camera.current;

            if (!cam || Event.current.type != EventType.Repaint)
            {
                return;
            }

            Color oldColor = Handles.color;

            // shadow
            shadowColor.a = shadowColor.a * oldColor.a;
            Handles.color = shadowColor;
            Handles.DrawDottedLine(
                cam.ScreenToWorldPoint(cam.WorldToScreenPoint(p1) + (Vector3)screenOffset),
                cam.ScreenToWorldPoint(cam.WorldToScreenPoint(p2) + (Vector3)screenOffset), screenSpaceSize);

            // line itself
            Handles.color = oldColor;
            Handles.DrawDottedLine(p1, p2, screenSpaceSize);
        }
示例#13
0
        private void DrawLimitedPrismatic(ArticulationBody body, Vector3 primaryAxis, ArticulationDrive drive, Matrix4x4 parentAnchorSpace)
        {
            using (new Handles.DrawingScope(parentAnchorSpace))
            {
                Vector3 lowerPoint = primaryAxis * drive.lowerLimit;
                Vector3 upperPoint = primaryAxis * drive.upperLimit;

                Handles.DrawDottedLine(lowerPoint, upperPoint, DashSize);

                int idLower = GUIUtility.GetControlID(Handles.s_SliderHash, FocusType.Passive);
                int idUpper = GUIUtility.GetControlID(Handles.s_SliderHash, FocusType.Passive);

                EditorGUI.BeginChangeCheck();
                {
                    Handles.color = Handles.xAxisColor;
                    lowerPoint    = Handles.Slider(idLower, lowerPoint, primaryAxis, CapScale, prismaticHandleDrawFunction, 0);

                    Handles.color = Handles.yAxisColor;
                    upperPoint    = Handles.Slider(idUpper, upperPoint, primaryAxis, CapScale, prismaticHandleDrawFunction, 0);
                }
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(target, "Changing Articulation body parent anchor prismatic limits");
                    float newLowerLimit = drive.lowerLimit;
                    float newUpperLimit = drive.upperLimit;

                    // Disallow moving Lower limit past Upper limit and vice versa, based on which handle is being held down
                    if (GUIUtility.hotControl == idLower)
                    {
                        float directionLower = Mathf.Sign(lowerPoint.x + lowerPoint.y + lowerPoint.z);
                        newLowerLimit = lowerPoint.magnitude * directionLower;
                        if (newLowerLimit > drive.upperLimit)
                        {
                            newLowerLimit = drive.upperLimit;
                        }
                    }
                    else if (GUIUtility.hotControl == idUpper)
                    {
                        float directionUpper = Mathf.Sign(upperPoint.x + upperPoint.y + upperPoint.z);
                        newUpperLimit = upperPoint.magnitude * directionUpper;
                        if (newUpperLimit < drive.lowerLimit)
                        {
                            newUpperLimit = drive.lowerLimit;
                        }
                    }

                    ArticulationDrive tempDrive = SetDriveLimits(drive, newLowerLimit, newUpperLimit);

                    if (body.linearLockX == ArticulationDofLock.LimitedMotion)
                    {
                        body.xDrive = tempDrive;
                    }
                    else if (body.linearLockY == ArticulationDofLock.LimitedMotion)
                    {
                        body.yDrive = tempDrive;
                    }
                    else if (body.linearLockZ == ArticulationDofLock.LimitedMotion)
                    {
                        body.zDrive = tempDrive;
                    }
                }
            }
        }