예제 #1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="data"></param>
 /// <param name="offsetX"></param>
 /// <param name="offsetY"></param>
 public PixelHitTest(PixelHitTestData data, int offsetX, int offsetY, float sourceWidth, float sourceHeight)
 {
     _data             = data;
     this.offsetX      = offsetX;
     this.offsetY      = offsetY;
     this.sourceWidth  = sourceWidth;
     this.sourceHeight = sourceHeight;
 }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="data"></param>
        /// <param name="offsetX"></param>
        /// <param name="offsetY"></param>
        public PixelHitTest(PixelHitTestData data, int offsetX, int offsetY)
        {
            _data        = data;
            this.offsetX = offsetX;
            this.offsetY = offsetY;

            scaleX = 1;
            scaleY = 1;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="data"></param>
        /// <param name="offsetX"></param>
        /// <param name="offsetY"></param>
        public PixelHitTest(PixelHitTestData data, int offsetX, int offsetY)
        {
            _data = data;
            this.offsetX = offsetX;
            this.offsetY = offsetY;

            scaleX = 1;
            scaleY = 1;
        }
 static public int get_pixels(IntPtr l)
 {
     try {
         FairyGUI.PixelHitTestData self = (FairyGUI.PixelHitTestData)checkSelf(l);
         pushValue(l, true);
         pushValue(l, self.pixels);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 static public int constructor(IntPtr l)
 {
     try {
         FairyGUI.PixelHitTestData o;
         o = new FairyGUI.PixelHitTestData();
         pushValue(l, true);
         pushValue(l, o);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 static public int set_scale(IntPtr l)
 {
     try {
         FairyGUI.PixelHitTestData self = (FairyGUI.PixelHitTestData)checkSelf(l);
         System.Single             v;
         checkType(l, 2, out v);
         self.scale = v;
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 static public int Load(IntPtr l)
 {
     try {
         FairyGUI.PixelHitTestData self = (FairyGUI.PixelHitTestData)checkSelf(l);
         FairyGUI.Utils.ByteBuffer a1;
         checkType(l, 2, out a1);
         self.Load(a1);
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 static public int set_pixels(IntPtr l)
 {
     try {
         FairyGUI.PixelHitTestData self = (FairyGUI.PixelHitTestData)checkSelf(l);
         System.Byte[]             v;
         checkArray(l, 2, out v);
         self.pixels = v;
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
예제 #9
0
 static int GetPixelHitTestData(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         FairyGUI.UIPackage        obj  = (FairyGUI.UIPackage)ToLua.CheckObject <FairyGUI.UIPackage>(L, 1);
         string                    arg0 = ToLua.CheckString(L, 2);
         FairyGUI.PixelHitTestData o    = obj.GetPixelHitTestData(arg0);
         ToLua.PushObject(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
예제 #10
0
파일: UIPackage.cs 프로젝트: yinlei/Fishing
        void LoadPackage()
        {
            string[] arr = null;
            string str;

            str = LoadString("sprites.bytes");
            if (str == null)
            {
                Debug.LogError("FairyGUI: cannot load package from " + _assetNamePrefix);
                return;
            }
            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;
            }

            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);
                }
            }

            str = _descPack["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.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(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;
                        }

                    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;
            }
        }
예제 #11
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);
        }
예제 #12
0
        virtual public void ConstructFromXML(XML xml)
        {
            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    col = xml.Elements("controller");
            Controller controller;

            foreach (XML cxml in col)
            {
                controller = new Controller();
                _controllers.Add(controller);
                controller.parent = this;
                controller.Setup(cxml);
            }

            XML listNode = xml.GetNode("displayList");

            if (listNode != null)
            {
                col = listNode.Elements();
                GObject u;
                foreach (XML cxml in col)
                {
                    u = ConstructChild(cxml);
                    if (u == null)
                    {
                        continue;
                    }

                    u.underConstruct   = true;
                    u.constructingData = cxml;
                    u.Setup_BeforeAdd(cxml);
                    AddChild(u);
                }
            }
            this.relations.Setup(xml);

            int cnt = _children.Count;

            for (int i = 0; i < cnt; i++)
            {
                GObject u = _children[i];
                u.relations.Setup(u.constructingData);
            }

            for (int i = 0; i < cnt; i++)
            {
                GObject u = _children[i];
                u.Setup_AfterAdd(u.constructingData);
                u.underConstruct   = false;
                u.constructingData = null;
            }

            str = xml.GetAttribute("mask");
            if (str != null)
            {
                this.mask = GetChildById(str).displayObject;
            }

            XMLList transCol = xml.Elements("transition");

            foreach (XML cxml in transCol)
            {
                Transition trans = new Transition(this);
                trans.Setup(cxml);
                _transitions.Add(trans);
            }

            if (_transitions.Count > 0)
            {
                this.onAddedToStage.Add(__addedToStage);
                this.onRemovedFromStage.Add(__removedFromStage);
            }

            ApplyAllControllers();

            _buildingDisplayList = false;
            underConstruct       = false;

            BuildNativeDisplayList();
        }
예제 #13
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;
		}