static public Add ( Array array, element ) : T[] | ||
array | Array | |
Résultat | T[] |
public static T LoadAsset <T> (string label = "Load Unity Asset", string[] filters = null) where T : UnityEngine.Object { #if UNITY_EDITOR if (filters == null) { if (typeof(T).IsSubclassOf(typeof(Texture))) { filters = new string[] { "Textures", "PSD,TIFF,TIF,JPG,TGA,PNG,GIF,BMP,IFF,PICT" } } ; if (typeof(T) == typeof(Transform) || typeof(T) == typeof(Mesh)) { filters = new string[] { "Meshes", "FBX,DAE,3DS,DXF,OBJ,SKP" } } ; if (typeof(T) == typeof(TerrainData)) { filters = new string[] { "TerrainData", "ASSET" } } ; } ArrayTools.Add(ref filters, "All files"); ArrayTools.Add(ref filters, "*"); string path = UnityEditor.EditorUtility.OpenFilePanelWithFilters(label, "Assets", filters); if (path != null && path.Length != 0) { path = path.Replace(Application.dataPath, "Assets"); T asset = (T)UnityEditor.AssetDatabase.LoadAssetAtPath(path, typeof(T)); return(asset); } #endif return(null); }
public static void SetUserData(this UnityEditor.AssetImporter importer, string param, string[] data, bool reload = false) { char endline = '\n'; //';' string userData = importer.userData; string[] userDataSplit = userData.Split('\n', ';'); //preparing new data line if (data == null) { data = new string[0]; } string newDataString = param + ":" + data.ToStringMemberwise(separator: ","); //param line number (-1 if not found) int numInSplit = -1; for (int i = 0; i < userDataSplit.Length; i++) { if (userDataSplit[i].StartsWith(param + ":")) { numInSplit = i; } } //erasing empty data if (numInSplit >= 0 && data.Length == 0) { ArrayTools.RemoveAt(ref userDataSplit, numInSplit); } //replacing line if (numInSplit >= 0 && data.Length != 0) { userDataSplit[numInSplit] = newDataString; } //adding new line if (numInSplit == -1 && data.Length != 0) { ArrayTools.Add(ref userDataSplit, newDataString); } //to string string newUserData = ""; for (int i = 0; i < userDataSplit.Length; i++) { if (userDataSplit[i].Length == 0) { continue; } newUserData += userDataSplit[i]; if (i != userDataSplit.Length - 1) { newUserData += endline; } } //writing if (newUserData != userData) { importer.userData = newUserData; UnityEditor.EditorUtility.SetDirty(importer); UnityEditor.AssetDatabase.WriteImportSettingsIfDirty(importer.assetPath); if (reload) { UnityEditor.AssetDatabase.Refresh(); } } }