Beispiel #1
0
    public static CDepCollectInfo __DoBuildScriptableObject(string fullAssetPath, ScriptableObject so,
                                                            bool realBuildOrJustPath = true)
    {
        var hasBuilded = false;

        fullAssetPath = Path.ChangeExtension(fullAssetPath, AppEngine.GetConfig("AssetBundleExt"));

        if (so == null)
        {
            Logger.LogError("Error Null ScriptableObject: {0}", fullAssetPath);
        }
        else
        {
            //so.name = fullAssetPath;
            if (!BuildRecord.ContainsKey(fullAssetPath))
            {
                AddCache(fullAssetPath);
                if (!IsJustCollect && realBuildOrJustPath)
                {
                    KBuildTools.BuildScriptableObject(so, fullAssetPath);
                    hasBuilded = true;
                }
            }
        }

        return(new CDepCollectInfo
        {
            Path = fullAssetPath,
            Asset = so,
            HasBuild = hasBuilded,
        });
    }
Beispiel #2
0
        public static string GetResourceExportPath()
        {
            var resourcePath = KBuildTools.GetExportPath(EditorUserBuildSettings.activeBuildTarget,
                                                         KResourceModule.Quality);

            return(resourcePath);
        }
Beispiel #3
0
    //
    /// <summary>
    /// 如果非realBuild,僅返回最終路徑
    /// DoBuildAssetBundle和__DoBuildScriptableObject有两个开关,决定是否真的Build
    /// realBuildOrJustPath由外部传入,一般用于进行md5比较后,传入来的,【不收集Build缓存】 TODO:其实可以收集的。。
    /// IsJustCollect用于全局的否决真Build,【收集Build缓存】
    /// </summary>
    /// <param name="path"></param>
    /// <param name="asset"></param>
    /// <param name="realBuildOrJustPath"></param>
    /// <returns></returns>
    public static CDepCollectInfo DoBuildAssetBundle(string path, UnityEngine.Object asset,
                                                     bool realBuildOrJustPath = true)
    {
        path = Path.ChangeExtension(path, AppEngine.GetConfig("AssetBundleExt"));
        //asset.name = fullAssetPath;
        var hasBuilded = false;

        if (!BuildRecord.ContainsKey(path))
        {
            if (realBuildOrJustPath)
            {
                AddCache(path);
            }
            if (IsJustCollect)
            {
                AddCache(path);
            }
            if (!IsJustCollect && realBuildOrJustPath)
            {
                //BuildedCache[fullAssetPath] = true;
                KBuildTools.BuildAssetBundle(asset, path);
                hasBuilded = true;
            }
        }

        return(new CDepCollectInfo
        {
            Path = path,
            Asset = asset,
            HasBuild = hasBuilded,
        });
    }
Beispiel #4
0
    public void ExportCurrentUI()
    {
        //if (changeLayer)
        //{
        // 去掉一些残留的Clone
        //var allTrans = GameObject.FindObjectsOfType<Transform>();
        //for (var i = allTrans.Length - 1; i >= 0 ; i--)
        //{
        //    var child = allTrans[i];
        //    if (child != null && child.gameObject.name.EndsWith("Window(Clone)"))
        //    {
        //        GameObject.DestroyImmediate(child.gameObject);
        //    }
        //}
        EditorApplication.SaveScene(); // 强制保存一下,保证一些Prefab更新

        //}

        foreach (var windowAsset in GameObject.FindObjectsOfType <KUIWindowAsset>())
        {
            var uiName          = windowAsset.name;
            var tempPanelObject = CreateTempPrefab(windowAsset.gameObject);

            if (ExportCurrentUIEvent != null)
            {
                ExportCurrentUIEvent(this, UIScenePath, uiName, tempPanelObject);
            }
            else
            {
                KBuildTools.BuildAssetBundle(tempPanelObject, GetBuildRelPath(uiName));
            }
            DestroyTempPrefab(tempPanelObject);
        }
    }
Beispiel #5
0
        public static void ExportCurrentUI()
        {
            var UIName = Path.GetFileNameWithoutExtension(EditorApplication.currentScene);

            var uiRoot = GameObject.Find("UI");

            KBuildTools.BuildAssetBundle(uiRoot, GetBuildRelPath(UIName));
        }
Beispiel #6
0
    public static void MenuCheckAndLogDependencies()
    {
        var obj = Selection.activeObject;

        if (obj == null)
        {
            Debug.LogError("No selection object");
            return;
        }
        var assetPath = AssetDatabase.GetAssetPath(obj);

        KBuildTools.CheckAndLogDependencies(assetPath);
    }
