Beispiel #1
0
        //パッキングする
        static void PackSub(DicingTextures target, bool rebuild)
        {
            AssetBuildTimeStamp timeStamp = null;
            string targetName             = target.name;

            if (!RebuildCheckTimeStamp(target, rebuild, out timeStamp))
            {
                //メモリリーク対策(Unity2017.4では動作を確認。5.5ではリークが残る)
                timeStamp = null;
                System.GC.Collect();
                EditorUtility.UnloadUnusedAssetsImmediate(true);
                Debug.Log(string.Format(targetName + " is not changed"));
                return;
            }
            EditorUtility.SetDirty(target);
            //使用テクスチャをロード
            Profiler.BeginSample("LoadTextures");
            List <TextureInfo> textures = LoadTextures(target);

            Profiler.EndSample();
            //アトラス情報を作成
            Profiler.BeginSample("MakeAtlas");
            List <Atlas> atlasList = MakeAtlas(target, textures, target.InputDir);

            Profiler.EndSample();
            //アトラス画像とデータを出力して、ターゲットをリビルド
            Profiler.BeginSample("RebuildTarget");
            RebuildTarget(timeStamp, target, atlasList);
            Profiler.EndSample();

            //どれくらいサイズが減ったか、計測して出力
            OutputPerformace(targetName, textures, atlasList);
        }
        public AssetBuildTimeStamp MakeBuildTimeStampAllChildren <T>() where T : UnityEngine.Object
        {
            AssetBuildTimeStamp  timeStamp = new AssetBuildTimeStamp();
            List <MainAssetInfo> list      = GetAllChildren <T>();
            List <Object>        assets    = new List <Object>();

            list.ForEach(x => assets.Add(x.Asset));
            timeStamp.MakeList(assets);
            return(timeStamp);
        }
Beispiel #3
0
 //リビルド
 public void Build(AssetBuildTimeStamp buildTimeStamp, List <Texture2D> outputTextures, List <DicingTextureData> textureDataList)
 {
     this.buildTimeStamp  = buildTimeStamp;
     this.textureDataList = textureDataList;
     this.atlasTextures   = outputTextures;
     if (buildTimeStamp == null)
     {
         Debug.LogError("buildTimeStamp is null");
     }
     else if (buildTimeStamp.InfoList.Count == 0)
     {
         Debug.LogError("buildTimeStamp is zero");
     }
     EditorUtility.SetDirty(this);
 }
        //再ビルドが必要かタイムスタンプをチェック
        static bool RebuildCheckTimeStamp(DicingTextures target, bool rebuild, out AssetBuildTimeStamp timeStamp)
        {
            MainAssetInfo dir = new MainAssetInfo(target.InputDir);

            timeStamp = dir.MakeBuildTimeStampAllChildren <Texture2D>();
            if (rebuild)
            {
                return(true);
            }
            else
            {
                //タイムスタンプが一致するなら、再ビルド必要ない
                return(!target.BuildTimeStamp.Compare(timeStamp));
            }
        }
        public bool Compare(AssetBuildTimeStamp target)
        {
            if (target.infoList.Count != infoList.Count)
            {
                return(false);
            }

            for (int i = 0; i < this.infoList.Count; i++)
            {
                if (!this.infoList[i].Compare(target.infoList[i]))
                {
                    return(false);
                }
            }
            return(true);
        }
Beispiel #6
0
        //アトラス画像とデータを出力して、インポートするターゲットをリビルド
        static void RebuildTarget(AssetBuildTimeStamp buildTimeStamp, DicingTextures target, List <Atlas> atlasList)
        {
            List <string>            outputTexturePathList = new List <string>();
            List <DicingTextureData> textureDataList       = new List <DicingTextureData>();

            //アトラス画像をファイルとして出力
            string dir   = AssetDatabase.GetAssetPath(target.OutputDir);
            int    count = 0;

            foreach (var atlas in atlasList)
            {
                ++count;
                Texture2D texture = atlas.MakeAtlasTexture();
                string    path    = FilePathUtil.Combine(dir, atlas.Name + ".png");
                outputTexturePathList.Add(path);

                atlas.Write(path, texture);
                Object.DestroyImmediate(texture);
                DisplayProgressBar(target, 0.7f + 0.2f * count / atlasList.Count, "Make AtlasTexture");

                //元テクスチャを再現するための、頂点データやアトラス画像に対するUV値を作成
                textureDataList.AddRange(atlas.MakeImportData());

                DisplayProgressBar(target, 0.7f + 0.29f * count / atlasList.Count, "Make AtlasTexture");
            }
            textureDataList.Sort((a, b) => string.Compare(a.Name, b.Name));

            //新しいテクスチャをロード
            List <Texture2D> newTextureList = new List <Texture2D>();

            foreach (var path in outputTexturePathList)
            {
                Texture2D texture = AssetDatabase.LoadAssetAtPath <Texture2D>(path);
                if (texture == null)
                {
                    AssetDatabase.ImportAsset(path);
                    texture = AssetDatabase.LoadAssetAtPath <Texture2D>(path);
                }
                newTextureList.Add(texture);
            }

            //登録済みのテクスチャのうち、使わなくなったものを削除
            List <Texture2D> removeTextureList = new List <Texture2D>();

            foreach (var texture in target.AtlasTextures)
            {
                if (!newTextureList.Contains(texture))
                {
                    removeTextureList.Add(texture);
                }
            }

            //テクスチャを設定
            target.Build(buildTimeStamp, newTextureList, textureDataList);


            //インポート設定を上書き
            foreach (var path in outputTexturePathList)
            {
                AssetDatabase.ImportAsset(path);
                OverrideAtlasTextureImportSetting(path, target);
            }

            //使わなくなったものを削除
            foreach (var texture in removeTextureList)
            {
                Debug.Log("Remove " + texture.name);
                AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(texture));
            }
        }