Add Button To Level Tab
Add Button To Level TabSince version v1.20 the level editor is completely independent of the UI implementation. You do not need to use any rigid UI extension system. Simply add the needed UI to the scene. To extend the level tab of the built-in example UI duplicate the 'Load' button (search for 'RightMenu_Level_LoadBtn'), rearrange it, update its text and change its 'OnClick()' function to call your script. If you want to use a custom UI, then you can find more information in this article.
SummaryTo add an additional button to the level tab of the editor the name of the button must be added to an array in the inspector of a 'LE_GUILevelEditor' instance in the level editor scene. Once this is done the button will be added and events will be fired on click. An event handler needs to be provided for the new button in order to implement its functionality.
Step 1: Add Button Name In InspectorTo add a button to the level tab of the right menu window select the instance of 'LE_GUILevelEditor' in your level editor scene and add the button name to the 'ADDITIONAL_LEVEL_TAB_BUTTONS' array in the inspector. In this example we add the 'Play' button.
Step 2: Event RegistrationThe code below will add the OnPlay event handler method to the methods called when the 'Play' button is clicked. The string passed in the first parameter has to exactly match the string entered in the inspector. Keep in mind that you also should unregister the event handler when your script gets destroyed otherwise a memory leak could occur.
// Register for the button click event of the additional level tab button called 'Play', whichLE_EventInterface.AddAdditionalLevelTabButtonHandler("Play", OnPlay);
// is called when the button with the passed name is clicked by the user
Step 3: Event HandlingPut the code that you want to execute when the button is clicked in the event handler method. For example the 'Play' button event handler could first check if the level is playable. Maybe some important game logic objects are missing, for example the player start position marker. Then it should set some variable that will indicate your level loader, which level it should load as soon as the game scene is loaded (more information on how to load a level here). Finally, the game scene would be loaded.
private void OnPlay(object p_sender, System.EventArgs p_args)
// You should first check if the level is playable (e.g. the player start position is defined)...
// If not you should display a message to the user
// You should now tell you level loader which level should be loaded once the game scene is loaded...
// For example a static variable like 'MyLevelLoader.LevelToLoad = "LevelXYZ";'
// Now you can simply load you game scene, which will then load the desired level.Application.LoadLevel(1);
// In this example we expect your game scene to have the index 1