Пример #1
0
    public void RequestImage(DCustomEquipment equipment, RequestImageCallback callback, CallbackToken callbackToken, Color backgroundColor, Color penguinColor)
    {
        string           imageHash        = calcHash(equipment, backgroundColor, penguinColor);
        ItemRenderParams itemRenderParams = new ItemRenderParams();

        itemRenderParams.CallbackToken   = callbackToken;
        itemRenderParams.equipment       = equipment;
        itemRenderParams.BackgroundColor = backgroundColor;
        itemRenderParams.bodyColor       = penguinColor;
        itemRenderParams.ImageHash       = imageHash;
        ItemRenderParams renderParams = itemRenderParams;

        RequestImage(renderParams, callback);
    }
Пример #2
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();
        }
    }