Example #1
0
 /// <summary>
 /// 提示UI
 /// </summary>
 void TipsGUI()
 {
     GUILayout.Label("2.资源打包", EditorGUIHelper.TitleStyle);
     GUILayout.Space(5);
     GUILayout.Label("资源根目录:");
     foreach (var root in  BApplication.GetAllRuntimeDirects())
     {
         GUILayout.Label(root);
     }
     GUILayout.Label(string.Format("AB输出目录:{0}", exportPath));
     options = (BuildAssetBundleOptions)EditorGUILayout.EnumPopup("压缩格式:", options);
 }
        /// <summary>
        /// 提示UI
        /// </summary>
        void TipsGUI()
        {
            GUILayout.Label("2.资源打包", EditorGUIHelper.LabelH2);
            GUILayout.Space(5);
            GUILayout.Label("Runtime目录:");
            foreach (var root in BApplication.GetAllRuntimeDirects())
            {
                GUILayout.Label(root);
            }

            GUILayout.Space(3);
            GUILayout.Label("AssetBundle输出目录:DevOps");
            //
            //assetConfig.AESCode = EditorGUILayout.TextField("AES密钥(V2 only):", assetConfig.AESCode);
            //assetConfig.IsUseHashName = EditorGUILayout.Toggle("hash命名:", assetConfig.IsUseHashName);
        }
Example #3
0
        /// <summary>
        /// 收集图集信息
        /// </summary>
        static private void GetSpriteAtlasInfo()
        {
            atlasMap            = new Dictionary <string, List <string> >();
            textureExtensionSet = new HashSet <string>();
            //
            var path   = BApplication.GetAllRuntimeDirects().ToArray();
            var assets = AssetDatabase.FindAssets("t:spriteatlas", path).ToList();

            //GUID to assetPath
            for (int i = 0; i < assets.Count; i++)
            {
                var p = AssetDatabase.GUIDToAssetPath(assets[i]).ToLower();
                //获取依赖中的textrue
                var dps = GetDependencies(p).ToList();
                atlasMap[p] = dps;
                for (int j = 0; j < dps.Count; j++)
                {
                    textureExtensionSet.Add(Path.GetExtension(dps[j]));
                }
            }
        }
Example #4
0
        /// <summary>
        ///  获取runtime下的资源
        /// </summary>
        /// <returns></returns>
        public List <string> GetRuntimeAssetsPath()
        {
            var       allRuntimeDirects    = BApplication.GetAllRuntimeDirects();
            var       runtimeAssetPathList = new List <string>();
            Stopwatch sw = new Stopwatch();

            sw.Start();
            //寻找所有Runtime的资产
            var runtimeGuids = AssetDatabase.FindAssets("", allRuntimeDirects.ToArray()).Distinct().ToList();

            foreach (var guid in runtimeGuids)
            {
                var path = AssetDatabase.GUIDToAssetPath(guid).ToLower();
                path = IPath.ReplaceBackSlash(path);
                runtimeAssetPathList.Add(path);
            }

            runtimeAssetPathList = CheckAssetsPath(runtimeAssetPathList.ToArray());
            sw.Stop();
            Debug.Log($"GetRuntimeAssetsInfo耗时:{sw.ElapsedMilliseconds}ms");
            return(runtimeAssetPathList);
        }
        /// <summary>
        /// 加载runtime的Asset信息
        /// </summary>
        /// <returns></returns>
        public List <AssetReference> GetRuntimeAssetsInfo()
        {
            var       allRuntimeDirects = BApplication.GetAllRuntimeDirects();
            var       assetPathList     = new List <string>();
            var       retAssetList      = new List <AssetReference>();
            Stopwatch sw = new Stopwatch();

            sw.Start();
            foreach (var runtimePath in allRuntimeDirects)
            {
                //创建
                var runtimeGuids = AssetDatabase.FindAssets("", new string[] { runtimePath });
                assetPathList.AddRange(runtimeGuids);
            }

            //去重
            assetPathList = assetPathList.Distinct().Select((guid) => AssetDatabase.GUIDToAssetPath(guid)).ToList();
            assetPathList = CheckAssetsPath(assetPathList.ToArray());
            //
            foreach (var path in assetPathList)
            {
                //var path = AssetDatabase.GUIDToAssetPath(guid);
                //无法获取类型资源,移除
                var type = AssetDatabase.GetMainAssetTypeAtPath(path);
                if (type == null)
                {
                    Debug.LogError("【Loder】无法获取资源类型:" + path);
                    continue;
                }

                var outAR = AssetReference.CreateReference(path);
                //添加输出
                retAssetList.Add(outAR);
            }

            Debug.LogFormat("LoadAllRuntimeAssets耗时:{0}ms", sw.ElapsedMilliseconds);
            return(retAssetList);
        }
