예제 #1
0
        public DisplayHeader(Field field)
        {
            this.m_field = field;

            this.m_displayBackSprite = new AtlasSprite()
            {
                Frame = Game.Content.Textures.DisplayBack
            };

            this.m_displayFrontSprite = new AtlasSprite()
            {
                Frame = Game.Content.Textures.DisplayFront
            };

            this.m_spinnerSprite = new AtlasSprite()
            {
                Frame = Game.Content.Textures.DisplaySpinner
            };
            this.m_spinnerSprite.SetColor(Color.DarkGray);
            Game.Content.Animations.FieldDisplaySpinner.Apply(this.m_spinnerSprite);

            this.m_globeSprite = new AtlasSprite {
                Frame = Game.Content.Textures.DisplayGlobe
            };
            Game.Content.Animations.FieldFlip.Apply(this.m_globeSprite);

            this.UpdateSignalCore(false, true, false);
        }
예제 #2
0
        static void MakeSpritePrefab(string path, string parentDir)
        {
            Sprite sprite = AssetDatabase.LoadAssetAtPath <Sprite>(path);

            if (sprite == null)
            {
                Debug.Log("sprite is null, path:" + path);
                return;
            }

            string   targetPath = path.Replace(UI_FILE_PATH + parentDir, UI_LOAD_PREFAB_PATH);
            FileInfo fileInfo   = new FileInfo(targetPath);
            string   targetDir  = fileInfo.Directory + "/";

            if (!Directory.Exists(targetDir))
            {
                Directory.CreateDirectory(targetDir);
            }

            string createPath = targetPath.Replace(fileInfo.Extension, ".prefab");

            if (!File.Exists(createPath))
            {
                GameObject  go          = new GameObject(sprite.name);
                AtlasSprite atlasSprite = go.AddComponent <AtlasSprite>();
                atlasSprite.sprite = sprite;
                PrefabUtility.CreatePrefab(createPath, go);
                GameObject.DestroyImmediate(go);

                Debug.Log("Create Prefab : " + createPath);
            }
        }
예제 #3
0
    void OnSelectAtlas(Object obj)
    {
        AtlasSprite sprite = serializedObject.targetObject as AtlasSprite;

        sprite.atlas = obj as AtlasSheet;

        NGUITools.SetDirty(serializedObject.targetObject);
        NGUISettings.atlas = obj as UIAtlas;
    }
예제 #4
0
            public AtlasSprite(AtlasSprite sprite)
            {
                Region = sprite.Region;

                _originalOffsetX = sprite._originalOffsetX;
                _originalOffsetY = sprite._originalOffsetY;

                Set(sprite);
            }
예제 #5
0
		NTexture CreateSpriteTexture(AtlasSprite sprite)
		{
			PackageItem atlasItem;
			if (_itemsById.TryGetValue(sprite.atlas, out atlasItem))
				return new NTexture((NTexture)GetItemAsset(atlasItem), sprite.rect);
			else
			{
				Debug.LogWarning("FairyGUI: " + sprite.atlas + " not found in " + this.name);
				return NTexture.Empty;
			}
		}
예제 #6
0
    /// <summary>
    /// Sprite selection callback function.
    /// </summary>

    void SelectSprite(string spriteName)
    {
        AtlasSprite sprite = serializedObject.targetObject as AtlasSprite;

        sprite.spriteName = spriteName;
        if (sprite.isValid)
        {
            NGUITools.SetDirty(serializedObject.targetObject);
            NGUISettings.selectedSprite = spriteName;
        }
    }
예제 #7
0
    /// <summary>
    /// Draw the sprite preview.
    /// </summary>

    public override void OnPreviewGUI(Rect rect, GUIStyle background)
    {
        AtlasSprite asp = target as AtlasSprite;

        if (asp == null || !asp.isValid)
        {
            return;
        }

        Sprite s = asp.Renderer.sprite;

        NGUIEditorTools.DrawSprite(s.texture, rect, asp.Renderer.color, s.textureRect, s.border);
    }
