Files
CartoonRPG/Assets/StixGames/GrassShader/Scripts/GrassTextureAdder.cs
Caleb Sandford deQuincey 02c4b5ab66 Adding in new packages
2025-06-05 22:59:18 +01:00

53 lines
1.3 KiB
C#

using UnityEngine;
namespace StixGames.GrassShader
{
/// <summary>
/// A simple helper script that adds editable textures to a grass material
/// You could also use a custom texture for this, just make sure to set it to editable by script in the importer settings.
/// </summary>
[AddComponentMenu("Stix Games/Deprecated/Grass Texture Adder")]
public class GrassTextureAdder : MonoBehaviour
{
public int size = 1024;
public bool addColorHeight, addDisplacement;
// Use this for initialization
private void Start()
{
if (addColorHeight)
{
var tex = new Texture2D(size, size, TextureFormat.ARGB32, false, true);
var pixels = new Color[size * size];
for (int i = 0; i < pixels.Length; i++)
{
pixels[i] = new Color(1, 1, 1, 1);
}
tex.SetPixels(pixels);
tex.Apply();
GetComponent<Renderer>().material.SetTexture("_Displacement", tex);
}
if (addDisplacement)
{
var tex = new Texture2D(size, size, TextureFormat.ARGB32, false, true);
var pixels = new Color[size * size];
for (int i = 0; i < pixels.Length; i++)
{
pixels[i] = new Color(0.5f, 0.5f, 1, 1);
}
tex.SetPixels(pixels);
tex.Apply();
GetComponent<Renderer>().material.SetTexture("_Displacement", tex);
}
}
}
}