コード例 #1
0
        static void SelectedGizmos(Probe probe, GizmoType gizmoType)
        {
            Vector3 worldOrigin    = probe.transform.TransformPoint(probe.origin);
            Vector3 worldDirection = probe.transform.localToWorldMatrix * (probe.direction.normalized * probe.reach);
            Vector3 worldTarget    = worldOrigin + worldDirection;

            Gizmos.color = Color.cyan;
            Gizmos.DrawLine(worldOrigin, worldTarget);

            Handles.color = Color.cyan;
            Quaternion rotation = Quaternion.FromToRotation(Vector3.forward, worldDirection.normalized);
            float      size     = HandleUtility.GetHandleSize(worldTarget) * 0.15f;

            Handles.ConeCap(0, worldTarget - size * 0.5f * worldDirection.normalized, rotation, size);

            if (Event.current.shift)
            {
                Color color = Handles.color;
                color.a = 0.6f;
                var oldMatrix = Gizmos.matrix;
                Gizmos.color  = color;
                Gizmos.matrix = Matrix4x4.TRS(worldOrigin, rotation, Vector3.one);
                Gizmos.DrawCube(Vector3.zero, new Vector3(0.3f, 0.3f, 0.005f));
                Gizmos.matrix = oldMatrix;
            }
        }
コード例 #2
0
        //void OnDisable()
        //{
        //    SceneView.onSceneGUIDelegate -= OnSceneGUI;
        //}

        void OnSceneGUI()
        {
            //if (roadGraph == null) return;
            var roadGraph = ((RoadGraphDatabase)target).RoadGraph;

            if (roadGraph == null)
            {
                return;
            }

            int counter = 0;

            foreach (GraphNode <RoadNode> node in roadGraph)
            {
                foreach (var connection in node.Connections)
                {
                    Vector3    fromNodePos   = connection.FromNode.Value.Position;
                    Vector3    toNodePos     = connection.ToNode.Value.Position;
                    Vector3    direction     = toNodePos - fromNodePos;
                    Quaternion arrowRotation = Quaternion.LookRotation(direction);
                    Handles.color = Color.red;
                    //red line to show the connection
                    Handles.DrawLine(fromNodePos, toNodePos);
                    Handles.color = Color.blue;
                    //Draws an arrow near the toNode
                    Handles.ConeCap(counter++, toNodePos - direction.normalized * .15f, arrowRotation, .1f);
                }
            }
            HandleUtility.Repaint();
        }
コード例 #3
0
        /// <summary>
        /// Draws an arrow in the scene.
        /// Useful for actions that set a direction.
        /// </summary>
        public static void DrawArrow(Vector3 fromPos, Vector3 toPos, Color color, float arrowScale = 0.2f)
        {
            var direction = toPos - fromPos;

            if (direction.sqrMagnitude < 0.0001f)
            {
                return;
            }

            var lookAtRotation = Quaternion.LookRotation(direction);
            var distance       = Vector3.Distance(fromPos, toPos);
            var handleSize     = HandleUtility.GetHandleSize(toPos);
            var arrowSize      = handleSize * arrowScale;

            var originalColor = Handles.color;

            Handles.color = color;

            Handles.DrawLine(fromPos, toPos);

#if UNITY_5_5_OR_NEWER
            Handles.ConeHandleCap(0, fromPos + direction.normalized * (distance - arrowSize), lookAtRotation, arrowSize, EventType.Repaint); // fudge factor to position cap correctly
#else
            Handles.ConeCap(0, fromPos + direction.normalized * (distance - arrowSize), lookAtRotation, arrowSize);                          // fudge factor to position cap correctly
#endif

            Handles.color = originalColor;
        }
コード例 #4
0
    private void Draw()
    {
        var worldBezier = targetPath.WorldSpaceBezier;
        var vertexCount = DynamicBezier.GoodNumMidPoints * worldBezier.Knots.Count;

        vertexCount /= 2;
        var cPointCache = new EvaluationCache(worldBezier, vertexCount).Values;

        // draw bezier
        PathEditorUtility.DrawSplineInScene(cPointCache);

        // draw direction cone cap
        if (!settings.HideDirectionCones &&
            targetScript.transform.lossyScale != Vector3.zero &&
            targetPath.LocalBezier.Knots.Count > 1)     // also hide cones if virtually a dot
        {
            float startConeSize = PathEditorUtility.Nice3DHandleSize(worldBezier.Evaluate(0f));
            float endConeSize   = PathEditorUtility.Nice3DHandleSize(worldBezier.Evaluate(1f));

            Handles.color = Color.yellow;
            Handles.ConeCap(0, worldBezier.Evaluate(0f), Quaternion.LookRotation(worldBezier.Evaluate(0.01f) - worldBezier.Evaluate(0f)), startConeSize);
            Handles.color = Color.magenta;
            Handles.ConeCap(0, worldBezier.Evaluate(1f), Quaternion.LookRotation(worldBezier.Evaluate(1f) - worldBezier.Evaluate(1f - 0.01f)), endConeSize);
        }

        // draw tangent lines
        if (!settings.HideTangentLines)
        {
            Handles.color = Color.cyan;
            for (int i = 0; i < worldBezier.Knots.Count - 1; i++)
            {
                Handles.DrawDottedLine(worldBezier.Knots[i], worldBezier.Knots[i + 1], 7.5f);
            }
        }

        // Draw knot labels
        var knotLabelStyle = new GUIStyle();

        knotLabelStyle.fontStyle     = FontStyle.Bold;
        knotLabelStyle.fontSize      = 17;
        knotLabelStyle.alignment     = TextAnchor.UpperRight;
        knotLabelStyle.contentOffset = new Vector2(25f, -50f);

        for (int i = 0; i < worldBezier.Knots.Count; i++)
        {
            knotLabelStyle.normal.textColor = PathEditorUtility.GetTColor((float)i / worldBezier.Knots.Count);
            Handles.Label(worldBezier.Knots[i], i.ToString(), knotLabelStyle);
        }

        // test t
        if (settings.TestInterpolate)
        {
            PathEditorUtility.DrawTestInterpolate(worldBezier, settings.EditorData.T);
        }

        // draw GUI
        InterpolateSceneGUI();
        ToolShelf();
    }
