2018-10-18 【UnityEditor】贝塞尔曲线查看小工具

2018-10-18 【UnityEditor】贝塞尔曲线查看小工具_第1张图片
image.png

调整点位置,点击曲线物体,可以查看物体位置是否正确

    using System.Collections;
    using System.Collections.Generic;
    using UnityEditor;
    using UnityEngine;

    namespace WenTools
    {
        [CustomEditor(typeof(BezielObj))]
        public class ShowBeziel : Editor
        {
            BezielObj m_selectBeziel;

            Transform[] m_bezielPoints;

            private void OnEnable()
            {
                //包含该组件的物体被选中时调用
                m_selectBeziel = target as BezielObj;
                Debug.Log("Beziel : " + m_selectBeziel.name);

                if(m_selectBeziel != null)
                {
                    DrawLine(m_selectBeziel);
                }
            }

            private void DrawLine(BezielObj beziel)
            {
                m_bezielPoints = beziel.GetComponentsInChildren();
                Vector3 p0 = m_bezielPoints[1].position;
                Vector3 p1 = m_bezielPoints[2].position;
                Vector3 p2 = m_bezielPoints[3].position;
                Vector3 p3 = m_bezielPoints[4].position;

                Vector3 pstart = p0;
                Vector3 pend = Vector3.zero;

                for (float i = 0.01f; i < 1; i += 0.01f)
                {
                    pend = StaticFunctions.BezierCurve(p0, p1, p2, p3, i);
                    Debug.DrawLine(pstart, pend, Color.yellow, 0.1f);
                    pstart = pend;
                }
            }

        }
    }

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class BezielObj : MonoBehaviour {

    }

你可能感兴趣的:(2018-10-18 【UnityEditor】贝塞尔曲线查看小工具)