|
|
|
|
|
|
[AddRandomizerMenu("Perception/Texture Randomizer")] |
|
|
|
public class TextureRandomizer : Randomizer |
|
|
|
{ |
|
|
|
static readonly int k_BaseMap = Shader.PropertyToID("_BaseMap"); |
|
|
|
static readonly int k_BaseTexture = Shader.PropertyToID("_BaseColorMap"); |
|
|
|
#else
|
|
|
|
static readonly int k_BaseTexture = Shader.PropertyToID("_BaseMap"); |
|
|
|
const string k_TutorialHueShaderName = "Shader Graphs/HueShiftOpaque"; |
|
|
|
static readonly int k_BaseColorMap = Shader.PropertyToID("_BaseColorMap"); |
|
|
|
#endif
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
var tags = tagManager.Query<TextureRandomizerTag>(); |
|
|
|
foreach (var tag in tags) |
|
|
|
{ |
|
|
|
var renderer = tag.GetComponent<MeshRenderer>(); |
|
|
|
renderer.material.SetTexture(k_BaseTexture, texture.Sample()); |
|
|
|
var renderer = tag.GetComponent<Renderer>(); |
|
|
|
#if HDRP_PRESENT
|
|
|
|
// Choose the appropriate shader texture property ID depending on whether the current material is
|
|
|
|
// using the default HDRP/lit shader or the Perception tutorial's HueShiftOpaque shader
|
|
|
|
var material = renderer.material; |
|
|
|
var propertyId = material.shader.name == k_TutorialHueShaderName ? k_BaseMap : k_BaseColorMap; |
|
|
|
material.SetTexture(propertyId, texture.Sample()); |
|
|
|
#else
|
|
|
|
renderer.material.SetTexture(k_BaseMap, texture.Sample()); |
|
|
|
#endif
|
|
|
|
} |
|
|
|
} |
|
|
|
} |