コード例 #5
0
 public static void ConeCap(int controlID, Vector3 position, Quaternion rotation, float size)
 {
                 #if UNITY_5_6_OR_NEWER
     Handles.ConeHandleCap(controlID, position, rotation, size, EventType.Repaint);
                 #else
     Handles.ConeCap(controlID, position, rotation, size);
                 #endif
 }
コード例 #6
0
 /// <summary>
 /// Draw marker to show direction of transitions.
 /// </summary>
 /// <param name="window">The window transitions too.</param>
 private void DrawDirectionMarker(Vector2 pos, Color colour)
 {
     //Handles.BeginGUI();
     Handles.color = colour;
     Handles.ConeCap(0, pos, Quaternion.identity, 15);
     //Handles.EndGUI();
     //Repaint();
 }
コード例 #7
0
    void OnSceneGUI()
    {
        Handles.color = Color.green;

        Handles.ConeCap(0, DrawConeCap.transform.position - DrawConeCap.transform.forward * (DrawConeCap.VisionDistance / 2),
                        DrawConeCap.transform.rotation,
                        DrawConeCap.VisionDistance);
    }
コード例 #8
0
    void DoDrawGizmos(Color color, bool drawConnectorLines = false)
    {
        HingeJoint2D[] joints = gameObject.GetComponents <HingeJoint2D>();

        foreach (HingeJoint2D joint in joints)
        {
            Handles.color = color;

            Vector3 anchor = new Vector3(joint.anchor.x, joint.anchor.y, 0);
            anchor = joint.transform.rotation * anchor;

            // Draw the rotation Arc
            if (joint.connectedBody != null)
            {
                float radius = new Vector3(joint.connectedAnchor.x * joint.connectedBody.transform.lossyScale.x, joint.connectedAnchor.y * joint.connectedBody.transform.lossyScale.y, 0).magnitude;

                Handles.DrawWireArc(new Vector3(transform.position.x + anchor.x * transform.lossyScale.x,
                                                transform.position.y + anchor.y * transform.lossyScale.y,
                                                transform.position.z - 1),
                                    Vector3.forward,
                                    (Application.isPlaying ? cachedRotationStarts[joint] * Quaternion.Euler(transform.rotation.eulerAngles - cachedOriginalRotations[joint].eulerAngles) : joint.connectedBody.transform.rotation) * Quaternion.Euler(0, 0, joint.limits.min + transform.rotation.z) * (Application.isPlaying ? cachedAngleStarts[joint] : new Vector3(joint.connectedAnchor.normalized.x, joint.connectedAnchor.normalized.y)),
                                    joint.useLimits ? joint.limits.min - joint.limits.max : 360,
                                    radius);


                // Add the motor's direction if used.
                if (joint.useMotor && !Mathf.Approximately(joint.motor.motorSpeed, 0))
                {
                    Handles.ConeCap(0, (transform.position + new Vector3(anchor.x * transform.lossyScale.x, anchor.y * transform.lossyScale.y + radius, 0)), Quaternion.Euler(0, joint.motor.motorSpeed > 0 ? -90 : 90, 0), 0.5f);
                }

                if (drawConnectorLines)
                {
                    Gizmos.color = COLOR_CONNECTED_ANCHOR_LINK;

                    if (Application.isPlaying)
                    {
                        Gizmos.DrawLine(joint.connectedBody.transform.position, joint.transform.position + anchor);
                    }
                    else
                    {
                        DrawLinkBetweenBodyAndAnchor(joint.connectedBody, joint.connectedBody.transform.rotation * joint.connectedAnchor);
                    }
                }
            }

            // Draw the link between the two anchors


            DrawAnchor(anchor);
            if (!Application.isPlaying)
            {
                DrawConnectedAnchor(joint.connectedBody, joint.connectedBody.transform.rotation * joint.connectedAnchor);
            }
        }
    }
コード例 #9
0
        /// <summary>
        /// Draws the scene view helpers for IKSolverAim
        /// </summary>
        public static void AddScene(IKSolverAim solver, Color color, bool modifiable)
        {
            // Protect from null reference errors
            if (!solver.IsValid(false))
            {
                return;
            }
            if (solver.transform == null)
            {
                return;
            }
            if (Application.isPlaying && !solver.initiated)
            {
                return;
            }

            Handles.color = color;
            GUI.color     = color;

            // Display the bones
            for (int i = 0; i < solver.bones.Length; i++)
            {
                IKSolver.Bone bone = solver.bones[i];

                if (i < solver.bones.Length - 1)
                {
                    Handles.DrawLine(bone.transform.position, solver.bones[i + 1].transform.position);
                }
                Handles.SphereCap(0, solver.bones[i].transform.position, Quaternion.identity, jointSize);
            }

            if (solver.axis != Vector3.zero)
            {
                Handles.ConeCap(0, solver.transform.position, Quaternion.LookRotation(solver.transform.rotation * solver.axis), jointSize * 2f);
            }

            // Selecting joint and manipulating IKPosition
            if (Application.isPlaying && solver.IKPositionWeight > 0)
            {
                if (modifiable)
                {
                    Handles.SphereCap(0, solver.IKPosition, Quaternion.identity, selectedSize);

                    // Manipulating position
                    solver.IKPosition = Handles.PositionHandle(solver.IKPosition, Quaternion.identity);
                }

                // Draw a transparent line from transform to IKPosition
                Handles.color = new Color(color.r, color.g, color.b, color.a * solver.IKPositionWeight);
                Handles.DrawLine(solver.bones[solver.bones.Length - 1].transform.position, solver.transform.position);
                Handles.DrawLine(solver.transform.position, solver.IKPosition);
            }

            Handles.color = Color.white;
            GUI.color     = Color.white;
        }
