using System.Collections.Generic; using ch.sycoforge.Decal; using ch.sycoforge.Decal.Projectors.Geometry; using UnityEngine; public class RuntimeDecalCombiner { public static List Combine(IList decals) { Dictionary> dictionary = new Dictionary>(); foreach (EasyDecal decal in decals) { if (decal.Source == SourceMode.Atlas && decal.Projector != null) { if (!dictionary.ContainsKey(decal.Atlas)) { dictionary.Add(decal.Atlas, new List()); } dictionary[decal.Atlas].Add(decal); } } return Combine(dictionary); } private static List Combine(Dictionary> mappings) { List list = new List(); if (mappings.Count > 0) { foreach (DecalTextureAtlas key in mappings.Keys) { IList list2 = mappings[key]; foreach (EasyDecal item in list2) { GameObject gameObject = Combine(list2, key); if (gameObject != null) { list.Add(gameObject); } } } return list; } return list; } private static GameObject Combine(IList decals, DecalTextureAtlas atlas) { if (decals.Count > 0) { DynamicMesh dynamicMesh = new DynamicMesh(DecalBase.DecalRoot, RecreationMode.Always); GameObject gameObject = new GameObject($"Combined Decals Root [{atlas.name}]"); MeshFilter meshFilter = gameObject.AddComponent(); MeshRenderer meshRenderer = gameObject.AddComponent(); foreach (EasyDecal decal in decals) { if (decal.Source == SourceMode.Atlas && decal.Projector != null) { dynamicMesh.Add(decal.Projector.Mesh, decal.LocalToWorldMatrix, gameObject.transform.worldToLocalMatrix); decal.gameObject.SetActive(value: false); } } meshRenderer.material = atlas.Material; meshFilter.sharedMesh = dynamicMesh.ConvertToMesh(null); } return null; } }