RegisterFont() 공개 정적인 메소드

public static RegisterFont ( BaseFont font, string alias ) : void
font BaseFont
alias string
리턴 void
예제 #1
0
		void LoadPackage()
		{
			string[] arr = null;
			string str;

			str = LoadString("sprites.bytes");
			if (str == null)
			{
				Debug.LogError("FairyGUI: cannot load package from '" + _assetNamePrefix + "'");
				return;
			}

			_loadingPackage = true;

			arr = str.Split('\n');
			int cnt = arr.Length;
			for (int i = 1; i < cnt; i++)
			{
				str = arr[i];
				if (str.Length == 0)
					continue;

				string[] arr2 = str.Split(' ');
				AtlasSprite sprite = new AtlasSprite();
				string itemId = arr2[0];
				int binIndex = int.Parse(arr2[1]);
				if (binIndex >= 0)
					sprite.atlas = "atlas" + binIndex;
				else
				{
					int pos = itemId.IndexOf("_");
					if (pos == -1)
						sprite.atlas = "atlas_" + itemId;
					else
						sprite.atlas = "atlas_" + itemId.Substring(0, pos);
				}
				sprite.rect.x = int.Parse(arr2[2]);
				sprite.rect.y = int.Parse(arr2[3]);
				sprite.rect.width = int.Parse(arr2[4]);
				sprite.rect.height = int.Parse(arr2[5]);
				sprite.rotated = arr2[6] == "1";
				_sprites[itemId] = sprite;
			}

			byte[] hittestData = LoadBinary("hittest.bytes");
			if (hittestData != null)
			{
				ByteBuffer ba = new ByteBuffer(hittestData);
				while (ba.bytesAvailable)
				{
					PixelHitTestData pht = new PixelHitTestData();
					_hitTestDatas[ba.ReadString()] = pht;
					pht.Load(ba);
				}
			}

			if (!_descPack.TryGetValue("package.xml", out str))
				throw new Exception("FairyGUI: invalid package '" + _assetNamePrefix + "'");

			XML xml = new XML(str);

			id = xml.GetAttribute("id");
			name = xml.GetAttribute("name");

			XML rxml = xml.GetNode("resources");
			if (rxml == null)
				throw new Exception("FairyGUI: invalid package xml '" + _assetNamePrefix + "'");

			XMLList resources = rxml.Elements();

			_itemsById = new Dictionary<string, PackageItem>();
			_itemsByName = new Dictionary<string, PackageItem>();
			PackageItem pi;

			foreach (XML cxml in resources)
			{
				pi = new PackageItem();
				pi.owner = this;
				pi.type = FieldTypes.ParsePackageItemType(cxml.name);
				pi.id = cxml.GetAttribute("id");
				pi.name = cxml.GetAttribute("name");
				pi.exported = cxml.GetAttributeBool("exported");
				pi.file = cxml.GetAttribute("file");
				str = cxml.GetAttribute("size");
				if (str != null)
				{
					arr = str.Split(',');
					pi.width = int.Parse(arr[0]);
					pi.height = int.Parse(arr[1]);
				}
				switch (pi.type)
				{
					case PackageItemType.Image:
						{
							string scale = cxml.GetAttribute("scale");
							if (scale == "9grid")
							{
								arr = cxml.GetAttributeArray("scale9grid");
								if (arr != null)
								{
									Rect rect = new Rect();
									rect.x = int.Parse(arr[0]);
									rect.y = int.Parse(arr[1]);
									rect.width = int.Parse(arr[2]);
									rect.height = int.Parse(arr[3]);
									pi.scale9Grid = rect;

									pi.tileGridIndice = cxml.GetAttributeInt("gridTile");
								}
							}
							else if (scale == "tile")
								pi.scaleByTile = true;
							break;
						}

					case PackageItemType.Font:
						{
							pi.bitmapFont = new BitmapFont(pi);
							FontManager.RegisterFont(pi.bitmapFont, null);
							break;
						}
				}
				_items.Add(pi);
				_itemsById[pi.id] = pi;
				if (pi.name != null)
					_itemsByName[pi.name] = pi;
			}

			bool preloadAll = Application.isPlaying;
			if (preloadAll)
			{
				cnt = _items.Count;
				for (int i = 0; i < cnt; i++)
					GetItemAsset(_items[i]);

				_descPack = null;
				_sprites = null;
			}
			else
				_items.Sort(ComparePackageItem);

			if (_resBundle != null)
			{
				_resBundle.Unload(false);
				_resBundle = null;
			}

			_loadingPackage = false;
		}
