先附上git地址
https://github.com/huqiang0204/huqiang.UnitySubThreadUI
可以在面板中快捷创建,右键才菜单->UIComposite->DesignedDockPanel
注意UIComposite下的子组件不要随意改名,因为子组件通过名称查找的
示例代码,里面用到了滚动框组件和数据绑定,数据驱动UI及使用方法后面再做介绍
public class LayoutTestPage : UIPage
{
class View
{
public DesignedDockPanel Layout;
public EventCallBack Last;
public EventCallBack Next;
}
View view;
public override void Initial(ModelElement parent, object dat = null)
{
model = ModelManagerUI.CloneModel("baseUI", "layout");
base.Initial(parent, dat);
view = model.ComponentReflection<View>();
var area = view.Layout.MainContent;
area.AddContent("page0");
var d = area.AddArea(DockpanelArea.Dock.Down,0.3f);
var context = d.AddContent("page1");
d.model.parent.GetComponent<ImageElement>().color = Color.red;
var one = d.AddArea(DockpanelArea.Dock.Right,0.4f);
context = one.AddContent("page2");
context.LoadPopWindow<GridTestWindow>();
//d.Refresh();
one.model.parent.GetComponent<ImageElement>().color = Color.green;
var top = area.AddArea(DockpanelArea.Dock.Top, 0.2f);
top.AddContent("page3");
top.model.parent.GetComponent<ImageElement>().color = Color.yellow;
var l = top.AddArea(DockpanelArea.Dock.Left, 0.4f);
l.model.parent.GetComponent<ImageElement>().color = Color.blue;
l.control.headDock = TabControl.HeadDock.Down;
context = l.AddContent("page5");
context.LoadPopWindow<GridTestWindow2>();
//l.Refresh();
view.Last.Click = (o, e) => { LoadPage<TestPage>(); };
view.Next.Click = (o, e) => { LoadPage<DrawPage>(); };
}
}
public class GridTestWindow : PopWindow
{
class View
{
public ScrollY Scroll;
}
class Item
{
public TextElement Text;
}
View view;
public override void Initial(ModelElement parent, UIPage ui, object obj = null)
{
model = ModelManagerUI.CloneModel("baseUI", "gridscroll");
base.Initial(parent, ui, obj);
view = model.ComponentReflection<View>();
List<int> testData = new List<int>();
for (int i = 0; i < 33; i++)
testData.Add(i);
view.Scroll.BindingData = testData;
view.Scroll.SetItemUpdate<Item,int>( (o, e, i) => { o.Text.text = i.ToString();});
view.Scroll.Refresh();
}
}
public class GridTestWindow2 : PopWindow
{
class View
{
public ScrollX Scroll;
}
class Item
{
public TextElement Text;
}
View view;
public override void Initial(ModelElement parent, UIPage ui, object obj = null)
{
model = ModelManagerUI.CloneModel("baseUI", "gridscroll");
base.Initial(parent, ui, obj);
view = model.ComponentReflection<View>();
List<int> testData = new List<int>();
for (int i = 0; i < 44; i++)
testData.Add(i);
view.Scroll.BindingData = testData;
view.Scroll.SetItemUpdate<Item,int>( (o, e, i) => {o.Text.text = i.ToString();});
view.Scroll.Refresh();
}
}
没有录入鼠标,操作怪怪的