Beispiel #7
0
    /// <summary>
    /// 获取完整的打包路径,并确保目录存在
    /// </summary>
    /// <param name="path"></param>
    /// <param name="buildTarget"></param>
    /// <returns></returns>
    public static string MakeSureExportPath(string path, BuildTarget buildTarget, KResourceQuality quality)
    {
        path = KBuildTools.GetExportPath(buildTarget, quality) + path;

        string exportDirectory = path.Substring(0, path.LastIndexOf('/'));

        if (!System.IO.Directory.Exists(exportDirectory))
        {
            System.IO.Directory.CreateDirectory(exportDirectory);
        }

        path = path.Replace("/", @"\");

        return(path);
    }
Beispiel #8
0
    public static uint BuildScriptableObject <T>(T scriptObject, string path, BuildTarget buildTarget,
                                                 KResourceQuality quality) where T : ScriptableObject
    {
        const string tempAssetPath = "Assets/~Temp.asset";

        AssetDatabase.CreateAsset(scriptObject, tempAssetPath);
        T tempObj = (T)AssetDatabase.LoadAssetAtPath(tempAssetPath, typeof(T));

        if (tempObj == null)
        {
            throw new System.Exception();
        }

        uint crc = KBuildTools.BuildAssetBundle(tempObj, path, buildTarget, quality);

        AssetDatabase.DeleteAsset(tempAssetPath);

        return(crc);
    }
Beispiel #9
0
    /// <summary>
    /// Extra Flag ->   ex:  Android/  AndroidSD/  AndroidHD/
    /// </summary>
    /// <param name="platfrom"></param>
    /// <param name="quality"></param>
    /// <returns></returns>
    public static string GetExportPath(BuildTarget platfrom, KResourceQuality quality = KResourceQuality.Sd)
    {
        string basePath =
            Path.GetFullPath(Application.dataPath + "/" +
                             KEngine.AppEngine.GetConfig(KEngineDefaultConfigs.AssetBundleBuildRelPath) + "/");

        if (File.Exists(basePath))
        {
            KBuildTools.ShowDialog("路径配置错误: " + basePath);
            throw new System.Exception("路径配置错误");
        }
        if (!Directory.Exists(basePath))
        {
            Directory.CreateDirectory(basePath);
        }

        string path = null;

        switch (platfrom)
        {
        case BuildTarget.Android:
        case BuildTarget.iPhone:
        case BuildTarget.StandaloneWindows:
            var platformName = KResourceModule.BuildPlatformName;
            if (quality != KResourceQuality.Sd)     // SD no need add
            {
                platformName += quality.ToString().ToUpper();
            }

            path = basePath + platformName + "/";
            break;

        default:
            KBuildTools.ShowDialog("构建平台配置错误");
            throw new System.Exception("构建平台配置错误");
        }
        return(path);
    }
Beispiel #10
0
 public static void ClearPlayerPrefs()
 {
     PlayerPrefs.DeleteAll();
     PlayerPrefs.Save();
     KBuildTools.ShowDialog("Prefs Cleared!");
 }
Beispiel #11
0
        /// <summary>
        /// ResourceDep系统专用的打包AssetBundle函数
        /// </summary>
        /// <param name="asset"></param>
        /// <param name="path"></param>
        /// <param name="depFileRelativeBuildPath">依赖文件列表,相对的AssetBundle打包路径</param>
        /// <param name="buildTarget"></param>
        /// <param name="quality"></param>
        /// <returns></returns>
        private static BuildBundleResult BuildAssetBundle(Object asset, string path,
                                                          IList <string> depFileRelativeBuildPath, BuildTarget buildTarget, KResourceQuality quality)
        {
            //是否是Level / Scene
            var isScene = asset.ToString().Contains("SceneAsset");

            uint crc  = 0;
            var  time = DateTime.Now;
            // 最终完整路径
            var buildToFullPath = KBuildTools.MakeSureExportPath(path, buildTarget, quality) +
                                  AppEngine.GetConfig(KEngineDefaultConfigs.AssetBundleExt);
            var buildToRelativePath = AbsPath2RelativePath(buildToFullPath);//buildToFullPath.Replace(workdirPath, "").Substring(1); // 转换成相对路径,避免路径过程无法打包的问题

            var assetPath = AssetDatabase.GetAssetPath(asset);

            // 版本标记
            var unityAssetType = GetUnityAssetType(assetPath);

            if (unityAssetType == UnityAssetType.Builtin || unityAssetType == UnityAssetType.Memory)
            {
                var buildAssetPath = GetBuildAssetPath(asset);
                KAssetVersionControl.TryMarkRecord(buildAssetPath);
                BuildedPool.Add(buildAssetPath);
            }
            else
            {
                KAssetVersionControl.TryMarkBuildVersion(assetPath);
                BuildedPool.Add(assetPath);
            }

            bool result = false;

            if (isScene)
            {
                var resultStr = BuildPipeline.BuildStreamedSceneAssetBundle(new string[] { assetPath }, buildToRelativePath,
                                                                            buildTarget, out crc);
                result = String.IsNullOrEmpty(resultStr);
                if (!String.IsNullOrEmpty(resultStr))
                {
                    Debug.LogError(resultStr);
                }
            }
            else
            {
                result = BuildPipeline.BuildAssetBundle(asset, null, buildToRelativePath,
                                                        out crc,
                                                        BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.DeterministicAssetBundle |
                                                        BuildAssetBundleOptions.CompleteAssets,
                                                        buildTarget);
            }

            // 创建依赖记录文件
            string fullManifestPath = null;

            //if (depFileRelativeBuildPath != null && depFileRelativeBuildPath.Any())
            {
                //var manifestFileContent = string.Join("\n", depFileRelativeBuildPath.KToArray());
                if (depFileRelativeBuildPath == null)
                {
                    depFileRelativeBuildPath = new List <string>();
                }

                var manifestPath = path + ".manifest";
                fullManifestPath = KBuildTools.MakeSureExportPath(manifestPath, buildTarget, quality) +
                                   AppEngine.GetConfig(KEngineDefaultConfigs.AssetBundleExt);
                var relativeManifestPath = AbsPath2RelativePath(fullManifestPath); // 转成相对路径

                var utf8NoBom = new UTF8Encoding(false);
                //try
                //{
                File.WriteAllLines(relativeManifestPath, depFileRelativeBuildPath.KToArray(), utf8NoBom);
                //}
                //catch (Exception e)
                //{
                //    // 会出现DirectoryNotFound,但是目录明明就存在! 先Catch
                //    Logger.LogError("Exception: {0}", e.Message);
                //    var dirPath = Path.GetDirectoryName(fullManifestPath);
                //    if (Directory.Exists(dirPath))
                //        Logger.LogError("Directory Exists: {0}", dirPath);
                //    else
                //    {
                //        Logger.LogError("Directory not exists: {0}", dirPath);
                //    }
                //}
            }

            if (result)
            {
                var abInfo = new FileInfo(buildToFullPath);
                Logger.Log("Build AssetBundle: {0} / CRC: {1} / Time: {2:F4}s / Size: {3:F3}KB / FullPath: {4} / RelPath: {5}", path, crc, (DateTime.Now - time).TotalSeconds,
                           abInfo.Length / 1024d, buildToFullPath, buildToRelativePath);
            }
            else
            {
                Logger.LogError("生成文件失败: {0}, crc: {1} 耗时: {2:F5}, 完整路径: {3}", path, crc,
                                (DateTime.Now - time).TotalSeconds, buildToFullPath);
            }
            return(new BuildBundleResult
            {
                Crc = crc,
                FullPath = buildToFullPath,
                RelativePath = path,
                IsSuccess = result,
                ManifestFullPath = fullManifestPath,
            });
        }
Beispiel #12
0
    // 包含json!,不包含圖集
    static CDepCollectInfo GetBuildSpineData(SkeletonDataAsset data)
    {
        string path = AssetDatabase.GetAssetPath(data);

        // DataAsset
        bool needBuildDataAsset = KBuildTools.CheckNeedBuild(path);

        if (needBuildDataAsset)
        {
            KBuildTools.MarkBuildVersion(path);
        }

        // Spine的JSON
        string textAssetPath          = AssetDatabase.GetAssetPath(data.skeletonJSON);
        bool   needBuildJsonTextAsset = KBuildTools.CheckNeedBuild(textAssetPath);

        if (needBuildJsonTextAsset)
        {
            KBuildTools.MarkBuildVersion(textAssetPath);
        }

        //string originPath = path;
        //string tmpPath = "Assets/~TempSkeletonDataAsset.asset";
        //bool copyResult = AssetDatabase.CopyAsset(path, tmpPath);
        //Logger.Assert(copyResult);
        //SkeletonDataAsset copyData = AssetDatabase.LoadAssetAtPath(tmpPath, typeof(SkeletonDataAsset)) as SkeletonDataAsset;
        if (data.spriteCollection == null || data.skeletonJSON == null)
        {
            Logger.LogError("Err Spine Data: {0}, Lack of SpriteCollection or Json", data.name);
            //return "";
        }

        string spriteColPath      = BuildSpriteCollection(data.spriteCollection);
        string spriteColAssetPath = AssetDatabase.GetAssetPath(data.spriteCollection.gameObject);
        bool   needBuildSpriteCol = KBuildTools.CheckNeedBuild(spriteColAssetPath);

        if (needBuildSpriteCol)
        {
            KBuildTools.MarkBuildVersion(spriteColAssetPath);
        }

        SkeletonDataAsset copyData = GameObject.Instantiate(data) as SkeletonDataAsset;

        copyData.spriteCollection = null; // 挖空图集, 保留Json!


        // SpineData包括了这个SkeletonData!
        var skeletonDataBuildResult = __DoBuildScriptableObject(DepBuildToFolder + "/SkeletonData_" + data.name, copyData, needBuildDataAsset || needBuildJsonTextAsset);  // json文件直接放在SkeletonDataAsset打包! 分离图集

        CSpineData spineData = ScriptableObject.CreateInstance <CSpineData>();

        spineData.SpriteCollectionPath = spriteColPath;
        spineData.DataAssetPath        = skeletonDataBuildResult.Path; // 保留json文件,不挖空 copyData.skeletonJSON

        path = __GetPrefabBuildPath(path);
        // DataAsset或圖集或Json任一重打包了,都要重新打包CSpineData(記錄圖集保存地方和Jsondataasset保存地方)
        var spineDataBuildResult = __DoBuildScriptableObject(DepBuildToFolder + "/SpineData_" + path, spineData, needBuildDataAsset || needBuildSpriteCol || needBuildJsonTextAsset);

        spineDataBuildResult.Child = skeletonDataBuildResult;

        GameObject.DestroyImmediate(copyData);

        return(spineDataBuildResult);
    }
Beispiel #13
0
    // Prefab build, 单次build缓存
    public static string BuildSpriteCollection(tk2dSpriteCollectionData data)
    {
        if (data == null)
        {
            Logger.LogError("[BuildSpriteColleccion]Null SpriteCol Data!!!");
            return("");
        }
        GameObject spriteColPrefab = PrefabUtility.FindPrefabRoot(data.gameObject) as GameObject;

        Logger.Assert(spriteColPrefab);

        string path = AssetDatabase.GetAssetPath(spriteColPrefab);  // prefab只用来获取路径,不打包不挖空

        if (string.IsNullOrEmpty(path))
        {
            Logger.Log("Null Sprite Collection {0}", path);
            return("");   // !!! SpriteCollection可能动态生成的,不打包它
        }
        bool needBuild = KBuildTools.CheckNeedBuild(path);

        if (needBuild)
        {
            KBuildTools.MarkBuildVersion(path);
        }

        path = __GetPrefabBuildPath(path);

        GameObject copySpriteColObj            = GameObject.Instantiate(spriteColPrefab) as GameObject;
        tk2dSpriteCollectionData spriteColData = copySpriteColObj.GetComponent <tk2dSpriteCollectionData>();

        foreach (Material mat in spriteColData.materials) // many materials
        {
            string matPath = BuildDepMaterial(mat, GameDef.PictureScale);
            if (!string.IsNullOrEmpty(matPath))  // 材质可能动态创建的,无需打包
            //CResourceDependencies.Create(spriteColData, CResourceDependencyType.SPRITE_COLLECTION, matPath);
            {
                KAssetDep.Create <CTk2dSpriteCollectionDep>(spriteColData, matPath);
            }
        }

        spriteColData.materials = new Material[0]; // 挖空spriteCollections
        spriteColData.textures  = new Texture[0];
        foreach (var def in spriteColData.spriteDefinitions)
        {
            def.material = null;
            // 进行缩放!
            //if (def.positions != null)
            //{
            //    // position!  size!
            //    for (var ip = 0; ip < def.positions.Length; ip++)
            //    {
            //        def.positions[ip] = def.positions[ip] / GameDef.PictureScale;
            //    }
            //    for (var ip = 0; ip < def.untrimmedBoundsData.Length; ip++)
            //    {
            //        def.untrimmedBoundsData[ip] = def.untrimmedBoundsData[ip] / GameDef.PictureScale;
            //    }
            //    for (var ip = 0; ip < def.boundsData.Length; ip++)
            //    {
            //        def.boundsData[ip] = def.boundsData[ip] / GameDef.PictureScale;
            //    }
            //}
        }

        var result = DoBuildAssetBundle(DepBuildToFolder + "/Col_" + path, copySpriteColObj, needBuild);  // Build主对象, 被挖空Material了的

        GameObject.DestroyImmediate(copySpriteColObj);

        return(result.Path);
    }