mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-08-22 18:45:06 -05:00
Merge pull request #1052 from ousttrue/feature10/impl_firstperson_list
Feature10/impl firstperson list
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
using System.Collections;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -11,22 +13,39 @@ namespace UniVRM10
|
||||
{
|
||||
static Rect LeftSide(Rect position, float width)
|
||||
{
|
||||
return new Rect(position.x, position.y, position.width-width, position.height);
|
||||
return new Rect(position.x, position.y, position.width - width, position.height);
|
||||
}
|
||||
static Rect RightSide(Rect position, float width)
|
||||
{
|
||||
return new Rect(position.x + (position.width-width), position.y, width, position.height);
|
||||
return new Rect(position.x + (position.width - width), position.y, width, position.height);
|
||||
}
|
||||
|
||||
const float WIDTH = 140.0f;
|
||||
|
||||
public override void OnGUI(Rect position,
|
||||
SerializedProperty property, GUIContent label)
|
||||
{
|
||||
var rendererProp = property.FindPropertyRelative("Renderer");
|
||||
var flagProp = property.FindPropertyRelative("FirstPersonFlag");
|
||||
|
||||
const float WIDTH = 140.0f;
|
||||
EditorGUI.PropertyField(LeftSide(position, WIDTH), rendererProp, new GUIContent(""), true);
|
||||
EditorGUI.PropertyField(RightSide(position, WIDTH), flagProp, new GUIContent(""), true);
|
||||
var root = (property.serializedObject.targetObject as VRM10Object).Prefab;
|
||||
if (root != null)
|
||||
{
|
||||
var renderers = root.GetComponentsInChildren<Renderer>();
|
||||
var paths = renderers.Select(x => x.transform.RelativePathFrom(root.transform)).ToArray();
|
||||
var selected = Array.IndexOf(paths, rendererProp.stringValue);
|
||||
var newSelect = EditorGUI.Popup(LeftSide(position, WIDTH), selected, renderers.Select(x => x.name).ToArray());
|
||||
if (newSelect != selected && newSelect != -1)
|
||||
{
|
||||
rendererProp.stringValue = paths[newSelect];
|
||||
}
|
||||
EditorGUI.PropertyField(RightSide(position, WIDTH), flagProp, new GUIContent(""), true);
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorGUI.PropertyField(LeftSide(position, WIDTH), rendererProp, new GUIContent(""), true);
|
||||
EditorGUI.PropertyField(RightSide(position, WIDTH), flagProp, new GUIContent(""), true);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace UniVRM10
|
||||
LookAt,
|
||||
FirstPerson,
|
||||
}
|
||||
Tabs _tab = Tabs.Meta;
|
||||
static Tabs _tab = Tabs.Meta;
|
||||
|
||||
// for SerializedProperty
|
||||
PropGui m_expression;
|
||||
|
||||
@@ -4,44 +4,8 @@ using UnityEngine;
|
||||
namespace UniVRM10
|
||||
{
|
||||
[CreateAssetMenu(menuName = "VRM10/Expression")]
|
||||
public sealed class VRM10Expression : ScriptableObject
|
||||
public sealed class VRM10Expression : PrefabRelatedScriptableObject
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
/// <summary>
|
||||
/// Preview 用のObject参照
|
||||
/// </summary>
|
||||
[SerializeField]
|
||||
GameObject m_prefab;
|
||||
public GameObject Prefab
|
||||
{
|
||||
set { m_prefab = value; }
|
||||
get
|
||||
{
|
||||
if (m_prefab == null)
|
||||
{
|
||||
var assetPath = UnityEditor.AssetDatabase.GetAssetPath(this);
|
||||
if (!string.IsNullOrEmpty(assetPath))
|
||||
{
|
||||
// if asset is subasset of prefab
|
||||
m_prefab = UnityEditor.AssetDatabase.LoadAssetAtPath<GameObject>(assetPath);
|
||||
if (m_prefab != null) return m_prefab;
|
||||
|
||||
var parent = UnityPath.FromUnityPath(assetPath).Parent;
|
||||
var prefabPath = parent.Parent.Child(parent.FileNameWithoutExtension + ".prefab");
|
||||
m_prefab = UnityEditor.AssetDatabase.LoadAssetAtPath<GameObject>(prefabPath.Value);
|
||||
if (m_prefab != null) return m_prefab;
|
||||
|
||||
var parentParent = UnityPath.FromUnityPath(assetPath).Parent.Parent;
|
||||
var vrmPath = parent.Parent.Child(parent.FileNameWithoutExtension + ".vrm");
|
||||
m_prefab = UnityEditor.AssetDatabase.LoadAssetAtPath<GameObject>(vrmPath.Value);
|
||||
if (m_prefab != null) return m_prefab;
|
||||
}
|
||||
}
|
||||
return m_prefab;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// ExpressionPreset が Unknown 場合の識別子
|
||||
/// </summary>
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
using UniGLTF;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UniVRM10
|
||||
{
|
||||
/// <summary>
|
||||
/// ScriptableObject なのだけど Editor では、ヒエラルキーを参照したい。
|
||||
/// 参照して、ヒエラルキー内の Renderer を選択したりしたい。
|
||||
///
|
||||
/// そういうオブジェクト。
|
||||
/// </summary>
|
||||
public class PrefabRelatedScriptableObject : ScriptableObject
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
/// <summary>
|
||||
/// Preview 用のObject参照
|
||||
/// </summary>
|
||||
[SerializeField]
|
||||
GameObject m_prefab;
|
||||
public GameObject Prefab
|
||||
{
|
||||
set { m_prefab = value; }
|
||||
get
|
||||
{
|
||||
if (m_prefab == null)
|
||||
{
|
||||
var assetPath = UnityEditor.AssetDatabase.GetAssetPath(this);
|
||||
if (!string.IsNullOrEmpty(assetPath))
|
||||
{
|
||||
// if asset is subasset of prefab
|
||||
m_prefab = UnityEditor.AssetDatabase.LoadAssetAtPath<GameObject>(assetPath);
|
||||
if (m_prefab != null) return m_prefab;
|
||||
|
||||
// 同じフォルダに prefab が居る
|
||||
var parent = UnityPath.FromUnityPath(assetPath).Parent;
|
||||
var prefabPath = parent.Parent.Child(parent.FileNameWithoutExtension + ".prefab");
|
||||
m_prefab = UnityEditor.AssetDatabase.LoadAssetAtPath<GameObject>(prefabPath.Value);
|
||||
if (m_prefab != null) return m_prefab;
|
||||
|
||||
// 同じフォルダに vrm(ScriptedImporter) が居る
|
||||
var parentParent = UnityPath.FromUnityPath(assetPath).Parent.Parent;
|
||||
var vrmPath = parent.Parent.Child(parent.FileNameWithoutExtension + ".vrm");
|
||||
m_prefab = UnityEditor.AssetDatabase.LoadAssetAtPath<GameObject>(vrmPath.Value);
|
||||
if (m_prefab != null) return m_prefab;
|
||||
}
|
||||
}
|
||||
return m_prefab;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fa46394d71fe3814ca9b60f0b3409c6d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -17,7 +17,7 @@ namespace UniVRM10
|
||||
/// * FirstPerson
|
||||
///
|
||||
/// </summary>
|
||||
public class VRM10Object : ScriptableObject
|
||||
public class VRM10Object : PrefabRelatedScriptableObject
|
||||
{
|
||||
public static SubAssetKey SubAssetKey => new SubAssetKey(typeof(VRM10Object), "_vrm1_");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user