源战役客户端
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

107 行
3.3 KiB

  1. /*
  2. * TortoiseSVN的基础操作内嵌Unity
  3. *
  4. * TortoiseSVN的help功能
  5. *
  6. */
  7. using UnityEngine;
  8. using UnityEditor;
  9. using System.Diagnostics;
  10. using LuaFramework;
  11. public class UnitySVN
  12. {
  13. private const string COMMIT = "commit";
  14. private const string UPDATE = "update";
  15. private const string SVN_COMMIT = "Assets/SVN/Commit %d";
  16. private const string SVN_COMMIT_ALL = "Assets/SVN/CommitAll %f";
  17. private const string SVN_UPDATE = "Assets/SVN/Update %g";
  18. private const string SVN_UPDATE_ALL = "Assets/SVN/UpdateAll %h";
  19. /// <summary>
  20. /// 创建一个SVN的cmd命令
  21. /// </summary>
  22. /// <param name="command">命令(可在help里边查看)</param>
  23. /// <param name="path">命令激活路径</param>
  24. public static void SVNCommand(string command, string path)
  25. {
  26. //closeonend 2 表示假设提交没错,会自动关闭提交界面返回原工程,详细描述可在
  27. //TortoiseSVN/help/TortoiseSVN/Automating TortoiseSVN里查看
  28. string c = "/c tortoiseproc.exe /command:{0} /path:\"{1}\" /closeonend 2";
  29. c = string.Format(c, command, path);
  30. ProcessStartInfo info = new ProcessStartInfo("cmd.exe", c);
  31. info.WindowStyle = ProcessWindowStyle.Hidden;
  32. Process.Start(info);
  33. }
  34. /// <summary>
  35. /// 提交选中内容
  36. /// </summary>
  37. //[MenuItem(SVN_COMMIT)]
  38. public static void SVNCommit()
  39. {
  40. SVNCommand(COMMIT, GetSelectedObjectPath());
  41. }
  42. /// <summary>
  43. /// 提交全部Assets文件夹内容
  44. /// </summary>
  45. [MenuItem(SVN_COMMIT_ALL)]
  46. public static void SVNCommitAll()
  47. {
  48. SVNCommand(COMMIT, Application.dataPath);
  49. }
  50. /// <summary>
  51. /// 更新选中内容
  52. /// </summary>
  53. [MenuItem(SVN_UPDATE)]
  54. public static void SVNUpdate()
  55. {
  56. SVNCommand(UPDATE, GetSelectedObjectPath());
  57. }
  58. /// <summary>
  59. /// 更新全部内容
  60. /// </summary>
  61. [MenuItem(SVN_UPDATE_ALL)]
  62. public static void SVNUpdateAll()
  63. {
  64. SVNCommand(UPDATE, Application.dataPath);
  65. }
  66. /// <summary>
  67. /// 获取全部选中物体的路径
  68. /// 包括meta文件
  69. /// </summary>
  70. /// <returns></returns>
  71. private static string GetSelectedObjectPath()
  72. {
  73. string path = string.Empty;
  74. for (int i = 0; i < Selection.objects.Length; i++)
  75. {
  76. LogManager.Log(AssetDatabase.GetAssetPath(Selection.objects[i]));
  77. path += AssetsPathToFilePath(AssetDatabase.GetAssetPath(Selection.objects[i]));
  78. //路径分隔符
  79. path += "*";
  80. //meta文件
  81. path += AssetsPathToFilePath(AssetDatabase.GetAssetPath(Selection.objects[i])) + ".meta";
  82. //路径分隔符
  83. path += "*";
  84. }
  85. return path;
  86. }
  87. /// <summary>
  88. /// 将Assets路径转换为File路径
  89. /// </summary>
  90. /// <param name="path">Assets/Editor/...</param>
  91. /// <returns></returns>
  92. public static string AssetsPathToFilePath(string path)
  93. {
  94. string m_path = Application.dataPath;
  95. m_path = m_path.Substring(0, m_path.Length - 6);
  96. m_path += path;
  97. return m_path;
  98. }
  99. }