Пример #1
0
        private static void Build(MeshBuilder builder, Decal decal, GameObject gameObject)
        {
            MeshFilter   filter   = decal.GetComponent <MeshFilter>() ?? decal.gameObject.AddComponent <MeshFilter>();
            MeshRenderer renderer = decal.GetComponent <MeshRenderer>() ?? decal.gameObject.AddComponent <MeshRenderer>();

            if (filter.sharedMesh != null && !filter.sharedMesh.isReadable)
            {
                return;
            }

            if (decal.material == null)
            {
                Object.DestroyImmediate(filter.sharedMesh);
                filter.sharedMesh       = null;
                renderer.sharedMaterial = null;
                return;
            }

            Build(builder, decal, gameObject.GetComponent <MeshFilter>());
            builder.Push(decal.pushDistance);

            if (filter.sharedMesh == null)
            {
                filter.sharedMesh      = new Mesh();
                filter.sharedMesh.name = "Decal";
            }

            builder.ToMesh(filter.sharedMesh);
            filter.sharedMesh.UploadMeshData(true);

            renderer.sharedMaterial = decal.material;
        }
Пример #2
0
        private static GameObject[] Build(MeshBuilder builder, Decal decal)
        {
            MeshFilter   filter   = decal.GetComponent <MeshFilter>() ?? decal.gameObject.AddComponent <MeshFilter>();
            MeshRenderer renderer = decal.GetComponent <MeshRenderer>() ?? decal.gameObject.AddComponent <MeshRenderer>();


            if (filter.sharedMesh != null && !filter.sharedMesh.isReadable)
            {
                return(null);
            }

            if (decal.material == null || decal.sprite == null)
            {
                Object.DestroyImmediate(filter.sharedMesh);
                filter.sharedMesh       = null;
                renderer.sharedMaterial = null;
                return(null);
            }


            var objects = DecalUtils.GetAffectedObjects(decal);

            foreach (var obj in objects)
            {
                Build(builder, decal, obj);
            }
            builder.Push(decal.pushDistance);


            if (filter.sharedMesh == null)
            {
                filter.sharedMesh      = new Mesh();
                filter.sharedMesh.name = "Decal";
            }

            builder.ToMesh(filter.sharedMesh);
            renderer.sharedMaterial = decal.material;

            return(objects.Select(i => i.gameObject).ToArray());
        }