wip : Cleaning not uses & integration liminal spaces
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f13157381d6fb6040abab2d065cfc6e5
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 998ca963664cdba409eb7e9bdb3d997a
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,28 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class BoatMover : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Transform _target;
|
||||
[SerializeField] private float _speed = 2f;
|
||||
[SerializeField] private float _tiltAmount = 3f;
|
||||
[SerializeField] private float _tiltSpeed = 0.8f;
|
||||
|
||||
private Vector3 _startPosition;
|
||||
private Quaternion _startRotation;
|
||||
|
||||
void Start()
|
||||
{
|
||||
_startPosition = transform.position;
|
||||
_startRotation = transform.rotation;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (_target == null) return;
|
||||
|
||||
transform.position = Vector3.MoveTowards(transform.position, _target.position, _speed * Time.deltaTime);
|
||||
|
||||
float tilt = Mathf.Sin(Time.time * _tiltSpeed) * _tiltAmount;
|
||||
transform.rotation = _startRotation * Quaternion.Euler(tilt, 0, tilt * 0.5f);
|
||||
}
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2ad389ae7a3c264478f56add3bdc53f1
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
using OctoCore.Components;
|
||||
using UnityEngine;
|
||||
|
||||
public class BoatPlayerSync : MonoBehaviour
|
||||
{
|
||||
private Vector3 _lastPosition;
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
_lastPosition = transform.position;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (OctoPlayer.Instance == null) return;
|
||||
|
||||
Vector3 delta = transform.position - _lastPosition;
|
||||
OctoPlayer.Instance.GetComponent<CharacterController>().Move(delta);
|
||||
|
||||
_lastPosition = transform.position;
|
||||
}
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2ff2be398108c8842bb01e0bb8f52f54
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bf1554292afd92b4eb64a4621c48b6ba
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 11ac527ae2550fe439450496a224f113
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
#region Using statements
|
||||
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Unheimlich.Core
|
||||
{
|
||||
public class FlagEnumAttribute : PropertyAttribute
|
||||
{
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 41e19a4b75910c146a0b391bbc5f1ea8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 187485
|
||||
packageName: URP Stylized Water Shader - Proto Series
|
||||
packageVersion: 1.0
|
||||
assetPath: Assets/Bitgem/StylisedWater/URP/Scripts/Bitgem/Core/FlagEnumAttribute.cs
|
||||
uploadId: 412673
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 68ba1b4fc29360446b280c7c9cdf24ec
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
#region Using statements
|
||||
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Unheimlich.Editor
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(Core.FlagEnumAttribute))]
|
||||
public class EnumFlagsAttributeDrawer : PropertyDrawer
|
||||
{
|
||||
public override void OnGUI(Rect _position, SerializedProperty _property, GUIContent _label)
|
||||
{
|
||||
_property.intValue = EditorGUI.MaskField(_position, _label, _property.intValue, _property.enumNames);
|
||||
}
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d359930cbabfcc7448e9f0e56039b644
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 187485
|
||||
packageName: URP Stylized Water Shader - Proto Series
|
||||
packageVersion: 1.0
|
||||
assetPath: Assets/Bitgem/StylisedWater/URP/Scripts/Bitgem/Editor/FlagEnumAttributeDrawer.cs
|
||||
uploadId: 412673
|
||||
+397
@@ -0,0 +1,397 @@
|
||||
#region Using statements
|
||||
|
||||
using Unheimlich.Core;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Unheimlich.VFX.StylisedWater
|
||||
{
|
||||
[ExecuteInEditMode]
|
||||
[RequireComponent(typeof(MeshFilter))]
|
||||
public class WaterVolumeBase : MonoBehaviour
|
||||
{
|
||||
#region Constants
|
||||
|
||||
public const int MAX_TILES_X = 100;
|
||||
public const int MAX_TILES_Y = 50;
|
||||
public const int MAX_TILES_Z = 100;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Flag lists
|
||||
|
||||
[System.Flags]
|
||||
public enum TileFace : int
|
||||
{
|
||||
NegX = 1,
|
||||
PosX = 2,
|
||||
NegZ = 4,
|
||||
PosZ = 8
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private fields
|
||||
|
||||
protected bool isDirty = true;
|
||||
|
||||
private UnityEngine.Mesh mesh = null;
|
||||
private MeshFilter meshFilter = null;
|
||||
|
||||
private bool[,,] tiles = null;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public fields
|
||||
|
||||
[FlagEnum]
|
||||
public TileFace IncludeFaces = TileFace.NegX | TileFace.NegZ | TileFace.PosX | TileFace.PosZ;
|
||||
|
||||
[FlagEnum]
|
||||
public TileFace IncludeFoam = TileFace.NegX | TileFace.NegZ | TileFace.PosX | TileFace.PosZ;
|
||||
|
||||
[Range(0.1f, 100f)]
|
||||
public float TileSize = 1f;
|
||||
|
||||
public bool ShowDebug = true;
|
||||
public bool RealtimeUpdates = false;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private methods
|
||||
|
||||
private void ensureReferences()
|
||||
{
|
||||
// ensure a mesh filter
|
||||
if (meshFilter == null)
|
||||
{
|
||||
mesh = null;
|
||||
meshFilter = gameObject.GetComponent<MeshFilter>();
|
||||
if (meshFilter == null)
|
||||
{
|
||||
meshFilter = gameObject.AddComponent<MeshFilter>();
|
||||
}
|
||||
}
|
||||
|
||||
// ensure a mesh
|
||||
if (mesh == null)
|
||||
{
|
||||
mesh = meshFilter.sharedMesh;
|
||||
if (mesh == null || mesh.name != "WaterVolume-" + gameObject.GetInstanceID())
|
||||
{
|
||||
mesh = new UnityEngine.Mesh();
|
||||
mesh.name = "WaterVolume-" + gameObject.GetInstanceID();
|
||||
}
|
||||
}
|
||||
|
||||
// apply the mesh to the filter
|
||||
meshFilter.sharedMesh = mesh;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public methods
|
||||
|
||||
public float? GetHeight(Vector3 _position)
|
||||
{
|
||||
// convert the position to a tile
|
||||
var x = Mathf.FloorToInt((_position.x - transform.position.x + 0.5f) / TileSize);
|
||||
var z = Mathf.FloorToInt((_position.z - transform.position.z + 0.5f) / TileSize);
|
||||
|
||||
// check if out of bounds
|
||||
if (x < 0 || x >= MAX_TILES_X || z < 0 || z >= MAX_TILES_Z)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// find the highest active water block in the column
|
||||
// TODO : could be reworked to cater for gaps
|
||||
for (var y = MAX_TILES_Y - 1; y >= 0; y--)
|
||||
{
|
||||
if (tiles[x, y, z])
|
||||
{
|
||||
return transform.position.y + y * TileSize;
|
||||
}
|
||||
}
|
||||
|
||||
// no water in the column
|
||||
return null;
|
||||
}
|
||||
|
||||
public void Rebuild()
|
||||
{
|
||||
// Debug.Log("rebuilding water volume \"" + gameObject.name + "\"");
|
||||
|
||||
// ensure references to components before trying to use them
|
||||
ensureReferences();
|
||||
|
||||
// delete any existing mesh
|
||||
mesh.Clear();
|
||||
|
||||
// allow any child class to generate the tiles to build from
|
||||
tiles = new bool[MAX_TILES_X, MAX_TILES_Y, MAX_TILES_Z];
|
||||
GenerateTiles(ref tiles);
|
||||
|
||||
// prepare buffers for the mesh data
|
||||
var vertices = new List<Vector3>();
|
||||
var normals = new List<Vector3>();
|
||||
var uvs = new List<Vector2>();
|
||||
var colors = new List<Color>();
|
||||
var indices = new List<int>();
|
||||
|
||||
// iterate the tiles
|
||||
for (var x = 0; x < MAX_TILES_X; x++)
|
||||
{
|
||||
for (var y = 0; y < MAX_TILES_Y; y++)
|
||||
{
|
||||
for (var z = 0; z < MAX_TILES_Z; z++)
|
||||
{
|
||||
// check there is water here
|
||||
if (!tiles[x, y, z])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// calculate tile position
|
||||
var x0 = x * TileSize - 0.5f;
|
||||
var x1 = x0 + TileSize;
|
||||
var y0 = y * TileSize - 0.5f;
|
||||
var y1 = y0 + TileSize;
|
||||
var z0 = z * TileSize - 0.5f;
|
||||
var z1 = z0 + TileSize;
|
||||
var ux0 = x0 + transform.position.x;
|
||||
var ux1 = x1 + transform.position.x;
|
||||
var uy0 = y0 + transform.position.y;
|
||||
var uy1 = y1 + transform.position.y;
|
||||
var uz0 = z0 + transform.position.z;
|
||||
var uz1 = z1 + transform.position.z;
|
||||
|
||||
// check for edges
|
||||
var negX = x == 0 || !tiles[x - 1, y, z];
|
||||
var posX = x == MAX_TILES_X - 1 || !tiles[x + 1, y, z];
|
||||
var negY = y == 0 || !tiles[x, y - 1, z];
|
||||
var posY = y == MAX_TILES_Y - 1 || !tiles[x, y + 1, z];
|
||||
var negZ = z == 0 || !tiles[x, y, z - 1];
|
||||
var posZ = z == MAX_TILES_Z - 1 || !tiles[x, y, z + 1];
|
||||
var negXnegZ = !negX && !negZ && x > 0 && z > 0 && !tiles[x - 1, y, z - 1];
|
||||
var negXposZ = !negX && !posZ && x > 0 && z < MAX_TILES_Z && !tiles[x - 1, y, z + 1];
|
||||
var posXposZ = !posX && !posZ && x < MAX_TILES_X && z < MAX_TILES_Z && !tiles[x + 1, y, z + 1];
|
||||
var posXnegZ = !posX && !negZ && x < MAX_TILES_X && z > 0 && !tiles[x + 1, y, z - 1];
|
||||
var faceNegX = negX && (IncludeFaces & TileFace.NegX) == TileFace.NegX;
|
||||
var facePosX = posX && (IncludeFaces & TileFace.PosX) == TileFace.PosX;
|
||||
var faceNegZ = negZ && (IncludeFaces & TileFace.NegZ) == TileFace.NegZ;
|
||||
var facePosZ = posZ && (IncludeFaces & TileFace.PosZ) == TileFace.PosZ;
|
||||
var foamNegX = negX && (IncludeFoam & TileFace.NegX) == TileFace.NegX;
|
||||
var foamPosX = posX && (IncludeFoam & TileFace.PosX) == TileFace.PosX;
|
||||
var foamNegZ = negZ && (IncludeFoam & TileFace.NegZ) == TileFace.NegZ;
|
||||
var foamPosZ = posZ && (IncludeFoam & TileFace.PosZ) == TileFace.PosZ;
|
||||
var foamNegXnegZ = negXnegZ && ((IncludeFoam & TileFace.NegX) == TileFace.NegX || (IncludeFoam & TileFace.NegZ) == TileFace.NegZ);
|
||||
var foamNegXposZ = negXposZ && ((IncludeFoam & TileFace.PosX) == TileFace.PosX || (IncludeFoam & TileFace.PosZ) == TileFace.PosZ);
|
||||
var foamPosXposZ = posXposZ && ((IncludeFoam & TileFace.NegZ) == TileFace.NegZ || (IncludeFoam & TileFace.PosZ) == TileFace.PosZ);
|
||||
var foamPosXnegZ = posXnegZ && ((IncludeFoam & TileFace.PosZ) == TileFace.PosZ || (IncludeFoam & TileFace.NegZ) == TileFace.NegZ);
|
||||
|
||||
// create the top face
|
||||
if (y == MAX_TILES_Y - 1 || !tiles[x, y + 1, z])
|
||||
{
|
||||
vertices.Add(new Vector3(x0, y1, z0));
|
||||
vertices.Add(new Vector3(x0, y1, z1));
|
||||
vertices.Add(new Vector3(x1, y1, z1));
|
||||
vertices.Add(new Vector3(x1, y1, z0));
|
||||
normals.Add(new Vector3(0, 1, 0));
|
||||
normals.Add(new Vector3(0, 1, 0));
|
||||
normals.Add(new Vector3(0, 1, 0));
|
||||
normals.Add(new Vector3(0, 1, 0));
|
||||
uvs.Add(new Vector2(ux0, uz0));
|
||||
uvs.Add(new Vector2(ux0, uz1));
|
||||
uvs.Add(new Vector2(ux1, uz1));
|
||||
uvs.Add(new Vector2(ux1, uz0));
|
||||
colors.Add(foamNegX || foamNegZ || foamNegXnegZ ? Color.red : Color.black);
|
||||
colors.Add(foamNegX || foamPosZ || foamNegXposZ ? Color.red : Color.black);
|
||||
colors.Add(foamPosX || foamPosZ || foamPosXposZ ? Color.red : Color.black);
|
||||
colors.Add(foamPosX || foamNegZ || foamPosXnegZ ? Color.red : Color.black);
|
||||
var v = vertices.Count - 4;
|
||||
if (foamNegX && foamPosZ || foamPosX && foamNegZ)
|
||||
{
|
||||
indices.Add(v + 1);
|
||||
indices.Add(v + 2);
|
||||
indices.Add(v + 3);
|
||||
indices.Add(v + 3);
|
||||
indices.Add(v);
|
||||
indices.Add(v + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
indices.Add(v);
|
||||
indices.Add(v + 1);
|
||||
indices.Add(v + 2);
|
||||
indices.Add(v + 2);
|
||||
indices.Add(v + 3);
|
||||
indices.Add(v);
|
||||
}
|
||||
}
|
||||
|
||||
// create the side faces
|
||||
if (faceNegX)
|
||||
{
|
||||
vertices.Add(new Vector3(x0, y0, z1));
|
||||
vertices.Add(new Vector3(x0, y1, z1));
|
||||
vertices.Add(new Vector3(x0, y1, z0));
|
||||
vertices.Add(new Vector3(x0, y0, z0));
|
||||
normals.Add(new Vector3(-1, 0, 0));
|
||||
normals.Add(new Vector3(-1, 0, 0));
|
||||
normals.Add(new Vector3(-1, 0, 0));
|
||||
normals.Add(new Vector3(-1, 0, 0));
|
||||
uvs.Add(new Vector2(uz1, uy0));
|
||||
uvs.Add(new Vector2(uz1, uy1));
|
||||
uvs.Add(new Vector2(uz0, uy1));
|
||||
uvs.Add(new Vector2(uz0, uy0));
|
||||
colors.Add(Color.black);
|
||||
colors.Add(posY ? Color.red : Color.black);
|
||||
colors.Add(posY ? Color.red : Color.black);
|
||||
colors.Add(Color.black);
|
||||
var v = vertices.Count - 4;
|
||||
indices.Add(v);
|
||||
indices.Add(v + 1);
|
||||
indices.Add(v + 2);
|
||||
indices.Add(v + 2);
|
||||
indices.Add(v + 3);
|
||||
indices.Add(v);
|
||||
}
|
||||
if (facePosX)
|
||||
{
|
||||
vertices.Add(new Vector3(x1, y0, z0));
|
||||
vertices.Add(new Vector3(x1, y1, z0));
|
||||
vertices.Add(new Vector3(x1, y1, z1));
|
||||
vertices.Add(new Vector3(x1, y0, z1));
|
||||
normals.Add(new Vector3(1, 0, 0));
|
||||
normals.Add(new Vector3(1, 0, 0));
|
||||
normals.Add(new Vector3(1, 0, 0));
|
||||
normals.Add(new Vector3(1, 0, 0));
|
||||
uvs.Add(new Vector2(uz0, uy0));
|
||||
uvs.Add(new Vector2(uz0, uy1));
|
||||
uvs.Add(new Vector2(uz1, uy1));
|
||||
uvs.Add(new Vector2(uz1, uy0));
|
||||
colors.Add(Color.black);
|
||||
colors.Add(posY ? Color.red : Color.black);
|
||||
colors.Add(posY ? Color.red : Color.black);
|
||||
colors.Add(Color.black);
|
||||
var v = vertices.Count - 4;
|
||||
indices.Add(v);
|
||||
indices.Add(v + 1);
|
||||
indices.Add(v + 2);
|
||||
indices.Add(v + 2);
|
||||
indices.Add(v + 3);
|
||||
indices.Add(v);
|
||||
}
|
||||
if (faceNegZ)
|
||||
{
|
||||
vertices.Add(new Vector3(x0, y0, z0));
|
||||
vertices.Add(new Vector3(x0, y1, z0));
|
||||
vertices.Add(new Vector3(x1, y1, z0));
|
||||
vertices.Add(new Vector3(x1, y0, z0));
|
||||
normals.Add(new Vector3(0, 0, -1));
|
||||
normals.Add(new Vector3(0, 0, -1));
|
||||
normals.Add(new Vector3(0, 0, -1));
|
||||
normals.Add(new Vector3(0, 0, -1));
|
||||
uvs.Add(new Vector2(ux0, uy0));
|
||||
uvs.Add(new Vector2(ux0, uy1));
|
||||
uvs.Add(new Vector2(ux1, uy1));
|
||||
uvs.Add(new Vector2(ux1, uy0));
|
||||
colors.Add(Color.black);
|
||||
colors.Add(posY ? Color.red : Color.black);
|
||||
colors.Add(posY ? Color.red : Color.black);
|
||||
colors.Add(Color.black);
|
||||
var v = vertices.Count - 4;
|
||||
indices.Add(v);
|
||||
indices.Add(v + 1);
|
||||
indices.Add(v + 2);
|
||||
indices.Add(v + 2);
|
||||
indices.Add(v + 3);
|
||||
indices.Add(v);
|
||||
}
|
||||
if (facePosZ)
|
||||
{
|
||||
vertices.Add(new Vector3(x1, y0, z1));
|
||||
vertices.Add(new Vector3(x1, y1, z1));
|
||||
vertices.Add(new Vector3(x0, y1, z1));
|
||||
vertices.Add(new Vector3(x0, y0, z1));
|
||||
normals.Add(new Vector3(0, 0, 1));
|
||||
normals.Add(new Vector3(0, 0, 1));
|
||||
normals.Add(new Vector3(0, 0, 1));
|
||||
normals.Add(new Vector3(0, 0, 1));
|
||||
uvs.Add(new Vector2(ux1, uy0));
|
||||
uvs.Add(new Vector2(ux1, uy1));
|
||||
uvs.Add(new Vector2(ux0, uy1));
|
||||
uvs.Add(new Vector2(ux0, uy0));
|
||||
colors.Add(Color.black);
|
||||
colors.Add(posY ? Color.red : Color.black);
|
||||
colors.Add(posY ? Color.red : Color.black);
|
||||
colors.Add(Color.black);
|
||||
var v = vertices.Count - 4;
|
||||
indices.Add(v);
|
||||
indices.Add(v + 1);
|
||||
indices.Add(v + 2);
|
||||
indices.Add(v + 2);
|
||||
indices.Add(v + 3);
|
||||
indices.Add(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// apply the buffers
|
||||
mesh.SetVertices(vertices);
|
||||
mesh.SetNormals(normals);
|
||||
mesh.SetUVs(0, uvs);
|
||||
mesh.SetColors(colors);
|
||||
mesh.SetTriangles(indices, 0);
|
||||
|
||||
// update
|
||||
mesh.RecalculateBounds();
|
||||
//mesh.RecalculateNormals();
|
||||
mesh.RecalculateTangents();
|
||||
|
||||
meshFilter.sharedMesh = mesh;
|
||||
|
||||
// flag as clean
|
||||
isDirty = false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Virtual methods
|
||||
|
||||
protected virtual void GenerateTiles(ref bool[,,] _tiles) { }
|
||||
public virtual void Validate() { }
|
||||
|
||||
#endregion
|
||||
|
||||
#region MonoBehaviour events
|
||||
|
||||
void OnValidate()
|
||||
{
|
||||
// keep tile size in a sensible range
|
||||
TileSize = Mathf.Clamp(TileSize, 0.1f, 100f);
|
||||
|
||||
// allow any child class to perform validation
|
||||
Validate();
|
||||
|
||||
// flag as needing rebuilding
|
||||
isDirty = true;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
// rebuild if needed
|
||||
if (isDirty || (!Application.isPlaying && RealtimeUpdates))
|
||||
{
|
||||
Rebuild();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1912f68a566bec4429513ef3d402aaeb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 187485
|
||||
packageName: URP Stylized Water Shader - Proto Series
|
||||
packageVersion: 1.0
|
||||
assetPath: Assets/Bitgem/StylisedWater/URP/Scripts/Bitgem/VFX/StylisedWater/WaterVolumeBase.cs
|
||||
uploadId: 412673
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
#region Using statements
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Unheimlich.VFX.StylisedWater
|
||||
{
|
||||
[AddComponentMenu("Bitgem/Water Volume (Box)")]
|
||||
public class WaterVolumeBox : WaterVolumeBase
|
||||
{
|
||||
#region Public fields
|
||||
|
||||
public Vector3 Dimensions = Vector3.zero;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public methods
|
||||
|
||||
protected override void GenerateTiles(ref bool[,,] _tiles)
|
||||
{
|
||||
// calculate volume in tiles
|
||||
var maxX = Mathf.Clamp(Mathf.RoundToInt(Dimensions.x / TileSize), 1, MAX_TILES_X);
|
||||
var maxY = Mathf.Clamp(Mathf.RoundToInt(Dimensions.y / TileSize), 1, MAX_TILES_Y);
|
||||
var maxZ = Mathf.Clamp(Mathf.RoundToInt(Dimensions.z / TileSize), 1, MAX_TILES_Z);
|
||||
|
||||
// populate the tiles with a box volume
|
||||
for (var x = 0; x < maxX; x++)
|
||||
{
|
||||
for (var y = 0; y < maxY; y++)
|
||||
{
|
||||
for (var z = 0; z < maxZ; z++)
|
||||
{
|
||||
_tiles[x, y, z] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void Validate()
|
||||
{
|
||||
// keep values sensible
|
||||
Dimensions.x = Mathf.Clamp(Dimensions.x, 1, MAX_TILES_X);
|
||||
Dimensions.y = Mathf.Clamp(Dimensions.y, 1, MAX_TILES_Y);
|
||||
Dimensions.z = Mathf.Clamp(Dimensions.z, 1, MAX_TILES_Z);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 427749d1fc2d12648a7acfc208590ea3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 187485
|
||||
packageName: URP Stylized Water Shader - Proto Series
|
||||
packageVersion: 1.0
|
||||
assetPath: Assets/Bitgem/StylisedWater/URP/Scripts/Bitgem/VFX/StylisedWater/WaterVolumeBox.cs
|
||||
uploadId: 412673
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
#region Using statements
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Unheimlich.VFX.StylisedWater
|
||||
{
|
||||
public class WaterVolumeHelper : MonoBehaviour
|
||||
{
|
||||
#region Private static fields
|
||||
|
||||
private static WaterVolumeHelper instance = null;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public fields
|
||||
|
||||
public WaterVolumeBase WaterVolume = null;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public static properties
|
||||
|
||||
public static WaterVolumeHelper Instance { get { return instance; } }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public methods
|
||||
|
||||
public float? GetHeight(Vector3 _position)
|
||||
{
|
||||
// ensure a water volume
|
||||
if (!WaterVolume)
|
||||
{
|
||||
return 0f;
|
||||
}
|
||||
|
||||
// ensure a material
|
||||
var renderer = WaterVolume.gameObject.GetComponent<MeshRenderer>();
|
||||
if (!renderer || !renderer.sharedMaterial)
|
||||
{
|
||||
return 0f;
|
||||
}
|
||||
|
||||
// replicate the shader logic, using parameters pulled from the specific material, to return the height at the specified position
|
||||
var waterHeight = WaterVolume.GetHeight(_position);
|
||||
if (!waterHeight.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var _WaveFrequency = renderer.sharedMaterial.GetFloat("_WaveFrequency");
|
||||
var _WaveScale = renderer.sharedMaterial.GetFloat("_WaveScale");
|
||||
var _WaveSpeed = renderer.sharedMaterial.GetFloat("_WaveSpeed");
|
||||
var time = Time.time * _WaveSpeed;
|
||||
var shaderOffset = (Mathf.Sin(_position.x * _WaveFrequency + time) + Mathf.Cos(_position.z * _WaveFrequency + time)) * _WaveScale;
|
||||
return waterHeight.Value + shaderOffset;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region MonoBehaviour events
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
instance = this;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cf39edffa406b4d4c8db438c744f592a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 187485
|
||||
packageName: URP Stylized Water Shader - Proto Series
|
||||
packageVersion: 1.0
|
||||
assetPath: Assets/Bitgem/StylisedWater/URP/Scripts/Bitgem/VFX/StylisedWater/WaterVolumeHelper.cs
|
||||
uploadId: 412673
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
#region Using statements
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Unheimlich.VFX.StylisedWater
|
||||
{
|
||||
[AddComponentMenu("Bitgem/Water Volume (Transforms)")]
|
||||
public class WaterVolumeTransforms : WaterVolumeBase
|
||||
{
|
||||
#region MonoBehaviour events
|
||||
|
||||
private void OnDrawGizmos()
|
||||
{
|
||||
if (!ShowDebug)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// iterate the chldren
|
||||
for (var i = 0; i < transform.childCount; i++)
|
||||
{
|
||||
// grab the local position/scale
|
||||
var pos = transform.GetChild(i).localPosition;
|
||||
var sca = transform.GetChild(i).localScale / TileSize;
|
||||
|
||||
// fix to the grid
|
||||
var x = Mathf.RoundToInt(pos.x / TileSize);
|
||||
var y = Mathf.RoundToInt(pos.y / TileSize);
|
||||
var z = Mathf.RoundToInt(pos.z / TileSize);
|
||||
|
||||
var drawPos = new Vector3(x, y, z) * TileSize;
|
||||
var drawSca = new Vector3(Mathf.RoundToInt(sca.x), Mathf.RoundToInt(sca.y), Mathf.RoundToInt(sca.z)) * TileSize;
|
||||
drawPos += drawSca / 2f;
|
||||
drawPos += transform.position;
|
||||
drawPos -= new Vector3(TileSize, TileSize, TileSize);
|
||||
|
||||
// render as wired volumes
|
||||
Gizmos.DrawWireCube(drawPos, drawSca);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTransformChildrenChanged()
|
||||
{
|
||||
Rebuild();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public methods
|
||||
|
||||
protected override void GenerateTiles(ref bool[,,] _tiles)
|
||||
{
|
||||
// iterate the chldren
|
||||
for (var i = 0; i < transform.childCount; i++)
|
||||
{
|
||||
// grab the local position/scale
|
||||
var pos = transform.GetChild(i).localPosition;
|
||||
var sca = transform.GetChild(i).localScale / TileSize;
|
||||
|
||||
// fix to the grid
|
||||
var x = Mathf.RoundToInt(pos.x / TileSize);
|
||||
var y = Mathf.RoundToInt(pos.y / TileSize);
|
||||
var z = Mathf.RoundToInt(pos.z / TileSize);
|
||||
|
||||
// iterate the size of the transform
|
||||
for (var ix = x; ix < x + Mathf.RoundToInt(sca.x); ix++)
|
||||
{
|
||||
for (var iy = y; iy < y + Mathf.RoundToInt(sca.y); iy++)
|
||||
{
|
||||
for (var iz = z; iz < z + Mathf.RoundToInt(sca.z); iz++)
|
||||
{
|
||||
// validate
|
||||
if (ix < 0 || ix >= MAX_TILES_X || iy < 0 | iy >= MAX_TILES_Y || iz < 0 || iz >= MAX_TILES_Z)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// add the tile
|
||||
_tiles[ix, iy, iz] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6d1bc949ada500e40a47e0e6f07b2d86
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 187485
|
||||
packageName: URP Stylized Water Shader - Proto Series
|
||||
packageVersion: 1.0
|
||||
assetPath: Assets/Bitgem/StylisedWater/URP/Scripts/Bitgem/VFX/StylisedWater/WaterVolumeTransforms.cs
|
||||
uploadId: 412673
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
#region Using statements
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Unheimlich.VFX.StylisedWater
|
||||
{
|
||||
public class WateverVolumeFloater : MonoBehaviour
|
||||
{
|
||||
#region Public fields
|
||||
|
||||
public WaterVolumeHelper WaterVolumeHelper = null;
|
||||
|
||||
#endregion
|
||||
|
||||
#region MonoBehaviour events
|
||||
|
||||
void Update()
|
||||
{
|
||||
var instance = WaterVolumeHelper ? WaterVolumeHelper : WaterVolumeHelper.Instance;
|
||||
if (!instance)
|
||||
{
|
||||
Debug.Log("No Instance !");
|
||||
return;
|
||||
}
|
||||
|
||||
transform.position = new Vector3(transform.position.x, instance.GetHeight(transform.position) ?? transform.position.y, transform.position.z);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 36aa02d38bb10b548bc7b8879596b15c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 187485
|
||||
packageName: URP Stylized Water Shader - Proto Series
|
||||
packageVersion: 1.0
|
||||
assetPath: Assets/Bitgem/StylisedWater/URP/Scripts/Bitgem/VFX/StylisedWater/WateverVolumeFloater.cs
|
||||
uploadId: 412673
|
||||
Reference in New Issue
Block a user