예제 #1
0
        private void SaveSnapshot(AssetSnapshot snapshot)
        {
            string savePath = PathUtil.Combine(outputDir, string.Format("digest_{0}.txt", newVersion));
            string modPath  = PathUtil.Combine(outputDir, string.Format("modlist_{0}.txt", newVersion));
            string verPath  = PathUtil.Combine(outputDir, string.Format("modver_{0}.txt", newVersion));

            snapshot.SaveDigest(savePath, verPath);
            // save mod list
            File.WriteAllText(modPath, modList.Join("\n"));
            // save version at file
            if (!oldVersion.IsEmpty())
            {
                File.WriteAllText(versionFile, string.Format("{0} {1}\n", oldVersion, newVersion));
            }
        }
예제 #2
0
        private List <string> GetRawAssetMods(AssetSnapshot snapshot, string srcDir)
        {
            List <string> mod = new List <string>();

            foreach (string assetPath in EditorAssetUtil.ListAssetPaths(srcDir, FileType.All, true))
            {
                if (assetPath.EndsWithIgnoreCase(".meta") || Path.GetFileName(assetPath).StartsWith(".", StringComparison.Ordinal))
                {
                    continue;
                }

                AssetDigest digest = snapshot.GetAssetDigest(assetPath);
                if (digest.IsModified())
                {
                    mod.Add(assetPath);
                }
            }
            return(mod);
        }
예제 #3
0
        static bool IsDepModified(AssetSnapshot snapshot, AssetDigest digest)
        {
            string[] dependPaths = AssetDatabase.GetDependencies(new string[] { "Assets/" + digest.path });
            bool     modified    = digest.IsModified();

            // check dependencies midified
            for (int i = 0; i < dependPaths.Length; ++i)
            {
                dependPaths[i] = EditorAssetUtil.GetAssetRelativePath(dependPaths[i]);
                if (digest.path == dependPaths[i])
                {
                    continue;
                }
                AssetDigest depDigest = snapshot.GetDependDigest(dependPaths[i]);
                modified |= depDigest.IsModified();
                if (depDigest.path.Is(FileType.Asset, FileType.Prefab))
                {
                    modified |= IsDepModified(snapshot, depDigest);
                }
            }
            return(modified);
        }
예제 #4
0
        private List <string> GetAssetMods(AssetSnapshot snapshot, string srcDir)
        {
            List <string> mods = new List <string>();

            string[] assetPaths = EditorAssetUtil.ListAssetPaths(srcDir, FileType.All, true);
            foreach (string assetPath in assetPaths)
            {
                if (assetPath.EndsWithIgnoreCase(".meta") ||
                    Path.GetFileName(assetPath).StartsWith(".", StringComparison.Ordinal) ||
                    assetPath.EndsWithIgnoreCase(".unity"))
                {
                    continue;
                }

                AssetDigest digest   = snapshot.GetAssetDigest(assetPath);
                bool        modified = IsDepModified(snapshot, digest);

                if (modified)
                {
                    mods.Add(assetPath);
                }
            }
            return(mods);
        }
예제 #5
0
        /// <summary>
        /// Build the specified snapshotPath and outputDir.
        /// </summary>
        /// <param name="snapshotPath">Snapshot path. null if no previous snapshot exists</param>
        /// <param name="outputDir">Output dir.</param>
        public void Build()
        {
            BuildConfig.Reset();
            List <ObjRef> dirRefs    = abPath.dirs;
            List <ObjRef> rawDirRefs = abPath.rawDirs;

            if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.WebGL)
            {
                // WWW Caching only allows asset bundle.
                dirRefs.AddRange(rawDirRefs);
                rawDirRefs.Clear();
            }

            if (Directory.Exists(outputDir) && !Directory.GetFiles(outputDir).IsEmpty())
            {
                throw new Exception(string.Format("Output directory {0} is not empty", outputDir));
            }
            AssetSnapshot snapshot = GetPrevSnapshot();

            try
            {
                List <string> assetMods    = new List <string>();
                List <string> rawAssetMods = new List <string>();
                // get mods
                foreach (ObjRef dir in rawDirRefs)
                {
                    rawAssetMods.AddRange(GetRawAssetMods(snapshot, dir.path));
                }
                foreach (ObjRef dir in dirRefs)
                {
                    assetMods.AddRange(GetAssetMods(snapshot, dir.path));
                }
                string err1 = VerifyLowerCase(assetMods);
                string err2 = VerifyLowerCase(rawAssetMods);
                if (!err1.IsEmpty() || !err2.IsEmpty())
                {
                    throw new Exception($"{err1}\n{err2}");
                }

                assetMods.RemoveAll(m => rawAssetMods.Contains(m));
                log.Debug("Modified raw assets ({0:D0})", rawAssetMods.Count);
                log.Debug("Modified assets ({0:D0})", assetMods.Count);
                string[] srcList = assetMods.ConvertAll(p => "Assets/" + p).ToArray();
                // preprocess
                var buildLog = BuildScript.PrebuildAll(ProcessStage.Verify);
                if (!buildLog.isEmpty)
                {
                    throw new Exception(buildLog.ToString());
                }
                buildLog = BuildScript.PrebuildAssets(srcList);
                if (!buildLog.isEmpty)
                {
                    Debug.LogError(buildLog.ToString());
                    EditorUtility.DisplayDialog("Verify Fails", buildLog.ToString(), "OK");
                }
                // change texture formats
                texFormat.ConvertDependencies(srcList);
                // build
                GenerateRawAsset(rawAssetMods, outputDir);
                GenerateAsset(assetMods, outputDir);
                AssetDatabase.SaveAssets();
                modList.Clear();
                modList.AddRange(assetMods);
                modList.AddRange(rawAssetMods);
            } catch (Exception ex)
            {
                log.Error(ex);
                throw ex;
            }

            if (!modList.IsEmpty())
            {
                SaveSnapshot(snapshot);
            }
            else
            {
                if (File.Exists(versionFile))
                {
                    File.Delete(versionFile);
                }
                Debug.LogError("No resource change found");
            }
        }