- 虽然改名, 在unity里有AssetDatabase.RenameAsset, 或AssetDatabase.MoveAsset, 但这里难点不是改名,而是怎么让GIT知道修改文件. Git是大小敏感, 而Win是大小不敏感的, 通常开发中,GIT确实没发知道文件名有变动.
- Git提供mv 指令,可以通知文件有变动,
git mv oldFilenPath newFilePath
- 实际项目中, 资源中会有多个仓库,方便各模块的管理, 可以通过 - C选项指定仓库目录
git -C oldFileDir mv oldFilePat newFilePath
- 在C# 中间可以创建Process来调用外部exe, 结合以上, 可以在unity里实现改名同时让git 知道文件名被修改
private void TestRenameAsset(string path){try{var oldPath = path.Replace("\\", "/");var dir = Path.GetDirectoryName(oldPath);var newPath = dir + "/" + Path.GetFileName(oldPath).ToLower();AssetDatabase.MoveAsset(path, newPath);using (var process = new Process()){var abOldPath = Path.GetFullPath(oldPath);var abNewPath = Path.GetFullPath(newPath);var abDir = Path.GetFullPath(dir);process.StartInfo.FileName = "git";process.StartInfo.Arguments = $"-C \"{abDir}\" mv \"{abOldPath}\" \"{abNewPath}\"";process.StartInfo.UseShellExecute = false;process.StartInfo.RedirectStandardOutput = true;process.StartInfo.CreateNoWindow = true;process.Start();string result = process.StandardOutput.ReadToEnd();process.WaitForExit();}}catch (Exception e){UnityEngine.Debug.LogError($"Fail to rename asset to lower: {e}");}}