Skip to content

Commit d23845c

Browse files
committed
Ver3.0.0-alpha.3
1 parent 9fb0931 commit d23845c

8 files changed

Lines changed: 580 additions & 77 deletions

‎Packages/jp.unisakistudio.posingsystem/Editor/AnimatorControllerDeepCopy.cs‎

Lines changed: 398 additions & 0 deletions
Large diffs are not rendered by default.

‎Packages/jp.unisakistudio.posingsystem/Editor/AnimatorControllerDeepCopy.cs.meta‎

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Packages/jp.unisakistudio.posingsystem/Editor/PosingAnimationAdjustmentWindow.cs‎

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace jp.unisakistudio.posingsystemeditor
1111
{
1212
public class PosingAnimationAdjustmentWindow : EditorWindow
1313
{
14-
public bool IsOpen = false;
14+
private bool _isOpen = false;
1515
private const string DefaultAdjustmentFolderRoot = "Assets/UnisakiStudio/GeneratedResources";
1616
private static readonly char[] InvalidFileNameChars = System.IO.Path.GetInvalidFileNameChars();
1717

@@ -23,7 +23,6 @@ public class PosingAnimationAdjustmentWindow : EditorWindow
2323
private readonly List<MuscleGroup> _muscleGroups = new();
2424

2525
private PosingSystem _posingSystem;
26-
private string _posingSystemInstanceId = "";
2726
private readonly List<AnimationEntry> _animationEntries = new();
2827
private string[] _animationLabels = Array.Empty<string>();
2928
private int _selectedAnimationIndex = -1;
@@ -113,6 +112,11 @@ private class MuscleGroup
113112
public readonly List<int> Indexes = new();
114113
}
115114

115+
public bool IsOpen
116+
{
117+
get { return _isOpen && _posingSystem != null; }
118+
}
119+
116120
private string GetAnimationKey(AnimationEntry entry)
117121
{
118122
if (entry?.Layer?.menuName != null && entry?.Animation?.displayName != null)
@@ -696,6 +700,7 @@ public static void ShowWindow(PosingSystem posingSystem)
696700
foreach (var existWindow in Resources.FindObjectsOfTypeAll<PosingAnimationAdjustmentWindow>())
697701
{
698702
window = existWindow;
703+
existWindow.CleanupPreview();
699704
}
700705

701706
if (!window)
@@ -712,10 +717,9 @@ public static void ShowWindow(PosingSystem posingSystem)
712717

713718
private void Initialize(PosingSystem posingSystem)
714719
{
715-
IsOpen = true;
720+
_isOpen = true;
716721

717722
_posingSystem = posingSystem;
718-
_posingSystemInstanceId = UnityEditor.GlobalObjectId.GetGlobalObjectIdSlow(_posingSystem).ToString();
719723
BuildMuscleGroups();
720724
RebuildAnimationEntries();
721725

@@ -735,6 +739,18 @@ private void Initialize(PosingSystem posingSystem)
735739
Repaint();
736740
}
737741

742+
public void Close()
743+
{
744+
_isOpen = false;
745+
CleanupPreview();
746+
_posingSystem = null;
747+
_animationEntries.Clear();
748+
_animationLabels = Array.Empty<string>();
749+
_selectedAnimationIndex = -1;
750+
_adjustments = null;
751+
Repaint();
752+
}
753+
738754
private void OnEnable()
739755
{
740756
if (!IsOpen)
@@ -747,10 +763,10 @@ private void OnEnable()
747763
Selection.selectionChanged += OnSelectionChanged;
748764
BuildMuscleGroups();
749765
RebuildAnimationEntries();
750-
766+
751767
// 全ての姿勢の調整値を事前に読み込み
752768
PreloadAllAdjustmentData();
753-
769+
754770
if (_animationEntries.Count > 0)
755771
{
756772
_selectedAnimationIndex = Mathf.Clamp(_selectedAnimationIndex, 0, _animationEntries.Count - 1);
@@ -865,20 +881,12 @@ private void OnGUI()
865881
if (!IsOpen)
866882
{
867883
EditorGUILayout.HelpBox("アニメーションの調整は現在停止中です", MessageType.Warning);
868-
884+
869885
return;
870886
}
871887

872888
// Undo操作による値変更をチェック
873889
CheckForUndoChanges();
874-
875-
if (_posingSystem == null && _posingSystemInstanceId != "")
876-
{
877-
Debug.Log("[PosingSystem] PosingSystem が見つかりません。InstanceID: " + _posingSystemInstanceId + ", SelectedObject: " + UnityEditor.GlobalObjectId.GetGlobalObjectIdSlow(Selection.activeGameObject));
878-
UnityEditor.GlobalObjectId globalObjectId;
879-
UnityEditor.GlobalObjectId.TryParse(_posingSystemInstanceId, out globalObjectId);
880-
_posingSystem = UnityEditor.GlobalObjectId.GlobalObjectIdentifierToObjectSlow(globalObjectId) as PosingSystem;
881-
}
882890

883891
if (_posingSystem == null)
884892
{
@@ -2339,15 +2347,17 @@ private void ApplyPreviewPose()
23392347
{
23402348
originalPosition = _posingSystem.GetAvatar().transform.position;
23412349
originalRotation = _posingSystem.GetAvatar().transform.rotation;
2342-
2350+
23432351
// プレビューアバターが元のアバターと異なる場合のみ、元のアバターを非アクティブにする
23442352
if (_previewAvatar.gameObject != _posingSystem.GetAvatar().gameObject)
23452353
{
23462354
_posingSystem.GetAvatar().gameObject.SetActive(false);
2355+
EditorUtility.SetDirty(_posingSystem.gameObject);
23472356
}
23482357
}
23492358

23502359
_previewAvatar.gameObject.SetActive(true);
2360+
EditorUtility.SetDirty(_posingSystem.gameObject);
23512361

23522362
HumanPoseHandler poseHandler = null;
23532363
try
@@ -2410,12 +2420,14 @@ private void CleanupPreview()
24102420
if (_posingSystem.GetAvatar() != null && _previewAvatar.gameObject != _posingSystem.GetAvatar().gameObject)
24112421
{
24122422
_previewAvatar.gameObject.SetActive(false);
2423+
EditorUtility.SetDirty(_posingSystem.gameObject);
24132424
}
24142425
_previewAvatar = null;
24152426
}
2416-
if (_posingSystem.GetAvatar() != null)
2427+
if (_posingSystem != null && _posingSystem.GetAvatar() != null)
24172428
{
24182429
_posingSystem.GetAvatar().gameObject.SetActive(true);
2430+
EditorUtility.SetDirty(_posingSystem.gameObject);
24192431
}
24202432
}
24212433

‎Packages/jp.unisakistudio.posingsystem/Editor/PosingSystemConverter.cs‎

Lines changed: 57 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)