示例#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));
        }
示例#2
0
        private static void OnDecalMaterialLoadSus(DecalVolumeParam arg1, UnityObject arg2)
        {
            _logger.DebugFormat("OnDecalMaterialLoadSus");
            if (arg1 == null || arg2 == null || arg2.AsObject == null)
            {
                _logger.DebugFormat("OnDecalMaterialLoad failed !");
                return;
            }
            Material m      = arg2.AsObject as Material;
            Material newMat = GameObject.Instantiate <Material>(m);

            arg1.meshRen.sharedMaterial             = newMat;
            arg1.meshRen.sharedMaterial.mainTexture = arg1.texture;
            arg1.meshRen.enabled = true;
        }