private int GetTypeNumber(int i) { ActionList _target = (ActionList)target; int number = 0; if (actionsManager) { for (int j = 0; j < actionsManager.GetActionsSize(); j++) { try { if (_target.actions[i].GetType().ToString() == actionsManager.GetActionName(j)) { number = j; break; } } catch { string defaultAction = actionsManager.GetDefaultAction(); _target.actions[i] = (Action)CreateInstance(defaultAction); } } } return(number); }
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); 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); }
private List <Action> ResizeList(List <Action> list, int listSize) { 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 (Action _action in list) { idArray.Add(_action.id); } idArray.Sort(); list.Add((Action)CreateInstance(defaultAction)); // 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); }
protected void DrawSharedElements() { if (AdvGame.GetReferences() == null) { Debug.LogError("A References file is required - please use the Adventure Creator window to create one."); EditorGUILayout.LabelField("No References file found!"); } else { actionsManager = AdvGame.GetReferences().actionsManager; ActionList _target = (ActionList)target; if (actionsManager) { int numActions = _target.actions.Count; if (numActions < 1) { numActions = 1; string defaultAction = actionsManager.GetDefaultAction(); _target.actions.Add((Action)CreateInstance(defaultAction)); } EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Expand all")) { Undo.RegisterUndo(_target, "Expand actions"); foreach (Action action in _target.actions) { action.isDisplayed = true; } } if (GUILayout.Button("Collapse all")) { Undo.RegisterUndo(_target, "Collapse actions"); foreach (Action action in _target.actions) { action.isDisplayed = false; } } EditorGUILayout.EndHorizontal(); for (int i = 0; i < _target.actions.Count; i++) { EditorGUILayout.BeginVertical("Button"); typeNumber = GetTypeNumber(i); string actionLabel = " " + (i).ToString() + ": " + _target.actions[i].title + _target.actions[i].SetLabel(); _target.actions[i].isDisplayed = EditorGUILayout.Foldout(_target.actions[i].isDisplayed, actionLabel); if (_target.actions[i].isDisplayed) { typeNumber = EditorGUILayout.Popup("Action type:", typeNumber, actionsManager.GetActionTitles()); EditorGUILayout.Space(); // Rebuild constructor if Subclass and type string do not match if (_target.actions[i].GetType().ToString() != actionsManager.GetActionName(typeNumber)) { _target.actions[i] = RebuildAction(_target.actions[i], typeNumber); } ShowActionGUI(_target.actions[i], _target.gameObject, i, _target.actions.Count); EditorGUILayout.BeginHorizontal(); if (i > 0) { if (GUILayout.Button("Move up")) { Undo.RegisterUndo(_target, "Move action up"); _target.actions = AdvGame.SwapActions(_target.actions, i, i - 1); } } if (i < _target.actions.Count - 1) { if (GUILayout.Button("Insert new")) { Undo.RegisterUndo(_target, "Create action"); numActions += 1; _target.actions = ResizeList(_target.actions, numActions); // Swap all elements up one for (int k = numActions - 1; k > i + 1; k--) { _target.actions = AdvGame.SwapActions(_target.actions, k, k - 1); } } } if (_target.actions.Count > 1) { if (GUILayout.Button("Delete")) { Undo.RegisterUndo(_target, "Delete action"); _target.actions.RemoveAt(i); numActions -= 1; } } if (i < _target.actions.Count - 1) { if (GUILayout.Button("Move down")) { Undo.RegisterUndo(_target, "Move action down"); _target.actions = AdvGame.SwapActions(_target.actions, i, i + 1); } } EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndVertical(); EditorGUILayout.Space(); } if (GUILayout.Button("Add new action")) { Undo.RegisterUndo(_target, "Create action"); numActions += 1; } _target.actions = ResizeList(_target.actions, 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); 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); 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; } }