private void Create() { if (location == VariableLocation.Global) { if (KickStarter.variablesManager == null) { return; } Undo.RecordObject(KickStarter.variablesManager, "Add " + location + " variables"); } else if (location == VariableLocation.Local) { if (KickStarter.localVariables == null) { return; } Undo.RecordObject(KickStarter.localVariables, "Add " + location + " variables"); } else if (location == VariableLocation.Component) { if (variables == null) { return; } Undo.RecordObject(variables, "Add " + location + " variables"); } if (Vars == null) { return; } for (int i = 0; i < numVars; i++) { GVar variable = new GVar(newVar); variable.AssignUniqueID(GetIDArray()); variable.label = newVar.label + "_" + i.ToString(); Vars.Add(variable); } Debug.Log(numVars + " new " + location + " variables created"); }
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(); } } }
private void ConvertLocalToGlobal(GVar localVariable, int localIndex) { if (localVariable == null) { return; } if (EditorUtility.DisplayDialog("Convert " + localVariable.label + " to Global 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 Global DeactivateAllVars(); GVar newGlobalVariable = new GVar(localVariable); int newGlobalID = newGlobalVariable.AssignUniqueID(GetIDArray(vars)); vars.Add(newGlobalVariable); // Update current scene bool updatedScene = false; ActionList[] actionLists = FindObjectsOfType <ActionList>(); foreach (ActionList actionList in actionLists) { foreach (Action action in actionList.actions) { bool updatedActionList = action.ConvertLocalVariableToGlobal(localVariable.id, newGlobalID); if (updatedActionList) { updatedScene = true; UnityVersionHandler.CustomSetDirty(actionList, true); ACDebug.Log("Updated Action " + actionList.actions.IndexOf(action) + " of ActionList '" + actionList.name + "'", actionList); } } } Conversation[] conversations = FindObjectsOfType <Conversation>(); foreach (Conversation conversation in conversations) { bool updatedConversation = conversation.ConvertLocalVariableToGlobal(localVariable.id, newGlobalID); if (updatedConversation) { updatedScene = true; UnityVersionHandler.CustomSetDirty(conversation, true); ACDebug.Log("Updated Conversation '" + conversation + "'"); } } if (updatedScene) { UnityVersionHandler.SaveScene(); } // Update Speech Manager if (KickStarter.speechManager) { KickStarter.speechManager.ConvertLocalVariableToGlobal(localVariable, newGlobalID); } // Remove old Local KickStarter.localVariables.localVars.RemoveAt(localIndex); EditorUtility.SetDirty(KickStarter.localVariables); UnityVersionHandler.SaveScene(); // Mark for saving EditorUtility.SetDirty(this); AssetDatabase.SaveAssets(); } } }