void OnEnable()
    {
        curveLineRenderer = (CurveLineRenderer)target;

        handleTransform = curveLineRenderer.transform;
        handleRotation  = Tools.pivotRotation == PivotRotation.Local
            ? handleTransform.rotation : Quaternion.identity;
        handleMeshFilter   = curveLineRenderer.GetComponent <MeshFilter>();
        handleMeshCollider = curveLineRenderer.GetComponent <MeshCollider>();

        SceneView.onSceneGUIDelegate = OnSceneDraw;
        RebuildMesh();
    }
    void RebuildMesh()
    {
        if (handleMeshFilter == null || curveLineRenderer == null)
        {
            return;
        }

        Mesh mesh = handleMeshFilter.sharedMesh;

        if (mesh == null)
        {
            mesh      = new Mesh();
            mesh.name = "Curve Line Mesh";
            handleMeshFilter.sharedMesh = mesh;
        }

        Material[] materials = curveLineRenderer.GetComponent <MeshRenderer>().sharedMaterials;
        for (int i = 0; i < materials.Length; ++i)
        {
            if (materials[i].mainTexture.wrapMode != TextureWrapMode.Repeat)
            {
                Debug.LogWarning("Main texture of " + materials[i].name + " should have 'Repeat' wrap mode");
            }
        }
        ;

        curveLineRenderer.Rebuild(mesh, handleMeshCollider);
    }