GObject CreateObject(PackageItem item, System.Type userClass) { Stats.LatestObjectCreation = 0; Stats.LatestGraphicsCreation = 0; GetItemAsset(item); GObject g = null; if (item.type == PackageItemType.Component) { if (userClass != null) g = (GComponent)userClass.Assembly.CreateInstance(userClass.FullName); else g = UIObjectFactory.NewObject(item); } else g = UIObjectFactory.NewObject(item); if (g == null) return null; _constructing++; g.packageItem = item; g.ConstructFromResource(); _constructing--; return g; }
public MyDragDropManager() { _agent = (GComponent)UIObjectFactory.NewObject("component"); _agent.gameObjectName = "MyDragDropAgent"; _agent.SetHome(GRoot.inst); _agent.touchable = false;//important _agent.draggable = true; //_agent.SetSize(100, 100); _agent.sortingOrder = int.MaxValue; _agent.onDragEnd.Add(__dragEnd); loader_a = (GLoader)UIObjectFactory.NewObject("loader"); loader_a.SetPivot(0.5f, 0.5f, true); loader_a.align = AlignType.Center; loader_a.verticalAlign = VertAlignType.Middle; loader_b = (GLoader)UIObjectFactory.NewObject("loader"); loader_b.SetPivot(0.5f, 0.5f, true); loader_b.align = AlignType.Center; loader_b.verticalAlign = VertAlignType.Middle; _agent.AddChild(loader_a); _agent.AddChild(loader_b); }
internal GObject CreateObject(PackageItem item, Type userClass) { GObject g; if (item.type == PackageItemType.Component) { if (userClass != null) { g = (GComponent)userClass.Assembly.CreateInstance(userClass.FullName); } else { g = UIObjectFactory.NewObject(item); } } else { g = UIObjectFactory.NewObject(item); } if (g == null) { return(null); } _constructing++; g.ConstructFromResource(item); _constructing--; return(g); }
/// <summary> /// /// </summary> /// <param name="url"></param> /// <param name="luaClass"></param> public static void SetExtension(string url, System.Type baseType, LuaFunction extendFunction) { UIObjectFactory.SetPackageItemExtension(url, () => { GComponent gcom = (GComponent)Activator.CreateInstance(baseType); gcom.data = extendFunction; return(gcom); }); }
public DragDropManager() { _agent = (GLoader)UIObjectFactory.NewObject("loader"); _agent.touchable = false; //important _agent.draggable = true; _agent.SetSize(100, 100); _agent.align = AlignType.Center; _agent.verticalAlign = VertAlignType.Middle; _agent.sortingOrder = int.MaxValue; _agent.onDragEnd.Add(__dragEnd); }
static public int constructor(IntPtr l) { try { FairyGUI.UIObjectFactory o; o = new FairyGUI.UIObjectFactory(); pushValue(l, true); pushValue(l, o); return(2); } catch (Exception e) { return(error(l, e)); } }
public DragDropManager() { _agent = (GLoader)UIObjectFactory.NewObject(ObjectType.Loader); _agent.gameObjectName = "DragDropAgent"; _agent.SetHome(GRoot.inst); _agent.touchable = false;//important _agent.draggable = true; _agent.SetSize(100, 100); _agent.SetPivot(0.5f, 0.5f, true); _agent.align = AlignType.Center; _agent.verticalAlign = VertAlignType.Middle; _agent.sortingOrder = int.MaxValue; _agent.onDragEnd.Add(__dragEnd); }
private GObject ConstructChild(XML xml) { string pkgId = xml.GetAttribute("pkg"); UIPackage thisPkg = _packageItem.owner; UIPackage pkg; if (pkgId != null && pkgId != thisPkg.id) { pkg = UIPackage.GetById(pkgId); if (pkg == null) { return(null); } } else { pkg = thisPkg; } string src = xml.GetAttribute("src"); if (src != null) { PackageItem pi = pkg.GetItem(src); if (pi == null) { return(null); } GObject g = pkg.CreateObject(pi, null); return(g); } else { GObject g; if (xml.name == "text" && xml.GetAttributeBool("input", false)) { g = new GTextInput(); } else { g = UIObjectFactory.NewObject(xml.name); } return(g); } }
internal GObject CreateObject(PackageItem item, System.Type userClass) { GObject g = null; if (item.type == PackageItemType.Component) { if (userClass != null) g = (GComponent)userClass.Assembly.CreateInstance(userClass.FullName); else g = UIObjectFactory.NewObject(item); } else g = UIObjectFactory.NewObject(item); if (g == null) return null; _constructing++; g.ConstructFromResource(item); _constructing--; return g; }
static int _CreateFairyGUI_UIObjectFactory(IntPtr L) { try { int count = LuaDLL.lua_gettop(L); if (count == 0) { FairyGUI.UIObjectFactory obj = new FairyGUI.UIObjectFactory(); ToLua.PushObject(L, obj); return(1); } else { return(LuaDLL.luaL_throw(L, "invalid arguments to ctor method: FairyGUI.UIObjectFactory.New")); } } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
GObject CreateObject(PackageItem item, System.Type userClass) { Stats.LatestObjectCreation = 0; Stats.LatestGraphicsCreation = 0; GetItemAsset(item); GObject g = null; if (item.type == PackageItemType.Component) { if (userClass != null) { g = (GComponent)Activator.CreateInstance(userClass); } else { g = UIObjectFactory.NewObject(item); } } else { g = UIObjectFactory.NewObject(item); } if (g == null) { return(null); } _constructing++; g.packageItem = item; g.ConstructFromResource(); _constructing--; return(g); }
internal void ConstructFromResource(List <GObject> objectPool, int poolIndex) { XML xml = packageItem.componentData; string str; string[] arr; underConstruct = true; arr = xml.GetAttributeArray("size"); sourceWidth = int.Parse(arr[0]); sourceHeight = int.Parse(arr[1]); initWidth = sourceWidth; initHeight = sourceHeight; SetSize(sourceWidth, sourceHeight); arr = xml.GetAttributeArray("pivot"); if (arr != null) { float f1 = float.Parse(arr[0]); float f2 = float.Parse(arr[1]); this.SetPivot(f1, f2, xml.GetAttributeBool("anchor")); } this.opaque = xml.GetAttributeBool("opaque", true); arr = xml.GetAttributeArray("hitTest"); if (arr != null) { PixelHitTestData hitTestData = packageItem.owner.GetPixelHitTestData(arr[0]); if (hitTestData != null) { this.rootContainer.hitArea = new PixelHitTest(hitTestData, int.Parse(arr[1]), int.Parse(arr[2])); } } OverflowType overflow; str = xml.GetAttribute("overflow"); if (str != null) { overflow = FieldTypes.ParseOverflowType(str); } else { overflow = OverflowType.Visible; } str = xml.GetAttribute("margin"); if (str != null) { _margin.Parse(str); } if (overflow == OverflowType.Scroll) { ScrollType scroll; str = xml.GetAttribute("scroll"); if (str != null) { scroll = FieldTypes.ParseScrollType(str); } else { scroll = ScrollType.Vertical; } ScrollBarDisplayType scrollBarDisplay; str = xml.GetAttribute("scrollBar"); if (str != null) { scrollBarDisplay = FieldTypes.ParseScrollBarDisplayType(str); } else { scrollBarDisplay = ScrollBarDisplayType.Default; } int scrollBarFlags = xml.GetAttributeInt("scrollBarFlags"); Margin scrollBarMargin = new Margin(); str = xml.GetAttribute("scrollBarMargin"); if (str != null) { scrollBarMargin.Parse(str); } string vtScrollBarRes = null; string hzScrollBarRes = null; arr = xml.GetAttributeArray("scrollBarRes"); if (arr != null) { vtScrollBarRes = arr[0]; hzScrollBarRes = arr[1]; } SetupScroll(scrollBarMargin, scroll, scrollBarDisplay, scrollBarFlags, vtScrollBarRes, hzScrollBarRes); } else { SetupOverflow(overflow); } arr = xml.GetAttributeArray("clipSoftness"); if (arr != null) { this.clipSoftness = new Vector2(int.Parse(arr[0]), int.Parse(arr[1])); } _buildingDisplayList = true; XMLList.Enumerator et = xml.GetEnumerator("controller"); Controller controller; while (et.MoveNext()) { controller = new Controller(); _controllers.Add(controller); controller.parent = this; controller.Setup(et.Current); } GObject child; DisplayListItem[] displayList = packageItem.displayList; int childCount = displayList.Length; for (int i = 0; i < childCount; i++) { DisplayListItem di = displayList[i]; if (objectPool != null) { child = objectPool[poolIndex + i]; } else { if (di.packageItem != null) { di.packageItem.Load(); child = UIObjectFactory.NewObject(di.packageItem); child.packageItem = di.packageItem; child.ConstructFromResource(); } else { child = UIObjectFactory.NewObject(di.type); } } child.underConstruct = true; child.Setup_BeforeAdd(di.desc); child.parent = this; _children.Add(child); } this.relations.Setup(xml); for (int i = 0; i < childCount; i++) { _children[i].relations.Setup(displayList[i].desc); } for (int i = 0; i < childCount; i++) { child = _children[i]; child.Setup_AfterAdd(displayList[i].desc); child.underConstruct = false; } str = xml.GetAttribute("mask"); if (str != null) { this.mask = GetChildById(str).displayObject; } et = xml.GetEnumerator("transition"); while (et.MoveNext()) { Transition trans = new Transition(this); trans.Setup(et.Current); _transitions.Add(trans); } if (_transitions.Count > 0) { this.onAddedToStage.Add(__addedToStage); this.onRemovedFromStage.Add(__removedFromStage); } ApplyAllControllers(); _buildingDisplayList = false; underConstruct = false; BuildNativeDisplayList(); SetBoundsChangedFlag(); ConstructFromXML(xml); }
internal void ConstructFromResource(List <GObject> objectPool, int poolIndex) { if (!packageItem.translated) { packageItem.translated = true; TranslationHelper.TranslateComponent(packageItem); } ByteBuffer buffer = packageItem.rawData; buffer.Seek(0, 0); underConstruct = true; sourceWidth = buffer.ReadInt(); sourceHeight = buffer.ReadInt(); initWidth = sourceWidth; initHeight = sourceHeight; SetSize(sourceWidth, sourceHeight); if (buffer.ReadBool()) { minWidth = buffer.ReadInt(); maxWidth = buffer.ReadInt(); minHeight = buffer.ReadInt(); maxHeight = buffer.ReadInt(); } if (buffer.ReadBool()) { float f1 = buffer.ReadFloat(); float f2 = buffer.ReadFloat(); SetPivot(f1, f2, buffer.ReadBool()); } if (buffer.ReadBool()) { _margin.top = buffer.ReadInt(); _margin.bottom = buffer.ReadInt(); _margin.left = buffer.ReadInt(); _margin.right = buffer.ReadInt(); } OverflowType overflow = (OverflowType)buffer.ReadByte(); if (overflow == OverflowType.Scroll) { int savedPos = buffer.position; buffer.Seek(0, 7); SetupScroll(buffer); buffer.position = savedPos; } else { SetupOverflow(overflow); } if (buffer.ReadBool()) //clipSoftness { buffer.Skip(8); } _buildingDisplayList = true; buffer.Seek(0, 1); int controllerCount = buffer.ReadShort(); for (int i = 0; i < controllerCount; i++) { int nextPos = buffer.ReadShort(); nextPos += buffer.position; Controller controller = new Controller(); _controllers.Add(controller); controller.parent = this; controller.Setup(buffer); buffer.position = nextPos; } buffer.Seek(0, 2); GObject child; int childCount = buffer.ReadShort(); for (int i = 0; i < childCount; i++) { int dataLen = buffer.ReadShort(); int curPos = buffer.position; if (objectPool != null) { child = objectPool[poolIndex + i]; } else { buffer.Seek(curPos, 0); ObjectType type = (ObjectType)buffer.ReadByte(); string src = buffer.ReadS(); string pkgId = buffer.ReadS(); PackageItem pi = null; if (src != null) { UIPackage pkg; if (pkgId != null) { pkg = UIPackage.GetById(pkgId); } else { pkg = packageItem.owner; } pi = pkg != null?pkg.GetItem(src) : null; } if (pi != null) { child = UIObjectFactory.NewObject(pi); child.packageItem = pi; child.ConstructFromResource(); } else { child = UIObjectFactory.NewObject(type); } } child.underConstruct = true; child.Setup_BeforeAdd(buffer, curPos); child.InternalSetParent(this); _children.Add(child); buffer.position = curPos + dataLen; } buffer.Seek(0, 3); this.relations.Setup(buffer, true); buffer.Seek(0, 2); buffer.Skip(2); for (int i = 0; i < childCount; i++) { int nextPos = buffer.ReadShort(); nextPos += buffer.position; buffer.Seek(buffer.position, 3); _children[i].relations.Setup(buffer, false); buffer.position = nextPos; } buffer.Seek(0, 2); buffer.Skip(2); for (int i = 0; i < childCount; i++) { int nextPos = buffer.ReadShort(); nextPos += buffer.position; child = _children[i]; child.Setup_AfterAdd(buffer, buffer.position); child.underConstruct = false; buffer.position = nextPos; } buffer.Seek(0, 4); buffer.Skip(2); //customData this.opaque = buffer.ReadBool(); int maskId = buffer.ReadShort(); if (maskId != -1) { this.mask = GetChildAt(maskId).displayObject; buffer.ReadBool(); //reversedMask } string hitTestId = buffer.ReadS(); if (hitTestId != null) { PackageItem pi = packageItem.owner.GetItem(hitTestId); if (pi != null && pi.pixelHitTestData != null) { int i1 = buffer.ReadInt(); int i2 = buffer.ReadInt(); this.rootContainer.hitArea = new PixelHitTest(pi.pixelHitTestData, i1, i2, sourceWidth, sourceHeight); } } buffer.Seek(0, 5); int transitionCount = buffer.ReadShort(); for (int i = 0; i < transitionCount; i++) { int nextPos = buffer.ReadShort(); nextPos += buffer.position; Transition trans = new Transition(this); trans.Setup(buffer); _transitions.Add(trans); buffer.position = nextPos; } if (_transitions.Count > 0) { this.onAddedToStage.Add(__addedToStage); this.onRemovedFromStage.Add(__removedFromStage); } ApplyAllControllers(); _buildingDisplayList = false; underConstruct = false; BuildNativeDisplayList(); SetBoundsChangedFlag(); if (packageItem.objectType != ObjectType.Component) { ConstructExtension(buffer); } OnConstruct(); }
IEnumerator _CreateObjectAsync(PackageItem item, CreateObjectCallback callback) { Stats.LatestObjectCreation = 0; Stats.LatestGraphicsCreation = 0; float frameTime = UIConfig.frameTimeForAsyncUIConstruction; List<DisplayListItem> itemList = new List<DisplayListItem>(); CollectComponentChildren(item, itemList); itemList.Add(new DisplayListItem(item, null)); int cnt = itemList.Count; List<GObject> objectPool = new List<GObject>(cnt); GObject obj; DisplayListItem di; float t = Time.realtimeSinceStartup; for (int i = 0; i < cnt; i++) { di = itemList[i]; if (di.packageItem != null) { obj = UIObjectFactory.NewObject(di.packageItem); obj.packageItem = di.packageItem; objectPool.Add(obj); _constructing++; if (di.packageItem.type == PackageItemType.Component) { int poolStart = objectPool.Count - di.packageItem.displayList.Length - 1; ((GComponent)obj).ConstructFromResource(objectPool, poolStart); objectPool.RemoveRange(poolStart, di.packageItem.displayList.Length); } else { GetItemAsset(di.packageItem); obj.ConstructFromResource(); } _constructing--; } else { obj = UIObjectFactory.NewObject(di.type); objectPool.Add(obj); if (di.type == "list" && di.listItemCount > 0) { int poolStart = objectPool.Count - di.listItemCount - 1; for (int k = 0; k < di.listItemCount; k++) //把他们都放到pool里,这样GList在创建时就不需要创建对象了 ((GList)obj).itemPool.ReturnObject(objectPool[k + poolStart]); objectPool.RemoveRange(poolStart, di.listItemCount); } } if ((i % 5 == 0) && Time.realtimeSinceStartup - t >= frameTime) { yield return null; t = Time.realtimeSinceStartup; } } callback(objectPool[0]); }
static IEnumerator _CreateObject(PackageItem item, UIPackage.CreateObjectCallback callback) { Stats.LatestObjectCreation = 0; Stats.LatestGraphicsCreation = 0; float frameTime = UIConfig.frameTimeForAsyncUIConstruction; List <DisplayListItem> itemList = new List <DisplayListItem>(); DisplayListItem di = new DisplayListItem(item, ObjectType.Component); di.childCount = CollectComponentChildren(item, itemList); itemList.Add(di); int cnt = itemList.Count; List <GObject> objectPool = new List <GObject>(cnt); GObject obj; float t = Time.realtimeSinceStartup; bool alreadyNextFrame = false; for (int i = 0; i < cnt; i++) { di = itemList[i]; if (di.packageItem != null) { obj = UIObjectFactory.NewObject(di.packageItem); obj.packageItem = di.packageItem; objectPool.Add(obj); UIPackage._constructing++; if (di.packageItem.type == PackageItemType.Component) { int poolStart = objectPool.Count - di.childCount - 1; ((GComponent)obj).ConstructFromResource(objectPool, poolStart); objectPool.RemoveRange(poolStart, di.childCount); } else { obj.ConstructFromResource(); } UIPackage._constructing--; } else { obj = UIObjectFactory.NewObject(di.type); objectPool.Add(obj); if (di.type == ObjectType.List && di.listItemCount > 0) { int poolStart = objectPool.Count - di.listItemCount - 1; for (int k = 0; k < di.listItemCount; k++) //把他们都放到pool里,这样GList在创建时就不需要创建对象了 { ((GList)obj).itemPool.ReturnObject(objectPool[k + poolStart]); } objectPool.RemoveRange(poolStart, di.listItemCount); } } if ((i % 5 == 0) && Time.realtimeSinceStartup - t >= frameTime) { yield return(null); t = Time.realtimeSinceStartup; alreadyNextFrame = true; } } if (!alreadyNextFrame) //强制至至少下一帧才调用callback,避免调用者逻辑出错 { yield return(null); } callback(objectPool[0]); }
/// <summary> /// /// </summary> /// <param name="url"></param> /// <param name="luaClass"></param> public static void SetExtension(string url, System.Type baseType, LuaFunction extendFunction) { UIObjectFactory.SetPackageItemExtension(url, baseType); packageItemExtensions[url] = extendFunction; }
bool LoadPackage(ByteBuffer buffer) { if (buffer.ReadUint() != 0x46475549) { throw new Exception("FairyGUI: old package format found in '" + assetPath + "'"); } buffer.version = buffer.ReadInt(); buffer.ReadBool(); //compressed id = buffer.ReadString(); name = buffer.ReadString(); if (_packageInstById.ContainsKey(id) && name != _packageInstById[id].name) { Log.Warning("FairyGUI: Package id conflicts, '" + name + "' and '" + _packageInstById[id].name + "'"); return(false); } buffer.Skip(20); int indexTablePos = buffer.position; int cnt; buffer.Seek(indexTablePos, 4); cnt = buffer.ReadInt(); string[] stringTable = new string[cnt]; for (int i = 0; i < cnt; i++) { stringTable[i] = buffer.ReadString(); } buffer.stringTable = stringTable; if (buffer.Seek(indexTablePos, 5)) { cnt = buffer.ReadInt(); for (int i = 0; i < cnt; i++) { int index = buffer.ReadUshort(); int len = buffer.ReadInt(); stringTable[index] = buffer.ReadString(len); } } buffer.Seek(indexTablePos, 1); PackageItem pi; cnt = buffer.ReadShort(); for (int i = 0; i < cnt; i++) { int nextPos = buffer.ReadInt(); nextPos += buffer.position; pi = new PackageItem(); pi.owner = this; pi.type = (PackageItemType)buffer.ReadByte(); pi.id = buffer.ReadS(); pi.name = buffer.ReadS(); buffer.ReadS(); //path pi.file = buffer.ReadS(); pi.exported = buffer.ReadBool(); pi.width = buffer.ReadInt(); pi.height = buffer.ReadInt(); switch (pi.type) { case PackageItemType.Image: { pi.objectType = ObjectType.Image; int scaleOption = buffer.ReadByte(); if (scaleOption == 1) { Rectangle rect = new Rectangle(); rect.X = buffer.ReadInt(); rect.Y = buffer.ReadInt(); rect.Width = buffer.ReadInt(); rect.Height = buffer.ReadInt(); pi.scale9Grid = rect; pi.tileGridIndice = buffer.ReadInt(); } else if (scaleOption == 2) { pi.scaleByTile = true; } buffer.ReadBool(); //smoothing break; } case PackageItemType.MovieClip: { buffer.ReadBool(); //smoothing pi.objectType = ObjectType.MovieClip; pi.rawData = buffer.ReadBuffer(); break; } case PackageItemType.Font: { pi.rawData = buffer.ReadBuffer(); break; } case PackageItemType.Component: { int extension = buffer.ReadByte(); if (extension > 0) { pi.objectType = (ObjectType)extension; } else { pi.objectType = ObjectType.Component; } pi.rawData = buffer.ReadBuffer(); UIObjectFactory.ResolvePackageItemExtension(pi); break; } case PackageItemType.Atlas: case PackageItemType.Sound: case PackageItemType.Misc: { pi.file = assetPath + "_" + Path.GetFileNameWithoutExtension(pi.file); break; } } _items.Add(pi); _itemsById[pi.id] = pi; if (pi.name != null) { _itemsByName[pi.name] = pi; } buffer.position = nextPos; } buffer.Seek(indexTablePos, 2); cnt = buffer.ReadShort(); for (int i = 0; i < cnt; i++) { int nextPos = buffer.ReadShort(); nextPos += buffer.position; string itemId = buffer.ReadS(); pi = _itemsById[buffer.ReadS()]; AtlasSprite sprite = new AtlasSprite(); sprite.atlas = pi; sprite.rect.X = buffer.ReadInt(); sprite.rect.Y = buffer.ReadInt(); sprite.rect.Width = buffer.ReadInt(); sprite.rect.Height = buffer.ReadInt(); sprite.rotated = buffer.ReadBool(); _sprites[itemId] = sprite; buffer.position = nextPos; } if (buffer.Seek(indexTablePos, 3)) { cnt = buffer.ReadShort(); for (int i = 0; i < cnt; i++) { int nextPos = buffer.ReadInt(); nextPos += buffer.position; if (_itemsById.TryGetValue(buffer.ReadS(), out pi)) { if (pi.type == PackageItemType.Image) { pi.pixelHitTestData = new PixelHitTestData(); pi.pixelHitTestData.Load(buffer); } } buffer.position = nextPos; } } buffer.Seek(indexTablePos, 0); cnt = buffer.ReadShort(); _dependencies = new Dictionary <string, string> [cnt]; for (int i = 0; i < cnt; i++) { Dictionary <string, string> kv = new Dictionary <string, string>(); kv.Add("id", buffer.ReadS()); kv.Add("name", buffer.ReadS()); _dependencies[i] = kv; } return(true); }
bool LoadPackage(ByteBuffer buffer, string packageSource, string assetNamePrefix) { if (buffer.ReadUint() != 0x46475549) { if (Application.isPlaying) { throw new Exception("FairyGUI: old package format found in '" + packageSource + "'"); } else { Debug.LogWarning("FairyGUI: old package format found in '" + packageSource + "'"); return(false); } } buffer.version = buffer.ReadInt(); buffer.ReadBool(); //compressed id = buffer.ReadString(); name = buffer.ReadString(); if (_packageInstById.ContainsKey(id) && name != _packageInstById[id].name) { Debug.LogWarning("FairyGUI: Package id conflicts, '" + name + "' and '" + _packageInstById[id].name + "'"); return(false); } buffer.Skip(20); int indexTablePos = buffer.position; int cnt; buffer.Seek(indexTablePos, 4); cnt = buffer.ReadInt(); string[] stringTable = new string[cnt]; for (int i = 0; i < cnt; i++) { stringTable[i] = buffer.ReadString(); } buffer.stringTable = stringTable; buffer.Seek(indexTablePos, 1); PackageItem pi; if (assetNamePrefix == null) { assetNamePrefix = string.Empty; } else if (assetNamePrefix.Length > 0) { assetNamePrefix = assetNamePrefix + "_"; } cnt = buffer.ReadShort(); for (int i = 0; i < cnt; i++) { int nextPos = buffer.ReadInt(); nextPos += buffer.position; pi = new PackageItem(); pi.owner = this; pi.type = (PackageItemType)buffer.ReadByte(); pi.id = buffer.ReadS(); pi.name = buffer.ReadS(); buffer.ReadS(); //path pi.file = buffer.ReadS(); pi.exported = buffer.ReadBool(); pi.width = buffer.ReadInt(); pi.height = buffer.ReadInt(); switch (pi.type) { case PackageItemType.Image: { pi.objectType = ObjectType.Image; int scaleOption = buffer.ReadByte(); if (scaleOption == 1) { Rect rect = new Rect(); rect.x = buffer.ReadInt(); rect.y = buffer.ReadInt(); rect.width = buffer.ReadInt(); rect.height = buffer.ReadInt(); pi.scale9Grid = rect; pi.tileGridIndice = buffer.ReadInt(); } else if (scaleOption == 2) { pi.scaleByTile = true; } buffer.ReadBool(); //smoothing break; } case PackageItemType.MovieClip: { buffer.ReadBool(); //smoothing pi.objectType = ObjectType.MovieClip; pi.rawData = buffer.ReadBuffer(); break; } case PackageItemType.Font: { pi.rawData = buffer.ReadBuffer(); break; } case PackageItemType.Component: { int extension = buffer.ReadByte(); if (extension > 0) { pi.objectType = (ObjectType)extension; } else { pi.objectType = ObjectType.Component; } pi.rawData = buffer.ReadBuffer(); UIObjectFactory.ResolvePackageItemExtension(pi); break; } case PackageItemType.Atlas: case PackageItemType.Sound: case PackageItemType.Misc: { pi.file = assetNamePrefix + pi.file; break; } } _items.Add(pi); _itemsById[pi.id] = pi; if (pi.name != null) { _itemsByName[pi.name] = pi; } buffer.position = nextPos; } buffer.Seek(indexTablePos, 2); cnt = buffer.ReadShort(); for (int i = 0; i < cnt; i++) { int nextPos = buffer.ReadShort(); nextPos += buffer.position; string itemId = buffer.ReadS(); pi = _itemsById[buffer.ReadS()]; AtlasSprite sprite = new AtlasSprite(); sprite.atlas = pi; sprite.rect.x = buffer.ReadInt(); sprite.rect.y = buffer.ReadInt(); sprite.rect.width = buffer.ReadInt(); sprite.rect.height = buffer.ReadInt(); sprite.rotated = buffer.ReadBool(); _sprites[itemId] = sprite; buffer.position = nextPos; } if (buffer.Seek(indexTablePos, 3)) { cnt = buffer.ReadShort(); for (int i = 0; i < cnt; i++) { int nextPos = buffer.ReadInt(); nextPos += buffer.position; if (_itemsById.TryGetValue(buffer.ReadS(), out pi)) { if (pi.type == PackageItemType.Image) { pi.pixelHitTestData = new PixelHitTestData(); pi.pixelHitTestData.Load(buffer); } } buffer.position = nextPos; } } if (!Application.isPlaying) { _items.Sort(ComparePackageItem); } return(true); }