Example #1
0
 protected override void Apply()
 {
     base.Apply();
     for (int i = 0; i < targets.Length; i++)
     {
         string path = ((AssetImporter)targets[i]).assetPath;
         var sourceAsset = (SpriteLibrarySourceAsset) extraDataTargets[i];
         SpriteLibrarySourceAssetImporter.SaveSpriteLibrarySourceAsset(sourceAsset, path);
     }
 }
Example #2
0
 protected override void InitializeExtraDataInstance(Object extraTarget, int targetIndex)
 {
     var obj = SpriteLibrarySourceAssetImporter.LoadSpriteLibrarySourceAsset(((AssetImporter) targets[targetIndex]).assetPath);
     if (obj != null)
     {
         var extraTargetSourceAsset = extraTarget as SpriteLibrarySourceAsset;
         extraTargetSourceAsset.library = obj.library;
         extraTargetSourceAsset.primaryLibraryID = obj.primaryLibraryID;
     }
 }
 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();
 }
 void OnPreprocessAsset()
 {
     if (assetImporter is SpriteLibrarySourceAssetImporter)
     {
         var obj = SpriteLibrarySourceAssetImporter.LoadSpriteLibrarySourceAsset(assetPath);
         if (obj != null)
         {
             SpriteLibraryAsset mainLibraryAsset = null;
             var mainLibraryAssetAssetPath       = AssetDatabase.GUIDToAssetPath(obj.primaryLibraryID);
             mainLibraryAsset = AssetDatabase.LoadAssetAtPath <SpriteLibraryAsset>(mainLibraryAssetAssetPath);
             var so      = new SerializedObject(obj);
             var library = so.FindProperty("m_Library");
             SpriteLibraryDataInspector.UpdateLibraryWithNewMainLibrary(mainLibraryAsset, library);
             if (so.hasModifiedProperties)
             {
                 so.ApplyModifiedPropertiesWithoutUndo();
                 SpriteLibrarySourceAssetImporter.SaveSpriteLibrarySourceAsset(obj, assetPath);
             }
         }
     }
 }