コード例 #10
0
        private void DrawArrow(Vector2 posStart, Vector2 posEnd)
        {
            float      dis   = Vector2.Distance(posEnd, posStart);
            Vector2    nor   = (posEnd - posStart).normalized;
            Vector2    cross = nor * (dis * 0.2f) + posStart;
            Quaternion q     = Quaternion.FromToRotation(Vector3.back, posStart - posEnd);

            //		Handles.Label (cross, arrows.ToString());
            cross = nor * (dis * 0.5f) + posStart;
            Handles.ConeCap(0, new Vector3(cross.x, cross.y, -100), q, 18);
        }
コード例 #11
0
 void OnSceneGUI()
 {
     Handles.color = Color.yellow;
     Handles.DrawAAPolyLine(3.0f, positions);
     Handles.color = Color.red;
     for (int i = 0; i < drawpathObj.wplist.Count - 1; i++)
     {
         Quaternion t_rotation = Quaternion.LookRotation(positions [i + 1] - positions [i]);
         Handles.ConeCap(0, positions[i + 1], t_rotation, arrowSize);
     }
 }
コード例 #12
0
ファイル: BaseNode.cs プロジェクト: platefaces/EditorDemo
 public override void DrawBezier()
 {
     if (_handle[0].node != null)
     {
         Vector3 end   = new Vector2(_handle [0].area.xMin - 15, _handle [0].area.center.y) + nodeRect.position;
         Vector2 start = _handle [0].node.nodeRect.center;
         _parent.DrawBezier(start, end);
         Handles.color = Color.white;
         end.z         = -100;
         Handles.ConeCap(1, end, Quaternion.FromToRotation(Vector3.back, Vector3.left), 18);
     }
 }
コード例 #13
0
        protected override void Animate(BGTransition.SwayTransition swayTransition, Vector3 point, float distanceToCamera, Plane plane)
        {
            var verts = GetVertsByPlaneAndDistance(new Vector3(swayTransition.Value, swayTransition.Value, swayTransition.Value), point, distanceToCamera, plane);

            var size = swayTransition.Value * ScalePreviewPoint * distanceToCamera / 5;

            BGEditorUtility.SwapHandlesColor(PointersColor, () => { foreach (var position in verts)
                                                                    {
                                                                        Handles.ConeCap(0, position, Quaternion.LookRotation(point - position), size);
                                                                    }
                                             });
        }
コード例 #14
0
        private void DrawArrowFor(int wpIndex, float handleSize, Vector3 arrowPointsAt)
        {
            Color arg_5A_0 = Handles.color;

            Handles.color = this._arrowsColor;
            Vector3 vector  = this._src.wps[wpIndex];
            Vector3 vector2 = arrowPointsAt - vector;

            if (vector2.magnitude >= handleSize * 1.75f)
            {
                Handles.ConeCap(wpIndex, vector + Vector3.ClampMagnitude(vector2, handleSize), Quaternion.LookRotation(vector2), handleSize * 0.65f);
            }
            Handles.color = arg_5A_0;
        }
コード例 #15
0
    void DoDrawGizmos(Color color, bool drawConnectorLines = false)
    {
        SliderJoint2D[] joints = gameObject.GetComponents <SliderJoint2D>();

        foreach (SliderJoint2D joint in joints)
        {
            Gizmos.color = color;

            DrawAnchorLeadingLine(joint.anchor);

            /*
             * if(Application.isPlaying && cachedSliderRotationStarts[joint] != transform.localRotation)
             * {
             *      cachedSliderRotationStarts[joint] = transform.localRotation;
             *      cachedParentRotationStarts[joint] = transform.parent.rotation;
             * }
             */
            Quaternion rotation = Application.isPlaying ? Quaternion.Euler(transform.parent.rotation.eulerAngles - cachedParentRotationStarts[joint].eulerAngles) : Quaternion.identity;

            // Draw the slider
            Vector3 minEnd = transform.position + new Vector3(joint.anchor.x * transform.lossyScale.x, joint.anchor.y * transform.lossyScale.y, 0) + (rotation * Quaternion.Euler(0, 0, joint.angle + 180) * Vector3.up) * (joint.useLimits ? Mathf.Min(joint.limits.min, joint.limits.max) : 100000);
            Vector3 maxEnd = transform.position + new Vector3(joint.anchor.x * transform.lossyScale.x, joint.anchor.y * transform.lossyScale.y, 0) + (rotation * Quaternion.Euler(0, 0, joint.angle + 180) * Vector3.up) * (joint.useLimits ? Mathf.Max(joint.limits.min, joint.limits.max) : -100000);
            Gizmos.DrawLine(minEnd, maxEnd);

            if (drawConnectorLines && joint.connectedBody != null)
            {
                Gizmos.color = COLOR_CONNECTED_ANCHOR_LINK;
                if (Application.isPlaying)
                {
                    Gizmos.DrawLine(joint.connectedBody.transform.position, joint.connectedBody.transform.position + joint.connectedBody.transform.rotation * joint.connectedAnchor);
                }
                else
                {
                    DrawLinkBetweenBodyAndAnchor(joint.connectedBody, joint.connectedBody.transform.rotation * joint.connectedAnchor);
                }
            }

            Handles.color = color;

            // Add the motor's direction if used.
            if (joint.useMotor && !Mathf.Approximately(joint.motor.motorSpeed, 0) && (!joint.useLimits || Mathf.Abs(joint.limits.max - joint.limits.min) != 0))
            {
                Handles.ConeCap(0, minEnd - (joint.useLimits ? Vector3.zero : (maxEnd - minEnd).normalized) + (maxEnd - minEnd) * 0.5f, Quaternion.LookRotation((maxEnd - minEnd) * (joint.motor.motorSpeed > 0 ?  -1: 1)), 0.5f);
            }

            Gizmos.color = COLOR_ANCHOR;
            DrawAnchor(joint.anchor);
            DrawConnectedAnchor(joint.connectedBody, joint.connectedBody.transform.rotation * joint.connectedAnchor);
        }
    }
