diff --git a/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/SaveFileDialog.cs b/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/SaveFileDialog.cs index b820a39f2..9ac7cea24 100644 --- a/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/SaveFileDialog.cs +++ b/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/SaveFileDialog.cs @@ -35,15 +35,15 @@ namespace UniGLTF return path; } - public static string GetDir(string title, string name) + public static string GetDir(string title, string dir = null) { - string directory = m_lastExportDir; + string directory = string.IsNullOrEmpty(dir) ? m_lastExportDir : dir; if (string.IsNullOrEmpty(directory)) { directory = Directory.GetParent(Application.dataPath).ToString(); } - var path = EditorUtility.SaveFolderPanel(title, directory, name); + var path = EditorUtility.SaveFolderPanel(title, directory, null); if (!string.IsNullOrEmpty(path)) { m_lastExportDir = Path.GetDirectoryName(path).Replace("\\", "/"); diff --git a/Assets/VRM10/Editor/Vrm10InstanceEditor.cs b/Assets/VRM10/Editor/Vrm10InstanceEditor.cs index 376d37145..3beb96798 100644 --- a/Assets/VRM10/Editor/Vrm10InstanceEditor.cs +++ b/Assets/VRM10/Editor/Vrm10InstanceEditor.cs @@ -115,6 +115,21 @@ namespace UniVRM10 return loaded; } + static string GetSaveName(Vrm10Instance instance) + { + if (instance == null) + { + return "Assets/vrm-1.0.assets"; + } + + if (VRMShaders.PathObject.TryGetFromAsset(instance, out var asset)) + { + return (asset.Parent.Child(instance.name + ".asset")).UnityAssetPath; + } + + return $"Assets/{instance.name}.assets"; + } + void SetupVRM10Object(Vrm10Instance instance) { if (!CheckHumanoid(instance.gameObject)) @@ -124,10 +139,17 @@ namespace UniVRM10 } EditorGUILayout.HelpBox("Humanoid OK.", MessageType.Info); + + // VRM10Object + var prop = serializedObject.FindProperty(nameof(Vrm10Instance.Vrm)); + if (prop.objectReferenceValue == null) + { + EditorGUILayout.HelpBox("No VRM10Object.", MessageType.Error); + } if (GUILayout.Button("Create new VRM10Object")) { - var saveName = (instance.name ?? "vrm-1.0"); - var dir = SaveFileDialog.GetDir(SaveTitle, saveName); + var saveName = GetSaveName(instance); + var dir = SaveFileDialog.GetDir(SaveTitle, System.IO.Path.GetDirectoryName(saveName)); if (!string.IsNullOrEmpty(dir)) { var expressions = new Dictionary(); @@ -146,7 +168,6 @@ namespace UniVRM10 { // update editor serializedObject.Update(); - var prop = serializedObject.FindProperty(nameof(Vrm10Instance.Vrm)); prop.objectReferenceValue = asset; serializedObject.ApplyModifiedProperties(); } diff --git a/Assets/VRM10/Runtime/Components/Vrm10Instance/Vrm10Instance.cs b/Assets/VRM10/Runtime/Components/Vrm10Instance/Vrm10Instance.cs index d1397552e..6c8afcc26 100644 --- a/Assets/VRM10/Runtime/Components/Vrm10Instance/Vrm10Instance.cs +++ b/Assets/VRM10/Runtime/Components/Vrm10Instance/Vrm10Instance.cs @@ -92,6 +92,13 @@ namespace UniVRM10 void Start() { + if (Vrm == null) + { + Debug.LogError("no VRM10Object"); + enabled = false; + return; + } + // cause new Vrm10Runtime. // init LookAt init rotation. var runtime = Runtime; diff --git a/Assets/VRMShaders/GLTF/IO/Runtime/PathObject.cs b/Assets/VRMShaders/GLTF/IO/Runtime/PathObject.cs index 55cddca2e..4ba004bfa 100644 --- a/Assets/VRMShaders/GLTF/IO/Runtime/PathObject.cs +++ b/Assets/VRMShaders/GLTF/IO/Runtime/PathObject.cs @@ -161,14 +161,22 @@ namespace VRMShaders } var assetPath = AssetDatabase.GetAssetPath(src); - if (string.IsNullOrEmpty(assetPath)) + if (!string.IsNullOrEmpty(assetPath)) { - dst = default; - return false; + dst = FromUnityAssetPath(assetPath); + return true; } - dst = FromUnityAssetPath(assetPath); - return true; + var prefab = PrefabUtility.GetPrefabAssetPathOfNearestInstanceRoot(src); + if (!string.IsNullOrEmpty(prefab)) + { + dst = FromUnityAssetPath(prefab); + return true; + } + + dst = default; + return false; + } public void ImportAsset()