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); }
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); }