コード例 #16
0
    private void Draw()
    {
        CubicBezier worldBezier = cubicBezierPath.WorldSpaceBezier;

        // draw bezier
        Vector3[] cPointCache = new EvaluationCache(worldBezier, CubicBezier.GoodNumMidPoints).Values;

        /*Handles.color = Color.yellow;
         * Handles.DrawAAPolyLine(cPointCache);
         */
        for (int i = 0; i < cPointCache.Length - 1; i++)
        {
            Handles.color = Color.Lerp(Color.yellow, Color.magenta, (float)i / cPointCache.Length);
            var lineSegment = new Vector3[2];
            lineSegment[0] = cPointCache[i];
            lineSegment[1] = cPointCache[i + 1];
            Handles.DrawAAPolyLine(lineSegment);
        }

        // draw direction cone cap
        if (!settings.HideDirectionCones && targetScript.transform.lossyScale != Vector3.zero) //check for zero vector, since LookRotation logs messages
        {
            float startConeSize = PathEditorUtility.Nice3DHandleSize(worldBezier.Evaluate(0f));
            float endConeSize   = PathEditorUtility.Nice3DHandleSize(worldBezier.Evaluate(1f));

            Handles.color = Color.yellow;
            Handles.ConeCap(0, worldBezier.Evaluate(0f), Quaternion.LookRotation(worldBezier.Tangent(0f)), startConeSize);
            Handles.color = Color.magenta;
            Handles.ConeCap(0, worldBezier.Evaluate(1f), Quaternion.LookRotation(worldBezier.Tangent(1f)), endConeSize);
        }

        // draw tangent lines
        if (!settings.HideTangentLines)
        {
            Handles.color = Color.cyan;
            Handles.DrawDottedLine(worldBezier.StartPosition, worldBezier.StartTangent, 7.5f);
            Handles.DrawDottedLine(worldBezier.EndPosition, worldBezier.EndTangent, 7.5f);
        }

        // test t
        if (settings.TestInterpolate)
        {
            PathEditorUtility.DrawTestInterpolate(worldBezier, settings.EditorData.T);
        }

        // draw GUI
        InterpolateSceneGUI();
        ToolShelf();
    }
コード例 #17
0
    private void Draw()
    {
        Vector3 startPoint = linePath.Evaluate(0f);
        Vector3 endPoint   = linePath.Evaluate(1f);

        // draw line
        var cPointCache = new Vector3[32];

        for (int i = 0; i < cPointCache.Length; i++)
        {
            cPointCache[i] = Vector3.Lerp(startPoint, endPoint, (float)i / (cPointCache.Length - 1));
        }

        for (int i = 0; i < cPointCache.Length - 1; i++)
        {
            Handles.color = Color.Lerp(Color.yellow, Color.magenta, (float)i / cPointCache.Length);
            var lineSegment = new Vector3[2];
            lineSegment[0] = cPointCache[i];
            lineSegment[1] = cPointCache[i + 1];
            Handles.DrawAAPolyLine(lineSegment);
        }

        // draw direction cone cap
        if (!settings.HideDirectionCones &&
            linePath.LocalSpaceTransform.lossyScale != Vector3.zero &&
            linePath.StartPosition != linePath.EndPosition)    // also hide cones if virtually a dot
        {
            float startConeSize = PathEditorUtility.Nice3DHandleSize(startPoint);
            float endConeSize   = PathEditorUtility.Nice3DHandleSize(endPoint);

            Handles.color = Color.yellow;
            Handles.ConeCap(0, startPoint, Quaternion.LookRotation(linePath.Tangent()), startConeSize);
            Handles.color = Color.magenta;
            Handles.ConeCap(0, endPoint, Quaternion.LookRotation(linePath.Tangent()), endConeSize);
        }

        // test t
        Handles.color = PathEditorUtility.GetTColor(settings.EditorData.T);
        if (settings.TestInterpolate)
        {
            Vector3 targetPoint = linePath.Evaluate(settings.EditorData.T);
            float   sphereSize  = PathEditorUtility.Nice3DHandleSize(targetPoint);
            Handles.SphereCap(0, targetPoint, Quaternion.identity, sphereSize);
        }

        // draw GUI
        InterpolateSceneGUI();
        ToolShelf();
    }
