Пример #1
0
        public void Deserialize(string animName)
        {
            UiAnimation.UiTexture uiTexture;
            UiAnimation.UiAnchor  array;
            XmlSerializer         xmlSerializer = new XmlSerializer(typeof(UiAnimation.UiSourceAnimation));

            xmlSerializer.UnknownNode      += new XmlNodeEventHandler(this.serializer_UnknownNode);
            xmlSerializer.UnknownAttribute += new XmlAttributeEventHandler(this.serializer_UnknownAttribute);
            TextAsset sourceData = UiAnimMgr.instance.GetSourceData(animName);

            if (sourceData == null)
            {
                Debug.Log(string.Concat("Could not find asset ", animName));
                return;
            }
            MemoryStream memoryStream = new MemoryStream(sourceData.bytes);

            UiAnimation.UiSourceAnimation uiSourceAnimation = xmlSerializer.Deserialize(memoryStream) as UiAnimation.UiSourceAnimation;
            memoryStream.Close();
            if (uiSourceAnimation == null)
            {
                Debug.Log("No ui animation.");
                return;
            }
            this.m_frame = uiSourceAnimation.frame;
            foreach (UiAnimation.UiSourceAnimGroup group in uiSourceAnimation.frame.animation.groups)
            {
                UiAnimation.UiAnimGroup uiAnimGroup = new UiAnimation.UiAnimGroup()
                {
                    m_parentKey  = group.parentKey,
                    m_bounceBack = false
                };
                if (group.looping == null)
                {
                    uiAnimGroup.m_looping = false;
                    uiAnimGroup.m_bounce  = false;
                }
                else if (group.looping == "REPEAT")
                {
                    uiAnimGroup.m_looping = true;
                    uiAnimGroup.m_bounce  = false;
                }
                else if (group.looping == "BOUNCE")
                {
                    uiAnimGroup.m_looping = true;
                    uiAnimGroup.m_bounce  = true;
                }
                foreach (UiAnimation.UiScale mScale in group.m_scales)
                {
                    if (mScale.m_childKey == null)
                    {
                        continue;
                    }
                    mScale.SetSmoothing();
                    uiAnimGroup.m_elements.Add(mScale);
                }
                foreach (UiAnimation.UiAlpha mAlpha in group.m_alphas)
                {
                    if (mAlpha.m_childKey == null)
                    {
                        continue;
                    }
                    mAlpha.SetSmoothing();
                    uiAnimGroup.m_elements.Add(mAlpha);
                }
                foreach (UiAnimation.UiRotation mRotation in group.m_rotations)
                {
                    if (mRotation.m_childKey == null)
                    {
                        continue;
                    }
                    mRotation.SetSmoothing();
                    uiAnimGroup.m_elements.Add(mRotation);
                }
                foreach (UiAnimation.UiTranslation mTranslation in group.m_translations)
                {
                    if (mTranslation.m_childKey == null)
                    {
                        continue;
                    }
                    mTranslation.SetSmoothing();
                    uiAnimGroup.m_elements.Add(mTranslation);
                }
                this.m_groups.Add(uiAnimGroup);
            }
            foreach (UiAnimation.UiLayer layer in uiSourceAnimation.frame.layers)
            {
                foreach (UiAnimation.UiSourceTexture texture in layer.textures)
                {
                    if (texture.m_parentKey != null)
                    {
                        this.m_textures.TryGetValue(texture.m_parentKey, out uiTexture);
                        if (uiTexture == null)
                        {
                            int d = 0;
                            UiTextureAtlasMemberRec recordFirstOrDefault = StaticDB.uiTextureAtlasMemberDB.GetRecordFirstOrDefault((UiTextureAtlasMemberRec memberRec) => (memberRec.CommittedName == null || texture.m_atlas == null ? false : memberRec.CommittedName.Equals(texture.m_atlas, StringComparison.OrdinalIgnoreCase)));
                            if (recordFirstOrDefault != null)
                            {
                                d = recordFirstOrDefault.ID;
                            }
                            Sprite sprite = null;
                            if (d > 0)
                            {
                                sprite = TextureAtlas.GetSprite(d);
                            }
                            else if (texture.m_resourceImage != null)
                            {
                                sprite = Resources.Load <Sprite>(texture.m_resourceImage);
                            }
                            if (sprite == null)
                            {
                                Debug.Log(string.Concat(new object[] { "Could not find sprite for textureAtlasMemberID ", d, " resourceImage ", texture.m_resourceImage, " in Ui Animation ", animName }));
                            }
                            else
                            {
                                UiAnimation.UiTexture mAtlas = new UiAnimation.UiTexture()
                                {
                                    m_alpha     = texture.m_alpha,
                                    m_alphaMode = texture.m_alphaMode
                                };
                                UiAnimation.UiTexture uiTexture1 = mAtlas;
                                if (texture.m_anchors.Count <= 0)
                                {
                                    array = null;
                                }
                                else
                                {
                                    array = texture.m_anchors.ToArray()[0];
                                }
                                uiTexture1.m_anchor    = array;
                                mAtlas.m_atlas         = texture.m_atlas;
                                mAtlas.m_resourceImage = texture.m_resourceImage;
                                mAtlas.m_width         = texture.m_width;
                                mAtlas.m_height        = texture.m_height;
                                mAtlas.m_hidden        = texture.m_hidden;
                                mAtlas.m_parentKey     = texture.m_parentKey;
                                mAtlas.m_sprite        = sprite;
                                this.m_textures.Add(texture.m_parentKey, mAtlas);
                            }
                        }
                        else
                        {
                            Debug.Log(string.Concat("Found duplicate texture ", texture.m_parentKey));
                        }
                    }
                }
            }
            List <UiAnimation.UiAnimElement> uiAnimElements = new List <UiAnimation.UiAnimElement>();

            foreach (UiAnimation.UiAnimGroup mGroup in this.m_groups)
            {
                mGroup.m_maxTime = 0f;
                foreach (UiAnimation.UiAnimElement mElement in mGroup.m_elements)
                {
                    UiAnimation.UiTexture uiTexture2 = null;
                    this.m_textures.TryGetValue(mElement.m_childKey, out uiTexture2);
                    if (uiTexture2 == null)
                    {
                        uiAnimElements.Add(mElement);
                        Debug.Log(string.Concat("Removing element with childKey ", mElement.m_childKey, ", no associated texture was found."));
                    }
                    else
                    {
                        mElement.m_texture = uiTexture2;
                        float totalTime = mElement.GetTotalTime();
                        if (totalTime > mGroup.m_maxTime)
                        {
                            mGroup.m_maxTime = totalTime;
                        }
                    }
                }
                foreach (UiAnimation.UiAnimElement uiAnimElement in uiAnimElements)
                {
                    mGroup.m_elements.Remove(uiAnimElement);
                }
            }
        }
