Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using UnityEngine;
- namespace StylizedGrass
- {
- //Testing runtime generation
- [ExecuteInEditMode]
- public class RuntimeColorMapTest : MonoBehaviour
- {
- public GrassColorMapRenderer colorMapRenderer;
- private void Reset()
- {
- colorMapRenderer = GetComponent<GrassColorMapRenderer>();
- }
- public void OnGUI()
- {
- if (GUILayout.Button("Render"))
- {
- if(colorMapRenderer.colorMap == null) colorMapRenderer.colorMap = ScriptableObject.CreateInstance<GrassColorMap>();
- colorMapRenderer.terrainObjects.Clear();
- colorMapRenderer.AssignActiveTerrains();
- colorMapRenderer.RecalculateBounds();
- //Use some randomization, in order to see a difference
- float r = UnityEngine.Random.Range(0.9f, 1.1f);
- colorMapRenderer.colorMap.bounds.size = Vector3.Scale(colorMapRenderer.colorMap.bounds.size, new Vector3(r, 1f, r));
- colorMapRenderer.textureDetail = UnityEngine.Random.value * 100f;
- colorMapRenderer.Render();
- }
- if (colorMapRenderer.colorMap && colorMapRenderer.colorMap.texture)
- {
- GUI.DrawTexture(new Rect(5, 32, 256, 256), colorMapRenderer.colorMap.texture, ScaleMode.ScaleToFit, false);
- GUI.DrawTexture(new Rect(256 + 15, 32, 256, 256), colorMapRenderer.colorMap.texture, ScaleMode.ScaleToFit, true);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement