public static void ResetList(ActionList _target) { if (_target.actions.Count == 0 || (_target.actions.Count == 1 && _target.actions[0] == null)) { _target.actions.Clear(); AC.Action newAction = ActionList.GetDefaultAction(); _target.actions.Add(newAction); } }
public static void ResetList(ActionListAsset _targetAsset) { if (_targetAsset.actions.Count == 0 || (_targetAsset.actions.Count == 1 && _targetAsset.actions[0] == null)) { if (_targetAsset.actions.Count == 1) { ActionListAssetEditor.DeleteAction(_targetAsset.actions[0], _targetAsset); } Action newAction = ActionList.GetDefaultAction(); _targetAsset.actions.Add(newAction); newAction.hideFlags = HideFlags.HideInHierarchy; AssetDatabase.AddObjectToAsset(newAction, _targetAsset); AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(newAction)); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); } }
protected void DrawSharedElements(ActionList _target) { if (PrefabUtility.GetPrefabType(_target) == PrefabType.Prefab) { EditorGUILayout.HelpBox("Scene-based Actions can not live in prefabs - use ActionList assets instead.", MessageType.Info); return; } int numActions = 0; if (_target.source != ActionListSource.AssetFile) { numActions = _target.actions.Count; if (numActions < 1) { numActions = 1; AC.Action newAction = ActionList.GetDefaultAction(); _target.actions.Add(newAction); } } EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); if (_target.source == ActionListSource.AssetFile) { GUI.enabled = false; } if (GUILayout.Button("Expand all", EditorStyles.miniButtonLeft)) { Undo.RecordObject(_target, "Expand actions"); foreach (AC.Action action in _target.actions) { action.isDisplayed = true; } } if (GUILayout.Button("Collapse all", EditorStyles.miniButtonMid)) { Undo.RecordObject(_target, "Collapse actions"); foreach (AC.Action action in _target.actions) { action.isDisplayed = false; } } GUI.enabled = true; if (GUILayout.Button("Action List Editor", EditorStyles.miniButtonMid)) { if (_target.source == ActionListSource.AssetFile) { if (_target.assetFile != null) { ActionListEditorWindow.Init(_target.assetFile); } } else { ActionListEditorWindow.Init(_target); } } if (!Application.isPlaying) { GUI.enabled = false; } if (GUILayout.Button("Run now", EditorStyles.miniButtonRight)) { _target.Interact(); } GUI.enabled = true; EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); if (_target.source == ActionListSource.AssetFile) { return; } ActionListEditor.ResetList(_target); if (actionsManager == null) { EditorGUILayout.HelpBox("An Actions Manager asset file must be assigned in the Game Editor Window", MessageType.Warning); OnEnable(); return; } if (!actionsManager.displayActionsInInspector) { EditorGUILayout.HelpBox("As set by the Actions Manager, Actions are only displayed in the ActionList Editor window.", MessageType.Info); return; } for (int i = 0; i < _target.actions.Count; i++) { if (_target.actions[i] == null) { ACDebug.LogWarning("An empty Action was found, and was deleted"); _target.actions.RemoveAt(i); continue; } EditorGUILayout.BeginVertical("Button"); EditorGUILayout.BeginHorizontal(); int typeIndex = KickStarter.actionsManager.GetActionTypeIndex(_target.actions[i]); string actionLabel = " (" + (i).ToString() + ") " + actionsManager.EnabledActions[typeIndex].GetFullTitle() + _target.actions[i].SetLabel(); _target.actions[i].isDisplayed = EditorGUILayout.Foldout(_target.actions[i].isDisplayed, actionLabel); if (!_target.actions[i].isEnabled) { EditorGUILayout.LabelField("DISABLED", EditorStyles.boldLabel, GUILayout.MaxWidth(100f)); } if (GUILayout.Button(Resource.CogIcon, GUILayout.Width(20f), GUILayout.Height(15f))) { ActionSideMenu(i); } _target.actions[i].isAssetFile = false; EditorGUILayout.EndHorizontal(); if (_target.actions[i].isBreakPoint) { EditorGUILayout.HelpBox("Break point", MessageType.None); } if (_target.actions[i].isDisplayed) { GUI.enabled = _target.actions[i].isEnabled; if (!actionsManager.DoesActionExist(_target.actions[i].GetType().ToString())) { EditorGUILayout.HelpBox("This Action type has been disabled in the Actions Manager", MessageType.Warning); } else { int newTypeIndex = ActionListEditor.ShowTypePopup(_target.actions[i], typeIndex); if (newTypeIndex >= 0) { // Rebuild constructor if Subclass and type string do not match ActionEnd _end = new ActionEnd(); _end.resultAction = _target.actions[i].endAction; _end.skipAction = _target.actions[i].skipAction; _end.linkedAsset = _target.actions[i].linkedAsset; _end.linkedCutscene = _target.actions[i].linkedCutscene; Undo.RecordObject(_target, "Change Action type"); _target.actions[i] = ActionListEditor.RebuildAction(_target.actions[i], newTypeIndex, _end.resultAction, _end.skipAction, _end.linkedAsset, _end.linkedCutscene); } if (_target.useParameters && _target.parameters != null && _target.parameters.Count > 0) { _target.actions[i].ShowGUI(_target.parameters); } else { _target.actions[i].ShowGUI(null); } } } if (_target.actions[i].endAction == AC.ResultAction.Skip || _target.actions[i].numSockets == 2 || _target.actions[i] is ActionCheckMultiple || _target.actions[i] is ActionParallel) { _target.actions[i].SkipActionGUI(_target.actions, _target.actions[i].isDisplayed); } GUI.enabled = true; EditorGUILayout.EndVertical(); EditorGUILayout.Space(); } if (GUILayout.Button("Add new action")) { Undo.RecordObject(_target, "Create action"); numActions += 1; } _target.actions = ActionListEditor.ResizeList(_target.actions, numActions); }
public static void ModifyAction(ActionList _target, AC.Action _action, string callback) { int i = -1; if (_action != null && _target.actions.IndexOf(_action) > -1) { i = _target.actions.IndexOf(_action); } switch (callback) { case "Enable": Undo.RecordObject(_target, "Enable action"); _action.isEnabled = true; break; case "Disable": Undo.RecordObject(_target, "Disable action"); _action.isEnabled = false; break; case "Cut": Undo.RecordObject(_target, "Cut action"); List <AC.Action> cutList = new List <AC.Action>(); AC.Action cutAction = Object.Instantiate(_action) as AC.Action; cutList.Add(cutAction); AdvGame.copiedActions = cutList; _target.actions.Remove(_action); break; case "Copy": List <AC.Action> copyList = new List <AC.Action>(); AC.Action copyAction = Object.Instantiate(_action) as AC.Action; copyAction.ClearIDs(); copyAction.nodeRect = new Rect(0, 0, 300, 60); copyList.Add(copyAction); AdvGame.copiedActions = copyList; break; case "Paste after": Undo.RecordObject(_target, "Paste actions"); List <AC.Action> pasteList = AdvGame.copiedActions; _target.actions.InsertRange(i + 1, pasteList); AdvGame.DuplicateActionsBuffer(); break; case "Insert end": Undo.RecordObject(_target, "Create action"); AC.Action newAction = ActionList.GetDefaultAction(); _target.actions.Add(newAction); break; case "Insert after": Undo.RecordObject(_target, "Create action"); _target.actions.Insert(i + 1, ActionList.GetDefaultAction()); break; case "Delete": Undo.RecordObject(_target, "Delete action"); _target.actions.Remove(_action); break; case "Move to top": Undo.RecordObject(_target, "Move action to top"); _target.actions[0].nodeRect.x += 30f; _target.actions[0].nodeRect.y += 30f; _target.actions.Remove(_action); _target.actions.Insert(0, _action); break; case "Move up": Undo.RecordObject(_target, "Move action up"); _target.actions.Remove(_action); _target.actions.Insert(i - 1, _action); break; case "Move to bottom": Undo.RecordObject(_target, "Move action to bottom"); _target.actions.Remove(_action); _target.actions.Insert(_target.actions.Count, _action); break; case "Move down": Undo.RecordObject(_target, "Move action down"); _target.actions.Remove(_action); _target.actions.Insert(i + 1, _action); break; case "Toggle breakpoint": Undo.RecordObject(_target, "Toggle breakpoint"); _action.isBreakPoint = !_action.isBreakPoint; break; } }
public static void ModifyAction(ActionList _target, AC.Action _action, string callback) { int i = -1; if (_action != null && _target.actions.IndexOf(_action) > -1) { i = _target.actions.IndexOf(_action); } bool doUndo = (callback != "Copy"); if (doUndo) { Undo.SetCurrentGroupName(callback); Undo.RecordObjects(new UnityEngine.Object [] { _target }, callback); Undo.RecordObjects(_target.actions.ToArray(), callback); } switch (callback) { case "Enable": _action.isEnabled = true; break; case "Disable": _action.isEnabled = false; break; case "Cut": List <AC.Action> cutList = new List <AC.Action>(); AC.Action cutAction = Object.Instantiate(_action) as AC.Action; cutAction.name = cutAction.name.Replace("(Clone)", ""); cutList.Add(cutAction); AdvGame.copiedActions = cutList; _target.actions.Remove(_action); break; case "Copy": List <AC.Action> copyList = new List <AC.Action>(); AC.Action copyAction = Object.Instantiate(_action) as AC.Action; copyAction.name = copyAction.name.Replace("(Clone)", ""); copyAction.ClearIDs(); copyAction.nodeRect = new Rect(0, 0, 300, 60); copyList.Add(copyAction); AdvGame.copiedActions = copyList; break; case "Paste after": List <AC.Action> pasteList = AdvGame.copiedActions; _target.actions.InsertRange(i + 1, pasteList); AdvGame.DuplicateActionsBuffer(); break; case "Insert end": AC.Action newAction = ActionList.GetDefaultAction(); _target.actions.Add(newAction); break; case "Insert after": Action insertAfterAction = ActionList.GetDefaultAction(); _target.actions.Insert(i + 1, insertAfterAction); insertAfterAction.endAction = _action.endAction; insertAfterAction.skipAction = -1; insertAfterAction.skipActionActual = _action.skipActionActual; break; case "Delete": Undo.RecordObject(_target, "Delete action"); _target.actions.Remove(_action); break; case "Move to top": _target.actions[0].nodeRect.x += 30f; _target.actions[0].nodeRect.y += 30f; _target.actions.Remove(_action); _target.actions.Insert(0, _action); break; case "Move up": _target.actions.Remove(_action); _target.actions.Insert(i - 1, _action); break; case "Move to bottom": _target.actions.Remove(_action); _target.actions.Insert(_target.actions.Count, _action); break; case "Move down": _target.actions.Remove(_action); _target.actions.Insert(i + 1, _action); break; case "Toggle breakpoint": _action.isBreakPoint = !_action.isBreakPoint; break; } if (doUndo) { Undo.RecordObjects(new UnityEngine.Object [] { _target }, callback); Undo.RecordObjects(_target.actions.ToArray(), callback); Undo.CollapseUndoOperations(Undo.GetCurrentGroup()); EditorUtility.SetDirty(_target); } }