示例#1
0
        private void CalcPerformance(DicingTexture dicingTexture)
        {
            calcPerformance = false;

            if (dicingTexture != null)
            {
                var assetPath = AssetDatabase.GetAssetPath(dicingTexture);
                var fullPath  = UnityPathUtility.ConvertAssetPathToFullPath(assetPath);

                var fileInfo = new FileInfo(fullPath);

                infoFileSize = (float)fileInfo.Length / MB;
            }
            else
            {
                return;
            }

            var textures = dicingTexture.GetAllDicingSource()
                           .Select(x => AssetDatabase.GUIDToAssetPath(x.guid))
                           .Select(x => AssetDatabase.LoadMainAssetAtPath(x) as Texture2D)
                           .Where(x => x != null)
                           .ToArray();

            // 消費メモリサイズを計測.
            totalMemSize = 0;
            textures.ForEach(x =>
            {
                var mem       = Mathf.NextPowerOfTwo(x.width) * Mathf.NextPowerOfTwo(x.height);
                mem          *= !x.alphaIsTransparency ? 3 : 4;
                totalMemSize += mem;
            });
            totalMemSize /= MB;

            if (dicingTexture.Texture != null)
            {
                var mem = Mathf.NextPowerOfTwo(dicingTexture.Texture.width) * Mathf.NextPowerOfTwo(dicingTexture.Texture.height);
                mem *= !dicingTexture.Texture.alphaIsTransparency ? 3 : 4;
                totalAtlasMemSize = (float)mem / MB;
            }

            // ファイルサイズ.
            totalFileSize = 0f;
            textures.Select(x => AssetDatabase.GetAssetPath(x))
            .Select(x => UnityPathUtility.ConvertAssetPathToFullPath(x))
            .Select(x => new FileInfo(x))
            .ForEach(x => totalFileSize += (float)x.Length / MB);

            if (dicingTexture.Texture != null)
            {
                var assetPath = AssetDatabase.GetAssetPath(dicingTexture.Texture);
                var fullPath  = UnityPathUtility.ConvertAssetPathToFullPath(assetPath);

                var fileInfo = new FileInfo(fullPath);

                atlasFileSize = (float)fileInfo.Length / MB;
            }

            calcPerformance = true;
        }
示例#2
0
        public static void Show(DicingTexture dicingTexture, string selection, Action <string> onSelectAction, Action onCloseAction)
        {
            if (instance != null)
            {
                instance.Close();
                instance = null;
            }

            var comp = DisplayWizard <DicingSpriteSelector>("Select DicingSprite");

            comp.onSelectAction = onSelectAction;
            comp.onCloseAction  = onCloseAction;

            comp.dicingTexture        = dicingTexture;
            comp.selectionTextureName = selection;
            comp.preViewSize          = 200f;

            comp.sourceTextures = dicingTexture.GetAllDicingSource()
                                  .Select(x =>
            {
                var path = AssetDatabase.GUIDToAssetPath(x.guid);
                return(AssetDatabase.LoadMainAssetAtPath(path) as Texture2D);
            })
                                  .Where(x => x != null)
                                  .ToArray();
        }
示例#3
0
        public string[] GetAllPatternName()
        {
            if (dicingTexture == null)
            {
                return(new string[0]);
            }

            var sourceTextures = dicingTexture.GetAllDicingSource();
            var patternNames   = sourceTextures.Select(x => x.textureName).ToArray();

            return(patternNames);
        }
示例#4
0
        public void BuildTextureInfos()
        {
            // 選択中テクスチャ.
            var selectionTextures = Selection.objects != null?
                                    Selection.objects.OfType <Texture2D>().ToArray() :
                                        new Texture2D[0];

            // パック済みのテクスチャは除外.
            if (selectDicingTexture != null)
            {
                selectionTextures = selectionTextures
                                    .Where(x => x != selectDicingTexture.Texture)
                                    .ToArray();
            }

            var allDicingSource = selectDicingTexture != null?
                                  selectDicingTexture.GetAllDicingSource() :
                                      new DicingSourceData[0];

            var textureInfoByGuid = new Dictionary <string, TextureInfo>();

            foreach (var item in allDicingSource)
            {
                if (string.IsNullOrEmpty(item.guid))
                {
                    continue;
                }

                var assetPath = AssetDatabase.GUIDToAssetPath(item.guid);
                var texture   = AssetDatabase.LoadMainAssetAtPath(assetPath) as Texture2D;

                var info = new TextureInfo();

                info.status = texture != null ? TextureStatus.Exist : TextureStatus.Missing;

                if (info.status == TextureStatus.Exist)
                {
                    var fullPath   = UnityPathUtility.ConvertAssetPathToFullPath(assetPath);
                    var lastUpdate = File.GetLastWriteTime(fullPath).ToUnixTime();

                    if (item.lastUpdate != lastUpdate)
                    {
                        info.status = TextureStatus.Update;
                    }

                    info.texture = texture;
                }

                textureInfoByGuid.Add(item.guid, info);
            }

            foreach (var texture in selectionTextures)
            {
                var assetPath = AssetDatabase.GetAssetPath(texture);
                var guid      = AssetDatabase.AssetPathToGUID(assetPath);

                var info = textureInfoByGuid.GetValueOrDefault(guid);

                if (info == null)
                {
                    info = new TextureInfo()
                    {
                        status  = TextureStatus.Add,
                        texture = texture,
                    };

                    textureInfoByGuid.Add(guid, info);
                }
                else
                {
                    textureInfoByGuid[guid].status = TextureStatus.Update;
                }
            }

            textureInfos = textureInfoByGuid.Values.ToArray();

            CalcPerformance(selectDicingTexture);

            Repaint();
        }