How do you set Toggle UI interactable size manually in Unity? - unity3d

I'm trying to make a toggle UI like the one on this youtube(https://www.youtube.com/watch?v=mQTnB71NUAw&ab_channel=MaxShakurov").
This example uses a button UI to make this happen. But I'm trying to make it with a toggle UI that Unity provides.
But here is the problem that I faced.
Issue: There is a big difference in the interactable box size of what I expected.
Below is an example to make it easy to reproduce.
My Unity version: 2018.4.23f1
I created a new project.
I added a default toggle UI
---> There is a big difference between my expectation of interactable box size and the actual one.
My initial expectation was to make toggle UI to be able to interact with the size of its' target graphic.
How can you make a toggle UI to be able to interact on only the size of a target graphic?

The interaction space is expanded to any child object having a graphic element (Image, Text, etc) with Raycast Target enabled.
All you have to do is
Go to the Label object in the Hierarchy
Go to the Text component in the Inspector
Disable the Raycast Target checkbox
As a result you should now have only the checkbox itself interactive

Related

Depending of drag and drop operation from anchor position in unreal engine 4

I have the problem with Drag-and-Drop Operation for UI elements:
i have created a test object to drag: DragTestObject_BP and have override the functions:
OnMouseBottonDown Function and OnDragDetected.
Recepient will be HUD_BP with overridden is OnDrop function.
The problem is, that first drag-and-drop operation is functioning without problem only, if the anchor for drag object is set for upper left corner. Otherwise the drag object has some wired offset.
Position on start:
Drag object jumped by first mouse click on it
Might be a bit late, but youll want to put the widget you're clicking to drag ("DragTestObject_BP") inside of another widget.
It's probably a good idea to remove any canvas panel in "DragTestObject_BP" as well.
This will make the origin of "DragTestObject_BP" where it is located visually, instead of using the location of the canvas panel which is the issue you seem to have run into.

Visibility parameter of WPF control not visible with UI Automation?

I started writing test for a WPF application with FlaUI (UI Automation framework). Now I want to get the Visibility value of a couple of buttons.
These buttons are located on the same position in the WPF window. The first is a start button which will start a measurement. When clicked, the measurement button is replaced with a stop button. The visibility of these buttons are set in the code behind of the xaml and needs to be checked/verified.
With FlaUI I only get IsEnabled boolean and OffScreen boolean. But when using the Offscreen parameter, this boolean is not set or is set to the correct value for a couple of seconds but is changed again while the measurement is still running.
I also tried other ways, like looking for a clickable point of the not visible button. But those are not working.
Can this be done without extending the button class with an AutomationPeer and exposing a ValuePattern? I googled a bit but cannot find an (decent) answer. Hopefully someone can help.
I think an important part of your question is the word "replaced". Commonly a program draws one set of controls (in your case the start button) and later draws another set. Possible on top to hide the first, or possible by deleting them.
Commonly controls, including buttons, are drawn within other containing controls and so it may be that the button controls are not there at all, hence the visibility checks should be done on the parent or ancestor controls.
This Q&A seems related to the problem you are having and it may provide some more insight.

How do you sort UI elements in Canvas?

I don't get how you sort UI elements Z-index in Unity inside a Canvas, is it by hierarchy order ?
I'm trying to do a settings screen like in this video: https://www.youtube.com/watch?v=-qNo1jloR_k
It's quite simple, you click on the button and it set the whole panel as first sibling in the hierarchy.
But this is what I get:
https://gyazo.com/cec14f21df2ded191875e6a8cfd9f124
Also, my gameplay panel had a red background, my graphics panel a green one, and my sound panel a yellow one.
I could avoid this problem by changing alpha on panels, but would like to make it work with z sorting... that I can't seem to understand on Unity.
Using unity 2017.1.2 and .NET 4.6 .
The child that is lower in the hierarchy is rendered on top of other ones.
Let's say there are 2 panels. panel1(red) and panel2(green).If the hierarchy is like this:
-panel1
-panel2
Then panel2 will be rendered on top of panel1. So, you'll see green panel.
Hope this answers your question.
Another suggestion, it is better to deactivate the unused panels and activate only the used panels. Because, if the unused panel is active, when it's not shown, it'll still take the processing power which is a waste. For example, if you have animation in the main menu, but currently you are showing the settings panel, your approach will keep the animations running in the main menu.

Stacked UI elements: how to have only the visible ones to respond to click

I have 3 dropdown that are stacked on top of each other; I use canvas group to make the non relevant ones invisible; although the click is intercepted only on the topmost control.
How do you work around this? Should I keep track of the position in the hierarchy and swap it when I need to have a specific dropdown control so I can use it? Feels like a lot of work...hopefully is there an easier way?
The image component of UI elements has a Raycast Target property that you can set to false. This will make them unclickable.

Gui text does not display

I am using unity 4.6 to develop a small game.
There is no gui text object in the menu. Therefore I created an empty object and added gui text as a component. But it does not display the text I type. Need help on this. Thank you
I think that 4.6 is when they introduced the new UI system so you can use that.It is actually pretty easy...from the drop down menu that you created the game object go to UI. There you can select from a number UI options one of witch is Text or UI Text if my memory serves me well. When you click it it will create a canvas object and UI Text object that is a child of the Canvas.From here just select the Text object and in the inspector you have a textbox which should serve your need :) Also the Canvas is your screen in the sense that if you drag your text to the top left corner of the Canvas(in the scene view) your text will be in the top left corner of the screen when you start your game(at least in the default settings). Hope that helps!
P.S. Also here is a link to the new UI article that the Unity guys have on their site: https://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/the-new-ui
That happens sometimes. Delete the current gameobject and the guitext in the scene. Do what you did backwards.
Create a new guitext then create a new empty gameobject. Change the transform of the empty gameobject to 0,0,0 then drag the new gui text into the empty gameobject.
That should solve your problem.
The default text you should see if that went well is "New Text".
If you are editing the new text in the text area and it stopped showing, you will need to increase the width and sometimes the Height of the guiText. Don't use the scale tool as that will work but the graphics you get will be low quality text rendering on the screen.