private bool SearchSceneForType(string sceneFile, ActionType actionType) { string sceneLabel = string.Empty; bool foundInstance = false; if (sceneFile != string.Empty) { sceneLabel = "(Scene: " + sceneFile + ") "; UnityVersionHandler.OpenScene(sceneFile); } // Speech lines and journal entries ActionList[] actionLists = GameObject.FindObjectsOfType(typeof(ActionList)) as ActionList[]; foreach (ActionList list in actionLists) { int[] foundIDs = SearchActionsForType(list.GetActions(), actionType); if (foundIDs != null && foundIDs.Length > 0) { ACDebug.Log(sceneLabel + " Found " + foundIDs.Length + " instances in '" + list.gameObject.name + "' " + CreateIDReport(foundIDs), list.gameObject); foundInstance = true; } } return(foundInstance); }
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); } } }
/** * <summary>Locates an object with a supplied ConstantID number (Unity Editor only). * If the object is not found in the current scene, all scenes in the Build Settings will be searched. * Once an object is found, it will be pinged in the Hierarchy window.</summary> * <param name = "_constantID">The ConstantID number of the object to find</param> */ public static void FindObjectWithConstantID(int _constantID) { string originalScene = UnityVersionHandler.GetCurrentSceneName(); if (UnityVersionHandler.SaveSceneIfUserWants()) { // Search scene files for ID string[] sceneFiles = GetSceneFiles(); foreach (string sceneFile in sceneFiles) { UnityVersionHandler.OpenScene(sceneFile); ConstantID[] idObjects = FindObjectsOfType(typeof(ConstantID)) as ConstantID[]; if (idObjects != null && idObjects.Length > 0) { foreach (ConstantID idObject in idObjects) { if (idObject.constantID == _constantID) { ACDebug.Log("Found Constant ID: " + _constantID + " on '" + idObject.gameObject.name + "' in scene: " + sceneFile); EditorGUIUtility.PingObject(idObject.gameObject); EditorGUIUtility.ExitGUI(); return; } } } } ACDebug.LogWarning("Cannot find object with Constant ID: " + _constantID); UnityVersionHandler.OpenScene(originalScene); } }
/** * <summary>Adds the scene additively.</summary> */ public void AddLevel() { if (name != "") { UnityVersionHandler.OpenScene(name, false, true); } else { UnityVersionHandler.OpenScene(number, false, true); } }
/** * <summary>Loads the scene normally.</summary> * <param name = "forceReload">If True, the scene will be re-loaded if it is already open.</param> */ public void LoadLevel(bool forceReload = false) { if (name != "") { UnityVersionHandler.OpenScene(name, forceReload); } else { UnityVersionHandler.OpenScene(number, forceReload); } }
/** * <summary>Adds the scene additively.</summary> */ public void AddLevel() { if (!string.IsNullOrEmpty(name)) { UnityVersionHandler.OpenScene(name, false, true); } else { UnityVersionHandler.OpenScene(number, false, true); } }
/** * <summary>Loads the scene normally.</summary> * <param name = "forceReload">If True, the scene will be re-loaded if it is already open.</param> */ public void LoadLevel(bool forceReload = false) { if (!string.IsNullOrEmpty(name)) { UnityVersionHandler.OpenScene(name, forceReload); } else { UnityVersionHandler.OpenScene(number, forceReload); } }
private void SearchSceneForType(string sceneFile, ActionType actionType) { string sceneLabel = ""; if (sceneFile != "") { sceneLabel = "(Scene: " + sceneFile + ") "; UnityVersionHandler.OpenScene(sceneFile); } // Speech lines and journal entries ActionList[] actionLists = GameObject.FindObjectsOfType(typeof(ActionList)) as ActionList[]; foreach (ActionList list in actionLists) { int numFinds = SearchActionsForType(list.GetActions(), actionType); if (numFinds > 0) { ACDebug.Log(sceneLabel + " Found " + numFinds + " instances in '" + list.gameObject.name + "'"); } } }
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 }