• Hello Guest!

    We have recently updated our Site Policies regarding the use of Non Commercial content within Paid Content posts. Please read the new policy here.

    An offical announcement about this new policy can be read on our Discord.

    ~The VaMHub Moderation Team
  • Hello Guest!

    We posted an announcment regarding upcoming changes to Paid Content submissions.

    Please see this thread for more information.

[ Coding ] Canvas and layers in VAM + text inputs

hazmhox

Moderator
Featured Contributor
Messages
844
Reactions
5,672
Points
123
Hey guys !

@meshedvr (or anyone who found a way to implement canvas properly) I'm trying to come up with two tiny plugins : one that allows you to add subtitles, another that allows you to fade in and out the view... and my code is based on canvas. No matter what I try (layer, sorting order), the canvas renders on top of everything (including the floating UI of VAM). Could you maybe be give me a few hints about how your UI is implemented that would allow me to add properly the gameobjects in the scene and render them behind the UI.

Because at the moment, for the fade for instance... if something goes wrong while the fade is complete, you cannot access the menu and you have to kill the app :p

And another thing, i've tried to find a way to create text input (just like sliders or dropdowns) in the custom UI of a plugin... but it seems there isn't one. Is that something possible or not ? It would be to have a textfield and allow the user to type in some text ( subtitles related of course ! ).

Thank you in advance.

EDIT : Forget the canvas part, I just found out that I made a mistake, the rendering order does not work when you don't specify a target camera. Now the canvas is properly behind the UI ! I Would still love to get your input on textfields tho !
 
Last edited:
If you want your Canvas to accept input in a standard VaM way, you'll need to register it with SuperController, and unregister it when you remove it (OnDestroy, etc.):

Code:
SuperController.singleton.AddCanvas(myCanvas);
SuperController.singleton.RemoveCanvas(myCanvas);

Please note that AddCanvas will set the sortingLayerName so it overrides whatever sorting layer you might have set.

If you wish to preserve the sorting layer you have do the following:
Code:
myCanvas.gameObject.AddComponent<IgnoreCanvas>();

Please note that AddCanvas tells SuperController to control setting that Canvas' camera as needed if it is a world space Canvas. This allows controllers and mice to all be properly processed by the UI system.
 
Text fields in the plugin UI. There is an example of this in the sample scripts I include in VaM called TemplateWithSamples.cs:

Code:
                // JSONStorableString example
                jstring = new JSONStorableString("FooString", "");
                // register tells engine you want value saved in json file during save and also make it available to
                // animation/trigger system
                //RegisterString(jstring);
                dtext = CreateTextField(jstring);
 
Ok ! Really sweet infos for the canvas, thank you meshed.

For the text fields, I indeed know the template ( you may now know that I've done a bit of coding now in VAM :p ), but the CreateTextField function only creates a simple text box with the value inside, not an input field that the user can fill to specify it's own value for instance.

I did find out a way that would be pretty much easier than what I had in mind initially using actions. Setting the value of a JSONStorableString which will be used to display the subtitles.

Thank you again for your help.
 
That's not urgent. I could bypass the issue by creating my own method to write it inside the UI.
But I think I found a workaround that would work even better from a user perspective :)

Could be nice to have that in 2.x tho ! a bit more options for the custom UI could be really awesome.
 
@hazmhox if it helps, here's a CreateTextInput method you can use: https://github.com/acidbubbles/vam-collider-editor/blob/master/src/ColliderEditor.cs#L540

C#:
    public UIDynamicTextField CreateTextInput(JSONStorableString jss, bool rightSide = false)
    {
        var textfield = CreateTextField(jss, rightSide);
        textfield.height = 20f;
        textfield.backgroundColor = Color.white;
        var input = textfield.gameObject.AddComponent<InputField>();
        var rect = input.GetComponent<RectTransform>().sizeDelta = new Vector2(1f, 0.4f);
        input.textComponent = textfield.UItext;
        jss.inputField = input;
        return textfield;
    }
 
Wow ! Thank you @Acid Bubbles , I did not even thought about checking your code ^^

Well I guess this thread is answered. Thank you a lot guys !
 
Back
Top Bottom