Example #6
0
        /// <summary>
        /// 简单收集
        /// </summary>
        public static void CollectShaderVariant()
        {
            //先搜集所有keyword到工具类SVC
            ToolSVC = new ShaderVariantCollection();
            var shaders = AssetDatabase.FindAssets("t:Shader", new string[] { "Assets", "Packages" }).ToList();

            foreach (var shader in shaders)
            {
                ShaderVariantCollection.ShaderVariant sv = new ShaderVariantCollection.ShaderVariant();
                var shaderPath = AssetDatabase.GUIDToAssetPath(shader);
                sv.shader = AssetDatabase.LoadAssetAtPath <Shader>(shaderPath);
                ToolSVC.Add(sv);
                //
                allShaderNameList.Add(shaderPath);
            }


            //防空
            var dirt = Path.GetDirectoryName(toolsSVCpath);

            if (!Directory.Exists(dirt))
            {
                Directory.CreateDirectory(dirt);
            }

            AssetDatabase.CreateAsset(ToolSVC, toolsSVCpath);


            var paths = BApplication.GetAllRuntimeDirects().ToArray();
            //搜索所有runtime中所有可能挂载mat的地方
            var scriptObjectAssets = AssetDatabase.FindAssets("t:ScriptableObject", paths).ToList(); //自定义序列化脚本中也有可能有依赖
            var prefabAssets       = AssetDatabase.FindAssets("t:Prefab", paths).ToList();
            var matAssets          = AssetDatabase.FindAssets("t:Material", paths).ToList();


            //ERROR: 添加runtime中独立的shader,没有mat 视为其没有Shader_Featrue变体
            var shadertAssets = AssetDatabase.FindAssets("t:Shader", paths); //自定义序列化脚本中也有可能有依赖

            foreach (var guid in shadertAssets)
            {
                var path = AssetDatabase.GUIDToAssetPath(guid);
                Debug.LogError("不建议将shader放在runtime中,没有mat信息 无法搜集变体! " + path);
            }

            //搜索mat
            var guidList = new List <string>();

            guidList.AddRange(prefabAssets);
            guidList.AddRange(matAssets);
            guidList.AddRange(scriptObjectAssets);
            List <string> allMatPaths = new List <string>();

            //GUID to assetPath
            for (int i = 0; i < guidList.Count; i++)
            {
                var path = AssetDatabase.GUIDToAssetPath(guidList[i]);
                //获取依赖中的mat
                var dependenciesPath = AssetDatabase.GetDependencies(path, true);
                foreach (var dp in dependenciesPath)
                {
                    if (Path.GetExtension(dp).Equals(".mat", StringComparison.OrdinalIgnoreCase))
                    {
                        allMatPaths.Add(dp);
                    }
                    else if (Path.GetExtension(dp).Equals(".asset", StringComparison.OrdinalIgnoreCase)) //依赖的ScripttableObject,会
                    {
                        scriptObjectAssets.Add(AssetDatabase.AssetPathToGUID(dp));
                    }
                }
            }

            //ScripttableObject 里面有可能存mat信息
            foreach (var asset in scriptObjectAssets)
            {
                var path = AssetDatabase.GUIDToAssetPath(asset);
                var mat  = AssetDatabase.LoadAssetAtPath <Material>(path);
                if (mat != null)
                {
                    allMatPaths.Add(path);
                }
            }

            //开始收集ShaderVaraint
            allMatPaths = allMatPaths.Distinct().ToList();
            ShaderVariantCollection allShaderVaraint = null;
            var tools = new ShaderVariantsCollectionTools();

            allShaderVaraint = tools.CollectionKeywords(allMatPaths.ToArray(), ToolSVC);


            //输出SVC文件
            var targetDir = Path.GetDirectoryName(BResources.ALL_SHADER_VARAINT_ASSET_PATH);

            if (!Directory.Exists(targetDir))
            {
                Directory.CreateDirectory(targetDir);
            }

            AssetDatabase.DeleteAsset(BResources.ALL_SHADER_VARAINT_ASSET_PATH);
            AssetDatabase.CreateAsset(allShaderVaraint, BResources.ALL_SHADER_VARAINT_ASSET_PATH);
            AssetDatabase.Refresh();

            Debug.Log("<color=red>shader_features收集完毕,multi_compiles默认全打包需要继承IPreprocessShaders.OnProcessShader自行剔除!</color>");
            // var dependencies = AssetDatabase.GetDependencies(BResources.ALL_SHADER_VARAINT_ASSET_PATH);
            // foreach (var guid in dependencies )
            // {
            //     Debug.Log("依赖shader:" + guid);
            // }
        }
