FairyGUI.FieldTypes.ParsePackageItemType C# (CSharp) Method

ParsePackageItemType() public static method

public static ParsePackageItemType ( string value ) : PackageItemType
value string
return PackageItemType
        public static PackageItemType ParsePackageItemType(string value)
        {
            switch (value)
            {
                case "image":
                    return PackageItemType.Image;
                case "movieclip":
                    return PackageItemType.MovieClip;
                case "component":
                    return PackageItemType.Component;
                case "atlas":
                    return PackageItemType.Atlas;
                case "sound":
                    return PackageItemType.Sound;
                case "font":
                    return PackageItemType.Font;
                case "misc":
                    return PackageItemType.Misc;
                default:
                    return PackageItemType.Misc;
            }
        }

Usage Example

Example #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;
		}
All Usage Examples Of FairyGUI.FieldTypes::ParsePackageItemType