public void RemoveAction(int index) { BaseCutsceneAction action = actions[index]; actions.Remove(action); AssetDatabase.RemoveObjectFromAsset(action); AssetDatabase.SaveAssets(); }
public override void OnInspectorGUI() { CutsceneDetails obj = serializedObject.targetObject as CutsceneDetails; for (int i = 0; i < obj.actions.Count; ++i) { SerializedProperty property = serializedObject.FindProperty($"actions.Array.data[{i}]"); if (property != null) { BaseCutsceneAction act = property.objectReferenceValue as BaseCutsceneAction; if (i >= collapse.Count) { collapse.Add(false); } EditorGUILayout.BeginHorizontal(); collapse[i] = EditorGUILayout.Foldout(collapse[i], act.GetEditorName()); if (GUILayout.Button("X")) { collapse.RemoveAt(i); RemoveAction(obj, i); EditorGUILayout.EndHorizontal(); continue; } if (GUILayout.Button("Up")) { if (i > 0) { obj.actions.RemoveAt(i); obj.actions.Insert(i - 1, act); } } if (GUILayout.Button("Down")) { if (i < obj.actions.Count - 1) { obj.actions.RemoveAt(i); obj.actions.Insert(i + 1, act); } } EditorGUILayout.EndHorizontal(); if (collapse[i]) { EditorGUI.indentLevel++; EditorGUILayout.PropertyField(property); EditorGUI.indentLevel--; } } } EditorGUILayout.LabelField("Add Action"); EditorGUI.indentLevel++; EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Action Type"); typeSelected = (CutsceneActionType)EditorGUILayout.EnumPopup(typeSelected); EditorGUILayout.EndHorizontal(); switch (typeSelected) { case CutsceneActionType.SwitchScene: AddActionButton <SwitchSceneCutsceneAction>(obj, "Add Scene Switch", "SwitchScene"); break; case CutsceneActionType.Dialogue: AddActionButton <DialogueCutsceneAction>(obj, "Add Dialogue Action", "StartDialogue"); break; case CutsceneActionType.PassTime: AddActionButton <PassTimeCutsceneAction>(obj, "Add Pass Time Action", "Pass Time"); break; case CutsceneActionType.SetPlayerAnimation: AddActionButton <SetPlayerAnimationAction>(obj, "Add Set Player Animation", "Set Player Animation"); break; case CutsceneActionType.ModalPopup: AddActionButton <ModalPopupAction>(obj, "Add Modal Popup", "Modal Popup"); break; } EditorGUI.indentLevel--; serializedObject.ApplyModifiedProperties(); serializedObject.Update(); EditorUtility.SetDirty(obj); }