Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Sep 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private void Initialize(GameObject prefab)

//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;
};
Expand Down
72 changes: 2 additions & 70 deletions Assets/VRM10/Runtime/Components/Expression/PreviewMaterialItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@
using System.Collections.Generic;
using UnityEngine;
using UniGLTF.Extensions.VRMC_vrm;
#if UNITY_EDITOR
using UnityEditor;
#endif


namespace UniVRM10
{

public enum ShaderPropertyType
{
//
Expand Down Expand Up @@ -68,7 +65,7 @@ public PreviewMaterialItem(Material material)
public string[] PropNames
{
get;
private set;
set;
}

public void RestoreInitialValues()
Expand All @@ -79,7 +76,6 @@ public void RestoreInitialValues()
}
}

#if UNITY_EDITOR
public const string UV_PROPERTY = "_MainTex_ST";
public const string COLOR_PROPERTY = "_Color";
public const string EMISSION_COLOR_PROPERTY = "_EmissionColor";
Expand Down Expand Up @@ -108,69 +104,5 @@ public static MaterialColorType GetBindType(string property)

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
}
}