Пример #1
0
        static void ClearProject()
        {
            if (Instance != null)
            {
                if (Instance.project != null)
                {
                    ProjectUtils.DestroyProject(Instance.project);
                    Instance.project = null;
                }

                Instance.folderPath = null;
                Instance.Repaint();
            }
            else
            {
                // Attempt to get a reference of the Project asset itself
                Project project = ProjectUtils.FetchProject();
                if (project != null)
                {
                    ProjectUtils.DestroyProject(project);
                }
            }

            Debug.Log("[Arcweave] Project folder cleared.");
        }
Пример #2
0
        /*
         * Precompute board names.
         */
        private void PrecomputeBoardNames()
        {
            List <string> boardIDs   = new List <string>();
            List <string> boardPaths = new List <string>();

            ProjectUtils.GetBoardsFullPaths(project, boardIDs, boardPaths);

            this.boardIDs   = boardIDs.ToArray();
            this.boardPaths = boardPaths.ToArray();
        }
Пример #3
0
 /*
  * Handle project refresh button.
  */
 private void HandleProjectRefresh(Project project, DateTime newTimestamp)
 {
     EditorGUILayout.LabelField("Project sources are newer than the generated Arcweave data.", Resources.styles.refreshWarningLabelStyle);
     if (GUILayout.Button("Refresh"))
     {
         if (ProjectUtils.ReadProject(project, project.folderPath))
         {
             project.sourceTimestamp = newTimestamp.ToBinary();
             EditorUtility.SetDirty(project);
             AssetDatabase.SaveAssets();
         }
     }
 }
Пример #4
0
        /*
         * Draw the project folder selection.
         */
        private void HandleProjectFolderSelector()
        {
            UnityAction <string> onSetFolder = (string currentPath) =>
            {
                string newFolderPath = EditorUtility.OpenFolderPanel("Project path", currentPath, null);

                if (string.IsNullOrEmpty(newFolderPath))
                {
                    return;
                }

                // Check that project is inside Unity's Assets
                DirectoryInfo dir      = new DirectoryInfo(newFolderPath);
                DirectoryInfo assetDir = new DirectoryInfo(Application.dataPath);
                if (!dir.FullName.Contains(assetDir.FullName))
                {
                    string message = "The Arcweave project must be placed inside Unity's Asset Folder.\n";
                    message += "Unity Asset Folder: " + assetDir.FullName + "\n";
                    message += "Selected Folder: " + dir.FullName + "\n";
                    message += "Please try again.";
                    EditorUtility.DisplayDialog("Wrong Path", message, "Okay");
                    return;
                }

                // Check project file
                FileInfo projectFileInfo = ProjectUtils.GetProjectFile(newFolderPath);
                if (projectFileInfo == null)
                {
                    string message = "Oops... We cannot find the project at the specified path:\n";
                    message += newFolderPath;
                    message += "\nPlease try again.";
                    EditorUtility.DisplayDialog("Arcweave Project missing", message, "Okay");
                }
                else
                {
                    bool    generateClasses = true;
                    Project current         = ProjectUtils.FetchProject();
                    if (current != null)
                    {
                        string message = "Generated Project folder is not empty.\n";
                        message += "Do you wish to proceed?\n";
                        message += "(doing this will delete all contents in Assets/Resources/Arcweave/)";
                        bool continueWithErasing = EditorUtility.DisplayDialog("Directory not empty", message, "Do it", "Nevermind");
                        if (continueWithErasing)
                        {
                            ProjectUtils.DestroyProject(current);
                            generateClasses = true;
                        }
                    }

                    // Proceed with generation
                    if (generateClasses)
                    {
                        // Start generating
                        Project newProject = CreateInstance <Project>();
                        if (ProjectUtils.ReadProject(newProject, newFolderPath))
                        {
                            // Set new folder path
                            folderPath = newFolderPath;

                            // Set board
                            project                  = newProject;
                            project.folderPath       = newFolderPath;
                            project.startingBoardIdx = 0;

                            // Setup the board names
                            PrecomputeBoardNames();

                            // Setup the element names
                            Board main = project.boards[project.startingBoardIdx];
                            PrecomputeElementNames(main);

                            // Setup the project file timestamp
                            project.sourceTimestamp = projectFileInfo.LastWriteTimeUtc.ToBinary();

                            // Save project asset
                            string projectPath = "Assets" + ProjectUtils.projectResourceFolder + "Project.asset";
                            AssetDatabase.CreateAsset(newProject, projectPath);
                            EditorUtility.SetDirty(newProject);
                            AssetDatabase.SaveAssets();
                        }
                        else
                        {
                            DestroyImmediate(newProject);
                        }
                    }
                }
            };

            if (string.IsNullOrEmpty(folderPath))
            {
                EditorGUILayout.LabelField("No project folder selected.");
                if (GUILayout.Button("Setup"))
                {
                    onSetFolder(Application.dataPath);
                }
            }
            else
            {
                EditorGUILayout.LabelField("Current project path: " + folderPath, Resources.styles.folderLabelStyle);
                if (GUILayout.Button("Change"))
                {
                    onSetFolder(folderPath);
                }
            }
        }