public static void ClassBody(CodeGenerator gen, DataContext rootContext, List <DataContext> widgetContextList) { gen.PrintLine("// Generated by github.com/davyxu/cellorigin"); gen.PrintLine("using UnityEngine;"); gen.PrintLine("using UnityEngine.UI;"); gen.PrintLine(); gen.PrintLine("partial class ", ClassName(rootContext), " : Framework.BaseView"); gen.PrintLine("{"); gen.In(); gen.PrintLine(PresenterTemplate.ClassName(rootContext), " _Presenter;"); gen.PrintLine(); // TODO 变量声明代码 foreach (DataContext widgetContext in widgetContextList) { WidgetDeclare(gen, widgetContext); } gen.PrintLine(); gen.PrintLine("public override void Bind( Framework.BasePresenter presenter )"); gen.PrintLine("{"); gen.In(); gen.PrintLine("_Presenter = presenter as ", PresenterTemplate.ClassName(rootContext), ";"); gen.PrintLine(); gen.PrintLine("var trans = this.transform;"); gen.PrintLine(); // TODO List中的名称重名检查 // 打印控件搜索代码 foreach (DataContext widgetContext in widgetContextList) { FindWidgetlAssignToVar(gen, rootContext, widgetContext); } gen.PrintLine(); // 打印控件绑定代码 foreach (DataContext widgetContext in widgetContextList) { WidgetBind(gen, rootContext, widgetContext); } gen.Out(); gen.PrintLine("}"); // Bind gen.PrintLine(); gen.Out(); gen.PrintLine("}"); // Class }
public override void OnInspectorGUI() { DataContext ctx = target as DataContext; GUILayout.BeginHorizontal(); if (GUILayout.Button("Detect Type")) { ctx.Detect(); } ctx.Type = (WidgetType)EditorGUILayout.EnumPopup(ctx.Type); GUILayout.EndHorizontal(); switch (ctx.Type) { case WidgetType.InputField: case WidgetType.Text: { ctx.SyncType = (DataSyncType)EditorGUILayout.EnumPopup("SyncType", ctx.SyncType); break; } } switch (ctx.Type) { case WidgetType.View: { EditorGUILayout.LabelField("View: " + ViewTemplate.ClassName(ctx)); EditorGUILayout.LabelField("Presenter: " + PresenterTemplate.ClassName(ctx)); break; } case WidgetType.ScrollRect: { EditorGUILayout.LabelField("Instance in View: _" + ctx.Name); EditorGUILayout.LabelField("Property in Presenter: " + ctx.Name); EditorGUILayout.LabelField("Item View: " + ViewTemplate.ClassItemName(ctx)); EditorGUILayout.LabelField("Item Presenter: " + PresenterTemplate.ClassItemName(ctx)); break; } case WidgetType.Button: { EditorGUILayout.LabelField("Command: " + PresenterTemplate.Command(ctx)); break; } case WidgetType.InputField: case WidgetType.Text: { EditorGUILayout.LabelField("Instance in View: _" + ctx.Name); EditorGUILayout.LabelField("Property in Presenter: " + ctx.Name); break; } } if (GUILayout.Button("Add To Child")) { ctx.AddToTopChild(); } if (GUILayout.Button("Remove Child")) { if (EditorUtility.DisplayDialog("移除确认?", "移除所有子节点的DataContext", "是", "否")) { ctx.RemoveAllChild(); } } if (GUILayout.Button("Detect Child")) { ctx.DetectAllChild(); } base.OnInspectorGUI(); }