Project.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using System.Linq;
  5. using UnityProjectCloner;
  6. namespace UnityProjectCloner
  7. {
  8. public class Project : System.ICloneable
  9. {
  10. public string name;
  11. public string projectPath;
  12. string rootPath;
  13. public string assetPath;
  14. public string projectSettingsPath;
  15. public string libraryPath;
  16. public string packagesPath;
  17. public string autoBuildPath;
  18. char[] separator = new char[1] { '/' };
  19. /// <summary>
  20. /// Default constructor
  21. /// </summary>
  22. public Project()
  23. {
  24. }
  25. /// <summary>
  26. /// Initialize the project object by parsing its full path returned by Unity into a bunch of individual folder names and paths.
  27. /// </summary>
  28. /// <param name="path"></param>
  29. public Project(string path)
  30. {
  31. ParsePath(path);
  32. }
  33. /// <summary>
  34. /// Create a new object with the same settings
  35. /// </summary>
  36. /// <returns></returns>
  37. public object Clone()
  38. {
  39. Project newProject = new Project();
  40. newProject.rootPath = rootPath;
  41. newProject.projectPath = projectPath;
  42. newProject.assetPath = assetPath;
  43. newProject.projectSettingsPath = projectSettingsPath;
  44. newProject.libraryPath = libraryPath;
  45. newProject.name = name;
  46. newProject.separator = separator;
  47. newProject.packagesPath = packagesPath;
  48. newProject.autoBuildPath = autoBuildPath;
  49. return newProject;
  50. }
  51. /// <summary>
  52. /// Update the project object by renaming and reparsing it. Pass in the new name of a project, and it'll update the other member variables to match.
  53. /// </summary>
  54. /// <param name="name"></param>
  55. public void updateNewName(string newName)
  56. {
  57. name = newName;
  58. ParsePath(rootPath + "/" + name + "/Assets");
  59. }
  60. /// <summary>
  61. /// Debug override so we can quickly print out the project info.
  62. /// </summary>
  63. /// <returns></returns>
  64. public override string ToString()
  65. {
  66. string printString = name + "\n" +
  67. rootPath + "\n" +
  68. projectPath + "\n" +
  69. assetPath + "\n" +
  70. projectSettingsPath + "\n" +
  71. packagesPath + "\n" +
  72. autoBuildPath + "\n" +
  73. libraryPath;
  74. return (printString);
  75. }
  76. private void ParsePath(string path)
  77. {
  78. //Unity's Application functions return the Assets path in the Editor.
  79. projectPath = path;
  80. //pop off the last part of the path for the project name, keep the rest for the root path
  81. List<string> pathArray = projectPath.Split(separator).ToList<string>();
  82. name = pathArray.Last();
  83. pathArray.RemoveAt(pathArray.Count() - 1);
  84. rootPath = string.Join(separator[0].ToString(), pathArray);
  85. assetPath = projectPath + "/Assets";
  86. projectSettingsPath = projectPath + "/ProjectSettings";
  87. libraryPath = projectPath + "/Library";
  88. packagesPath = projectPath + "/Packages";
  89. autoBuildPath = projectPath + "/AutoBuild";
  90. }
  91. }
  92. }