229 lines
No EOL
5.2 KiB
C#
229 lines
No EOL
5.2 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;
|
|
|
|
for (int i = 0; i < drops.Length; i++)
|
|
{
|
|
drops[i] = new Drop();
|
|
}
|
|
|
|
for (int i = 0; i < drails.Length; i++)
|
|
{
|
|
drails[i] = new Drail();
|
|
}
|
|
}
|
|
|
|
GraphXData data;
|
|
|
|
Drop[] drops = new Drop[10];
|
|
Drail[] drails = new Drail[40];
|
|
Matrix4x4[] matrices = new Matrix4x4[50];
|
|
|
|
// pool
|
|
// fall and fade
|
|
// just need to fall at and spawn at a height and rate
|
|
// to hit the box in time
|
|
|
|
// just DRIP DRIP DRIPS
|
|
// falling shit is distracting and spatially confusing
|
|
|
|
// pooling and drip downs
|
|
// code first then review and refine visually
|
|
|
|
// consider the moving parts
|
|
|
|
// pools (x and y and size)
|
|
// check for edge then drip all out (cohesion)so adjust position as dripping
|
|
|
|
// and x and y are not world space just 0-1 (square so now skewing ^-^)
|
|
// map to world space with the rendering
|
|
// pools and drips all share the same matrix and instanced renderer
|
|
|
|
// now with your door open lets get the pooling working before any more lewds
|
|
|
|
|
|
// fix rain & analog visual representation of beat (two birds one stone)
|
|
|
|
// public AnimationCurve animCurve; ??
|
|
|
|
public class Range
|
|
{
|
|
public float min = 0;
|
|
public float max = 0;
|
|
|
|
public Range(float min = 0, float max = 0)
|
|
{
|
|
this.min = min;
|
|
this.max = max;
|
|
}
|
|
|
|
public static Range zero { get { return new Range(0, 0); } }
|
|
public static Range one { get { return new Range(0, 1); } }
|
|
|
|
public float length { get { return max - min; } }
|
|
public float middle { get { return min + length / 2; } }
|
|
}
|
|
|
|
public class Drop
|
|
{
|
|
public bool down; // ready to go
|
|
public Quaternion quat;
|
|
public float scale;
|
|
|
|
public Drop()
|
|
{
|
|
this.down = true;
|
|
this.scale = Random.Range(1f, 2f);
|
|
this.quat = Quaternion.identity;
|
|
}
|
|
}
|
|
|
|
public class Drail
|
|
{
|
|
public Quaternion quat;
|
|
public float scale;
|
|
|
|
public Drail()
|
|
{
|
|
this.quat = Quaternion.identity;
|
|
this.scale = 0;
|
|
}
|
|
}
|
|
|
|
|
|
public void Step(Main main)
|
|
{
|
|
for (int i = 0; i < drops.Length; i++)
|
|
{
|
|
Drop drop = drops[i];
|
|
|
|
if (drop.down && !bumped)
|
|
{
|
|
drop.quat = UnityEngine.Random.rotation;
|
|
// nay not a position but rather a quaternion!
|
|
// that is clamped and scaled to fit the box (builtin corner handling)
|
|
|
|
// main.poof.Splash(
|
|
// ClampOut(drop.quat),
|
|
// drop.quat * new Vector3(0.1f, 0.1f, 0.3f),
|
|
// 0.15f
|
|
// );
|
|
|
|
drop.down = false;
|
|
}
|
|
else
|
|
{
|
|
// recycle
|
|
// and drip off is as easy as an angle comparison with con direction
|
|
float angle = Quaternion.Angle(drop.quat, main.inputRot);
|
|
if (angle < 45 && Random.value < 0.5f)
|
|
{
|
|
drop.down = true;
|
|
}
|
|
else
|
|
{
|
|
for (int j = 0; j < drails.Length; j++)
|
|
{
|
|
Drail drail = drails[j];
|
|
if (drail.scale == 0 && Random.value < 0.3f)
|
|
{
|
|
drail.quat = drop.quat;
|
|
drail.scale = Random.value;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
bumped = false;
|
|
}
|
|
|
|
public void Rain(Main main)
|
|
{
|
|
for (int i = 0; i < drops.Length; i++)
|
|
{
|
|
Drop drop = drops[i];
|
|
|
|
float angle = Quaternion.Angle(drop.quat, main.inputRot) / 180f;
|
|
if (angle < 0.8f)
|
|
{
|
|
drop.quat = Quaternion.Slerp(drop.quat, main.inputRot, Time.deltaTime / 10 * angle);
|
|
}
|
|
|
|
Vector3 pos = ClampOut(drop.quat);
|
|
|
|
float scale = 1;
|
|
if (drop.down)
|
|
{
|
|
scale = (1 - main.lerp);
|
|
pos += drop.quat * Vector3.forward * 6f * main.lerp * main.lerp;
|
|
}
|
|
else if (main.lerp < 0.1f)
|
|
{
|
|
scale *= Mathf.Lerp(1.2f, 1, (main.lerp * main.lerp) / 0.1f);
|
|
}
|
|
|
|
Quaternion rot = drop.quat;
|
|
rot = Quaternion.LookRotation(Main.SnapDir(rot * Vector3.forward));
|
|
|
|
matrices[i].SetTRS(
|
|
pos,
|
|
rot,
|
|
new Vector3(0.1f, 0.1f, 0.08f) * scale * drop.scale
|
|
);
|
|
}
|
|
|
|
for (int i = 0; i < drails.Length; i++)
|
|
{
|
|
Drail drail = drails[i];
|
|
|
|
drail.scale = Mathf.Max(drail.scale - Time.deltaTime / 6, 0);
|
|
|
|
matrices[drops.Length + i].SetTRS(
|
|
ClampOut(drail.quat),
|
|
Quaternion.LookRotation(Main.SnapDir(drail.quat * Vector3.forward)),
|
|
Vector3.one * drail.scale * 0.06f
|
|
);
|
|
}
|
|
|
|
Graphics.DrawMeshInstanced(data.dripMesh, 0, data.wetMat, matrices);
|
|
}
|
|
|
|
bool bumped = false;
|
|
public void Bump(Vector3 dir)
|
|
{
|
|
for (int i = 0; i < drops.Length; i++)
|
|
{
|
|
Drop drop = drops[i];
|
|
|
|
drop.quat = Quaternion.Lerp(drop.quat, Quaternion.LookRotation(dir), 0.1f);
|
|
|
|
float angle = Quaternion.Angle(drop.quat, Quaternion.LookRotation(dir));
|
|
if (angle < 90)
|
|
{
|
|
drop.down = true;
|
|
}
|
|
}
|
|
bumped = true;
|
|
}
|
|
|
|
public Vector3 ClampOut(Quaternion quat)
|
|
{
|
|
Vector3 pos = quat * Vector3.forward * 7.5f;
|
|
pos.x = Mathf.Clamp(pos.x, -3.5f, 3.5f);
|
|
pos.y = Mathf.Clamp(pos.y, -2.5f, 2.5f);
|
|
pos.z = Mathf.Clamp(pos.z, -3.5f, 3.5f);
|
|
|
|
return pos;
|
|
}
|
|
} |