コード例 #1
0
 private static void ProcessSpecialResource(string path)
 {
     if (m_specialCache.ContainsKey(path))
     {
         return;
     }
     m_specialCache.Add(path, path);
     if (EditorPath.IsShader(path))
     {
         if (!BundleDataManager.CheckPathInBundle(path))
         {
             BundleData shader = BundleDataManager.GetBundleData(BundleName.BN_SHADER);
             if (shader != null && shader.children.Count > 0)
             {
                 BundleDataManager.AddPathToBundle(path, shader.children[0], 1024);
             }
         }
     }
     else if (EditorPath.IsMaterial(path))
     {
         BundleData shaderBundle = BundleDataManager.GetBundleData(BundleName.BN_SHADER);
         if (shaderBundle == null)
         {
             return;
         }
         UnityEngine.Object[] assetAtPath = AssetDatabase.LoadAllAssetsAtPath(path);
         foreach (var obj in assetAtPath)
         {
             if (obj != null && obj.GetType() == typeof(Material))
             {
                 Material mat = obj as Material;
                 if (mat != null && mat.shader != null && !string.IsNullOrEmpty(mat.shader.name))
                 {
                     if (!shaderBundle.includs.Contains(mat.shader.name))
                     {
                         shaderBundle.includs.Add(mat.shader.name);
                     }
                 }
             }
             if ((!(obj is GameObject)) && (!(obj is Component)))
             {
                 Resources.UnloadAsset(obj);
             }
         }
         ProcessClear();
     }
     else if (EditorPath.IsScript(path))
     {
         BundleData script = BundleDataManager.GetBundleData(BundleName.BN_SCRIPT);
         if (script != null && script.children.Count > 0)
         {
             BundleDataManager.AddPathToBundle(path, script.children[0], 1024);
         }
     }
 }
コード例 #2
0
        public static ShaderInfo CreateShaderInfo(string assetPath)
        {
            if (!EditorPath.IsShader(assetPath))
            {
                return(null);
            }

            ShaderInfo shaderInfo = null;

            if (!_dictShaderInfo.TryGetValue(assetPath, out shaderInfo))
            {
                shaderInfo = new ShaderInfo();
                _dictShaderInfo.Add(assetPath, shaderInfo);
            }
            Shader shader     = AssetDatabase.LoadAssetAtPath <Shader>(assetPath);
            string shaderText = File.ReadAllText(assetPath);

            //ShaderUtil.OpenCompiledShader(shader, (int)ShaderPlatformModes.Custom, 1 << (int)ShaderUtil.ShaderCompilerPlatformType.D3D11, false);

            typeof(ShaderUtil).GetMethod("OpenCompiledShader", BindingFlags.Static | BindingFlags.NonPublic).Invoke(null, new object[] { shader, (int)ShaderPlatformModes.Custom, 1 << (int)ShaderCompilerPlatformType.D3D11, false });
            try
            {
                CompiledShaderInfo compiledShaderInfo = CompiledShaderInfo.CreateCompiledShaderInfo(shaderText);
                shaderInfo.Path = assetPath;
                //shaderInfo.MaxLOD = ShaderUtil.GetLOD(shader);
                //shaderInfo.Variant = ShaderUtil.GetVariantCount(shader, true);
                shaderInfo.Property    = ShaderUtil.GetPropertyCount(shader);
                shaderInfo.RenderQueue = shader.renderQueue;
                shaderInfo.Pass        = compiledShaderInfo.GetPass();
                shaderInfo.Instruction = compiledShaderInfo.GetInstruction();
                shaderInfo.SubShader   = compiledShaderInfo.GetSubShaderCount();
                shaderInfo.Sample      = compiledShaderInfo.GetSample();
                shaderInfo.RenderType  = compiledShaderInfo.GetRenderType();
                shaderInfo.CompiledShaderInfoList.Add(compiledShaderInfo);
            }
            catch (Exception ex)
            {
                Debug.LogError(ex.Message);
                return(null);
            }
            return(shaderInfo);
        }
コード例 #3
0
        public static void ExportBundleDictToOutput()
        {
            EditorTool.CreateDirectory(BuildConfig.InterpretedOutputPath);

            BundleDataControl dataControl    = BundleDataControl.Instance;
            BundleMainfest    bundleMainfest = new BundleMainfest();

            BundleData[] bundleData = BundleDataAccessor.Datas.ToArray();

            Dictionary <string, string> dict = new Dictionary <string, string>();

            for (int i = 0; i < bundleData.Length; ++i)
            {
                for (int j = 0; j < bundleData[i].includs.Count; ++j)
                {
                    string path = bundleData[i].includs[j];
                    if (string.IsNullOrEmpty(path))
                    {
                        continue;
                    }

                    if (!dict.ContainsKey(path))
                    {
                        dict.Add(path, bundleData[i].name);
                    }
                    else
                    {
                        Debug.LogWarningFormat("[BundleExport] Path to bundle name have same path {0} : {1} _ {2}", path, bundleData[i].name, dict[path]);
                    }

                    BundleImportData data = dataControl.GetPathImportData(path);
                    if (data == null || !data.Publish || !path.StartsWith("Assets", StringComparison.OrdinalIgnoreCase))
                    {
                        continue;
                    }

                    string bundlePath = path; // format path to load path!!!
                    bundleMainfest.AddPathToBundle(bundlePath, bundleData[i].name);
                }
            }

            for (int i = 0; i < bundleData.Length; ++i)
            {
                for (int j = 0; j < bundleData[i].includs.Count; ++j)
                {
                    string[] dep = AssetDepot.GetDependenciesCache(bundleData[i].includs[j]);
                    for (int k = 0; k < dep.Length; ++k)
                    {
                        if (EditorPath.IsScript(dep[k]) || EditorPath.IsShader(dep[k]))
                        {
                            continue;
                        }

                        string bundleName = null;
                        dict.TryGetValue(EditorPath.NormalizePathSplash(dep[k]), out bundleName);
                        if (string.IsNullOrEmpty(bundleName) || bundleName == bundleData[i].name)
                        {
                            continue;
                        }

                        BundleState childBuildState = BundleDataManager.GetBundleState(bundleName);
                        if (childBuildState.loadState == BundleLoadState.Preload || childBuildState.size == -1)
                        {
                            continue;
                        }

                        bundleMainfest.AddBundleDepend(bundleData[i].name, bundleName);
                    }
                }
            }

            List <BundleState> stateList = new List <BundleState>(BundleDataAccessor.States);

            bundleMainfest.AddBundleState(stateList);

            bundleMainfest.SaveBytes(BuildConfig.BundleMainfestOutputPath);

            AssetDatabase.ImportAsset(BuildConfig.BundleMainfestOutputPath, ImportAssetOptions.ForceSynchronousImport);
        }