/// <summary> /// Converts the <see cref="MaterialProperty.PropType"/> to <see cref="RuntimeMaterialPropertyType"/> /// </summary> /// <param name="propType">The prop type</param> /// <returns><see cref="RuntimeMaterialPropertyType"/></returns> public static RuntimeMaterialPropertyType ConvertPropType(MaterialProperty.PropType propType) { RuntimeMaterialPropertyType type = RuntimeMaterialPropertyType.Color; switch (propType) { case MaterialProperty.PropType.Color: type = RuntimeMaterialPropertyType.Color; break; case MaterialProperty.PropType.Vector: type = RuntimeMaterialPropertyType.Vector; break; case MaterialProperty.PropType.Float: type = RuntimeMaterialPropertyType.Float; break; case MaterialProperty.PropType.Range: type = RuntimeMaterialPropertyType.Range; break; case MaterialProperty.PropType.Texture: type = RuntimeMaterialPropertyType.Texture; break; } return(type); }
public static void PropertyField(MaterialProperty property, Material material, string context = "") { MaterialProperty.PropType lType = property.type; switch (lType) { case MaterialProperty.PropType.Color: ColorField(new GUIContent(property.displayName, context), property.name, material); break; case MaterialProperty.PropType.Float: FloatField(new GUIContent(property.displayName, context), property.name, material); break; case MaterialProperty.PropType.Range: SliderField(new GUIContent(property.displayName, context), property.name, property.rangeLimits.x, property.rangeLimits.y, material); break; case MaterialProperty.PropType.Texture: TextureField(new GUIContent(property.displayName, context), property.name, material, TextureFieldType.Small); TextureDataField(new GUIContent(), property.name + "_ST"); break; case MaterialProperty.PropType.Vector: VectorField(new GUIContent(property.displayName, context), property.name, material, PackagePart.x, PackagePart.y, PackagePart.z, PackagePart.w); break; } }
private void ShowPropertyBlock(int index, Material mat, MaterialPropertyBlock block) { #region check paramter if (mat == null) { EditorGUILayout.LabelField("mat is null."); return; } if (block == null) { EditorGUILayout.LabelField("block is null."); return; } #endregion MaterialProperty[] props = MaterialEditor.GetMaterialProperties(new Material[] { mat }); for (var i = 0; i < props.Length; i++) { MaterialProperty prop = props[i]; string name = prop.name; string displayName = prop.displayName; MaterialProperty.PropType type = prop.type; switch (type) { case MaterialProperty.PropType.Color: { Color value = block.GetColor(name); Color newValue = EditorGUILayout.ColorField(GetName(displayName, name), value); if (newValue != value) { m_viewer.SetValue(index, name, newValue); } } break; case MaterialProperty.PropType.Vector: { Vector4 value = block.GetVector(name); Vector4 newValue = EditorGUILayout.Vector4Field(GetName(displayName, name), value); if (newValue != value) { m_viewer.SetValue(index, name, newValue); } } break; case MaterialProperty.PropType.Float: { float value = block.GetFloat(name); float newValue = EditorGUILayout.FloatField(GetName(displayName, name), value); if (newValue != value) { m_viewer.SetValue(index, name, newValue); } } break; case MaterialProperty.PropType.Range: { float value = block.GetFloat(name); float newValue = EditorGUILayout.FloatField(GetName(displayName, name), value); if (newValue != value) { m_viewer.SetValue(index, name, newValue); } } break; case MaterialProperty.PropType.Texture: { Texture value = block.GetTexture(name); Texture newValue = EditorGUILayout.ObjectField( GetName(displayName, name), value, typeof(Texture), true) as Texture; if (newValue != value) { m_viewer.SetValue(index, name, newValue); } } break; default: { } break; } } }
public RuntimeMaterialProperty(string name, MaterialProperty.PropType propType) { this.name = name; this.type = ConvertPropType(propType); }