コード例 #1
0
        protected override void DrawLocalGizmos(ref Matrix4x4 matrix)
        {
            base.DrawLocalGizmos(ref matrix);

            if (_previewRotation)
            {
                ValidateSamples();

                int segmentCount = this.segmentCount;
                Location loc;
                Quaternion rot;
                Vector3 pos;

                Handles.color = previewRotationColor;

                for (loc.index = 0; loc.index < segmentCount; loc.index++)
                {
                    int count = Mathf.CeilToInt(node(loc.index).length);

                    for (int t = 0; t <= count; t++)
                    {
                        if (t == count && loc.index != segmentCount - 1) continue;

                        loc.time = (float)t / count;
                        rot = GetRotation(loc, Space.Self);
                        pos = GetPoint(loc, Space.Self);

                        Handles.ArrowHandleCap(0, pos, rot, 0.75f, EventType.Repaint);
                        HandlesKit.DrawAALine(pos, pos + rot * Vector3.up);
                    }
                }
            }
        }
コード例 #2
0
        protected virtual void DrawLocalGizmos(ref Matrix4x4 matrix)
        {
            // 绘制路径

            int count = segmentCount;

            for (int i = 0; i < count; i++)
            {
                this[i].Draw(_segmentColor, _segmentWidth);
            }

            // 绘制箭头

            using (new HandlesColorScope(_arrowColor))
            {
                Vector3 point    = this[count - 1].GetPoint(1f);
                float   scale    = HandleUtility.GetHandleSize(point) / Mathf.Abs(_worldScale);
                Vector3 vector   = new Vector3(0.06f, 0f, -0.2f) * scale;
                var     tangent  = this[count - 1].GetTangent(1f);
                var     rotation = Quaternion.LookRotation(tangent, matrix.inverse.MultiplyPoint(Camera.current.transform.position) - point);
                HandlesKit.DrawAALine(point, point + rotation * vector);
                vector.x = -vector.x;
                HandlesKit.DrawAALine(point, point + rotation * vector);
            }
        }
コード例 #3
0
            protected override void OnRotateToolSceneGUI(CardinalPathWithRotation path)
            {
                int count = path.nodeCount;

                for (int i = 0; i < count; i++)
                {
                    var position = path.GetNodePosition(i);
                    var rotation = path.GetNodeRatation(i);

                    float size = HandleUtility.GetHandleSize(position);

                    Handles.color = new Color(0.6f, 1f, 0.3f);
                    Handles.ArrowHandleCap(0, position, rotation, size, EventType.Repaint);
                    HandlesKit.DrawAALine(position, position + rotation * Vector3.up * size);

                    if (selectedNode == i)
                    {
                        using (var scope = new ChangeCheckScope(path))
                        {
                            if (path.IsNodeLookTangent(i))
                            {
                                rotation = Handles.Disc(rotation, position, rotation * Vector3.forward, size, false, 0.01f);
                            }
                            else
                            {
                                rotation = Handles.RotationHandle(rotation, position);
                            }
                            if (scope.changed)
                            {
                                path.SetNodeRatation(i, rotation);
                            }
                        }
                    }
                    else
                    {
                        Handles.color = capNormalColor;
                        if (Handles.Button(position, Quaternion.identity, size * capSize, size * capSize, Handles.DotHandleCap))
                        {
                            selectedNode = i;
                        }
                    }
                }
            }