예제 #2
0
        void LoadPackage()
        {
            string str = this.LoadString("sprites.bytes");

            string[] arr = str.Split(sep1);
            int      cnt = arr.Length;

            for (int i = 1; i < cnt; i++)
            {
                str = arr[i];
                if (str.Length == 0)
                {
                    continue;
                }

                string[]    arr2     = str.Split(sep2);
                AtlasSprite sprite   = new AtlasSprite();
                string      itemId   = arr2[0];
                int         binIndex = int.Parse(arr2[1]);
                if (binIndex >= 0)
                {
                    sprite.atlas = "atlas" + binIndex;
                }
                else
                {
                    int pos = itemId.IndexOf("_");
                    if (pos == -1)
                    {
                        sprite.atlas = "atlas_" + itemId;
                    }
                    else
                    {
                        sprite.atlas = "atlas_" + itemId.Substring(0, pos);
                    }
                }
                sprite.rect.x      = int.Parse(arr2[2]);
                sprite.rect.y      = int.Parse(arr2[3]);
                sprite.rect.width  = int.Parse(arr2[4]);
                sprite.rect.height = int.Parse(arr2[5]);
                sprite.rotated     = arr2[6] == "1";
                _sprites[itemId]   = sprite;
            }

            str = GetDesc("package.xml");
            XML xml = new XML(str);

            id   = xml.GetAttribute("id");
            name = xml.GetAttribute("name");

            XML rxml = xml.GetNode("resources");

            if (rxml == null)
            {
                throw new Exception("Invalid package xml");
            }

            XMLList resources = rxml.Elements();

            _itemsById   = new Dictionary <string, PackageItem>();
            _itemsByName = new Dictionary <string, PackageItem>();
            PackageItem pi;

            foreach (XML cxml in resources)
            {
                pi      = new PackageItem();
                pi.type = FieldTypes.ParsePackageItemType(cxml.name);
                pi.id   = cxml.GetAttribute("id");
                pi.name = cxml.GetAttribute("name");
                pi.file = cxml.GetAttribute("file");
                str     = cxml.GetAttribute("size");
                if (str != null)
                {
                    arr       = str.Split(sep0);
                    pi.width  = int.Parse(arr[0]);
                    pi.height = int.Parse(arr[1]);
                }
                switch (pi.type)
                {
                case PackageItemType.Image:
                {
                    string scale = cxml.GetAttribute("scale");
                    if (scale == "9grid")
                    {
                        arr = cxml.GetAttributeArray("scale9grid");
                        if (arr != null)
                        {
                            Rect rect = new Rect();
                            rect.x        = int.Parse(arr[0]);
                            rect.y        = int.Parse(arr[1]);
                            rect.width    = int.Parse(arr[2]);
                            rect.height   = int.Parse(arr[3]);
                            pi.scale9Grid = rect;
                        }
                    }
                    else if (scale == "tile")
                    {
                        pi.scaleByTile = true;
                    }
                    break;
                }
                }
                pi.owner = this;
                _items.Add(pi);
                _itemsById[pi.id] = pi;
                if (pi.name != null)
                {
                    _itemsByName[pi.name] = pi;
                }
            }

            cnt = _items.Count;
            for (int i = 0; i < cnt; i++)
            {
                pi = _items[i];
                if (pi.type == PackageItemType.Font)
                {
                    pi.Load();
                    FontManager.RegisterFont(pi.bitmapFont, null);
                }
                else
                {
                    GetItemAsset(pi);
                }
            }

            if (_resBundle != null)
            {
                _resBundle.Unload(false);
                _resBundle = null;
            }
        }