I need to change the items placed in UI on basis of items clicked on.
User have to click on Name of the game then it will unable the existing item and enable the chapters item to show chapters.
Note: I don't need to change scenes, I know how to change scene with buttons.
I have attached the screenshot of the main menu.
Just create a reference of the gameObjects you want to Activate/Deactivate.
Create a button and use GameObject.SetActive to activate/deactivated the objects you want when the user press it.
You can make the button invisible so the user thinks he's clicking the title but actually he clicks a button.
I Hope this helps. :D
I suggest creating a button for every menu interaction in general.
To handle your buttons OnClickEvents you need to create an empty gameObject on your scene and attach to it a script that your buttoms will use to do whatever you want when you click them.
For example:
//You can name your method however you like.
public void ButtomClicked(){
//Hide the UI on the screen expect the Back button.
//Show chapters to the player
}
Create a button and from the inspector select the Empty Gameobject this script is attached to and then select the ButtomClicked method. When you press the buttom the code in the method will run.
To avoid activating/deactivating all this buttons one by one, you can attach them to a panel(UI element) and activate/deactivate the panel istead. So, lets say you have 3 panels.
The Main menu panel, the Chapters panel and the Options panel.
When the player wants to see the chapters, you diactivate the main menu panel and activate the chapters panel. To make this feel really polished you can add transition animations later on.
This is how i handle my UI without never changing scenes. It gives a really smooth and polished feel to the user.
If you have more quastions about UI, plz watch this turtorial, it helped me a lot to understand the basics.
Related
Normally a menu is opened by click right mouse button(this part is handled easily),yet sometimes I need to open the menu automatically and wait for the user to choose an item. My approach like this:
//let menu be a ContextMenuStrip
//newlyCreatedObject be a object set by menu's click event handler
public Object createNewObject()
{
menu.show(); //this line should block until menu close,but it didn't
return newlyCreatedObject; //ERROR:immediately return before event handler run
}
Ideally the menu.show() part should act like a MFC Dialog's DoModal() that handle all the menu's interaction and return when menu is closed. After that i can get the newlyCreatedObject and do whatever i want with it.
So my question is how can i wait the menu to finish,before return newlyCreatedObject?
PS:I am trying to write a UE4 blueprint like application. In UE4 Blueprint you could either click right mouse button to show up a menu and choose what to add or drag a link out of a pin and release button to show up a menu and link the newly added function automatically(this part is what I want to achieve). I guess it would be possible to break up the create part and link part, but this must lead to a lot of state condition.
have such code
bool b = EditorUtility.DisplayDialog("Test",
"Reset or continue?", "Reset", "Continue");
if (b)
{
ResetGame();
}
but it works only in Editor and not in Game. How to replace the EditorUtility.DisplayDialog with something that works for game?
Any Unity class that includes the word "Editor" or came from the UnityEditor namespace means that the class is designed to used in the Editor only and will only work in the Editor. So EditorUtility is for Unity Editor only.
You need to implement your own Modal Window and to be able to this, you must understand basic Unity UI such as creating buttons, panels, texts. So learn the Unity basic UI first. All you need to do is to put the UI Objects in a panel then acivate/deactivate them when needed.
For example, this is your dialogue panle:
public GameObject dialoguePanel;
to show a dialogue of the UI Panel
dialoguePanel.SetActive(true);
To hide it:
dialoguePanel.SetActive(false);
You can subscribe to the dialogue's button or UI controls events dynamically with onClick.AddListener. See this post for more information on how to subscribe to UI events.
If you still can't implement your Modal Window, then follow the tutorials below as that's exactly what you are looking for.
Unity Tutorial for a generic modal Window:
MAKING A GENERIC MODAL WINDOW Part 1
MAKING A GENERIC MODAL WINDOW Part 2
MAKING A GENERIC MODAL WINDOW Part 3
I have made a custom MessageBox for my application and it launches as a UserControl. I have two buttons inside it and I would like to allow users to press Tab to switch between Buttons. However, since it's a UserControl overlaying the content, Pressing tab more than twice makes the focus go in the background on elements that aren't supposed to be tabbed at.
I can't figure out a good idea how to prevent this, I've thought of making a method that will select all elements and make their IsTabStop values to false and then restore them later, but I think that would be more of a problem then a solution.
Is there a way around this to limit tabbing only to the UserControl?
I would also appreciate advice on working with the message box.. the whole messagebox is an async function that has an infinitive loop until the answer is given. Is there another way to stop the application until one of the message box options was selected?
Crowcoder's reference has lead to correct MSDN page where I found my solution:
dialog = new UCMessageBox("Are you sure you want to exit the application?", MBType.YesNo);
AppMessageBox.Children.Add(dialog);
KeyboardNavigation.SetTabNavigation(dialog, KeyboardNavigationMode.Cycle);
The key was to call .SetTabNavigation function and direct it to my dialog (custom UserControl for the message box) and setting the KeyboardNavigationMode to Cycle.
After closing the UC rest of the application continued normally regarding navigation.
I want to create simple wizard with 3 pages
Page 1 have just next button
Page 2 have next and previous
Page 3 have previous and finish
I have created the pages and add to them needed buttons and in the events I have call to the next pages, for instance in page one in the button click I added the following code
private void Button_Click(object sender, RoutedEventArgs e)
{
p2 = new Page2();
NavigationService.Navigate(p2);
}
In the main window cs I have changed the inheritance to NavigationWindow instead of Window and in the xaml also. Currently its working but I have 3 questions.
The pages which displayed is part of the main window, how can i avoid it, since when I run it the buttons place is not like I put in the designer? It was changed.
The button currently in the Grid, should I put them in different control (the button place should be like any wizard in the left buttom of the page) ?
How can I avoid the navigation arrows in the page right upper screen?
Thanks!
To answer your questsions in reverse,
3. How can I avoid the navigation arrows in the page upper right screen?
I have an opensource library http://winchrome.codeplex.com/ that re-styles navigation windows in several ways. For example these are all NavigationWindow s
In short you just style the NavigationWindow to only show the parts you want.
2.The button currently in the Grid, should I put them in different control (the button place should be like any wizard in the left buttom of the page) ?
If you look at the styles from WinChrome then you will see that it is just a case of rebuiliding the UI as you want and providing a ContentPresenter to hold your pages. e.g. the VS2012 style applies lots of styles on the window but avoids adding back and forward buttons., whereas the Win7 style rebuilds the back and forwards in a Win7 Style.
If you do this however you will need a means of passing your enabled or visible states to the buttons outside the pages. Take a look at http://www.codeproject.com/Articles/8197/Designer-centric-Wizard-control for how to do this in Winforms. In WPF you could either derive from your Pages to create WizardPage classes with CanBack, CanNext or IsFinish properties, or alteratively define attached properties to do the same (There are examples of how to do this in VS2012.cs where we define the glow color)
And finally
1. The pages which displayed is part of the main window, how can i avoid it, since when I run it the buttons place is not like I put in the designer? It was changed.
I'd need to see some code to comment on how you've done it, but if you look at any of the demo programs in WinChrome then you can see how I've done it without problems.
Good luck!
On the Windows Form application I have a Lamp image (a black and white one, and a bright one. For OFF and ON respectively).
Using the Button how can I achieve the scenario such that same button will turn the property of the image (pictureBox in my case) to show the Lamp as ON and pressing the same button again will turn the Lamp off.
I am accessing the 'Visible' property of picture box.
Put two images on top of each other and get the button to switch which one of them is enabled.
In the form designer you make one of them visible and the other non-visible. The code in the button handler can then be something like:
lightImage.Visible = !lightImage.Visible;
darkImage.Visible = != lightImage.Visible;
That will swap which one is visible and eliminate the need to keep state elsewhere.
A bit late to the party, but you can use a checkbox and set the appearance to button.
I think that would do what is expected by the original post.
I'm not sure about the way to put 2 images over each other, but if you want to reach the same effect:
place the 2 image files in your project resources
in the click event of the button, toggle the button image depending on a setting:
this would be in the click event:
Properties.Settings.Default.IsOptimizedForTracer !=Properties.Settings.Default.IsOptimizedForTracer;
if (!Properties.Settings.Default.IsOptimizedForTracer)
{
btnOptimizeForTracer.Image = Properties.Resources.TracerOFF;
return;
}
btnOptimizeForTracer.Image = Properties.Resources.TracerON;