コード例 #18
0
        //private Texture2D arrow;
        public void DrawCap(Vector3 pos, Vector3 startPos, Vector3 endPos, Quaternion rot, Color shadowColor, Color lineColor)
        {
            if (FlowSystem.GetZoom() < 1f)
            {
                return;
            }

            //if (this.arrow == null) this.arrow = UnityEngine.Resources.Load<Texture2D>("UI.Windows/Flow/Arrow");

            var size = 12f;

            size /= FlowSystem.GetZoom();

            //pos = this.editor.zoomDrawer.ConvertScreenCoordsToZoomCoords(pos, topLeft: true);

            var scrollPos = -FlowSystem.GetScrollPosition();
            var offset    = -8f;

            if (this.editor.scrollRect.Contains(new Vector3(pos.x - scrollPos.x + FlowSystemEditorWindow.GetSettingsWidth() + offset, pos.y - scrollPos.y + FlowSystemEditorWindow.TOOLBAR_HEIGHT + offset, 0f)) == false)
            {
                return;
            }

            var shadowOffset = Vector3.one * 1f;

            shadowOffset.z = 0f;

            /*var v1 = startPos - endPos;
             * v1.x = -v1.x;
             * var v2 = Vector3.left;
             *
             * var angle = Mathf.Atan2(
             *      Vector3.Dot(Vector3.back, Vector3.Cross(v1, v2)),
             *      Vector3.Dot(v1, v2)) * Mathf.Rad2Deg;
             *
             * var oldColor = GUI.color;
             *
             * GUI.color = shadowColor;
             * GUIExt.DrawTextureRotated(new Rect(pos.x - size * 0.5f + shadowOffset.x, pos.y - size * 0.5f + shadowOffset.y, size, size), arrow, -angle + 180f);
             * GUI.color = lineColor;
             * GUIExt.DrawTextureRotated(new Rect(pos.x - size * 0.5f, pos.y - size * 0.5f, size, size), arrow, -angle + 180f);
             *
             * GUI.color = oldColor;*/

            Handles.color = shadowColor;
            Handles.ConeCap(-1, pos + shadowOffset, rot, 15f);
            Handles.color = lineColor;
            Handles.ConeCap(-1, pos, rot, 15f);
        }
コード例 #19
0
        /// <summary>
        /// Draws repositionable handles at every point in the path, for easier setup
        /// </summary>
        public void OnSceneGUI()
        {
            Handles.color = Color.green;
            RaceManager t = (target as RaceManager);

            if (t.Checkpoints != null)
            {
                for (int i = 0; i < t.Checkpoints.Length; i++)
                {
                    if (t.Checkpoints[i] != null)
                    {
                        // draws the path item number
                        GUIStyle style = new GUIStyle();
                        style.normal.textColor = Color.red;
                        Handles.Label(t.Checkpoints[i].transform.position + (Vector3.down * 0.4f) + (Vector3.right * 0.4f), "CP-" + i, style);
                    }
                }
            }

            for (int i = 0; i < t.StartPositions.Length; i++)
            {
                Vector3 oldPoint = t.StartPositions[i];

                Handles.color = Color.magenta;

                // we draw the start angle
                Handles.ConeCap(0, oldPoint, Quaternion.AngleAxis(t.StartAngleDegree, Vector3.up), 2f);

                Handles.color = Color.green;

                EditorGUI.BeginChangeCheck();

                // we draw the path item number
                GUIStyle style = new GUIStyle();
                style.normal.textColor = Color.gray;
                Handles.Label(t.StartPositions[i] + (Vector3.down * 0.4f) + (Vector3.right * 0.4f), "start-" + (i + 1), style);

                // we draw a movable handle
                Vector3 newPoint = Handles.PositionHandle(oldPoint, Quaternion.identity);

                // records changes
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(target, "Start Position Move Handle");
                    t.StartPositions[i] = newPoint;
                }
            }
        }
コード例 #20
0
        public static void ConeHandleCap(int controlID, Vector3 position, Quaternion rotation, float size, EventType eventType)
        {
#if UNITY_5_6_OR_NEWER
            Handles.ConeHandleCap(controlID, position, rotation, size, eventType);
#else
            switch (eventType)
            {
            case (EventType.Layout):
                HandleUtility.AddControl(controlID, HandleUtility.DistanceToCircle(position, size));
                break;

            case (EventType.Repaint):
                Handles.ConeCap(controlID, position, rotation, size);
                break;
            }
#endif
        }
コード例 #21
0
        static void DrawHandleCap(HandleCaps capType, int controlID, Vector3 position, Quaternion rotation, float size)
        {
            #if UNITY_5_5_OR_NEWER
            switch (capType)
            {
            case HandleCaps.Cube:

                Handles.CubeHandleCap(controlID, position, rotation, size, EventType.Repaint);

                break;

            case HandleCaps.Cone:

                Handles.ConeHandleCap(controlID, position, rotation, size, EventType.Repaint);

                break;

            case HandleCaps.Circle:

                Handles.CircleHandleCap(controlID, position, rotation, size, EventType.Repaint);

                break;
            }
            #else
            switch (capType)
            {
            case HandleCaps.Cube:

                Handles.CubeCap(controlID, position, rotation, size);

                break;

            case HandleCaps.Cone:

                Handles.ConeCap(controlID, position, rotation, size);

                break;

            case HandleCaps.Circle:

                Handles.CircleCap(controlID, position, rotation, size);

                break;
            }
            #endif
        }
コード例 #22
0
 void SecondWindow2(int unusedWindowID)
 {
     capSize  = EditorGUILayout.IntField("尺寸:", capSize);
     capEuler = EditorGUILayout.Vector3Field("testVector3:", capEuler);
     if (GUILayout.Button("关闭绘制图形"))
     {
         secondWindow2 = false;
     }
     Handles.color = Color.red;
     Handles.DrawLine(new Vector2(75, 100), new Vector3(150, 200));
     Handles.CircleCap(1, new Vector2(300, 150), Quaternion.identity, capSize);
     Handles.color = Color.green;
     Handles.SphereCap(2, new Vector2(100, 250), Quaternion.Euler(capEuler), capSize);
     Handles.CubeCap(3, new Vector2(300, 250), Quaternion.Euler(capEuler), capSize);
     Handles.color = Color.blue;
     Handles.CylinderCap(4, new Vector2(100, 350), Quaternion.Euler(capEuler), capSize);
     Handles.ConeCap(5, new Vector2(300, 350), Quaternion.Euler(capEuler), capSize);
     GUI.DragWindow();//画出子窗口
 }
