public ObiParticleGroup InsertNewParticleGroup(string name, int index)
        {
            if (index >= 0 && index <= groups.Count)
            {
                ObiParticleGroup group = ScriptableObject.CreateInstance <ObiParticleGroup>();
                group.SetSourceBlueprint(this);
                group.name = name;

#if UNITY_EDITOR
                if (!Application.isPlaying)
                {
                    AssetDatabase.AddObjectToAsset(group, this);
                    Undo.RegisterCreatedObjectUndo(group, "Insert particle group");

                    Undo.RecordObject(this, "Insert particle group");
                    groups.Insert(index, group);

                    if (EditorUtility.IsPersistent(this))
                    {
                        EditorUtility.SetDirty(this);
                        AssetDatabase.SaveAssets();
                    }
                }
                else
#endif
                {
                    groups.Insert(index, group);
                }

                return(group);
            }
            return(null);
        }
        private void InitializeGroupsList()
        {
            particleGroupList = new ReorderableList(editor.serializedObject,
                                                    editor.serializedObject.FindProperty("groups"),
                                                    false, true, true, true);

            particleGroupList.drawHeaderCallback = (Rect rect) => {
                EditorGUI.LabelField(rect, "Groups");
            };

            particleGroupList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => {
                var element = particleGroupList.serializedProperty.GetArrayElementAtIndex(index);
                rect.y += 4;

                SerializedObject obj   = new SerializedObject(element.objectReferenceValue);
                ObiParticleGroup group = obj.targetObject as ObiParticleGroup;

                EditorGUI.PropertyField(new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight),
                                        obj.FindProperty("m_Name"), new GUIContent("Name"));
                rect.y += EditorGUIUtility.singleLineHeight + 2;

                if (GUI.Button(new Rect(rect.x, rect.y, rect.width * 0.5f, EditorGUIUtility.singleLineHeight), "Select", EditorStyles.miniButtonLeft))
                {
                    if ((Event.current.modifiers & EventModifiers.Shift) == 0)
                    {
                        for (int p = 0; p < editor.selectionStatus.Length; p++)
                        {
                            editor.selectionStatus[p] = false;
                        }
                    }

                    foreach (int p in group.particleIndices)
                    {
                        editor.selectionStatus[p] = true;
                    }

                    UpdateSelection();
                }

                if (GUI.Button(new Rect(rect.x + rect.width * 0.5f, rect.y, rect.width * 0.5f, EditorGUIUtility.singleLineHeight), "Set", EditorStyles.miniButtonRight))
                {
                    group.particleIndices.Clear();
                    for (int p = 0; p < editor.selectionStatus.Length; p++)
                    {
                        if (editor.selectionStatus[p])
                        {
                            group.particleIndices.Add(p);
                        }
                    }
                }

                obj.ApplyModifiedProperties();
            };

            particleGroupList.elementHeight = (EditorGUIUtility.singleLineHeight + 2) * 2 + 8;

            particleGroupList.onAddCallback = (ReorderableList list) => {
                var group = editor.Blueprint.AppendNewParticleGroup("new group");

                for (int i = 0; i < editor.selectionStatus.Length; i++)
                {
                    if (editor.selectionStatus[i])
                    {
                        group.particleIndices.Add(i);
                    }
                }

                AssetDatabase.SaveAssets();
            };

            particleGroupList.onRemoveCallback = (ReorderableList list) => {
                editor.Blueprint.RemoveParticleGroupAt(list.index);
            };
        }