✨ Add water shader by Atlas and, flip some faces and experiment with animations
This commit is contained in:
parent
bf6da1e7c9
commit
c50e9258cf
1764 changed files with 303341 additions and 66722 deletions
48
Assets/Bakery/examples/scripts/BakeryVolumeReceiver.cs
Normal file
48
Assets/Bakery/examples/scripts/BakeryVolumeReceiver.cs
Normal file
|
@ -0,0 +1,48 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
// Example script, a counterpart to BakeryVolumeTrigger.cs (see that script for more info)
|
||||
//
|
||||
public class BakeryVolumeReceiver : MonoBehaviour
|
||||
{
|
||||
public bool forceUsage = false;
|
||||
|
||||
// used by triggers
|
||||
internal int enterCounter = 0;
|
||||
internal BakeryVolumeTrigger movableTrigger = null;
|
||||
|
||||
Renderer[] renderers;
|
||||
MaterialPropertyBlock current;
|
||||
|
||||
// Cache renderers affected by volumes
|
||||
void Awake()
|
||||
{
|
||||
if (renderers == null) renderers = GetComponentsInChildren<Renderer>() as Renderer[];
|
||||
if (forceUsage)
|
||||
{
|
||||
// HDRP can sometimes (?) fail to use globally set volumes when SRP batching is enabled, so disable it for this object.
|
||||
SetPropertyBlock(new MaterialPropertyBlock());
|
||||
}
|
||||
}
|
||||
|
||||
// Called by triggers
|
||||
public void SetPropertyBlock(MaterialPropertyBlock mb)
|
||||
{
|
||||
if (renderers == null) renderers = GetComponentsInChildren<Renderer>() as Renderer[];
|
||||
for(int i=0; i<renderers.Length; i++)
|
||||
{
|
||||
renderers[i].SetPropertyBlock(mb);
|
||||
}
|
||||
current = mb;
|
||||
}
|
||||
|
||||
// Update shader properties here if the volume is moving
|
||||
void LateUpdate()
|
||||
{
|
||||
if (movableTrigger == null) return;
|
||||
|
||||
movableTrigger.UpdateBounds();
|
||||
SetPropertyBlock(current);
|
||||
}
|
||||
}
|
12
Assets/Bakery/examples/scripts/BakeryVolumeReceiver.cs.meta
Normal file
12
Assets/Bakery/examples/scripts/BakeryVolumeReceiver.cs.meta
Normal file
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2b3f9409bbd2d70498366efc67277202
|
||||
timeCreated: 1605956660
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
78
Assets/Bakery/examples/scripts/BakeryVolumeTrigger.cs
Normal file
78
Assets/Bakery/examples/scripts/BakeryVolumeTrigger.cs
Normal file
|
@ -0,0 +1,78 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
// Example volume switching script
|
||||
//
|
||||
// The high-level logic is following:
|
||||
//
|
||||
// - Volumes overlap each other a bit, so we don't need blending! The size of the overlap is the size of your largest dynamic object.
|
||||
// - As object enters the volume, set volume data to it. Increment the counter.
|
||||
// - As object leaves the volume, decrement the counter. If it equals 0, use global volume (set empty property block).
|
||||
// - If the volume is moving, set volume data every frame, in LateUpdate.
|
||||
//
|
||||
public class BakeryVolumeTrigger : MonoBehaviour
|
||||
{
|
||||
public bool movable;
|
||||
|
||||
BakeryVolume vol;
|
||||
MaterialPropertyBlock mb; // current volume shader properties
|
||||
|
||||
static MaterialPropertyBlock mbEmpty; // default empty block, no values (will revert to global volume)
|
||||
static int mVolumeMin, mVolumeInvSize; // shader property IDs
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if (mbEmpty == null) mbEmpty = new MaterialPropertyBlock();
|
||||
|
||||
// Create a MaterialPropertyBlock with Volume parameters for future use
|
||||
vol = GetComponent<BakeryVolume>();
|
||||
mb = new MaterialPropertyBlock();
|
||||
if (vol.bakedTexture0 != null)
|
||||
{
|
||||
mb.SetTexture("_Volume0", vol.bakedTexture0);
|
||||
mb.SetTexture("_Volume1", vol.bakedTexture1);
|
||||
mb.SetTexture("_Volume2", vol.bakedTexture2);
|
||||
if (vol.bakedTexture3 != null) mb.SetTexture("_Volume3", vol.bakedTexture3);
|
||||
}
|
||||
if (vol.bakedMask != null) mb.SetTexture("_VolumeMask", vol.bakedMask);
|
||||
if (mVolumeMin == 0) mVolumeMin = Shader.PropertyToID("_VolumeMin");
|
||||
if (mVolumeInvSize == 0) mVolumeInvSize = Shader.PropertyToID("_VolumeInvSize");
|
||||
mb.SetVector(mVolumeMin, vol.GetMin());
|
||||
mb.SetVector(mVolumeInvSize, vol.GetInvSize());
|
||||
if (vol.supportRotationAfterBake) mb.SetMatrix("_VolumeMatrix", vol.GetMatrix());
|
||||
}
|
||||
|
||||
// Apply MaterialPropertyBlock to renderers entering the trigger
|
||||
void OnTriggerEnter(Collider c)
|
||||
{
|
||||
var rcv = c.GetComponent<BakeryVolumeReceiver>();
|
||||
if (rcv == null) return;
|
||||
|
||||
Debug.Log(c.name + " entered " + this.name);
|
||||
|
||||
rcv.enterCounter++;
|
||||
rcv.movableTrigger = movable ? this : null;
|
||||
rcv.SetPropertyBlock(mb);
|
||||
}
|
||||
|
||||
// Handle exiting the trigger
|
||||
void OnTriggerExit(Collider c)
|
||||
{
|
||||
var rcv = c.GetComponent<BakeryVolumeReceiver>();
|
||||
if (rcv == null) return;
|
||||
|
||||
Debug.Log(c.name + " exited " + this.name);
|
||||
|
||||
// Only set empty property block, if the counter is 0 (= exited ALL volumes)
|
||||
rcv.enterCounter--;
|
||||
if (rcv.enterCounter == 0) rcv.SetPropertyBlock(mbEmpty);
|
||||
}
|
||||
|
||||
public void UpdateBounds()
|
||||
{
|
||||
vol.UpdateBounds();
|
||||
mb.SetVector(mVolumeMin, vol.GetMin());
|
||||
mb.SetVector(mVolumeInvSize, vol.GetInvSize());
|
||||
}
|
||||
}
|
12
Assets/Bakery/examples/scripts/BakeryVolumeTrigger.cs.meta
Normal file
12
Assets/Bakery/examples/scripts/BakeryVolumeTrigger.cs.meta
Normal file
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 88131403915d92648ac25dbc4ffb0e1b
|
||||
timeCreated: 1605889761
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
52
Assets/Bakery/examples/scripts/VolumeTestScene2.cs
Normal file
52
Assets/Bakery/examples/scripts/VolumeTestScene2.cs
Normal file
|
@ -0,0 +1,52 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class VolumeTestScene2 : MonoBehaviour
|
||||
{
|
||||
public Transform secondFloor;
|
||||
public BakeryVolumeTrigger[] secondFloorVolumes;
|
||||
public float secondFloorHeight;
|
||||
public bool randomizeLastRoom;
|
||||
public Transform baseRoom;
|
||||
public Transform alternativeRoom;
|
||||
|
||||
void SwapRooms()
|
||||
{
|
||||
var tmp = alternativeRoom.position;
|
||||
alternativeRoom.position = baseRoom.position;
|
||||
baseRoom.position = tmp;
|
||||
}
|
||||
|
||||
void UpdateRooms()
|
||||
{
|
||||
for(int i=0; i<secondFloorVolumes.Length; i++)
|
||||
{
|
||||
secondFloorVolumes[i].UpdateBounds();
|
||||
}
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (randomizeLastRoom)
|
||||
{
|
||||
if (Random.Range(0,2) == 1)
|
||||
{
|
||||
SwapRooms();
|
||||
}
|
||||
}
|
||||
|
||||
secondFloor.position += Vector3.up * secondFloorHeight;
|
||||
|
||||
UpdateRooms();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.Space))
|
||||
{
|
||||
SwapRooms();
|
||||
UpdateRooms();
|
||||
}
|
||||
}
|
||||
}
|
12
Assets/Bakery/examples/scripts/VolumeTestScene2.cs.meta
Normal file
12
Assets/Bakery/examples/scripts/VolumeTestScene2.cs.meta
Normal file
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f7a6f035f96fb254a92088728f6ac9f7
|
||||
timeCreated: 1605889761
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Add table
Add a link
Reference in a new issue