Example #1
0
        /// <summary>
        /// 收集创建目标对象所需的所有类型信息
        /// </summary>
        /// <param name="item"></param>
        /// <param name="list"></param>
        static int CollectComponentChildren(PackageItem item, List <DisplayListItem> list)
        {
            ByteBuffer buffer = item.rawData;

            buffer.Seek(0, 2);

            int             dcnt = buffer.ReadShort();
            DisplayListItem di;
            PackageItem     pi;

            for (int i = 0; i < dcnt; i++)
            {
                int dataLen = buffer.ReadShort();
                int curPos  = buffer.position;

                buffer.Seek(curPos, 0);

                ObjectType type  = (ObjectType)buffer.ReadByte();
                string     src   = buffer.ReadS();
                string     pkgId = buffer.ReadS();

                buffer.position = curPos;

                if (src != null)
                {
                    UIPackage pkg;
                    if (pkgId != null)
                    {
                        pkg = UIPackage.GetById(pkgId);
                    }
                    else
                    {
                        pkg = item.owner;
                    }

                    pi = pkg != null?pkg.GetItem(src) : null;

                    di = new DisplayListItem(pi, type);

                    if (pi != null && pi.type == PackageItemType.Component)
                    {
                        di.childCount = CollectComponentChildren(pi, list);
                    }
                }
                else
                {
                    di = new DisplayListItem(null, type);
                    if (type == ObjectType.List) //list
                    {
                        di.listItemCount = CollectListChildren(buffer, list);
                    }
                }

                list.Add(di);
                buffer.position = curPos + dataLen;
            }

            return(dcnt);
        }
Example #2
0
		/// <summary>
		/// 收集创建目标对象所需的所有类型信息
		/// </summary>
		/// <param name="item"></param>
		/// <param name="list"></param>
		void CollectComponentChildren(PackageItem item, List<DisplayListItem> list)
		{
			if (!item.decoded)
				LoadComponent(item);
			if (item.displayList == null)
				LoadComponentChildren(item);

			int cnt = item.displayList.Length;
			for (int i = 0; i < cnt; i++)
			{
				DisplayListItem di = item.displayList[i];
				if (di.packageItem != null && di.packageItem.type == PackageItemType.Component)
					CollectComponentChildren(di.packageItem, list);
				else if (di.type == "list") //也要收集列表的item
				{
					XMLList.Enumerator et = di.desc.GetEnumerator("item");
					string defaultItem = null;
					di.listItemCount = 0;
					while (et.MoveNext())
					{
						XML ix = et.Current;
						string url = ix.GetAttribute("url");
						if (string.IsNullOrEmpty(url))
						{
							if (defaultItem == null)
								defaultItem = di.desc.GetAttribute("defaultItem");
							url = defaultItem;
							if (string.IsNullOrEmpty(url))
								continue;
						}

						PackageItem pi = UIPackage.GetItemByURL(url);
						if (pi != null)
						{
							if (pi.type == PackageItemType.Component)
								CollectComponentChildren(pi, list);

							list.Add(new DisplayListItem(pi, null));
							di.listItemCount++;
						}
					}
				}
				list.Add(di);
			}
		}
Example #3
0
		void LoadComponentChildren(PackageItem item)
		{
			XML listNode = item.componentData.GetNode("displayList");
			if (listNode != null)
			{
				XMLList col = listNode.Elements();
				int dcnt = col.Count;
				item.displayList = new DisplayListItem[dcnt];
				DisplayListItem di;
				for (int i = 0; i < dcnt; i++)
				{
					XML cxml = col[i];

					string src = cxml.GetAttribute("src");
					if (src != null)
					{
						string pkgId = cxml.GetAttribute("pkg");
						UIPackage pkg;
						if (pkgId != null && pkgId != item.owner.id)
							pkg = UIPackage.GetById(pkgId);
						else
							pkg = item.owner;

						PackageItem pi = pkg != null ? pkg.GetItem(src) : null;
						if (pi != null)
							di = new DisplayListItem(pi, null);
						else
							di = new DisplayListItem(null, cxml.name);
					}
					else
					{
						if (cxml.name == "text" && cxml.GetAttributeBool("input", false))
							di = new DisplayListItem(null, "inputtext");
						else
							di = new DisplayListItem(null, cxml.name);
					}

					di.desc = cxml;
					item.displayList[i] = di;
				}
			}
			else
				item.displayList = new DisplayListItem[0];
		}
Example #4
0
        static int CollectListChildren(ByteBuffer buffer, List <DisplayListItem> list)
        {
            buffer.Seek(buffer.position, 8);

            string defaultItem   = buffer.ReadS();
            int    listItemCount = 0;
            int    itemCount     = buffer.ReadShort();

            for (int i = 0; i < itemCount; i++)
            {
                int nextPos = buffer.ReadShort();
                nextPos += buffer.position;

                string url = buffer.ReadS();
                if (url == null)
                {
                    url = defaultItem;
                }
                if (!string.IsNullOrEmpty(url))
                {
                    PackageItem pi = UIPackage.GetItemByURL(url);
                    if (pi != null)
                    {
                        DisplayListItem di = new DisplayListItem(pi, pi.objectType);
                        if (pi.type == PackageItemType.Component)
                        {
                            di.childCount = CollectComponentChildren(pi, list);
                        }

                        list.Add(di);
                        listItemCount++;
                    }
                }
                buffer.position = nextPos;
            }

            return(listItemCount);
        }
Example #5
0
        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);
        }
Example #6
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]);
        }
Example #7
0
        void LoadComponentChildren(PackageItem item)
        {
            XML listNode = item.componentData.GetNode("displayList");
            if (listNode != null)
            {
                XMLList col = listNode.Elements();
                int dcnt = col.Count;
                item.displayList = new DisplayListItem[dcnt];
                DisplayListItem di;
                for (int i = 0; i < dcnt; i++)
                {
                    XML cxml = col[i];

                    string src = cxml.GetAttribute("src");
                    if (src != null)
                    {
                        string pkgId = cxml.GetAttribute("pkg");
                        UIPackage pkg;
                        if (pkgId != null && pkgId != item.owner.id)
                            pkg = UIPackage.GetById(pkgId);
                        else
                            pkg = item.owner;

                        PackageItem pi = pkg != null ? pkg.GetItem(src) : null;
                        if (pi != null)
                            di = new DisplayListItem(pi, null);
                        else
                            di = new DisplayListItem(null, cxml.name);
                    }
                    else
                    {
                        if (cxml.name == "text" && cxml.GetAttributeBool("input", false))
                            di = new DisplayListItem(null, "inputtext");
                        else
                            di = new DisplayListItem(null, cxml.name);
                    }

                    di.desc = cxml;
                    item.displayList[i] = di;
                }
            }
            else
                item.displayList = new DisplayListItem[0];
        }