colored mesh made

have a single mesh that changes color based on keyboard input. needs to be  made for each cell and have color based on cell-value
This commit is contained in:
Simon O'Shea
2023-08-03 15:55:52 -04:00
parent 78c5f3689c
commit e6bd6d2c58
6 changed files with 150 additions and 10 deletions
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: d8e054874fd90944d9eb03b3398db874
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,83 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 8
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: GridMaterial
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
m_Parent: {fileID: 0}
m_ModifiedSerializedProperties: 0
m_ValidKeywords: []
m_InvalidKeywords: []
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_LockedProperties:
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Ints: []
m_Floats:
- _BumpScale: 1
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _GlossMapScale: 1
- _Glossiness: 0.5
- _GlossyReflections: 1
- _Metallic: 0
- _Mode: 0
- _OcclusionStrength: 1
- _Parallax: 0.02
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _UVSec: 0
- _ZWrite: 1
m_Colors:
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
m_BuildTextureStacks: []
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 6ab99349792397f45a20efcb8c623941
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:
@@ -140,7 +140,7 @@ Transform:
m_GameObject: {fileID: 480666364}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 10.190587, y: 4.699326, z: -7.144069}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
@@ -229,7 +229,7 @@ MeshRenderer:
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 0}
- {fileID: 2100000, guid: 6ab99349792397f45a20efcb8c623941, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
@@ -349,7 +349,7 @@ Transform:
m_GameObject: {fileID: 519420028}
serializedVersion: 2
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalPosition: {x: 0, y: 0, z: -10}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 1
m_Children: []
@@ -13,7 +13,7 @@ public class Main : MonoBehaviour
void Start()
{
// Create world
world = new LogicGrid(5, 5, 10f, new Vector3(-10, -30));
world = new LogicGrid(5, 5, 10f, new Vector3(0, 0));
// Set default placement to Obstacle
placementValue = -1;
@@ -4,8 +4,12 @@ using UnityEngine;
public class MeshTesting : MonoBehaviour
{
Material m_Material;
void Start()
{
m_Material = GetComponent<Renderer>().material;
Debug.Log("Mesh Testing");
@@ -13,14 +17,24 @@ public class MeshTesting : MonoBehaviour
// Build required data-structures for triangle mesh
Vector3[] vertices = new Vector3[3];
Vector2[] uv = new Vector2[3];
int[] triangles = new int[3];
Vector3[] vertices = new Vector3[4];
Vector2[] uv = new Vector2[4];
int[] triangles = new int[6];
// Set vertices of polygon (triangle)
// Set vertices of polygon (2 triangles -> 1 quad)
vertices[0] = new Vector3( 0, 0);
vertices[1] = new Vector3( 0, 100);
vertices[2] = new Vector3(100, 100);
vertices[1] = new Vector3( 0, 10);
vertices[2] = new Vector3(10, 10);
vertices[3] = new Vector3(10, 0);
// UV index contains texture position that should match to vertex with same index
uv[0] = new Vector2(0, 0);
uv[1] = new Vector2(0, 1);
uv[2] = new Vector2(1, 1);
uv[3] = new Vector2(1, 0);
// Set order of indexes of vertices to draw polygon (v1 -> v2 -> v3 -> v1)
// Note: always set clockwise, otherwise mesh will be facing backwards
@@ -28,6 +42,9 @@ public class MeshTesting : MonoBehaviour
triangles[1] = 1;
triangles[2] = 2;
triangles[3] = 0;
triangles[4] = 2;
triangles[5] = 3;
mesh.vertices = vertices;
mesh.uv = uv;
@@ -36,4 +53,28 @@ public class MeshTesting : MonoBehaviour
GetComponent<MeshFilter>().mesh = mesh;
}
private void Update()
{
if(Input.GetKeyDown("1"))
{
Debug.Log("1");
m_Material.color = Color.white;
//m_Material.SetColor("_Color", Color.white);
}
if (Input.GetKeyDown("2"))
{
Debug.Log("2");
m_Material.color = Color.black;
//m_Material.SetColor("_Color", Color.white);
}
if (Input.GetKeyDown("3"))
{
Debug.Log("3");
m_Material.color = Color.green;
//m_Material.SetColor("_Color", Color.white);
}
}
}