Added many other

This commit is contained in:
2026-08-06 18:56:32 +03:00
parent 9f2fd08ee5
commit d9d7ee49d2
2144 changed files with 1115424 additions and 1284 deletions
@@ -0,0 +1,80 @@
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());
if (vol.rotateAroundY) mb.SetVector("_VolumeRY", vol.GetRotationY());
mb.SetVector("_VolumeVoxelSize", new Vector3(1.0f/vol.bakedTexture0.width, 1.0f/vol.bakedTexture0.height, 1.0f/vol.bakedTexture0.depth));
}
// 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());
}
}