Skip to content

Commit

Permalink
Merge pull request #1136 from ousttrue/fix1/fix_firstperson_editor
Browse files Browse the repository at this point in the history
Fix1/fix firstperson editor
  • Loading branch information
PoChang007 authored Aug 6, 2021
2 parents a1e6190 + 081dbae commit 8f31f32
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 15 deletions.
26 changes: 24 additions & 2 deletions Assets/VRM10/Editor/Components/VRM10ObjectEditor.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using UniGLTF;
using System.Linq;
using UniGLTF;
using UnityEditor;
using UnityEngine;

namespace UniVRM10
{
Expand All @@ -22,7 +24,7 @@ enum Tabs
SerializedPropertyEditor m_meta;
SerializedPropertyEditor m_lookAt;
SerializedPropertyEditor m_firstPerson;
SerializedPropertyEditor m_asset;
SerializedProperty m_prefab;

void OnEnable()
{
Expand All @@ -36,10 +38,22 @@ void OnEnable()
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())
{
Expand All @@ -62,6 +76,14 @@ public override void OnInspectorGUI()
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;
}
Expand Down
2 changes: 2 additions & 0 deletions Assets/VRM10/Editor/ScriptedImporter/RemapEditorVrm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public static void Extract(ScriptedImporter importer, GltfData data)
// 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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,21 @@ public class VRM10ObjectFirstPerson
{
[SerializeField]
public List<RendererFirstPersonFlags> Renderers = new List<RendererFirstPersonFlags>();
public void SetDefault(Transform root)
{
Renderers.Clear();

// public void CopyTo(GameObject _dst, Dictionary<Transform, Transform> map)
// {
// var dst = _dst.GetOrAddComponent<VRM10Controller>();
// dst.Vrm.FirstPerson.Renderers = Renderers.Select(x =>
// {
// var renderer = map[x.Renderer.transform].GetComponent<Renderer>();
// return new RendererFirstPersonFlags
// {
// Renderer = renderer,
// FirstPersonFlag = x.FirstPersonFlag,
// };
// }).ToList();
// }
var renderers = root.GetComponentsInChildren<Renderer>();
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".
Expand Down

0 comments on commit 8f31f32

Please sign in to comment.