#Runtime Editor Docs
##Overview
Runtime Editor is the set of scripts and prefabs which help you to create scene editor, game level editor or build your own modeling application.
It supports [drag & drop](infrastructure.md#drag-and-drop), [undo & redo](infrastructure.md#runtime-undo) and [selection](infrastructure.md#runtime-selection) api.
To implement user interface and core functions runtime editor use [transform-handles](transform-handles.md), [gizmos](gizmos.md), [save load subsystem](save-load.md) and three controls: [menu](menu-control.md), [virtualizing tree view](vtv.md) and [dock panels](dock-panels.md).
Out of the box it has six Views:
* __Scene View__ to manipulate objects in the scene.
* __Hierarchy View__ for displaying and manipulating the object tree.
* __Project View__ to manage assets and scenes.
* [Inspector View](#inspector-view) to display and edit object properties.
* __Console View__ to display information, warnings and errors.
* __Game View__ for the game.
* [Add More...](#how-to-add-custom-window-to-window-manager)
The Runtime Editor has many ready-to-use property and component editors and it is relatively easy [to create new ones](#how-to-select-component-properties). __"Add Component"__ drop-down button allows you to add components at runtime.
There are also several important dialogs included:
* __Save Scene Dialog__.
* __Object Picker__.
* __Color Picker__.
* __Asset Bundles and Libraries Importer__.
* __Manage Projects Dialog__.

#Getting Started
To get started with Runtime Editor do following:
1. Create new scene and __save__ it.
2. Click Tools->Runtime Editor->Create

3. Add Battlehub/RTEditor/Scripts/__Game View Camera__ component to __Main Camera__

4. Create several Game Objects and add [__Expose To Editor__](#infrastructure.md#expose-to-editor) component.

5. You will see the imported assets in the project window.

!!! note
Demo scene can be found in __Assets/Battlehub/RTEditor/Demo__
##Main & Context Menu
Runtime Editor use [Menu control](menu-control.md) to implement main and context-menu. To extend main menu create static class with __[MenuDefinition]__ attribute and add static methods with __[MenuCommand]__ attribute.
```C#
using Battlehub.RTCommon;
using Battlehub.RTEditor;
using Battlehub.UIControls.MenuControl;
using UnityEngine;
[MenuDefinition]
public static class MyMenu
{
/// add new command to exising menu
[MenuCommand("MenuWindow/Create My Window")]
public static void CreateMyWindow()
{
Debug.Log("Create My Window");
}
/// add new command to new menu
[MenuCommand("My Menu/My Submenu/My Command")]
public static void CreateMyMenu()
{
Debug.Log("Create My Menu");
}
/// disable menu item
[MenuCommand("My Menu/My Submenu/My Command", validate: true)]
public static bool ValidateMyCommand()
{
Debug.Log("Disable My Command");
return false;
}
/// replace existing menu item
[MenuCommand("MenuFile/Close")]
public static void Close()
{
Debug.Log("Intercepted");
IRuntimeEditor rte = IOC.Resolve();
rte.Close();
}
/// Hide existing menu item
[MenuCommand("MenuHelp/About RTE", hide: true)]
public static void HideAbout() { }
}
```

To open context menu with custom commands do following:
```C#
using Battlehub.RTCommon;
using Battlehub.RTEditor;
using Battlehub.UIControls.MenuControl;
using UnityEngine;
public static class MyContextMenu
{
public static void OpenContextMenu()
{
IContextMenu contextMenu = IOC.Resolve();
MenuItemInfo cmd1 = new MenuItemInfo { Path = "My Command 1" };
cmd1.Action = new MenuItemEvent();
cmd1.Action.AddListener((args) =>
{
Debug.Log("Run My Command1");
IRuntimeEditor editor = IOC.Resolve();
Debug.Log(editor.Selection.activeGameObject);
});
MenuItemInfo cmd2 = new MenuItemInfo { Path = "My Command 2" };
cmd2.Validate = new MenuItemValidationEvent();
cmd2.Action = new MenuItemEvent();
cmd2.Validate.AddListener((args) =>
{
args.IsValid = false;
});
cmd2.Action.AddListener((args) =>
{
Debug.Log("Run My Command2");
});
contextMenu.Open(new[]
{
cmd1, cmd2
});
}
}
```

Built-in context menu populated and opened from Assets/Battlehub/RTEditor/Scripts/__ProjectFolderView.cs__ and __ProjectTreeView.cs__

##RTEDeps
The main purpose of the Assets/Battlehub/RTEditor/__RTEDeps.cs__ class is to register various services into [IOC](infrastructure.md#ioc):
* [IResourcePreviewUtility](#resource-preview-utility) - create preview for Game Object or asset.
* [IWindowManager](#window-manager) - manage build-in and custom windows.
* [IContextMenu](#main-context-menu) - create and show context menu.
* __IRuntimeConsole__ - log messages cache.
* [IRuntimeEditor](#iruntimeeditor) - the main interface of the RuntimeEditor.
##IRuntimeEditor
IRuntimeEditor inherits the [IRTE interface](infrastructure.md#irte-interface) and adds several important methods and events.
```C#
using Battlehub.RTCommon;
using Battlehub.RTEditor;
using UnityEngine;
public class GetRuntimeEditor : MonoBehaviour
{
void Start()
{
IRuntimeEditor editor = IOC.Resolve();
}
}
```
Events:
* `event RTEEvent SceneLoading` - fired before loading the scene.
* `event RTEEvent SceneLoaded` - fired after loading the scene.
* `event RTEEvent SceneSaving` - fired before saving the scene.
* `event RTEEvent SceneSaved` - fired before saving the scene.
Methods:
* `void NewScene(bool confirm = true)` - create a new scene (show the confirmation dialog by default).
* `void SaveScene()` - save the current scene. If the scene is new, the save scene dialog will appear.
* `void CreateWindow(string window)` - call corresponding method of [window manager](#window-manager).
* `void CreateOrActivateWindow(string window)` - this method creates a window only if it does not exist.
* `ProjectAsyncOperation CreatePrefab(ProjectItem folder, ExposeToEditor obj, bool? includeDeps = null)` - create prefab with preview.
* `ProjectAsyncOperation SaveAsset(UnityObject obj)` - save asset.
* `ProjectAsyncOperation DeleteAssets(ProjectItem[] projectItems)` - delete assets.
* `ProjectAsyncOperation UpdatePreview(UnityObject obj)` - update asset preview.
Example:
```C#
using Battlehub.RTCommon;
using Battlehub.RTEditor;
using Battlehub.RTSL.Interface;
using System.Collections;
using UnityEngine;
public class IRuntimeEditorMethodsUsageExample : MonoBehaviour
{
IEnumerator Start()
{
//Get runtime editor
IRuntimeEditor editor = IOC.Resolve();
//Use IProject interface if editor is not opened or does not exist.
//See save-load/#project for details
Debug.Assert(editor.IsOpened);
//Create Prefabs folder
IProject project = IOC.Resolve();
yield return project.CreateFolder("Prefabs");
ProjectItem folder = project.GetFolder("Prefabs");
//Create new object and hide it from hierarchy
GameObject go = GameObject.CreatePrimitive(PrimitiveType.Sphere);
go.hideFlags = HideFlags.HideAndDontSave;
go.SetActive(false);
//Create prefab with preview and destroy source object
yield return editor.CreatePrefab(folder, go.AddComponent(), true);
Destroy(go);
//Load prefab
ProjectAsyncOperation