Beispiel #1
0
    private void DrawSelectedPointInspector()
    {
        GUILayout.Label("-----Selected Point-----");

        EditorGUI.BeginChangeCheck();
        // Display the vector of the selected point in the inspector.
        Vector3 point = EditorGUILayout.Vector3Field("Position", m_path.GetControlPoint(m_selectedIndex));

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(m_path, "Move Point");
            m_path.SetControlPoint(m_selectedIndex, point);
            EditorUtility.SetDirty(m_path);
        }

        if (GUILayout.Button("Insert Point"))
        {
            Undo.RecordObject(m_path, "Insert Point");
            m_path.AddPoint(m_selectedIndex);
            EditorUtility.SetDirty(m_path);
        }

        if (m_path.ControlPointCount > 0)
        {
            if (GUILayout.Button("Remove Selected Point"))
            {
                Undo.RecordObject(m_path, "Remove Point");
                m_path.RemovePoint(m_selectedIndex);
                EditorUtility.SetDirty(m_path);
            }
        }
    }
Beispiel #2
0
    public override void OnInspectorGUI()
    {
        m_path = target as LinearPath;

        EditorGUI.BeginChangeCheck();
        bool loop = EditorGUILayout.Toggle("Loop", m_path.Loop);

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(m_path, "Toggle Loop");
            EditorUtility.SetDirty(m_path);
            m_path.Loop = loop;
        }

        // Do we have a point selected?
        if (m_selectedIndex >= 0 && m_selectedIndex < m_path.ControlPointCount)
        {
            DrawSelectedPointInspector();
        }
        else
        {
            // Add and remove only affect the end of the path.
            if (GUILayout.Button("Add Point"))
            {
                Undo.RecordObject(m_path, "Add Point");
                m_path.AddPoint(m_path.ControlPointCount - 1);
                EditorUtility.SetDirty(m_path);
            }

            if (m_path.ControlPointCount > 0)
            {
                if (GUILayout.Button("Remove Point"))
                {
                    Undo.RecordObject(m_path, "Remove Point");
                    m_path.RemovePoint(m_path.ControlPointCount - 1);
                    EditorUtility.SetDirty(m_path);
                }
            }
        }
    }