예제 #1
0
    private void OnSceneGUI()
    {
        int   controlID = GUIUtility.GetControlID(FocusType.Passive);
        Event e         = Event.current;


        float hit = 100f;
        Ray   ray = HandleUtility.GUIPointToWorldRay(e.mousePosition);

        if (plane.Raycast(ray, out hit))
        {
            Vector3 relativePoint = ray.GetPoint(hit);
            Handles.color = Color.green;
            if (m_toggleAddPoints)
            {
                HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive));


                SerializedProperty sp        = m_points.GetArrayElementAtIndex(m_points.arraySize - 1);
                Transform          tp        = (Transform)sp.objectReferenceValue;
                Vector3            lastPoint = tp.position;
                Handles.DrawLine(lastPoint, relativePoint);
                switch (e.GetTypeForControl(controlID))
                {
                case EventType.MouseDown:
                    if (e.button == 0 && !e.alt && !e.control && !e.shift)
                    {
                        m_generator.AddTubePoint(relativePoint);
                        m_generator.RebuildMesh();
                    }
                    break;

                case EventType.Layout:
                    HandleUtility.AddDefaultControl(controlID);
                    break;
                }
            }
        }
    }