Example #1
0
        private void GenerateAtlasSpritePrefab(string atlasDir)
        {
            Dictionary <string, string> md5Map = new Dictionary <string, string>();

            FileInfo[] resFiles = BMEditUtility.GetAllFiles(atlasDir, "*.*");
            for (int j = 0; j < resFiles.Length; j++)
            {
                FileInfo info = resFiles[j];
                if (info.FullName.EndsWith(".meta", StringComparison.Ordinal) || info.FullName.EndsWith(".txt", StringComparison.Ordinal))
                {
                    continue;
                }

                string dirName        = Path.GetFileName(info.DirectoryName);
                string outPath        = $"{_settings.atlasSpritePrefabDir}{dirName}/";
                string spriteFileName = Path.GetFileName(info.FullName);
                string spriteName     = Path.GetFileNameWithoutExtension(info.FullName);
                string texPath        = BMEditUtility.Absolute2Relativity(info.FullName);
                string md5            = HashHelper.ComputeMD5(texPath);
                md5Map.Add(texPath, md5);
                TextureImporter ti = AssetImporter.GetAtPath(texPath) as TextureImporter;
                if (ti)
                {
                    if (!Directory.Exists(outPath))
                    {
                        Directory.CreateDirectory(outPath);
                    }
                    GameObject     spritePrefab   = new GameObject(spriteName);
                    SpriteRenderer spriteRenderer = spritePrefab.AddComponent <SpriteRenderer>();
                    Vector4        border         = ti.spriteBorder;
                    ti.spritePackingTag = "Atlas_" + dirName;
                    ti.SaveAndReimport();
                    spriteRenderer.sprite = AssetDatabase.LoadAssetAtPath <Sprite>(texPath);;
                    //spritePrefab.hideFlags = HideFlags.HideInHierarchy;
                    var savePath = outPath + spriteName + ".prefab";
                    if (File.Exists(savePath))
                    {
                        File.Delete(savePath);
                    }
                    PrefabUtility.SaveAsPrefabAsset(spritePrefab, savePath);
                    //var texture2D = AssetDatabase.LoadAssetAtPath<Texture2D>(rPath);
                    //var sprite = Sprite.Create(texture2D, new Rect(0,0,texture2D.width,texture2D.height), new Vector2(0.5f,0.5f), 400, 0,SpriteMeshType.FullRect,border);
                    DestroyImmediate(spritePrefab);
                }
            }

            //Save md5
            BMEditUtility.SaveDictionary(Path.Combine(atlasDir, "manifest.txt"), md5Map);
        }
Example #2
0
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();


            if (!string.IsNullOrEmpty(_settings.scenesVersionFile))
            {
                EditorGUILayout.Space();
                foreach (var folder in _settings.scenesFolderList)
                {
                    FileInfo[] sceneFiles = BMEditUtility.GetAllFiles(folder, _settings.scenesPattern);
                    for (int i = 0; i < sceneFiles.Length; i++)
                    {
                        string path = BMEditUtility.Absolute2Relativity(sceneFiles[i].DirectoryName) + "/" + sceneFiles[i].Name; //相对路径
                        if (_scenesVersionDict.TryGetValue(path, out string version))
                        {
                            var oldVer = version;
                            version = EditorGUILayout.TextField(path.Replace(_settings.resDir, ""), version);
                            if (version != oldVer)
                            {
                                _scenesVersionDict[path] = version;
                                BMEditUtility.SaveDictionary(_settings.scenesVersionFile, _scenesVersionDict);
                            }
                        }
                        else
                        {
                            EditorGUILayout.TextField(path.Replace(_settings.resDir, ""), "0");
                        }
                    }
                }

                if (GUILayout.Button("Save Scene Version"))
                {
                    BMEditUtility.SaveDictionary(_settings.scenesVersionFile, _scenesVersionDict);
                }
                //重制所有场景版本号
                if (GUILayout.Button("Reset All Scenes Version"))
                {
                    _scenesVersionDict = new Dictionary <string, string>();
                    BMEditUtility.SaveDictionary(_settings.scenesVersionFile, _scenesVersionDict);
//                _settings.sceneVersions = new List<int>();
//                _settings.scenePaths = new List<string>();
//                serializedObject.ApplyModifiedProperties();
//                BMEditUtility.SaveSetting(_settings);
                }
            }

            EditorGUILayout.Space();
            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("Generate Atlas Sprite"))
            {
                GenerateAtlasSprite(false);
            }
            if (GUILayout.Button("Force Generate Atlas Sprite"))
            {
                GenerateAtlasSprite(true);
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Space();
            //uiSpriteDir
            _settings.uiSpriteDir = EditorGUILayout.TextField("UI Sprite", _settings.uiSpriteDir);
            if (!string.IsNullOrEmpty(_settings.uiSpriteDir))
            {
                if (GUILayout.Button("Update All Packing Tag"))
                {
                    UpdatePackingTag(_settings.uiSpriteDir);
                }
            }
        }
