/// <summary> /// Returns the path to the original project. /// If currently open project is the original, returns its own path. /// If the original project folder cannot be found, retuns an empty string. /// </summary> /// <returns></returns> public static string GetOriginalProjectPath() { if (IsClone()) { /// If this is a clone... /// Original project path can be deduced by removing the suffix from the clone's path. string cloneProjectPath = ProjectCloner.GetCurrentProject().projectPath; int index = cloneProjectPath.LastIndexOf(ProjectCloner.CloneNameSuffix); if (index > 0) { string originalProjectPath = cloneProjectPath.Substring(0, index); if (Directory.Exists(originalProjectPath)) { return(originalProjectPath); } } return(string.Empty); } else { /// If this is the original, we return its own path. return(ProjectCloner.GetCurrentProjectPath()); } }
/// <summary> /// Returns all clone projects path. /// </summary> /// <returns></returns> public static List <string> GetCloneProjectsPath() { List <string> projectsPath = new List <string>(); for (int i = 0; i < MaxCloneProjectCount; i++) { string originalProjectPath = ProjectCloner.GetCurrentProject().projectPath; string cloneProjectPath = originalProjectPath + ProjectCloner.CloneNameSuffix + "_" + i; if (Directory.Exists(cloneProjectPath)) { projectsPath.Add(cloneProjectPath); } } return(projectsPath); }
/// <summary> /// Creates clone of the project located at the given path. /// </summary> /// <param name="sourceProjectPath"></param> /// <returns></returns> public static Project CreateCloneFromPath(string sourceProjectPath) { Project sourceProject = new Project(sourceProjectPath); string cloneProjectPath = null; //Find available clone suffix id for (int i = 0; i < MaxCloneProjectCount; i++) { string originalProjectPath = ProjectCloner.GetCurrentProject().projectPath; string possibleCloneProjectPath = originalProjectPath + ProjectCloner.CloneNameSuffix + "_" + i; if (!Directory.Exists(possibleCloneProjectPath)) { cloneProjectPath = possibleCloneProjectPath; break; } } if (string.IsNullOrEmpty(cloneProjectPath)) { Debug.LogError("The number of cloned projects has reach its limit. Limit: " + MaxCloneProjectCount); return(null); } Project cloneProject = new Project(cloneProjectPath); Debug.Log("Start project name: " + sourceProject); Debug.Log("Clone project name: " + cloneProject); ProjectCloner.CreateProjectFolder(cloneProject); ProjectCloner.CopyLibraryFolder(sourceProject, cloneProject); ProjectCloner.LinkFolders(sourceProject.assetPath, cloneProject.assetPath); ProjectCloner.LinkFolders(sourceProject.projectSettingsPath, cloneProject.projectSettingsPath); ProjectCloner.LinkFolders(sourceProject.packagesPath, cloneProject.packagesPath); ProjectCloner.LinkFolders(sourceProject.autoBuildPath, cloneProject.autoBuildPath); ProjectCloner.RegisterClone(cloneProject); return(cloneProject); }
/// <summary> /// Returns the path to the clone project. /// If currently open project is the clone, returns its own path. /// If the clone does not exist yet, retuns an empty string. /// </summary> /// <returns></returns> public static string GetCloneProjectPath() { if (IsClone()) { /// If this is the clone, we return its own path. return(ProjectCloner.GetCurrentProjectPath()); } else { /// If this is the original... /// Clone project path can be deduced by add the suffix to the original's path. string originalProjectPath = ProjectCloner.GetCurrentProject().projectPath; string cloneProjectPath = originalProjectPath + ProjectCloner.CloneNameSuffix; if (Directory.Exists(cloneProjectPath)) { return(cloneProjectPath); } return(string.Empty); } }
/// <summary> /// Returns the path to the original project. /// If currently open project is the original, returns its own path. /// If the original project folder cannot be found, retuns an empty string. /// </summary> /// <returns></returns> public static string GetOriginalProjectPath() { if (IsClone()) { // If this is a clone... // Original project path can be deduced by removing the suffix from the clone's path. string cloneProjectPath = ProjectCloner.GetCurrentProject().projectPath; string originalProjectPath = cloneProjectPath.Remove(cloneProjectPath.Length - ProjectCloner.CloneNameSuffix.Length); if (Directory.Exists(originalProjectPath)) { return(originalProjectPath); } return(string.Empty); } else { // If this is the original, we return its own path. return(ProjectCloner.GetCurrentProjectPath()); } }
private void OnGUI() { GUILayout.Label("Clone settings", EditorStyles.boldLabel); if (isClone) { /// If it is a clone project... string originalProjectPath = ProjectCloner.GetOriginalProjectPath(); if (originalProjectPath == string.Empty) { /// If original project cannot be found, display warning message. string thisProjectName = ProjectCloner.GetCurrentProject().name; string supposedOriginalProjectName = ProjectCloner.GetCurrentProject().name.Replace("_clone", ""); EditorGUILayout.HelpBox( "This project is a clone, but the link to the original seems lost.\nYou have to manually open the original and create a new clone instead of this one.\nThe original project should have a name '" + supposedOriginalProjectName + "', if it was not changed.", MessageType.Warning); } else { /// If original project is present, display some usage info. EditorGUILayout.HelpBox( "This project is a clone of the project '" + Path.GetFileName(originalProjectPath) + "'.\nIf you want to make changes the project files or manage clones, please open the original project through Unity Hub.", MessageType.Info); } } else { /// If it is an original project... if (isCloneCreated) { /// If clone is created, we can either open it or delete it. string cloneProjectPath = ProjectCloner.GetCloneProjectPath(); EditorGUILayout.TextField("Clone project path", cloneProjectPath, EditorStyles.textField); if (GUILayout.Button("Open clone project")) { ProjectCloner.OpenProject(cloneProjectPath); } if (GUILayout.Button("Delete clone")) { bool delete = EditorUtility.DisplayDialog( "Delete the clone?", "Are you sure you want to delete the clone project '" + ProjectCloner.GetCurrentProject().name + "_clone'? If so, you can always create a new clone from ProjectCloner window.", "Delete", "Cancel"); if (delete) { ProjectCloner.DeleteClone(); this.Repaint(); } } } else { /// If no clone created yet, we must create it. EditorGUILayout.HelpBox("No project clones found. Create a new one!", MessageType.Info); if (GUILayout.Button("Create new clone")) { ProjectCloner.CreateCloneFromCurrent(); } } } }
private void OnGUI() { if (isClone) { /// If it is a clone project... string originalProjectPath = ProjectCloner.GetOriginalProjectPath(); if (originalProjectPath == string.Empty) { /// If original project cannot be found, display warning message. string thisProjectName = ProjectCloner.GetCurrentProject().name; string supposedOriginalProjectName = ProjectCloner.GetCurrentProject().name.Replace("_clone", ""); EditorGUILayout.HelpBox( "This project is a clone, but the link to the original seems lost.\nYou have to manually open the original and create a new clone instead of this one.\nThe original project should have a name '" + supposedOriginalProjectName + "', if it was not changed.", MessageType.Warning); } else { /// If original project is present, display some usage info. EditorGUILayout.HelpBox( "This project is a clone of the project '" + Path.GetFileName(originalProjectPath) + "'.\nIf you want to make changes the project files or manage clones, please open the original project through Unity Hub.", MessageType.Info); } } else { /// If it is an original project... if (isCloneCreated) { GUILayout.BeginVertical("HelpBox"); GUILayout.Label("Clones of this Project"); /// If clone(s) is created, we can either open it or delete it. var cloneProjectsPath = ProjectCloner.GetCloneProjectsPath(); for (int i = 0; i < cloneProjectsPath.Count; i++) { GUILayout.BeginVertical("GroupBox"); string cloneProjectPath = cloneProjectsPath[i]; EditorGUILayout.LabelField("Clone " + i); EditorGUILayout.TextField("Clone project path", cloneProjectPath, EditorStyles.textField); if (GUILayout.Button("Open in New Editor")) { ProjectCloner.OpenProject(cloneProjectPath); } GUILayout.BeginHorizontal(); if (GUILayout.Button("Delete")) { bool delete = EditorUtility.DisplayDialog( "Delete the clone?", "Are you sure you want to delete the clone project '" + ProjectCloner.GetCurrentProject().name + "_clone'? If so, you can always create a new clone from ProjectCloner window.", "Delete", "Cancel"); if (delete) { ProjectCloner.DeleteClone(cloneProjectPath); } } //Offer a solution to user in-case they are stuck with deleting project if (GUILayout.Button("?", GUILayout.Width(30))) { var openUrl = EditorUtility.DisplayDialog("Can't delete clone?", "Sometime clone can't be deleted due to it's still being opened by another unity instance running in the background." + "\nYou can read this answer from ServerFault on how to find and kill the process.", "Open Answer"); if (openUrl) { Application.OpenURL("https://serverfault.com/a/537762"); } } GUILayout.EndHorizontal(); GUILayout.EndVertical(); } GUILayout.EndVertical(); //Have difficulty with naming //GUILayout.Label("Other", EditorStyles.boldLabel); if (GUILayout.Button("Add new clone")) { ProjectCloner.CreateCloneFromCurrent(); } } else { /// If no clone created yet, we must create it. EditorGUILayout.HelpBox("No project clones found. Create a new one!", MessageType.Info); if (GUILayout.Button("Create new clone")) { ProjectCloner.CreateCloneFromCurrent(); } } } }