mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-09-08 03:48:19 -05:00
PreviewSceneManager has Prefab
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -34,18 +32,7 @@ namespace VRM
|
||||
public static void DrawElement(Rect position, SerializedProperty property,
|
||||
PreviewSceneManager scene)
|
||||
{
|
||||
/*
|
||||
for (var depth = property.depth;
|
||||
property.NextVisible(true) && property.depth > depth;
|
||||
)
|
||||
{
|
||||
{
|
||||
var height = EditorGUI.GetPropertyHeight(property);
|
||||
EditorGUI.PropertyField(new Rect(position.x, y, position.width, height), property, false);
|
||||
y += height;
|
||||
}
|
||||
}
|
||||
*/
|
||||
if (scene == null) return;
|
||||
var height = 16;
|
||||
|
||||
var y = position.y;
|
||||
@@ -63,6 +50,8 @@ namespace VRM
|
||||
|
||||
static int StringPopup(Rect rect, SerializedProperty prop, string[] options)
|
||||
{
|
||||
if (options == null) { return -1; }
|
||||
|
||||
var oldIndex = Array.IndexOf(options, prop.stringValue);
|
||||
var newIndex = EditorGUI.Popup(rect, oldIndex, options);
|
||||
if (newIndex != oldIndex && newIndex >= 0 && newIndex < options.Length)
|
||||
@@ -72,14 +61,17 @@ namespace VRM
|
||||
return newIndex;
|
||||
}
|
||||
|
||||
static void IntPopup(Rect rect, SerializedProperty prop, string[] options)
|
||||
static int IntPopup(Rect rect, SerializedProperty prop, string[] options)
|
||||
{
|
||||
if (options == null){ return -1; }
|
||||
|
||||
var oldIndex = prop.intValue;
|
||||
var newIndex = EditorGUI.Popup(rect, oldIndex, options);
|
||||
if (newIndex != oldIndex && newIndex >= 0 && newIndex < options.Length)
|
||||
{
|
||||
prop.intValue = newIndex;
|
||||
}
|
||||
return newIndex;
|
||||
}
|
||||
|
||||
static void FloatSlider(Rect rect, SerializedProperty prop, float maxValue)
|
||||
|
||||
@@ -12,6 +12,33 @@ namespace VRM
|
||||
PreviewSceneManager m_scene;
|
||||
PreviewFaceRenderer m_renderer;
|
||||
|
||||
GameObject m_prefab;
|
||||
GameObject Prefab
|
||||
{
|
||||
get { return m_prefab; }
|
||||
set
|
||||
{
|
||||
if (m_prefab == value) return;
|
||||
m_prefab = value;
|
||||
|
||||
if (m_scene != null)
|
||||
{
|
||||
//Debug.LogFormat("OnDestroy");
|
||||
GameObject.DestroyImmediate(m_scene.gameObject);
|
||||
m_scene = null;
|
||||
}
|
||||
|
||||
if (m_prefab != null)
|
||||
{
|
||||
m_scene = PreviewSceneManager.GetOrCreate(m_prefab);
|
||||
if (m_scene != null)
|
||||
{
|
||||
m_scene.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#region for Editor
|
||||
SerializedProperty m_BlendShapeNameProp;
|
||||
SerializedProperty m_PresetProp;
|
||||
@@ -52,8 +79,10 @@ namespace VRM
|
||||
m_renderer = new PreviewFaceRenderer();
|
||||
|
||||
var assetPath = AssetDatabase.GetAssetPath(target);
|
||||
m_scene = PreviewSceneManager.GetOrCreate(assetPath);
|
||||
m_scene.gameObject.SetActive(false);
|
||||
if (!string.IsNullOrEmpty(assetPath))
|
||||
{
|
||||
Prefab = AssetDatabase.LoadAssetAtPath<GameObject>(assetPath);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
@@ -77,10 +106,7 @@ namespace VRM
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
//base.OnInspectorGUI();
|
||||
|
||||
//攻撃力の数値をラベルとして表示する
|
||||
//EditorGUILayout.LabelField("攻撃力", character.攻撃力.ToString());
|
||||
m_prefab = (GameObject)EditorGUILayout.ObjectField("prefab", m_prefab, typeof(GameObject), false);
|
||||
|
||||
serializedObject.Update();
|
||||
|
||||
@@ -114,17 +140,20 @@ namespace VRM
|
||||
return;
|
||||
}
|
||||
if (Event.current.type != EventType.Repaint)
|
||||
{ // if we don't need to update yet, then don't
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_renderer == null)
|
||||
{
|
||||
// if we don't need to update yet, then don't
|
||||
return;
|
||||
}
|
||||
|
||||
var image = m_renderer.Render(r, background, m_scene);
|
||||
GUI.DrawTexture(r, image, ScaleMode.StretchToFill, false); // draw the RenderTexture in the ObjectPreview pane
|
||||
if (m_renderer != null && m_scene != null)
|
||||
{
|
||||
var image = m_renderer.Render(r, background, m_scene);
|
||||
if (image != null)
|
||||
{
|
||||
// draw the RenderTexture in the ObjectPreview pane
|
||||
GUI.DrawTexture(r, image, ScaleMode.StretchToFill, false);
|
||||
}
|
||||
}
|
||||
|
||||
EditorGUI.DropShadowLabel(new Rect(r.x, r.y, r.width, 40f),
|
||||
BlendShapeKey.CreateFrom((BlendShapeClip)target).ToString());
|
||||
|
||||
@@ -26,6 +26,8 @@ namespace VRM
|
||||
|
||||
public Texture Render(Rect r, GUIStyle background, PreviewSceneManager scene)
|
||||
{
|
||||
if (scene == null) return null;
|
||||
|
||||
// we are technically rendering everything in the scene, so scene fog might affect it...
|
||||
bool fog = RenderSettings.fog; // ... let's remember the current fog setting...
|
||||
Unsupported.SetRenderSettingsUseFogNoDirty(false); // ... and then temporarily turn it off
|
||||
@@ -34,7 +36,7 @@ namespace VRM
|
||||
m_previewUtility.BeginPreview(r, background); // set up the PreviewRenderUtility's mini internal scene
|
||||
|
||||
// setup the ObjectPreview's camera
|
||||
scene.SetupCamera(m_previewUtility.m_Camera);
|
||||
scene.SetupCamera(m_previewUtility.camera);
|
||||
|
||||
foreach (var item in scene.EnumRenderItems)
|
||||
{
|
||||
@@ -51,7 +53,7 @@ namespace VRM
|
||||
}
|
||||
|
||||
// VERY IMPORTANT: this manually tells the camera to render and produce the render texture
|
||||
m_previewUtility.m_Camera.Render();
|
||||
m_previewUtility.camera.Render();
|
||||
|
||||
// reset the scene's fog from before
|
||||
return m_previewUtility.EndPreview(); // grab the RenderTexture resulting from DoRenderPreview() > RenderMeshPreview() > PreviewRenderUtility.m_Camera.Render()
|
||||
|
||||
Reference in New Issue
Block a user