static List <int> SubInt(int a, int[] array) { List <string> list = new List <string>(); List <int> returnList = new List <int>(); for (int i = 0; i < array.Length; i++) { list.Add(Convert.ToString(array[i])); } foreach (string VARIABLE in list) { if (VARIABLE.Contains(Convert.ToString(a))) { returnList.Add(list.IndexOf(VARIABLE)); } ; } foreach (var VARIABLE in returnList) { Console.WriteLine(VARIABLE); } //Console.WriteLine(b[0]); //Console.WriteLine(list[0]); Console.ReadKey(); return(returnList); }
public Dictionary <string, string> GetSubDatasets() { Dictionary <string, string> dic = new Dictionary <string, string>(); string[] sd = GetMetadata("SUBDATASETS"); var kvDic = new Dictionary <string, string>(); foreach (var VARIABLE in sd) { if (VARIABLE.Contains("=")) { var kv = VARIABLE.Split('='); if (kv.Length == 2) { kvDic.Add(kv[0], kv[1]); } } } int i = 1; while (kvDic.ContainsKey("SUBDATASET_" + i + "_NAME")) { string subDsFilePath = kvDic["SUBDATASET_" + i + "_NAME"]; int index = subDsFilePath.LastIndexOf("://"); string name = subDsFilePath.Substring(index + 3, subDsFilePath.Length - index - 3); dic.Add(name, kvDic["SUBDATASET_" + i + "_NAME"]); i = i + 1; } return(dic); }
/// <summary> /// 运行texturePacker打包图集 /// </summary> void ProcessTexturePacker(name_dic dic) { //创建目录 string dicPath = atlasResPath + "/" + dic._atlasName; if (Directory.Exists(dicPath)) { Directory.Delete(dicPath, true); } Directory.CreateDirectory(dicPath); AssetDatabase.Refresh(); string pngPath = $"{dicPath}/{dic._atlasName}.png"; int _idx = pngPath.IndexOf("Assets/"); pngPath = pngPath.Substring(_idx); string dataPath = $"{dicPath}/{dic._atlasName}.txt"; dataPath = dataPath.Substring(_idx); StringBuilder atlasPaths = new StringBuilder(); string inPath = $"{_textureDic}/{dic._atlasName}"; if (!Directory.Exists(inPath)) { return; } string[] paths = Directory.GetFiles(inPath); foreach (var VARIABLE in paths) { if (VARIABLE.Contains(".meta")) { continue; } int idx = VARIABLE.IndexOf("Assets/"); string _assetsPath = VARIABLE.Substring(idx); atlasPaths.Append(_assetsPath); atlasPaths.Append(" "); } string AtlasSize = "1024"; //核心代码: 传入四个参数, 依次是commond命令载体, 打成整图后的图片路径, 生成的txt文件位置, 需要被打成图集的图片们(依次用空格间隔开) string commond = @" --sheet {0} --data {1} --format unity-texture2d --trim-mode None --pack-mode Best --algorithm Polygon --max-size " + AtlasSize + @" --size-constraints POT --disable-rotation --scale 1 {2}"; string arg = string.Format(commond, pngPath, dataPath, atlasPaths.ToString()); EditorUtility.DisplayProgressBar("message", "texturePacker", 0.1f); System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo.Arguments = arg; process.StartInfo.UseShellExecute = false; process.StartInfo.FileName = @"TexturePacker.exe"; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; process.Start(); process.WaitForExit(); process.Dispose(); EditorUtility.ClearProgressBar(); AssetDatabase.Refresh(); }
//--监听“资源即将被保存”事件 public static string[] OnWillSaveAssets(string[] paths) { if (paths != null) { foreach (var VARIABLE in paths) { if (VARIABLE.Contains(".cs")) { UpdateAllScript(); break; } } } return(paths); }
public static object GetTraget(this SerializedProperty serializedProperty) { object target = serializedProperty.serializedObject.targetObject; var path = serializedProperty.propertyPath; path.Replace(".Array.data[", "["); var elements = path.Split('.'); foreach (var VARIABLE in elements) { if (VARIABLE.Contains("[")) { var elementName = VARIABLE.Substring(0, VARIABLE.IndexOf("[")); var index = int.Parse(VARIABLE.Substring(VARIABLE.IndexOf("[") + 1).Replace("]", string.Empty)); target = GetValue(target, elementName, index); } else { target = GetValue(target, VARIABLE); } } return(target); }
static void Main() { //Create COM Objects. Create a COM object for everything that is referenced Excel.Application xlApp = new Excel.Application(); string excelFileLocation = string.Empty; var files = Directory.GetFiles(Environment.CurrentDirectory); foreach (var VARIABLE in files) { if (VARIABLE.Contains("excel")) { excelFileLocation = VARIABLE; } } // GetRelativePath(); Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(excelFileLocation); //(@"D:\csrp\BookStoreDatabase\BookStoreDatabase\bin\Debug\excelinputBook.xlsx"); Excel._Worksheet xlWorksheet = xlWorkbook.Sheets[1]; Excel.Range xlRange = xlWorksheet.UsedRange; //Then you can read from the sheet, keeping in mind that indexing in Excel is not 0 based. //This just reads the cells and prints them back just as they were in the file. //iterate over the rows and columns and print to the console as it appears in the file //excel is not zero based!! int rowCount = 3; int colCount = 2; for (int i = 1; i <= rowCount; i++) { for (int j = 1; j <= colCount; j++) { //new line if (j == 1) { Console.Write("\r\n"); } //write the value to the console if (xlRange.Cells[i, j] != null && xlRange.Cells[i, j].Value2 != null) { Console.Write(xlRange.Cells[i, j].Value2.ToString() + "\t"); } //add useful things here! } } //cleanup GC.Collect(); GC.WaitForPendingFinalizers(); //rule of thumb for releasing com objects: // never use two dots, all COM objects must be referenced and released individually // ex: [somthing].[something].[something] is bad //release com objects to fully kill excel process from running in the background Marshal.ReleaseComObject(xlRange); Marshal.ReleaseComObject(xlWorksheet); //close and release xlWorkbook.Close(); Marshal.ReleaseComObject(xlWorkbook); //quit and release xlApp.Quit(); Marshal.ReleaseComObject(xlApp); }