From b4b01e75188223c4df67aef7300acc39d9378748 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Fri, 6 Aug 2021 17:19:36 +0900 Subject: [PATCH 1/3] prefab field --- .../VRM10/Editor/Components/VRM10ObjectEditor.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Assets/VRM10/Editor/Components/VRM10ObjectEditor.cs b/Assets/VRM10/Editor/Components/VRM10ObjectEditor.cs index fa61e3737..b7bdb22e3 100644 --- a/Assets/VRM10/Editor/Components/VRM10ObjectEditor.cs +++ b/Assets/VRM10/Editor/Components/VRM10ObjectEditor.cs @@ -22,7 +22,7 @@ namespace UniVRM10 SerializedPropertyEditor m_meta; SerializedPropertyEditor m_lookAt; SerializedPropertyEditor m_firstPerson; - SerializedPropertyEditor m_asset; + SerializedProperty m_prefab; void OnEnable() { @@ -36,10 +36,22 @@ namespace UniVRM10 m_meta = VRM10MetaEditor.Create(serializedObject); m_lookAt = SerializedPropertyEditor.Create(serializedObject, nameof(m_target.LookAt)); m_firstPerson = SerializedPropertyEditor.Create(serializedObject, nameof(m_target.FirstPerson)); + + m_prefab = serializedObject.FindProperty("m_prefab"); } public override void OnInspectorGUI() { + // prefab + if (_tab == Tabs.FirstPerson && m_prefab.objectReferenceValue == null) + { + EditorGUILayout.HelpBox("required !", MessageType.Error); + } + serializedObject.Update(); + EditorGUILayout.ObjectField(m_prefab); + serializedObject.ApplyModifiedProperties(); + EditorGUILayout.Separator(); + // select sub editor using (new EnabledScope()) { From f28b5f93df545d87311865086f6318cf8dafab65 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Fri, 6 Aug 2021 17:24:05 +0900 Subject: [PATCH 2/3] assign vrmObject.Prefab when Extract --- Assets/VRM10/Editor/ScriptedImporter/RemapEditorVrm.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Assets/VRM10/Editor/ScriptedImporter/RemapEditorVrm.cs b/Assets/VRM10/Editor/ScriptedImporter/RemapEditorVrm.cs index 86a952ceb..9093b11b8 100644 --- a/Assets/VRM10/Editor/ScriptedImporter/RemapEditorVrm.cs +++ b/Assets/VRM10/Editor/ScriptedImporter/RemapEditorVrm.cs @@ -78,6 +78,8 @@ namespace UniVRM10 // vrmObject の expression を置き換える var vrmObject = AssetDatabase.LoadAllAssetsAtPath(importer.assetPath).First(x => x is VRM10Object) as VRM10Object; vrmObject.Expression.Replace(map); + vrmObject.Prefab = prefab; // for FirstPerson Editor + // extract ExtractSubAsset(vrmObject, $"{path}/{vrmObject.name}.asset", false); From 081dbae6ff58aa8116dfe89aaf1babbba6735a44 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Fri, 6 Aug 2021 17:42:20 +0900 Subject: [PATCH 3/3] first person `set default` button --- .../Editor/Components/VRM10ObjectEditor.cs | 12 ++++++++- .../VRM10Object/VRM10ObjectFirstPerson.cs | 27 ++++++++++--------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/Assets/VRM10/Editor/Components/VRM10ObjectEditor.cs b/Assets/VRM10/Editor/Components/VRM10ObjectEditor.cs index b7bdb22e3..55efce643 100644 --- a/Assets/VRM10/Editor/Components/VRM10ObjectEditor.cs +++ b/Assets/VRM10/Editor/Components/VRM10ObjectEditor.cs @@ -1,5 +1,7 @@ -using UniGLTF; +using System.Linq; +using UniGLTF; using UnityEditor; +using UnityEngine; namespace UniVRM10 { @@ -74,6 +76,14 @@ namespace UniVRM10 break; case Tabs.FirstPerson: + using (new EditorGUI.DisabledScope(m_target.Prefab == null)) + { + if (GUILayout.Button("set default")) + { + m_target.FirstPerson.SetDefault(m_target.Prefab.transform); + } + EditorGUILayout.HelpBox("Clear Renderers and add all renderers (Auto)", MessageType.Info); + } m_firstPerson.OnInspectorGUI(); break; } diff --git a/Assets/VRM10/Runtime/Components/VRM10Object/VRM10ObjectFirstPerson.cs b/Assets/VRM10/Runtime/Components/VRM10Object/VRM10ObjectFirstPerson.cs index aaafcdf99..8e80e8f84 100644 --- a/Assets/VRM10/Runtime/Components/VRM10Object/VRM10ObjectFirstPerson.cs +++ b/Assets/VRM10/Runtime/Components/VRM10Object/VRM10ObjectFirstPerson.cs @@ -11,20 +11,21 @@ namespace UniVRM10 { [SerializeField] public List Renderers = new List(); + public void SetDefault(Transform root) + { + Renderers.Clear(); - // public void CopyTo(GameObject _dst, Dictionary map) - // { - // var dst = _dst.GetOrAddComponent(); - // dst.Vrm.FirstPerson.Renderers = Renderers.Select(x => - // { - // var renderer = map[x.Renderer.transform].GetComponent(); - // return new RendererFirstPersonFlags - // { - // Renderer = renderer, - // FirstPersonFlag = x.FirstPersonFlag, - // }; - // }).ToList(); - // } + var renderers = root.GetComponentsInChildren(); + var paths = renderers.Select(x => x.transform.RelativePathFrom(root)).ToArray(); + foreach (var path in paths) + { + Renderers.Add(new RendererFirstPersonFlags + { + FirstPersonFlag = UniGLTF.Extensions.VRMC_vrm.FirstPersonType.auto, + Renderer = path, + }); + } + } // If no layer names are set, use the default layer IDs. // Otherwise use the two Unity layers called "VRMFirstPersonOnly" and "VRMThirdPersonOnly".