105 lines
No EOL
2.6 KiB
C#
105 lines
No EOL
2.6 KiB
C#
using System.Collections.Generic;
|
|
using System.Collections;
|
|
using UnityEngine;
|
|
|
|
public class GraphX
|
|
{
|
|
public GraphX(GraphXData data)
|
|
{
|
|
this.data = data;
|
|
}
|
|
|
|
GraphXData data;
|
|
|
|
Matrix4x4[] bodyMatrices = new Matrix4x4[9 * 7 * 9];
|
|
Matrix4x4[] coreMatrices = new Matrix4x4[3 * 3 * 3];
|
|
Matrix4x4 foodMatrix = new Matrix4x4();
|
|
Matrix4x4 arrowMatrix = new Matrix4x4();
|
|
Matrix4x4 faceMatrix = new Matrix4x4();
|
|
|
|
public float foodScale = 0;
|
|
|
|
public void Render(Main main)
|
|
{
|
|
foodScale = Mathf.Lerp(foodScale, 1, 6 * Time.deltaTime);
|
|
foodMatrix.SetTRS(
|
|
main.food,
|
|
Quaternion.Euler(new Vector3(Mathf.Sin(Time.time), Mathf.Sin(Time.time / 2), Mathf.Sin(Time.time / 3)) * 30),
|
|
foodScale * Vector3.one
|
|
); Graphics.DrawMesh(data.foodMesh, foodMatrix, data.unlitMat, 0);
|
|
|
|
if (!main.aiMode && main.playing)
|
|
{
|
|
arrowMatrix.SetTRS(
|
|
main.snake[0],
|
|
main.rig.controllerRot,
|
|
Vector3.one
|
|
); Graphics.DrawMesh(data.arrowMesh, arrowMatrix, data.unlitMat, 0);
|
|
}
|
|
|
|
// Face
|
|
if (main.snake.Count > 0)
|
|
{
|
|
faceMatrix.SetTRS(
|
|
main.snake[0],
|
|
Quaternion.LookRotation(main.dir),
|
|
Vector3.one
|
|
); Graphics.DrawMesh(data.faceMesh, faceMatrix, data.snakeMat, 0);
|
|
|
|
// Body
|
|
for (int i = 1; i < bodyMatrices.Length; i++)
|
|
{
|
|
if (i > 0 && i < main.snake.Count)
|
|
{
|
|
Vector3 segmentDir = main.snake[i - 1] - main.snake[i];
|
|
if (segmentDir.sqrMagnitude == 0)
|
|
{
|
|
segmentDir = new Vector3Int(0, 0, 1);
|
|
}
|
|
bodyMatrices[i].SetTRS(main.snake[i], Quaternion.LookRotation(segmentDir), Vector3.one);
|
|
}
|
|
else
|
|
{
|
|
bodyMatrices[i].SetTRS(Vector3.zero, Quaternion.identity, Vector3.zero);
|
|
}
|
|
}
|
|
Graphics.DrawMeshInstanced(data.bodyMesh, 0, data.snakeMat, bodyMatrices);
|
|
}
|
|
|
|
// Core
|
|
for (int i = 0; i < coreMatrices.Length; i++)
|
|
{
|
|
if (i < main.core.Count)
|
|
{
|
|
coreMatrices[i].SetTRS(main.core[i], Quaternion.identity, Vector3.one);
|
|
}
|
|
else
|
|
{
|
|
coreMatrices[i].SetTRS(Vector3.zero, Quaternion.identity, Vector3.zero);
|
|
}
|
|
}
|
|
Graphics.DrawMeshInstanced(data.coreMesh, 0, data.unlitMat, coreMatrices);
|
|
|
|
|
|
// Body Roll
|
|
if (rollTime > 0)
|
|
{
|
|
rollTime -= Time.deltaTime;
|
|
}
|
|
else
|
|
{
|
|
if (main.justAte < 729)
|
|
{
|
|
Shader.SetGlobalInt("_JustAte", ++main.justAte);
|
|
}
|
|
|
|
rollTime = Mathf.Clamp01((60 / (float)main.bpm) / 27);
|
|
}
|
|
}
|
|
|
|
float rollTime;
|
|
public void Step(Main main)
|
|
{
|
|
Shader.SetGlobalInt("_JustAte", main.justAte++);
|
|
}
|
|
} |