コード例 #1
0
        public override void OnInspectorGUI()
        {
            serializedObject.UpdateIfRequiredOrScript();

            Editor.DrawPropertiesExcluding(serializedObject, "m_Script");

            GUI.enabled = !EditorApplication.isPlaying;
            GUILayout.Label("Presets");

            GUILayout.BeginHorizontal();
            if (GUILayout.Button("4-segment circle"))
            {
                Undo.RecordObject(section, "Set cable section preset");
                section.CirclePreset(4);
                ResetSelection();
            }

            if (GUILayout.Button("8-segment circle"))
            {
                Undo.RecordObject(section, "Set cable section preset");
                section.CirclePreset(8);
                ResetSelection();
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            if (GUILayout.Button("12-segment circle"))
            {
                Undo.RecordObject(section, "Set cable section preset");
                section.CirclePreset(12);
                ResetSelection();
            }

            if (GUILayout.Button("16-segment circle"))
            {
                Undo.RecordObject(section, "Set cable section preset");
                section.CirclePreset(16);
                ResetSelection();
            }
            GUILayout.EndHorizontal();

            GUILayout.Label("Tools");
            if (GUILayout.Button("Add vertex"))
            {
                Undo.RecordObject(section, "Add rope vertex");
                section.vertices.Add(Vector2.zero);
            }

            if (GUILayout.Button("Remove selected vertices"))
            {
                Undo.RecordObject(section, "Remove rope vertices");
                for (int i = selected.Length - 1; i > 0; --i)
                {
                    if (selected[i] && section.vertices.Count > 3)
                    {
                        section.vertices.RemoveAt(i);
                    }
                }
                // special cases: first vertex:
                if (selected[0] && section.vertices.Count > 3)
                {
                    section.vertices.RemoveAt(0);
                    section.vertices[section.vertices.Count - 1] = section.vertices[0];
                }

                ResetSelection();
            }
            GUI.enabled = true;

            // Apply changes to the serializedProperty
            if (GUI.changed)
            {
                serializedObject.ApplyModifiedProperties();
                EditorUtility.SetDirty(target);
            }
        }