private string GenerateGridBrushInstanceLibraryPath(Type brushType) { var path = FileUtil.CombinePaths(s_LibraryPath, brushType.ToString() + s_GridBrushExtension); path = FileUtil.NiceWinPath(path); return(path); }
private string GenerateGridBrushInstanceLibraryPath(Type brushType) { string unityPath = FileUtil.CombinePaths(new string[] { GridPaletteBrushes.s_LibraryPath, brushType.ToString() + GridPaletteBrushes.s_GridBrushExtension }); return(FileUtil.NiceWinPath(unityPath)); }
internal static void ReplaceText(string path, params string[] input) { path = FileUtil.NiceWinPath(path); string[] array = File.ReadAllLines(path); for (int i = 0; i < input.Length; i += 2) { for (int j = 0; j < array.Length; j++) { array[j] = array[j].Replace(input[i], input[i + 1]); } } File.WriteAllLines(path, array); }
internal static void ReplaceText(string path, params string[] input) { path = FileUtil.NiceWinPath(path); string[] contents = File.ReadAllLines(path); int index1 = 0; while (index1 < input.Length) { for (int index2 = 0; index2 < contents.Length; ++index2) { contents[index2] = contents[index2].Replace(input[index1], input[index1 + 1]); } index1 += 2; } File.WriteAllLines(path, contents); }
internal static bool AppendTextAfter(string path, string find, string append) { bool result = false; path = FileUtil.NiceWinPath(path); List <string> list = new List <string>(File.ReadAllLines(path)); for (int i = 0; i < list.Count; i++) { if (list[i].Contains(find)) { list.Insert(i + 1, append); result = true; break; } } File.WriteAllLines(path, list.ToArray()); return(result); }
internal static bool AppendTextAfter(string path, string find, string append) { bool flag = false; path = FileUtil.NiceWinPath(path); List <string> stringList = new List <string>((IEnumerable <string>)File.ReadAllLines(path)); for (int index = 0; index < stringList.Count; ++index) { if (stringList[index].Contains(find)) { stringList.Insert(index + 1, append); flag = true; break; } } File.WriteAllLines(path, stringList.ToArray()); return(flag); }
internal static bool ReplaceTextRegex(string path, params string[] input) { bool result = false; path = FileUtil.NiceWinPath(path); string[] array = File.ReadAllLines(path); for (int i = 0; i < input.Length; i += 2) { for (int j = 0; j < array.Length; j++) { string text = array[j]; array[j] = Regex.Replace(text, input[i], input[i + 1]); if (text != array[j]) { result = true; } } } File.WriteAllLines(path, array); return(result); }
internal static bool ReplaceTextRegex(string path, params string[] input) { bool flag = false; path = FileUtil.NiceWinPath(path); string[] contents = File.ReadAllLines(path); int index1 = 0; while (index1 < input.Length) { for (int index2 = 0; index2 < contents.Length; ++index2) { string input1 = contents[index2]; contents[index2] = Regex.Replace(input1, input[index1], input[index1 + 1]); if (input1 != contents[index2]) { flag = true; } } index1 += 2; } File.WriteAllLines(path, contents); return(flag); }
internal static void UnityFileCopy(string from, string to, bool overwrite) { File.Copy(FileUtil.NiceWinPath(from), FileUtil.NiceWinPath(to), overwrite); }
internal static void UnityDirectoryDelete(string path, bool recursive) { Directory.Delete(FileUtil.NiceWinPath(path), recursive); }
private bool ExtractMaterialsGUI() { using (new EditorGUILayout.HorizontalScope()) { EditorGUILayout.PrefixLabel(Styles.Materials); using (new EditorGUI.DisabledScope(!m_CanExtractEmbeddedMaterials)) { if (GUILayout.Button(Styles.ExtractEmbeddedMaterials)) { // use the first target for selecting the destination folder, but apply that path for all targets string destinationPath = (target as ModelImporter).assetPath; destinationPath = EditorUtility.SaveFolderPanel("Select Materials Folder", FileUtil.DeleteLastPathNameComponent(destinationPath), ""); if (string.IsNullOrEmpty(destinationPath)) { // cancel the extraction if the user did not select a folder return(false); } string assetPath = FileUtil.GetProjectRelativePath(destinationPath); //Where all the required embedded materials are not in the asset database, we need to reimport them if (!AllEmbeddedMaterialsAreImported()) { if (EditorUtility.DisplayDialog(L10n.Tr("Are you sure you want to re-extract the Materials?"), L10n.Tr("In order to re-extract the Materials we'll need to reimport the mesh, this might take a while. Do you want to continue?"), L10n.Tr("Yes"), L10n.Tr("No"))) { ReimportEmbeddedMaterials(); } else { return(false); } } if (!assetPath.StartsWith("Assets")) { destinationPath = FileUtil.NiceWinPath(destinationPath); // Destination could be a package. Need to get assetPath instead of relativePath // The GUID isn't known yet so can't find it from that foreach (var package in PackageManager.PackageInfo.GetAllRegisteredPackages()) { if (destinationPath.StartsWith(package.resolvedPath)) { assetPath = package.assetPath + destinationPath.Substring(package.resolvedPath.Length); break; } } } if (string.IsNullOrEmpty(assetPath)) { return(false); } try { // batch the extraction of the textures AssetDatabase.StartAssetEditing(); PrefabUtility.ExtractMaterialsFromAsset(targets, assetPath); } finally { AssetDatabase.StopAssetEditing(); } // AssetDatabase.StopAssetEditing() invokes OnEnable(), which invalidates all the serialized properties, so we must return. return(true); } } } return(false); }
private void ExtractTexturesGUI() { using (new EditorGUILayout.HorizontalScope()) { EditorGUILayout.PrefixLabel(Styles.Textures); using ( new EditorGUI.DisabledScope(!m_HasEmbeddedTextures.boolValue && !m_HasEmbeddedTextures.hasMultipleDifferentValues)) { if (GUILayout.Button(Styles.ExtractEmbeddedTextures)) { // when extracting textures, we must handle the case when multiple selected assets could generate textures with the same name at the user supplied path // we proceed as follows: // 1. each asset extracts the textures in a separate temp folder // 2. we remap the extracted assets to the respective asset importer // 3. we generate unique names for each asset and move them to the user supplied path // 4. we re-import all the assets to have the internal materials linked to the newly extracted textures List <Tuple <Object, string> > outputsForTargets = new List <Tuple <Object, string> >(); // use the first target for selecting the destination folder, but apply that path for all targets string assetPath = (target as ModelImporter).assetPath; assetPath = EditorUtility.SaveFolderPanel("Select Textures Folder", FileUtil.DeleteLastPathNameComponent(assetPath), ""); if (string.IsNullOrEmpty(assetPath)) { // cancel the extraction if the user did not select a folder return; } var destinationPath = FileUtil.GetProjectRelativePath(assetPath); if (!destinationPath.StartsWith("Assets")) { assetPath = FileUtil.NiceWinPath(assetPath); // Destination could be a package. Need to get assetPath instead of relativePath // The GUID isn't known yet so can't find it from that foreach (var package in PackageManager.PackageInfo.GetAllRegisteredPackages()) { if (assetPath.StartsWith(package.resolvedPath)) { destinationPath = package.assetPath + assetPath.Substring(package.resolvedPath.Length); break; } } } try { // batch the extraction of the textures AssetDatabase.StartAssetEditing(); foreach (var t in targets) { var tempPath = FileUtil.GetUniqueTempPathInProject(); tempPath = tempPath.Replace("Temp", UnityEditorInternal.InternalEditorUtility.GetAssetsFolder()); outputsForTargets.Add(Tuple.Create(t, tempPath)); var importer = t as ModelImporter; importer.ExtractTextures(tempPath); } } finally { AssetDatabase.StopAssetEditing(); } try { // batch the remapping and the reimport of the assets AssetDatabase.Refresh(); AssetDatabase.StartAssetEditing(); foreach (var item in outputsForTargets) { var importer = item.Item1 as ModelImporter; var guids = AssetDatabase.FindAssets("t:Texture", new string[] { item.Item2 }); foreach (var guid in guids) { var path = AssetDatabase.GUIDToAssetPath(guid); var tex = AssetDatabase.LoadAssetAtPath <Texture>(path); if (tex == null) { continue; } importer.AddRemap(new AssetImporter.SourceAssetIdentifier(tex), tex); var newPath = Path.Combine(destinationPath, FileUtil.UnityGetFileName(path)); newPath = AssetDatabase.GenerateUniqueAssetPath(newPath); AssetDatabase.MoveAsset(path, newPath); } AssetDatabase.ImportAsset(importer.assetPath, ImportAssetOptions.ForceUpdate); AssetDatabase.DeleteAsset(item.Item2); } } finally { AssetDatabase.StopAssetEditing(); } } } } }