Added overlay to view nutrient mapping
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
using UnityEditor.TextCore.Text;
|
||||
using UnityEngine;
|
||||
using static UnityEngine.GraphicsBuffer;
|
||||
using static UnityEngine.UIElements.UxmlAttributeDescription;
|
||||
|
||||
public class NutrientController : MonoBehaviour
|
||||
{
|
||||
private float[,] nutrientMap;
|
||||
[SerializeField, Range(10, 100)] int sizeX;
|
||||
[SerializeField, Range(10, 100)] int sizeY;
|
||||
[SerializeField] MeshRenderer meshRenderer;
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
@@ -40,4 +44,63 @@ public class NutrientController : MonoBehaviour
|
||||
|
||||
nutrientMap[locX, locY] -= used;
|
||||
}
|
||||
|
||||
public void AddNutrients(float x, float y, float added)
|
||||
{
|
||||
int locX = Mathf.FloorToInt(x * sizeX);
|
||||
int locY = Mathf.FloorToInt(y * sizeY);
|
||||
|
||||
nutrientMap[locX, locY] += added;
|
||||
}
|
||||
|
||||
private void Render()
|
||||
{
|
||||
Texture2D texture = new Texture2D(sizeX, sizeY);
|
||||
for (int r = 0; r < sizeX; r++)
|
||||
{
|
||||
for (int c = 0; c < sizeY; c++)
|
||||
{
|
||||
float colorValue = nutrientMap[r, c];
|
||||
texture.SetPixel(r, c, new Color(colorValue, colorValue, colorValue));
|
||||
}
|
||||
}
|
||||
|
||||
texture.Apply();
|
||||
meshRenderer.material.mainTexture = texture;
|
||||
}
|
||||
|
||||
private void ConsoleDump()
|
||||
{
|
||||
string toPrint = "\n";
|
||||
for (int r = 0; r < sizeX; r++)
|
||||
{
|
||||
for (int c = 0; c < sizeY; c++)
|
||||
{
|
||||
toPrint += nutrientMap[r, c] + " ";
|
||||
}
|
||||
toPrint += "\n";
|
||||
}
|
||||
Debug.Log(toPrint);
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
[UnityEditor.CustomEditor(typeof(NutrientController))]
|
||||
|
||||
public class NutrientControllerEditor: UnityEditor.Editor
|
||||
{
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
base.OnInspectorGUI();
|
||||
if (GUILayout.Button("Sample Button"))
|
||||
{
|
||||
(target as NutrientController).Render();
|
||||
}
|
||||
|
||||
if(GUILayout.Button("Dump it"))
|
||||
{
|
||||
(target as NutrientController).ConsoleDump();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user