Esempio n. 1
0
        public static void CreateDecalVolume(ClientEffectEntity entity,
                                             Contexts contexts,
                                             Vector3 position,
                                             Vector3 forward,
                                             Vector3 head,
                                             int sprayPrintSpriteId)
        {
            CreateDebugGameObject();
            _decal = GameObject.CreatePrimitive(PrimitiveType.Cube);
            MeshRenderer meshRen = _decal.GetComponent <MeshRenderer>();

            meshRen.enabled = false;
            _decal.GetComponent <BoxCollider>().enabled = false;
            _decal.transform.localScale = Vector3.one;

            DecalVolume dv = _decal.AddComponent <DecalVolume>();

            dv.Volume.m_origin = Vector3.zero;
            dv.Volume.m_size   = new Vector3(1.2f, 1.2f, 1.2f);

            _decal.transform.position = position;
            _decal.transform.Rotate(head, Space.Self);
            var bundleName = AssetBundleConstant.Icon_Spray;
            var assetName  = string.Format("Spray_{0}", sprayPrintSpriteId);

            _logger.DebugFormat(assetName);
            var assetManager = contexts.session.commonSession.AssetManager;

            AssetInfo assetInfo = new AssetInfo(bundleName, assetName);

            assetManager.LoadAssetAsync(assetName, assetInfo, (source, unityObj) =>
            {
                DecalVolumeParam param = new DecalVolumeParam();
                param.meshRen          = meshRen;
                if (unityObj != null && unityObj.AsObject != null)
                {
                    if (unityObj.AsObject is Texture2D)
                    {
                        param.texture = unityObj.AsObject as Texture2D;
                    }
                    else if (unityObj.AsObject is Sprite)
                    {
                        Sprite sprite = unityObj.AsObject as Sprite;
                        param.texture = sprite.texture;
                    }
                    else
                    {
                        _logger.DebugFormat("unityObj.AsObject is null !");
                        return;
                    }
                    assetManager.LoadAssetAsync(param, new AssetInfo("shaders", "MaterialForDecal"), OnDecalMaterialLoadSus);
                    dv.Create(forward, 0);
                }
                else
                {
                    _logger.DebugFormat("bundleName : " + bundleName + " assetName : " + assetName);
                }
            });
            entity.assets.LoadedAssets.Add(assetInfo, new UnityObject(_decal, assetInfo));
        }
Esempio n. 2
0
        public static Mesh Create(DecalVolume decal, float surfaceMaxAngle, float surfaceDistance, float smoothAngle, Vector3 normal, float ratio)
        {
            var pols      = new List <Polygon>();
            var transform = decal.transform;
            var bounds    = decal.GetBounds();
            List <GameObject> affectedList = decal.GetGameObjectsInBounds(meshRenderers, meshColliders, ignoreLayer, careLayer);

            Terrain[] terrains = Terrain.activeTerrains;

            for (int i = 0, count = terrains.Length; i < count; i++)
            {
                if ((1 << terrains[i].gameObject.layer & ignoreLayer.value) > 0)
                {
                    continue;
                }

                Vector3 terrainPos    = terrains[i].GetPosition();
                Vector3 terrainSize   = terrains[i].terrainData.size;
                var     terrainBounds = new Bounds(terrainPos + terrainSize * 0.5f, terrainSize);

                if (bounds.Intersects(terrainBounds) == false)
                {
                    continue;
                }
                pols.AddRange(CreateFromTerrain(terrains[i], terrainPos, terrainSize, bounds, decal, surfaceMaxAngle));
            }

            pols.AddRange(CreateFromObjects(affectedList, decal, surfaceMaxAngle));

            Mesh mesh = CreateMesh(pols, true);

            var verts = mesh.vertices;

            for (int i = 0, count = verts.Length; i < count; i++)
            {
                verts[i] = transform.InverseTransformPoint(verts[i]);
            }
            mesh.vertices = verts;

            mesh.vertices = PushMesh(mesh, surfaceDistance, normal, ratio);
            mesh.uv       = CreateUVs(mesh.vertices, decal.Volume, decal.Sprite);
            mesh.name     = "Decal Mesh";

            mesh.RecalculateBounds();
            mesh.RecalculateNormals();

            return(mesh);
        }