This repository has been archived on 2024-11-03. You can view files and clone it, but cannot push or open issues or pull requests.
snakeinabox/Assets/Scripts/Drip.cs
2020-07-09 11:41:01 -07:00

138 lines
No EOL
3 KiB
C#

using UnityEngine;
using UnityEditor;
using System;
using System.Collections;
using System.Collections.Generic;
using Random = UnityEngine.Random;
using NaughtyAttributes;
public class Drip
{
public Drip(GraphXData data)
{
this.data = data;
}
GraphXData data;
// public AnimationCurve animCurve;
public class Drop
{
public float x, z;
public float firstY, lastY, rot;
public Drop()
{
this.x = 0;
this.z = 0;
this.firstY = -1000;
this.lastY = -1000;
this.rot = 0;
}
}
Drop[] drops = new Drop[9];
Matrix4x4[] matrices = new Matrix4x4[9];
public void Step(Main main)
{
for (int i = 0; i < drops.Length; i++)
{
if (drops[i] == null)
{
drops[i] = new Drop();
}
else if (drops[i].lastY == 3.5f)
{
main.poof.Splash(
new Vector3(drops[i].x, 3.5f, drops[i].z),
new Vector3(0.3f, 1, 0.3f),
0.1f
);
}
drops[i].x = Random.Range(-10f, 10f);
drops[i].z = Random.Range(-10f, 10f);
float height = 60f;
float offset = Random.Range(-30f, 30f);
drops[i].firstY = offset + (height / 2);
drops[i].lastY = offset - (height / 2);
drops[i].rot = 360 * Random.value;
if ((drops[i].x < main.design.bounds.x + 0.5f && drops[i].x > -main.design.bounds.x - 0.5f)
&& (drops[i].z < main.design.bounds.z + 0.5f && drops[i].z > -main.design.bounds.z - 0.5f))
{
// if its inside we need precise timing otherwise it doesn't matter
drops[i].lastY = 3.5f;
drops[i].firstY = drops[i].lastY + height;
}
}
testTime = 0;
}
float testTime;
public void Rain(Main main)
{
testTime += Time.deltaTime * 1.1f;
float stepTime = 60f / (float)main.bpm;
float lerp = Mathf.Clamp01(testTime / stepTime);
for (int i = 0; i < drops.Length; i++)
{
Vector3 pos = Vector3.zero;
Vector3 scale = Vector3.zero;
float rot = 0;
if (drops[i] != null)
{
pos = new Vector3(
drops[i].x,
Mathf.Lerp(drops[i].firstY, drops[i].lastY, lerp),
drops[i].z
);
float s = lerp * 2;
if (s > 1)
{
s = 1 - (s - 1);
}
if (drops[i].lastY == 3.5f)
{
s += 0.5f;
}
// s *= 10f;
scale = new Vector3(
s,
s * 2 * Vector2.Distance(new Vector2(pos.x, pos.z), new Vector2(main.rig.head.position.x, main.rig.head.position.z)),
s
);
rot = drops[i].rot;
}
matrices[i].SetTRS(pos, Quaternion.Euler(0, rot, 0), scale);
}
Graphics.DrawMeshInstanced(data.dripMesh, 0, data.wetMat, matrices);
}
void OnDrawGizmos()
{
// for (int i = 0; i < tracks.Length; i++)
// {
// for (int j = 0; j < tracks[i].positionCount; j++)
// {
// Gizmos.color = Color.black;
// Gizmos.DrawSphere(tracks[i].GetPosition(j), 0.1f);
// }
// }
}
}