Editing a printer's draw order or z-index?

All about user interface, be it customizing built-in UIs or adding new ones.
Post Reply
himatako
Posts: 5
Joined: 16 Jan 2021 17:15

Editing a printer's draw order or z-index?

Post by himatako »

I looked through the documentation and I don't find a way to modify the z position or the draw order of a printer. Seems like making a custom @printer command based on ModifyPrinter is the only way to go?

I've tried to do it but I don't think ITextPrinter exposing a way to modify this either, so before I dive myself into further coding, I'd like to know if there's an easier way of doing this.

Elringus
admin
Posts: 538
Joined: 11 May 2020 18:03

Re: Editing a printer's draw order or z-index?

Post by Elringus »

You can change z-pos with z param of printer command, eg @printer PrinterId pos:,,10. Though, not sure if that'll will help with the drawing order. To change the drawing order, get the printer UI from UI manager and use IManagedUI.SortingOrder property.

himatako
Posts: 5
Joined: 16 Jan 2021 17:15

Re: Editing a printer's draw order or z-index?

Post by himatako »

I tried the position command but it didn't seem to affect the printer's z position at all (unless I was looking at the wrong object.) If I modify it directly from the editor, the z position does affect the drawing order though. In any case, IManagedUI.SortingOrder sounds better and less hacky. I'll try to see if I can add a drawOrder parameter to the @printer command myself. Thanks!

Elringus
admin
Posts: 538
Joined: 11 May 2020 18:03

Re: Editing a printer's draw order or z-index?

Post by Elringus »

My bad, there was a bug that prevented changing z-pos of printers. I've fixed it now, updated package is in #download. Content game object is the one which position will be changed inside the printer prefab hierarchy.

himatako
Posts: 5
Joined: 16 Jan 2021 17:15

Re: Editing a printer's draw order or z-index?

Post by himatako »

Elringus wrote: 19 Jan 2021 12:26

My bad, there was a bug that prevented changing z-pos of printers. I've fixed it now, updated package is in #download. Content game object is the one which position will be changed inside the printer prefab hierarchy.

Thank you! I'll update and use that.

I've also made changing the sorting order to work with the following code. I'm going to post it here just in case people might find it useful as a starting point to give more parameters to @printer command.

Code: Select all

using Naninovel;
using Naninovel.UI;
using Naninovel.Commands;
using UniRx.Async;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[CommandAlias("printer")]
public class MyCustomPrinterCommand : ModifyTextPrinter
{
    /// <summary>
    /// Add a parameter "drawOrder" which will determine the sorting order of the printer
    /// </summary>
    [ParameterDefaultValue("0")]
    public IntegerParameter DrawOrder = 1;

    public override async UniTask ExecuteAsync(CancellationToken cancellationToken = default)
    {
        var uimanager = Engine.GetService<IUIManager>();
        var printerUI = uimanager.GetUI(AssignedId);
        RevealableTextPrinterPanel textPrinter = printerUI as RevealableTextPrinterPanel;
        if(textPrinter != null)
        {
            textPrinter.SortingOrder = DrawOrder;
        }        
        //Debug.Log(printerUI);
        Debug.Log(DrawOrder);
        await base.ExecuteAsync(cancellationToken);
    }
}

It looks pretty hacky with the typecast, but I don't think I can access SortingOrder property from IManagedUI, so I had to resort to that.

Post Reply