@@ -148,13 +148,14 @@ protected override void Configure()
148148
149149 foreach ( var posingSystem in ctx . AvatarRootObject . GetComponentsInChildren < PosingSystem > ( ) )
150150 {
151- if ( posingSystem . data != null && posingSystem . data != GetDefineSerializeJson ( posingSystem ) )
151+ if ( posingSystem . data != null && posingSystem . data != GetDefineSerializeJson ( posingSystem , true ) )
152152 {
153153 ErrorReport . ReportError ( errorLocalizer , ErrorSeverity . NonFatal , "オブジェクトの設定が更新されています。再度プレビルドを行ってください" , posingSystem . name ) ;
154154 }
155155
156- if ( posingSystem . data == null || posingSystem . data . Length == 0 || posingSystem . data != GetDefineSerializeJson ( posingSystem ) )
156+ if ( posingSystem . data == null || posingSystem . data . Length == 0 || posingSystem . data != GetDefineSerializeJson ( posingSystem , true ) )
157157 {
158+ Debug . Log ( "ConvertToModularAvatarComponents: " + ctx . AvatarRootObject . name + " " + posingSystem . name ) ;
158159 ConvertToModularAvatarComponents ( posingSystem ) ;
159160 }
160161 }
@@ -182,7 +183,7 @@ protected override void Configure()
182183
183184 foreach ( var posingSystem in ctx . AvatarRootObject . GetComponentsInChildren < PosingSystem > ( ) )
184185 {
185- if ( posingSystem . previewAvatarObject == null )
186+ if ( posingSystem . thumbnailPackObject == null )
186187 {
187188 TakeScreenshot ( posingSystem , true , true ) ;
188189 SetMenuIcon ( posingSystem ) ;
@@ -510,15 +511,15 @@ private static string GetAssetContentHash(UnityEngine.Object obj)
510511 return hash . ToString ( ) ;
511512 }
512513
513- public static string GetDefineSerializeJson ( PosingSystem posingSystem )
514+ public static string GetDefineSerializeJson ( PosingSystem posingSystem , bool ignoreInstanceId = false )
514515 {
515516 // Map to DTOs that do NOT have previewImage fields
516517 var dto = new DefineSerializeRootDTO
517518 {
518519 list = new System . Collections . Generic . List < LayerDefineDTO > ( ) ,
519520 overrides = new System . Collections . Generic . List < OverrideAnimationDefineDTO > ( ) ,
520521 version = VersionName ,
521- savedInstanceId = UnityEditor . GlobalObjectId . GetGlobalObjectIdSlow ( posingSystem ) . ToString ( ) ,
522+ savedInstanceId = ignoreInstanceId ? posingSystem . savedInstanceId : UnityEditor . GlobalObjectId . GetGlobalObjectIdSlow ( posingSystem ) . ToString ( ) ,
522523 } ;
523524
524525 if ( posingSystem . defines != null )
@@ -879,9 +880,22 @@ public static void CreateOriginalAnimatorController(PosingSystem posingSystem)
879880 {
880881 // 共通ポージングAnimatorを探す
881882 var maMergeAnimator = GetCommonMergeAnimator ( posingSystem ) ;
883+
884+ if ( maMergeAnimator == null || maMergeAnimator . animator == null )
885+ {
886+ Debug . LogError ( "[PosingSystem] MergeAnimator or its animator is null" ) ;
887+ return ;
888+ }
889+
890+ var animatorController = maMergeAnimator . animator as AnimatorController ;
891+ if ( animatorController == null )
892+ {
893+ Debug . LogError ( "[PosingSystem] Animator is not an AnimatorController" ) ;
894+ return ;
895+ }
882896
883897 // 設定されているAnimatorControllerが標準のものかどうかをチェックし、標準じゃないなら処理はもうしなくていい
884- var isDefault = ( maMergeAnimator . animator as AnimatorController ) . layers . Any ( l => l . name == "USSPS_IsDefault" ) ;
898+ var isDefault = animatorController . layers . Any ( l => l . name == "USSPS_IsDefault" ) ;
885899 if ( ! isDefault )
886900 {
887901 // 他のPosingSystemの共通ポージングAnimatorにも同じものを設定する
@@ -912,28 +926,43 @@ public static void CreateOriginalAnimatorController(PosingSystem posingSystem)
912926 }
913927 var avatar = posingSystem . GetAvatar ( ) ;
914928
915- var templeteAnimatorControllerPath = AssetDatabase . GetAssetPath ( maMergeAnimator . animator ) ;
929+ var templeteAnimatorControllerPath = AssetDatabase . GetAssetPath ( animatorController ) ;
916930
917931 // AnimatorControllerの保存先を決める
918932 var directoryPath = PosingSystemEditor . GetGeneratedFolderPath ( ) ;
919933 var newAnimatorControllerPath = directoryPath + "/" + avatar . name + ".controller" ;
920934 newAnimatorControllerPath = AssetDatabase . GenerateUniqueAssetPath ( newAnimatorControllerPath ) ;
935+ Debug . Log ( "newAnimatorControllerPath: " + newAnimatorControllerPath ) ;
921936
922937 // 複製を実行
923- AssetDatabase . CopyAsset ( templeteAnimatorControllerPath , newAnimatorControllerPath ) ;
938+ Debug . Log ( "templeteAnimatorControllerPath: " + templeteAnimatorControllerPath ) ;
939+ /*
940+ var newAnimatorController = new AnimatorController();
941+ EditorUtility.CopySerialized(maMergeAnimator.animator, newAnimatorController);
942+ AssetDatabase.CreateAsset(newAnimatorController, newAnimatorControllerPath);
943+ */
944+ var newAnimatorController = AnimatorControllerDeepCopy . CloneAnimatorController ( animatorController , newAnimatorControllerPath ) ;
945+ // AssetDatabase.CopyAsset(templeteAnimatorControllerPath, newAnimatorControllerPath);
946+
947+ if ( newAnimatorController == null )
948+ {
949+ Debug . LogError ( "Failed to clone AnimatorController" ) ;
950+ return ;
951+ }
924952
925953 // オブジェクトに割り当てる
926- maMergeAnimator . animator = AssetDatabase . LoadAssetAtPath < AnimatorController > ( newAnimatorControllerPath ) ;
954+ maMergeAnimator . animator = newAnimatorController ;
927955
928956 // 新しいAnimatorControllerの「USSPS_IsDefault」レイヤーを削除する
929- var animatorController = maMergeAnimator . animator as AnimatorController ;
930- var isDefaultLayerIndex = animatorController . layers . ToList ( ) . FindIndex ( l => l . name == "USSPS_IsDefault" ) ;
957+ var isDefaultLayerIndex = newAnimatorController . layers . ToList ( ) . FindIndex ( l => l . name == "USSPS_IsDefault" ) ;
931958 if ( isDefaultLayerIndex != - 1 )
932959 {
933- var layers = animatorController . layers . ToList ( ) ;
960+ var layers = newAnimatorController . layers . ToList ( ) ;
934961 layers . RemoveAt ( isDefaultLayerIndex ) ;
935- animatorController . layers = layers . ToArray ( ) ;
962+ newAnimatorController . layers = layers . ToArray ( ) ;
963+ EditorUtility . SetDirty ( newAnimatorController ) ;
936964 }
965+ AssetDatabase . SaveAssets ( ) ;
937966
938967 // 変更を記録
939968 Undo . RecordObject ( maMergeAnimator , "set animator controller" ) ;
@@ -1832,8 +1861,6 @@ public static void TakeScreenshot(PosingSystem posingSystem, bool force = false,
18321861 return ;
18331862 }
18341863
1835- PosingSystemEditor . CreateThumbnailPack ( posingSystem ) ;
1836-
18371864 var srcAvatar = posingSystem . GetAvatar ( ) ;
18381865 if ( srcAvatar == null )
18391866 {
@@ -1857,7 +1884,7 @@ public static void TakeScreenshot(PosingSystem posingSystem, bool force = false,
18571884 posingSystem . previewAvatarObject = clone ;
18581885 foreach ( var clonePosingSystem in clone . GetComponentsInChildren < PosingSystem > ( ) )
18591886 {
1860- clonePosingSystem . tag = "EditorOnly" ;
1887+ clonePosingSystem . gameObject . tag = "EditorOnly" ;
18611888 }
18621889 VRC . SDKBase . Editor . BuildPipeline . VRCBuildPipelineCallbacks . OnPreprocessAvatar ( clone ) ;
18631890 Object . DestroyImmediate ( clone . GetComponent < VRC . SDK3 . Avatars . Components . VRCAvatarDescriptor > ( ) ) ;
@@ -1893,7 +1920,10 @@ public static void TakeScreenshot(PosingSystem posingSystem, bool force = false,
18931920 TakeIconScreenshot ( animation , clone , camera , force ) ;
18941921 if ( ! AssetDatabase . IsSubAsset ( animation . previewImage ) )
18951922 {
1896- AssetDatabase . AddObjectToAsset ( animation . previewImage , posingSystem . thumbnailPackObject ) ;
1923+ if ( posingSystem . thumbnailPackObject != null )
1924+ {
1925+ AssetDatabase . AddObjectToAsset ( animation . previewImage , posingSystem . thumbnailPackObject ) ;
1926+ }
18971927 }
18981928 }
18991929 }
@@ -1909,7 +1939,10 @@ public static void TakeScreenshot(PosingSystem posingSystem, bool force = false,
19091939 TakeIconScreenshot ( animation , clone , camera , force ) ;
19101940 if ( ! AssetDatabase . IsSubAsset ( animation . previewImage ) )
19111941 {
1912- AssetDatabase . AddObjectToAsset ( animation . previewImage , posingSystem . thumbnailPackObject ) ;
1942+ if ( posingSystem . thumbnailPackObject != null )
1943+ {
1944+ AssetDatabase . AddObjectToAsset ( animation . previewImage , posingSystem . thumbnailPackObject ) ;
1945+ }
19131946 }
19141947 }
19151948 AssetDatabase . SaveAssets ( ) ;
@@ -1996,6 +2029,12 @@ void deepSearchControl(VRC.SDK3.Avatars.ScriptableObjects.VRCExpressionsMenu.Con
19962029 }
19972030 }
19982031
2032+ foreach ( var menuItem in posingSystem . GetComponentsInChildren < ModularAvatarMenuItem > ( ) )
2033+ {
2034+ controlHash [ ( menuItem . Control . parameter . name , ( int ) menuItem . Control . value ) ] = menuItem . Control ;
2035+ }
2036+
2037+
19992038 for ( int i = 0 ; i < posingSystem . defines . Count ; i ++ )
20002039 {
20012040 for ( int j = 0 ; j < posingSystem . defines [ i ] . animations . Count ; j ++ )
@@ -2004,7 +2043,6 @@ void deepSearchControl(VRC.SDK3.Avatars.ScriptableObjects.VRCExpressionsMenu.Con
20042043 if ( controlHash . ContainsKey ( ( posingSystem . defines [ i ] . paramName , animation . typeParameterValue ) ) )
20052044 {
20062045 controlHash [ ( posingSystem . defines [ i ] . paramName , animation . typeParameterValue ) ] . icon = animation . previewImage ;
2007- controlHash [ ( posingSystem . defines [ i ] . paramName , animation . typeParameterValue ) ] . icon . hideFlags = HideFlags . None ;
20082046 }
20092047 }
20102048 }
0 commit comments