3using System.Collections;
4using System.Reflection;
11 private MeshRenderer _meshRenderer;
12 private Material[] _materials;
16 _meshRenderer = (MeshRenderer)
target;
18 pb_GUIUtility.AddVerticalLayoutGroup(gameObject);
20 pb_TypeInspector enabled_inspector = pb_InspectorResolver.GetInspector(typeof(
bool));
22 enabled_inspector.Initialize(
"Enabled", UpdateEnabled, OnSetEnabled);
24 enabled_inspector.transform.SetParent(transform);
27 _materials = _meshRenderer.materials;
29 if (_materials !=
null)
52 foreach (var _material
in _materials)
54 pb_TypeInspector metallic = pb_InspectorResolver.GetInspector(typeof(
float));
55 pb_TypeInspector smoothness = pb_InspectorResolver.GetInspector(typeof(
float));
60 pb_TypeInspector color = pb_InspectorResolver.GetInspector(typeof(
Color));
62 pb_GUIUtility.CreateLabel(
"Material " + i).transform.SetParent(transform);;
64 if (_material.HasProperty(
"_Metallic"))
66 metallic.SetIndexInCollection(i);
67 metallic.Initialize(
"Metallic", GetStoredMetallicValue, OnSetMetallicValue);
68 metallic.transform.SetParent(transform);
71 if (_material.HasProperty(
"_Glossiness"))
73 smoothness.SetIndexInCollection(i);
74 smoothness.Initialize(
"Smoothness", GetStoredSmoothnessValue, OnSetSmoothnessValue);
75 smoothness.transform.SetParent(transform);
79 if (_material.HasProperty(
"_Color"))
81 color.SetIndexInCollection(i);
82 color.Initialize(
"Color", GetStoredColorValue, OnSetColorValue);
83 color.transform.SetParent(transform);
86 texture.SetIndexInCollection(i);
87 texture.Initialize(
"Texture", GetStoredImageValue, OnSetImageValue);
88 texture.transform.SetParent(transform);
90 if (_material.HasProperty(
"_MainTex"))
91 texture.
ui_image.texture = _material.GetTexture(
"_MainTex");
93 if (_material.HasProperty(
"_MetallicGlossMap"))
95 metallicMap.SetIndexInCollection(i);
96 metallicMap.Initialize(
"Metallic", GetStoredMetallicImageValue, OnSetMetallicImageValue);
97 metallicMap.transform.SetParent(transform);
98 metallicMap.
ui_image.texture = _material.GetTexture(
"_MetallicGlossMap");
101 if (_material.HasProperty(
"_BumpMap"))
103 bumpMap.SetIndexInCollection(i);
104 bumpMap.Initialize(
"Normal", GetStoredNormalImageValue, OnSetNormalImageValue);
105 bumpMap.transform.SetParent(transform);
106 bumpMap.
ui_image.texture = _material.GetTexture(
"_BumpMap");
110 if (_material.HasProperty(
"_OcclusionMap"))
112 occlusionMap.SetIndexInCollection(i);
113 occlusionMap.Initialize(
"Occlusion", GetStoredOcclusionImageValue, OnSetOcclusionImageValue);
114 occlusionMap.transform.SetParent(transform);
115 occlusionMap.
ui_image.texture = _material.GetTexture(
"_OcclusionMap");
125 void ChangeToDoubleSidedShader()
130 object GetStoredColorValue(
int index)
132 return _materials[index].GetColor(
"_Color");
135 void OnSetColorValue(
int index,
object value)
137 foreach (var go
in pb_Selection.gameObjects)
139 var mr = go.GetComponent<MeshRenderer>();
140 if (mr ==
null)
continue;
141 var mats = mr.materials;
142 if (mats ==
null)
continue;
143 if (mats.Length - 1 >= index)
147 matSettings.color = (
Color)value;
148 cth.matSettings[index] = matSettings;
150 mats[index].color = (
Color)value;
154 object GetStoredImageValue(
int index)
156 return _materials[index].GetTexture(
"_MainTex");
159 void OnSetImageValue(
int index,
object value)
161 if (value is RawImage)
162 if (_materials[index].HasProperty(
"_MainTex"))
164 _materials[index].SetTexture(
"_MainTex", ((RawImage)value).mainTexture);
170 matSettings.textureName = (string)value;
171 cth.matSettings[index] = matSettings;
176 object GetStoredMetallicImageValue(
int index)
178 return _materials[index].GetTexture(
"_MetallicGlossMap");
181 void OnSetMetallicImageValue(
int index,
object value)
183 if (value is RawImage)
184 if (_materials[index].HasProperty(
"_MetallicGlossMap"))
186 _materials[index].SetTexture(
"_MetallicGlossMap", ((RawImage)value).mainTexture);
192 matSettings.metallicName = (string)value;
193 cth.matSettings[index] = matSettings;
196 object GetStoredNormalImageValue(
int index)
198 var texture = _materials[index].GetTexture(
"_BumpMap");
199 if (texture ==
null) texture =
new Texture2D(1,1);
203 void OnSetNormalImageValue(
int index,
object value)
205 if (value is RawImage)
206 if (_materials[index].HasProperty(
"_BumpMap"))
208 _materials[index].SetTexture(
"_BumpMap", ((RawImage)value).mainTexture);
214 matSettings.normalName = (string)value;
215 cth.matSettings[index] = matSettings;
218 object GetStoredOcclusionImageValue(
int index)
220 return _materials[index].GetTexture(
"_OcclusionMap");
223 void OnSetOcclusionImageValue(
int index,
object value)
225 if (value is RawImage)
226 if (_materials[index].HasProperty(
"_OcclusionMap"))
228 _materials[index].SetTexture(
"_OcclusionMap", ((RawImage)value).mainTexture);
234 matSettings.occlusionName = (string)value;
235 cth.matSettings[index] = matSettings;
238 object GetStoredMetallicValue(
int index)
240 return _materials[index].GetFloat(
"_Metallic");
243 void OnSetMetallicValue(
int index,
object value)
247 matSettings.metallic = (float)value;
248 cth.matSettings[index] = matSettings;
250 _materials[index].SetFloat(
"_Metallic", (
float)value);
252 object GetStoredSmoothnessValue(
int index)
254 return _materials[index].GetFloat(
"_Glossiness");
257 void OnSetSmoothnessValue(
int index,
object value)
259 foreach (var go
in pb_Selection.gameObjects)
261 var mr = go.GetComponent<MeshRenderer>();
262 if (mr ==
null)
continue;
263 var mats = mr.materials;
264 if (mats ==
null)
continue;
265 if (mats.Length - 1 >= index)
266 mats[index].SetFloat(
"_Glossiness", (
float)value);
270 object UpdateEnabled()
272 return _meshRenderer.enabled;
275 void OnSetEnabled(
object value)
277 _meshRenderer.enabled = (bool) value;
List< MatSettings > matSettings
Component target
The UnityEngine.Component being edited.
override void InitializeGUI()
static void AddDiff(Component component, string name, object value)
static void RegisterState(IUndo target, string message)
static void Change(Material mat, string shaderName)