Пример #1
0
        private void ShowLength(SplineBase spline, int curveIndex, GUIStyle style)
        {
            float distance     = spline.EvalDistance(curveIndex);
            float curveLength  = spline.EvalCurveLength(curveIndex, GetStepsPerCurve());
            float splineLength = spline.EvalSplineLength(GetStepsPerCurve());

            Handles.Label(spline.GetPoint(0.5f, curveIndex), string.Format("D: {0:0.00} m, C: {1:0.00} m, S: {2:0.00}", distance, curveLength, splineLength), style);
        }
Пример #2
0
        public void OnFork(ForkEventArgs args)
        {
            float min      = float.MaxValue;
            int   minIndex = -1;

            if (args.NextCurveIndex != -1)
            {
                min = args.Spline.EvalCurveLength(args.NextCurveIndex);
            }

            for (int i = 0; i < args.Branches.Length; ++i)
            {
                SplineBase branch = args.Branches[i];
                float      len    = branch.EvalCurveLength(0);
                if (len < min)
                {
                    min      = len;
                    minIndex = i;
                }
            }

            args.SelectBranchIndex = minIndex;
        }
        private void ShowPoint(int index, Vector3 point)
        {
            if (!CanShowPoint(index))
            {
                return;
            }

            Handles.color = ModeColors[(int)m_splineBase.GetControlPointMode(index)];
            if (index % 3 == 0)
            {
                Handles.color = Color.green;
            }

            float size = HandleUtility.GetHandleSize(point);

            Handles.CapFunction dcf = Handles.DotHandleCap;

            if (index == 0)
            {
                size *= 2f;
            }

            if (Handles.Button(point, m_handleRotation, size * HandleSize, size * PickSize, dcf))
            {
                m_selectedIndex = index;

                SplineControlPoint controlPoint = m_splineBase.GetComponentsInChildren <SplineControlPoint>(true).Where(cpt => cpt.Index == index).FirstOrDefault();
                if (controlPoint != null)
                {
                    if (Event.current.control || Event.current.shift)
                    {
                        GameObject[] objects = Selection.gameObjects;
                        Selection.activeGameObject = controlPoint.gameObject;
                        if (!objects.Contains(controlPoint.gameObject))
                        {
                            ArrayUtility.Add(ref objects, controlPoint.gameObject);
                        }
                        else
                        {
                            if (!Event.current.shift)
                            {
                                ArrayUtility.Remove(ref objects, controlPoint.gameObject);
                            }
                        }

                        Selection.objects = objects;
                    }
                    else
                    {
                        Selection.activeGameObject = controlPoint.gameObject;
                    }
                }

                Repaint();
            }

            if (m_selectedIndex == index)
            {
                int curveIndex     = (m_selectedIndex - 1) / 3;
                int prevCurveIndex = curveIndex - 1;
                int nextCurveIndex = curveIndex + 1;
                if (m_splineBase.Loop)
                {
                    if (prevCurveIndex < 0)
                    {
                        prevCurveIndex = m_splineBase.CurveCount - 1;
                    }

                    if (nextCurveIndex > m_splineBase.CurveCount - 1)
                    {
                        nextCurveIndex = 0;
                    }
                }


                GUIStyle style = new GUIStyle();
                style.normal.textColor = Color.green;

                if (prevCurveIndex >= 0)
                {
                    float prevLen = m_splineBase.EvalLength(prevCurveIndex);
                    float prevCur = m_splineBase.EvalCurveLength(prevCurveIndex, GetStepsPerCurve());
                    Handles.Label(m_splineBase.GetPoint(0.5f, prevCurveIndex), string.Format("Len: {0:0.00} m, Cur: {1:0.00} m", prevLen, prevCur), style);
                }
                if (nextCurveIndex < m_splineBase.CurveCount)
                {
                    float nextLen = m_splineBase.EvalLength(nextCurveIndex);
                    float nextCur = m_splineBase.EvalCurveLength(nextCurveIndex, GetStepsPerCurve());
                    Handles.Label(m_splineBase.GetPoint(0.5f, nextCurveIndex), string.Format("Len: {0:0.00} m, Cur: {1:0.00} m", nextLen, nextCur), style);
                }

                float cur = m_splineBase.EvalCurveLength(curveIndex, GetStepsPerCurve());
                float len = m_splineBase.EvalLength(curveIndex);
                Handles.Label(m_splineBase.GetPoint(0.5f, curveIndex), string.Format("Len: {0:0.00} m, Cur: {1:0.00} m", len, cur), style);
            }
        }
Пример #4
0
        private void ShowPoint(int index, Vector3 point)
        {
            if (!CanShowPoint(index))
            {
                return;
            }

            Handles.color = ModeColors[(int)m_splineBase.GetControlPointMode(index)];
            if (index % 3 == 0)
            {
                Handles.color = Color.green;
            }

            float size = HandleUtility.GetHandleSize(point);

            Handles.DrawCapFunction dcf = Handles.DotCap;

            if (index == 0)
            {
                size *= 2f;
            }

            if (Handles.Button(point, m_handleRotation, size * HandleSize, size * PickSize, dcf))
            {
                m_selectedIndex = index;

                SplineControlPoint controlPoint = m_splineBase.GetComponentsInChildren <SplineControlPoint>(true).Where(cpt => cpt.Index == index).FirstOrDefault();
                if (controlPoint != null)
                {
                    Selection.activeGameObject = controlPoint.gameObject;
                }



                Repaint();
            }

            if (m_selectedIndex == index)
            {
                int curveIndex     = (m_selectedIndex - 1) / 3;
                int prevCurveIndex = curveIndex - 1;
                int nextCurveIndex = curveIndex + 1;
                if (m_splineBase.Loop)
                {
                    if (prevCurveIndex < 0)
                    {
                        prevCurveIndex = m_splineBase.CurveCount - 1;
                    }

                    if (nextCurveIndex > m_splineBase.CurveCount - 1)
                    {
                        nextCurveIndex = 0;
                    }
                }


                GUIStyle style = new GUIStyle();
                style.normal.textColor = Color.green;

                if (prevCurveIndex >= 0)
                {
                    float prevLen = m_splineBase.EvalLength(prevCurveIndex);
                    float prevCur = m_splineBase.EvalCurveLength(prevCurveIndex, GetStepsPerCurve());
                    Handles.Label(m_splineBase.GetPoint(0.5f, prevCurveIndex), string.Format("Len: {0:0.00} m, Cur: {1:0.00} m", prevLen, prevCur), style);
                }
                if (nextCurveIndex < m_splineBase.CurveCount)
                {
                    float nextLen = m_splineBase.EvalLength(nextCurveIndex);
                    float nextCur = m_splineBase.EvalCurveLength(nextCurveIndex, GetStepsPerCurve());
                    Handles.Label(m_splineBase.GetPoint(0.5f, nextCurveIndex), string.Format("Len: {0:0.00} m, Cur: {1:0.00} m", nextLen, nextCur), style);
                }

                float cur = m_splineBase.EvalCurveLength(curveIndex, GetStepsPerCurve());
                float len = m_splineBase.EvalLength(curveIndex);
                Handles.Label(m_splineBase.GetPoint(0.5f, curveIndex), string.Format("Len: {0:0.00} m, Cur: {1:0.00} m", len, cur), style);

                EditorGUI.BeginChangeCheck();
                point = Handles.DoPositionHandle(point, m_handleRotation);
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(m_splineBase, UNDO_MOVEPOINT);
                    EditorUtility.SetDirty(m_splineBase);
                    m_splineBase.SetControlPointLocal(index, m_handleTransform.InverseTransformPoint(point));
                }
            }
        }