예제 #8
0
        public RouterHeader()
        {
            this.m_routerSprite = new AtlasSprite()
            {
                Frame = Game.Content.Textures.DisplayFront
            };
            this.m_routerSprite.SetColor(Game.Content.Colors.Router);

            this.m_globeSprite = new AtlasSprite()
            {
                Frame = Game.Content.Textures.DisplayGlobe
            };
            this.m_globeSprite.SetColor(Game.Content.Colors.RouterIcon);
        }
예제 #9
0
        public LevelListViewItem(LevelDescriptor descriptor)
        {
            this.Height     = Game.Content.GetSizeInDpi(40);
            this.Descriptor = descriptor;

            this.m_index = new TextSprite(Game.Content.Fonts.ButtonFont)
            {
                Text = (descriptor.Index + 1).ToString()
            };
            this.m_desc = new TextSprite(Game.Content.Fonts.ButtonFont)
            {
                Text = descriptor.Width + " x " + descriptor.Height
            };
            this.m_difficultBack = new AtlasSprite()
            {
                Frame = Game.Content.Textures.ButtonCircle
            };
            this.m_difficultBack.SetColor(Game.Content.Colors.DifficultColors[descriptor.Difficult]);
        }
예제 #10
0
    protected bool ShouldDrawProperties()
    {
        GUILayout.BeginHorizontal();
        if (NGUIEditorTools.DrawPrefixButton("Atlas"))
        {
            ComponentSelector.Show <AtlasSheet>(OnSelectAtlas);
        }
        SerializedProperty atlas = NGUIEditorTools.DrawProperty("", serializedObject, "mAtlas", GUILayout.MinWidth(20f));

        if (GUILayout.Button("Rand", GUILayout.Width(40f)))
        {
            if (atlas != null && Selection.objects.Length > 0)
            {
                AtlasSheet atl = atlas.objectReferenceValue as AtlasSheet;

                foreach (var sprite_obj in Selection.gameObjects)
                {
                    AtlasSprite sprite = sprite_obj.GetComponent <AtlasSprite>();
                    sprite.spriteName = atl.Atlas.spriteList[UnityEngine.Random.Range(0, atl.Atlas.spriteList.Count - 1)].name;
                }
            }
        }

        if (GUILayout.Button("Edit", GUILayout.Width(40f)))
        {
            if (atlas != null)
            {
                AtlasSheet atl = atlas.objectReferenceValue as AtlasSheet;
                NGUISettings.atlas = atl.Atlas;
                NGUIEditorTools.Select(atl.gameObject);
            }
        }
        GUILayout.EndHorizontal();

        SerializedProperty sp = serializedObject.FindProperty("mSpriteName");

        NGUIEditorTools.DrawAdvancedSpriteField((atlas.objectReferenceValue as AtlasSheet).Atlas, sp.stringValue, SelectSprite, false);

        return(true);
    }
예제 #11
0
    /// <summary>
    /// Draw the inspector properties.
    /// </summary>

    public override void OnInspectorGUI()
    {
        NGUIEditorTools.SetLabelWidth(80f);
        EditorGUILayout.Space();

        serializedObject.Update();

        EditorGUI.BeginDisabledGroup(!ShouldDrawProperties());
        EditorGUI.EndDisabledGroup();

        EditorGUIUtility.labelWidth = 0;

        EditorGUILayout.Space();

        AtlasSprite sprite = (AtlasSprite)target;

        serializedObject.ApplyModifiedProperties();

        if (sprite == null || !sprite.isValid)
        {
            return;
        }
    }
예제 #12
0
        public FieldStatus()
        {
            m_spacing = Game.Content.GetSizeInDpi(10);

            var font = Game.Content.Fonts.FieldStatusFont;

            m_levelIndex = new AutoSizeLabel(font)
            {
                Fixed = true
            };
            m_levelSizeLabel = new AutoSizeLabel(font)
            {
                Fixed = true
            };
            m_levelDifficult = new AtlasSprite()
            {
                Frame = Game.Content.Textures.ButtonCircle, Fixed = true
            };
            m_conectedLabel = new AutoSizeLabel(font)
            {
                Fixed = true
            };
        }
