Closed BattlehubCode closed 2 years ago
Hello, you can use the GetWindow, CreateWindow, DestroyWindow methods from IWindowManager to find, create and destroy windows.
IWindowManager wm = IOC.Resolve<IWindowManager>();
Here's an example of how you can dynamically change the layout:
using Battlehub.RTCommon;
using Battlehub.RTEditor;
using Battlehub.UIControls.DockPanels;
using UnityEngine;
public class ModifyLayoutExample : MonoBehaviour
{
protected LayoutInfo GetLayoutInfo(IWindowManager wm)
{
LayoutInfo scene = wm.CreateLayoutInfo(BuiltInWindowNames.Scene);
scene.IsHeaderVisible = false;
LayoutInfo console = wm.CreateLayoutInfo(BuiltInWindowNames.Console);
return LayoutInfo.Horizontal(scene, console, 0.75f);
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
IWindowManager wm = IOC.Resolve<IWindowManager>();
wm.SetLayout(GetLayoutInfo);
}
}
}
Here is how to modify menu:
using Battlehub.UIControls.MenuControl;
using System.Linq;
using UnityEngine;
public class ModifyMenuExample : MonoBehaviour
{
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
Menu menu = FindObjectsOfType<MainMenuButton>()
.Where(menu => menu.name == "MenuFile")
.Select(menu => menu.Menu)
.First();
var menuItems = menu.Items.ToList();
MenuItemInfo menuItem = new MenuItemInfo
{
Path = "Run My Command",
Command = "MyCommand",
Action = new MenuItemEvent()
};
menuItem.Action.AddListener(MyCommand);
menuItems.Insert(0, menuItem);
menu.SetMenuItems(menuItems.ToArray());
}
}
private void MyCommand(string cmd)
{
Debug.Log(cmd);
}
}
I want to dynamically change the RTEditor layout, hide / show any window, modify the window parameters, modify menu etc. You have given examples only to override at the start. How to do that in runtime?