/// <summary>
        /// Sets the current index for use in route traversal
        /// </summary>
        /// <param name="valueWaypoint">Interface to modify</param>
        /// <param name="controlSection">Current control section will be set by calculation</param>
        internal static void CalculateCurrentIndex(IValueSmoothWaypoint valueWaypoint, out CurveControlSection controlSection)
        {
            IControlNode[] controlNodes = new IControlNode[valueWaypoint.nodes.Length];
            for (int i = 0; i < valueWaypoint.nodes.Length; i++)
            {
                controlNodes[i] = ControlNode.CreateNode(i, valueWaypoint.nodes[i], Quaternion.identity, valueWaypoint.curveScales[i]);
            }
            CurveControlSection[] controlSections = CurveControlArgs.GetComputedAndSlicedSections(new CurveControlArgs(controlNodes, true));
            controlSection = controlSections[valueWaypoint.minIndex];

            float routeTime = (valueWaypoint.minIndex + valueWaypoint.current) / controlSections.Length;

            valueWaypoint.currentIndex = (int)(controlSections.Length * routeTime);
        }
Пример #2
0
        /// <summary>
        /// Draws scene view handles
        /// </summary>
        protected override void OnSceneGUI()
        {
            base.OnSceneGUI();
            IValueSmoothWaypoint valueSmoothWaypoint = m_MemberTarget.valueControl as IValueSmoothWaypoint;

            ValueWaypointEditorUtils.SelectionHandles(valueSmoothWaypoint, target, transform, m_ReorderableSmoothWaypoint.index);

            Color color = Handles.color;

            Handles.color = Color.green;

            if (valueSmoothWaypoint.selectionType != SelectionType.None)
            {
                IControlNode[] controlNodes = new IControlNode[valueSmoothWaypoint.nodes.Length];
                for (int i = 0; i < valueSmoothWaypoint.nodes.Length; i++)
                {
                    controlNodes[i] = ControlNode.CreateNode(i, valueSmoothWaypoint.nodes[i], Quaternion.identity, valueSmoothWaypoint.curveScales[i]);
                }

                var   controlSections = CurveControlArgs.GetComputedAndSlicedSections(new CurveControlArgs(controlNodes, true));
                float lineWidth       = 2;
                for (int i = 0; i < controlSections.Length; i++)
                {
                    var item = controlSections[i];
                    Handles.DrawBezier(item.p0.position,
                                       item.p1.position,
                                       item.q0.position,
                                       item.q1.position,
                                       Handles.color,
                                       null,
                                       lineWidth);
                }

                m_ReorderableSmoothWaypoint.SceneViewDrawSelected(valueSmoothWaypoint, Color.yellow);
                m_ReorderableSmoothWaypoint.SceneViewCreateWaypoint(valueSmoothWaypoint);
            }

            Handles.color = color;
        }