Ejemplo n.º 1
0
        public static void CreateAsset()
        {
            // If there is an existing asset, do not create another one.
            VersionControlForBuild existingAsset = AssetDatabase.LoadAssetAtPath <VersionControlForBuild>(ASSET_PATH);

            if (AssetDatabase.ReferenceEquals(existingAsset, null))
            {
                Debug.Log(LOG_HEADER + "Creating a version control asset for build...");
                existingAsset = ScriptableObject.CreateInstance <VersionControlForBuild>();
                string path = AssetDatabase.GenerateUniqueAssetPath(ASSET_PATH);
                AssetDatabase.CreateAsset(existingAsset, path);

                existingAsset.UpdateVersion();
                existingAsset.IncrementBuildNumber(0);

                EditorUtility.SetDirty(existingAsset);
                AssetDatabase.SaveAssets();
                AssetDatabase.Refresh();
                EditorUtility.FocusProjectWindow();
                Selection.activeObject = existingAsset;
            }
            else
            {
                Debug.LogWarning(LOG_HEADER + "Existing asset was found! If you want to create a new version control asset for Build, manually delete this asset and try again.");

                EditorUtility.FocusProjectWindow();
                Selection.activeObject = existingAsset;
            }
        }
        new void OnEnable()
        {
            base.OnEnable();
            _component1 = target as VersionControlForBuild;

            buildNumber = serializedObject.FindProperty("_buildNumber");

            overrideActiveBuildTarget = serializedObject.FindProperty("_overrideActiveBuildTarget");
            buildTarget = serializedObject.FindProperty("_buildTarget");

            builtProjectPath         = serializedObject.FindProperty("_builtProjectPath");
            additionalTag            = serializedObject.FindProperty("_additionalTag");
            additionalTagPosition    = serializedObject.FindProperty("_additionalTagPosition");
            isDevBuild               = serializedObject.FindProperty("_isDevBuild");
            doNotIncreaseBuildNumber = serializedObject.FindProperty("_doNotIncreaseBuildNumber");
            releaseNote              = serializedObject.FindProperty("_releaseNote");
            addiObjs = serializedObject.FindProperty("_additionalObjectsToBeCopied");

            exportToZip = serializedObject.FindProperty("_exportToZip");

            _major = major.intValue;
            _minor = minor.intValue;
            _patch = patch.intValue;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// [EDITOR_ONLY] Called by Unity Editor on postprocess build.
        /// </summary>
        /// <param name="report"></param>
        public void OnPostprocessBuild(BuildReport report)
        {
            Debug.Log("VersionAndControlForBuild::OnPostprocessBuild");

            /*
             *  Due to the fact that all the loaded object instances are destroyed before building a project, on postprocess build, it has to load an asset from a 'known(hard-coded)' asset path. This is the reason why the asset name and path should not be changed.
             */
            VersionControlForBuild target = AssetDatabase.LoadAssetAtPath <VersionControlForBuild>(ASSET_PATH);

            if (target == null)
            {
                Debug.LogWarning("[VersionControlForBuild] Version control asset for build was not found! Incrementing build number is disabled. Have you moved the Assets/_VersionControlForBuild.asset file?");
            }
            else
            {
                target.IncrementBuildNumber();

                string outputPath = report.summary.outputPath;
                // Debug.Log("outputPath : " + outputPath);

                // pathToBuiltProject : path/to/built/project/BuiltFileName.extension (standalone)
                //TODO check path for iOS
                string pathToBuiltProjectFolder = outputPath.Substring(0, outputPath.LastIndexOf('/'));

                // Release Note
                if (target._releaseNote != null)
                {
                    // Debug.Log("Build complete. builtProject folder : " + pathToBuiltProjectFolder);

                    // Application.dataPath : ~/Assets
                    // AssetDatabase.GetAssetPath(object) : Assets/path/to/file/FileName.extension
                    string releaseNoteFullPath = Application.dataPath.Substring(0, Application.dataPath.LastIndexOf('/')) + "/" + AssetDatabase.GetAssetPath(target._releaseNote);

                    string releaseNoteExtension = Path.GetExtension(releaseNoteFullPath);

                    string releaseNoteDestination = pathToBuiltProjectFolder + "/" + target._releaseNote.name + (target._additionalTagPosition == AdditionalTagPosition.NEXT_TO_PRODUCTNAME ? target._additionalTag : "")
                                                    + "_v" + target.CurrentVersion + (target._additionalTagPosition == AdditionalTagPosition.NEXT_TO_BUILDNUMBER ? target._additionalTag : "")
                                                    + "_" + target.GetCurrentDateYYMMDD() + releaseNoteExtension;

                    FileAttributes attr = File.GetAttributes(releaseNoteFullPath);
                    if ((attr & FileAttributes.Directory) == FileAttributes.Directory)
                    {
                        // Debug.Log("Directory!");
                        // Directory. check if the directory exists
                        if (Directory.Exists(releaseNoteDestination))
                        {
                            Debug.Log("Replacing Release Note Directory.");
                            FileUtil.ReplaceDirectory(releaseNoteFullPath, releaseNoteDestination);
                        }
                        else
                        {
                            Debug.Log("Copying Release Note directory.");
                            FileUtil.CopyFileOrDirectory(releaseNoteFullPath, releaseNoteDestination);
                        }
                    }
                    else
                    {
                        // Debug.Log("File!");
                        // File. Check if the file exists
                        if (File.Exists(releaseNoteDestination))
                        {
                            Debug.Log("Replacing Release Note file.");
                            FileUtil.ReplaceFile(releaseNoteFullPath, releaseNoteDestination);
                        }
                        else
                        {
                            Debug.Log("Copying Release Note file.");
                            FileUtil.CopyFileOrDirectory(releaseNoteFullPath, releaseNoteDestination);
                        }
                    }
                }

                // Additional objects to be copied to output folder.
                for (int i = 0; i < target._additionalObjectsToBeCopied.Length; i++)
                {
                    if (target._additionalObjectsToBeCopied[i] != null)
                    {
                        string objFullPath = Application.dataPath.Substring(0, Application.dataPath.LastIndexOf('/'))
                                             + "/" + AssetDatabase.GetAssetPath(target._additionalObjectsToBeCopied[i]);
                        string objExtension   = Path.GetExtension(objFullPath);
                        string objDestination = pathToBuiltProjectFolder + "/" + target._additionalObjectsToBeCopied[i].name + objExtension;

                        FileAttributes attr = File.GetAttributes(objFullPath);
                        if ((attr & FileAttributes.Directory) == FileAttributes.Directory)
                        {
                            // Directory
                            if (Directory.Exists(objDestination))
                            {
                                Debug.Log("Replacing " + objFullPath + " to " + objDestination);
                                FileUtil.ReplaceDirectory(objFullPath, objDestination);
                            }
                            else
                            {
                                Debug.Log("Copying " + objFullPath + " to " + objDestination);
                                FileUtil.CopyFileOrDirectory(objFullPath, objDestination);
                            }
                        }
                        else
                        {
                            // File
                            if (File.Exists(objDestination))
                            {
                                Debug.Log("Replacing " + objFullPath + " to " + objDestination);
                                FileUtil.ReplaceFile(objFullPath, objDestination);
                            }
                            else
                            {
                                Debug.Log("Copying " + objFullPath + " to " + objDestination);
                                FileUtil.CopyFileOrDirectory(objFullPath, objDestination);
                            }
                        }
                    }
                }


                // Export to Zip
                if (_exportToZip)
                {
                    //NOT IMPLEMENTED YET
                }
            }
        }