#if UNITY_EDITOR && UNITY_STANDALONE using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEditor; using NPOI.SS.UserModel; using System.Linq; using System.IO; using System; namespace BFEditor { public class TutorialConfigBridge { static TutorialConfigBridge instance; public static TutorialConfigBridge Instance { get { if (instance == null) { instance = new TutorialConfigBridge(); } return instance; } } public const int EXTRA_ROW_NUM = 4;//约定的非内容行数 public const int SOURCE_ROW_INDEX = 1;//约定可作为格式规范的行 private static string tutorialExcelPath; public IWorkbook tutorialConfig; //excel表内容 *******************************************************************F***************************** public int idIndex; public int nextIndex; public int guideTypeStrIndex; public int guideDescribeStrIndex; public int typeIndex; public int stageIndex; public int importantIndex; public int stepsIndex; public int targetIndex; public int conditionIndex; public int nextConditionIndex; public int actionIndex; public int paramsIndex; //表现相关 public int handPosIndex; public int boxPosIndex; public int arrowIndex; public int boxHeadIndex; public int boxHeadActIndex; public int boxHeadFlipIndex; public int boxHeadPositionIndex; public int animationPosIndex; public int boxHeadScaleIndex; public int voiceIndex; public int highlightIndex; public int radiusIndex; public int maskColorIndex; /// /// 打开窗口前调用 用于加载Excel表内容 /// public bool LoadTutorialExcel() { var tutorialExcelPath = ExportExcelTools.GetDesignExcelPath() + "/tutorial.xlsx"; tutorialConfig = BFExcelHelper.GetWorkbook(tutorialExcelPath); idIndex = tutorialConfig.GetBFConfigKeyColumnIndex(); nextIndex = tutorialConfig.GetBFConfigfieldColumnIndex("next"); guideTypeStrIndex = tutorialConfig.GetBFConfigfieldColumnIndex("guideTypeStr"); guideDescribeStrIndex = tutorialConfig.GetBFConfigfieldColumnIndex("guideDescribeStr"); typeIndex = tutorialConfig.GetBFConfigfieldColumnIndex("type"); stageIndex = tutorialConfig.GetBFConfigfieldColumnIndex("stage"); importantIndex = tutorialConfig.GetBFConfigfieldColumnIndex("important"); stepsIndex = tutorialConfig.GetBFConfigfieldColumnIndex("steps"); targetIndex = tutorialConfig.GetBFConfigfieldColumnIndex("target"); conditionIndex = tutorialConfig.GetBFConfigfieldColumnIndex("condition"); nextConditionIndex = tutorialConfig.GetBFConfigfieldColumnIndex("nextCondition"); actionIndex = tutorialConfig.GetBFConfigfieldColumnIndex("action"); paramsIndex = tutorialConfig.GetBFConfigfieldColumnIndex("params"); handPosIndex = tutorialConfig.GetBFConfigfieldColumnIndex("handPos"); boxPosIndex = tutorialConfig.GetBFConfigfieldColumnIndex("boxPos"); arrowIndex = tutorialConfig.GetBFConfigfieldColumnIndex("arrow"); boxHeadIndex = tutorialConfig.GetBFConfigfieldColumnIndex("boxHead"); boxHeadActIndex = tutorialConfig.GetBFConfigfieldColumnIndex("boxHeadAct"); boxHeadFlipIndex = tutorialConfig.GetBFConfigfieldColumnIndex("boxHeadFlip"); boxHeadPositionIndex = tutorialConfig.GetBFConfigfieldColumnIndex("boxHeadPosition"); animationPosIndex = tutorialConfig.GetBFConfigfieldColumnIndex("animationPos"); boxHeadScaleIndex = tutorialConfig.GetBFConfigfieldColumnIndex("boxHeadScale"); voiceIndex = tutorialConfig.GetBFConfigfieldColumnIndex("voice"); highlightIndex = tutorialConfig.GetBFConfigfieldColumnIndex("highlight"); radiusIndex = tutorialConfig.GetBFConfigfieldColumnIndex("radius"); maskColorIndex = tutorialConfig.GetBFConfigfieldColumnIndex("maskColor"); return true; } public ICell _GetCell(int index, int columnIndex) { var sheet = tutorialConfig.GetBFSheet(); var row = sheet.GetRow(index); var cell = row.GetBFMissingCell(columnIndex); return cell; } public string _GetCellValue(int index, int columnIndex) { string cellValue = string.Empty; var cell = _GetCell(index, columnIndex); switch (cell.CellType) { case CellType.String://字符串类型 cellValue = cell.StringCellValue; break; case CellType.Numeric: //数值类型 cellValue = cell.NumericCellValue.ToString(); break; case CellType.Formula: //公式 cell.SetCellType(CellType.Numeric); cellValue = cell.NumericCellValue.ToString(); break; case CellType.Blank: break; case CellType.Boolean: break; case CellType.Error: break; default: break; } return cellValue; } public void _SetCellValue(int index, int columnIndex, string value) { var cell = _GetCell(index, columnIndex); cell.SetCellValue(value); } //默认引导类型说明 public string GetDefaultGuideTypeStr(TutorialType type) { string value = string.Empty; switch (type) { case TutorialType.NONE: value = string.Empty; break; case TutorialType.CLICK: value = "【手指】"; break; case TutorialType.CLICK_AND_TEXT: value = "【文本框】【手指】"; break; case TutorialType.TEXT: value = "【文本框】"; break; case TutorialType.HIGHLIGHT_AND_TEXT: value = "【文本框】【高亮】"; break; case TutorialType.CLICK_FULL_SCREEN: value = "【手指】"; break; case TutorialType.TALK: value = "【剧情】"; break; case TutorialType.ACTION: value = "【事件】"; break; case TutorialType.CLICK_IN_BUILDING_MARK: value = "【手指】"; break; case TutorialType.FIND_BUILDING_IN_SCENE: value = "【手指】"; break; case TutorialType.HIGHLIGHT_BOSS: value = "【文本框】【高亮】"; break; case TutorialType.HIGHLIGHT_COMEOUT: value = "【文本框】【高亮】"; break; case TutorialType.HIGHLIGHT_BATTLE_UNIT: value = "【文本框】【高亮】"; break; default: value = string.Empty; break; } return value; } //数据Get Set ****************************************************************************** //ID public string GetID(int index) { return _GetCellValue(index, idIndex); } public void SetID(int index, string value) { _SetCellValue(index, idIndex, value); } //Next public string GetNextID(int index) { return _GetCellValue(index, nextIndex); } public void SetNextID(int index, string value) { _SetCellValue(index, nextIndex, value); } //GuideTypeStr public string GetGuideTypeStr(int index) { return _GetCellValue(index, guideTypeStrIndex); } public void SetGuideTypeStr(int index, string value) { _SetCellValue(index, guideTypeStrIndex, value); } //GuideDescribeStr public string GetGuideDescribeStr(int index) { return _GetCellValue(index, guideDescribeStrIndex); } public void SetGuideDescribeStr(int index, string value) { _SetCellValue(index, guideDescribeStrIndex, value); } //Type public string GetType(int index) { return _GetCellValue(index, typeIndex); } public void SetType(int index, string value) { _SetCellValue(index, typeIndex, value); } //Stage public string GetStage(int index) { return _GetCellValue(index, stageIndex); } public void SetStage(int index, string value) { _SetCellValue(index, stageIndex, value); } //Important public string GetImportant(int index) { return _GetCellValue(index, importantIndex); } public void SetImportant(int index, string value) { _SetCellValue(index, importantIndex, value); } //Steps public string GetSteps(int index) { return _GetCellValue(index, stepsIndex); } public void SetSteps(int index, string value) { _SetCellValue(index, stepsIndex, value); } //Target public string GetTarget(int index) { return _GetCellValue(index, targetIndex); } public void SetTarget(int index, string value) { _SetCellValue(index, targetIndex, value); } //Condition public string GetCondition(int index) { return _GetCellValue(index, conditionIndex); } public void SetCondition(int index, string value) { _SetCellValue(index, conditionIndex, value); } //NextCondition public string GetNextCondition(int index) { return _GetCellValue(index, nextConditionIndex); } public void SetNextCondition(int index, string value) { _SetCellValue(index, nextConditionIndex, value); } //Action public string GetAction(int index) { return _GetCellValue(index, actionIndex); } public void SetAction(int index, string value) { _SetCellValue(index, actionIndex, value); } //ActionParams public string GetActionParams(int index) { return _GetCellValue(index, paramsIndex); } public void SetActionParams(int index, string value) { _SetCellValue(index, paramsIndex, value); } //HandPos public string GetHandPos(int index) { return _GetCellValue(index, handPosIndex); } public void SetHandPos(int index, string value) { _SetCellValue(index, handPosIndex, value); } //BoxPos public string GetBoxPos(int index) { return _GetCellValue(index, boxPosIndex); } public void SetBoxPos(int index, string value) { _SetCellValue(index, boxPosIndex, value); } //Arrow public string GetArrow(int index) { return _GetCellValue(index, arrowIndex); } public void SetArrow(int index, string value) { _SetCellValue(index, arrowIndex, value); } //BoxHead public string GetBoxHead(int index) { return _GetCellValue(index, boxHeadIndex); } public void SetBoxHead(int index, string value) { _SetCellValue(index, boxHeadIndex, value); } //BoxHeadAct public string GetBoxHeadAct(int index) { return _GetCellValue(index, boxHeadActIndex); } public void SetBoxHeadAct(int index, string value) { _SetCellValue(index, boxHeadActIndex, value); } //BoxHeadFlip public string GetBoxHeadFlip(int index) { return _GetCellValue(index, boxHeadFlipIndex); } public void SetBoxHeadFlip(int index, string value) { _SetCellValue(index, boxHeadFlipIndex, value); } //BoxHeadPosition public string GetBoxHeadPosition(int index) { return _GetCellValue(index, boxHeadPositionIndex); } public void SetBoxHeadPosition(int index, string value) { _SetCellValue(index, boxHeadPositionIndex, value); } //AnimationPos public string GetAnimationPosition(int index) { return _GetCellValue(index, animationPosIndex); } public void SetAnimationPosition(int index, string value) { _SetCellValue(index, animationPosIndex, value); } //BoxHeadScale public string GetBoxHeadScale(int index) { return _GetCellValue(index, boxHeadScaleIndex); } public void SetBoxHeadScale(int index, string value) { _SetCellValue(index, boxHeadScaleIndex, value); } //Voice public string GetVoice(int index) { return _GetCellValue(index, voiceIndex); } public void SetVoice(int index, string value) { _SetCellValue(index, voiceIndex, value); } //Voice public string GetHighlight(int index) { return _GetCellValue(index, highlightIndex); } public void SetHighlight(int index, string value) { _SetCellValue(index, highlightIndex, value); } //Radius public string GetRadius(int index) { return _GetCellValue(index, radiusIndex); } public void SetRadius(int index, string value) { _SetCellValue(index, radiusIndex, value); } //MaskColor public string GetMaskColor(int index) { return _GetCellValue(index, maskColorIndex); } public void SetMaskColor(int index, string value) { _SetCellValue(index, maskColorIndex, value); } //通用方法 ****************************************************************************** /// /// 获得实际行数 /// public int GetRowNum() { if (tutorialConfig == null) return 0; var sheet = tutorialConfig.GetBFSheet(); return sheet.LastRowNum + 1; } /// /// 插入一条新引导 /// /// public void InsertRow(int index) { if (tutorialConfig == null) return; var sheet = tutorialConfig.GetBFSheet(); //如果不是在最末处添加 则需要移动 if (index < sheet.LastRowNum + 1) { sheet.ShiftRows(index, sheet.LastRowNum, 1); } var row = sheet.CreateRow(index); var sourceRow = sheet.GetRow(SOURCE_ROW_INDEX);//作为可参考的原row for (int i = 0; i < sourceRow.LastCellNum; i++) { var cell = row.CreateCell(i); cell.SetCellType(sourceRow.GetCell(i).CellType); } //保存 SaveExcel(); //重新加载 LoadTutorialExcel(); } /// /// 删除一条引导 /// /// public void DeleteRow(int index) { if (tutorialConfig == null) return; var sheet = tutorialConfig.GetBFSheet(); sheet.ShiftRows(index + 1, sheet.LastRowNum + 1, -1); //保存 SaveExcel(); //重新加载 LoadTutorialExcel(); } /// /// 将现有数据保存至Excel /// public void SaveExcel() { if (tutorialConfig == null) return; var tutorialExcelPath = ExportExcelTools.GetDesignExcelPath() + "/tutorial.xlsx"; tutorialConfig.SaveBFExcel(tutorialExcelPath); } } } #endif