Example #3
0
        static void CalcAssetBundleInfos()
        {
            for (int i = 0; i < buildInfoList.Count; i++)
            {
                BuildInfo buildInfo = buildInfoList[i];
                buildInfo.subBuildInfoMap = new Dictionary <string, SubBuildInfo>();
                for (int j = 0; j < buildInfo.assetPaths.Count; j++)
                {
                    string path    = buildInfo.assetPaths[j];
                    string dirName = Path.GetDirectoryName(path);
                    string name;
                    int    version = 0;
                    switch (buildInfo.buildType)
                    {
                    case BuildType.Pack:
                        name = BMUtility.Path2Name(dirName);
                        break;

                    case BuildType.Scene:
                        name = BMUtility.Path2Name(dirName + "/" + Path.GetFileNameWithoutExtension(path));
                        if (scenesVersionDict.TryGetValue(path, out string verStr))
                        {
                            version = int.Parse(verStr);
                        }
                        else
                        {    //新场景
                            version = 1;
                            scenesVersionDict.Add(path, version.ToString());
                            BMEditUtility.SaveDictionary(settings.scenesVersionFile, scenesVersionDict);
                        }
                        break;

                    case BuildType.Shader:
                        name = BMUtility.Path2Name(buildInfo.buildName);
                        break;

                    case BuildType.Lua:
                        name = BMUtility.Path2Name(buildInfo.buildName);
                        break;

                    default:    // BuildType.Single:
                        name = BMUtility.Path2Name(dirName + "/" + Path.GetFileName(path));
                        break;
                    }
                    string       md5     = BMUtility.EncryptWithMD5(name + "." + settings.Suffix_Bundle);
                    SubBuildInfo subInfo = null;
                    if (!buildInfo.subBuildInfoMap.TryGetValue(md5, out subInfo))
                    {
                        string abName = name;
                        if (settings.useHashName)
                        {
                            abName = md5;
                        }
                        subInfo = new SubBuildInfo()
                        {
                            bundleName       = name,
                            buildMd5         = md5,
                            buildType        = buildInfo.buildType,
                            version          = version,
                            assetBundleBuild = new AssetBundleBuild()
                            {
                                assetBundleName    = abName,
                                assetBundleVariant = settings.Suffix_Bundle,
                            },
                            assetPaths        = new List <string>(),
                            assetHashs        = new List <string>(),
                            dependenceMap     = new Dictionary <string, string[]>(),
                            dependenceHashMap = new Dictionary <string, string[]>(),
                        };
                        buildInfo.subBuildInfoMap.Add(md5, subInfo);
                    }
                    //添加依赖关系
                    AddDependence(path, subInfo.dependenceMap);
                    string hash = HashHelper.ComputeMD5(path);
                    subInfo.assetPaths.Add(path.ToLower());
                    subInfo.assetHashs.Add(hash);
                    AssetBundleBuild abb = subInfo.assetBundleBuild;
                    abb.assetNames = subInfo.assetPaths.ToArray();

                    //abb.addressableNames = subInfo.assetPaths.ToArray();
                    subInfo.assetBundleBuild = abb;
                    EditorUtility.DisplayProgressBar("Calc Asset Bundle Build Infos...", path, (float)(j + 1.0f) / (float)buildInfo.assetPaths.Count);
                }
            }
            EditorUtility.ClearProgressBar();


            Logger.Log("Calc Asset Bundle Infos Over.");
        }