예제 #13
0
    public void RefreshItem()
    {
        Init();

        if (number > 0)
        {
            content.gameObject.SetActive(true);
            unitNumberText.text = "X" + number;
        }
        else
        {
            content.gameObject.SetActive(false);
        }

        unitNameText.text = unitName;

        AtlasSprite aSprite = GameResourceLoadManager.GetInstance().LoadAtlasSprite(icon);

        if (aSprite == null)
        {
            DebugUtils.LogError(DebugUtils.Type.UI, string.Format("Can't find unit item icon : {0}, please check this!", icon));
        }
        unitImage.SetSprite(aSprite);
        //GameResourceLoadManager.GetInstance().LoadAtlasSprite( icon, delegate ( string name, AtlasSprite atlasSprite, System.Object param )
        //{
        //    if( unitImage == null )
        //    {
        //        return;
        //    }
        //    unitImage.SetSprite( atlasSprite );

        //    if ( atlasSprite == null )
        //    {
        //        DebugUtils.LogError( DebugUtils.Type.UI, "Can't find unit item icon, please check this." );
        //    }
        //}, true );
    }
예제 #14
0
파일: UIPackage.cs 프로젝트: aideas/F-N-GUI
        void LoadPackage()
        {
            string[] arr = null;
            string str;

            str = LoadString("sprites.bytes");
            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;
            }
        }
예제 #15
0
        void LoadFont(PackageItem item)
        {
            BitmapFont font = new BitmapFont(item);

            item.bitmapFont = font;
            ByteBuffer buffer = item.rawData;

            buffer.Seek(0, 0);

            bool ttf = buffer.ReadBool();

            font.colorEnabled = buffer.ReadBool();
            font.scaleEnabled = buffer.ReadBool();
            buffer.ReadBool();            //hasChannel
            int fontSize   = buffer.ReadInt();
            int xadvance   = buffer.ReadInt();
            int lineHeight = buffer.ReadInt();

            float       texScaleX   = 1;
            float       texScaleY   = 1;
            NTexture    mainTexture = null;
            AtlasSprite mainSprite  = null;

            if (ttf && _sprites.TryGetValue(item.id, out mainSprite))
            {
                mainTexture = (NTexture)GetItemAsset(mainSprite.atlas);
                texScaleX   = mainTexture.root.uvRect.Width / mainTexture.width;
                texScaleY   = mainTexture.root.uvRect.Height / mainTexture.height;
            }

            buffer.Seek(0, 1);

            BitmapFont.BMGlyph bg;
            int cnt = buffer.ReadInt();

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

                bg = new BitmapFont.BMGlyph();
                char ch = buffer.ReadChar();
                font.AddChar(ch, bg);

                string img = buffer.ReadS();
                int    bx  = buffer.ReadInt();
                int    by  = buffer.ReadInt();
                bg.offsetX = buffer.ReadInt();
                bg.offsetY = buffer.ReadInt();
                bg.width   = buffer.ReadInt();
                bg.height  = buffer.ReadInt();
                bg.advance = buffer.ReadInt();
                bg.channel = buffer.ReadByte();
                if (bg.channel == 1)
                {
                    bg.channel = 3;
                }
                else if (bg.channel == 2)
                {
                    bg.channel = 2;
                }
                else if (bg.channel == 3)
                {
                    bg.channel = 1;
                }

                if (ttf)
                {
                    if (mainSprite.rotated)
                    {
                        bg.uv[0] = new Vector2((float)(by + bg.height + mainSprite.rect.X) * texScaleX,
                                               1 - (float)(mainSprite.rect.Bottom - bx) * texScaleY);
                        bg.uv[1] = new Vector2(bg.uv[0].X - (float)bg.height * texScaleX, bg.uv[0].Y);
                        bg.uv[2] = new Vector2(bg.uv[1].X, bg.uv[0].Y + (float)bg.width * texScaleY);
                        bg.uv[3] = new Vector2(bg.uv[0].X, bg.uv[2].Y);
                    }
                    else
                    {
                        bg.uv[0] = new Vector2((float)(bx + mainSprite.rect.X) * texScaleX,
                                               1 - (float)(by + bg.height + mainSprite.rect.Y) * texScaleY);
                        bg.uv[1] = new Vector2(bg.uv[0].X, bg.uv[0].Y + (float)bg.height * texScaleY);
                        bg.uv[2] = new Vector2(bg.uv[0].X + (float)bg.width * texScaleX, bg.uv[1].Y);
                        bg.uv[3] = new Vector2(bg.uv[2].X, bg.uv[0].Y);
                    }

                    bg.lineHeight = lineHeight;
                }
                else
                {
                    PackageItem charImg;
                    if (_itemsById.TryGetValue(img, out charImg))
                    {
                        GetItemAsset(charImg);
                        charImg.texture.GetUV(bg.uv);
                        bg.width  = charImg.texture.width;
                        bg.height = charImg.texture.height;

                        if (mainTexture == null)
                        {
                            mainTexture = charImg.texture.root;
                        }
                    }

                    if (fontSize == 0)
                    {
                        fontSize = bg.height;
                    }

                    if (bg.advance == 0)
                    {
                        if (xadvance == 0)
                        {
                            bg.advance = bg.offsetX + bg.width;
                        }
                        else
                        {
                            bg.advance = xadvance;
                        }
                    }

                    bg.lineHeight = bg.offsetY < 0 ? bg.height : (bg.offsetY + bg.height);
                    if (bg.lineHeight < font.size)
                    {
                        bg.lineHeight = font.size;
                    }
                }

                buffer.position = nextPos;
            }

            font.size        = fontSize;
            font.mainTexture = mainTexture;
        }
