void ISpriteEditorDataProvider.Apply()
        {
            var so = GetSerializedObject();

            m_SpriteSingle.Apply(so);
            var spriteSheetSO = so.FindProperty("m_SpriteSheet.m_Sprites");
            Dictionary <GUID, SpriteDataExt> newSprites = new Dictionary <GUID, SpriteDataExt>();

            foreach (var newSprite in m_SpritesMultiple)
            {
                newSprites.Add(newSprite.spriteID, newSprite);
            }

            if (spriteSheetSO.arraySize > 0)
            {
                var validateCurrent = spriteSheetSO.GetArrayElementAtIndex(0);
                for (int i = 0; i < spriteSheetSO.arraySize; ++i)
                {
                    var guid = SpriteRect.GetSpriteIDFromSerializedProperty(validateCurrent);
                    // find the GUID in our sprite list and apply to it;
                    if (newSprites.TryGetValue(guid, out SpriteDataExt smd))
                    {
                        smd.Apply(validateCurrent);
                        newSprites.Remove(guid);
                        validateCurrent.Next(false);
                    }
                    else// we can't find it, it is already deleted
                    {
                        spriteSheetSO.DeleteArrayElementAtIndex(i);
                        --i;
                    }
                }
            }

            // Add new ones
            int newCount = newSprites.Count();

            if (newCount > 0)
            {
                var idx = spriteSheetSO.arraySize;
                spriteSheetSO.arraySize += newCount;
                var addCurrent = spriteSheetSO.GetArrayElementAtIndex(idx);
                foreach (var newSprite in newSprites.Values)
                {
                    newSprite.Apply(addCurrent);
                    addCurrent.Next(false);
                }
            }

            SpriteSecondaryTextureDataTransfer.Apply(so, m_SecondaryTextureDataTransfer);
            so.ApplyModifiedPropertiesWithoutUndo();
        }
        void ISpriteEditorDataProvider.InitSpriteEditorDataProvider()
        {
            var so            = new SerializedObject(m_TextureImporter);
            var spriteSheetSO = so.FindProperty("m_SpriteSheet.m_Sprites");

            m_SpritesMultiple = new List <SpriteDataExt>();
            m_SpriteSingle    = new SpriteDataExt(so);

            for (int i = 0; i < spriteSheetSO.arraySize; ++i)
            {
                var sp   = spriteSheetSO.GetArrayElementAtIndex(i);
                var data = new SpriteDataExt(sp);
                m_SpritesMultiple.Add(data);
            }
            m_SecondaryTextureDataTransfer = SpriteSecondaryTextureDataTransfer.Load(so);
        }
        void ISpriteEditorDataProvider.Apply()
        {
            var so = new SerializedObject(m_TextureImporter);

            m_SpriteSingle.Apply(so);
            var spriteSheetSO = so.FindProperty("m_SpriteSheet.m_Sprites");

            GUID[] guids = new GUID[spriteSheetSO.arraySize];
            for (int i = 0; i < spriteSheetSO.arraySize; ++i)
            {
                var element = spriteSheetSO.GetArrayElementAtIndex(i);
                guids[i] = SpriteRect.GetSpriteIDFromSerializedProperty(element);
                // find the GUID in our sprite list and apply to it;
                var smd = m_SpritesMultiple.Find(x => x.spriteID == guids[i]);
                if (smd == null) // we can't find it, it is already deleted
                {
                    spriteSheetSO.DeleteArrayElementAtIndex(i);
                    --i;
                }
                else
                {
                    smd.Apply(element);
                }
            }

            // Add new ones
            var newSprites = m_SpritesMultiple.Where(x => !guids.Contains(x.spriteID));

            foreach (var newSprite in newSprites)
            {
                spriteSheetSO.InsertArrayElementAtIndex(spriteSheetSO.arraySize);
                var element = spriteSheetSO.GetArrayElementAtIndex(spriteSheetSO.arraySize - 1);
                newSprite.Apply(element);
            }

            SpriteSecondaryTextureDataTransfer.Apply(so, m_SecondaryTextureDataTransfer);
            so.ApplyModifiedPropertiesWithoutUndo();
        }
Ejemplo n.º 4
0
        void ISpriteEditorDataProvider.InitSpriteEditorDataProvider()
        {
            var so = GetSerializedObject();

            var spriteSheetSo = so.FindProperty("m_SpriteSheet.m_Sprites");

            m_SpritesMultiple = new List <SpriteDataExt>();
            m_SpriteSingle    = new SpriteDataExt(so);

            if (spriteSheetSo.arraySize > 0)
            {
                var sp = spriteSheetSo.GetArrayElementAtIndex(0);
                for (int i = 0; i < spriteSheetSo.arraySize; ++i)
                {
                    var data = new SpriteDataExt(sp);
                    m_SpritesMultiple.Add(data);
                    sp.Next(false);
                }
            }
            m_SecondaryTextureDataTransfer = SpriteSecondaryTextureDataTransfer.Load(so);

            m_NameFileIdPairs = GetSerializedNameFileIdTable(so);
        }