public override void SetStageOutInfo() { int out_num = 1; string ExcelPath = Application.dataPath + "/StreamingAssets/Excel/MyOut.xls"; ExcelOperator excelClass = new ExcelOperator(); DataTable OutData = new DataTable("OutData"); OutData = excelClass.ExcelReader(ExcelPath, caseName); if (stage_current > OutData.Rows.Count) { Debug.LogError("当前步骤OUT没有设置参数"); } else { //Debug.Log(OutData.Rows[stage_current][out_num].ToString()); if (OutData.Rows[stage_current][out_num].ToString() == "0") { GSKDATA.OutInfo[out_num] = false; //CaseClass.RBP_Set_OT_Data(out_num, GSKDATA.OutInfo[out_num]); ScreenScript.setOutData(out_num, 0); } else { GSKDATA.OutInfo[out_num] = true; //CaseClass.RBP_Set_OT_Data(out_num, GSKDATA.OutInfo[out_num]); ScreenScript.setOutData(out_num, 1); } } }
//代码初始化 public void CodeInitial() { List <string> stage_code = new List <string>(); string ExcelPath = Application.dataPath + "/StreamingAssets/Excel/MyCode.xls"; ExcelOperator excelClass = new ExcelOperator(); DataTable CodeData = new DataTable("CodeData"); CodeData = excelClass.ExcelReader(ExcelPath, caseName); int i = 0; while (i < CodeData.Rows.Count) { string tempcode = CodeData.Rows[i][stage_current].ToString(); if (tempcode != "") { stage_code.Add(CodeData.Rows[i][stage_current].ToString()); } i++; } if (stage_code.Count > 0) { //Debug.Log("程序行:" + stage_code.Count +" " + FileName); GSKFile.CreateFile(FileName); GSKFile.writeContents(stage_code, FileName); //GSKDATA.CurrentProgramName = FileName; } else { GSKFile.DeleteProgram(FileName); //FileName = "777777.prl"; } }
//案例三周边设备的还原 private void DevicePosition_case3() { string ExcelPath = Application.dataPath + "/StreamingAssets/Excel/MyDevice.xls"; Vector3 position = Vector3.zero; Vector3 posture = Vector3.zero; Vector3 scale = Vector3.zero; string fathername = ""; string devicename = ""; ExcelOperator excelClass = new ExcelOperator(); DataTable DeviceData = new DataTable("DeviceData"); DeviceData = excelClass.ExcelReader(ExcelPath, "case3"); devicename = DeviceData.Rows[0][0].ToString(); fathername = DeviceData.Rows[0][1].ToString(); position = StrToVector(DeviceData.Rows[0][2]); posture = StrToVector(DeviceData.Rows[0][3]); scale = StrToVector(DeviceData.Rows[0][4]); if (DeviceData.Rows[0][5].ToString() == "1") { origianlWorkpiece.SetActive(true); } else { origianlWorkpiece.SetActive(false); } Transform device = GameObject.Find(devicename).GetComponent <Transform>(); device.parent = GameObject.Find(fathername).GetComponent <Transform>(); device.localPosition = position; device.localEulerAngles = posture; device.localScale = scale; origianlWorkpiece.SetActive(true); }
//向当前sheet中添加数据 //addContent--添加到表的新的一条记录 public void AddData(string filepath, string sheetName, string[] addContent) { ExcelOperator excelReader = new ExcelOperator(); DataTable sheetTable = excelReader.ExcelReader(filepath + ".xls", sheetName); string connectionStr = "Driver={Microsoft Excel Driver (*.xls)}; ReadOnly=True; DriverID=790; Dbq=" + filepath + ";"; OdbcConnection odbcCon = new OdbcConnection(connectionStr); try{ OdbcCommand oCmd = new OdbcCommand(); oCmd.Connection = odbcCon; odbcCon.Open(); string updateStr = ""; updateStr = "insert into [" + sheetName + "$] values("; for (int j = 0; j < sheetTable.Columns.Count; j++) { if (j == sheetTable.Columns.Count - 1) { updateStr += "'" + addContent[j] + "')"; } else { updateStr += "'" + addContent[j] + "',"; } } oCmd.CommandText = updateStr; oCmd.ExecuteNonQuery(); odbcCon.Close(); }catch { UnityEngine.Debug.LogError("Excel更新错误,请检查相关信息---"); odbcCon.Close(); } }
//删除当前sheet中数据 //keyValue--要删除的一条记录的主键值 //key--表的主键的列 public void DeleteData(string filepath, string sheetName, string keyValue, int rowIndex, int key) { ExcelOperator excelReader = new ExcelOperator(); DataTable sheetTable = excelReader.ExcelReader(filepath + ".xls", sheetName); string connectionStr = "Driver={Microsoft Excel Driver (*.xls)}; ReadOnly=True; DriverID=790; Dbq=" + filepath + ";"; OdbcConnection odbcCon = new OdbcConnection(connectionStr); //删除为空行 try{ OdbcCommand oCmd = new OdbcCommand(); oCmd.Connection = odbcCon; odbcCon.Open(); string updateStr = "update [" + sheetName + "$] set "; for (int j = 0; j < sheetTable.Columns.Count; j++) { if (j == sheetTable.Columns.Count - 1) { updateStr += sheetTable.Columns[j].ColumnName + "=null"; } else { updateStr += sheetTable.Columns[j].ColumnName + "=null, "; } } updateStr += " where " + sheetTable.Columns[key].ColumnName + " ='" + keyValue + "'"; oCmd.CommandText = updateStr; oCmd.ExecuteNonQuery(); odbcCon.Close(); }catch { UnityEngine.Debug.LogError("Excel更新错误,请检查相关信息---"); odbcCon.Close(); } }
public override void DevicePosition() { string ExcelPath = Application.dataPath + "/StreamingAssets/Excel/MyDevice.xls"; Vector3 position = Vector3.zero; Vector3 posture = Vector3.zero; string fathername = ""; string devicename = ""; ExcelOperator excelClass = new ExcelOperator(); DataTable DeviceData = new DataTable("DeviceData"); DeviceData = excelClass.ExcelReader(ExcelPath, caseName); if (stage_current > DeviceData.Rows.Count) { Debug.LogError("当前步骤设备没有设置参数"); } else { devicename = DeviceData.Rows[0][0].ToString(); fathername = DeviceData.Rows[stage_current][1].ToString(); position = StrToVector(DeviceData.Rows[stage_current][2]); posture = StrToVector(DeviceData.Rows[stage_current][3]); } //Debug.Log(devicename); Transform device = GameObject.Find(devicename).GetComponent <Transform>(); device.parent = GameObject.Find(fathername).GetComponent <Transform>(); device.localPosition = position; device.localEulerAngles = posture; //device.localScale = new Vector3(0.1f, 0.1f, 0.1f); }
//案例六周边设备的还原 private void DevicePosition_case6() { Debug.Log("device return"); GameObject.Find("MyMotion").GetComponent <InstantiateObjects>().DestoryBox(); string ExcelPath = Application.dataPath + "/StreamingAssets/Excel/MyDevice.xls"; Vector3 position = Vector3.zero; Vector3 posture = Vector3.zero; Vector3 scale = Vector3.zero; string fathername = ""; string devicename = ""; ExcelOperator excelClass = new ExcelOperator(); DataTable DeviceData = new DataTable("DeviceData"); DeviceData = excelClass.ExcelReader(ExcelPath, "case6"); devicename = DeviceData.Rows[0][0].ToString(); fathername = DeviceData.Rows[0][1].ToString(); position = StrToVector(DeviceData.Rows[0][2]); posture = StrToVector(DeviceData.Rows[0][3]); scale = StrToVector(DeviceData.Rows[0][4]); Transform device = GameObject.Find(devicename).GetComponent <Transform>(); device.parent = GameObject.Find(fathername).GetComponent <Transform>(); device.localPosition = position; device.localEulerAngles = posture; device.localScale = scale; }
//设置相机位置 public void CameraPosition() { string ExcelPath = Application.dataPath + "/StreamingAssets/Excel/MyCamera.xls"; Camera camera = GameObject.Find("CameraFree").GetComponent <Camera>(); TransPosition(); Vector3 position = Vector3.zero; Vector3 posture = Vector3.zero; float size = 0; ExcelOperator excelClass = new ExcelOperator(); DataTable CameraData = new DataTable("CameraData"); CameraData = excelClass.ExcelReader(ExcelPath, caseName); if (stage_current > CameraData.Rows.Count) { Debug.LogError("当前步骤相机没有设置参数"); } else { //deal with the data from the excel //Debug.Log(CameraData.Rows[stage_current][1]); size = Convert.ToSingle(CameraData.Rows[stage_current][1]); position = StrToVector(CameraData.Rows[stage_current][2]); posture = StrToVector(CameraData.Rows[stage_current][3]); } camera.orthographicSize = size; camera.transform.position = position; camera.transform.eulerAngles = posture; }
//表格创建 void ExcelCreate() { if (!Directory.Exists(Application.dataPath + "/_TempExcel")) { Directory.CreateDirectory(Application.dataPath + "/_TempExcel"); } ExcelOperator excelWirter = new ExcelOperator(); //为Excel写入做准备 List <string> colName = new List <string>(); colName.Add("NAME"); List <List <string> > fileContent = new List <List <string> >(); List <string> colContent = new List <string>(); Transform[] selections = Selection.GetTransforms(SelectionMode.Unfiltered); foreach (Transform child in selections) { TransformRecursion(child, colContent); } for (int i = 0; i < colContent.Count; i++) { List <string> newCol = new List <string>(); newCol.Add(colContent[i]); fileContent.Add(newCol); } excelWirter.ExcelWriter(Application.dataPath + "/_TempExcel/" + excelName + ".xls", "NAME", colName, fileContent, true); }
//编辑界面初始化 public void PanelStageInitial() { //整体界面初始化 PanelInitial(); string winname = ""; string Speed_Bt = ""; string Zuobiao_Bt = ""; string ExcelPath = Application.dataPath + "/StreamingAssets/Excel/MyScreen.xls"; if (stage_current > 0) { GSKDATA.CurrentProgramName = FileName; } else { GSKDATA.CurrentProgramName = "777777.prl"; } ExcelOperator excelClass = new ExcelOperator(); DataTable PanelData = new DataTable("PanelData"); PanelData = excelClass.ExcelReader(ExcelPath, caseName); winname = PanelData.Rows[stage_current][0].ToString(); Speed_Bt = PanelData.Rows[stage_current][1].ToString(); Zuobiao_Bt = PanelData.Rows[stage_current][2].ToString(); WinInitial(winname); }
/// <summary> /// 功能控制参数初始化,默认全部允许. /// </summary> static public void Initialize() { //link = GameObject.Find("MainScript").GetComponent<RPCManager>(); excelPath = MotionPara.taskRootPath + MotionPara.taskName + "/FunctionManager.xls"; ExcelOperator excelOp = new ExcelOperator(); DataTable funcData = excelOp.ExcelReader(excelPath, "FUNCTION", "A", "A"); for (int i = 0; i < funcData.Rows.Count; i++) { string ID = Convert.ToString(funcData.Rows[i][0]).ToUpper(); if (ID != "") { IDDic.Add(ID, true); } } DataTable btnData = excelOp.ExcelReader(excelPath, "BUTTON", "A", "A"); for (int i = 0; i < btnData.Rows.Count; i++) { string ID = Convert.ToString(btnData.Rows[i][0]).ToUpper(); if (ID != "") { BtnDic.Add(ID, true); } } }
public static void Regex() { string content = ""; string filePath = Environment.CurrentDirectory + "\\content.txt"; ReadFile(ref content, filePath); string str = ""; filePath = Environment.CurrentDirectory + "\\sat.txt"; List <string> wordList = ReadFile(ref str, filePath); DataTable dt = new DataTable(); dt.Columns.Add("word"); dt.Columns.Add("main"); dt.Columns.Add("all"); string patten1 = "tgt\":\"(?<tgt>.*?)\",\"src\":\"(?<src>.*?)\"}"; Regex reg = new Regex(patten1); Dictionary <string, DataRow> dic = new Dictionary <string, DataRow>(); MatchCollection result = reg.Matches(content); foreach (Match temp in result) { DataRow dr = dt.NewRow(); dt.Rows.Add(dr); dr["word"] = temp.Groups["src"].Value; dr["main"] = temp.Groups["tgt"].Value; dic[temp.Groups["src"].Value] = dr; if (wordList.Contains(temp.Groups["src"].Value)) { wordList.Remove(temp.Groups["src"].Value); } } string patten2 = "tgt\":\"(?<tgt>.*?)\",\"src\":\"(?<src>.*?)\"}.*?entries\":\\[\"\",(?<entries>.*?)\\],\"type"; reg = new Regex(patten2); result = reg.Matches(content); foreach (Match temp in result) { dic[temp.Groups["src"].Value]["all"] = temp.Groups["entries"].Value; } str = ""; foreach (string word in wordList) { str += word + "\r\n"; } ExcelOperator.ExportData(dt, @"C:\Users\chent\Desktop\youdao.xlsx"); }
//正交相机位置确定 public void CameraPosition() { ExcelOperator excelClass = new ExcelOperator(); DataTable camera_data = new DataTable("cameraTable"); switch (GSKDATA.Scene_NO) { case 10: upDownTrans.position = GameObject.Find("Shape046").GetComponent <Transform>().position; rightLeftTrans.position = GameObject.Find("Shape046").GetComponent <Transform>().position; camera_data = excelClass.ExcelReader(ExcelPath, "case10"); break; case 1: upDownTrans.position = GameObject.Find("Shape12").GetComponent <Transform>().position; rightLeftTrans.position = GameObject.Find("Shape12").GetComponent <Transform>().position; camera_data = excelClass.ExcelReader(ExcelPath, "case1"); break; case 2: upDownTrans.position = GameObject.Find("Shape12").GetComponent <Transform>().position; rightLeftTrans.position = GameObject.Find("Shape12").GetComponent <Transform>().position; camera_data = excelClass.ExcelReader(ExcelPath, "case2"); break; case 3: upDownTrans.position = GameObject.Find("scene3").GetComponent <Transform>().position; rightLeftTrans.position = GameObject.Find("scene3").GetComponent <Transform>().position; camera_data = excelClass.ExcelReader(ExcelPath, "case3"); Scene3_table.SetActive(false); break; case 4: upDownTrans.position = GameObject.Find("scene4").GetComponent <Transform>().position; rightLeftTrans.position = GameObject.Find("scene4").GetComponent <Transform>().position; camera_data = excelClass.ExcelReader(ExcelPath, "case4"); break; case 5: upDownTrans.position = GameObject.Find("scene6").GetComponent <Transform>().position; rightLeftTrans.position = GameObject.Find("scene6").GetComponent <Transform>().position; camera_data = excelClass.ExcelReader(ExcelPath, "case0"); break; case 6: upDownTrans.position = GameObject.Find("scene3").GetComponent <Transform>().position; rightLeftTrans.position = GameObject.Find("scene3").GetComponent <Transform>().position; camera_data = excelClass.ExcelReader(ExcelPath, "case6"); Scene3_table.SetActive(true); break; } //set position of camera this.camera.orthographicSize = Convert.ToSingle(camera_data.Rows[0][1]); this.transform.position = StrToVector(camera_data.Rows[0][2]); this.transform.eulerAngles = StrToVector(camera_data.Rows[0][3]); }
private void bRemoveAllMacros_Click(object sender, EventArgs e) { LoggingForm logger = new LoggingForm(); logger.Show(this); string excelFilePath = textBoxExcelFilePath.Text; ExcelOperator access = new ExcelOperator(); access.AddCommand(new RemoveMacros(logger)); access.invoke(excelFilePath, true); }
private void TryOpenExcel(string name) { ExcelOperator excel = new ExcelOperator(); excel.OpenExcel(name); int idxRow = 2; while (true) { Range test = excel[idxRow, 1]; if (test.Value2 == null) { break; } else { idxRow++; } } int cnt = idxRow; Form_ImportProgress fip = new Form_ImportProgress(cnt - 2); fip.Show(); for (idxRow = 2; idxRow < cnt; idxRow++) { Range range = excel[idxRow, 1]; string[] raw1 = new string[6]; for (int idxColumn = 1; idxColumn <= 6; idxColumn++) { Range cell = excel[idxRow, idxColumn]; raw1[idxColumn - 1] = cell.Value2; } if (BookList.isExist(raw1[0], raw1[1], raw1[3])) { continue; } string[] raw2 = new string[6]; int word = (int)Math.Round(excel[idxRow, 7].Value2); raw2[0] = word.ToString(); for (int idxColumn = 8; idxColumn <= 12; idxColumn++) { Range cell = excel[idxRow, idxColumn]; raw2[idxColumn - 7] = (string)cell.Value2; } BookDetail item = new BookDetail(0, raw1, raw2); BookList.Add(BookList.getNextBID(), item); // ProgressBar fip.ChangeTo(idxRow - 1); } excel.QuitExcel(); fip.Close(); }
IEnumerator phase_11()//reapeat the prograss { if (GSKDATA.SoftCurrentMode == "Teach") { //CameraPosition(); float waittime = 0; ShowTips(); ReadTips(TitleName[stage_current]); waittime = GetVoiceTime(TitleName[stage_current]); yield return(StartCoroutine(Timer(waittime))); LstageRead(); List <string> stage_code = new List <string>(); string ExcelPath = Application.dataPath + "/StreamingAssets/Excel/MyCode.xls"; ExcelOperator excelClass = new ExcelOperator(); DataTable CodeData = new DataTable("CodeData"); CodeData = excelClass.ExcelReader(ExcelPath, caseName); int i = 0; while (i < CodeData.Rows.Count) { string tempcode = CodeData.Rows[i][stage_current + 1].ToString(); if (tempcode != "") { stage_code.Add(CodeData.Rows[i][stage_current + 1].ToString()); } i++; } if (stage_code.Count > 0) { //Debug.Log("程序行:" + stage_code.Count +" " + FileName); GSKFile.CreateFile(FileName); GSKFile.writeContents(stage_code, FileName); //GSKDATA.CurrentProgramName = FileName; } else { GSKFile.DeleteProgram(FileName); //FileName = "777777.prl"; } ScreenScript.SetCurrentWin_Teach("F3"); } else { Debug.Log("pass" + stage_current); GetCurrentCode(); GetCurrentPosition(); yield return(StartCoroutine(DoubleE())); } }
//计算总的步数,并记录每一大步的名称 public void CalculateTotalStage() { TitleName.Clear(); string ExcelPath = Application.dataPath + "/StreamingAssets/Excel/MyStage.xls"; ExcelOperator excelClass = new ExcelOperator(); DataTable TeachWData = new DataTable("TeachWData"); TeachWData = excelClass.ExcelReader(ExcelPath, caseName); StageTotal = TeachWData.Rows.Count; for (int i = 0; i < StageTotal; i++) { TitleName.Add((string)TeachWData.Rows[i][0]); } }
private void buttonDoExport_Click(object sender, EventArgs e) { LoggingForm logger = new LoggingForm(); logger.Show(this); string excelFilePath = textBoxExcelFilePath.Text; string codeFolderPath = GetMacroFolderPath(true); MacroEnv env = new MacroEnv(codeFolderPath); ExcelOperator access = new ExcelOperator(); access.AddCommand(new ExportMacros(logger, env, cbOverrideExport.Checked)); //access.AddCommand(new RemoveMacros(null)); access.invoke(excelFilePath, false); }
//读取每一阶段具体小步骤的信息 public void LstageRead() { stage_name = new List <string>(); string ExcelPath = Application.dataPath + "/StreamingAssets/Excel/MyStage.xls"; ExcelOperator excelClass = new ExcelOperator(); DataTable TeachWData = new DataTable("TeachWData"); TeachWData = excelClass.ExcelReader(ExcelPath, caseName); int i = 0; while (i < TeachWData.Rows.Count) { stage_name.Add(TeachWData.Rows[i][stage_current + 1].ToString()); i++; } }
/// <summary> /// 功能控制参数初始化,默认全部允许. /// </summary> static public void Initialize() { //link = GameObject.Find("MainScript").GetComponent<RPCManager>(); excelPath = MotionPara.taskRootPath + MotionPara.taskName + "/FunctionManager.xls"; ExcelOperator excelOp = new ExcelOperator(); DataTable funcData = excelOp.ExcelReader(excelPath, "FUNCTION", "A", "A"); for(int i = 0; i < funcData.Rows.Count; i++){ string ID = Convert.ToString(funcData.Rows[i][0]).ToUpper(); if(ID != "") IDDic.Add(ID, true); } DataTable btnData = excelOp.ExcelReader(excelPath, "BUTTON", "A", "A"); for(int i = 0; i < btnData.Rows.Count; i++){ string ID = Convert.ToString(btnData.Rows[i][0]).ToUpper(); if(ID != "") BtnDic.Add(ID, true); } }
//设置层级关系 void SetHierarchy() { if (!Directory.Exists(Application.dataPath + "/_TempExcel")) { Debug.LogError("请先创建_TempExcel文件夹!"); return; } if (!File.Exists(Application.dataPath + "/_TempExcel/" + excelName + ".xls")) { Debug.LogError(excelName + ".xls文件不存在!"); return; } ExcelOperator excelReader = new ExcelOperator(); DataTable setData = excelReader.ExcelReader(Application.dataPath + "/_TempExcel/" + excelName + ".xls", "SelectionsName", "A", "B"); string tempName = ""; string tempParent = ""; Transform transChild; Transform transParent; for (int i = 0; i < setData.Rows.Count; i++) { tempName = (string)setData.Rows[i][0]; tempParent = (string)setData.Rows[i][1]; try{ transChild = GameObject.Find(tempName).transform; }catch { transChild = new GameObject("EmptyObject").transform; } if (tempParent != "null") { try{ transParent = GameObject.Find(tempParent).transform; }catch { transParent = new GameObject("EmptyParent").transform; } } else { transParent = null; } transChild.parent = transParent; } }
public override void TryInit(object initObj) { myConfig = new ManagerConfig((string)initObj); databaseHost = myConfig.DatabaseHost; databaseName = myConfig.DatabaseName; myMongoDBOperator = new MongoDBOperator(databaseHost, databaseName); myExcalOperator = new ExcelOperator(); shotNoVersionNo = new ShotNoVersionNo(); tagPathGroup = new TagPathGroup(); currentShotNo = new CurrentShotNo(); if (!myMongoDBOperator.IsDatabaseExist()) { Console.WriteLine("The specified database does not exist! Please use the \"Import\" method to create the initial database from the configuration dir"); } }
private void Button_Click_2(object sender, RoutedEventArgs e) { string fileUrl = countFile.Text; string directoryPath = this.directoryPath.Text.Trim(); if (directoryPath.Length == 0) { DirectoryResult.Content = "保存目录未填写"; return; } ExcelOperator excelOperator = new ExcelOperator(directoryPath, fileUrl, rootWord.Text); excelOperator.Open(); excelOperator.ReadApartResult(); excelOperator.CountSearch(); CountResult.Content = "统计进度:" + "统计结束,请查看文件"; //excelOperator.CountSearch(); }
//更新当前sheet中数据 //contents--更新表的单条记录 //key--表的主键的列 public void UpdateData(string filepath, string sheetName, string[] contents, int key) { ExcelOperator excelReader = new ExcelOperator(); DataTable sheetTable = excelReader.ExcelReader(filepath + ".xls", sheetName); string connectionStr = "Driver={Microsoft Excel Driver (*.xls)}; ReadOnly=True; DriverID=790; Dbq=" + filepath + ";"; OdbcConnection odbcCon = new OdbcConnection(connectionStr); try{ OdbcCommand oCmd = new OdbcCommand(); oCmd.Connection = odbcCon; odbcCon.Open(); string updateStr = "update [" + sheetName + "$] set "; for (int j = 0; j < sheetTable.Columns.Count; j++) { if (j != key) { if (j == sheetTable.Columns.Count - 1) { updateStr += sheetTable.Columns[j].ColumnName + "='" + contents[j] + "'"; } else { updateStr += sheetTable.Columns[j].ColumnName + "='" + contents[j] + "', "; } } } updateStr += " where " + sheetTable.Columns[key].ColumnName + " ='" + contents[key] + "'"; oCmd.CommandText = updateStr; oCmd.ExecuteNonQuery(); odbcCon.Close(); } //catch{ // UnityEngine.Debug.LogError("Excel更新错误,请检查相关信息---" ); // odbcCon.Close(); //} catch (System.Exception e) { UnityEngine.Debug.LogError(e.Message); UnityEngine.Debug.LogError("Excel更新错误,请检查相关信息---"); odbcCon.Close(); } }
public void TestWriteRead() { var list = new List <Test2>(); list.Add(new Test2 { Count = 1, Log = "Test1" }); list.Add(new Test2 { Count = 2, Log = "周扬测试" }); var table = SimpleOrm.SimpleOrm.BuildDataTable(list); ExcelOperator.WriteOnNewSheet(table, path); var table2 = ExcelOperator.QueryAll(path, typeof(Test2).Name); var result = SimpleOrm.SimpleOrm.Read(table2); Assert.AreEqual(2, result.Count()); Assert.AreEqual("1", result.First().Count); Assert.AreEqual("周扬测试", result.Last().Log); }
//Prefab化 private void Prefablize() { if (!File.Exists(Application.dataPath + "/_TempExcel/" + excelName + ".xls")) { Debug.LogError(Application.dataPath + "/_TempExcel/" + excelName + ".xls文件不存在,请确认!"); return; } ExcelOperator excelReader = new ExcelOperator(); DataTable preData = excelReader.ExcelReader(Application.dataPath + "/_TempExcel/" + excelName + ".xls", "NAME", "A", "A"); string prefabName = (string)preData.Rows[0][0]; Transform tempTrans = ((GameObject)Resources.Load("Prefabs/ReplacePre/" + prefabName)).transform; Vector3 tempPos = Vector3.zero; Vector3 tempAngle = Vector3.zero; Vector3 tempScale = Vector3.zero; Transform parentTrans; Transform tempChild; for (int i = 0; i < preData.Rows.Count; i++) { string tempName = (string)preData.Rows[i][0]; try{ tempChild = GameObject.Find(tempName).transform; }catch { Debug.LogError(tempName + "---该物体不存在!"); return; } parentTrans = tempChild.parent; tempPos = tempChild.localPosition; tempAngle = tempChild.localEulerAngles; tempScale = tempChild.localScale; DestroyImmediate(tempChild.gameObject); Transform instanceTrans = (Transform)Instantiate(tempTrans, Vector3.zero, Quaternion.identity); instanceTrans.name = tempName; instanceTrans.parent = parentTrans; instanceTrans.localScale = tempScale; instanceTrans.localPosition = tempPos; instanceTrans.localEulerAngles = tempAngle; } Debug.Log("恭喜!替换已完成!"); }
/// <summary> /// 根据响应表格禁止相应的功能. /// </summary> /// <param name='sheet_name'> /// Sheet_name. /// </param> public void ForbitFunction(string sheet_name) { ExcelOperator excelOp = new ExcelOperator(); DataTable funcData = excelOp.ExcelReader(excelPath, sheet_name, "A", "A"); AllAllow(); string keys = ""; for (int i = 0; i < funcData.Rows.Count; i++) { keys = Convert.ToString(funcData.Rows[i][0]); if (IDDic.ContainsKey(keys)) { IDDic[keys] = false; } else { Debug.LogWarning("ID NOT FOUND! Check sheet '" + sheet_name + "', Position 'A" + (i + 2).ToString() + "';"); } } }
public void onClickAdd(object sender, EventArgs e) { TreeNode selectnode = appViews.window.treeView1.SelectedNode; if (selectnode != null) { int id = 0; int.TryParse(selectnode.Name, out id); if (id == 1) { OpenFileDialog dialog = new OpenFileDialog(); dialog.Multiselect = false; dialog.Title = "请选择文件夹"; dialog.Filter = "(excel文件)|*.xls;*.xlsx"; if (dialog.ShowDialog() == DialogResult.OK) { appModels.mainPageModel.addTreeView(dialog.SafeFileName); ExcelOperator.ImportToSqLite(dialog.FileName, AfterTableImport); } } } }
//设置各个轴的位置 public void AxisPosition() { ToolPosition(); string ExcelPath = Application.dataPath + "/StreamingAssets/Excel/MyAxis.xls"; ExcelOperator excelClass = new ExcelOperator(); DataTable AxisData = new DataTable("AxisTable"); AxisData = excelClass.ExcelReader(ExcelPath, caseName); if (stage_current > AxisData.Rows.Count) { Debug.LogError("当前步骤轴没有设置参数"); } else { //deal with the data from the excel float j1 = Convert.ToSingle(AxisData.Rows[stage_current][1]); float j4 = Convert.ToSingle(AxisData.Rows[stage_current][4]); float j2 = Convert.ToSingle(AxisData.Rows[stage_current][2]); float j5 = Convert.ToSingle(AxisData.Rows[stage_current][5]); float j3 = Convert.ToSingle(AxisData.Rows[stage_current][3]); float j6 = Convert.ToSingle(AxisData.Rows[stage_current][6]); //J1_6Initial(j1, j2, j3, j4, j5, j6, z1, z2); MotionScript.AxisPositionSet(j1, j2, j3, j4, j5, j6); } }
protected void Button1_Click(object sender, EventArgs e) { using (SqlConnection cn = new SqlConnection()) { ExcelOperator excel = new ExcelOperator(); excel.CreateExcel();//创建excel表 cn.ConnectionString = sqlconn; cn.Open(); string eid = Session["eid"].ToString(); string cmdtext = string.Format("select * from 员工 where eid ='{0}'", eid);//将编辑好的语句连接好 SqlDataAdapter sda = new SqlDataAdapter(cmdtext, cn); SqlCommand cmd = new SqlCommand(cmdtext, cn); SqlDataAdapter adapter = new SqlDataAdapter(); //实例化数据适配器 adapter.SelectCommand = cmd; //让适配器执行SELECT命令 DataSet dataSet = new DataSet(); //实例化结果数据集 int n = adapter.Fill(dataSet); //将结果放入数据适配器,返回元祖个数 string[] fields = new string[] { "员工代号", "员工姓名", "所属部门", "年龄", "登入密码", "是否管理员" }; for (int indexColumn = 0; indexColumn < dataSet.Tables[0].Columns.Count; indexColumn++) { Range range = excel[1, indexColumn + 1]; range.Value2 = fields[indexColumn]; } for (int indexRow = 0; indexRow < dataSet.Tables[0].Rows.Count; indexRow++) { for (int indexColumn = 0; indexColumn < dataSet.Tables[0].Columns.Count; indexColumn++) { Range range = excel[indexRow + 2, indexColumn + 1]; range.Value2 = dataSet.Tables[0].Rows[indexRow][indexColumn]; } } } }
//代码检测 public void GetCurrentCode() { CorrectCode = new List <string>(); //正确的code string ExcelPath = Application.dataPath + "/StreamingAssets/Excel/MyCode.xls"; ExcelOperator excelClass = new ExcelOperator(); DataTable CodeData = new DataTable("CodeData"); CodeData = excelClass.ExcelReader(ExcelPath, caseName); int i = 0; while (i < CodeData.Rows.Count) { string temps = CodeData.Rows[i][stage_current + 1].ToString(); if (temps != "" && temps != null) { if (!Regex.IsMatch(temps, @"^P[0-9]{3}")) { CorrectCode.Add(CodeData.Rows[i][stage_current + 1].ToString()); } } i++; } }
public void GetCurrentPosition() { string ExcelPath = Application.dataPath + "/StreamingAssets/Excel/MyAxis.xls"; ExcelOperator excelClass = new ExcelOperator(); DataTable AxisData = new DataTable("AxisTable"); AxisData = excelClass.ExcelReader(ExcelPath, caseName); if (stage_current > AxisData.Rows.Count) { Debug.LogError("当前步骤轴没有设置参数"); } else { //deal with the data from the excel float j1 = Convert.ToSingle(AxisData.Rows[stage_current + 1][1]); float j4 = Convert.ToSingle(AxisData.Rows[stage_current + 1][4]); float j2 = Convert.ToSingle(AxisData.Rows[stage_current + 1][2]); float j5 = Convert.ToSingle(AxisData.Rows[stage_current + 1][5]); float j3 = Convert.ToSingle(AxisData.Rows[stage_current + 1][3]); float j6 = Convert.ToSingle(AxisData.Rows[stage_current + 1][6]); CorrectAngles = new float[6] { j1, j2, j3, j4, j5, j6 }; Debug.Log("currentangles:" + CorrectAngles[0] + " " + CorrectAngles[1] + " " + CorrectAngles[2] + " " + CorrectAngles[3] + " " + CorrectAngles[4] + " " + CorrectAngles[5]); } }
//表格创建 void ExcelCreate() { if(!Directory.Exists(Application.dataPath + "/_TempExcel")){ Directory.CreateDirectory(Application.dataPath + "/_TempExcel"); } ExcelOperator excelWirter = new ExcelOperator(); //为Excel写入做准备 List<string> colName = new List<string>(); colName.Add("NAME"); List<List<string>> fileContent = new List<List<string>>(); List<string> colContent = new List<string>(); Transform[] selections = Selection.GetTransforms(SelectionMode.Unfiltered); foreach(Transform child in selections){ TransformRecursion(child, colContent); } for(int i = 0; i < colContent.Count; i++){ List<string> newCol = new List<string>(); newCol.Add(colContent[i]); fileContent.Add(newCol); } excelWirter.ExcelWriter(Application.dataPath + "/_TempExcel/" + excelName + ".xls", "NAME", colName, fileContent, true); }
//案例一的周边设备的还原 private void DevicePosition_case1() { string ExcelPath = Application.dataPath + "/StreamingAssets/Excel/MyDevice.xls"; Vector3 position = Vector3.zero; Vector3 posture = Vector3.zero; string fathername = ""; string devicename = ""; ExcelOperator excelClass = new ExcelOperator(); DataTable DeviceData = new DataTable("DeviceData"); DeviceData = excelClass.ExcelReader(ExcelPath, "case1"); devicename = DeviceData.Rows[0][0].ToString(); fathername = DeviceData.Rows[0][1].ToString(); position = StrToVector(DeviceData.Rows[0][2]); posture = StrToVector(DeviceData.Rows[0][3]); Transform device = GameObject.Find(devicename).GetComponent <Transform>(); device.parent = GameObject.Find(fathername).GetComponent <Transform>(); device.localPosition = position; device.localEulerAngles = posture; }
//删除当前sheet中数据 //keyValue--要删除的一条记录的主键值 //key--表的主键的列 public void DeleteData(string filepath, string sheetName, string keyValue, int rowIndex, int key){ ExcelOperator excelReader = new ExcelOperator(); DataTable sheetTable = excelReader.ExcelReader(filepath + ".xls", sheetName); string connectionStr = "Driver={Microsoft Excel Driver (*.xls)}; ReadOnly=True; DriverID=790; Dbq=" + filepath + ";"; OdbcConnection odbcCon = new OdbcConnection(connectionStr); //删除为空行 try{ OdbcCommand oCmd = new OdbcCommand(); oCmd.Connection = odbcCon; odbcCon.Open(); string updateStr = "update ["+sheetName+"$] set "; for(int j = 0; j < sheetTable.Columns.Count; j++){ if(j == sheetTable.Columns.Count-1){ updateStr += sheetTable.Columns[j].ColumnName+"=null"; }else{ updateStr += sheetTable.Columns[j].ColumnName+"=null, "; } } updateStr += " where "+sheetTable.Columns[key].ColumnName+" ='"+keyValue+"'"; oCmd.CommandText = updateStr; oCmd.ExecuteNonQuery(); odbcCon.Close(); }catch{ UnityEngine.Debug.LogError("Excel更新错误,请检查相关信息---" ); odbcCon.Close(); } }
//向当前sheet中添加数据 //addContent--添加到表的新的一条记录 public void AddData(string filepath, string sheetName, string[] addContent){ ExcelOperator excelReader = new ExcelOperator(); DataTable sheetTable = excelReader.ExcelReader(filepath + ".xls", sheetName); string connectionStr = "Driver={Microsoft Excel Driver (*.xls)}; ReadOnly=True; DriverID=790; Dbq=" + filepath + ";"; OdbcConnection odbcCon = new OdbcConnection(connectionStr); try{ OdbcCommand oCmd = new OdbcCommand(); oCmd.Connection = odbcCon; odbcCon.Open(); string updateStr=""; updateStr = "insert into ["+sheetName+"$] values("; for(int j = 0; j < sheetTable.Columns.Count; j++){ if(j == sheetTable.Columns.Count-1){ updateStr += "'"+addContent[j]+"')"; }else{ updateStr += "'"+addContent[j]+"',"; } } oCmd.CommandText = updateStr; oCmd.ExecuteNonQuery(); odbcCon.Close(); }catch{ UnityEngine.Debug.LogError("Excel更新错误,请检查相关信息---" ); odbcCon.Close(); } }
//更新当前sheet中数据 //contents--更新表的单条记录 //key--表的主键的列 public void UpdateData(string filepath, string sheetName, string[] contents, int key){ ExcelOperator excelReader = new ExcelOperator(); DataTable sheetTable = excelReader.ExcelReader(filepath + ".xls", sheetName); string connectionStr = "Driver={Microsoft Excel Driver (*.xls)}; ReadOnly=True; DriverID=790; Dbq=" + filepath + ";"; OdbcConnection odbcCon = new OdbcConnection(connectionStr); try{ OdbcCommand oCmd = new OdbcCommand(); oCmd.Connection = odbcCon; odbcCon.Open(); string updateStr = "update ["+sheetName+"$] set "; for(int j = 0; j < sheetTable.Columns.Count; j++){ if(j != key){ if(j == sheetTable.Columns.Count-1){ updateStr += sheetTable.Columns[j].ColumnName+"='"+contents[j]+"'"; }else{ updateStr += sheetTable.Columns[j].ColumnName+"='"+contents[j] +"', "; } } } updateStr += " where "+sheetTable.Columns[key].ColumnName+" ='"+contents[key]+"'"; oCmd.CommandText = updateStr; oCmd.ExecuteNonQuery(); odbcCon.Close(); } //catch{ // UnityEngine.Debug.LogError("Excel更新错误,请检查相关信息---" ); // odbcCon.Close(); //} catch(System.Exception e){ UnityEngine.Debug.LogError(e.Message); UnityEngine.Debug.LogError("Excel更新错误,请检查相关信息---" ); odbcCon.Close(); } }
//检查模型比例 void checkScale() { Debug.Log("物体Scale信息检查"); ExcelOperator excelReader = new ExcelOperator(); System.Data.DataTable sheetTable = excelReader.ExcelReader(MotionPara.taskRootPath + MotionPara.taskName + "/ObjectName.xls", "NAME", "A", "A"); for (int i = 0; i < sheetTable.Rows.Count; i++) { DataRow dr = sheetTable.Rows[i]; string objName = dr[0].ToString(); if (GameObject.Find(objName) != null) { float scale_x = GameObject.Find(objName).transform.localScale.x; float scale_y = GameObject.Find(objName).transform.localScale.y; float scale_z = GameObject.Find(objName).transform.localScale.z; if ((Mathf.Abs(scale_x - 1.0f) < 0.01f) && (Mathf.Abs(scale_y - 1.0f) < 0.01f) && (Mathf.Abs(scale_z - 1.0f) < 0.01f)) { } else { Debug.LogError(MotionPara.taskName + "工程中ObjectName.xls中NAME工作表中第" + (i + 2) + "行的物体" + objName + "的Scale出错"); } } else { Debug.LogError(MotionPara.taskName + "工程中ObjectName.xls中NAME工作表中第" + (i + 2) + "行的物体" + objName + "不存在"); } } Debug.Log("物体Scale信息检查——完毕"); }
//向MAIN中添加新的Motion void addAction(string actionName, int column, int row){ tmp_TextFields = new string[sheet_columns]; for(int i=0; i<sheet_columns; i++){ tmp_TextFields[i] = ""; } if(column == 2 && actionName == "CAMERA"){ //添加数据 if(row == sheet_rows){ //自动化生成数据:ID, tmp_TextFields[key] = (sheet_rows+2).ToString(); //自动化生成数据 //获得actionName的新ID ExcelOperator excelReader = new ExcelOperator(); sheetTable = excelReader.ExcelReader(filepath + ".xls", actionName); tmp_TextFields[column] = actionName+ "@"+ (sheetTable.Rows.Count+2).ToString(); //添加数据 addData(filepath, SheetNames[selectSheet], tmp_TextFields); } //插入数据 else{ for(int i=0; i<sheet_columns; i++){ tmp_TextFields[i] = contents[row, i]; } //获得actionName的新ID ExcelOperator excelReader = new ExcelOperator(); sheetTable = excelReader.ExcelReader(filepath + ".xls", actionName); string actName = actionName+ "@"+ (sheetTable.Rows.Count+2).ToString(); if(tmp_TextFields[column] == ""){ tmp_TextFields[column] = actName; } else{ tmp_TextFields[column] += "|"+actName; } //更新数据 updateData(filepath, SheetNames[selectSheet], tmp_TextFields); } //跳转表格 selectSheet = 1; } else if(column == 3 && actionName == "TIPS"){ //添加数据 if(row == sheet_rows){ //自动化生成数据:ID, tmp_TextFields[key] = (sheet_rows+2).ToString(); //自动化生成数据 //获得actionName的新ID ExcelOperator excelReader = new ExcelOperator(); sheetTable = excelReader.ExcelReader(filepath + ".xls", actionName); tmp_TextFields[column] = actionName+ "@"+ (sheetTable.Rows.Count+2).ToString(); //添加数据 addData(filepath, SheetNames[selectSheet], tmp_TextFields); } //插入数据 else{ for(int i=0; i<sheet_columns; i++){ tmp_TextFields[i] = contents[row, i]; } //获得actionName的新ID ExcelOperator excelReader = new ExcelOperator(); sheetTable = excelReader.ExcelReader(filepath + ".xls", actionName); string actName = actionName+ "@"+ (sheetTable.Rows.Count+2).ToString(); tmp_TextFields[column] = actName; //更新数据 updateData(filepath, SheetNames[selectSheet], tmp_TextFields); } //跳转表格 selectSheet = 2; } else if(column == 4){ //添加数据 if(row == sheet_rows){ //自动化生成数据:ID, tmp_TextFields[key] = (sheet_rows+2).ToString(); //自动化生成数据 //获得actionName的新ID ExcelOperator excelReader = new ExcelOperator(); sheetTable = excelReader.ExcelReader(filepath + ".xls", actionName); tmp_TextFields[column] = actionName+ "@"+ (sheetTable.Rows.Count+2).ToString(); //添加数据 addData(filepath, SheetNames[selectSheet], tmp_TextFields); } //插入数据 else{ for(int i=0; i<sheet_columns; i++){ tmp_TextFields[i] = contents[row, i]; } //获得actionName的新ID ExcelOperator excelReader = new ExcelOperator(); sheetTable = excelReader.ExcelReader(filepath + ".xls", actionName); string actName = actionName+ "@"+ (sheetTable.Rows.Count+2).ToString(); if(tmp_TextFields[column] == ""){ tmp_TextFields[column] = actName; } else{ tmp_TextFields[column] += "|"+actName; } //更新数据 updateData(filepath, SheetNames[selectSheet], tmp_TextFields); } //跳转表格 if(actionName == "CAMERA"){ selectSheet = 1; } else if(actionName == "TIPS"){ selectSheet = 2; } else if(actionName == "EXCEL"){ selectSheet = 3; } else if(actionName == "3DMAX"){ selectSheet = 4; } else if(actionName == "PROGRAM"){ selectSheet = 5; } } else if(column == 5 && actionName == "TRIGGER"){ //添加数据 if(row == sheet_rows){ //自动化生成数据:ID, tmp_TextFields[key] = (sheet_rows+2).ToString(); //自动化生成数据 //获得actionName的新ID ExcelOperator excelReader = new ExcelOperator(); sheetTable = excelReader.ExcelReader(filepath + ".xls", actionName); tmp_TextFields[column] = actionName+ "@"+ (sheetTable.Rows.Count+2).ToString(); //添加数据 addData(filepath, SheetNames[selectSheet], tmp_TextFields); } //插入数据 else{ for(int i=0; i<sheet_columns; i++){ tmp_TextFields[i] = contents[row, i]; } //获得actionName的新ID ExcelOperator excelReader = new ExcelOperator(); sheetTable = excelReader.ExcelReader(filepath + ".xls", actionName); string actName = actionName+ "@"+ (sheetTable.Rows.Count+2).ToString(); if(tmp_TextFields[column] == ""){ tmp_TextFields[column] = actName; } else{ tmp_TextFields[column] += "|"+actName; } //更新数据 updateData(filepath, SheetNames[selectSheet], tmp_TextFields); } //跳转表格 selectSheet = 6; } getSheetData(filepath, SheetNames[selectSheet]); showAddWindow = true; old_selectCategory = 0; showAddSelection = false; }
//Prefab化 private void Prefablize() { if(!File.Exists(Application.dataPath + "/_TempExcel/" + excelName + ".xls")){ Debug.LogError(Application.dataPath + "/_TempExcel/" + excelName + ".xls文件不存在,请确认!"); return; } ExcelOperator excelReader = new ExcelOperator(); DataTable preData = excelReader.ExcelReader(Application.dataPath + "/_TempExcel/" + excelName + ".xls", "NAME", "A", "A"); string prefabName = (string)preData.Rows[0][0]; Transform tempTrans = ((GameObject)Resources.Load("Prefabs/ReplacePre/" + prefabName)).transform; Vector3 tempPos = Vector3.zero; Vector3 tempAngle = Vector3.zero; Vector3 tempScale = Vector3.zero; Transform parentTrans; Transform tempChild; for(int i = 0; i < preData.Rows.Count; i++){ string tempName = (string)preData.Rows[i][0]; try{ tempChild = GameObject.Find(tempName).transform; }catch{ Debug.LogError(tempName + "---该物体不存在!"); return; } parentTrans = tempChild.parent; tempPos = tempChild.localPosition; tempAngle = tempChild.localEulerAngles; tempScale = tempChild.localScale; DestroyImmediate(tempChild.gameObject); Transform instanceTrans = (Transform)Instantiate(tempTrans, Vector3.zero, Quaternion.identity); instanceTrans.name = tempName; instanceTrans.parent = parentTrans; instanceTrans.localScale = tempScale; instanceTrans.localPosition = tempPos; instanceTrans.localEulerAngles = tempAngle; } Debug.Log("恭喜!替换已完成!"); }
//Excel数据处理 private void ExcelLocationCreate(string nodeName, string column_name, bool cover_flag) { nodeName = nodeName.ToUpper(); //检查是否存在以该数模命名的文件夹 string locationPath = MotionPara.taskRootPath + MotionPara.taskName + "/"; string subPath = ""; if (nodeName.StartsWith("C")) { subPath = "C/"; } else if (nodeName.StartsWith("Y")) { subPath = "Y/"; } else if (nodeName.StartsWith("Z")) { subPath = "Z/"; } else { UnityEngine.Debug.LogError("输入的节点名称:" + nodeName + ",格式不正确!"); return; } //检查数字是否正确 int fileNum = 0; try { fileNum = int.Parse(nodeName.Substring(1)); } catch { UnityEngine.Debug.LogError("输入的节点名称:" + nodeName + ",格式不正确!"); return; } string filePreName = nodeName.Substring(0, 1) + fileNum.ToString(); //检验根目录是否存在 if (Directory.Exists(locationPath)) { //Excel处理类 ExcelOperator excelOp = new ExcelOperator(); if (File.Exists(locationPath + "ObjectName.xls")) { //首先处理ObjectName文件 DataTable objNameTab = excelOp.ExcelReader(locationPath + "ObjectName.xls", "NAME", "A", "A"); //为Excel写入做准备 List<string> colName = new List<string>(); colName.Add("NAME"); colName.Add("POSITION"); colName.Add("EULERANGLES"); List<List<string>> fileContent = new List<List<string>>(); List<string> colContent = new List<string>(); string objName = ""; string objPosition = ""; string objRotation = ""; Transform objTransform = null; for (int i = 0; i < objNameTab.Rows.Count; i++) { try { objTransform = GameObject.Find((string)objNameTab.Rows[i][0].ToString()).transform; } catch { UnityEngine.Debug.LogError((string)objNameTab.Rows[i][0].ToString() + ",该物体在当前场景中不存在,请确认!"); return; } objName = objTransform.name; objPosition = objTransform.position.x.ToString() + "," + objTransform.position.y.ToString() + "," + objTransform.position.z.ToString(); objRotation = objTransform.eulerAngles.x.ToString() + "," + objTransform.eulerAngles.y.ToString() + "," + objTransform.eulerAngles.z.ToString(); colContent = new List<string>(); colContent.Add(objName); colContent.Add(objPosition); colContent.Add(objRotation); fileContent.Add(colContent); } excelOp.ExcelWriter(locationPath + subPath + filePreName + "Location.xls", "LOCATION" + column_name, colName, fileContent, cover_flag); UnityEngine.Debug.Log(filePreName + "Location.xls表格LOCATION" + column_name + " sheet生成成功!"); //然后处理SpecialName文件 string speName = ""; string speType = ""; string speValue = ""; if (File.Exists(locationPath + "ObjectName.xls")) { DataTable specialNameTab = excelOp.ExcelReader(locationPath + "ObjectName.xls", "SPECIAL", "A", "B"); if (specialNameTab.Rows.Count > 0) { List<string> colName1 = new List<string>(); List<List<string>> fileContent1 = new List<List<string>>(); List<string> colContent1 = new List<string>(); colName1.Add("NAME"); colName1.Add("TYPE"); colName1.Add("CONTENT"); bool isRight = true; for (int i = 0; i < specialNameTab.Rows.Count; i++) { speName = (string)specialNameTab.Rows[i][0].ToString(); speType = (string)specialNameTab.Rows[i][1].ToString(); speValue = GetSpecialObjInfo(speName, speType, ref isRight); if (!isRight) { return; } else { colContent1 = new List<string>(); colContent1.Add(speName); colContent1.Add(speType); colContent1.Add(speValue); fileContent1.Add(colContent1); } } excelOp.ExcelWriter(locationPath + subPath + filePreName + "Location.xls", "SPECIAL" + column_name, colName1, fileContent1, false); UnityEngine.Debug.Log(filePreName + "Location.xls表格SPECIAL" + column_name + " sheet生成成功!"); } } } else { UnityEngine.Debug.LogError(locationPath + "ObjectName.xls,该文件不存在,请确认!"); return; } } else { UnityEngine.Debug.LogError(locationPath + ",该路径不存在,请检查!"); return; } }
//向当前sheet中添加数据 void addData(string filepath, string sheetName, string[] addContent){ ExcelOperator ewo = new ExcelOperator(); ewo.AddData(filepath, sheetName, addContent); //更新 getSheetData(filepath, sheetName); }
//删除当前sheet中数据 void deleteData(string filepath, string sheetName, string keyValue, int rowIndex){ ExcelOperator ewo = new ExcelOperator(); ewo.DeleteData(filepath, sheetName, keyValue, rowIndex, key); //更新数据 getSheetData(filepath, sheetName); }
//平台运动主入口函数 public IEnumerator MainEntrance(int id_number, int row_number) { //ID号准确性检查 if(id_number >= idList.Count || id_number < 0){ Debug.LogError("输入的ID号超出范围, 请检查输入的ID号或者相应的ID表."); yield break; } //根据ID加载功能表格 ExcelOperator excelReader = new ExcelOperator(); string[] sheetArray = new string[] {"MAIN", "CAMERA", "TIPS", "EXCEL", "Group", "3DMAX", "TRIGGER", "PROGRAM"}; //3DMAX信息读取 maxNumber = 0; bool readedMax = false; //ID表遍历 for(int i = id_number; i < idList.Count; i++){ cTime = 0f; addMotionTime = 0f; tableNum = (i + 1).ToString(); MotionPara.excelName = idList[i]; DataSet motionDataSet = excelReader.ExcelReader(MotionPara.dataRootPath + MotionPara.excelName + ".xls", sheetArray); //检查功能表格正确性 if(motionDataSet.Tables.Count != 0){ //总流程表遍历 //设置表格主键 motionDataSet.Tables["[MAIN$]"].PrimaryKey = new DataColumn[] {motionDataSet.Tables["[MAIN$]"].Columns["ID"]}; motionDataSet.Tables["[CAMERA$]"].PrimaryKey = new DataColumn[] {motionDataSet.Tables["[CAMERA$]"].Columns["ID"]}; motionDataSet.Tables["[TIPS$]"].PrimaryKey = new DataColumn[] {motionDataSet.Tables["[TIPS$]"].Columns["ID"]}; motionDataSet.Tables["[EXCEL$]"].PrimaryKey = new DataColumn[] {motionDataSet.Tables["[EXCEL$]"].Columns["ID"]}; motionDataSet.Tables["[3DMAX$]"].PrimaryKey = new DataColumn[] {motionDataSet.Tables["[3DMAX$]"].Columns["ID"]}; motionDataSet.Tables["[TRIGGER$]"].PrimaryKey = new DataColumn[] {motionDataSet.Tables["[TRIGGER$]"].Columns["ID"]}; motionDataSet.Tables["[PROGRAM$]"].PrimaryKey = new DataColumn[] {motionDataSet.Tables["[PROGRAM$]"].Columns["ID"]}; motionDataSet.Tables["[Group$]"].PrimaryKey = new DataColumn[] {motionDataSet.Tables["[Group$]"].Columns["ID"]}; //修正时间设定 if (isTimeLoad){ if (i == 0){ currentTime = 0f; }else{ currentTime = nodeTimeList[i - 1]; } } for(int j = row_number; j < motionDataSet.Tables["[MAIN$]"].Rows.Count; j++){ if (isTimeLoad) //进度条时间修订值 { try { maxProcess = (currentTime + float.Parse((string)motionDataSet.Tables["[MAIN$]"].Rows[j][6].ToString())) * perTime; } catch { Debug.LogError("时间信息可能为空,位置:" + ErrorLocation.Locate("MAIN", "TIME", MotionPara.mainRowNumber)); } } rowNum = (j + 2).ToString(); //自动生成Location等状态信息 if (createPosition){ if (j == 0){ st_Location.LocationCreate(MotionPara.excelName, (j + 2).ToString(), false); }else{ st_Location.LocationCreate(MotionPara.excelName, (j + 2).ToString(), false); } } MotionPara.mainRowNumber = j; //检查到有错停止运行 MotionPara.shouldStop = false; //检查到有空行停止运行 bool isRowBlank = false; //先解决CAMERA问题,考过程不触发 string cameStr = (string)motionDataSet.Tables["[MAIN$]"].Rows[j][2].ToString(); if(cameStr != ""){ isRowBlank = isRowBlank || true; st_Interface.TipsWindow(false, "", false); yield return StartCoroutine(CameraCoroutine(cameStr, motionDataSet.Tables["[CAMERA$]"])); }else{ isRowBlank = isRowBlank || false; } //再解决TIPS问题,教触发,练触发可选,考不触发 string tipsStr = (string)motionDataSet.Tables["[MAIN$]"].Rows[j][3].ToString(); if(tipsStr != ""){ isRowBlank = isRowBlank || true; yield return StartCoroutine(TipsCoroutine(tipsStr, motionDataSet.Tables["[TIPS$]"])); }else{ st_Interface.TipsWindow(false, "", false); isRowBlank = isRowBlank || false; } //如果是练过程,等待触发完成再继续往下运动,Trigger,TODO:触发的是程序内部的某个动作而不是表格动作 if(FuncPara.currentMotion == MotionState.Exercising){ string triggerStr = (string)motionDataSet.Tables["[MAIN$]"].Rows[j][5].ToString(); if(triggerStr != ""){ isRowBlank = isRowBlank || true; //练触发 yield return StartCoroutine(TriggerCoroutine(triggerStr, motionDataSet.Tables["[TRIGGER$]"])); }else{ isRowBlank = isRowBlank || false; } } //Excel、3DMax、Tips、Camera、Program动画同时运动 string motionStr = (string)motionDataSet.Tables["[MAIN$]"].Rows[j][4].ToString(); motionAdministrator.Clear(); if(motionStr != ""){ isRowBlank = isRowBlank || true; yield return StartCoroutine(GeneralCoroutine(motionStr, motionDataSet.Tables["[CAMERA$]"], motionDataSet.Tables["[EXCEL$]"], motionDataSet.Tables["[3DMAX$]"], motionDataSet.Tables["[Group$]"], motionDataSet.Tables["[TIPS$]"], motionDataSet.Tables["[PROGRAM$]"])); }else{ isRowBlank = isRowBlank || false; } if(!isRowBlank){ Debug.LogError(MotionPara.dataRootPath + MotionPara.excelName + ".xls" + "表格,[MAIN]Sheet,第" + (MotionPara.mainRowNumber + 2) + "行为空!"); yield break; } if(MotionPara.shouldStop){ yield break; } if(computeTime){ float totalTime = (cameraTime+ tipsTime+ motionsTime); float tmp_addMotionTime = addMotionTime; addMotionTime += totalTime; //Debug.Log("_ID: " + motionDataSet.Tables["[MAIN$]"].Rows[j][1] + ";" + addMotionTime); //更新数据库CN中sheet MAIN,记录CN每条运动的时间 ExcelOperator ewo = new ExcelOperator(); string[] contents = new string[motionDataSet.Tables["[MAIN$]"].Columns.Count]; for (int k = 0; k < contents.Length; k++){ contents[k] = motionDataSet.Tables["[MAIN$]"].Rows[j][k].ToString(); } contents[6] = addMotionTime.ToString(); ewo.UpdateData(MotionPara.dataRootPath + MotionPara.excelName, "MAIN", contents, 1); cTime += (totalTime); //更新数据库CID中sheet 3DMAX,记录CN每条运动的时间 for (int k = 0; k < motionAdministrator._motionList.Count; k++) { if(motionAdministrator._motionList[k].GetType().ToString() == "MaxMotion") { if(!readedMax){ DataTable sheetTable = excelReader.ExcelReader(MotionPara.dataRootPath + "CID" + ".xls", "3DMAX"); if(sheetTable.Rows.Count > 0){ Debug.LogError("CID.xls中工作表3DMAX中已有数据,请删除最后一个ID为2的行之前 的数据"); } readedMax = true; } MaxMotion mm = (MaxMotion)motionAdministrator._motionList[k]; string[] addContent = new string[10]; addContent[0] = (maxNumber + 2).ToString(); addContent[1] = MotionPara.excelName; addContent[2] = mm.AnimationParent.name; addContent[3] = mm.AnimationName; addContent[4] = mm.StandardTime.ToString(); if (mm.PC2_Animation_Name.Count > 0) { addContent[5] = mm.PC2_Animation_Name[0].ToString(); addContent[6] = mm.PC2_Animation_StartFrame[0].ToString(); addContent[7] = mm.PC2_Animation_EndFrame[0].ToString(); for (int m = 1; m < mm.PC2_Animation_Name.Count; m++) { addContent[5] += ("|" + mm.PC2_Animation_Name[m].ToString()); addContent[6] += ("|" + mm.PC2_Animation_StartFrame[m].ToString()); addContent[7] += ("|" + mm.PC2_Animation_EndFrame[m].ToString()); } } addContent[8] = tmp_addMotionTime.ToString(); addContent[9] = addMotionTime.ToString(); ewo.AddData(MotionPara.dataRootPath + "CID", "3DMAX", addContent); maxNumber++; } } } //修正时间设定 if (isTimeLoad && !computeTime) { hSliderValue = maxProcess; } } //row参数清零 row_number = 0; //单步播放 if (isSinglePlay) { MotionPara.singlePlay = true; yield return StartCoroutine(SingleStepTimer()); } //生成位置 if(i == idList.Count - 1 && createPosition){ st_Location.LocationCreate(MotionPara.excelName, "END", false); } }else{ Debug.LogError(MotionPara.dataRootPath + idList[i] + ".xls" + "表格为空,请检查!"); yield break; } if (computeTime) { //更新数据库CID中sheet ID,记录CN的总时间 Debug.Log(idList[i] + ": " + cTime); string[] contents = new string[3]; DataTable sheetTable = excelReader.ExcelReader(MotionPara.dataRootPath + "CID" + ".xls", "ID"); DataRow dr = sheetTable.Rows[i]; contents = new string[sheetTable.Columns.Count]; for (int k = 0; k < contents.Length; k++) { contents[k] = dr[k].ToString(); } contents[2] = cTime.ToString(); ExcelOperator ewo = new ExcelOperator(); ewo.UpdateData(MotionPara.dataRootPath + "CID", "ID", contents, 0); } } st_Interface.TipsWindow(false, "", false); computeTime = false; yield return null; }
//获取sheet中数据 void getSheetData(string filepath,string sheetname){ ExcelOperator excelReader = new ExcelOperator(); sheetTable = excelReader.ExcelReader(filepath + ".xls", sheetname); sheet_rows = sheetTable.Rows.Count; sheet_columns = sheetTable.Columns.Count; for(int i = 0; i< sheetTable.Columns.Count; i++){//获得PrimiryKey的列数,即列名为ID的列数 DataColumn dc = sheetTable.Columns[i]; if(dc.ColumnName == "ID"){ key = i; break; } } nullColumns = "当前表的空行总数:"; int tmp = 0; string tmpSting = "空行:"; for(int i = 0; i < sheetTable.Rows.Count; i++){ //获得sheet行数 DataRow dr = sheetTable.Rows[i]; if(dr[key].ToString() == null || dr[key].ToString() == ""){ tmp++; tmpSting += (i+2).ToString()+ ", "; } } nullColumns += tmp.ToString(); if(tmp > 0){ nullColumns += "; "+ tmpSting; } contents = new string[sheet_rows, sheetTable.Columns.Count]; addContent = new string[sheetTable.Columns.Count]; columnName = new string[sheetTable.Columns.Count]; for(int i = 0; i < sheet_rows; i++){//获得sheet中数据 DataRow dr = sheetTable.Rows[i]; for(int j = 0; j < sheetTable.Columns.Count; j++){ contents[i , j] = dr[j]. ToString(); } } for(int j = 0; j < sheetTable.Columns.Count; j++){ addContent[j] = ""; columnName[j] = sheetTable.Columns[j].ColumnName; } //设置列名 setColumnName(sheetname); hSbarValue = 0; vSbarValue = 0; }
//JASON读取 private void JsonLocationCreate(string nodeName, string column_name, bool cover_flag) { nodeName = nodeName.ToUpper(); //检查是否存在以该数模命名的文件夹 string locationPath = MotionPara.taskRootPath + MotionPara.taskName + "/"; string subPath = ""; if (nodeName.StartsWith("C")) { subPath = "C/"; } else if (nodeName.StartsWith("Y")) { subPath = "Y/"; } else if (nodeName.StartsWith("Z")) { subPath = "Z/"; } else { UnityEngine.Debug.LogError("输入的节点名称:" + nodeName + ",格式不正确!"); return; } //检查数字是否正确 int fileNum = 0; try { fileNum = int.Parse(nodeName.Substring(1)); } catch { UnityEngine.Debug.LogError("输入的节点名称:" + nodeName + ",格式不正确!"); return; } string filePreName = nodeName.Substring(0, 1) + fileNum.ToString(); //检验根目录是否存在 if (Directory.Exists(locationPath)) { //Json处理类 JsonOperator jsonOp = new JsonOperator(); ExcelOperator excelOp = new ExcelOperator(); if (File.Exists(locationPath + "ObjectName.xls")) { //首先处理ObjectName文件 DataTable objNameTab = excelOp.ExcelReader(locationPath + "ObjectName.xls", "NAME", "A", "A"); //为Json写入做准备 string[] nameArray = new string[] { "NAME", "POSITION", "EULERANGLES" }; string[,] contentArray = new string[3, objNameTab.Rows.Count]; string objName = ""; string objPosition = ""; string objRotation = ""; Transform objTransform = null; for (int i = 0; i < objNameTab.Rows.Count; i++) { try { objTransform = GameObject.Find((string)objNameTab.Rows[i][0].ToString()).transform; } catch { UnityEngine.Debug.LogError((string)objNameTab.Rows[i][0].ToString() + ",该物体在当前场景中不存在,请确认!"); return; } objName = objTransform.name; objPosition = objTransform.position.x.ToString() + "," + objTransform.position.y.ToString() + "," + objTransform.position.z.ToString(); objRotation = objTransform.eulerAngles.x.ToString() + "," + objTransform.eulerAngles.y.ToString() + "," + objTransform.eulerAngles.z.ToString(); contentArray[0, i] = objName; contentArray[1, i] = objPosition; contentArray[2, i] = objRotation; } jsonOp.JsonWriter(locationPath + subPath + filePreName + "Location.json", "LOCATION" + column_name, nameArray, contentArray, cover_flag); UnityEngine.Debug.Log(filePreName + "Location.json表格LOCATION" + column_name + " sheet生成成功!"); //然后处理SpecialName文件 string speName = ""; string speType = ""; string speValue = ""; if (File.Exists(locationPath + "ObjectName.xls")) { DataTable specialNameTab = excelOp.ExcelReader(locationPath + "ObjectName.xls", "SPECIAL", "A", "B"); if (specialNameTab.Rows.Count > 0) { string[] nameArrayS = new string[] { "NAME", "TYPE", "CONTENT" }; string[,] contentArrayS = new string[3, specialNameTab.Rows.Count]; bool isRight = true; for (int i = 0; i < specialNameTab.Rows.Count; i++) { speName = (string)specialNameTab.Rows[i][0].ToString(); speType = (string)specialNameTab.Rows[i][1].ToString(); speValue = GetSpecialObjInfo(speName, speType, ref isRight); if (!isRight) { return; } else { contentArrayS[0, i] = speName; contentArrayS[1, i] = speType; contentArrayS[2, i] = speValue; } } jsonOp.JsonWriter(locationPath + subPath + filePreName + "Location.json", "SPECIAL" + column_name, nameArrayS, contentArrayS, false); UnityEngine.Debug.Log(filePreName + "Location.json表格SPECIAL" + column_name + " sheet生成成功!"); } } } else { UnityEngine.Debug.LogError(locationPath + "ObjectName.xls,该文件不存在,请确认!"); return; } } else { UnityEngine.Debug.LogError(locationPath + ",该路径不存在,请检查!"); return; } }
//Excel数据位置设置 private void ExcelLocationSet(string nodeName, string column_name) { nodeName = nodeName.ToUpper(); //检查是否存在以该数模命名的文件夹 string locationPath = MotionPara.taskRootPath + MotionPara.taskName + "/"; string subPath = ""; if (nodeName.StartsWith("C")) { subPath = "C/"; } else if (nodeName.StartsWith("Y")) { subPath = "Y/"; } else if (nodeName.StartsWith("Z")) { subPath = "Z/"; } else { UnityEngine.Debug.LogError("输入的节点名称:" + nodeName + ",格式不正确!"); return; } //检查数字是否正确 int fileNum = 0; try { fileNum = int.Parse(nodeName.Substring(1)); } catch { UnityEngine.Debug.LogError("输入的节点名称:" + nodeName + ",格式不正确!"); return; } string filePreName = nodeName.Substring(0, 1) + fileNum.ToString(); //Excel处理类 ExcelOperator excelOp = new ExcelOperator(); if (File.Exists(locationPath + subPath + filePreName + "Location.xls")) { DataTable posTable = excelOp.ExcelReader(locationPath + subPath + filePreName + "Location.xls", "LOCATION" + column_name, "A", "C"); Transform objTransform = null; bool isRight = true; BaseCompute baseCal = new BaseCompute(); for (int i = 0; i < posTable.Rows.Count; i++) { try { objTransform = GameObject.Find((string)posTable.Rows[i][0].ToString()).transform; } catch { UnityEngine.Debug.LogError((string)posTable.Rows[i][0].ToString() + ",该物体在当前场景中不存在,请确认!"); return; } objTransform.position = baseCal.Vector3Conversion((string)posTable.Rows[i][1].ToString(), ref isRight); if (!isRight) { UnityEngine.Debug.LogError((string)posTable.Rows[i][1].ToString() + ",位置向量转化错误,请检查!"); return; } objTransform.eulerAngles = baseCal.Vector3Conversion((string)posTable.Rows[i][2].ToString(), ref isRight); if (!isRight) { UnityEngine.Debug.LogError((string)posTable.Rows[i][2].ToString() + ",角度向量转化错误,请检查!"); return; } } if (File.Exists(locationPath + subPath + filePreName + "Location.xls")) { DataTable speTable = excelOp.ExcelReader(locationPath + subPath + filePreName + "Location.xls", "SPECIAL" + column_name, "A", "C"); string speName = ""; string speType = ""; string speValue = ""; for (int i = 0; i < speTable.Rows.Count; i++) { speName = (string)speTable.Rows[i][0].ToString(); speType = (string)speTable.Rows[i][1].ToString(); speValue = (string)speTable.Rows[i][2].ToString(); SetSpecialObjInfo(speName, speType, speValue, ref isRight); if (!isRight) { UnityEngine.Debug.LogError((string)speTable.Rows[i][0].ToString() + ",该处信息有误,请检查!"); return; } } } } else { UnityEngine.Debug.LogError(locationPath + subPath + filePreName + "Location.xls,该文件不存在,请确认!"); return; } }
//当前任务参数初始化 public bool ParaInitialize() { string idPath = MotionPara.taskRootPath + MotionPara.taskName + "/"; if(FuncPara.curentMode == Movement.Chai){ idPath += "C/CID.xls"; MotionPara.dataRootPath = MotionPara.taskRootPath + MotionPara.taskName + "/C/"; IDTableName = "CID"; subTablePath = "/C/"; }else if(FuncPara.curentMode == Movement.Zhuang){ idPath += "Z/ZID.xls"; MotionPara.dataRootPath = MotionPara.taskRootPath + MotionPara.taskName + "/Z/"; IDTableName = "ZID"; subTablePath = "/Z/"; }else{ idPath += "Y/YID.xls"; MotionPara.dataRootPath = MotionPara.taskRootPath + MotionPara.taskName + "/Y/"; IDTableName = "YID"; subTablePath = "/Y/"; } ExcelOperator excelReader = new ExcelOperator(); DataTable idTable = excelReader.ExcelReader(idPath, "ID", "A", "C"); if(idTable.Rows.Count == 0){ Debug.LogError(MotionPara.taskName + " Project's CID sheet is null. Please check it! "); return false; } MotionPara.phaseNameList.Clear(); idList.Clear(); nodeTimeList.Clear(); totalTimeS = 0f; for(int i = 0; i < idTable.Rows.Count; i++){ idList.Add((string)idTable.Rows[i][0]); MotionPara.phaseNameList.Add((string)idTable.Rows[i][1].ToString()); if (isTimeLoad) { nodeTimeList.Add(float.Parse((string)idTable.Rows[i][2].ToString())); totalTimeS += nodeTimeList[i]; } //Debug.Log(idList[i] + "---" + MotionPara.phaseNameList[i]); } //加载进度条总时间 if (isTimeLoad) { perTime = TotalValue / totalTimeS; } //运动通用参数初始化 if(!File.Exists(MotionPara.taskRootPath + MotionPara.taskName + "/ToolsVariable.xls")){ Debug.LogError(MotionPara.taskRootPath + MotionPara.taskName + "/ToolsVariable.xls,该表格不存在,请检查!"); return false; } DataTable toolVariable = excelReader.ExcelReader(MotionPara.taskRootPath + MotionPara.taskName + "/ToolsVariable.xls", "Tools", "A", "B"); try{ MotionPara.safeHeight = float.Parse((string)toolVariable.Rows[0][1].ToString()); MotionPara.toolMoveSpeed = float.Parse((string)toolVariable.Rows[1][1].ToString()); MotionPara.toolRotateSpeed = float.Parse((string)toolVariable.Rows[2][1].ToString()); MotionPara.copperName = (string)toolVariable.Rows[3][1].ToString(); MotionPara.copperHitSpeed = float.Parse((string)toolVariable.Rows[4][1].ToString()); MotionPara.copperForwardDis = float.Parse((string)toolVariable.Rows[5][1].ToString()); string[] copperVectorArray = ((string)toolVariable.Rows[6][1].ToString()).Split(',', ','); MotionPara.copperVector.x = float.Parse(copperVectorArray[0]); MotionPara.copperVector.y = float.Parse(copperVectorArray[1]); MotionPara.copperVector.z = float.Parse(copperVectorArray[2]); MotionPara.wrenchBackDis = float.Parse((string)toolVariable.Rows[7][1].ToString()); MotionPara.wrenchSpeed = float.Parse((string)toolVariable.Rows[8][1].ToString()); MotionPara.screwBackRate = float.Parse((string)toolVariable.Rows[9][1].ToString()); MotionPara.rotateDegreeRate = float.Parse((string)toolVariable.Rows[10][1].ToString()); MotionPara.cameraLineSpeed = float.Parse((string)toolVariable.Rows[11][1].ToString()); MotionPara.cameraAngleSpeed = float.Parse((string)toolVariable.Rows[12][1].ToString()); }catch{ Debug.LogError(MotionPara.taskRootPath + MotionPara.taskName + "/ToolsVariable.xls表中参数填写错误!"); return false; } //Program运动相关ID初始化 DataTable programIDTable = excelReader.ExcelReader(Application.streamingAssetsPath + "/ExcelMotionData" + "/ProgramMotionID.xls", "ID", "A", "B"); for(int i = 0; i < programIDTable.Rows.Count; i++){ MotionPara.programMotionID.Add(((string)programIDTable.Rows[i][1].ToString()).ToUpper()); } //Tools参数初始化 MotionPara.toolsName.Clear(); MotionPara.toolsInitPos.Clear(); MotionPara.toolsInitEuler.Clear(); if(File.Exists(MotionPara.taskRootPath + MotionPara.taskName + "/Tools.xls")){ DataTable toolInitTable = excelReader.ExcelReader(MotionPara.taskRootPath + MotionPara.taskName + "/Tools.xls", "Tools", "A", "C"); for(int i = 0; i < toolInitTable.Rows.Count; i++){ string tempName = (string)toolInitTable.Rows[i][0].ToString(); if(tempName == ""){ Debug.LogError(MotionPara.taskRootPath + MotionPara.taskName + "/Tools.xls表中(" + (i + 2) + ", A)名字为空!"); } MotionPara.toolsName.Add(tempName); string tempPos = (string)toolInitTable.Rows[i][1].ToString(); string[] posArray = tempPos.Split(',',','); Vector3 tempPosVec = new Vector3(0f, 0f, 0f); try{ tempPosVec.x = float.Parse(posArray[0]); tempPosVec.y = float.Parse(posArray[1]); tempPosVec.z = float.Parse(posArray[2]); }catch{ Debug.LogError(MotionPara.taskRootPath + MotionPara.taskName + "/Tools.xls表中(" + (i + 2) + ", B)位置信息错误!"); } MotionPara.toolsInitPos.Add(tempPosVec); string tempEuler = (string)toolInitTable.Rows[i][2].ToString(); string[] eulerArray = tempEuler.Split(',',','); Vector3 tempEulerVec = new Vector3(0f, 0f, 0f); try{ tempEulerVec.x = float.Parse(eulerArray[0]); tempEulerVec.y = float.Parse(eulerArray[1]); tempEulerVec.z = float.Parse(eulerArray[2]); }catch{ Debug.LogError(MotionPara.taskRootPath + MotionPara.taskName + "/Tools.xls表中(" + (i + 2) + ", C)角度信息错误!"); } MotionPara.toolsInitEuler.Add(tempEulerVec); } } //按钮和功能控制信息读取 BtnFunction.Initialize(); return true; }
//更新当前sheet中数据,单条记录 void updateData(string filepath, string sheetName, string[] contents){ ExcelOperator ewo = new ExcelOperator(); ewo.UpdateData(filepath, sheetName, contents, key); //更新 getSheetData(filepath,sheetName); }
/// <summary> /// 根据响应表格禁止相应的功能. /// </summary> /// <param name='sheet_name'> /// Sheet_name. /// </param> public void ForbitFunction(string sheet_name) { ExcelOperator excelOp = new ExcelOperator(); DataTable funcData = excelOp.ExcelReader(excelPath, sheet_name, "A", "A"); AllAllow(); string keys = ""; for(int i = 0; i < funcData.Rows.Count; i++){ keys = Convert.ToString(funcData.Rows[i][0]); if(IDDic.ContainsKey(keys)) IDDic[keys] = false; else Debug.LogWarning("ID NOT FOUND! Check sheet '" + sheet_name + "', Position 'A" + (i + 2).ToString() + "';"); } }
//初始化 void ProjectInit() { GUI.contentColor = Color.white; GUI.skin.label.fontSize = 13; GUI.skin.label.normal.textColor = Color.white; GUI.Label(new Rect(30, 80, 300, 20), "新项目文件系统初始化:"); GUI.Label(new Rect(40, 110, 130, 20), "输入新项目名称:"); newProjName = GUI.TextField(new Rect(150, 110, 100, 20), newProjName); if (GUI.Button(new Rect(270, 110, 100, 20), "文件生成")) { if (Directory.Exists(Application.dataPath + "/Resources/" + newProjName)) { Debug.LogError("该项目已存在工程目录"); } else { createProject(newProjName); } } GUI.Label(new Rect(40, 140, 300, 20), "新项目ObjectName表检查:"); if (GUI.Button(new Rect(200, 140, 100, 20), "表格检查")) { //NameCreate_Script.Create(); } GUI.Label(new Rect(30, 180, 300, 20), "运动表格管理:"); GUI.Label(new Rect(40, 210, 300, 20), "新增运动表:"); newExcelName = GUI.TextField(new Rect(120, 210, 130, 20), newExcelName); if (GUI.Button(new Rect(270, 210, 100, 20), "表格生成")) { newExcelName = newExcelName.ToUpper(); string subStr = ""; if (newExcelName.StartsWith("C")) { subStr = "/C/" + newExcelName + ".xls"; } else if (newExcelName.StartsWith("Y")) { subStr = "/Y/" + newExcelName + ".xls"; } else if (newExcelName.StartsWith("Z")) { subStr = "/Z/" + newExcelName + ".xls"; } else { Debug.LogError("\"" + newExcelName + "\"表格名格式错误!"); return; } File.Copy(Application.streamingAssetsPath + "/ExcelMotionData/C1.xls", Application.dataPath + "/Resources/" + MotionPara.taskName + subStr, false); ExcelOperator excelOp = new ExcelOperator(); DataTable idTable = excelOp.ExcelReader(Application.dataPath + "/Resources/" + MotionPara.taskName + st_Manager.subTablePath + st_Manager.IDTableName + ".xls", "ID", "A", "A"); bool toInsert = true; for (int i = 0; i < idTable.Rows.Count; i++) { if ((string)idTable.Rows[i][0].ToString() == newExcelName) { toInsert = false; break; } } if (toInsert) { excelOp.AddData(Application.dataPath + "/Resources/" + MotionPara.taskName + st_Manager.subTablePath + st_Manager.IDTableName, "ID", new string[] { newExcelName, "Description", ""}); } } }
//添加数据的窗口 void drawAddWindow(int id){ if(GUI.Button(new Rect(ExcelAddWindow.width-50, 10, 30, 30), tex_CloseButton)){ showAddWindow = false; showAddSelection = false; old_selectCategory = 0; } if(SheetNames[selectSheet] == "MAIN"){ } else if(SheetNames[selectSheet] == "CAMERA"){ old_selectCategory = selectCategory; selectCategory = GUI.Toolbar(new Rect(10, 20, SheetNames.Length * 80, 30), selectCategory, cameraCategory); if(GUI.Button(new Rect(30+SheetNames.Length*80, 20, 80, 30),"添加")){ addData(filepath, SheetNames[selectSheet], tmp_TextFields); showAddWindow = false; showAddSelection = false; old_selectCategory = 0; } //更新 if(old_selectCategory != selectCategory || !showAddSelection){ tmp_TextFields = new string[sheet_columns]; selectToggles = new bool[sheet_columns]; showAddSelection = true; for(int i=0; i<sheet_columns; i++){ tmp_TextFields[i] = ""; selectToggles[i] = true; } //自动化生成数据:ID,摄像机 tmp_TextFields[key] = (sheet_rows+2).ToString(); tmp_TextFields[2] = mainCamera; //自动化生成数据 if(selectCategory == 0){ selectToggles[9] = false; selectToggles[10] = false; selectToggles[11] = false; selectToggles[13] = false; add_sheet_width = (10+ (sheet_columns-4)* btn_width+ btn_width) - ExcelAddWindow.width; } else if(selectCategory == 1){ selectToggles[6] = false; selectToggles[12] = false; add_sheet_width = (10+ (sheet_columns-2)* btn_width+ btn_width) - ExcelAddWindow.width; } add_hSbarValue = 0; add_i = 0; } if(selectCategory >= 0){ //滑动条 bool hor = (add_sheet_width < 0); if(!hor){ GUI.depth = 0; add_hSbarValue = GUI.HorizontalScrollbar(new Rect(10, ExcelAddWindow.height-20, ExcelAddWindow.width-20, 30), add_hSbarValue, 1.0F, 0.0F, 10.0F); GUI.depth = 1; } //列名,数据 for(int i=0,j = 0; j < sheet_columns; j++){ if(selectToggles[j]){ columnName[j] = GUI.TextField(new Rect(10+ btn_width*i- (add_sheet_width)*add_hSbarValue/8f, 60, btn_width, btn_height), columnName[j]); GUI.SetNextControlName(j.ToString()); tmp_TextFields[j] = GUI.TextField(new Rect(10+ btn_width*i- (add_sheet_width)*add_hSbarValue/8f, 60+ btn_height, btn_width, btn_height), tmp_TextFields[j]); i++; } } //添加数据 bool isNecessary = false; if(selectCategory == 0){ isNecessary = (add_i==0 || add_i==1 || add_i==2 || add_i==3 || add_i==6); } else if(selectCategory == 1){ isNecessary = (add_i==0 || add_i==1 || add_i==2 || add_i==3 || add_i==5 || add_i==9 || add_i==10 || add_i==11 ); } if(selectToggles[add_i]){ if(isNecessary){ GUI.color = Color.green; } columnName[add_i] = GUI.TextField(new Rect(10- (add_sheet_width)*add_hSbarValue/8f, 60+ 3*btn_height, 2*btn_width, btn_height), columnName[add_i]); GUI.SetNextControlName(add_i.ToString()); tmp_TextFields[add_i] = GUI.TextField(new Rect(10+ 2*btn_width- (add_sheet_width)*add_hSbarValue/8f, 60+ 3*btn_height, btn_width, btn_height), tmp_TextFields[add_i]); if(isNecessary){ GUI.color = Color.white; } }else{ if(add_i == (sheet_columns-1)){ addData(filepath, SheetNames[selectSheet], tmp_TextFields); showAddWindow = false; showAddSelection = false; old_selectCategory = 0; }else{ add_i++; } } if(GUI.Button(new Rect(10+ 3*btn_width- (add_sheet_width)*add_hSbarValue/8f, 60+ 3*btn_height, btn_width, btn_height),"确认")){ if(add_i < (sheet_columns-1)){ add_i++; } else{ addData(filepath, SheetNames[selectSheet], tmp_TextFields); showAddWindow = false; showAddSelection = false; old_selectCategory = 0; } } } } else if(SheetNames[selectSheet] == "TIPS"){ //更新 if(!showAddSelection){ tmp_TextFields = new string[sheet_columns]; selectToggles = new bool[sheet_columns]; showAddSelection = true; for(int i=0; i<sheet_columns; i++){ tmp_TextFields[i] = ""; selectToggles[i] = true; } //自动化生成数据:ID,摄像机 tmp_TextFields[key] = (sheet_rows+2).ToString(); tmp_TextFields[2] = "down_left"; tmp_TextFields[3] = "false"; tmp_TextFields[4] = "false"; //自动化生成数据 add_hSbarValue = 0f; add_sheet_width = (10+ (sheet_columns)* btn_width+ btn_width) - ExcelAddWindow.width; add_i = 0; } //滑动条 bool hor = (add_sheet_width < 0); if(!hor){ GUI.depth = 0; add_hSbarValue = GUI.HorizontalScrollbar(new Rect(10, ExcelAddWindow.height-20, ExcelAddWindow.width-20, 30), add_hSbarValue, 1.0F, 0.0F, 10.0F); GUI.depth = 1; } //列名,数据 for(int i=0,j = 0; j < sheet_columns; j++){ if(selectToggles[j]){ columnName[j] = GUI.TextField(new Rect(10+ btn_width*i- (add_sheet_width)*add_hSbarValue/8f, 60, btn_width, btn_height), columnName[j]); GUI.SetNextControlName(j.ToString()); tmp_TextFields[j] = GUI.TextField(new Rect(10+ btn_width*i- (add_sheet_width)*add_hSbarValue/8f, 60+ btn_height, btn_width, btn_height), tmp_TextFields[j]); i++; } } if(GUI.Button(new Rect(10+ btn_width*sheet_columns- (add_sheet_width)*add_hSbarValue/8f, 60+ btn_height, btn_width, btn_height),"添加")){ addData(filepath, SheetNames[selectSheet], tmp_TextFields); showAddWindow = false; showAddSelection = false; old_selectCategory = 0; } //添加数据 bool isNecessary = false; isNecessary = (add_i==0 || add_i==1); if(selectToggles[add_i]){ if(isNecessary){ GUI.color = Color.green; } columnName[add_i] = GUI.TextField(new Rect(10- (add_sheet_width)*add_hSbarValue/8f, 60+ 3*btn_height, 2*btn_width, btn_height), columnName[add_i]); GUI.SetNextControlName(add_i.ToString()); tmp_TextFields[add_i] = GUI.TextField(new Rect(10+ 2*btn_width- (add_sheet_width)*add_hSbarValue/8f, 60+ 3*btn_height, btn_width, btn_height), tmp_TextFields[add_i]); if(isNecessary){ GUI.color = Color.white; } }else{ if(add_i == (sheet_columns-1)){ addData(filepath, SheetNames[selectSheet], tmp_TextFields); showAddWindow = false; showAddSelection = false; old_selectCategory = 0; }else{ add_i++; } } if(GUI.Button(new Rect(10+ 3*btn_width- (add_sheet_width)*add_hSbarValue/8f, 60+ 3*btn_height, btn_width, btn_height),"确认")){ if(add_i < (sheet_columns-1)){ add_i++; } else{ addData(filepath, SheetNames[selectSheet], tmp_TextFields); showAddWindow = false; showAddSelection = false; old_selectCategory = 0; } } } else if(SheetNames[selectSheet] == "EXCEL"){ old_selectCategory = selectCategory; selectCategory = GUI.Toolbar(new Rect(10, 20, SheetNames.Length * 80, 30), selectCategory, excelCategory); if(GUI.Button(new Rect(30+SheetNames.Length*80, 20, 80, 30),"添加")){ addData(filepath, SheetNames[selectSheet], tmp_TextFields); showAddWindow = false; showAddSelection = false; old_selectCategory = 0; } //更新 if(old_selectCategory != selectCategory || !showAddSelection){ tmp_TextFields = new string[sheet_columns]; selectToggles = new bool[sheet_columns]; showAddSelection = true; for(int i=0; i<sheet_columns; i++){ tmp_TextFields[i] = ""; selectToggles[i] = true; } //自动化生成数据:ID,摄像机 tmp_TextFields[key] = (sheet_rows+2).ToString(); tmp_TextFields[3] = (selectCategory+1).ToString(); //自动化生成数据 if(selectCategory == 0){ selectToggles[7] = false; selectToggles[8] = false; selectToggles[9] = false; selectToggles[10] = false; selectToggles[11] = false; selectToggles[12] = false; selectToggles[13] = false; add_sheet_width = (10+ (sheet_columns-7)* btn_width+ btn_width) - ExcelAddWindow.width; } else if(selectCategory == 1){ selectToggles[4] = false; selectToggles[5] = false; selectToggles[6] = false; selectToggles[12] = false; selectToggles[13] = false; add_sheet_width = (10+ (sheet_columns-5)* btn_width+ btn_width) - ExcelAddWindow.width; } else if(selectCategory == 2){ selectToggles[4] = false; selectToggles[8] = false; selectToggles[12] = false; selectToggles[13] = false; add_sheet_width = (10+ (sheet_columns-4)* btn_width+ btn_width) - ExcelAddWindow.width; } else if(selectCategory == 3){ selectToggles[4] = false; selectToggles[6] = false; selectToggles[7] = false; selectToggles[8] = false; selectToggles[10] = false; add_sheet_width = (10+ (sheet_columns-5)* btn_width+ btn_width) - ExcelAddWindow.width; } else if(selectCategory == 4){ selectToggles[4] = false; selectToggles[5] = false; selectToggles[6] = false; selectToggles[7] = false; selectToggles[8] = false; selectToggles[9] = false; selectToggles[10] = false; add_sheet_width = (10+ (sheet_columns-7)* btn_width+ btn_width) - ExcelAddWindow.width; } add_hSbarValue = 0; add_i = 0; } if(selectCategory >= 0){ //滑动条 bool hor = (add_sheet_width < 0); if(!hor){ GUI.depth = 0; add_hSbarValue = GUI.HorizontalScrollbar(new Rect(10, ExcelAddWindow.height-20, ExcelAddWindow.width-20, 30), add_hSbarValue, 1.0F, 0.0F, 10.0F); GUI.depth = 1; } //列名,数据 for(int i=0,j = 0; j < sheet_columns; j++){ if(selectToggles[j]){ columnName[j] = GUI.TextField(new Rect(10+ btn_width*i- (add_sheet_width)*add_hSbarValue/8f, 60, btn_width, btn_height), columnName[j]); GUI.SetNextControlName(j.ToString()); tmp_TextFields[j] = GUI.TextField(new Rect(10+ btn_width*i- (add_sheet_width)*add_hSbarValue/8f, 60+ btn_height, btn_width, btn_height), tmp_TextFields[j]); i++; } } //添加数据 bool isNecessary = false; if(selectCategory == 0){ isNecessary = (add_i==0 || add_i==1 || add_i==2 || add_i==3 || add_i==5 || add_i==6); } else if(selectCategory == 1){ isNecessary = (add_i==0 || add_i==1 || add_i==2 || add_i==3 || add_i==7 || add_i==9 || add_i==10); } else if(selectCategory == 2){ isNecessary = (add_i==0 || add_i==1 || add_i==2 || add_i==3 || add_i==5 || add_i==6 || add_i==7 || add_i==9 || add_i==10); } else if(selectCategory == 3){ isNecessary = (add_i==0 || add_i==1 || add_i==2 || add_i==3 || add_i==11 || add_i==12 || add_i==13 ); } else if(selectCategory == 4){ isNecessary = (add_i==0 || add_i==1 || add_i==2 || add_i==3 || add_i==11 || add_i==12 || add_i==13 ); } if(selectToggles[add_i]){ if(isNecessary){ GUI.color = Color.green; } columnName[add_i] = GUI.TextField(new Rect(10- (add_sheet_width)*add_hSbarValue/8f, 60+ 3*btn_height, 2*btn_width, btn_height), columnName[add_i]); GUI.SetNextControlName(add_i.ToString()); tmp_TextFields[add_i] = GUI.TextField(new Rect(10+ 2*btn_width- (add_sheet_width)*add_hSbarValue/8f, 60+ 3*btn_height, btn_width, btn_height), tmp_TextFields[add_i]); if(isNecessary){ GUI.color = Color.white; } }else{ if(add_i == (sheet_columns-1)){ addData(filepath, SheetNames[selectSheet], tmp_TextFields); showAddWindow = false; showAddSelection = false; old_selectCategory = 0; }else{ add_i++; } } if(GUI.Button(new Rect(10+ 3*btn_width- (add_sheet_width)*add_hSbarValue/8f, 60+ 3*btn_height, btn_width, btn_height),"确认")){ if(add_i < (sheet_columns-1)){ add_i++; } else{ addData(filepath, SheetNames[selectSheet], tmp_TextFields); showAddWindow = false; showAddSelection = false; old_selectCategory = 0; } } //新建Group if(add_i == 2){ if(GUI.Button(new Rect(10+ 4*btn_width- (add_sheet_width)*add_hSbarValue/8f, 60+ 3*btn_height, btn_width, btn_height),"新建Group")){ //保存Excel临时数据 tmpExcelData = new string[tmp_TextFields.Length]; for(int i=0; i<tmp_TextFields.Length; i++){ tmpExcelData[i] = tmp_TextFields[i]; } ExcelOperator excelReader = new ExcelOperator(); sheetTable = excelReader.ExcelReader(filepath + ".xls", "Group"); DataRow dr = sheetTable.Rows[0]; int newGroup = -1; for(int i=0; i<sheetTable.Columns.Count; i++){ if(dr[i].ToString() == "0" || dr[i].ToString() == ""){ newGroup = i-1; break; } } Debug.Log("newGroup:"+newGroup); if(newGroup != -1){ tmpExcelData[2] = newGroup.ToString(); excelToGroup = true; tmpExcelSelect = selectCategory; //跳转Group表 selectSheet = 7; getSheetData(filepath, SheetNames[selectSheet]); showAddWindow = false; old_selectCategory = 0; showAddSelection = false; } else{ if(MotionPara.isEditor){ Debug.LogError("Group中没有空的列,请手动在Group中添加列."); } } } } } } else if(SheetNames[selectSheet] == "3DMAX"){ old_selectCategory = selectCategory; selectCategory = GUI.Toolbar(new Rect(10, 20, SheetNames.Length * 80, 30), selectCategory, maxCategory); if(GUI.Button(new Rect(30+SheetNames.Length*80, 20, 80, 30),"添加")){ addData(filepath, SheetNames[selectSheet], tmp_TextFields); showAddWindow = false; showAddSelection = false; old_selectCategory = 0; } //更新 if(old_selectCategory != selectCategory || !showAddSelection){ tmp_TextFields = new string[sheet_columns]; selectToggles = new bool[sheet_columns]; showAddSelection = true; for(int i=0; i<sheet_columns; i++){ tmp_TextFields[i] = ""; selectToggles[i] = true; } //自动化生成数据:ID,摄像机 tmp_TextFields[key] = (sheet_rows+2).ToString(); //自动化生成数据 if(selectCategory == 0){ selectToggles[5] = false; selectToggles[6] = false; selectToggles[7] = false; add_sheet_width = (10+ (sheet_columns-3)* btn_width+ btn_width) - ExcelAddWindow.width; } else{ add_sheet_width = (10+ (sheet_columns)* btn_width+ btn_width) - ExcelAddWindow.width; } add_hSbarValue = 0; add_i = 0; } if(selectCategory >= 0){ //滑动条 bool hor = (add_sheet_width < 0); if(!hor){ GUI.depth = 0; add_hSbarValue = GUI.HorizontalScrollbar(new Rect(10, ExcelAddWindow.height-20, ExcelAddWindow.width-20, 30), add_hSbarValue, 1.0F, 0.0F, 10.0F); GUI.depth = 1; } //列名,数据 for(int i=0,j = 0; j < sheet_columns; j++){ if(selectToggles[j]){ columnName[j] = GUI.TextField(new Rect(10+ btn_width*i- (add_sheet_width)*add_hSbarValue/8f, 60, btn_width, btn_height), columnName[j]); GUI.SetNextControlName(j.ToString()); tmp_TextFields[j] = GUI.TextField(new Rect(10+ btn_width*i- (add_sheet_width)*add_hSbarValue/8f, 60+ btn_height, btn_width, btn_height), tmp_TextFields[j]); i++; } } //添加数据 bool isNecessary = false; if(selectCategory == 0){ isNecessary = (add_i==0 || add_i==1 || add_i==2 || add_i==3 ); } else if(selectCategory == 1){ isNecessary = (add_i==0 || add_i==1 || add_i==2 || add_i==3 || add_i==5 || add_i==6 || add_i==7); } if(selectToggles[add_i]){ if(isNecessary){ GUI.color = Color.green; } columnName[add_i] = GUI.TextField(new Rect(10- (add_sheet_width)*add_hSbarValue/8f, 60+ 3*btn_height, 2*btn_width, btn_height), columnName[add_i]); GUI.SetNextControlName(add_i.ToString()); tmp_TextFields[add_i] = GUI.TextField(new Rect(10+ 2*btn_width- (add_sheet_width)*add_hSbarValue/8f, 60+ 3*btn_height, btn_width, btn_height), tmp_TextFields[add_i]); if(isNecessary){ GUI.color = Color.white; } }else{ if(add_i == (sheet_columns-1)){ addData(filepath, SheetNames[selectSheet], tmp_TextFields); showAddWindow = false; showAddSelection = false; old_selectCategory = 0; }else{ add_i++; } } if(GUI.Button(new Rect(10+ 3*btn_width- (add_sheet_width)*add_hSbarValue/8f, 60+ 3*btn_height, btn_width, btn_height),"确认")){ if(add_i < (sheet_columns-1)){ add_i++; } else{ addData(filepath, SheetNames[selectSheet], tmp_TextFields); showAddWindow = false; showAddSelection = false; old_selectCategory = 0; } } } } else if(SheetNames[selectSheet] == "PROGRAM"){ old_selectCategory = selectCategory; selectCategory = GUI.Toolbar(new Rect(10, 20, SheetNames.Length * 80, 30), selectCategory, programCategory); if(GUI.Button(new Rect(30+SheetNames.Length*80, 20, 80, 30),"添加")){ addData(filepath, SheetNames[selectSheet], tmp_TextFields); showAddWindow = false; showAddSelection = false; old_selectCategory = 0; } //更新 if(old_selectCategory != selectCategory || !showAddSelection){ tmp_TextFields = new string[sheet_columns]; selectToggles = new bool[sheet_columns]; showAddSelection = true; for(int i=0; i<sheet_columns; i++){ tmp_TextFields[i] = ""; selectToggles[i] = true; } //自动化生成数据:ID,摄像机 tmp_TextFields[key] = (sheet_rows+2).ToString(); if(selectCategory == 0){ tmp_TextFields[2] = "TongBang"; } else if(selectCategory == 1){ tmp_TextFields[2] = "BaiFang"; } else if(selectCategory == 2){ tmp_TextFields[2] = "NingSong"; tmp_TextFields[11] = "-1,0,0"; } else if(selectCategory == 3){ tmp_TextFields[2] = "NingChu"; tmp_TextFields[9] = "0,-1,0"; } //自动化生成数据 if(selectCategory == 0){ selectToggles[9] = false; selectToggles[10] = false; selectToggles[11] = false; add_sheet_width = (10+ (sheet_columns-1)* btn_width+ btn_width) - ExcelAddWindow.width; } else if(selectCategory == 1){ selectToggles[9] = false; selectToggles[10] = false; selectToggles[11] = false; add_sheet_width = (10+ (sheet_columns-2)* btn_width+ btn_width) - ExcelAddWindow.width; } else if(selectCategory == 2){ add_sheet_width = (10+ (sheet_columns)* btn_width+ btn_width) - ExcelAddWindow.width; } else if(selectCategory == 3){ selectToggles[10] = false; selectToggles[11] = false; add_sheet_width = (10+ (sheet_columns-1)* btn_width+ btn_width) - ExcelAddWindow.width; } add_hSbarValue = 0; add_i = 0; } if(selectCategory >= 0){ //滑动条 bool hor = (add_sheet_width < 0); if(!hor){ GUI.depth = 0; add_hSbarValue = GUI.HorizontalScrollbar(new Rect(10, ExcelAddWindow.height-20, ExcelAddWindow.width-20, 30), add_hSbarValue, 1.0F, 0.0F, 10.0F); GUI.depth = 1; } //列名,数据 for(int i=0,j = 0; j < sheet_columns; j++){ if(selectToggles[j]){ if(j <= 2){ columnName[j] = GUI.TextField(new Rect(10+ btn_width*i- (add_sheet_width)*add_hSbarValue/8f, 60, btn_width, btn_height), columnName[j]); }else{ programCategory_content[selectCategory, j-3] = GUI.TextField(new Rect(10+ btn_width*i- (add_sheet_width)*add_hSbarValue/8f, 60, btn_width, btn_height), programCategory_content[selectCategory, j-3]); } GUI.SetNextControlName(j.ToString()); tmp_TextFields[j] = GUI.TextField(new Rect(10+ btn_width*i- (add_sheet_width)*add_hSbarValue/8f, 60+ btn_height, btn_width, btn_height), tmp_TextFields[j]); i++; } } //添加数据 bool isNecessary = false; if(selectCategory == 0){ isNecessary = (add_i==0 || add_i==1 || add_i==2 || add_i==3 || add_i==4 || add_i==5 || add_i==6); } else if(selectCategory == 1){ isNecessary = (add_i==0 || add_i==1 || add_i==2 || add_i==3 || add_i==4); } else if(selectCategory == 2){ isNecessary = (add_i==0 || add_i==1 || add_i==2 || add_i==3 || add_i==4 || add_i==5 || add_i==6 || add_i==7 || add_i==8); } else if(selectCategory == 3){ isNecessary = (add_i==0 || add_i==1 || add_i==2 || add_i==3 || add_i==4 || add_i==5 || add_i==6 || add_i==7); } if(selectToggles[add_i]){ if(isNecessary){ GUI.color = Color.green; } if(add_i <= 2){ columnName[add_i] = GUI.TextField(new Rect(10- (add_sheet_width)*add_hSbarValue/8f, 60+ 3*btn_height, 2*btn_width, btn_height), columnName[add_i]); }else{ programCategory_content[selectCategory, add_i-3] = GUI.TextField(new Rect(10- (add_sheet_width)*add_hSbarValue/8f, 60+ 3*btn_height, 2*btn_width, btn_height), programCategory_content[selectCategory, add_i-3]); } GUI.SetNextControlName(add_i.ToString()); tmp_TextFields[add_i] = GUI.TextField(new Rect(10+ 2*btn_width- (add_sheet_width)*add_hSbarValue/8f, 60+ 3*btn_height, btn_width, btn_height), tmp_TextFields[add_i]); if(isNecessary){ GUI.color = Color.white; } }else{ if(add_i == (sheet_columns-1)){ addData(filepath, SheetNames[selectSheet], tmp_TextFields); showAddWindow = false; showAddSelection = false; old_selectCategory = 0; }else{ add_i++; } } if(GUI.Button(new Rect(10+ 3*btn_width- (add_sheet_width)*add_hSbarValue/8f, 60+ 3*btn_height, btn_width, btn_height),"确认")){ if(add_i < (sheet_columns-1)){ add_i++; } else{ addData(filepath, SheetNames[selectSheet], tmp_TextFields); showAddWindow = false; showAddSelection = false; old_selectCategory = 0; } } //新建Group if(add_i == 3){ if(GUI.Button(new Rect(10+ 4*btn_width- (add_sheet_width)*add_hSbarValue/8f, 60+ 3*btn_height, btn_width, btn_height),"新建Group")){ //保存Program临时数据 tmpProgramData = new string[tmp_TextFields.Length]; for(int i=0; i<tmp_TextFields.Length; i++){ tmpProgramData[i] = tmp_TextFields[i]; } ExcelOperator excelReader = new ExcelOperator(); sheetTable = excelReader.ExcelReader(filepath + ".xls", "Group"); DataRow dr = sheetTable.Rows[0]; int newGroup = -1; for(int i=0; i<sheetTable.Columns.Count; i++){ if(dr[i].ToString() == "0" || dr[i].ToString() == ""){ newGroup = i-1; break; } } Debug.Log("newGroup:"+newGroup); if(newGroup != -1){ tmpProgramData[3] = newGroup.ToString(); programToGroup = true; tmpProgramSelect = selectCategory; //跳转Group表 selectSheet = 7; getSheetData(filepath, SheetNames[selectSheet]); showAddWindow = false; old_selectCategory = 0; showAddSelection = false; } else{ if(MotionPara.isEditor){ Debug.LogError("Group中没有空的列,请手动在Group中添加列."); } } } } } } else if(SheetNames[selectSheet] == "TRIGGER"){ //更新 if(!showAddSelection){ tmp_TextFields = new string[sheet_columns]; selectToggles = new bool[sheet_columns]; showAddSelection = true; showTriggerType = true; showTriggerKey = true; for(int i=0; i<sheet_columns; i++){ tmp_TextFields[i] = ""; selectToggles[i] = true; } //自动化生成数据:ID tmp_TextFields[key] = (sheet_rows+2).ToString(); //自动化生成数据 add_hSbarValue = 0f; add_sheet_width = (10+ (sheet_columns)* btn_width+ btn_width) - ExcelAddWindow.width; add_i = 0; } //滑动条 bool hor = (add_sheet_width < 0); if(!hor){ GUI.depth = 0; add_hSbarValue = GUI.HorizontalScrollbar(new Rect(10, ExcelAddWindow.height-20, ExcelAddWindow.width-20, 30), add_hSbarValue, 1.0F, 0.0F, 10.0F); GUI.depth = 1; } //列名,数据 for(int i=0,j = 0; j < sheet_columns; j++){ if(selectToggles[j]){ columnName[j] = GUI.TextField(new Rect(10+ btn_width*i- (add_sheet_width)*add_hSbarValue/8f, 60, btn_width, btn_height), columnName[j]); GUI.SetNextControlName(j.ToString()); tmp_TextFields[j] = GUI.TextField(new Rect(10+ btn_width*i- (add_sheet_width)*add_hSbarValue/8f, 60+ btn_height, btn_width, btn_height), tmp_TextFields[j]); i++; } } if(GUI.Button(new Rect(10+ btn_width*sheet_columns- (add_sheet_width)*add_hSbarValue/8f, 60+ btn_height, btn_width, btn_height),"添加")){ addData(filepath, SheetNames[selectSheet], tmp_TextFields); showAddWindow = false; showAddSelection = false; old_selectCategory = 0; } //添加数据 bool isNecessary = false; isNecessary = (add_i==0 || add_i==1 || add_i==2 || add_i==3 || add_i==4); if(selectToggles[add_i]){ if(isNecessary){ GUI.color = Color.green; } columnName[add_i] = GUI.TextField(new Rect(10- (add_sheet_width)*add_hSbarValue/8f, 60+ 3*btn_height, 2*btn_width, btn_height), columnName[add_i]); GUI.SetNextControlName(add_i.ToString()); tmp_TextFields[add_i] = GUI.TextField(new Rect(10+ 2*btn_width- (add_sheet_width)*add_hSbarValue/8f, 60+ 3*btn_height, btn_width, btn_height), tmp_TextFields[add_i]); if(isNecessary){ GUI.color = Color.white; } }else{ if(add_i == (sheet_columns-1)){ addData(filepath, SheetNames[selectSheet], tmp_TextFields); showAddWindow = false; showAddSelection = false; old_selectCategory = 0; }else{ add_i++; } } if(GUI.Button(new Rect(10+ 3*btn_width- (add_sheet_width)*add_hSbarValue/8f, 60+ 3*btn_height, btn_width, btn_height),"确认")){ if(add_i < (sheet_columns-1)){ add_i++; } else{ addData(filepath, SheetNames[selectSheet], tmp_TextFields); showAddWindow = false; showAddSelection = false; old_selectCategory = 0; } } //Trigger if(showTriggerType && add_i == 2){ for(int k=0; k<triggerType.Length; k++){ if(GUI.Button(new Rect(10+ 4*btn_width- (add_sheet_width)*add_hSbarValue/8f, 60+ (3+k)*btn_height, btn_width*2, btn_height), triggerType[k])){ if(tmp_TextFields[2] == ""){ tmp_TextFields[2] = triggerType[k]; }else{ if(tmp_TextFields[2].Contains("&")){ string[] tmpStr = tmp_TextFields[2].Split('&'); tmp_TextFields[2] = tmpStr[1]+"&"+triggerType[k]; } else{ tmp_TextFields[2] = tmp_TextFields[2]+"&"+triggerType[k]; } } } } } if(showTriggerKey && add_i == 3){ if(tmp_TextFields[2].Contains("MOUSE")){//鼠标操作 for(int k=0; k<triggerKey_Mouse.Length; k++){ if(GUI.Button(new Rect(10+ 4*btn_width- (add_sheet_width)*add_hSbarValue/8f, 60+ (3+k)*btn_height, btn_width*2, btn_height), triggerKey_Mouse[k])){ if(tmp_TextFields[3] == ""){ tmp_TextFields[3] = triggerKey_Mouse[k]; }else{ if(tmp_TextFields[3].Contains("&")){ string[] tmpStr = tmp_TextFields[3].Split('&'); tmp_TextFields[3] = tmpStr[1]+ "&"+ triggerKey_Mouse[k]; } else{ tmp_TextFields[3] = tmp_TextFields[3]+ "&"+ triggerKey_Mouse[k]; } } } } } else if(tmp_TextFields[2].Contains("KEY")){ } else if(tmp_TextFields[2].Contains("KEY")){ } else if(tmp_TextFields[2].Contains("SCROLLWHEEL")){ } } } else if(SheetNames[selectSheet] == "Group"){ if(!showAddSelection){ tmp_TextFields = new string[2]; showAddSelection = true; for(int i=0; i<tmp_TextFields.Length; i++){ tmp_TextFields[i] = ""; } ExcelOperator excelReader = new ExcelOperator(); sheetTable = excelReader.ExcelReader(filepath + ".xls", "Group"); DataRow dr = sheetTable.Rows[0]; int newGroup = -1; for(int i=0; i<sheetTable.Columns.Count; i++){ if(dr[i].ToString() == "0" || dr[i].ToString() == ""){ newGroup = i-1; break; } } Debug.Log("newGroup:"+newGroup); tmp_TextFields[0] = newGroup.ToString(); } GUI.color = Color.green; GUI.Label(new Rect(10, 60+30*0, 100, 30), "列名"); GUI.Label(new Rect(10, 60+30*1, 100, 30), "物体名"); GUI.SetNextControlName("0"); tmp_TextFields[0] = GUI.TextField(new Rect(120, 60+30*0, 200, 30), tmp_TextFields[0]); GUI.SetNextControlName("1"); tmp_TextFields[1] = GUI.TextField(new Rect(120, 60+30*1, 200, 30), tmp_TextFields[1]); string tmp = "注:可在Hierarchy菜单中选中多个物体,然后打开插件Tool/Wuhao/获取选中物体信息中,点击‘获得当前选中多个Gameobject’"; GUI.Label(new Rect(320, 60+30*1, 200, 100), tmp); GUI.color = Color.white; if(GUI.Button(new Rect(10, 60+30*2, 100, 30),"确认")){ Debug.Log("add 列名:"+ tmp_TextFields[0]+ ",物体名:"+ tmp_TextFields[1]); string col=""; if(tmp_TextFields[0].Contains("Group")){ col = tmp_TextFields[0].Substring(5); }else{ col = tmp_TextFields[0]; } int columnNumber = int.Parse(col)+ 1; if(!(contents[0, columnNumber] =="" || contents[0, columnNumber] =="0")){ if(MotionPara.isEditor){ Debug.LogError("插入Group的列不为空,不允许插入."); } }else{ addGroupData(tmp_TextFields[0], tmp_TextFields[1]); showAddSelection = false; showAddWindow = false; old_selectCategory = 0; //跳转Excel if(excelToGroup){ excelToGroup = false; //跳转Excel表 selectSheet = 3; getSheetData(filepath, SheetNames[selectSheet]); showAddWindow = false; old_selectCategory = 0; showAddSelection = false; //恢复数据 showAddWindow = true; showAddSelection = true; selectCategory = tmpExcelSelect; tmp_TextFields = new string[tmpExcelData.Length]; for(int i=0; i<tmp_TextFields.Length; i++){ tmp_TextFields[i] = tmpExcelData[i]; } } //跳转Program if(programToGroup){ programToGroup = false; //跳转Program表 selectSheet = 5; getSheetData(filepath, SheetNames[selectSheet]); showAddWindow = false; old_selectCategory = 0; showAddSelection = false; //恢复数据 showAddWindow = true; showAddSelection = true; selectCategory = tmpProgramSelect; tmp_TextFields = new string[tmpProgramData.Length]; for(int i=0; i<tmp_TextFields.Length; i++){ tmp_TextFields[i] = tmpProgramData[i]; } } } } } GUI.DragWindow(); }
void checkMotionObject() { Debug.Log("运动物体填写检查"); //List保存ObjectName的物体名 List<string> objNames = new List<string>(); ExcelOperator excelReader = new ExcelOperator(); System.Data.DataTable sheetTable = excelReader.ExcelReader(MotionPara.taskRootPath + MotionPara.taskName + "/ObjectName.xls", "NAME", "A", "A"); for (int i = 0; i < sheetTable.Rows.Count; i++) { DataRow dr = sheetTable.Rows[i]; objNames.Add(dr[0].ToString()); } //ID表遍历 string excel_Name = ""; for (int i = 0; i < GameObject.Find("MainScript").GetComponent<MotionManager>().idList.Count; i++) { excel_Name = GameObject.Find("MainScript").GetComponent<MotionManager>().idList[i]; // Debug.Log("excel_Name:"+excel_Name); //Camera sheetTable = excelReader.ExcelReader(MotionPara.dataRootPath + excel_Name + ".xls", "CAMERA", "D", "D"); for (int j = 0; j < sheetTable.Rows.Count; j++) { DataRow dr = sheetTable.Rows[j]; // Debug.Log("CAMERA,"+ j+ ","+ dr[0].ToString()); if (!objNames.Contains(dr[0].ToString())) { Debug.LogError(MotionPara.taskName + "工程中" + excel_Name + ".xls中CAMERA工作表中第" + (j + 2) + "行的参考物体" + dr[0].ToString() + "在ObjectName.xls中不存在"); } } //EXCEL sheetTable = excelReader.ExcelReader(MotionPara.dataRootPath + excel_Name + ".xls", "EXCEL", "L", "L"); for (int j = 0; j < sheetTable.Rows.Count; j++) { DataRow dr = sheetTable.Rows[j]; if (dr[0].ToString() != "") { // Debug.Log("EXCEL,"+ j+ ","+ dr[0].ToString()); if (!objNames.Contains(dr[0].ToString())) { Debug.LogError(MotionPara.taskName + "工程中" + excel_Name + ".xls中EXCEL工作表中第" + (j + 2) + "行的参考物体" + dr[0].ToString() + "在ObjectName.xls中不存在"); } } } //3DMAX sheetTable = excelReader.ExcelReader(MotionPara.dataRootPath + excel_Name + ".xls", "3DMAX", "C", "C"); for (int j = 0; j < sheetTable.Rows.Count; j++) { DataRow dr = sheetTable.Rows[j]; // Debug.Log("3DMAX,"+ j+ ","+ dr[0].ToString()); if (!objNames.Contains(dr[0].ToString())) { Debug.LogError(MotionPara.taskName + "工程中" + excel_Name + ".xls中3DMAX工作表中第" + (j + 2) + "行的参考物体" + dr[0].ToString() + "在ObjectName.xls中不存在"); } } //PROGRAM sheetTable = excelReader.ExcelReader(MotionPara.dataRootPath + excel_Name + ".xls", "PROGRAM", "C", "E"); for (int j = 0; j < sheetTable.Rows.Count; j++) { DataRow dr = sheetTable.Rows[j]; if (dr[0].ToString() == "BaiFang" || dr[0].ToString() == "NingSong" || dr[0].ToString() == "NingChu") { // Debug.Log("PROGRAM,"+ j+ ","+ dr[2].ToString()); if (!objNames.Contains(dr[2].ToString())) { Debug.LogError(MotionPara.taskName + "工程中" + excel_Name + ".xls中PROGRAM工作表中第" + (j + 2) + "行的参考物体" + dr[2].ToString() + "在ObjectName.xls中不存在"); } } } //TRIGGER sheetTable = excelReader.ExcelReader(MotionPara.dataRootPath + excel_Name + ".xls", "TRIGGER", "E", "E"); for (int j = 0; j < sheetTable.Rows.Count; j++) { DataRow dr = sheetTable.Rows[j]; if (dr[0].ToString() != "") { // Debug.Log("TRIGGER,"+ j+ ","+ dr[0].ToString()); if (GameObject.Find(dr[0].ToString()) == null) { Debug.LogError(MotionPara.taskName + "工程中" + excel_Name + ".xls中TRIGGER工作表中第" + (j + 2) + "行的物体" + dr[0].ToString() + "不存在"); } } } //GROUP sheetTable = excelReader.ExcelReader(MotionPara.dataRootPath + excel_Name + ".xls", "GROUP"); for (int j = 0; j < sheetTable.Rows.Count; j++) { DataRow dr = sheetTable.Rows[j]; for (int k = 1; k < sheetTable.Columns.Count; k++) { if (dr[k].ToString() != "" && dr[k].ToString() != "0") { // Debug.Log("GROUP,"+ j+ ","+ k+ ","+ dr[k].ToString()); if (!objNames.Contains(dr[k].ToString())) { Debug.LogError(MotionPara.taskName + "工程中" + excel_Name + ".xls中GROUP工作表中第" + (j + 2) + "行第" + (k) + "列的物体" + dr[k].ToString() + "在ObjectName.xls中不存在"); } } } } } Debug.Log("运动物体填写检查完毕"); }
//进度条触发 private void ProcessTrigger() { //鼠标抬起 if (Input.GetMouseButtonUp(0)) { dragActive = false; dragLock = true; float processValue = hSliderValue; //停止当前运动 StopButton(); //拖到最后停止 if (Mathf.Abs(processValue - TotalValue) < 0.01f || processValue > TotalValue) { //设置到最终位置,结束 hSliderValue = TotalValue; //设置 SetLocation(idList.Count, "END"); } //拖到开始位置 else if (processValue < 0.01f) { //从头开始播 hSliderValue = 0f; //设置 SetLocation(1, "2"); StartCoroutine(MainEntrance(0, 0)); } //中间位置 else { //当前时间 float presentTime = processValue / perTime; //Debug.Log(presentTime); //节点号 int nodeNo = 0; //行号 //int rowNo = 0; ExcelOperator excelReader = new ExcelOperator(); float timeRecorder = 0f; for (int i = 0; i < nodeTimeList.Count; i++) { timeRecorder += nodeTimeList[i]; if (presentTime <= timeRecorder) { nodeNo = i + 1; float basicTime = timeRecorder - nodeTimeList[i]; DataTable mainTable = excelReader.ExcelReader(MotionPara.dataRootPath + idList[i] + ".xls", "MAIN", "G", "G"); for (int j = 0; j < mainTable.Rows.Count; j++) { if (presentTime < float.Parse((string)mainTable.Rows[j][0].ToString()) + basicTime) { SetLocation(nodeNo, (j + 2).ToString()); if (j != 0) { hSliderValue = (basicTime + float.Parse((string)mainTable.Rows[j - 1] [0].ToString())) * perTime; } else { hSliderValue = basicTime * perTime; } //快速跳转 StartCoroutine(MainEntrance(i, j)); //rowNo = j; //Debug.Log("Node: " + nodeNo + "---Row: " + rowNo); i = nodeTimeList.Count; //跳出第二个循环 break; } } } } } //3DMAX处理 MaxStateProcess(hSliderValue, preProcess); //锁住解除 dragLock = false; } }
//3DMax状态处理 private void MaxStateProcess(float current_value, float pre_process) { ExcelOperator excelReader = new ExcelOperator(); DataTable maxTable = excelReader.ExcelReader(MotionPara.dataRootPath + IDTableName + ".xls", "3DMAX", "A", "J"); //表格行重复判断,因为编辑人员的疏忽可能导致3DMAX表格内容重复 List<string> repeatedJudge = new List<string>(); for (int i = 0; i < maxTable.Rows.Count; i++) { string keyStr = (string)maxTable.Rows[i][0].ToString(); if (repeatedJudge.Contains(keyStr)) { return; //以下重复,退出 } else { repeatedJudge.Add(keyStr); //ID表 string tableID = (string)maxTable.Rows[i][1].ToString(); int idIndex = idList.IndexOf(tableID); if (idIndex == -1) { Debug.LogError(IDTableName + ".xls,(" + (i + 2).ToString() + ",B)ID表填写错误!"); return; } else { //读入后面的数据 float basicTime = 0f; if (idIndex != 0) basicTime = nodeTimeList[idIndex - 1]; float endValue = (float.Parse((string)maxTable.Rows[i][9].ToString()) + basicTime) * perTime; //首先判断需不需要改变Max状态 float valMin = pre_process; float valMax = current_value; if (pre_process > current_value) { valMin = current_value; valMax = pre_process; } if (endValue < valMin || endValue > valMax) //无需更改状态 { continue; } else //需要更改状态 { DataRow maxRow = maxTable.Rows[i]; bool isRight = true; MaxInfoManager maxInfo = new MaxInfoManager(); MaxMotion maxMotion = maxInfo.MaxInfoGet(maxRow, keyStr, ref isRight); if (endValue < current_value) { //已经运行过了 maxMotion.setCurrentProgress(false); } else { //没有运行到 maxMotion.setCurrentProgress(true); } } } } } }
//设置层级关系 void SetHierarchy () { if(!Directory.Exists(Application.dataPath + "/_TempExcel")){ Debug.LogError("请先创建_TempExcel文件夹!"); return; } if(!File.Exists(Application.dataPath + "/_TempExcel/" + excelName + ".xls")){ Debug.LogError(excelName + ".xls文件不存在!"); return; } ExcelOperator excelReader = new ExcelOperator(); DataTable setData = excelReader.ExcelReader(Application.dataPath + "/_TempExcel/" + excelName + ".xls", "SelectionsName", "A", "B"); string tempName = ""; string tempParent = ""; Transform transChild; Transform transParent; for(int i = 0; i < setData.Rows.Count; i++){ tempName = (string)setData.Rows[i][0]; tempParent = (string)setData.Rows[i][1]; try{ transChild = GameObject.Find(tempName).transform; }catch{ transChild = new GameObject("EmptyObject").transform; } if(tempParent != "null"){ try{ transParent = GameObject.Find(tempParent).transform; }catch{ transParent = new GameObject("EmptyParent").transform; } }else{ transParent = null; } transChild.parent = transParent; } }