예제 #16
0
        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);
        }
예제 #17
0
        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);
        }
예제 #18
0
        void LoadFont(PackageItem item)
        {
            BitmapFont font = new BitmapFont(item);

            item.bitmapFont = font;
            ByteBuffer buffer = item.rawData;

            buffer.Seek(0, 0);

            bool ttf = buffer.ReadBool();

            font.canTint    = buffer.ReadBool();
            font.resizable  = buffer.ReadBool();
            font.hasChannel = buffer.ReadBool();
            int fontSize   = buffer.ReadInt();
            int xadvance   = buffer.ReadInt();
            int lineHeight = buffer.ReadInt();

            float       texScaleX   = 1;
            float       texScaleY   = 1;
            NTexture    mainTexture = null;
            AtlasSprite mainSprite  = null;

            if (ttf && _sprites.TryGetValue(item.id, out mainSprite))
            {
                mainTexture = (NTexture)GetItemAsset(mainSprite.atlas);
                texScaleX   = mainTexture.root.uvRect.width / mainTexture.width;
                texScaleY   = mainTexture.root.uvRect.height / mainTexture.height;
            }

            buffer.Seek(0, 1);

            BitmapFont.BMGlyph bg;
            int cnt = buffer.ReadInt();

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

                bg = new BitmapFont.BMGlyph();
                char ch = buffer.ReadChar();
                font.AddChar(ch, bg);

                string img = buffer.ReadS();
                int    bx  = buffer.ReadInt();
                int    by  = buffer.ReadInt();
                bg.offsetX = buffer.ReadInt();
                bg.offsetY = buffer.ReadInt();
                bg.width   = buffer.ReadInt();
                bg.height  = buffer.ReadInt();
                bg.advance = buffer.ReadInt();
                bg.channel = buffer.ReadByte();
                if (bg.channel == 1)
                {
                    bg.channel = 3;
                }
                else if (bg.channel == 2)
                {
                    bg.channel = 2;
                }
                else if (bg.channel == 3)
                {
                    bg.channel = 1;
                }

                if (ttf)
                {
                    if (mainSprite.rotated)
                    {
                        bg.uv[0] = new Vector2((float)(by + bg.height + mainSprite.rect.x) * texScaleX,
                                               1 - (float)(mainSprite.rect.yMax - bx) * texScaleY);
                        bg.uv[1] = new Vector2(bg.uv[0].x - (float)bg.height * texScaleX, bg.uv[0].y);
                        bg.uv[2] = new Vector2(bg.uv[1].x, bg.uv[0].y + (float)bg.width * texScaleY);
                        bg.uv[3] = new Vector2(bg.uv[0].x, bg.uv[2].y);
                    }
                    else
                    {
                        bg.uv[0] = new Vector2((float)(bx + mainSprite.rect.x) * texScaleX,
                                               1 - (float)(by + bg.height + mainSprite.rect.y) * texScaleY);
                        bg.uv[1] = new Vector2(bg.uv[0].x, bg.uv[0].y + (float)bg.height * texScaleY);
                        bg.uv[2] = new Vector2(bg.uv[0].x + (float)bg.width * texScaleX, bg.uv[1].y);
                        bg.uv[3] = new Vector2(bg.uv[2].x, bg.uv[0].y);
                    }

                    bg.lineHeight = lineHeight;
                }
                else
                {
                    PackageItem charImg;
                    if (_itemsById.TryGetValue(img, out charImg))
                    {
                        GetItemAsset(charImg);
                        Rect uvRect = charImg.texture.uvRect;
                        bg.uv[0] = uvRect.position;
                        bg.uv[1] = new Vector2(uvRect.xMin, uvRect.yMax);
                        bg.uv[2] = new Vector2(uvRect.xMax, uvRect.yMax);
                        bg.uv[3] = new Vector2(uvRect.xMax, uvRect.yMin);
                        if (charImg.texture.rotated)
                        {
                            NGraphics.RotateUV(bg.uv, ref uvRect);
                        }
                        bg.width  = charImg.texture.width;
                        bg.height = charImg.texture.height;

                        if (mainTexture == null)
                        {
                            mainTexture = charImg.texture.root;
                        }
                    }

                    if (fontSize == 0)
                    {
                        fontSize = bg.height;
                    }

                    if (bg.advance == 0)
                    {
                        if (xadvance == 0)
                        {
                            bg.advance = bg.offsetX + bg.width;
                        }
                        else
                        {
                            bg.advance = xadvance;
                        }
                    }

                    bg.lineHeight = bg.offsetY < 0 ? bg.height : (bg.offsetY + bg.height);
                    if (bg.lineHeight < font.size)
                    {
                        bg.lineHeight = font.size;
                    }
                }

                buffer.position = nextPos;
            }

            font.size        = fontSize;
            font.mainTexture = mainTexture;
            if (!font.hasChannel)
            {
                font.shader = ShaderConfig.imageShader;
            }
        }
예제 #19
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;
		}
예제 #20
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;
            }
        }
예제 #21
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;
            }
        }
예제 #22
0
파일: UIPackage.cs 프로젝트: yinlei/Fishing
 NTexture CreateSpriteTexture(AtlasSprite sprite)
 {
     PackageItem atlasItem;
     if (_itemsById.TryGetValue(sprite.atlas, out atlasItem))
         return new NTexture((NTexture)GetItemAsset(atlasItem), sprite.rect);
     else
     {
         Debug.LogWarning("FairyGUI: " + sprite.atlas + " not found in " + this.name);
         return NTexture.Empty;
     }
 }
예제 #23
0
            public AtlasSprite(AtlasSprite sprite)
            {
                Region = sprite.Region;

                _originalOffsetX = sprite._originalOffsetX;
                _originalOffsetY = sprite._originalOffsetY;

                Set(sprite);
            }