Skip to content

Commit 9fb0931

Browse files
committed
Ver3.0.0-alpha.2
1 parent 7d34015 commit 9fb0931

10 files changed

Lines changed: 356 additions & 181 deletions

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

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
using UnityEngine;
66
using jp.unisakistudio.posingsystem;
77
using VRC.SDK3.Avatars.Components;
8+
using System.IO;
89

910
namespace jp.unisakistudio.posingsystemeditor
1011
{
1112
public class PosingAnimationAdjustmentWindow : EditorWindow
1213
{
1314
public bool IsOpen = false;
14-
private const string DefaultAdjustmentFolderRoot = "Packages/jp.unisakistudio.posingsystem/Resources";
15+
private const string DefaultAdjustmentFolderRoot = "Assets/UnisakiStudio/GeneratedResources";
1516
private static readonly char[] InvalidFileNameChars = System.IO.Path.GetInvalidFileNameChars();
1617

1718
// マッスル名の日本語翻訳配列(HumanTrait.MuscleCountに対応)
@@ -22,6 +23,7 @@ public class PosingAnimationAdjustmentWindow : EditorWindow
2223
private readonly List<MuscleGroup> _muscleGroups = new();
2324

2425
private PosingSystem _posingSystem;
26+
private string _posingSystemInstanceId = "";
2527
private readonly List<AnimationEntry> _animationEntries = new();
2628
private string[] _animationLabels = Array.Empty<string>();
2729
private int _selectedAnimationIndex = -1;
@@ -713,6 +715,7 @@ private void Initialize(PosingSystem posingSystem)
713715
IsOpen = true;
714716

715717
_posingSystem = posingSystem;
718+
_posingSystemInstanceId = UnityEditor.GlobalObjectId.GetGlobalObjectIdSlow(_posingSystem).ToString();
716719
BuildMuscleGroups();
717720
RebuildAnimationEntries();
718721

@@ -868,6 +871,14 @@ private void OnGUI()
868871

869872
// Undo操作による値変更をチェック
870873
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+
}
871882

872883
if (_posingSystem == null)
873884
{
@@ -1320,7 +1331,7 @@ private void DuplicateAndSaveAllAdjustmentClips()
13201331
}
13211332
else
13221333
{
1323-
EditorUtility.DisplayDialog("情報", "複製保存する変更が見つかりませんでした。", "OK");
1334+
EditorUtility.DisplayDialog("情報", "複製保存する変更はありませんでした。", "OK");
13241335
}
13251336
}
13261337

@@ -2258,14 +2269,20 @@ private string GetAdjustmentFolderPath()
22582269
if (string.IsNullOrEmpty(folder))
22592270
{
22602271
folder = DefaultAdjustmentFolderRoot;
2272+
if (!Directory.Exists(folder))
2273+
{
2274+
Directory.CreateDirectory(folder);
2275+
}
2276+
var folderObject = AssetDatabase.LoadMainAssetAtPath(folder);
2277+
AssetDatabase.SetLabels(folderObject, new string[] { label });
22612278
}
22622279
var avatarName = _posingSystem.GetAvatar().gameObject.name;
22632280
avatarName = SanitizeFileName(avatarName);
22642281
if (string.IsNullOrEmpty(avatarName))
22652282
{
22662283
avatarName = "PosingSystem";
22672284
}
2268-
return $"{folder}/Generated/{avatarName}";
2285+
return $"{folder}/{avatarName}";
22692286
}
22702287

22712288
private static string SanitizeFileName(string value)

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

Lines changed: 12 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ private void AutoDetectAvatarPrefabsAndNames()
7777
string commonPath = GetCommonPath(variantPaths);
7878
if (string.IsNullOrEmpty(commonPath)) return;
7979

80-
Debug.Log($"検出されたアバターデータフォルダ: {commonPath}");
80+
Debug.Log($"[PosingSystem]検出されたアバターデータフォルダ: {commonPath}");
8181

8282
// 共通フォルダ配下のすべてのPrefabとFBXを検索
8383
var allAssets = AssetDatabase.FindAssets("t:GameObject", new[] { commonPath });
@@ -128,7 +128,7 @@ private void AutoDetectAvatarPrefabsAndNames()
128128
}
129129
}
130130

131-
Debug.Log($"自動検出完了: {targetAvatarPrefabs.Count}個のPrefab/FBX, {targetGameObjectNames.Count}個の名前");
131+
Debug.Log($"[PosingSystem]自動検出完了: {targetAvatarPrefabs.Count}個のPrefab/FBX, {targetGameObjectNames.Count}個の名前");
132132
}
133133

