Example #1
0
        static void CopySpriteLibraryToOverride(List <SpriteLibCategoryOverride> libOverride, SerializedProperty lib)
        {
            libOverride.Clear();
            if (lib.arraySize == 0)
            {
                return;
            }

            var categoryEntries = lib.GetArrayElementAtIndex(0);

            for (var i = 0; i < lib.arraySize; ++i)
            {
                var overrideCategory = new SpriteLibCategoryOverride()
                {
                    categoryList       = new List <SpriteCategoryEntry>(),
                    entryOverrideCount = 0,
                    fromMain           = false,
                    name            = categoryEntries.FindPropertyRelative(SpriteLibraryPropertyString.name).stringValue,
                    overrideEntries = new List <SpriteCategoryEntryOverride>()
                };
                var entries = categoryEntries.FindPropertyRelative(SpriteLibraryPropertyString.categoryList);
                var overrideCategoryEntries = overrideCategory.overrideEntries;
                if (entries.arraySize > 0)
                {
                    var entry = entries.GetArrayElementAtIndex(0);
                    for (var j = 0; j < entries.arraySize; ++j)
                    {
                        overrideCategoryEntries.Add(new SpriteCategoryEntryOverride()
                        {
                            fromMain       = false,
                            name           = entry.FindPropertyRelative(SpriteLibraryPropertyString.name).stringValue,
                            sprite         = (Sprite)entry.FindPropertyRelative(SpriteLibraryPropertyString.sprite).objectReferenceValue,
                            spriteOverride = (Sprite)entry.FindPropertyRelative(SpriteLibraryPropertyString.sprite).objectReferenceValue
                        });
                        entry.Next(false);
                    }
                }
                libOverride.Add(overrideCategory);
                categoryEntries.Next(false);
            }
        }
 static void ConvertToSourceAsset()
 {
     foreach (var obj in Selection.objects)
     {
         if (obj is SpriteLibraryAsset)
         {
             var asset            = (SpriteLibraryAsset)obj;
             var path             = AssetDatabase.GetAssetPath(asset);
             var currentAssetPath = Path.GetDirectoryName(path);
             var fileName         = Path.GetFileNameWithoutExtension(path);
             var convertFileName  = fileName + ".spriteLib";
             convertFileName = AssetDatabase.GenerateUniqueAssetPath(Path.Combine(currentAssetPath, convertFileName));
             var convertAsset = ScriptableObject.CreateInstance <SpriteLibrarySourceAsset>();
             convertAsset.library = new List <SpriteLibCategoryOverride>(asset.categories.Count);
             for (int i = 0; i < asset.categories.Count; ++i)
             {
                 var category    = asset.categories[i];
                 var newCategory = new SpriteLibCategoryOverride()
                 {
                     overrideEntries    = new List <SpriteCategoryEntryOverride>(category.categoryList.Count),
                     name               = category.name,
                     entryOverrideCount = 0,
                     fromMain           = false
                 };
                 convertAsset.library.Add(newCategory);
                 for (int j = 0; j < category.categoryList.Count; ++j)
                 {
                     newCategory.overrideEntries.Add(new SpriteCategoryEntryOverride()
                     {
                         name           = category.categoryList[j].name,
                         sprite         = null,
                         fromMain       = false,
                         spriteOverride = category.categoryList[j].sprite
                     });
                 }
             }
             SpriteLibrarySourceAssetImporter.SaveSpriteLibrarySourceAsset(convertAsset, convertFileName);
         }
     }
     AssetDatabase.Refresh();
 }