internal static void Open() { if (instance == null) { instance = UIKit.CreateUI <MapIconSelector>(UIMain.appCanvasRect, "KKMapIconSelector"); } instance.rectTransform.anchoredPosition3D = eventData.position; CreateContent(); instance.SetActive(true); }
// Reminder since I keep forgetting: The UI must be built while in play mode for the buttons to work public void BuildUI() { if (testUI) { return; } treeItems = new List <TreeView.TreeItem> (); foreach (var item in testTreeItems) { treeItems.Add(new TreeView.TreeItem(item, i => (i as TestTreeItem).Name, i => (i as TestTreeItem).Count != 0, 0)); } Window basePanel = UIKit.CreateUI <Window>(appCanvas.transform as RectTransform, "testUI"); testUI = basePanel.gameObject; basePanel .Title("A test") .Vertical() .ControlChildSize(true, true) .ChildForceExpand(false, false) .PreferredSizeFitter(true, true) .Anchor(AnchorPresets.MiddleCenter) .Pivot(PivotPresets.TopLeft) .PreferredWidth(300) .Add <UIButton>() .Text("Button A") .OnClick(ButtonAction) .FlexibleLayout(true, false) .Finish() .Add <Layout>() .Horizontal() .ControlChildSize(true, true) .ChildForceExpand(false, false) .Anchor(AnchorPresets.HorStretchTop) .FlexibleLayout(true, false) .Add <UIEmpty>() .FlexibleLayout(true, true) .Finish() .Add <UIButton>() .Text("B") .OnClick(ButtonAction) .Finish() .Add <UIEmpty>() .FlexibleLayout(true, true) .Finish() .Add <UIButton>() .Text("C") .OnClick(ButtonAction) .Finish() .Add <UIEmpty>() .FlexibleLayout(true, true) .Finish() .Add <UIButton>() .Image(SpriteLoader.GetSprite("KodeUI/Default/toggle_on")) .OnClick(ButtonAction) .Finish() .Finish() .Add <Layout>() .Horizontal() .ControlChildSize(true, true) .ChildForceExpand(false, false) .Anchor(AnchorPresets.HorStretchTop) .FlexibleLayout(true, false) .Add <UIButton>() .Text("Very Long text") .OnClick(ButtonAction) .FlexibleLayout(true, false) .Finish() .Add <UIEmpty>() .FlexibleLayout(true, true) .Finish() .Add <UIButton>() .Text("Is Long") .OnClick(ButtonAction) .FlexibleLayout(true, false) .Finish() .Finish() .Add <UIText>() .Text("A long text that should overflow to the next line") .Alignment(TextAlignmentOptions.TopLeft) .FlexibleLayout(true, false) .Finish() .Add <Layout>() .Horizontal() .ControlChildSize(true, true) .ChildForceExpand(false, false) .Anchor(AnchorPresets.HorStretchTop) .Add <UIText>(out text) .Text("N/A") .Alignment(TextAlignmentOptions.TopLeft) .FlexibleLayout(true, false) .Finish() .Finish() .Add <UIToggle>() .OnValueChanged(Action) .FlexibleLayout(false, true) .PreferredSize(15, 15) .Finish() .Add <UIInputField>() .FlexibleLayout(true, false) .SizeDelta(0, 0) .Finish() .Add <TreeView>(out treeView) .Items(treeItems) .OnClick(OnTreeClicked) .OnStateChanged(OnTreeStateChanged) .PreferredSize(-1, 150) .FlexibleLayout(true, true) .Finish() .Finish(); // needed in the editor to have the proper layout when not in play mode LayoutRebuilder.ForceRebuildLayoutImmediate(basePanel.rectTransform); // TODO: // * LayoutElement sur tout ? Flexible Size H/V en fonction du layout parent ? // * ContentSizeFitter sur tout/certain ? H/V en fonction du layout parent ? }