134134
private string GetCommonPath(List<string> paths)
@@ -288,64 +288,28 @@ private void CreatePreset()
288288
}
289289

290290
// PosingSystemResourceFolderを探す
291-
var resourceFolderGuids = AssetDatabase.FindAssets("l:PosingSystemResourceFolder");
292-
string resourceFolderPath = "";
293-
294-
if (resourceFolderGuids.Length > 0)
295-
{
296-
// 複数ある場合は最初のものを使用するか、特定のルールで選ぶか。ここでは最初に見つかったフォルダを使用。
297-
resourceFolderPath = AssetDatabase.GUIDToAssetPath(resourceFolderGuids[0]);
298-
if (!AssetDatabase.IsValidFolder(resourceFolderPath))
299-
{
300-
resourceFolderPath = "Assets"; // フォールバック
301-
}
302-
}
303-
else
304-
{
305-
// ラベルが見つからない場合、現在のスクリプトの位置から推測するか、Assets直下にする
306-
resourceFolderPath = "Assets";
307-
}
308-
309-
// Generatedフォルダを確保
310-
string generatedFolderPath = Path.Combine(resourceFolderPath, "Generated").Replace("\\", "/");
311-
if (!AssetDatabase.IsValidFolder(generatedFolderPath))
312-
{
313-
AssetDatabase.CreateFolder(resourceFolderPath, "Generated");
314-
}
291+
var generatedFolderPath = PosingSystemEditor.GetGeneratedFolderPath();
315292

316293
// フォルダ作成 (名前重複回避)
317-
string targetFolderName = avatarName;
318-
string targetFolderPath = Path.Combine(generatedFolderPath, targetFolderName).Replace("\\", "/");
319-
320-
if (AssetDatabase.IsValidFolder(targetFolderPath))
321-
{
322-
// 重複回避ロジック
323-
int count = 1;
324-
while (AssetDatabase.IsValidFolder(targetFolderPath + " " + count))
325-
{
326-
count++;
327-
}
328-
targetFolderName = targetFolderName + " " + count;
329-
targetFolderPath = targetFolderPath + " " + count;
330-
}
331-
332-
AssetDatabase.CreateFolder(generatedFolderPath, targetFolderName);
294+
string targetFolderPath = Path.Combine(generatedFolderPath, avatarName).Replace("\\", "/");
295+
targetFolderPath = AssetDatabase.GenerateUniqueAssetPath(targetFolderPath);
296+
Directory.CreateDirectory(targetFolderPath);
333297

334298
try
335299
{
336300
// PosingSystemをクローンして初期化
337301
GameObject tempObj = Instantiate(sourcePosingSystem.gameObject);
338302
PosingSystem tempPs = tempObj.GetComponent<PosingSystem>();
339-
303+
340304
// プロパティ初期化
341305
tempPs.developmentMode = false;
342306
tempPs.previewAvatarObject = null; // プレビューアバターは保存しない
343307
tempPs.isWarning = false;
344308
tempPs.isError = false;
345-
309+
346310
// 調整アニメーションをコピーして参照を更新
347311
CopyAndUpdateAdjustmentClips(tempPs, targetFolderPath);
348-
312+
349313
// Preset作成
350314
Preset preset = new Preset(tempPs);
351315
string presetPath = Path.Combine(targetFolderPath, avatarName + "_Preset.preset").Replace("\\", "/");
@@ -357,12 +321,12 @@ private void CreatePreset()
357321
// PosingSystemPresetDefines作成
358322
var defines = CreateInstance<PosingSystemPresetDefines>();
359323
var presetDefine = new PosingSystemPresetDefines.PresetDefine();
360-
324+
361325
presetDefine.avatarName = avatarName;
362326
presetDefine.prefabs = new List<GameObject>(applicablePrefabs.Where(x => x != null));
363327
presetDefine.preset = preset;
364328
presetDefine.prefabsNames = new List<string>(targetGameObjectNames.Where(x => !string.IsNullOrEmpty(x)));
365-
329+
366330
// Prefab GUIDのハッシュ化
367331
presetDefine.prefabsHashes = new List<string>();
368332
foreach (var prefab in targetAvatarPrefabs)
@@ -383,7 +347,7 @@ private void CreatePreset()
383347

384348
AssetDatabase.SaveAssets();
385349
AssetDatabase.Refresh();
386-
350+
387351
// 作成したフォルダを選択状態にする
388352
var folderObj = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(targetFolderPath);
389353
Selection.activeObject = folderObj;

0 commit comments

Comments
 (0)