Пример #1
0
        public SplineContent GetPoint(int index)
        {
            if (index < 0 || index >= Count)
            {
                return(null);
            }
            PointInfo info = GetPointInfo(index);

            SplineContent content = new SplineContent(this[index], info, index, _spline.GetInstanceID());

            return(content);
        }
Пример #2
0
        public SplineContent[] GetPoints(PointInfo filter = PointInfo.Reference)
        {
            int n = Count;
            List <SplineContent> result = new List <SplineContent>();

            for (int i = 0; i < n; i++)
            {
                PointInfo info = GetPointInfo(i);
                if ((info & filter) == 0)
                {
                    continue;
                }
                SplineContent content = new SplineContent(this[i], info, i, _spline.GetInstanceID());
                result.Add(content);
            }
            return(result.ToArray());
        }
Пример #3
0
        public SplineContent[] GetPoints(int[] indexes)
        {
            int n = indexes.Length;

            SplineContent[] result = new SplineContent[indexes.Length];
            for (int i = 0; i < n; i++)
            {
                int index = indexes[i];
                if (index < 0 || index >= Count)
                {
                    continue;
                }
                PointInfo info = GetPointInfo(index);

                SplineContent content = new SplineContent(this[index], info, index, _spline.GetInstanceID());
                result[i] = content;
            }
            return(result.ToArray());
        }
Пример #4
0
        public static bool PointTypeControls(SplineContent point, out PointInfo info, int count)
        {
            Rect controlsRect = EditorGUILayout.GetControlRect(false, 23f);
            Rect position     = new Rect(controlsRect.xMin, controlsRect.yMin,
                                         EditorGUIUtility.currentViewWidth / 4, 23f);

            //Parse flags to bools
            var isRef         = (point.Info & PointInfo.Reference) == PointInfo.Reference;
            var isMagnet      = (point.Info & PointInfo.Sticky) == PointInfo.Sticky;
            var typeSelection = (point.Info & PointInfo.Cubiq) == PointInfo.Cubiq
                ? 2 : (point.Info & PointInfo.Quadratic) == PointInfo.Quadratic ? 1 : 0;

            bool needToUpdate = false;

            //Parse bools to flags
            info = isRef ? PointInfo.Reference : PointInfo.Control;
            //Draw controls
            if (isRef && point.Index < count - 1)
            {
                EditorGUI.BeginChangeCheck();
                typeSelection = GUI.Toolbar(position, typeSelection, _typeControls, ButtonStyle);
                needToUpdate  = EditorGUI.EndChangeCheck();
                position.x    = position.x + EditorGUIUtility.currentViewWidth / 4 + 10F;
            }
            position.width = 23f;

            EditorGUI.BeginChangeCheck();
            isMagnet = GUI.Toggle(position, isMagnet, _magnetButton, ButtonStyle);
            if (EditorGUI.EndChangeCheck())
            {
                needToUpdate = true;
            }
            //build new flags
            if (isMagnet)
            {
                info |= PointInfo.Sticky;
            }
            info |= typeSelection == 0 ? PointInfo.Linear :
                    typeSelection == 1 ? PointInfo.Quadratic : PointInfo.Cubiq;
            return(needToUpdate);
        }
Пример #5
0
        public SplineContent[] GetSegments(PointInfo filter =
                                           PointInfo.Linear | PointInfo.Quadratic | PointInfo.Cubiq)
        {
            int n = SegmentsCount;
            List <SplineContent> result = new List <SplineContent>();

            for (int i = 0; i < n; i++)
            {
                int       index = i * (Spline.SLen - 1);
                PointInfo info  = GetPointInfo(index);
                if ((info & filter) == 0)
                {
                    continue;
                }
                SplineContent content = new SplineContent(
                    this[index], this[index + 1], this[index + 2], this[index + 3],
                    info, index, _spline.GetInstanceID());
                result.Add(content);
            }
            return(result.ToArray());
        }
Пример #6
0
        public static void DrawSegment(SplineContent segment, Color color, bool dotted = false)
        {
            float weight  = SPSettings.Current.LineWeight;
            var   current = Handles.color;

            Handles.color = color;
            if ((segment.Info & PointInfo.Linear) == PointInfo.Linear)
            {
                if (dotted)
                {
                    Handles.DrawDottedLine(segment.P0, segment.P3, 5F);
                }
                else
                {
                    Handles.DrawLine(segment.P0, segment.P3);
                }
            }
            else
            {
                Handles.DrawBezier(segment.P0, segment.P3, segment.P1,
                                   segment.P2, color, null, weight);
            }
            Handles.color = current;
        }