Example #7
0
 /// <summary>
 /// 初始化
 /// </summary>
 /// <param name="rootPath"></param>
 public void Init(string rootPath)
 {
     allRuntimeDirectList = BApplication.GetAllRuntimeDirects();
 }
Example #8
0
 /// <summary>
 /// 初始化
 /// </summary>
 /// <param name="path"></param>
 /// <param name="onInitEnd"></param>
 public void Init(string path, Action onInitEnd)
 {
     allRuntimeDirectList = BApplication.GetAllRuntimeDirects();
     //
     onInitEnd?.Invoke();
 }
Example #9
0
 /// <summary>
 /// 初始化
 /// </summary>
 /// <param name="rootPath"></param>
 public void Init(string rootPath, RuntimePlatform platform)
 {
     allRuntimeDirectList = BApplication.GetAllRuntimeDirects();
 }
        /// <summary>
        /// 简单收集
        /// </summary>
        public static void CollectShaderVariant()
        {
            //先搜集所有keyword到工具类SVC
            ToolSVC = new ShaderVariantCollection();
            var shaders = AssetDatabase.FindAssets("t:Shader", new string[] { "Assets", "Packages" }).ToList();

            foreach (var shader in shaders)
            {
                ShaderVariantCollection.ShaderVariant sv = new ShaderVariantCollection.ShaderVariant();
                var shaderPath = AssetDatabase.GUIDToAssetPath(shader);
                sv.shader = AssetDatabase.LoadAssetAtPath <Shader>(shaderPath);
                ToolSVC.Add(sv);
                //
                allShaderNameList.Add(shaderPath);
            }


            //防空
            var dirt = Path.GetDirectoryName(toolsSVCpath);

            if (!Directory.Exists(dirt))
            {
                Directory.CreateDirectory(dirt);
            }

            AssetDatabase.CreateAsset(ToolSVC, toolsSVCpath);


            //搜索所有Mat
            var paths   = BApplication.GetAllRuntimeDirects().ToArray();
            var assets  = AssetDatabase.FindAssets("t:Prefab", paths).ToList();
            var assets2 = AssetDatabase.FindAssets("t:Material", paths);

            assets.AddRange(assets2);
            List <string> allMatPaths = new List <string>();

            //GUID to assetPath
            for (int i = 0; i < assets.Count; i++)
            {
                var path = AssetDatabase.GUIDToAssetPath(assets[i]);
                //获取依赖中的mat
                var dependenciesPath = AssetDatabase.GetDependencies(path, true);
                var mats             = dependenciesPath.ToList().FindAll((dp) => AssetDatabase.GetMainAssetTypeAtPath(dp) == typeof(Material));
                allMatPaths.AddRange(mats);
            }

            allMatPaths = allMatPaths.Distinct().ToList();
            ShaderVariantCollection allShaderVaraint = null;

            //收集ShaderVaraint
            var tools = new ShaderVariantsCollectionTools();

            allShaderVaraint = tools.CollectionKeywords(allMatPaths.ToArray(), ToolSVC);



            var targetDir = Path.GetDirectoryName(BResources.ALL_SHADER_VARAINT_ASSET_PATH);

            if (!Directory.Exists(targetDir))
            {
                Directory.CreateDirectory(targetDir);
            }

            AssetDatabase.DeleteAsset(BResources.ALL_SHADER_VARAINT_ASSET_PATH);
            AssetDatabase.CreateAsset(allShaderVaraint, BResources.ALL_SHADER_VARAINT_ASSET_PATH);
            AssetDatabase.Refresh();

            // var dependencies = AssetDatabase.GetDependencies(BResources.ALL_SHADER_VARAINT_ASSET_PATH);
            // foreach (var guid in dependencies )
            // {
            //     Debug.Log("依赖shader:" + guid);
            // }
        }