コード例 #23
0
        void OnSceneGUI()
        {
            if (!_fadeControl.targetObject)
            {
                return;
            }
            var tpos = (_fadeControl.targetObject.position + _fadeControl.offset);

            Handles.color = new Color(1, 1, 1, 0.5f);
            Handles.SphereCap(0, tpos, Quaternion.identity, 0.1f);
            Ray ray = new Ray(tpos, _fadeControl.cameraTransform.position - tpos);

            Handles.DrawLine(tpos, ray.GetPoint(_fadeControl.distanceToEndFade));
            Handles.color = (_fadeControl.distanceToEndFade < _fadeControl.distanceToStartFade) ? Color.green : Color.red;
            Handles.DrawAAPolyLine(10f, new Vector3[] { ray.GetPoint(_fadeControl.distanceToEndFade), ray.GetPoint(_fadeControl.distanceToStartFade) });
            Handles.CubeCap(0, ray.GetPoint(_fadeControl.distanceToEndFade), Quaternion.LookRotation(_fadeControl.cameraTransform.position - ray.GetPoint(_fadeControl.distanceToEndFade)), 0.05f);
            Handles.ConeCap(0, ray.GetPoint(_fadeControl.distanceToStartFade), Quaternion.LookRotation(ray.GetPoint(_fadeControl.distanceToStartFade) - _fadeControl.cameraTransform.position), 0.1f);
            Handles.color = new Color(1, 1, 1, 0.5f);
            Handles.DrawLine(ray.GetPoint(_fadeControl.distanceToStartFade), _fadeControl.cameraTransform.position);
            Handles.DrawPolyLine(new Vector3[] { ray.GetPoint(_fadeControl.distanceToEndFade), ray.GetPoint(_fadeControl.distanceToStartFade) });
        }
コード例 #24
0
ファイル: NodeEditor.cs プロジェクト: andyqingliu/NodeCanvas
        void DrawConnection(Vector3 start, Vector3 end, Color color, int arrows, bool offset)
        {
            if (_currentEvent.type != EventType.repaint)
            {
                return;
            }
            Handles.color = color;
            Handles.DrawBezier(start, end, start, end, color, NodeStyles.connectionTexture, 3f);
            float      dis   = Vector2.Distance(end, start);
            Vector3    nor   = (end - start).normalized;
            Vector3    cross = nor * (dis * 0.2f) + start;
            Quaternion q     = Quaternion.FromToRotation(Vector3.back, start - end);

            cross.z = -100;
            for (int i = 0; i < arrows; i++)
            {
                cross   = nor * (dis * (0.5f + i * 20 / dis)) + start;
                cross.z = -100;
                Handles.ConeCap(i, cross, q, 18);
            }
        }
コード例 #25
0
    private void Draw()
    {
        QuadraticBezier worldBezier = qdrBezierPath.WorldSpaceBezier;
        var             cPointCache = new EvaluationCache(worldBezier, QuadraticBezier.GoodNumMidPoints).Values;

        // draw bezier
        PathEditorUtility.DrawSplineInScene(cPointCache);

        // draw direction cone cap
        if (!settings.HideDirectionCones &&
            targetScript.transform.lossyScale != Vector3.zero)         // also hide cones if virtually a dot
        {
            float startConeSize = PathEditorUtility.Nice3DHandleSize(worldBezier.Evaluate(0f));
            float endConeSize   = PathEditorUtility.Nice3DHandleSize(worldBezier.Evaluate(1f));

            Handles.color = Color.yellow;
            Handles.ConeCap(0, worldBezier.Evaluate(0f), Quaternion.LookRotation(worldBezier.Evaluate(0.01f) - worldBezier.Evaluate(0f)), startConeSize);
            Handles.color = Color.magenta;
            Handles.ConeCap(0, worldBezier.Evaluate(1f), Quaternion.LookRotation(worldBezier.Evaluate(1f) - worldBezier.Evaluate(1f - 0.01f)), endConeSize);
        }

        // draw tangent lines
        if (!settings.HideTangentLines)
        {
            Handles.color = Color.cyan;
            Handles.DrawDottedLine(worldBezier.StartPosition, worldBezier.MidTangent, 7.5f);
            Handles.DrawDottedLine(worldBezier.MidTangent, worldBezier.EndPosition, 7.5f);
        }

        // test t
        if (settings.TestInterpolate)
        {
            PathEditorUtility.DrawTestInterpolate(worldBezier, settings.EditorData.T);
        }

        // draw GUI
        InterpolateSceneGUI();
        ToolShelf();
    }
コード例 #26
0
    void OnDrawGizmos()
    {
        // Draw vertices
        Gizmos.color  = Color.yellow;
        Handles.color = Color.yellow;
        Vector3    direction;
        Vector3    capPosition;
        Quaternion orientation;

        foreach (AiEdge e in m_Successors)
        {
            if (e.m_Vertex != null && e.m_Cost > 0)
            {
                Gizmos.DrawLine(transform.position, e.m_Vertex.transform.position);
                direction   = e.m_Vertex.transform.position - transform.position;
                orientation = Quaternion.LookRotation(direction);

                capPosition = transform.position + direction * 0.75f;
                Handles.ConeCap(0, capPosition, orientation, 0.5f);
            }
        }
    }
