예제 #1
0
        private static List <UISpriteData> GetSprites()
        {
            var gameObject = GameObject.Find("/NGUI Root (2D)/ItemIconAtlas");

            if (gameObject == null)
            {
                SendOutput("Atlas object not found");

                return(null);
            }

            var component = gameObject.GetComponent <DynamicUIAtlas>();

            if (component == null)
            {
                SendOutput("Atlas component not found");

                return(null);
            }

            var prebakedAtlas = component.PrebakedAtlas;

            if (!DynamicUIAtlasTools.ReadPrebakedAtlasDescriptor(prebakedAtlas, out var sprites, out int _, out int _))
            {
                SendOutput("Could not read dynamic atlas descriptor");

                return(null);
            }

            if (!DynamicUIAtlasTools.ReadPrebakedAtlasTexture(prebakedAtlas, out var texture2D))
            {
                SendOutput("Could not read dynamic atlas texture");

                return(null);
            }

            Resources.UnloadAsset(texture2D);

            return(sprites);
        }
예제 #2
0
        private static List <string> GetSprites(out int bakedCount)
        {
            //Vanilla
            bakedCount = 0;
            var gameObject = GameObject.Find("/NGUI Root (2D)/ItemIconAtlas");

            if (gameObject == null)
            {
                SendOutput("Atlas object not found");

                return(null);
            }

            var component = gameObject.GetComponent <DynamicUIAtlas>();

            if (component == null)
            {
                SendOutput("Atlas component not found");

                return(null);
            }

            var prebakedAtlas = component.PrebakedAtlas;

            if (!DynamicUIAtlasTools.ReadPrebakedAtlasDescriptor(prebakedAtlas, out var sprites, out var iconWidth, out var iconHeight))
            {
                SendOutput("Could not read dynamic atlas descriptor");

                return(null);
            }

            var list = sprites.Select(s => s.name).ToList();

            bakedCount = list.Count;

            //Mod Icons
            foreach (var mod in ModManager.GetLoadedMods())
            {
                var modIconsPath = mod.Path + "/ItemIcons";
                if (!Directory.Exists(modIconsPath))
                {
                    continue;
                }

                foreach (var file in Directory.GetFiles(modIconsPath))
                {
                    if (!file.ToLower().EndsWith(".png"))
                    {
                        continue;
                    }

                    var name = Path.GetFileNameWithoutExtension(file);
                    if (list.Contains(name))
                    {
                        continue;
                    }

                    var tex = new Texture2D(1, 1, TextureFormat.ARGB32, false);
                    if (!tex.LoadImage(File.ReadAllBytes(file)))
                    {
                        continue;
                    }

                    if (tex.width == iconWidth && tex.height == iconHeight)
                    {
                        list.Add(name);
                    }

                    Object.Destroy(tex);
                }
            }

            return(list);
        }