Esempio n. 1
0
        /// <summary>
        /// Adds a new control point to the scene view and its drag point data
        /// to the game object.
        /// </summary>
        public void AddDragPointOnTraveller()
        {
            if (CurveTravellerControlPointIdx < 0 || CurveTravellerControlPointIdx >= ControlPoints.Count)
            {
                return;
            }

            var dragPoint = new DragPointData(DragPointEditable.GetDragPoints()[CurveTravellerControlPointIdx])
            {
                IsLocked = false
            };

            var   newIdx            = CurveTravellerControlPointIdx + 1;
            float ratio             = (float)newIdx / (DragPointEditable.GetDragPoints().Length - 1);
            var   dragPointPosition = Transform.worldToLocalMatrix.MultiplyPoint(CurveTravellerPosition);

            dragPointPosition -= DragPointEditable.GetEditableOffset();
            dragPointPosition -= DragPointEditable.GetDragPointOffset(ratio);
            dragPoint.Vertex   = dragPointPosition.ToVertex3D();
            var dragPoints = DragPointEditable.GetDragPoints().ToList();

            dragPoints.Insert(newIdx, dragPoint);
            DragPointEditable.SetDragPoints(dragPoints.ToArray());

            ControlPoints.Insert(newIdx,
                                 new ControlPoint(
                                     DragPointEditable.GetDragPoints()[newIdx],
                                     GUIUtility.GetControlID(FocusType.Passive),
                                     newIdx,
                                     ratio
                                     ));
            RebuildControlPoints();
        }
Esempio n. 2
0
        /// <summary>
        /// References drag point data to control points.
        /// </summary>
        /// <returns>True if control points were re-built, false otherwise.</returns>
        public bool RemapControlPoints()
        {
            // if count differs, rebuild
            if (ControlPoints.Count != DragPointEditable.GetDragPoints().Length)
            {
                RebuildControlPoints();
                return(true);
            }

            for (var i = 0; i < DragPointEditable.GetDragPoints().Length; ++i)
            {
                ControlPoints[i].DragPoint = DragPointEditable.GetDragPoints()[i];
            }

            return(false);
        }
Esempio n. 3
0
        /// <summary>
        /// Re-creates the control points of the scene view and references their
        /// drag point data.
        /// </summary>
        private void RebuildControlPoints()
        {
            ControlPoints.Clear();

            for (var i = 0; i < DragPointEditable.GetDragPoints().Length; ++i)
            {
                var cp = new ControlPoint(
                    DragPointEditable.GetDragPoints()[i],
                    GUIUtility.GetControlID(FocusType.Passive),
                    i,
                    DragPointEditable.GetDragPoints().Length >= 2 ? (float)i / (DragPointEditable.GetDragPoints().Length - 1) : 0.0f
                    );
                ControlPoints.Add(cp);
            }

            CurveTravellerControlId = GUIUtility.GetControlID(FocusType.Passive);
        }
Esempio n. 4
0
        /// <summary>
        /// Removes a control point and its data.
        /// </summary>
        /// <param name="controlId"></param>
        public void RemoveDragPoint(int controlId)
        {
            var idx = ControlPoints.FindIndex(controlPoint => controlPoint.ControlId == controlId);

            if (idx >= 0)
            {
                var removalOk = !ControlPoints[idx].DragPoint.IsLocked;
                if (!removalOk)
                {
                    removalOk = EditorUtility.DisplayDialog("Locked DragPoint Removal", "This drag point is locked!\nAre you really sure you want to remove it?", "Yes", "No");
                }

                if (removalOk)
                {
                    var dragPoints = DragPointEditable.GetDragPoints().ToList();
                    dragPoints.RemoveAt(idx);
                    DragPointEditable.SetDragPoints(dragPoints.ToArray());
                    ControlPoints.RemoveAt(idx);
                    RebuildControlPoints();
                }
            }
        }