コード例 #27
0
        public override void OnModuleSceneDebugGUI()
        {
            base.OnModuleSceneDebugGUI();
            CGVolume vol = Target.InData.GetData <CGVolume>();

            if (vol)
            {
                Handles.matrix = Target.Generator.transform.localToWorldMatrix;

                if (Target.ShowPathSamples)
                {
                    CGEditorUtility.SceneGUIPlot(vol.Position, 0.1f, Target.PathColor);
                    if (Target.ShowIndex)
                    {
                        var labels = Enumerable.Range(0, vol.Count).Select(i => i.ToString()).ToArray <string>();
                        CGEditorUtility.SceneGUILabels(vol.Position, labels, Color.black, Vector2.zero);
                    }
                }
                if (Target.ShowCrossSamples)
                {
                    int vtLo = Target.LimitCross.From * vol.CrossSize;
                    int vtHi = vtLo + vol.CrossSize;
                    if (!Target.LimitCross.SimpleValue)
                    {
                        vtLo = Target.LimitCross.Low * vol.CrossSize;
                        vtHi = (Target.LimitCross.High + 1) * vol.CrossSize;
                    }

                    vtLo = Mathf.Clamp(vtLo, 0, vol.VertexCount);
                    vtHi = Mathf.Clamp(vtHi, vtLo, vol.VertexCount);
                    var range = vol.Vertex.SubArray <Vector3>(vtLo, vtHi - vtLo);
                    CGEditorUtility.SceneGUIPlot(range, 0.1f, Color.white);

                    if (Target.ShowIndex)
                    {
                        var labels = Enumerable.Range(vtLo, vtHi).Select(i => i.ToString()).ToArray <string>();
                        CGEditorUtility.SceneGUILabels(range, labels, Color.black, Vector2.zero);
                    }

                    if (Target.ShowMap)
                    {
                        var labels = Enumerable.Range(vtLo, vtHi).Select(i => DTMath.SnapPrecision(vol.CrossMap[i], 3).ToString()).ToArray <string>();
                        CGEditorUtility.SceneGUILabels(range, labels, new Color(1, 0, 1), new Vector2(10, 20));
                    }

                    if (Target.ShowNormals)
                    {
                        DTHandles.PushHandlesColor(Target.NormalColor);

                        for (int i = vtLo; i < vtHi; i++)
                        {
                            Handles.DrawLine(vol.Vertex[i], vol.Vertex[i] + vol.VertexNormal[i] * 2);
                        }

                        DTHandles.PopHandlesColor();
                    }
                }
                if (Target.Interpolate)
                {
                    Vector3 pos;
                    Vector3 tan;
                    Vector3 up;
                    vol.InterpolateVolume(Target.InterpolatePathF, Target.InterpolateCrossF, out pos, out tan, out up);
                    Handles.ConeCap(0, pos, Quaternion.LookRotation(up, tan), 1f);
                }
                Handles.matrix = Matrix4x4.identity;
            }
        }
コード例 #28
0
        public override void OnSceneGUI()
        {
            var moveTowardsAction = (MoveTowardsAdvanced)target;

            if (moveTowardsAction.UpdateTargetPos())
            {
                var go          = target.Fsm.GetOwnerDefaultTarget(moveTowardsAction.gameObject);
                var goTransform = go.transform;
                var goPosition  = goTransform.position;

                var lookAtPosition = moveTowardsAction.GetTargetPos();
                var lookAtVector   = lookAtPosition - goPosition;
                if (lookAtVector == Vector3.zero)
                {
                    return;
                }
                var lookAtRotation = Quaternion.LookRotation(lookAtVector);

                var handleSize = HandleUtility.GetHandleSize(goPosition);
                var arrowSize  = handleSize * 0.2f;
                var distance   = (lookAtPosition - goPosition).magnitude;

                var goTarget = moveTowardsAction.targetObject.Value;

                // Position handles

                if (!moveTowardsAction.targetPosition.IsNone)
                {
                    if (goTarget != null)
                    {
                        // Edit local offset from target object

                        var goTargetTransform = goTarget.transform;
                        var worldTargetPos    = goTargetTransform.TransformPoint(moveTowardsAction.targetPosition.Value);

                        moveTowardsAction.targetPosition.Value = goTargetTransform.InverseTransformPoint(Handles.PositionHandle(worldTargetPos, goTarget.transform.rotation));
                        Handles.color = new Color(1, 1, 1, 0.2f);
                        Handles.DrawLine(goTargetTransform.position, moveTowardsAction.GetTargetPosWithVertical());
                    }
                    else
                    {
                        // Edit world position

                        moveTowardsAction.targetPosition.Value = Handles.PositionHandle(moveTowardsAction.targetPosition.Value, Quaternion.identity);
                    }
                }

                // Target vector

                Handles.DrawLine(goPosition, lookAtPosition);
                Handles.ConeCap(0, goPosition + lookAtVector.normalized * (distance - arrowSize * 0.7f), lookAtRotation, arrowSize);                 // fudge factor to position cap correctly

                // Show vertical offset

                if (moveTowardsAction.ignoreVertical.Value)
                {
                    Handles.DrawLine(lookAtPosition, moveTowardsAction.GetTargetPosWithVertical());
                }

                if (GUI.changed)
                {
                    FsmEditor.EditingActions();
                    FsmEditor.Repaint(true);
                }
            }
        }
