Boat Attack使用了Universal RP的许多新图形功能,可以用于探索 Universal RP 的使用方式和技巧。
您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

69 行
2.6 KiB

using UnityEngine;
using UnityEngine.Rendering.Universal;
namespace UnityEditor.Rendering.Universal
{
[VolumeComponentEditor(typeof(FilmGrain))]
sealed class FilmGrainEditor : VolumeComponentEditor
{
SerializedDataParameter m_Type;
SerializedDataParameter m_Intensity;
SerializedDataParameter m_Response;
SerializedDataParameter m_Texture;
public override void OnEnable()
{
var o = new PropertyFetcher<FilmGrain>(serializedObject);
m_Type = Unpack(o.Find(x => x.type));
m_Intensity = Unpack(o.Find(x => x.intensity));
m_Response = Unpack(o.Find(x => x.response));
m_Texture = Unpack(o.Find(x => x.texture));
}
public override void OnInspectorGUI()
{
PropertyField(m_Type);
if (m_Type.value.intValue == (int)FilmGrainLookup.Custom)
{
PropertyField(m_Texture);
var texture = (target as FilmGrain).texture.value;
if (texture != null)
{
var importer = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(texture)) as TextureImporter;
// Fails when using an internal texture as you can't change import settings on
// builtin resources, thus the check for null
if (importer != null)
{
bool valid = importer.mipmapEnabled == false
&& importer.alphaSource == TextureImporterAlphaSource.FromGrayScale
&& importer.filterMode == FilterMode.Point
&& importer.textureCompression == TextureImporterCompression.Uncompressed
&& importer.textureType == TextureImporterType.SingleChannel;
if (!valid)
CoreEditorUtils.DrawFixMeBox("Invalid texture import settings.", () => SetTextureImportSettings(importer));
}
}
}
PropertyField(m_Intensity);
PropertyField(m_Response);
}
static void SetTextureImportSettings(TextureImporter importer)
{
importer.textureType = TextureImporterType.SingleChannel;
importer.alphaSource = TextureImporterAlphaSource.FromGrayScale;
importer.mipmapEnabled = false;
importer.filterMode = FilterMode.Point;
importer.textureCompression = TextureImporterCompression.Uncompressed;
importer.SaveAndReimport();
AssetDatabase.Refresh();
}
}
}