Exemplo n.º 1
0
        private IEnumerator renderToTexture(ItemRenderParams param)
        {
            param.OutputTexture = null;
            DCustomEquipment equipment = param.equipment;
            int equipmentTemplateId    = equipment.DefinitionId;
            Dictionary <int, TemplateDefinition> templates = Service.Get <GameData>().Get <Dictionary <int, TemplateDefinition> >();

            if (!templates.ContainsKey(equipmentTemplateId))
            {
                Log.LogErrorFormatted(this, "Unable to locate template {0} in template definitions with id {1}.", equipment.Name, equipmentTemplateId);
                yield break;
            }
            TemplateDefinition templateDefinition = templates[equipmentTemplateId];
            AssetRequest <TemplateRenderData> templateRequest;

            try
            {
                templateRequest = Content.LoadAsync(templateDefinition.RenderDataKey);
            }
            catch (Exception)
            {
                Log.LogErrorFormatted(this, "Could not load render data for template definition {0} at {1}.", templateDefinition.Name, templateDefinition.RenderDataKey.Key);
                yield break;
            }
            if (templateRequest != null)
            {
                yield return(templateRequest);

                TemplateRenderData templateRenderData = templateRequest.Asset;
                penguin.transform.rotation = templateRenderData.ItemRotation;
                ModelRendererConfig config = new ModelRendererConfig(penguin.transform, templateRenderData.ItemPosition, new Vector2(256f, 256f))
                {
                    FieldOfView               = templateRenderData.CameraFOV,
                    FrameObjectInCamera       = false,
                    UseOcclusionCulling       = false,
                    AutoDestroyObjectToRender = false
                };
                if (param.BackgroundColor != Color.clear)
                {
                    config.CameraBackgroundColor = param.BackgroundColor;
                    config.UseSolidBackground    = true;
                }
                ModelRenderer modelRenderer = new ModelRenderer(config);
                modelRenderer.RotateCamera(templateRenderData.CameraRotation.eulerAngles);
                yield return(new WaitForEndOfFrame());

                param.OutputTexture = modelRenderer.Image;
                modelRenderer.Destroy();
            }
        }
        private IEnumerator renderToTexture(RenderParams param, GameObject decorationGameObject, StructureRenderData decorationRenderData)
        {
            ModelRendererConfig config = new ModelRendererConfig(decorationGameObject.transform, decorationRenderData.ItemPosition, new Vector2(256f, 256f))
            {
                FieldOfView               = decorationRenderData.CameraFOV,
                FrameObjectInCamera       = false,
                UseOcclusionCulling       = false,
                AutoDestroyObjectToRender = true
            };

            if (param.BackgroundColor != Color.clear)
            {
                config.CameraBackgroundColor = param.BackgroundColor;
                config.UseSolidBackground    = true;
            }
            ModelRenderer modelRenderer = new ModelRenderer(config);

            modelRenderer.RotateCamera(decorationRenderData.CameraRotation.eulerAngles);
            yield return(new WaitForEndOfFrame());

            param.OutputTexture = modelRenderer.Image;
            modelRenderer.Destroy();
        }