public void LinkProcess() { if (sourceObject == null) { return; } if (string.IsNullOrEmpty(CmdKey) || string.IsNullOrEmpty(BlockName)) { return; } if (csvLineData == null) { return; } Block _block = sourceObject.FindBlock(BlockName); if (_block == null) { return; } AdvCSVLine line = AdvUtility.SearchLineByKey(csvLineData, CmdKey); if (line != null) { line.generateBlock = _block; } ViewCSVLineData(sourceObject); AdvUtility.Log("Link Block Success"); }
public void InitializeByParams(object[] param) { CommandParam data = param[0] as CommandParam; AdvKeyContent bgKeys = AdvKeyContent.GetCurrentInstance(); if (string.Equals(data.command, "CgOff", System.StringComparison.OrdinalIgnoreCase)) { display = BackgroundDisplayType.HideAll; return; } if (bgKeys != null) { spriteCG = bgKeys.GetDiceCGByKey(data.image); if (spriteCG == null) { if (!string.IsNullOrEmpty(data.image)) { AdvUtility.LogWarning("找不到CG檔:" + data.image + " , 於 行數 " + (this.itemId - 3)); } } else { atlasCG = spriteCG.AtlasAsset; } } }
void PlayCommand(int commandId) { //if(this.workFlowchart.csvCmdList[commandId] == null) if (AdvUtility.FindCommandByCSVLine(workFlowchart, commandId) == null) { AdvUtility.LogWarning("找不到該行數 Command !"); return; } Command targetCmd = AdvUtility.FindCommandByCSVLine(workFlowchart, commandId); var targetBlock = targetCmd.ParentBlock; //ControlBackground bg = targetCmd.CSVBackgroundInfo; if (targetBlock.IsExecuting()) { // The Block is already executing. // Tell the Block to stop, wait a little while so the executing command has a // chance to stop, and then start execution again from the new command. targetBlock.Stop(); workFlowchart.StartCoroutine(RunBlock(workFlowchart, targetBlock, targetCmd.CommandIndex, 0.2f)); } else { // Block isn't executing yet so can start it now. workFlowchart.ExecuteBlock(targetBlock, targetCmd.CommandIndex); AdvManager.Instance.StartAdvScene(); } }
public void StartProcess() { AdvUpdateOption _option = new AdvUpdateOption() { sayText = _sayContentText, selectionText = _SelectionContentText, sayTerm = _saySpeakerTerm, saySprite = _sayAvatarSprite, sayVoice = _sayVoice, blockName = _blockName, background = _background, CG = _CG, billboard = _billboard, BGM = _bgm, }; if (sourceCSV == null) { AdvUtility.LogError("沒有選擇 CSV檔案"); return; } if (WifeEditorUtility.isInPrefabStage() == false) { Debug.LogError("必須要進入 prefab 編輯模式裡才能夠使用此功能"); return; } List <AdvCSVLine> outdate = AdvUtility.UpdateBlockByCSV(sourceObject, sourceCSV.text, _option, true); willRemove = outdate; UnityEditor.EditorUtility.SetDirty(sourceObject.gameObject); }
public void ReUpdateLastCSV() { if (objectList.Count <= 0) { return; } AdvUpdateOption _option = new AdvUpdateOption(); foreach (FlowchartExtend sourceObject in objectList) { if (sourceObject == null) { continue; } if (string.IsNullOrEmpty(sourceObject.csvBackup)) { AdvUtility.LogError("沒有Last CSV"); return; } List <AdvCSVLine> willRemove = AdvUtility.UpdateBlockByCSV(sourceObject, sourceObject.csvBackup, _option, true); if (willRemove.Count > 0) { Debug.LogWarning("Will Remove greater 0 , may be some error... (" + sourceObject.gameObject.name + ")"); } UnityEditor.EditorUtility.SetDirty(sourceObject.gameObject); PrefabUtility.SavePrefabAsset(sourceObject.gameObject); } }
public void AutoLink() { AdvUtility.AutoLinkCSVLine(sourceObject); UnityEditor.EditorUtility.SetDirty(sourceObject.gameObject); ViewCSVLineData(sourceObject); Debug.Log("Auto link success"); }
public static void RebuildCSVLine(Fungus.FlowchartExtend sourceObject) { AdvUtility.RebuildCSVLine(sourceObject); AdvUtility.AutoLinkCSVLine(sourceObject); UnityEditor.EditorUtility.SetDirty(sourceObject.gameObject); Debug.Log("Rebuild CSVLine & Link Block Success"); }
public void ReadFileReplace(string filePath) { var sr = new StreamReader(File.Open(filePath, FileMode.Open)); string rsult = sr.ReadToEnd(); sr.Dispose(); AdvUtility.UpdateBlockByCSV(workFlowchart, rsult, null, false); }
public void RebuildAdvCSVLine() { AdvUtility.RebuildCSVLine(sourceObject); UnityEditor.EditorUtility.SetDirty(sourceObject.gameObject); ViewCSVLineData(sourceObject); Debug.Log("Rebuild success"); }
public void RemoveUnlinkCSVLine() { if (!EditorUtility.DisplayDialog("Warning", "Are you sure to remove unlink CSVLine?", "OK")) { return; } foreach (var item in csvLineNoLink) { csvLineData.Remove(item); } UnityEditor.EditorUtility.SetDirty(sourceObject.gameObject); ViewCSVLineData(sourceObject); AdvUtility.Log("Remove Success"); }
void CreateBlocksByCsv(string originTxt) { FlowchartExtend flowchart = GetFlowchart() as FlowchartExtend; if (flowchart == null) { Debug.Log("This is not a FlowchartExtend"); return; } AdvUtility.CreateBlockByCSV(flowchart, originTxt, true); flowchart.ClearSelectedCommands(); DeselectAll(); UpdateBlockCollection(); }
public void StartRemove() { foreach (var item in willRemove) { sourceObject.csvLines.Remove(item); Fungus.Command cmd = item.generatedCommand; if (cmd != null) { string msg = string.Format("Remove deleted cmd : {0} -> {1} -> {2} & {3}", cmd.gameObject.name, AdvUtility.FindParentBlock(cmd).BlockName, cmd.ItemId, item.keys); Debug.Log(msg); AdvUtility.FindParentBlock(cmd).CommandList.Remove(cmd); Object.DestroyImmediate(cmd, true); } } willRemove.Clear(); }
//從哪個Block 進入 public void IntoBlock() { Block targetBlock = workFlowchart.FindBlock(BlockInput.text); if (targetBlock != null) { AdvUtility.Log("尋找到 Block :" + targetBlock.name); workFlowchart.StopAllBlocks(); AdvManager.Instance.StartAdvScene(); workFlowchart.ExecuteBlock(targetBlock); } else { AdvUtility.Log("尋找 Block 失敗 (" + BlockInput.text + ")"); } }
public override void OnEnter() { if (timelineAsset == null) { Continue(); return; } if (_inSceneTarget != FungusExt.AdvTargetObject.SelectedGameObject) { _target0 = AdvManager.Instance.GetAdvTargetObject(_inSceneTarget); } if (_target0 == null) { AdvUtility.LogWarning("> Timeline 指定的立繪已經不存在,因此跳過指令 "); Continue(); return; } if (playableDirectors == null) { PlayableDirector tempDirector = new GameObject("tempDirector").AddComponent <PlayableDirector>(); tempDirector.stopped += delegate { Destroy(tempDirector.gameObject); }; playableDirectors = tempDirector; } playableDirectors.playableAsset = timelineAsset; playableDirectors.SetBindingGameObject("Target0", _target0); playableDirectors.Play(timelineAsset); if (WaitForFinished) { playableDirectors.stopped += delegate { Continue(); }; } else { Continue(); } }
public void InitializeByParams(object[] param) { CommandParam data = param[0] as CommandParam; UIBillboardController _prefab = null; AdvKeyContent ADVKeys = AdvKeyContent.GetCurrentInstance(); if (ADVKeys != null) { _prefab = ADVKeys.GetBillboardPrefabByKey(data.image); if (_prefab != null) { if (!string.IsNullOrEmpty(data.name)) { useBody = data.name; } if (!string.IsNullOrEmpty(data.arg2)) { string[] splite = data.arg2.Split('|'); useEquips = new List <string>(); foreach (var item in splite) { useEquips.Add(item); } } } else if (!string.IsNullOrEmpty(data.image)) { AdvUtility.LogWarning("找不到Billboard prefab檔:" + data.image + " , 於 行數 " + (this.itemId - 3)); if (Application.isPlaying) { //_diceSprite = AdvManager.Instance.DefaultDiceSprite; } } } targetPrefab = _prefab; display = StageExtend.GetDisplayTypeByCommand(data.command); spriteDistance = StageExtend.GetBbDistanceByString(data.arg1); toPosition = StageExtend.GetBbPositionByString(data.target); hideWhich = StageExtend.GetBbHideByString(data.target); useDefaultSettings = true; }
void UpdateData(string Result) { string sourceCSV = Result; Fungus.FlowchartExtend sourceObject = pageRef.prefab; sourceObject.GoogleSheetID = spreadsheetId; sourceObject.GooglePageID = sheet_gid; List <AdvCSVLine> outdate = AdvUtility.UpdateBlockByCSV(sourceObject, sourceCSV, option, true); List <AdvCSVLine> willRemove = outdate; UnityEditor.EditorUtility.SetDirty(sourceObject.gameObject); PrefabUtility.SavePrefabAsset(sourceObject.gameObject); if (willRemove == null) { return; } if (popupDetal) { AdvPrefabUpdateResult.OpenWindow(sourceObject, willRemove); return; } if (!autoRemove) { return; } foreach (var item in willRemove) { sourceObject.csvLines.Remove(item); Fungus.Command cmd = item.generatedCommand; if (cmd != null) { string msg = string.Format("Auto remove update lost cmd ... {0} -> {1} -> {2}&cmd{3}", cmd.gameObject.name, AdvUtility.FindParentBlock(cmd).BlockName, cmd.ItemId, item.keys); Debug.Log(msg); AdvUtility.FindParentBlock(cmd).CommandList.Remove(cmd); Object.DestroyImmediate(cmd); } } willRemove.Clear(); }
public void InitializeByParams(object[] param) { CommandParam data = param[0] as CommandParam; AdvKeyContent bgKeys = AdvKeyContent.GetCurrentInstance(); if (bgKeys != null) { spriteBackground = bgKeys.GetBackgroundByKey(data.image); if (spriteBackground == null && !string.IsNullOrEmpty(data.image)) { AdvUtility.LogWarning("找不到BG檔:" + data.image + " , 於 行數 " + (this.itemId - 3)); } } if (data.command == "BgOff") { display = BackgroundDisplayType.HideAll; } }
void CreateData(string Result) { string sourceCSV = Result; Fungus.FlowchartExtend sourceObject = pageRef.prefab; if (sourceObject == null) { string path = string.Format("{0}/{1}.prefab", AdvScenarioManager.Instance.DefaultPrefabFolder, string.IsNullOrEmpty(pageRef.description) ? pageRef.Page_gid : pageRef.description); Fungus.FlowchartExtend tempObj = new GameObject().AddComponent <Fungus.FlowchartExtend>(); sourceObject = PrefabUtility.SaveAsPrefabAsset(tempObj.gameObject, path).GetComponent <Fungus.FlowchartExtend>(); pageRef.prefab = sourceObject; MonoBehaviour.DestroyImmediate(tempObj.gameObject); } sourceObject.GoogleSheetID = spreadsheetId; sourceObject.GooglePageID = sheet_gid; AdvUtility.CreateBlockByCSV(sourceObject, sourceCSV, true); }
protected virtual void CatchLocalizeText() { //Catch Localize Data when focus if (flowchart == null) { return; } MenuExtend t = target as MenuExtend; string textTerm = $"{flowchart.GoogleSheetID}.{flowchart.GooglePageID}.{csvCommandKeyProp.stringValue}"; string localText = FungusExt.LocalizeManager.GetLocalizeText(textTerm); if (string.IsNullOrEmpty(localText)) { string blockName = AdvUtility.FindParentBlock(flowchart, t).BlockName; Debug.LogError($"At : {t.gameObject.name} / {blockName} / {t.ItemId}"); } textProp.stringValue = string.IsNullOrEmpty(localText) ? $"(key not found : {textTerm})" : localText; serializedObject.ApplyModifiedProperties(); }
public void StartRemove() { if (willRemove == null) { return; } if (sourceObject == null) { return; } foreach (var item in willRemove) { sourceObject.csvLines.Remove(item); Command cmd = item.generatedCommand; if (cmd != null) { AdvUtility.FindParentBlock(cmd).CommandList.Remove(cmd); DestroyImmediate(cmd); } Block blk = item.generateBlock; if (blk != null) { var commandList = blk.CommandList; for (int j = 0; j < commandList.Count; ++j) { DestroyImmediate(commandList[j]); } if (blk._EventHandler != null) { DestroyImmediate(blk._EventHandler); } sourceObject.ClearSelectedCommands(); DestroyImmediate(blk); } } willRemove.Clear(); }
public void InitializeByParams(object[] param) { FungusExt.CommandParam data = param[0] as FungusExt.CommandParam; this._inSceneTarget = AdvUtility.GetAdvTargetObjectByString(data.target); AdvKeyContent ADVKeys = AdvKeyContent.GetCurrentInstance(); if (ADVKeys != null) { if (!string.IsNullOrEmpty(data.image)) { //從AdvKey 取得 Asset 資源 this.timelineAsset = ADVKeys.GetTimelineByKey(data.image); //如果有填Key 但又找不到的話 if (this.timelineAsset == null) { AdvUtility.LogWarning("找不到Timeline檔:" + data.image + " , 於 行數 " + (this.itemId - 3)); } } } }
public AdvCSVLine(string[] titleLabel, string[] lineData) { //搜尋開頭字串正不正確 int id_key = Array.IndexOf(titleLabel, AdvUtility.TitleKeys); int id_command = Array.IndexOf(titleLabel, AdvUtility.TitleCommand); int id_target = Array.IndexOf(titleLabel, AdvUtility.TitleTarget); int id_arg1 = Array.IndexOf(titleLabel, AdvUtility.TitleArg1); int id_arg2 = Array.IndexOf(titleLabel, AdvUtility.TitleArg2); int id_image = Array.IndexOf(titleLabel, AdvUtility.TitleImage); int id_name = Array.IndexOf(titleLabel, AdvUtility.TitleName); if (id_key == -1 || id_command == -1 || id_target == -1 || titleLabel.Length <= AdvUtility.CSVLanguageDataStart) { AdvUtility.LogWarning("CSV 檔案沒有正確的開頭資訊 (Keys, Command, Target, Arg1, Arg2, Text)"); return; } keys = lineData[id_key]; Command = lineData[id_command]; Target = lineData[id_target]; Arg1 = lineData[id_arg1]; Arg2 = lineData[id_arg2]; Image = lineData[id_image]; Name = lineData[id_name]; localizeText = new List <LocalizeText>(); for (int i = AdvUtility.CSVLanguageDataStart; i < titleLabel.Length; i++) { localizeText.Add(new LocalizeText() { tag = titleLabel[i], content = lineData[i] }); } beUpdate = true; }
public void ReadFile(string filePath) { string rsult = string.Empty; AdvManager.Instance.useDebugMsg = true; try { var sr = new StreamReader(File.Open(filePath, FileMode.Open)); rsult = sr.ReadToEnd(); sr.Dispose(); } catch (Exception e) { AdvUtility.Log("CSV 無法讀取, 確認是否有其他程式使用該檔案中 (" + e.Message + ")"); return; } if (workFlowchart != null) { Destroy(workFlowchart.gameObject); } GameObject copyFlowchart = Instantiate(flowchartPrefab); workFlowchart = copyFlowchart.GetComponent <FlowchartExtend>(); //workFlowchart = flowchartPrefab.GetComponent<Flowchart>(); firstCall = workFlowchart.GetComponent <CallExtend>(); //1. 開始 ADV系統 //2. 清除舊的除錯訊息 AdvManager.Instance.StartAdvScene(); AdvDebugMsg.ClearMessage(); AdvDebugMessageBox.ClearMessage(); //顯示讀取結果面板 ResultPanel.gameObject.SetActive(true); //開始讀取 AdvUtility.CreateBlockByCSV(workFlowchart, rsult, false); }
static CmdResult SetCommandPara(Command srcCmd, string[] titleLabel, string[] lineData, AdvUpdateOption advOption, SearchBlockHandler searchHandler) { //搜尋開頭字串正不正確 int id_key = Array.IndexOf(titleLabel, AdvUtility.TitleKeys); int id_command = Array.IndexOf(titleLabel, AdvUtility.TitleCommand); int id_target = Array.IndexOf(titleLabel, AdvUtility.TitleTarget); int id_arg1 = Array.IndexOf(titleLabel, AdvUtility.TitleArg1); int id_arg2 = Array.IndexOf(titleLabel, AdvUtility.TitleArg2); int id_image = Array.IndexOf(titleLabel, AdvUtility.TitleImage); int id_name = Array.IndexOf(titleLabel, AdvUtility.TitleName); if (id_key == -1 || id_command == -1 || id_target == -1 || titleLabel.Length <= CSVLanguageDataStart) { AdvUtility.LogWarning("CSV 檔案沒有正確的開頭資訊 (Keys, Command, Target, Arg1, Arg2, Text)"); return(CmdResult.Error); } ICommand iCmd = srcCmd as ICommand; if (iCmd == null) { return(CmdResult.Error); } List <LocalizeText> locTexts = new List <LocalizeText>(); for (int i = CSVLanguageDataStart; i < titleLabel.Length; i++) { locTexts.Add(new LocalizeText() { tag = titleLabel[i], content = lineData[i] }); } CmdResult cmdResult = CmdResult.Error; string srcCommand = lineData[id_command]; //如果指令為 Say if (String.Equals(srcCommand, CSVCommandSay[0], StringComparison.OrdinalIgnoreCase) || srcCommand == "") { iCmd.InitializeByParams(ParamCreateCommand( lineData[id_key], lineData[id_command], lineData[id_target], lineData[id_arg1], lineData[id_arg2], lineData[id_image], lineData[id_name], locTexts, searchHandler, advOption)); cmdResult = (advOption.sayText || advOption.sayTerm || advOption.saySprite) ? CmdResult.Success : CmdResult.Ignore; } else { for (int i = 0; i < CSVCommandMapping.GetLength(0); i++) { if (String.Equals(srcCommand, CSVCommandMapping[i, 0], StringComparison.OrdinalIgnoreCase)) { if (CheckOptionInIndex(advOption, i)) { iCmd.InitializeByParams(ParamCreateCommand( lineData[id_key], lineData[id_command], lineData[id_target], lineData[id_arg1], lineData[id_arg2], lineData[id_image], lineData[id_name], locTexts, searchHandler, advOption)); cmdResult = CmdResult.Success; } else { cmdResult = CmdResult.Ignore; } break; } } } if (cmdResult == CmdResult.Error) { Debug.Log($"設置參數時失敗: {iCmd.CSVCommandKey}"); } return(cmdResult); }
public static bool VerifyKey(string content) { CsvParser csvParser = new CsvParser(); string[][] csvTable = csvParser.Parse(content); //判斷CSV 檔案 有無內容 if (csvTable.Length <= 1) { AdvUtility.Log("資料不完整或是格是不正確"); return(false); } //搜尋開頭字串正不正確 int id_key = Array.IndexOf(csvTable[0], AdvUtility.TitleKeys); int id_command = Array.IndexOf(csvTable[0], AdvUtility.TitleCommand); int id_target = Array.IndexOf(csvTable[0], AdvUtility.TitleTarget); int id_arg1 = Array.IndexOf(csvTable[0], AdvUtility.TitleArg1); int id_arg2 = Array.IndexOf(csvTable[0], AdvUtility.TitleArg2); int id_image = Array.IndexOf(csvTable[0], AdvUtility.TitleImage); int id_name = Array.IndexOf(csvTable[0], AdvUtility.TitleName); //判斷CSV 檔案格式正不正確 if (id_command == -1) { AdvUtility.LogWarning("資料不完整或是格是不正確,確認 CSV 是否為逗號分隔 (?"); return(false); } if (id_command == -1 || id_target == -1 || id_arg1 == -1 || id_arg2 == -1 || id_image == -1 || id_name == -1) { AdvUtility.LogWarning("CSV 檔案沒有正確的開頭資訊 (Keys, Command, Target, Arg1, Arg2, Image, Name, Content_zh-tw)"); return(false); } int rowLength = csvTable.Length; int columnLength = csvTable[0].Length; //檢查是否有重複的值 int lineid = 1; List <string> Allkeys = new List <string>(); foreach (var csvLine in csvTable) { if (csvLine[id_key] == "") { AdvUtility.Log("匯入中止,CSV中有空白的Key,將Key值填充好後再次匯入 行數(" + lineid + ")"); return(false); } if (Allkeys.Contains(csvLine[id_key])) { AdvUtility.Log("匯入中止,CSV中有相同的Key,將重複的Key刪除留空後再次匯入 key(" + csvLine[id_key] + ")"); return(false); } Allkeys.Add(csvLine[id_key]); lineid++; } return(true); }
public static string AssignKey(string content) { CsvParser csvParser = new CsvParser(); string[][] csvTable = csvParser.Parse(content); //判斷CSV 檔案 有無內容 if (csvTable.Length <= 1) { AdvUtility.Log("資料不完整或是格是不正確"); return(null); } int id_key = Array.IndexOf(csvTable[0], AdvUtility.TitleKeys); int rowLength = csvTable.Length; int columnLength = csvTable[0].Length; //檢查是否有重複的值 int lineid = 1; List <string> Allkeys = new List <string>(); foreach (var csvLine in csvTable) { if (csvLine[id_key] == "") { AdvUtility.Log("匯入中止,CSV中有空白的Key,將Key值填充好後再次匯入 行數(" + lineid + ")"); return(null); } if (Allkeys.Contains(csvLine[id_key])) { AdvUtility.Log("匯入中止,CSV中有相同的Key,將重複的Key刪除留空後再次匯入 key(" + csvLine[id_key] + ")"); return(null); } Allkeys.Add(csvLine[id_key]); lineid++; } //至此確保所有的 Key 是唯一, 而且有部分是空白 int randId = 0; for (int i = 1; i < rowLength; i++) { if (csvTable[i][id_key] == "") { //為空白處給值 csvTable[i][id_key] = "cmd" + randId; randId++; while (Allkeys.Contains(csvTable[i][id_key])) { csvTable[i][id_key] = "cmd" + randId; randId++; } } } // Rebuild output string output = ""; for (int i = 0; i < rowLength; i++) { for (int j = 0; j < columnLength; j++) { if (j != 0) { output += ","; } output += csvTable[i][j]; } output += "\n"; } return(output); }
public static List <AdvCSVLine> UpdateBlockByCSV(FlowchartExtend srcFlowchart, string csvFile, AdvUpdateOption advOption, bool inEditor) { //讀入 CSV 檔案,使其分為 string 二維陣列 CsvParser csvParser = new CsvParser(); string[][] csvTable = csvParser.Parse(csvFile); //判斷CSV 檔案 有無內容 if (csvTable.Length <= 1) { AdvUtility.Log("No data rows in file"); return(null); } //搜尋開頭字串正不正確 int id_key = Array.IndexOf(csvTable[0], AdvUtility.TitleKeys); int id_command = Array.IndexOf(csvTable[0], AdvUtility.TitleCommand); int id_target = Array.IndexOf(csvTable[0], AdvUtility.TitleTarget); int id_arg1 = Array.IndexOf(csvTable[0], AdvUtility.TitleArg1); int id_arg2 = Array.IndexOf(csvTable[0], AdvUtility.TitleArg2); int id_image = Array.IndexOf(csvTable[0], AdvUtility.TitleImage); int id_name = Array.IndexOf(csvTable[0], AdvUtility.TitleName); //判斷CSV 檔案格式正不正確 if (id_command == -1) { AdvUtility.LogWarning("確認 CSV 是否為逗號分隔 (?"); LogBox("確認 CSV 檔案是否為逗號分隔 (? "); return(null); } if (id_key == -1 || id_command == -1 || id_target == -1 || csvTable[0].Length <= CSVLanguageDataStart) { AdvUtility.LogWarning("CSV 檔案沒有正確的開頭資訊 (Keys, Command, Target, Arg1, Arg2, Text)"); return(null); } //至此 CSV檔案正常 srcFlowchart.csvBackup = csvFile; if (AdvKeyContent.GetCurrentInstance() == null) { AdvUtility.LogWarning("Adv Keys 尚未初始化! 資源讀取將會失敗!"); } if (advOption == null) { advOption = new AdvUpdateOption(); } SearchBlockHandler searchHandler = new SearchBlockHandler(); ControlBackground workBackground = null; Block srcBlock = srcFlowchart.MainBlock; int srcCmdIndex = 0; SetCSVLineReadyToUpdate(srcFlowchart.csvLines); //針對每一行CSV做更新 for (int i = 1; i < csvTable.Length; i++) { //取出Command 以及 Key string srcCommandString = csvTable[i][id_command]; string cmdKey = csvTable[i][id_key]; //建立新的CSVLine AdvCSVLine newLine = new AdvCSVLine(csvTable[0], csvTable[i]); //尋找舊的CSVLine AdvCSVLine oldLine = SearchLineByKey(srcFlowchart.csvLines, cmdKey); //若CSV Line中具有該key if (oldLine != null) { //從Key提取 Command , 設置該 Command 所在 Block //2019.7.25 有可能這個Command 已經被編劇砍掉了,所以回傳null,但CSVLine 還保留著這個 Reference Command srcCmd = oldLine.generatedCommand; //如果是*Block CSVLine, 則不會有 Command if (srcCmd != null) { //這邊的動作是為了追蹤已經到哪個Block,哪個Line, 使得新指令能夠依賴此資訊插入 //srcBlock = srcCmd.ParentBlock; // Fungus 的 ParentBlock 為 Property srcBlock = FindParentBlock(srcFlowchart, srcCmd); if (srcBlock == null) { //Fungus 的 ParentBlock 為 Property , 這是不可序列化的, 因此只限定於開啟prefab時, 此值才能運作 AdvUtility.LogError("更新失敗, 嘗試跳出Prefab 視窗後,重新進入Prefab"); throw new NullReferenceException("更新失敗, 嘗試跳出Prefab 視窗後,重新進入Prefab"); } srcCmdIndex = srcBlock.CommandList.FindIndex(x => x == srcCmd); } //更新targetLine (AdvCSVLine)資料 , 但僅止於CSVLine資料更新, 實際Prefab 要不要動還是以參數為主 newLine.generatedCommand = srcCmd; ReplaceLine(srcFlowchart.csvLines, oldLine, newLine); CmdResult cmdResult = CmdResult.Error; string ResultMessage = ""; //在該Key中,如果Cmd值相同,則更新資料,(不同則新增資料 待製作) if (String.Equals(oldLine.Command, newLine.Command, StringComparison.OrdinalIgnoreCase)) { if (srcCommandString.StartsWith("*")) { //以新Block 為基準工作 if (oldLine.generateBlock != null) { srcBlock = oldLine.generateBlock; srcCmdIndex = -1; } else { //以舊Key 來補救 舊Key 無 Cmd資訊 string _oldName = oldLine.Command; Block workBlock = srcFlowchart.FindBlock(_oldName); if (workBlock != null) { srcBlock = workBlock; srcCmdIndex = -1; newLine.generateBlock = srcBlock; cmdResult = CmdResult.Success; AdvUtility.Log("> 以舊Key 更新 GenerateBlock"); } } newLine.generateBlock = srcBlock; if (advOption.blockName) { cmdResult = CmdResult.Success; } else { cmdResult = CmdResult.Ignore; } } else { //確保這個 Command 沒被編劇砍掉 才執行 if (srcCmd != null) { cmdResult = SetCommandPara(srcCmd, csvTable[0], csvTable[i], advOption, searchHandler); //更新command中的 CSVLine, Key SetupCommand(srcFlowchart, srcCmd, i, cmdKey); //如果指令是背景, 設置切入劇情時的背景 if (srcCmd.GetType() == typeof(ControlBackground)) { workBackground = srcCmd as ControlBackground; } } else { ResultMessage += $"該 command ({oldLine.Command}) 已於flowchart中刪除\n"; } } } else { //不同Command 可能是 Block 不同 if (srcCommandString.StartsWith("*")) { Block oldBlock = oldLine.generateBlock; if (oldBlock != null) { //以新Block 為基準工作 srcBlock = oldLine.generateBlock; srcCmdIndex = -1; newLine.generateBlock = srcBlock; if (advOption.blockName) { srcBlock.BlockName = srcCommandString; searchHandler.createBlockEvent?.Invoke(srcBlock); cmdResult = CmdResult.Success; } else { cmdResult = CmdResult.Ignore; } } else { AdvUtility.Log("> 舊Key 不包含 Block 資訊 , 嘗試以舊 Name 找 Block"); //允許不同, 執行以下 Block 命名相關指令, 記錄點,建立Block string _oldName = oldLine.Command; string _newName = srcCommandString; Block workBlock = srcFlowchart.FindBlock(_oldName); //AdvUtility.Log("尋找Block:" + _oldName + " , 結果 :" + workBlock); if (workBlock != null) { //以新Block 為基準工作 srcBlock = workBlock; srcCmdIndex = -1; newLine.generateBlock = srcBlock; if (advOption.blockName) { workBlock.BlockName = _newName; searchHandler.createBlockEvent?.Invoke(workBlock); //AdvUtility.Log("啟動 Invoke"); cmdResult = CmdResult.Success; } else { cmdResult = CmdResult.Ignore; } } else { AdvUtility.Log("> 無法找到舊Block 名稱 : " + _oldName); } } } else { //不處理不同Cmd的情況 ResultMessage += $"來源與目標的 Command 類型不同 , 放棄更新 {oldLine.Command} != {newLine.Command}\n"; } } if (cmdResult == CmdResult.Error) { AdvUtility.Log("> 更新指令 from key:" + cmdKey + " >> <color=red>失敗</color> (" + srcFlowchart.GetName() + ") >> " + ResultMessage); } //else if(cmdResult == CmdResult.Success) // AdvUtility.Log("> 更新指令 from key:" + cmdKey + " 成功 (" + srcFlowchart.GetName() + ")"); } else { //如果沒有該Key, 則新增資料 AdvUtility.Log("> <color=magenta>找不到Key值:" + cmdKey + " , 因此建立新指令</color>"); bool cmdResult = false; if (srcCommandString.StartsWith("*")) { cmdResult = true; string _name = srcCommandString; Vector2 newPosition = new Vector2(srcBlock._NodeRect.x, srcBlock._NodeRect.y); srcBlock = srcFlowchart.CreateBlock(newPosition + new Vector2(100, 75)); srcCmdIndex = -1; srcBlock.BlockName = _name; newLine.generateBlock = srcBlock; srcFlowchart.csvLines.Add(newLine); searchHandler.createBlockEvent?.Invoke(srcBlock); } else { //## Command 會接在Block最後面,因此需要調換位置 Command newCommand = CreateCommand(srcFlowchart, srcBlock, csvTable[0], csvTable[i], searchHandler); if (newCommand != null) { cmdResult = true; SetupCommand(srcFlowchart, newCommand, i, cmdKey); //## 需要調換Command位置 srcBlock.CommandList.RemoveAt(srcBlock.CommandList.Count - 1); srcBlock.CommandList.Insert(srcCmdIndex + 1, newCommand); srcCmdIndex = srcCmdIndex + 1; //設置flowchart中,CSVLine表key值對應的Command , 用於更新資料 newLine.generatedCommand = newCommand; srcFlowchart.csvLines.Add(newLine); //如果指令是背景, 設置切入劇情時的背景 if (newCommand.GetType() == typeof(ControlBackground)) { workBackground = newCommand as ControlBackground; } } } if (cmdResult == false) { AdvUtility.Log("> 更新指令 from key:" + cmdKey + " >> <color=red>失敗</color> (" + srcFlowchart.GetName() + ")"); } //else // AdvUtility.Log("> 更新指令 from key:" + cmdKey + " 成功 (" + srcFlowchart.GetName() + ")"); } } AdvUtility.Log("> 更新指令 順利結束"); List <AdvCSVLine> outdate = GetCSVLineNeverUpdate(srcFlowchart.csvLines); return(outdate); }
static Command CreateCommand(FlowchartExtend workFlowchart, Block workBlock, string[] titleLabel, string[] lineData, SearchBlockHandler searchHandler) { //搜尋開頭字串正不正確 int id_key = Array.IndexOf(titleLabel, AdvUtility.TitleKeys); int id_command = Array.IndexOf(titleLabel, AdvUtility.TitleCommand); int id_target = Array.IndexOf(titleLabel, AdvUtility.TitleTarget); int id_arg1 = Array.IndexOf(titleLabel, AdvUtility.TitleArg1); int id_arg2 = Array.IndexOf(titleLabel, AdvUtility.TitleArg2); int id_image = Array.IndexOf(titleLabel, AdvUtility.TitleImage); int id_name = Array.IndexOf(titleLabel, AdvUtility.TitleName); if (id_key == -1 || id_command == -1 || id_target == -1) { AdvUtility.LogWarning("CSV 檔案沒有正確的開頭資訊 (Keys, Command, Target, Arg1, Arg2, Text)"); return(null); } List <LocalizeText> locTexts = new List <LocalizeText>(); for (int i = CSVLanguageDataStart; i < titleLabel.Length; i++) { locTexts.Add(new LocalizeText() { tag = titleLabel[i], content = lineData[i] }); } string srcCommand = lineData[id_command]; Command commandCreated = null; //如果指令為 Say if (String.Equals(srcCommand, CSVCommandSay[0], StringComparison.OrdinalIgnoreCase) || srcCommand == "") { if (lineData[id_image] == "" && lineData[id_name] == "" && locTexts.Count == 0) { return(null); // Prevent only "keys" CSVLine } commandCreated = AddCommandToBlock(workFlowchart, workBlock, GetTypeOfCommand(CSVCommandSay[1])); ICommand iCmd = commandCreated as ICommand; iCmd?.InitializeByParams(ParamCreateCommand( lineData[id_key], lineData[id_command], lineData[id_target], lineData[id_arg1], lineData[id_arg2], lineData[id_image], lineData[id_name], locTexts, searchHandler)); } //或者其他類型 else { for (int i = 0; i < CSVCommandMapping.GetLength(0); i++) { if (String.Equals(srcCommand, CSVCommandMapping[i, 0], StringComparison.OrdinalIgnoreCase)) { commandCreated = AddCommandToBlock(workFlowchart, workBlock, GetTypeOfCommand(CSVCommandMapping[i, 1])); ICommand iCmd = commandCreated as ICommand; iCmd?.InitializeByParams(ParamCreateCommand( lineData[id_key], lineData[id_command], lineData[id_target], lineData[id_arg1], lineData[id_arg2], lineData[id_image], lineData[id_name], locTexts, searchHandler)); break; } } } return(commandCreated); }
//主要CSV 讀入部分 public static void CreateBlockByCSV(FlowchartExtend srcFlowchart, string csvFile, bool inEditor) { //讀入 CSV 檔案,使其分為 string 二維陣列 CsvParser csvParser = new CsvParser(); string[][] csvTable = csvParser.Parse(csvFile); //判斷CSV 檔案 有無內容 if (csvTable.Length <= 1) { AdvUtility.Log("No data rows in file"); return; } //搜尋開頭字串正不正確 int id_key = Array.IndexOf(csvTable[0], AdvUtility.TitleKeys); int id_command = Array.IndexOf(csvTable[0], AdvUtility.TitleCommand); int id_target = Array.IndexOf(csvTable[0], AdvUtility.TitleTarget); int id_arg1 = Array.IndexOf(csvTable[0], AdvUtility.TitleArg1); int id_arg2 = Array.IndexOf(csvTable[0], AdvUtility.TitleArg2); int id_image = Array.IndexOf(csvTable[0], AdvUtility.TitleImage); int id_name = Array.IndexOf(csvTable[0], AdvUtility.TitleName); //判斷CSV 檔案格式正不正確 if (id_command == -1) { AdvUtility.LogWarning("確認 CSV 是否為逗號分隔 (?"); LogBox("確認 CSV 檔案是否為逗號分隔 (? "); return; } if (id_key == -1 || id_command == -1 || id_target == -1) { AdvUtility.LogWarning("CSV 檔案沒有正確的開頭資訊 (Keys, Command, Target, Arg1, Arg2, Content_zh-tw)"); return; } //至此 CSV檔案正常 srcFlowchart.csvBackup = csvFile; if (AdvKeyContent.GetCurrentInstance() == null) { AdvUtility.LogWarning("Adv Keys 尚未初始化! 資源讀取將會失敗!"); } if (srcFlowchart.AutoGenerateBlock != null) { AdvUtility.LogWarning("該Block 已經使用過Create指令, 將清除並重新Create!"); } foreach (var comp in srcFlowchart.GetComponents <Component>()) { if (!(comp is Transform) && !(comp is FlowchartExtend)) { MonoBehaviour.DestroyImmediate(comp, true); } } //視覺化建立的 Block 的位置 Vector2 newNodePosition = Vector2.zero; newNodePosition = new Vector2( 50 / srcFlowchart.Zoom - srcFlowchart.ScrollPos.x + UnityEngine.Random.Range(-10.0f, 10.0f), 50 / srcFlowchart.Zoom - srcFlowchart.ScrollPos.y + UnityEngine.Random.Range(-10.0f, 10.0f) ); newNodePosition = GetNewBlockPosition(ref newNodePosition, new Vector2(50, 50)); //1. 儲存Block 資訊用於CSV架構 //2. SearchHandler為搜尋Block標籤用的事件,當新Block建立時,觸發事件去找該Block是不是該Command要找的Block Dictionary <string, Block> blockTree = new Dictionary <string, Block>(); SearchBlockHandler searchHandler = new SearchBlockHandler(); //建立入口Block Block baseBlock = srcFlowchart.CreateBlock(newNodePosition); srcFlowchart.AutoGenerateBlock = baseBlock; //Main Block 設置完成 baseBlock.BlockName = AdvUtility.CSVImportedBlockName; //Main Block 名稱設置為 Main blockTree.Add(baseBlock.BlockName, baseBlock); //第一行指令設置為 建立入口用 Call Entrance = AddCommandToBlock(srcFlowchart, baseBlock, GetTypeOfCommand("CallExtend")) as Call; //1. 正在添加的Block //2. 該Command 對應的背景, 用於跳場景用 Block workBlock = baseBlock; ControlBackground workBackground = null; srcFlowchart.csvLines = new List <AdvCSVLine>(); //重置 CSV Lines , 這樣的設置前提是每個 Flowchart只匯入一個 CSV LogBox("初始化完畢..."); //針對每一行CSV做處理 for (int i = 1; i < csvTable.Length; i++) { //建立新的CSV Line, 讀入該Line資料進去 AdvCSVLine thisLine = new AdvCSVLine(csvTable[0], csvTable[i]); //加入該CSV Line 進入 flowchart CSVLine 集合 srcFlowchart.csvLines.Add(thisLine); string srcCommand = csvTable[i][id_command]; bool comResult = false; //如果Command是*記錄點,建立Block,否則建立Command if (srcCommand.StartsWith("*")) { comResult = true; string _name = srcCommand; workBlock = srcFlowchart.CreateBlock(GetNewBlockPosition(ref newNodePosition, new Vector2(150, 50))); workBlock.BlockName = _name; blockTree.Add(workBlock.BlockName, workBlock); thisLine.generateBlock = workBlock; searchHandler.createBlockEvent?.Invoke(workBlock); } else { Command newCommand = CreateCommand(srcFlowchart, workBlock, csvTable[0], csvTable[i], searchHandler); if (newCommand != null) { comResult = true; SetupCommand(srcFlowchart, newCommand, i, csvTable[i][id_key]); //設置flowchart中,CSVLine表key值對應的Command , 用於更新資料 thisLine.generatedCommand = newCommand; //如果指令是背景, 設置切入劇情時的背景 if (newCommand.GetType() == typeof(ControlBackground)) { workBackground = newCommand as ControlBackground; } } } if (comResult == false) { LogBox("讀取第 " + i + " 行指令 失敗 , 指令碼(Command)錯誤"); } else { LogBox("讀取第 " + i + " 行指令 成功"); } } LogBox("文本讀取完畢!"); }
void OnFlowchartEnd() { AdvUtility.Log("> Adv 系統結束"); AdvManager.Instance.StopAdvScene(); }