1+ using System . Collections . Generic ;
2+ using System . Linq ;
3+ using UnityEditor ;
4+ using UnityEngine ;
5+
6+ namespace Giezi . Tools
7+ {
8+ public class SOVFixer
9+ {
10+ [ MenuItem ( "Tools/GieziTools/SOVariant/Fix SOVs" ) ]
11+ public static void FixSOVs ( )
12+ {
13+ IEnumerable < ScriptableObject > scriptableObjects =
14+ AssetDatabase . GetAllAssetPaths ( )
15+ . Where ( s => s . EndsWith ( ".asset" ) && s . StartsWith ( "Assets/" ) )
16+ . Select ( AssetDatabase . LoadAssetAtPath < ScriptableObject > )
17+ . Where ( o => o != null )
18+ . Where ( o => o . GetType ( ) . IsDefined ( typeof ( SOVariantAttribute ) , true ) ) ;
19+
20+ var _library = SOVariantDataAccessor . SoVariantDataLibrary ;
21+ Dictionary < ScriptableObject , SOVariantData > _localLibrary = new ( ) ;
22+ foreach ( ScriptableObject scriptableObject in scriptableObjects )
23+ {
24+ _localLibrary . Add ( scriptableObject , _library . GetSOVariantDataForTarget ( scriptableObject ) ) ;
25+ }
26+
27+ foreach ( SOVariantData soVariantData in _localLibrary . Values )
28+ {
29+ soVariantData . Children = new List < ScriptableObject > ( ) ;
30+ }
31+
32+ foreach ( KeyValuePair < ScriptableObject , SOVariantData > keyValuePair in _localLibrary )
33+ {
34+ if ( keyValuePair . Value . Parent != null )
35+ {
36+ _localLibrary [ keyValuePair . Value . Parent ] . Children . Add ( keyValuePair . Key ) ;
37+ }
38+ }
39+
40+ foreach ( KeyValuePair < ScriptableObject , SOVariantData > keyValuePair in _localLibrary )
41+ {
42+ _library . WriteToLibrary ( keyValuePair . Key , keyValuePair . Value . Parent ,
43+ keyValuePair . Value . Overridden , keyValuePair . Value . Children ) ;
44+ }
45+
46+ foreach ( KeyValuePair < ScriptableObject , SOVariantData > keyValuePair in _localLibrary )
47+ {
48+ if ( keyValuePair . Value . Children is { Count : > 0 } )
49+ {
50+ SOVariant < ScriptableObject > sov = new SOVariant < ScriptableObject > ( keyValuePair . Key ) ;
51+ sov . SaveData ( keyValuePair . Value . Overridden ) ;
52+ }
53+ }
54+
55+ EditorUtility . SetDirty ( _library ) ;
56+ AssetDatabase . SaveAssets ( ) ;
57+ AssetDatabase . Refresh ( ) ;
58+ }
59+ }
60+ }
0 commit comments