コード例 #29
0
        private static void DrawPose(AimPoser.Pose pose, Vector3 position, Quaternion rotation, Color color)
        {
            if (pose.pitch <= 0f || pose.yaw <= 0f)
            {
                return;
            }
            if (pose.direction == Vector3.zero)
            {
                return;
            }

            Handles.color = color;
            GUI.color     = color;

            Vector3 up = rotation * Vector3.up;
            Vector3 normalizedPoseDirection = pose.direction.normalized;
            Vector3 direction = rotation * normalizedPoseDirection;

            // Direction and label
            Handles.DrawLine(position, position + direction);
            Handles.ConeCap(0, position + direction, Quaternion.LookRotation(direction), 0.05f);
            Handles.Label(position + direction.normalized * 1.1f, pose.name);

            if (pose.yaw >= 180f && pose.pitch >= 180f)
            {
                Handles.color = Color.white;
                GUI.color     = Color.white;
                return;
            }

            Quaternion halfYaw = Quaternion.AngleAxis(pose.yaw, up);

            float   directionPitch = Vector3.Angle(up, direction);
            Vector3 crossRight     = halfYaw * Vector3.Cross(up, direction);
            Vector3 crossLeft      = Quaternion.Inverse(halfYaw) * Vector3.Cross(up, direction);

            bool isVertical = normalizedPoseDirection == Vector3.up || normalizedPoseDirection == Vector3.down;

            if (isVertical)
            {
                crossRight = halfYaw * Vector3.right;
                crossLeft  = Quaternion.Inverse(halfYaw) * Vector3.right;
            }

            float minPitch = Mathf.Clamp(directionPitch - pose.pitch, 0f, 180f);
            float maxPitch = Mathf.Clamp(directionPitch + pose.pitch, 0f, 180f);

            Quaternion upToCornerUpperRight = Quaternion.AngleAxis(minPitch, crossRight);
            Quaternion upToCornerLowerRight = Quaternion.AngleAxis(maxPitch, crossRight);
            Quaternion upToCornerUpperLeft  = Quaternion.AngleAxis(minPitch, crossLeft);
            Quaternion upToCornerLowerLeft  = Quaternion.AngleAxis(maxPitch, crossLeft);

            Vector3 toCornerUpperRight = upToCornerUpperRight * up;
            Vector3 toCornerLowerRight = upToCornerLowerRight * up;
            Vector3 toCornerUpperLeft  = upToCornerUpperLeft * up;
            Vector3 toCornerLowerLeft  = upToCornerLowerLeft * up;

            if (pose.yaw < 180f)
            {
                Handles.DrawLine(position, position + toCornerUpperRight);
                Handles.DrawLine(position, position + toCornerUpperLeft);

                Handles.DrawLine(position, position + toCornerLowerRight);
                Handles.DrawLine(position, position + toCornerLowerLeft);
            }

            Vector3 d = direction;

            if (isVertical)
            {
                d = Vector3.forward;
            }

            if (pose.pitch < 180f)
            {
                DrawPolyLineOnSphere(position, toCornerUpperLeft, toCornerUpperRight, d, Vector3.up, color);
                DrawPolyLineOnSphere(position, toCornerLowerLeft, toCornerLowerRight, d, Vector3.up, color);
            }

            if (pose.yaw < 180f)
            {
                DrawPolyLineOnSphere(position, toCornerUpperLeft, toCornerLowerLeft, Quaternion.Inverse(halfYaw) * d, crossLeft, color);
                DrawPolyLineOnSphere(position, toCornerUpperRight, toCornerLowerRight, halfYaw * d, crossRight, color);
            }

            Handles.color = Color.white;
            GUI.color     = Color.white;
        }
コード例 #30
0
        public override void OnSceneGUI()
        {
            var lookAtAction = (HutongGames.PlayMaker.Actions.LookAt)target;

            if (lookAtAction.UpdateLookAtPosition())
            {
                var go          = target.Fsm.GetOwnerDefaultTarget(lookAtAction.gameObject);
                var goTransform = go.transform;
                var goPosition  = goTransform.position;

                var lookAtPosition = lookAtAction.GetLookAtPosition();
                var lookAtVector   = lookAtPosition - goPosition;
                var lookAtRotation = Quaternion.LookRotation(lookAtVector);
                var lookAtAngle    = Vector3.Angle(goTransform.forward, lookAtVector);
                var lookAtNormal   = Vector3.Cross(goTransform.forward, lookAtVector);

                var handleSize = HandleUtility.GetHandleSize(goPosition);
                var arrowSize  = handleSize * 0.2f;
                var distance   = (lookAtPosition - goPosition).magnitude;

                var goTarget = lookAtAction.targetObject.Value;

                // Position handles

                if (!lookAtAction.targetPosition.IsNone)
                {
                    if (goTarget != null)
                    {
                        // Edit local offset from target object

                        var goTargetTransform = goTarget.transform;
                        var worldTargetPos    = goTargetTransform.TransformPoint(lookAtAction.targetPosition.Value);

                        lookAtAction.targetPosition.Value = goTargetTransform.InverseTransformPoint(Handles.PositionHandle(worldTargetPos, goTarget.transform.rotation));
                        Handles.color = new Color(1, 1, 1, 0.2f);
                        Handles.DrawLine(goTargetTransform.position, lookAtAction.GetLookAtPositionWithVertical());
                    }
                    else
                    {
                        // Edit world position

                        lookAtAction.targetPosition.Value = Handles.PositionHandle(lookAtAction.targetPosition.Value, Quaternion.identity);
                    }
                }

                // Forward vector

                Handles.color = Color.blue;
                Handles.DrawLine(goPosition, goPosition + goTransform.forward * handleSize);

                // Lookat vector

                Handles.DrawLine(goPosition, lookAtPosition);
                Handles.ConeCap(0, goPosition + lookAtVector.normalized * (distance - arrowSize * 0.7f), lookAtRotation, arrowSize);   // fudge factor to position cap correctly

                // Arc between vectors

                Handles.color = new Color(1, 1, 1, 0.2f);
                Handles.DrawSolidArc(goPosition, lookAtNormal, goTransform.forward, lookAtAngle, handleSize);

                // Show vertical offset

                if (lookAtAction.keepVertical.Value)
                {
                    Handles.DrawLine(lookAtPosition, lookAtAction.GetLookAtPositionWithVertical());
                }

                if (GUI.changed)
                {
                    FsmEditor.EditingActions();
                    FsmEditor.Repaint(true);
                }
            }
        }