public static void FindPlayerReferences(int playerID, string playerName) { if (EditorUtility.DisplayDialog("Search Player '" + playerName + "' references?", "The Editor will search ActionList assets, and scenes listed in the Build Settings, for references to this Player. The current scene will need to be saved and listed to be included in the search process. Continue?", "OK", "Cancel")) { if (UnityEditor.SceneManagement.EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo()) { // ActionList assets if (AdvGame.GetReferences().speechManager != null) { ActionListAsset[] allActionListAssets = AdvGame.GetReferences().speechManager.GetAllActionListAssets(); foreach (ActionListAsset actionListAsset in allActionListAssets) { SearchActionListAssetForPlayerReferences(playerID, playerName, actionListAsset); } } // Scenes string originalScene = UnityVersionHandler.GetCurrentSceneFilepath(); string[] sceneFiles = AdvGame.GetSceneFiles(); foreach (string sceneFile in sceneFiles) { UnityVersionHandler.OpenScene(sceneFile); string suffix = " in scene '" + sceneFile + "'"; SearchSceneForPlayerReferences(playerID, playerName, suffix); } UnityVersionHandler.OpenScene(originalScene); } } }
private void SearchForInstances(bool justLocal, ActionType actionType) { if (justLocal) { SearchSceneForType("", actionType); return; } // First look for lines that already have an assigned lineID string[] sceneFiles = AdvGame.GetSceneFiles(); if (sceneFiles == null || sceneFiles.Length == 0) { Debug.LogWarning("Cannot search scenes - no enabled scenes could be found in the Build Settings."); } else { foreach (string sceneFile in sceneFiles) { SearchSceneForType(sceneFile, actionType); } } ActionListAsset[] allActionListAssets = AdvGame.GetReferences().speechManager.GetAllActionListAssets(); foreach (ActionListAsset actionListAsset in allActionListAssets) { int[] foundIDs = SearchActionsForType(actionListAsset.actions, actionType); if (foundIDs != null && foundIDs.Length > 0) { ACDebug.Log("(Asset: " + actionListAsset.name + ") Found " + foundIDs.Length + " instances of '" + actionType.GetFullTitle() + "' " + CreateIDReport(foundIDs), actionListAsset); } } }
private void SearchForInstances(bool justLocal, ActionType actionType) { if (searchedAssets != null) { searchedAssets.Clear(); } if (justLocal) { SearchSceneForType("", actionType); return; } string[] sceneFiles = AdvGame.GetSceneFiles(); // First look for lines that already have an assigned lineID foreach (string sceneFile in sceneFiles) { SearchSceneForType(sceneFile, actionType); } // Settings if (KickStarter.settingsManager) { SearchAssetForType(KickStarter.settingsManager.actionListOnStart, actionType); if (KickStarter.settingsManager.activeInputs != null) { foreach (ActiveInput activeInput in KickStarter.settingsManager.activeInputs) { SearchAssetForType(activeInput.actionListAsset, actionType); } } } // Inventory if (KickStarter.inventoryManager) { SearchAssetForType(KickStarter.inventoryManager.unhandledCombine, actionType); SearchAssetForType(KickStarter.inventoryManager.unhandledHotspot, actionType); SearchAssetForType(KickStarter.inventoryManager.unhandledGive, actionType); // Item-specific events if (KickStarter.inventoryManager.items.Count > 0) { foreach (InvItem item in (KickStarter.inventoryManager.items)) { SearchAssetForType(item.useActionList, actionType); SearchAssetForType(item.lookActionList, actionType); SearchAssetForType(item.unhandledActionList, actionType); SearchAssetForType(item.unhandledCombineActionList, actionType); foreach (ActionListAsset actionList in item.combineActionList) { SearchAssetForType(actionList, actionType); } foreach (InvInteraction interaction in item.interactions) { if (interaction.actionList != null) { SearchAssetForType(interaction.actionList, actionType); } } } } foreach (Recipe recipe in KickStarter.inventoryManager.recipes) { SearchAssetForType(recipe.invActionList, actionType); SearchAssetForType(recipe.actionListOnCreate, actionType); } } // Cursor if (KickStarter.cursorManager) { // Prefixes foreach (ActionListAsset actionListAsset in KickStarter.cursorManager.unhandledCursorInteractions) { SearchAssetForType(actionListAsset, actionType); } } // Menus if (KickStarter.menuManager) { // Gather elements if (KickStarter.menuManager.menus.Count > 0) { foreach (AC.Menu menu in KickStarter.menuManager.menus) { SearchAssetForType(menu.actionListOnTurnOff, actionType); SearchAssetForType(menu.actionListOnTurnOn, actionType); foreach (MenuElement element in menu.elements) { if (element is MenuButton) { MenuButton button = (MenuButton)element; if (button.buttonClickType == AC_ButtonClickType.RunActionList) { SearchAssetForType(button.actionList, actionType); } } else if (element is MenuSavesList) { MenuSavesList button = (MenuSavesList)element; SearchAssetForType(button.actionListOnSave, actionType); } else if (element is MenuCycle) { MenuCycle cycle = (MenuCycle)element; SearchAssetForType(cycle.actionListOnClick, actionType); } else if (element is MenuJournal) { MenuJournal journal = (MenuJournal)element; SearchAssetForType(journal.actionListOnAddPage, actionType); } else if (element is MenuSlider) { MenuSlider slider = (MenuSlider)element; SearchAssetForType(slider.actionListOnChange, actionType); } else if (element is MenuToggle) { MenuToggle toggle = (MenuToggle)element; SearchAssetForType(toggle.actionListOnClick, actionType); } else if (element is MenuProfilesList) { MenuProfilesList profilesList = (MenuProfilesList)element; SearchAssetForType(profilesList.actionListOnClick, actionType); } } } } } searchedAssets.Clear(); }
private void Export() { #if UNITY_WEBPLAYER ACDebug.LogWarning("Game text cannot be exported in WebPlayer mode - please switch platform and try again."); #else if (variablesManager == null || exportColumns == null || exportColumns.Count == 0) { return; } if (variableLocation == VariableLocation.Local && allScenes) { bool canProceed = EditorUtility.DisplayDialog("Export variables", "AC will now go through your game, and collect all variables to be exported.\n\nIt is recommended to back up your project beforehand.", "OK", "Cancel"); if (!canProceed) { return; } if (!UnityEditor.SceneManagement.EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo()) { return; } } string suggestedFilename = ""; if (AdvGame.GetReferences().settingsManager) { suggestedFilename = AdvGame.GetReferences().settingsManager.saveFileName + " - "; } if (variableLocation == VariableLocation.Local && allScenes) { suggestedFilename += " All "; } suggestedFilename += variableLocation.ToString() + " Variables.csv"; string fileName = EditorUtility.SaveFilePanel("Export variables", "Assets", suggestedFilename, "csv"); if (fileName.Length == 0) { return; } List <string[]> output = new List <string[]>(); List <string> headerList = new List <string>(); headerList.Add("ID"); foreach (ExportColumn exportColumn in exportColumns) { headerList.Add(exportColumn.GetHeader()); } output.Add(headerList.ToArray()); // Global if (variableLocation == VariableLocation.Global) { List <GVar> exportVars = new List <GVar>(); foreach (GVar globalVariable in variablesManager.vars) { exportVars.Add(new GVar(globalVariable)); } foreach (GVar exportVar in exportVars) { List <string> rowList = new List <string>(); rowList.Add(exportVar.id.ToString()); foreach (ExportColumn exportColumn in exportColumns) { string cellText = exportColumn.GetCellText(exportVar, VariableLocation.Global, replaceForwardSlashes); rowList.Add(cellText); } output.Add(rowList.ToArray()); } } // Local else if (variableLocation == VariableLocation.Local) { if (allScenes) { string originalScene = UnityVersionHandler.GetCurrentSceneFilepath(); string[] sceneFiles = AdvGame.GetSceneFiles(); foreach (string sceneFile in sceneFiles) { UnityVersionHandler.OpenScene(sceneFile); if (FindObjectOfType <LocalVariables>()) { LocalVariables localVariables = FindObjectOfType <LocalVariables>(); if (localVariables != null) { string sceneName = UnityVersionHandler.GetCurrentSceneName(); output = GatherOutput(output, localVariables.localVars, sceneName); } } } if (string.IsNullOrEmpty(originalScene)) { UnityVersionHandler.NewScene(); } else { UnityVersionHandler.OpenScene(originalScene); } } else { string sceneName = UnityVersionHandler.GetCurrentSceneName(); output = GatherOutput(output, KickStarter.localVariables.localVars, sceneName); } } // Component else if (variableLocation == VariableLocation.Component) { string sceneName = UnityVersionHandler.GetCurrentSceneName(); if (variables != null) { output = GatherOutput(output, variables.vars, sceneName); } } string fileContents = CSVReader.CreateCSVGrid(output); if (!string.IsNullOrEmpty(fileContents) && Serializer.SaveFile(fileName, fileContents)) { int numExported = output.Count - 1; if (numExported == 1) { ACDebug.Log("1 " + variableLocation + " variable exported."); } else { ACDebug.Log(numExported.ToString() + " " + variableLocation + " variables exported."); } } #endif }
public static void FindGlobalReferences(MenuCommand command) { ActionListAsset actionListAsset = (ActionListAsset)command.context; if (EditorUtility.DisplayDialog("Search '" + actionListAsset.name + "' references?", "The Editor will search assets, and active scenes listed in the Build Settings, for references to this ActionList asset. The current scene will need to be saved and listed to be included in the search process. Continue?", "OK", "Cancel")) { if (UnityEditor.SceneManagement.EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo()) { bool foundReference = false; // Menus if (KickStarter.menuManager != null) { foreach (Menu menu in KickStarter.menuManager.menus) { if (menu.ReferencesAsset(actionListAsset)) { Debug.Log("'" + actionListAsset.name + "' is referenced by Menu '" + menu.title + "'"); foundReference = true; } foreach (MenuElement element in menu.elements) { if (element != null && element.ReferencesAsset(actionListAsset)) { Debug.Log("'" + actionListAsset.name + "' is referenced by Menu Element '" + element.title + "' in Menu '" + menu.title + "'"); foundReference = true; } } } } // Settings if (KickStarter.settingsManager != null) { if (KickStarter.settingsManager.actionListOnStart == actionListAsset) { Debug.Log("'" + actionListAsset.name + "' is referenced by the Settings Manager"); foundReference = true; } } // Inventory if (KickStarter.inventoryManager != null) { if (KickStarter.inventoryManager.unhandledCombine == actionListAsset || KickStarter.inventoryManager.unhandledGive == actionListAsset || KickStarter.inventoryManager.unhandledHotspot == actionListAsset) { Debug.Log("'" + actionListAsset.name + "' is referenced by the Inventory Manager"); foundReference = true; } foreach (Recipe recipe in KickStarter.inventoryManager.recipes) { if (recipe.actionListOnCreate == actionListAsset || (recipe.onCreateRecipe == OnCreateRecipe.RunActionList && recipe.invActionList == actionListAsset)) { Debug.Log("'" + actionListAsset.name + "' is referenced by Recipe " + recipe.EditorLabel); foundReference = true; } } foreach (InvItem invItem in KickStarter.inventoryManager.items) { if (invItem.ReferencesAsset(actionListAsset)) { Debug.Log("'" + actionListAsset.name + "' is referenced by Inventory Item " + invItem.EditorLabel); foundReference = true; } } } // Cursor if (KickStarter.cursorManager != null) { if (KickStarter.cursorManager.AllowUnhandledIcons()) { foreach (ActionListAsset unhandledCursorInteraction in KickStarter.cursorManager.unhandledCursorInteractions) { if (unhandledCursorInteraction == actionListAsset) { Debug.Log("'" + actionListAsset.name + "' is referenced by the Cursor Manager"); foundReference = true; } } } } // ActionListAssets if (KickStarter.speechManager != null) { ActionListAsset[] allAssets = KickStarter.speechManager.GetAllActionListAssets(); foreach (ActionListAsset asset in allAssets) { if (asset == actionListAsset) { continue; } foreach (Action action in asset.actions) { if (action != null) { if (action.ReferencesAsset(actionListAsset)) { string actionLabel = (KickStarter.actionsManager != null) ? (" (" + KickStarter.actionsManager.GetActionTypeLabel(action) + ")") : ""; Debug.Log("'" + actionListAsset.name + "' is referenced by Action #" + asset.actions.IndexOf(action) + actionLabel + " in ActionList asset '" + asset.name + "'", asset); foundReference = true; } } } } } // Scenes string originalScene = UnityVersionHandler.GetCurrentSceneFilepath(); string[] sceneFiles = AdvGame.GetSceneFiles(); foreach (string sceneFile in sceneFiles) { UnityVersionHandler.OpenScene(sceneFile); string suffix = " in scene '" + sceneFile + "'"; // ActionLists ActionList[] localActionLists = FindObjectsOfType <ActionList> (); foreach (ActionList actionList in localActionLists) { if (actionList.source == ActionListSource.InScene) { foreach (Action action in actionList.actions) { if (action != null) { if (action.ReferencesAsset(actionListAsset)) { string actionLabel = (KickStarter.actionsManager != null) ? (" (" + KickStarter.actionsManager.GetActionTypeLabel(action) + ")") : ""; Debug.Log("'" + actionListAsset.name + "' is referenced by Action #" + actionList.actions.IndexOf(action) + actionLabel + " in ActionList '" + actionList.gameObject.name + "'" + suffix, actionList); foundReference = true; } } } } } // iActionListAssetReferencers MonoBehaviour[] sceneObjects = FindObjectsOfType <MonoBehaviour> (); for (int i = 0; i < sceneObjects.Length; i++) { MonoBehaviour currentObj = sceneObjects[i]; iActionListAssetReferencer currentComponent = currentObj as iActionListAssetReferencer; if (currentComponent != null && currentComponent.ReferencesAsset(actionListAsset)) { Debug.Log("'" + actionListAsset.name + "' is referenced by '" + currentComponent + "'" + suffix); foundReference = true; } } } UnityVersionHandler.OpenScene(originalScene); if (!foundReference) { Debug.Log("No instances of '" + actionListAsset.name + "' were found.", actionListAsset); } } } }
private void ConvertGlobalToLocal(GVar globalVariable) { if (globalVariable == null) { return; } if (KickStarter.localVariables == null) { ACDebug.LogWarning("Cannot convert variable to local since the scene has not been prepared for AC."); return; } if (EditorUtility.DisplayDialog("Convert " + globalVariable.label + " to Local Variable?", "This will update all Actions and Managers that refer to this Variable. This is a non-reversible process, and you should back up your project first. Continue?", "OK", "Cancel")) { if (UnityVersionHandler.SaveSceneIfUserWants()) { // Create new Local DeactivateAllVars(); GVar newLocalVariable = new GVar(globalVariable); int newLocalID = newLocalVariable.AssignUniqueID(GetIDArray(KickStarter.localVariables.localVars)); KickStarter.localVariables.localVars.Add(newLocalVariable); UnityVersionHandler.CustomSetDirty(KickStarter.localVariables, true); UnityVersionHandler.SaveScene(); // Update current scene bool updatedScene = false; string originalScene = UnityVersionHandler.GetCurrentSceneFilepath(); ActionList[] actionLists = FindObjectsOfType <ActionList>(); foreach (ActionList actionList in actionLists) { foreach (Action action in actionList.actions) { bool updatedActionList = action.ConvertGlobalVariableToLocal(globalVariable.id, newLocalID, true); if (updatedActionList) { updatedScene = true; UnityVersionHandler.CustomSetDirty(actionList, true); ACDebug.Log("Updated Action " + actionList.actions.IndexOf(action) + " of ActionList '" + actionList.name + "' in scene '" + originalScene + "'", actionList); } } } Conversation[] conversations = FindObjectsOfType <Conversation>(); foreach (Conversation conversation in conversations) { bool updatedConversation = conversation.ConvertGlobalVariableToLocal(globalVariable.id, newLocalID, true); if (updatedConversation) { updatedScene = true; UnityVersionHandler.CustomSetDirty(conversation, true); ACDebug.Log("Updated Conversation " + conversation + ") in scene '" + originalScene + "'"); } } if (updatedScene) { UnityVersionHandler.SaveScene(); } // Update other scenes string[] sceneFiles = AdvGame.GetSceneFiles(); foreach (string sceneFile in sceneFiles) { if (sceneFile == originalScene) { continue; } UnityVersionHandler.OpenScene(sceneFile); actionLists = FindObjectsOfType <ActionList>(); foreach (ActionList actionList in actionLists) { foreach (Action action in actionList.actions) { bool isAffected = action.ConvertGlobalVariableToLocal(globalVariable.id, newLocalID, false); if (isAffected) { ACDebug.LogWarning("Cannot update Action " + actionList.actions.IndexOf(action) + " in ActionList '" + actionList.name + "' in scene '" + sceneFile + "' because it cannot access the Local Variable in scene '" + originalScene + "'."); } } } conversations = FindObjectsOfType <Conversation>(); foreach (Conversation conversation in conversations) { bool isAffected = conversation.ConvertGlobalVariableToLocal(globalVariable.id, newLocalID, false); if (isAffected) { ACDebug.LogWarning("Cannot update Conversation " + conversation + ") in scene '" + sceneFile + "' because it cannot access the Local Variable in scene '" + originalScene + "'."); } } } UnityVersionHandler.OpenScene(originalScene); // Update Menu Manager if (KickStarter.menuManager) { KickStarter.menuManager.CheckConvertGlobalVariableToLocal(globalVariable.id, newLocalID); } // Update Speech Manager if (KickStarter.speechManager) { // Search asset files ActionListAsset[] allActionListAssets = KickStarter.speechManager.GetAllActionListAssets(); UnityVersionHandler.OpenScene(originalScene); if (allActionListAssets != null) { foreach (ActionListAsset actionListAsset in allActionListAssets) { foreach (Action action in actionListAsset.actions) { bool isAffected = action.ConvertGlobalVariableToLocal(globalVariable.id, newLocalID, false); if (isAffected) { ACDebug.LogWarning("Cannot update Action " + actionListAsset.actions.IndexOf(action) + " in ActionList asset '" + actionListAsset.name + "' because asset files cannot refer to Local Variables."); } } } } KickStarter.speechManager.ConvertGlobalVariableToLocal(globalVariable, UnityVersionHandler.GetCurrentSceneName()); } // Remove old Global vars.Remove(globalVariable); // Mark for saving EditorUtility.SetDirty(this); if (KickStarter.localVariables != null) { UnityVersionHandler.CustomSetDirty(KickStarter.localVariables); } AssetDatabase.SaveAssets(); } } }
public static void FindGlobalReferences(MenuCommand command) { ConstantID _constantID = (ConstantID)command.context; if (_constantID != null) { if (_constantID.constantID == 0) { ACDebug.LogWarning("Cannot find references for " + _constantID.name + " because it's ConstantID value is zero!", _constantID); return; } if (EditorUtility.DisplayDialog("Search '" + _constantID.gameObject.name + "' references?", "The Editor will search assets, and active scenes listed in the Build Settings, for references to this GameObject. The current scene will need to be saved and listed to be included in the search process. Continue?", "OK", "Cancel")) { if (UnityEditor.SceneManagement.EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo()) { // Menus if (KickStarter.menuManager != null) { foreach (Menu menu in KickStarter.menuManager.menus) { if (menu.IsUnityUI()) { if (menu.ReferencesObjectOrID(_constantID.gameObject, _constantID.constantID)) { Debug.Log("'" + _constantID.gameObject.name + "' is referenced by Menu '" + menu.title + "'"); } foreach (MenuElement element in menu.elements) { if (element != null && element.ReferencesObjectOrID(_constantID.gameObject, _constantID.constantID)) { Debug.Log("'" + _constantID.gameObject.name + "' is referenced by Menu Element '" + element.title + "' in Menu '" + menu.title + "'"); } } } } } // ActionList assets if (AdvGame.GetReferences().speechManager != null) { ActionListAsset[] allActionListAssets = AdvGame.GetReferences().speechManager.GetAllActionListAssets(); foreach (ActionListAsset actionListAsset in allActionListAssets) { SearchActionListAssetForReferences(_constantID, actionListAsset); } } // Scenes string originalScene = UnityVersionHandler.GetCurrentSceneFilepath(); string[] sceneFiles = AdvGame.GetSceneFiles(); foreach (string sceneFile in sceneFiles) { UnityVersionHandler.OpenScene(sceneFile); string suffix = " in scene '" + sceneFile + "'"; SearchSceneForReferences(_constantID, suffix); } UnityVersionHandler.OpenScene(originalScene); } } } }
private void Export() { #if UNITY_WEBPLAYER ACDebug.LogWarning("Game text cannot be exported in WebPlayer mode - please switch platform and try again."); #else if (variablesManager == null || exportColumns == null || exportColumns.Count == 0) { return; } if (variableLocation == VariableLocation.Local && allScenes) { bool canProceed = EditorUtility.DisplayDialog("Export variables", "AC will now go through your game, and collect all variables to be exported.\n\nIt is recommended to back up your project beforehand.", "OK", "Cancel"); if (!canProceed) { return; } if (!UnityVersionHandler.SaveSceneIfUserWants()) { return; } } string suggestedFilename = ""; if (AdvGame.GetReferences().settingsManager) { suggestedFilename = AdvGame.GetReferences().settingsManager.saveFileName + " - "; } if (variableLocation == VariableLocation.Local && allScenes) { suggestedFilename += " All "; } suggestedFilename += variableLocation.ToString() + " Variables.csv"; string fileName = EditorUtility.SaveFilePanel("Export variables", "Assets", suggestedFilename, "csv"); if (fileName.Length == 0) { return; } bool fail = false; List <string[]> output = new List <string[]>(); List <string> headerList = new List <string>(); headerList.Add("ID"); foreach (ExportColumn exportColumn in exportColumns) { headerList.Add(exportColumn.GetHeader()); } output.Add(headerList.ToArray()); // Global if (variableLocation == VariableLocation.Global) { List <GVar> exportVars = new List <GVar>(); foreach (GVar globalVariable in variablesManager.vars) { exportVars.Add(new GVar(globalVariable)); } foreach (GVar exportVar in exportVars) { List <string> rowList = new List <string>(); rowList.Add(exportVar.id.ToString()); foreach (ExportColumn exportColumn in exportColumns) { string cellText = exportColumn.GetCellText(exportVar, VariableLocation.Global, replaceForwardSlashes); rowList.Add(cellText); if (cellText.Contains(CSVReader.csvDelimiter)) { fail = true; ACDebug.LogError("Cannot export variables since global variable " + exportVar.id.ToString() + " (" + exportVar.label + ") contains the character '" + CSVReader.csvDelimiter + "'."); } } output.Add(rowList.ToArray()); } } // Local else if (variableLocation == VariableLocation.Local) { if (allScenes) { string originalScene = UnityVersionHandler.GetCurrentSceneFilepath(); string[] sceneFiles = AdvGame.GetSceneFiles(); foreach (string sceneFile in sceneFiles) { UnityVersionHandler.OpenScene(sceneFile); if (FindObjectOfType <LocalVariables>()) { LocalVariables localVariables = FindObjectOfType <LocalVariables>(); if (localVariables != null) { string sceneName = UnityVersionHandler.GetCurrentSceneName(); output = GatherOutput(output, localVariables.localVars, sceneName); } } } if (originalScene == "") { UnityVersionHandler.NewScene(); } else { UnityVersionHandler.OpenScene(originalScene); } } else { string sceneName = UnityVersionHandler.GetCurrentSceneName(); output = GatherOutput(output, KickStarter.localVariables.localVars, sceneName); } } // Component else if (variableLocation == VariableLocation.Component) { string sceneName = UnityVersionHandler.GetCurrentSceneName(); if (variables != null) { output = GatherOutput(output, variables.vars, sceneName); } } if (!fail) { int length = output.Count; System.Text.StringBuilder sb = new System.Text.StringBuilder(); for (int j = 0; j < length; j++) { sb.AppendLine(string.Join(CSVReader.csvDelimiter, output[j])); } if (Serializer.SaveFile(fileName, sb.ToString())) { int numExported = output.Count - 1; if (numExported == 1) { ACDebug.Log("1 " + variableLocation + " variable exported."); } else { ACDebug.Log(numExported.ToString() + " " + variableLocation + " variables exported."); } } } #endif }