Пример #2
0
        public void Deserialize(string animName)
        {
            XmlSerializer xmlSerializer = new XmlSerializer(typeof(UiAnimation.UiSourceAnimation));

            xmlSerializer.UnknownNode      += this.serializer_UnknownNode;
            xmlSerializer.UnknownAttribute += this.serializer_UnknownAttribute;
            TextAsset sourceData = UiAnimMgr.instance.GetSourceData(animName);

            if (sourceData == null)
            {
                Debug.Log("Could not find asset " + animName);
                return;
            }
            MemoryStream memoryStream = new MemoryStream(sourceData.bytes);

            UiAnimation.UiSourceAnimation uiSourceAnimation = xmlSerializer.Deserialize(memoryStream) as UiAnimation.UiSourceAnimation;
            memoryStream.Close();
            if (uiSourceAnimation == null)
            {
                Debug.Log("No ui animation.");
                return;
            }
            this.m_frame = uiSourceAnimation.frame;
            foreach (UiAnimation.UiSourceAnimGroup uiSourceAnimGroup in uiSourceAnimation.frame.animation.groups)
            {
                UiAnimation.UiAnimGroup uiAnimGroup = new UiAnimation.UiAnimGroup();
                uiAnimGroup.m_parentKey  = uiSourceAnimGroup.parentKey;
                uiAnimGroup.m_bounceBack = false;
                if (uiSourceAnimGroup.looping == null)
                {
                    uiAnimGroup.m_looping = false;
                    uiAnimGroup.m_bounce  = false;
                }
                else if (uiSourceAnimGroup.looping == "REPEAT")
                {
                    uiAnimGroup.m_looping = true;
                    uiAnimGroup.m_bounce  = false;
                }
                else if (uiSourceAnimGroup.looping == "BOUNCE")
                {
                    uiAnimGroup.m_looping = true;
                    uiAnimGroup.m_bounce  = true;
                }
                foreach (UiAnimation.UiScale uiScale in uiSourceAnimGroup.m_scales)
                {
                    if (uiScale.m_childKey != null)
                    {
                        uiScale.SetSmoothing();
                        uiAnimGroup.m_elements.Add(uiScale);
                    }
                }
                foreach (UiAnimation.UiAlpha uiAlpha in uiSourceAnimGroup.m_alphas)
                {
                    if (uiAlpha.m_childKey != null)
                    {
                        uiAlpha.SetSmoothing();
                        uiAnimGroup.m_elements.Add(uiAlpha);
                    }
                }
                foreach (UiAnimation.UiRotation uiRotation in uiSourceAnimGroup.m_rotations)
                {
                    if (uiRotation.m_childKey != null)
                    {
                        uiRotation.SetSmoothing();
                        uiAnimGroup.m_elements.Add(uiRotation);
                    }
                }
                foreach (UiAnimation.UiTranslation uiTranslation in uiSourceAnimGroup.m_translations)
                {
                    if (uiTranslation.m_childKey != null)
                    {
                        uiTranslation.SetSmoothing();
                        uiAnimGroup.m_elements.Add(uiTranslation);
                    }
                }
                this.m_groups.Add(uiAnimGroup);
            }
            foreach (UiAnimation.UiLayer uiLayer in uiSourceAnimation.frame.layers)
            {
                using (List <UiAnimation.UiSourceTexture> .Enumerator enumerator7 = uiLayer.textures.GetEnumerator())
                {
                    while (enumerator7.MoveNext())
                    {
                        UiAnimation.UiSourceTexture texture = enumerator7.Current;
                        if (texture.m_parentKey != null)
                        {
                            UiAnimation.UiTexture uiTexture;
                            this.m_textures.TryGetValue(texture.m_parentKey, out uiTexture);
                            if (uiTexture != null)
                            {
                                Debug.Log("Found duplicate texture " + texture.m_parentKey);
                            }
                            else
                            {
                                int num = 0;
                                UiTextureAtlasMemberRec recordFirstOrDefault = StaticDB.uiTextureAtlasMemberDB.GetRecordFirstOrDefault((UiTextureAtlasMemberRec memberRec) => memberRec.CommittedName != null && texture.m_atlas != null && memberRec.CommittedName.Equals(texture.m_atlas, StringComparison.OrdinalIgnoreCase));
                                if (recordFirstOrDefault != null)
                                {
                                    num = recordFirstOrDefault.ID;
                                }
                                Sprite sprite = null;
                                if (num > 0)
                                {
                                    sprite = TextureAtlas.GetSprite(num);
                                }
                                else if (texture.m_resourceImage != null)
                                {
                                    sprite = Resources.Load <Sprite>(texture.m_resourceImage);
                                }
                                if (sprite != null)
                                {
                                    UiAnimation.UiTexture uiTexture2 = new UiAnimation.UiTexture();
                                    uiTexture2.m_alpha         = texture.m_alpha;
                                    uiTexture2.m_alphaMode     = texture.m_alphaMode;
                                    uiTexture2.m_anchor        = ((texture.m_anchors.Count <= 0) ? null : texture.m_anchors.ToArray()[0]);
                                    uiTexture2.m_atlas         = texture.m_atlas;
                                    uiTexture2.m_resourceImage = texture.m_resourceImage;
                                    uiTexture2.m_width         = texture.m_width;
                                    uiTexture2.m_height        = texture.m_height;
                                    uiTexture2.m_hidden        = texture.m_hidden;
                                    uiTexture2.m_parentKey     = texture.m_parentKey;
                                    uiTexture2.m_sprite        = sprite;
                                    this.m_textures.Add(texture.m_parentKey, uiTexture2);
                                }
                                else
                                {
                                    Debug.Log(string.Concat(new object[]
                                    {
                                        "Could not find sprite for textureAtlasMemberID ",
                                        num,
                                        " resourceImage ",
                                        texture.m_resourceImage,
                                        " in Ui Animation ",
                                        animName
                                    }));
                                }
                            }
                        }
                    }
                }
            }
            List <UiAnimation.UiAnimElement> list = new List <UiAnimation.UiAnimElement>();

            foreach (UiAnimation.UiAnimGroup uiAnimGroup2 in this.m_groups)
            {
                uiAnimGroup2.m_maxTime = 0f;
                foreach (UiAnimation.UiAnimElement uiAnimElement in uiAnimGroup2.m_elements)
                {
                    UiAnimation.UiTexture uiTexture3 = null;
                    this.m_textures.TryGetValue(uiAnimElement.m_childKey, out uiTexture3);
                    if (uiTexture3 != null)
                    {
                        uiAnimElement.m_texture = uiTexture3;
                        float totalTime = uiAnimElement.GetTotalTime();
                        if (totalTime > uiAnimGroup2.m_maxTime)
                        {
                            uiAnimGroup2.m_maxTime = totalTime;
                        }
                    }
                    else
                    {
                        list.Add(uiAnimElement);
                        Debug.Log("Removing element with childKey " + uiAnimElement.m_childKey + ", no associated texture was found.");
                    }
                }
                foreach (UiAnimation.UiAnimElement item in list)
                {
                    uiAnimGroup2.m_elements.Remove(item);
                }
            }
        }