コード例 #4
0
            protected override void OnMoveToolSceneGUI(T path)
            {
                int count = path.nodeCount;

                for (int i = 0; i < count; i++)
                {
                    // 获取控制点位置
                    var   middle = path.GetNodePosition(i);
                    float capSize;

                    var back    = path.GetNodeBackControlPoint(i);
                    var forward = path.GetNodeForwardControlPoint(i);

                    // 绘制切线
                    Handles.color = selectedNode == i ? new Color(1f, 1f, 1f, 0.9f) : new Color(1f, 1f, 1f, 0.3f);
                    HandlesKit.DrawAALine(back, middle);
                    HandlesKit.DrawAALine(forward, middle);

                    // 绘制后控制点
                    capSize = HandleUtility.GetHandleSize(back) * FloatingWindow.capSize;

                    if (_selectedType == -1 && selectedNode == i)
                    {
                        using (var scope = new ChangeCheckScope(path))
                        {
                            Handles.color = capSelectedColor;
                            if (selectedTool == 0)
                            {
                                back = Handles.FreeMoveHandle(back, Quaternion.identity, capSize * 2, snap, Handles.RectangleHandleCap);
                            }
                            else if (selectedTool == 1)
                            {
                                back = Handles.PositionHandle(back, path.transform.rotation);
                            }
                            if (scope.changed)
                            {
                                path.SetNodeBackControlPoint(i, back);
                            }
                        }
                    }
                    else
                    {
                        Handles.color = capNormalColor;
                        if (Handles.Button(back, Quaternion.identity, capSize, capSize, Handles.DotHandleCap))
                        {
                            selectedNode  = i;
                            _selectedType = -1;
                        }
                    }


                    // 绘制前控制点
                    capSize = HandleUtility.GetHandleSize(forward) * FloatingWindow.capSize;

                    if (_selectedType == 1 && selectedNode == i)
                    {
                        using (var scope = new ChangeCheckScope(path))
                        {
                            Handles.color = capSelectedColor;
                            if (selectedTool == 0)
                            {
                                forward = Handles.FreeMoveHandle(forward, Quaternion.identity, capSize * 2, snap, Handles.RectangleHandleCap);
                            }
                            else if (selectedTool == 1)
                            {
                                forward = Handles.PositionHandle(forward, path.transform.rotation);
                            }
                            if (scope.changed)
                            {
                                path.SetNodeForwardControlPoint(i, forward);
                            }
                        }
                    }
                    else
                    {
                        Handles.color = capNormalColor;
                        if (Handles.Button(forward, Quaternion.identity, capSize, capSize, Handles.DotHandleCap))
                        {
                            selectedNode  = i;
                            _selectedType = 1;
                        }
                    }

                    // 绘制中控制点
                    capSize = HandleUtility.GetHandleSize(middle) * FloatingWindow.capSize;

                    if (_selectedType == 0 && selectedNode == i)
                    {
                        using (var scope = new ChangeCheckScope(path))
                        {
                            Handles.color = capSelectedColor;
                            if (selectedTool == 0)
                            {
                                middle = Handles.FreeMoveHandle(middle, Quaternion.identity, capSize * 2, snap, Handles.RectangleHandleCap);
                            }
                            else if (selectedTool == 1)
                            {
                                middle = Handles.PositionHandle(middle, path.transform.rotation);
                            }
                            if (scope.changed)
                            {
                                path.SetNodePosition(i, middle);
                            }
                        }
                    }
                    else
                    {
                        Handles.color = capNormalColor;
                        if (Handles.Button(middle, Quaternion.identity, capSize, capSize, Handles.DotHandleCap))
                        {
                            selectedNode  = i;
                            _selectedType = 0;
                        }
                    }
                }
            }
コード例 #5
0
            protected override void OnMoveToolSceneGUI(T path)
            {
                if (_showTension)
                {
                    for (int i = 0; i < path.segmentCount; i++)
                    {
                        float tension = path.GetSegmentTension(i);

                        var point1 = path.GetNodePosition(i);
                        var point2 = path.GetNodePosition((i + 1) % path.nodeCount);
                        point1 = point1 * 0.75f + point2 * 0.25f;
                        point2 = point1 / 3f + point2 * (2f / 3f);

                        var point = (point2 - point1) * tension + point1;

                        Handles.color = new Color(1f, 1f, 1f, 0.5f);
                        HandlesKit.DrawAALine(point1, point2, 4);

                        float capSize = HandleUtility.GetHandleSize(point) * FloatingWindow.capSize;

                        using (var scope = new ChangeCheckScope(path))
                        {
                            Handles.color = capNormalColor;
                            point         = Handles.FreeMoveHandle(point, Quaternion.identity, capSize, snap, Handles.CircleHandleCap);

                            tension = MathKit.ClosestPointOnSegmentFactor(point, point1, point2);
                            //tension = (float)Math.Round(tension, 2);

                            //using (new HandlesGUIScope(0))
                            //{
                            //    var pos2D = HandleUtility.WorldToGUIPoint(point);
                            //    var rect = new Rect(pos2D.x + 12, pos2D.y - 9, 32, 18);
                            //    EditorGUI.DrawRect(rect, new Color(0, 0, 0, 0.5f));
                            //    using (new GUIContentColorScope(Color.white))
                            //    {
                            //        EditorGUI.LabelField(rect, tension.ToString(), EditorStyles.whiteLabel);
                            //    }
                            //}

                            if (scope.changed)
                            {
                                path.SetSegmentTension(i, tension);
                            }
                        }
                    }
                }

                int count = path.nodeCount;

                for (int i = 0; i < count; i++)
                {
                    var position = path.GetNodePosition(i);

                    float capSize = HandleUtility.GetHandleSize(position) * FloatingWindow.capSize;

                    if (selectedNode == i)
                    {
                        using (var scope = new ChangeCheckScope(path))
                        {
                            Handles.color = capSelectedColor;
                            if (selectedTool == 0)
                            {
                                position = Handles.FreeMoveHandle(position, Quaternion.identity, capSize * 2, snap, Handles.RectangleHandleCap);
                            }
                            else
                            {
                                position = Handles.PositionHandle(position, path.transform.rotation);
                            }
                            if (scope.changed)
                            {
                                path.SetNodePosition(i, position);
                            }
                        }
                    }
                    else
                    {
                        Handles.color = capNormalColor;
                        if (Handles.Button(position, Quaternion.identity, capSize, capSize, Handles.DotHandleCap))
                        {
                            selectedNode = i;
                        }
                    }
                }
            }