From 852878765b0acfdb8bac1a54384a062c5636367c Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Tue, 3 Aug 2021 10:18:34 +0200 Subject: [PATCH] Allow visual style to modify the particle templates during init, so GLQuake and Software styles can share the same particle systems, but apply different particle sizes and materials. Also slightly tweaked the minimum particle size on all effects. --- Assets/Scripts/VisualStyle.cs | 40 +++++ Assets/Styles/GLQuake/GLQuake.asset | 2 + .../GLQuake/Particles/BlobExplosion.prefab | 4 +- .../GLQuake/Particles/LavaSplash.prefab | 2 +- .../GLQuake/Particles/ParticleEffect.prefab | 2 +- .../Particles/ParticleExplosion.prefab | 4 +- .../GLQuake/Particles/RogueExplosion.prefab | 2 +- .../{Particle.mat => RoundParticle.mat} | 2 +- ...rticle.mat.meta => RoundParticle.mat.meta} | 0 .../GLQuake/Particles/SquareParticle.mat | 142 ++++++++++++++++++ .../GLQuake/Particles/SquareParticle.mat.meta | 8 + .../GLQuake/Particles/TeleportSplash.prefab | 2 +- Assets/Styles/GLQuake/Software.asset | 15 +- 13 files changed, 215 insertions(+), 10 deletions(-) rename Assets/Styles/GLQuake/Particles/{Particle.mat => RoundParticle.mat} (99%) rename Assets/Styles/GLQuake/Particles/{Particle.mat.meta => RoundParticle.mat.meta} (100%) create mode 100644 Assets/Styles/GLQuake/Particles/SquareParticle.mat create mode 100644 Assets/Styles/GLQuake/Particles/SquareParticle.mat.meta diff --git a/Assets/Scripts/VisualStyle.cs b/Assets/Scripts/VisualStyle.cs index a4cc668..652bed9 100644 --- a/Assets/Scripts/VisualStyle.cs +++ b/Assets/Scripts/VisualStyle.cs @@ -30,6 +30,8 @@ public class VisualStyle : ScriptableObject public virtual void Activate() { + particles.Init(); + if (pointSampling) Shader.EnableKeyword("_POINT_SAMPLING"); else @@ -152,6 +154,12 @@ public class LiquidProperties [System.Serializable] public class ParticleSystems { + [SerializeField] + protected Material particleMaterial; + + [SerializeField] + protected float particleSize = 1.0f; + [SerializeField] protected ParticleSystem particleEffect; @@ -170,6 +178,38 @@ public class ParticleSystems [SerializeField] protected ParticleSystem lavaSplash; + public virtual void Init() + { + InitTemplate(particleEffect); + InitTemplate(explosion); + InitTemplate(rogueExplosion); + InitTemplate(blobExplosion); + InitTemplate(teleportSplash); + InitTemplate(lavaSplash); + } + + protected virtual void InitTemplate(ParticleSystem template) + { + if (template == null) + return; + + var main = template.main; + main.startSize = particleSize; + + if (particleMaterial != null) + { + var renderer = template.GetComponent(); + renderer.sharedMaterial = particleMaterial; + } + + int childCount = template.transform.childCount; + for (int i = 0; i < childCount; ++i) + { + var child = template.transform.GetChild(i); + InitTemplate(child.GetComponent()); + } + } + public virtual void RunParticleEffect(Vector3 position, Vector3 direction, Color colorMin, Color colorMax, int count, Layers layer) { var effect = InstantiateEffect(particleEffect, position, layer); diff --git a/Assets/Styles/GLQuake/GLQuake.asset b/Assets/Styles/GLQuake/GLQuake.asset index f91ba94..fe983c3 100644 --- a/Assets/Styles/GLQuake/GLQuake.asset +++ b/Assets/Styles/GLQuake/GLQuake.asset @@ -23,6 +23,8 @@ MonoBehaviour: lavaAlpha: 0.9 teleAlpha: 1 particles: + particleMaterial: {fileID: 2100000, guid: 4224080a2fee880419642256cbfaee41, type: 2} + particleSize: 1.38 particleEffect: {fileID: 9150008102338277659, guid: d911d6d226122ae4e97a2fc6f268503d, type: 3} explosion: {fileID: 9150008102338277659, guid: 94e2cf23692eef24d9a5145b0f705c55, diff --git a/Assets/Styles/GLQuake/Particles/BlobExplosion.prefab b/Assets/Styles/GLQuake/Particles/BlobExplosion.prefab index a74e843..4b423a0 100644 --- a/Assets/Styles/GLQuake/Particles/BlobExplosion.prefab +++ b/Assets/Styles/GLQuake/Particles/BlobExplosion.prefab @@ -4921,7 +4921,7 @@ ParticleSystemRenderer: m_SortingOrder: 0 m_RenderMode: 0 m_SortMode: 0 - m_MinParticleSize: 0.002 + m_MinParticleSize: 0.0025 m_MaxParticleSize: 0.5 m_CameraVelocityScale: 0 m_VelocityScale: 0 @@ -10107,7 +10107,7 @@ ParticleSystemRenderer: m_SortingOrder: 0 m_RenderMode: 0 m_SortMode: 0 - m_MinParticleSize: 0.002 + m_MinParticleSize: 0.0025 m_MaxParticleSize: 0.5 m_CameraVelocityScale: 0 m_VelocityScale: 0 diff --git a/Assets/Styles/GLQuake/Particles/LavaSplash.prefab b/Assets/Styles/GLQuake/Particles/LavaSplash.prefab index 6eddfe3..4084467 100644 --- a/Assets/Styles/GLQuake/Particles/LavaSplash.prefab +++ b/Assets/Styles/GLQuake/Particles/LavaSplash.prefab @@ -4839,7 +4839,7 @@ ParticleSystemRenderer: m_SortingOrder: 0 m_RenderMode: 0 m_SortMode: 0 - m_MinParticleSize: 0.003 + m_MinParticleSize: 0.0025 m_MaxParticleSize: 0.5 m_CameraVelocityScale: 0 m_VelocityScale: 0 diff --git a/Assets/Styles/GLQuake/Particles/ParticleEffect.prefab b/Assets/Styles/GLQuake/Particles/ParticleEffect.prefab index 6338a1a..4ffb9d1 100644 --- a/Assets/Styles/GLQuake/Particles/ParticleEffect.prefab +++ b/Assets/Styles/GLQuake/Particles/ParticleEffect.prefab @@ -4839,7 +4839,7 @@ ParticleSystemRenderer: m_SortingOrder: 0 m_RenderMode: 0 m_SortMode: 0 - m_MinParticleSize: 0.003 + m_MinParticleSize: 0.0025 m_MaxParticleSize: 0.5 m_CameraVelocityScale: 0 m_VelocityScale: 0 diff --git a/Assets/Styles/GLQuake/Particles/ParticleExplosion.prefab b/Assets/Styles/GLQuake/Particles/ParticleExplosion.prefab index 4b85460..62d583d 100644 --- a/Assets/Styles/GLQuake/Particles/ParticleExplosion.prefab +++ b/Assets/Styles/GLQuake/Particles/ParticleExplosion.prefab @@ -4840,7 +4840,7 @@ ParticleSystemRenderer: m_SortingOrder: 0 m_RenderMode: 0 m_SortMode: 0 - m_MinParticleSize: 0.003 + m_MinParticleSize: 0.0025 m_MaxParticleSize: 0.5 m_CameraVelocityScale: 0 m_VelocityScale: 0 @@ -9702,7 +9702,7 @@ ParticleSystemRenderer: m_SortingOrder: 0 m_RenderMode: 0 m_SortMode: 0 - m_MinParticleSize: 0.003 + m_MinParticleSize: 0.0025 m_MaxParticleSize: 0.5 m_CameraVelocityScale: 0 m_VelocityScale: 0 diff --git a/Assets/Styles/GLQuake/Particles/RogueExplosion.prefab b/Assets/Styles/GLQuake/Particles/RogueExplosion.prefab index dfc22ef..894f2c3 100644 --- a/Assets/Styles/GLQuake/Particles/RogueExplosion.prefab +++ b/Assets/Styles/GLQuake/Particles/RogueExplosion.prefab @@ -4839,7 +4839,7 @@ ParticleSystemRenderer: m_SortingOrder: 0 m_RenderMode: 0 m_SortMode: 0 - m_MinParticleSize: 0.003 + m_MinParticleSize: 0.0025 m_MaxParticleSize: 0.5 m_CameraVelocityScale: 0 m_VelocityScale: 0 diff --git a/Assets/Styles/GLQuake/Particles/Particle.mat b/Assets/Styles/GLQuake/Particles/RoundParticle.mat similarity index 99% rename from Assets/Styles/GLQuake/Particles/Particle.mat rename to Assets/Styles/GLQuake/Particles/RoundParticle.mat index eec84ce..eeb907e 100644 --- a/Assets/Styles/GLQuake/Particles/Particle.mat +++ b/Assets/Styles/GLQuake/Particles/RoundParticle.mat @@ -20,7 +20,7 @@ Material: m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} - m_Name: Particle + m_Name: RoundParticle m_Shader: {fileID: 4800000, guid: 0406db5a14f94604a8c57ccfbc9f3b46, type: 3} m_ShaderKeywords: m_LightmapFlags: 4 diff --git a/Assets/Styles/GLQuake/Particles/Particle.mat.meta b/Assets/Styles/GLQuake/Particles/RoundParticle.mat.meta similarity index 100% rename from Assets/Styles/GLQuake/Particles/Particle.mat.meta rename to Assets/Styles/GLQuake/Particles/RoundParticle.mat.meta diff --git a/Assets/Styles/GLQuake/Particles/SquareParticle.mat b/Assets/Styles/GLQuake/Particles/SquareParticle.mat new file mode 100644 index 0000000..4582f67 --- /dev/null +++ b/Assets/Styles/GLQuake/Particles/SquareParticle.mat @@ -0,0 +1,142 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &-826508141333875548 +MonoBehaviour: + m_ObjectHideFlags: 11 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3} + m_Name: + m_EditorClassIdentifier: + version: 4 +--- !u!21 &2100000 +Material: + serializedVersion: 6 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: SquareParticle + m_Shader: {fileID: 4800000, guid: 0406db5a14f94604a8c57ccfbc9f3b46, type: 3} + m_ShaderKeywords: + m_LightmapFlags: 4 + m_EnableInstancingVariants: 0 + m_DoubleSidedGI: 0 + m_CustomRenderQueue: 2001 + stringTagMap: + RenderType: Opaque + disabledShaderPasses: [] + m_SavedProperties: + serializedVersion: 3 + m_TexEnvs: + - _BaseMap: + m_Texture: {fileID: 2800000, guid: 36f6501e4b60c3d4bab2eb2659039dc4, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _BumpMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailAlbedoMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailMask: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailNormalMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _EmissionMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MainTex: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MetallicGlossMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _OcclusionMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _ParallaxMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _SpecGlossMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - unity_Lightmaps: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - unity_LightmapsInd: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - unity_ShadowMasks: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + m_Floats: + - _AlphaClip: 0 + - _Blend: 0 + - _BlendOp: 0 + - _BumpScale: 1 + - _CameraFadingEnabled: 0 + - _CameraFarFadeDistance: 2 + - _CameraNearFadeDistance: 1 + - _ClearCoatMask: 0 + - _ClearCoatSmoothness: 0 + - _ColorMode: 0 + - _Cull: 2 + - _Cutoff: 0.5 + - _DetailAlbedoMapScale: 1 + - _DetailNormalMapScale: 1 + - _DistortionBlend: 0.5 + - _DistortionEnabled: 0 + - _DistortionStrength: 1 + - _DistortionStrengthScaled: 0.1 + - _DstBlend: 0 + - _EnvironmentReflections: 1 + - _FlipbookBlending: 0 + - _FlipbookMode: 0 + - _GlossMapScale: 0 + - _Glossiness: 0 + - _GlossyReflections: 0 + - _Metallic: 0 + - _Mode: 0 + - _OcclusionStrength: 1 + - _Parallax: 0.005 + - _QueueOffset: 1 + - _ReceiveShadows: 1 + - _Smoothness: 0.5 + - _SmoothnessTextureChannel: 0 + - _SoftParticlesEnabled: 0 + - _SoftParticlesFarFadeDistance: 1 + - _SoftParticlesNearFadeDistance: 0 + - _SpecularHighlights: 1 + - _SrcBlend: 1 + - _Surface: 0 + - _WorkflowMode: 1 + - _ZWrite: 1 + m_Colors: + - _BaseColor: {r: 1, g: 1, b: 1, a: 1} + - _BaseColorAddSubDiff: {r: 1, g: 0, b: 0, a: 0} + - _CameraFadeParams: {r: 0, g: Infinity, b: 0, a: 0} + - _Color: {r: 1, g: 1, b: 1, a: 1} + - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} + - _SoftParticleFadeParams: {r: 0, g: 0, b: 0, a: 0} + - _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1} + m_BuildTextureStacks: [] diff --git a/Assets/Styles/GLQuake/Particles/SquareParticle.mat.meta b/Assets/Styles/GLQuake/Particles/SquareParticle.mat.meta new file mode 100644 index 0000000..7ebdead --- /dev/null +++ b/Assets/Styles/GLQuake/Particles/SquareParticle.mat.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 63b15323c45f06d4995fa1512a83cbcd +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 2100000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Styles/GLQuake/Particles/TeleportSplash.prefab b/Assets/Styles/GLQuake/Particles/TeleportSplash.prefab index 27d62a1..db2ed28 100644 --- a/Assets/Styles/GLQuake/Particles/TeleportSplash.prefab +++ b/Assets/Styles/GLQuake/Particles/TeleportSplash.prefab @@ -4839,7 +4839,7 @@ ParticleSystemRenderer: m_SortingOrder: 0 m_RenderMode: 0 m_SortMode: 0 - m_MinParticleSize: 0.003 + m_MinParticleSize: 0.0025 m_MaxParticleSize: 0.5 m_CameraVelocityScale: 0 m_VelocityScale: 0 diff --git a/Assets/Styles/GLQuake/Software.asset b/Assets/Styles/GLQuake/Software.asset index c78a3db..577d2f5 100644 --- a/Assets/Styles/GLQuake/Software.asset +++ b/Assets/Styles/GLQuake/Software.asset @@ -23,4 +23,17 @@ MonoBehaviour: lavaAlpha: 1 teleAlpha: 1 particles: - explosion: {fileID: 0} + particleMaterial: {fileID: 2100000, guid: 63b15323c45f06d4995fa1512a83cbcd, type: 2} + particleSize: 1.08 + particleEffect: {fileID: 9150008102338277659, guid: d911d6d226122ae4e97a2fc6f268503d, + type: 3} + explosion: {fileID: 9150008102338277659, guid: 94e2cf23692eef24d9a5145b0f705c55, + type: 3} + rogueExplosion: {fileID: 9150008102338277659, guid: 0a1fede38a8884d488bcf7625cad527e, + type: 3} + blobExplosion: {fileID: 9150008102338277659, guid: 3bc17ebf070910f4592c9491152e94b4, + type: 3} + teleportSplash: {fileID: 9150008102338277659, guid: 79bef89ba1457cb42a9fbeaf4acff66f, + type: 3} + lavaSplash: {fileID: 9150008102338277659, guid: 4db0c926dce46fe4c90920ecd8c5df2e, + type: 3}