public static AC.Action RebuildAction(AC.Action existingAction, int typeIndex, ActionList _target, int insertIndex = -1, ActionEnd _end = null) { ActionsManager actionsManager = AdvGame.GetReferences().actionsManager; int existingIndex = _target.actions.IndexOf(existingAction); if (actionsManager) { string className = actionsManager.AllActions [typeIndex].fileName; if (existingAction.GetType().ToString() != className && existingAction.GetType().ToString() != ("AC." + className)) { bool _showComment = existingAction.showComment; bool _showOutputSockets = existingAction.showOutputSockets; string _comment = existingAction.comment; ActionList _parentActionListInEditor = existingAction.parentActionListInEditor; AC.Action newAction = (AC.Action)CreateInstance(className); if (newAction == null && !className.StartsWith("AC.")) { newAction = (AC.Action)CreateInstance("AC." + className); } if (newAction == null) { newAction = (AC.Action)CreateInstance(ActionsManager.GetDefaultAction()); } newAction.name = className; if (_end != null) { newAction.endAction = _end.resultAction; newAction.skipAction = _end.skipAction; newAction.linkedAsset = _end.linkedAsset; newAction.linkedCutscene = _end.linkedCutscene; } newAction.showComment = _showComment; newAction.showOutputSockets = _showOutputSockets; newAction.comment = _comment; newAction.parentActionListInEditor = _parentActionListInEditor; if (insertIndex >= 0) { _target.actions.Insert(insertIndex, newAction); } else if (existingIndex >= 0) { _target.actions[existingIndex] = newAction; } //SyncAssetObjects (_target); return(newAction); } } return(existingAction); }
public static void ResetList(ActionList _target) { if (_target.actions.Count == 0 || (_target.actions.Count == 1 && _target.actions[0] == null)) { _target.actions.Clear(); AddAction(ActionsManager.GetDefaultAction(), -1, _target); } }
public static List <AC.Action> ResizeList(ActionListAsset _target, int listSize) { ActionsManager actionsManager = AdvGame.GetReferences().actionsManager; string defaultAction = ""; if (actionsManager) { defaultAction = actionsManager.GetDefaultAction(); } if (_target.actions.Count < listSize) { // Increase size of list while (_target.actions.Count < listSize) { List <int> idArray = new List <int>(); foreach (AC.Action _action in _target.actions) { idArray.Add(_action.id); } idArray.Sort(); Action newAction = (Action)CreateInstance(defaultAction); newAction.name = defaultAction; AssetDatabase.AddObjectToAsset(newAction, _target); _target.actions.Add(newAction); // Update id based on array foreach (int _id in idArray.ToArray()) { if (_target.actions [_target.actions.Count - 1].id == _id) { _target.actions [_target.actions.Count - 1].id++; } } } AssetDatabase.SaveAssets(); } else if (_target.actions.Count > listSize) { // Decrease size of list while (_target.actions.Count > listSize) { Action removeAction = _target.actions [_target.actions.Count - 1]; _target.actions.Remove(removeAction); UnityEngine.Object.DestroyImmediate(removeAction, true); } AssetDatabase.SaveAssets(); } return(_target.actions); }
public static List <AC.Action> ResizeList(List <AC.Action> list, int listSize) { ActionsManager actionsManager = AdvGame.GetReferences().actionsManager; string defaultAction = ""; if (actionsManager) { defaultAction = actionsManager.GetDefaultAction(); } if (list.Count < listSize) { // Increase size of list while (list.Count < listSize) { List <int> idArray = new List <int>(); foreach (AC.Action _action in list) { if (_action == null) { continue; } idArray.Add(_action.id); } idArray.Sort(); AC.Action newAction = (AC.Action)CreateInstance(defaultAction); newAction.name = defaultAction; list.Add(newAction); // Update id based on array foreach (int _id in idArray.ToArray()) { if (list [list.Count - 1].id == _id) { list [list.Count - 1].id++; } } } } else if (list.Count > listSize) { // Decrease size of list while (list.Count > listSize) { list.RemoveAt(list.Count - 1); } } return(list); }
public static void ResetList(ActionListAsset _targetAsset) { if (_targetAsset.actions.Count == 0 || (_targetAsset.actions.Count == 1 && _targetAsset.actions[0] == null)) { if (_targetAsset.actions.Count == 1) { DeleteAction(_targetAsset.actions[0], _targetAsset); } AddAction(ActionsManager.GetDefaultAction(), -1, _targetAsset); } }
public static ActionListAsset ResizeList(ActionListAsset _target, int listSize) { ActionsManager actionsManager = AdvGame.GetReferences().actionsManager; string defaultAction = ""; if (actionsManager) { defaultAction = ActionsManager.GetDefaultAction(); } if (_target.actions.Count < listSize) { // Increase size of list while (_target.actions.Count < listSize) { List <int> idArray = new List <int>(); foreach (AC.Action _action in _target.actions) { idArray.Add(_action.id); } idArray.Sort(); Action newAction = (Action)CreateInstance(defaultAction); newAction.name = defaultAction; AddAction(newAction, -1, _target); // Update id based on array foreach (int _id in idArray.ToArray()) { if (_target.actions [_target.actions.Count - 1].id == _id) { _target.actions [_target.actions.Count - 1].id++; } } } } else if (_target.actions.Count > listSize) { // Decrease size of list while (_target.actions.Count > listSize) { Action removeAction = _target.actions [_target.actions.Count - 1]; DeleteAction(removeAction, _target); } } return(_target); }
public static ActionList ResizeList(ActionList _target, int listSize) { string defaultAction = ActionsManager.GetDefaultAction(); if (string.IsNullOrEmpty(defaultAction)) { return(_target); } if (_target.actions.Count < listSize) { // Increase size of list while (_target.actions.Count < listSize) { List <int> idArray = new List <int>(); foreach (AC.Action _action in _target.actions) { if (_action == null) { continue; } idArray.Add(_action.id); } idArray.Sort(); AddAction(defaultAction, -1, _target); // Update id based on array foreach (int _id in idArray.ToArray()) { if (_target.actions [_target.actions.Count - 1].id == _id) { _target.actions [_target.actions.Count - 1].id++; } } } } else if (_target.actions.Count > listSize) { // Decrease size of list while (_target.actions.Count > listSize) { DeleteAction(_target.actions[_target.actions.Count - 1], _target); } } return(_target); }
/** * <summary>Gets the default Action set within ActionsManager.</summary> * <returns>The default Action set within ActionsManager</returns> */ public static AC.Action GetDefaultAction() { if (AdvGame.GetReferences().actionsManager) { string defaultAction = ActionsManager.GetDefaultAction(); AC.Action newAction = (AC.Action)ScriptableObject.CreateInstance(defaultAction); newAction.name = defaultAction; return(newAction); } else { ACDebug.LogError("Cannot create Action - no Actions Manager found."); return(null); } }
public static void ModifyAction(ActionListAsset _target, AC.Action _action, string callback) { ActionsManager actionsManager = AdvGame.GetReferences().actionsManager; if (actionsManager == null) { return; } 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"); _target.actions [i].isEnabled = true; break; case "Disable": Undo.RecordObject(_target, "Disable action"); _target.actions [i].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; cutAction.name = cutAction.name.Replace("(Clone)", ""); cutList.Add(cutAction); AdvGame.copiedActions = cutList; _target.actions.Remove(_action); Undo.DestroyObjectImmediate(_action); //UnityEngine.Object.DestroyImmediate (_action, true); AssetDatabase.SaveAssets(); break; case "Copy": List <AC.Action> copyList = new List <AC.Action>(); AC.Action copyAction = Object.Instantiate(_action) as AC.Action; copyAction.ClearIDs(); copyAction.name = copyAction.name.Replace("(Clone)", ""); copyList.Add(copyAction); AdvGame.copiedActions = copyList; break; case "Paste after": Undo.RecordObject(_target, "Paste actions"); List <AC.Action> pasteList = AdvGame.copiedActions; int j = i + 1; foreach (AC.Action action in pasteList) { if (action == null) { ACDebug.LogWarning("Error when pasting Action - cannot find original. Did you change scene before pasting? If you need to transfer Actions between scenes, copy them to an ActionList asset first."); continue; } AC.Action pastedAction = Object.Instantiate(action) as AC.Action; pastedAction.name = pastedAction.name.Replace("(Clone)", ""); pastedAction.hideFlags = HideFlags.HideInHierarchy; _target.actions.Insert(j, pastedAction); j++; AssetDatabase.AddObjectToAsset(pastedAction, _target); AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(pastedAction)); } AssetDatabase.SaveAssets(); break; case "Insert after": Undo.RecordObject(_target, "Create action"); Action newAction = ActionListAssetEditor.AddAction(actionsManager.GetDefaultAction(), i + 1, _target); newAction.endAction = _action.endAction; newAction.skipAction = -1; newAction.skipActionActual = _action.skipActionActual; break; case "Delete": Undo.RecordObject(_target, "Delete action"); _target.actions.Remove(_action); Undo.DestroyObjectImmediate(_action); //UnityEngine.Object.DestroyImmediate (_action, true); AssetDatabase.SaveAssets(); break; case "Move to top": Undo.RecordObject(_target, "Move action to top"); _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; } }
public override void OnInspectorGUI() { ActionListAsset _target = (ActionListAsset)target; ActionListAssetEditor.ShowPropertiesGUI(_target); EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); 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; } } if (GUILayout.Button("Action List Editor", EditorStyles.miniButtonMid)) { ActionListEditorWindow.Init(_target); } if (!Application.isPlaying) { GUI.enabled = false; } if (GUILayout.Button("Run now", EditorStyles.miniButtonRight)) { if (KickStarter.actionListAssetManager != null) { if (!_target.canRunMultipleInstances) { int numRemoved = KickStarter.actionListAssetManager.EndAssetList(_target); if (numRemoved > 0) { ACDebug.Log("Removed 1 instance of ActionList asset '" + _target.name + "' because it is set to only run one at a time.", _target); } } AdvGame.RunActionListAsset(_target); } else { ACDebug.LogWarning("An AC PersistentEngine object must be present in the scene for ActionList assets to run.", _target); } } GUI.enabled = true; EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); 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++) { int typeIndex = KickStarter.actionsManager.GetActionTypeIndex(_target.actions[i]); if (_target.actions[i] == null) { _target.actions.Insert(i, ActionListAssetEditor.RebuildAction(_target.actions[i], typeIndex, _target)); } _target.actions[i].isAssetFile = true; EditorGUILayout.BeginVertical("Button"); string actionLabel = " " + (i).ToString() + ": " + actionsManager.EnabledActions[typeIndex].GetFullTitle() + _target.actions[i].SetLabel(); actionLabel = actionLabel.Replace("\r\n", ""); actionLabel = actionLabel.Replace("\n", ""); actionLabel = actionLabel.Replace("\r", ""); if (actionLabel.Length > 40) { actionLabel = actionLabel.Substring(0, 40) + "..)"; } EditorGUILayout.BeginHorizontal(); _target.actions[i].isDisplayed = EditorGUILayout.Foldout(_target.actions[i].isDisplayed, actionLabel); if (!_target.actions[i].isEnabled) { EditorGUILayout.LabelField("DISABLED", EditorStyles.boldLabel, GUILayout.Width(100f)); } if (GUILayout.Button(Resource.CogIcon, GUILayout.Width(20f), GUILayout.Height(15f))) { ActionSideMenu(_target.actions[i]); } EditorGUILayout.EndHorizontal(); if (_target.actions[i].isDisplayed) { 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.Insert(i, ActionListAssetEditor.RebuildAction(_target.actions[i], newTypeIndex, _target, _end.resultAction, _end.skipAction, _end.linkedAsset, _end.linkedCutscene)); } EditorGUILayout.Space(); GUI.enabled = _target.actions[i].isEnabled; if (_target.useParameters) { if (Application.isPlaying) { _target.actions[i].AssignValues(_target.parameters); } _target.actions[i].ShowGUI(_target.parameters); } else { if (Application.isPlaying) { _target.actions[i].AssignValues(null); } _target.actions[i].ShowGUI(null); } } GUI.enabled = true; } if (_target.actions[i].endAction == AC.ResultAction.Skip || _target.actions[i] is ActionCheck || _target.actions[i] is ActionCheckMultiple || _target.actions[i] is ActionParallel) { _target.actions[i].SkipActionGUI(_target.actions, _target.actions[i].isDisplayed); } EditorGUILayout.EndVertical(); EditorGUILayout.Space(); } if (GUILayout.Button("Add new Action")) { Undo.RecordObject(_target, "Create action"); AddAction(actionsManager.GetDefaultAction(), _target.actions.Count, _target); } if (GUI.changed) { EditorUtility.SetDirty(_target); } }
public static void ModifyAction(ActionListAsset _target, AC.Action _action, string callback) { ActionsManager actionsManager = AdvGame.GetReferences().actionsManager; if (actionsManager == null) { return; } 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": _target.actions [i].isEnabled = true; break; case "Disable": _target.actions [i].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; DeleteAction(_action, _target); break; case "Copy": List <AC.Action> copyList = new List <AC.Action>(); AC.Action copyAction = Object.Instantiate(_action) as AC.Action; copyAction.ClearIDs(); copyAction.name = copyAction.name.Replace("(Clone)", string.Empty); copyList.Add(copyAction); AdvGame.copiedActions = copyList; break; case "Paste after": List <AC.Action> pasteList = AdvGame.copiedActions; int j = i + 1; foreach (AC.Action action in pasteList) { if (action == null) { ACDebug.LogWarning("Error when pasting Action - cannot find original. Did you change scene before pasting? If you need to transfer Actions between scenes, copy them to an ActionList asset first."); continue; } AC.Action pastedAction = Object.Instantiate(action) as AC.Action; pastedAction.name = pastedAction.name.Replace("(Clone)", string.Empty); AddAction(pastedAction, j, _target); j++; } break; case "Insert after": Action newAction = AddAction(ActionsManager.GetDefaultAction(), i + 1, _target); newAction.endAction = _action.endAction; newAction.skipAction = -1; newAction.skipActionActual = _action.skipActionActual; break; case "Delete": DeleteAction(_action, _target); break; case "Move to top": _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; } if (doUndo) { Undo.RecordObjects(new UnityEngine.Object [] { _target }, callback); Undo.RecordObjects(_target.actions.ToArray(), callback); Undo.CollapseUndoOperations(Undo.GetCurrentGroup()); EditorUtility.SetDirty(_target); } }
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; DeleteAction(_action, _target); 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": AddAction(ActionsManager.GetDefaultAction(), -1, _target); break; case "Insert after": Action insertAfterAction = AddAction(ActionsManager.GetDefaultAction(), i + 1, _target); insertAfterAction.endAction = _action.endAction; insertAfterAction.skipAction = -1; insertAfterAction.skipActionActual = _action.skipActionActual; break; case "Delete": Undo.RecordObject(_target, "Delete action"); DeleteAction(_action, _target); 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); } }
protected void DrawSharedElements(ActionList _target) { if (IsActionListPrefab(_target)) { 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; AddAction(ActionsManager.GetDefaultAction(), -1, _target); } } 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); actionsManager = AdvGame.GetReferences().actionsManager; 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); _target.actions.RemoveAt(i); numActions--; continue; } _target.actions[i].AssignParentList(_target); EditorGUILayout.BeginVertical("Button"); EditorGUILayout.BeginHorizontal(); int typeIndex = actionsManager.GetActionTypeIndex(_target.actions[i]); string actionLabel = " (" + i.ToString() + ") " + actionsManager.GetActionTypeLabel(_target.actions[i], true); actionLabel = actionLabel.Replace("\r\n", ""); actionLabel = actionLabel.Replace("\n", ""); actionLabel = actionLabel.Replace("\r", ""); if (actionLabel.Length > 40) { actionLabel = actionLabel.Substring(0, 40) + "..)"; } _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("", CustomStyles.IconCog)) { 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 is not listed 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] = RebuildAction(_target.actions[i], newTypeIndex, _target, -1, _end); } 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 = ActionListEditor.ResizeList(_target, numActions); }
public static void ModifyAction(ActionListAsset _target, AC.Action _action, string callback) { ActionsManager actionsManager = AdvGame.GetReferences().actionsManager; if (actionsManager == null) { return; } 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"); _target.actions [i].isEnabled = true; break; case "Disable": Undo.RecordObject(_target, "Disable action"); _target.actions [i].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); Undo.DestroyObjectImmediate(_action); //UnityEngine.Object.DestroyImmediate (_action, true); AssetDatabase.SaveAssets(); 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)", ""); copyList.Add(copyAction); AdvGame.copiedActions = copyList; break; case "Paste after": Undo.RecordObject(_target, "Paste actions"); List <AC.Action> pasteList = AdvGame.copiedActions; int j = i + 1; foreach (AC.Action action in pasteList) { AC.Action pastedAction = Object.Instantiate(action) as AC.Action; pastedAction.name = pastedAction.name.Replace("(Clone)", ""); pastedAction.hideFlags = HideFlags.HideInHierarchy; _target.actions.Insert(j, pastedAction); j++; AssetDatabase.AddObjectToAsset(pastedAction, _target); AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(pastedAction)); } AssetDatabase.SaveAssets(); break; case "Insert after": Undo.RecordObject(_target, "Create action"); ActionListAssetEditor.AddAction(actionsManager.GetDefaultAction(), i + 1, _target); break; case "Delete": Undo.RecordObject(_target, "Delete action"); _target.actions.Remove(_action); Undo.DestroyObjectImmediate(_action); //UnityEngine.Object.DestroyImmediate (_action, true); AssetDatabase.SaveAssets(); break; case "Move to top": Undo.RecordObject(_target, "Move action to top"); _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; } }