public void GenerateUI(UIDesciption uiDesc) { if (!UIGenerator.ScriptsWasCreated) { CheckFileSystem(); GenerateScripts(uiDesc); } else { CreateUnityObjects(uiDesc); } }
private UIDesciption GenerateUIDescription(string data, FileType type) { UIDesciption descr = null; switch (type) { case FileType.YAML: { YamlSerializer sr = new YamlSerializer(); var docs = sr.Deserialize(data); Config = docs[0] as UIGeneratorConfig; descr = docs[1] as UIDesciption; } break; } return(descr); }
private void GenerateScripts(UIDesciption uiDesc) { CheckFileSystem(); Template screen_template = GetTemplate("'screen'"); foreach (var screen in uiDesc.Screens) { string filename = screen.FileName; /* * Debug.Log("Create screen script: " + filename); * continue; */ if (File.Exists(filename)) { continue; } var stream = File.CreateText(filename); string result = screen_template.Render( Hash.FromAnonymousObject(new { screen = screen, config = s_config }) ); stream.Write(result); stream.Close(); GeneratePanelsScripts(screen); AssetDatabase.ImportAsset(filename); } UIGenerator.ScriptsWasCreated = true; }
private void CreateUnityObjects(UIDesciption uiDesc) { var mainSceneStructure = new MainSceneStructure(); foreach (var screen in uiDesc.Screens) { GameObject sc = new GameObject(NamesFormatter.PrefabName(screen.ClassName)); GameObject screen_panels_group = new GameObject(screen.PanelsGroupName); screen_panels_group.AddComponent <RectTransform>(); screen_panels_group.transform.SetParent(mainSceneStructure.Panels.transform); Type screen_type = screen.ComponentType; sc.AddComponent(screen_type); sc.transform.SetParent(mainSceneStructure.ScreenManager.transform); /* * * // Commented because BaseScreen finds PanelsGroup on Awake. * // PanelsGroup panels_group_comp = screen_panels_group.AddComponent(typeof(PanelsGroup)) as PanelsGroup; * var panels_field = typeof(BaseScreen).GetField("Panels"); * panels_field.SetValue(screen_comp, panels_group_comp); * */ foreach (var panel in screen.Panels) { GameObject pobj = new GameObject(NamesFormatter.PrefabName(panel.ClassName)); pobj.AddComponent <RectTransform>(); var panel_type = panel.ComponentType; var panel_comp = pobj.AddComponent(panel_type); pobj.transform.SetParent(screen_panels_group.transform); if (panel.Elements != null) { foreach (var element in panel.Elements) { element.Visit(panel, panel_comp as PanelBase); } } /* * string field_name = "_" + Screen.MakeFieldName(panel_type.Name); * var fields = screen_type.GetFields(BindingFlags.NonPublic | BindingFlags.Instance); */ //var field = screen_type.GetField(field_name, BindingFlags.NonPublic | BindingFlags.Instance); // /* * foreach(var f in fields) *{ * if(f.Name == field_name) * f.SetValue(screen_comp, panel_comp); *} */ PrefabUtility.CreatePrefab("Assets/Bully.UI/Prefabs/Panels/" + pobj.name + ".prefab", pobj, ReplacePrefabOptions.ConnectToPrefab); } string prefabName = string.Format("Assets/Bully.{0}/Prefabs/Screens/{1}.prefab", s_config.ProjectName, sc.name); PrefabUtility.CreatePrefab(prefabName, sc, ReplacePrefabOptions.ConnectToPrefab); } }