修改水

This commit is contained in:
2026-01-01 22:00:33 +08:00
parent 040a222bd6
commit 9ceffccd39
1800 changed files with 103929 additions and 139495 deletions

View File

@@ -1,78 +1,110 @@
using UnityEngine;
using Unity.Profiling;
using System;
using System.Threading;
using System.Collections;
using System.Collections.Generic;
namespace Obi
{
public interface IParticleRenderer
{
public ObiActor actor { get; }
public Color particleColor { get; }
public float radiusScale { get; }
}
public struct ParticleRendererData
{
public Color color;
public float radiusScale;
public ParticleRendererData(Color color, float radiusScale)
{
this.color = color;
this.radiusScale = radiusScale;
}
}
[AddComponentMenu("Physics/Obi/Obi Particle Renderer", 1000)]
[ExecuteInEditMode]
[RequireComponent(typeof(ObiActor))]
public class ObiParticleRenderer : MonoBehaviour, IParticleRenderer, ObiActorRenderer<ObiParticleRenderer>
public class ObiParticleRenderer : MonoBehaviour
{
public Material material;
public RenderBatchParams renderParameters = new RenderBatchParams(true);
static ProfilerMarker m_DrawParticlesPerfMarker = new ProfilerMarker("DrawParticles");
[field: SerializeField]
public Color particleColor { get; set; } = Color.white;
public bool render = true;
public Shader shader;
public Color particleColor = Color.white;
public float radiusScale = 1;
private ParticleImpostorRendering m_Impostors;
[field: SerializeField]
public float radiusScale { get; set; } = 1;
public ObiActor actor { get; private set; }
public void Awake()
public IEnumerable<Mesh> ParticleMeshes
{
actor = GetComponent<ObiActor>();
get { return impostors.Meshes; }
}
public ParticleImpostorRendering impostors
{
get {
if (m_Impostors == null)
m_Impostors = new ParticleImpostorRendering();
return m_Impostors;
}
}
public Material ParticleMaterial { get; private set; }
public void OnEnable()
{
((ObiActorRenderer<ObiParticleRenderer>)this).EnableRenderer();
GetComponent<ObiActor>().OnInterpolate += DrawParticles;
}
public void OnDisable()
{
((ObiActorRenderer<ObiParticleRenderer>)this).DisableRenderer();
GetComponent<ObiActor>().OnInterpolate -= DrawParticles;
if (m_Impostors != null)
m_Impostors.ClearMeshes();
DestroyImmediate(ParticleMaterial);
}
public void OnValidate()
void CreateMaterialIfNeeded()
{
((ObiActorRenderer<ObiParticleRenderer>)this).SetRendererDirty(Oni.RenderingSystemType.Particles);
}
RenderSystem<ObiParticleRenderer> ObiRenderer<ObiParticleRenderer>.CreateRenderSystem(ObiSolver solver)
{
switch (solver.backendType)
if (shader != null)
{
if (!shader.isSupported)
Debug.LogWarning("Particle rendering shader not suported.");
#if (OBI_BURST && OBI_MATHEMATICS && OBI_COLLECTIONS)
case ObiSolver.BackendType.Burst: return new BurstParticleRenderSystem(solver);
#endif
case ObiSolver.BackendType.Compute:
default:
if (SystemInfo.supportsComputeShaders)
return new ComputeParticleRenderSystem(solver);
return null;
if (ParticleMaterial == null || ParticleMaterial.shader != shader)
{
DestroyImmediate(ParticleMaterial);
ParticleMaterial = new Material(shader);
ParticleMaterial.hideFlags = HideFlags.HideAndDontSave;
}
}
}
void DrawParticles(ObiActor actor)
{
using (m_DrawParticlesPerfMarker.Auto())
{
if (!isActiveAndEnabled || !actor.isActiveAndEnabled || actor.solver == null)
{
impostors.ClearMeshes();
return;
}
CreateMaterialIfNeeded();
impostors.UpdateMeshes(actor);
DrawParticles();
}
}
private void DrawParticles()
{
if (ParticleMaterial != null)
{
ParticleMaterial.SetFloat("_RadiusScale", radiusScale);
ParticleMaterial.SetColor("_Color", particleColor);
// Send the meshes to be drawn:
if (render)
{
var meshes = ParticleMeshes;
foreach (Mesh mesh in meshes)
Graphics.DrawMesh(mesh, Matrix4x4.identity, ParticleMaterial, gameObject.layer);
}
}
}
}
}