#if UNITY_EDITOR でビルドエラーを修正

* PreviewSceneManager が MonoBehaviour かつ Editor 専用なのが微妙
This commit is contained in:
ousttrue 2021-09-10 13:04:13 +09:00
parent 38067cff63
commit 4adf95bab6
4 changed files with 61 additions and 71 deletions

View File

@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
namespace UniVRM10
{
public static class PreviewMaterialUtil
{
public static PreviewMaterialItem CreateForPreview(Material material)
{
var item = new PreviewMaterialItem(material);
var propNames = new List<string>();
for (int i = 0; i < ShaderUtil.GetPropertyCount(material.shader); ++i)
{
var propType = ShaderUtil.GetPropertyType(material.shader, i);
var name = ShaderUtil.GetPropertyName(material.shader, i);
switch (propType)
{
case ShaderUtil.ShaderPropertyType.Color:
// 色
{
var bindType = PreviewMaterialItem.GetBindType(name);
item.PropMap.Add(bindType, new PropItem
{
Name = name,
PropertyType = (UniVRM10.ShaderPropertyType)Enum.Parse(typeof(UniVRM10.ShaderPropertyType), propType.ToString(), true),
DefaultValues = material.GetColor(name),
});
propNames.Add(name);
}
break;
case ShaderUtil.ShaderPropertyType.TexEnv:
break;
}
}
item.PropNames = propNames.ToArray();
return item;
}
}
}
#endif

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 45f9865ffd894b04bad0c39f53154f55
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -97,7 +97,7 @@ namespace UniVRM10
//Debug.LogFormat("add material {0}", src.name);
materialNames.Add(src.name);
m_materialMap.Add(src.name, PreviewMaterialItem.CreateForPreview(dst));
m_materialMap.Add(src.name, PreviewMaterialUtil.CreateForPreview(dst));
}
return dst;
};

View File

@ -2,13 +2,10 @@ using System;
using System.Collections.Generic;
using UnityEngine;
using UniGLTF.Extensions.VRMC_vrm;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace UniVRM10
{
public enum ShaderPropertyType
{
//
@ -68,7 +65,7 @@ namespace UniVRM10
public string[] PropNames
{
get;
private set;
set;
}
public void RestoreInitialValues()
@ -79,7 +76,6 @@ namespace UniVRM10
}
}
#if UNITY_EDITOR
public const string UV_PROPERTY = "_MainTex_ST";
public const string COLOR_PROPERTY = "_Color";
public const string EMISSION_COLOR_PROPERTY = "_EmissionColor";
@ -108,69 +104,5 @@ namespace UniVRM10
throw new NotImplementedException();
}
public static PreviewMaterialItem CreateForPreview(Material material)
{
var item = new PreviewMaterialItem(material);
var propNames = new List<string>();
for (int i = 0; i < ShaderUtil.GetPropertyCount(material.shader); ++i)
{
var propType = ShaderUtil.GetPropertyType(material.shader, i);
var name = ShaderUtil.GetPropertyName(material.shader, i);
switch (propType)
{
case ShaderUtil.ShaderPropertyType.Color:
// 色
{
var bindType = GetBindType(name);
item.PropMap.Add(bindType, new PropItem
{
Name = name,
PropertyType = (UniVRM10.ShaderPropertyType)Enum.Parse(typeof(UniVRM10.ShaderPropertyType), propType.ToString(), true),
DefaultValues = material.GetColor(name),
});
propNames.Add(name);
}
break;
case ShaderUtil.ShaderPropertyType.TexEnv:
// テクスチャ
// {
// name += "_ST";
// item.PropMap.Add(name, new PropItem
// {
// PropertyType = propType,
// DefaultValues = material.GetVector(name),
// });
// propNames.Add(name);
// }
// // 縦横分離用
// {
// var st_name = name + "_S";
// item.PropMap.Add(st_name, new PropItem
// {
// PropertyType = propType,
// DefaultValues = material.GetVector(name),
// });
// propNames.Add(st_name);
// }
// {
// var st_name = name + "_T";
// item.PropMap.Add(st_name, new PropItem
// {
// PropertyType = propType,
// DefaultValues = material.GetVector(name),
// });
// propNames.Add(st_name);
// }
break;
}
}
item.PropNames = propNames.ToArray();
return item;
}
#endif
}
}