static string GetEventFuncsStr(UiNode uiNode, string fileStr, string className) { string funcsStr = ""; AutoCreateEvent(uiNode, fileStr, className, ref funcsStr); return(funcsStr); }
/// <summary> /// Adds the children of a node to the given parent transform /// </summary> /// <param name="node"></param> /// <param name="parentObject"></param> /// <param name="scale"></param> private void AddChildrenOfNode(UiNode node, Transform parentObject, float scale = DefaultScale) { if (node is UiInnerNode) { var innerNode = (UiInnerNode)node; if (innerNode.Children == null) { return; } var branchObjects = AddBranchObjects(innerNode, parentObject, scale); scale *= 0.8f; for (var i = 0; i < innerNode.Children.Count; i++) { AddChildrenOfNode(innerNode.Children[i], branchObjects[i].transform.Find(NodeName), scale); } } else if (node is UiLeaf) { var leaf = (UiLeaf)node; AddLeafObject(parentObject, leaf); } else { Debug.LogError("Unknown type of node, aborting structure generation"); } }
private IEnumerator Render(UiNode root) { var innerNode = root as UiInnerNode; if (innerNode == null || innerNode.Children?.Count == 0) { yield break; } innerNode.SortChildren(); var trees = innerNode.Children; yield return(null); foreach (var tree in trees) { var treeObject = TreeBuilder.GenerateTree(tree, Vector2.zero); tree.Circle.Position.Subscribe(v => { treeObject.transform.localPosition = new Vector3(v.x, 0, v.y); }); yield return(null); } TreeBuilder.CirclePacking(innerNode); ForestManipulator.AdjustFloorRadius(innerNode); }
static void UpgradeJsons() { DirectoryInfo dir = new DirectoryInfo(CACHE_FILE_PATH.Replace("{filename}.json", "")); var files = dir.GetFiles("*.json"); foreach (var file in files) { string content = File.ReadAllText(file.FullName, System.Text.Encoding.UTF8); content = content.Replace("UI", "Ui"); string uiName = file.Name.Replace("XUI", "Ui").Replace(".json", ""); Debug.Log(uiName); UiJsonOld oldJson = Json.Parse <UiJsonOld>(content); UiJson json = new UiJson(); json.SaveDirName = oldJson.SaveDirName.Replace("2d", ""); json.UiNodeData = new UiNode(); UiNode node = json.UiNodeData; node.Children = new Dictionary <string, UiNode>(); foreach (var oldData in oldJson.UiNodeDatas) { foreach (var oldChild in oldData.Children) { node.Children.Add(oldChild.Key, oldChild.Value); } } content = Json.ToString(json); File.WriteAllText(file.FullName, content, System.Text.Encoding.UTF8); } Debug.Log("更新Json文件完成。"); }
static void GetEventFunc(UiNode uiNode) { if (uiNode == null) { return; } string[] events; if (!UiDict.UiEventDict.TryGetValue(uiNode.Type, out events)) { return; } uiNode.NodeEvents = new UiNodeEvent[events.Length]; for (int i = 0; i < events.Length; ++i) { string eventStr = events[i]; uiNode.NodeEvents[i] = new UiNodeEvent() { IsActive = true, Type = eventStr }; } }
//根据相对坐标偏移量获取元素 public UiElement FindRelativeElement(int position, int offsetX, int offsetY) { UiNode relativeNode = uiNode.FindRelativeNode(position, offsetX, offsetY); UiElement relativeElement = new UiElement(relativeNode); return(relativeElement); }
/// <summary> /// Adds recursively the children of a node to the given parent transform /// </summary> /// <param name="node"></param> /// <param name="parent"></param> private void GenerateBranches(UiNode node, Transform parent) { var innerNode = node as UiInnerNode; if (innerNode != null) { if (HasOnlyLeaves(innerNode)) { DistributeSunflower(innerNode, parent); } else { DistributeCirclePacking(innerNode, parent); } manipulator.AddCircleVisualization( parent.Find(ForestManipulator.BranchName).Find(ForestManipulator.NodeName), innerNode.Circle.Radius); return; } var leaf = node as UiLeaf; if (leaf != null) { manipulator.AddLeafObject(parent, leaf); return; } Debug.LogError("Unknown type of node, aborting structure generation"); }
static void AutoInitUi(UiNode uiNode, string className, string path, ref string uiStr) { if (!string.IsNullOrEmpty(uiNode.Name)) { // string tmpStr = ""; string tranStr = "self.Transform"; string tmpPath = ""; string tmpType = ""; if (!string.IsNullOrEmpty(path)) { tmpPath = path; if (path.StartsWith("/")) { tmpPath = path.Remove(0, 1); } //if (uiNode.Is3dUi) //{ // tranStr += "3d"; //} } if (!string.IsNullOrEmpty(uiNode.Type)) { tmpType = uiNode.Type; } if (!string.IsNullOrEmpty(tmpPath) || !string.IsNullOrEmpty(tmpType)) { if (IsGridNode) { uiStr += " self." + uiNode.VarName + " = XUiHelper.TryGetComponent(" + tranStr + ", "; uiStr += !string.IsNullOrEmpty(tmpPath) ? "\"" + tmpPath + "\", " : "nil, "; uiStr += !string.IsNullOrEmpty(tmpType) ? "\"" + tmpType + "\")" : "nil)"; } else { uiStr += " self." + uiNode.VarName + " = " + tranStr; if (!string.IsNullOrEmpty(tmpPath)) { uiStr += ":Find(\"" + tmpPath + "\")"; } if (!string.IsNullOrEmpty(tmpType)) { uiStr += ":GetComponent(\"" + uiNode.Type + "\")"; } } uiStr += "\r\n"; } } foreach (var child in uiNode.Children) { string nextPath = path + child.Value.MidPath; nextPath = string.IsNullOrEmpty(nextPath) ? child.Value.Name : nextPath + "/" + child.Value.Name; AutoInitUi(child.Value, className, nextPath, ref uiStr); } }
static void CreateUiNode(Transform root, string path, string midPath, ref UiNode parentNode) { if (root == null) { return; } string uiType = GetUiType(root.name); UiNode uiNode = null; if (uiType != null) { uiNode = new UiNode() { Name = root.name, Type = uiType, Key = path, MidPath = midPath }; GetVarName(uiNode); GetEventFunc(uiNode); if (parentNode != null) { if (parentNode.Name == "root") { parentNode = uiNode; } else { if (parentNode.Children.ContainsKey(path)) { Debug.LogError("ui name is repeated: " + path); } else { parentNode.Children.Add(path, uiNode); } } } } if (root.childCount > 0) { for (int i = 0; i < root.childCount; i++) { Transform child = root.GetChild(i); if (uiNode != null) { CreateUiNode(child, path + "/" + child.name, "", ref uiNode); } else { CreateUiNode(child, path + "/" + child.name, midPath + "/" + root.name, ref parentNode); } } } }
/// <summary> /// Generates the unity tree according to the given data structure of the node /// </summary> /// <param name="node"></param> /// <param name="position"></param> public void GenerateTreeStructure(UiNode node, Vector2 position) { var tree = AddTreeObject(position); var trunk = AddBranchObject(node, tree.transform); node.SortChildren(); AddChildrenOfNode(node, trunk.transform.Find(NodeName)); }
private static void OnUiNodeUpdated(UiNode uinode) { hub.Clients.Group(uinode.PanelId).OnUiNodeUpdated(uinode); if (uinode.Settings["ShowOnHomePage"].Value == "true") { hub.Clients.Group(MAIN_PAGE_ID).OnUiNodeUpdated(uinode); } }
public void AdjustFloorRadius(UiNode forest) { Floor.SetActive(true); var xScale = Floor.SizeToScale(Axis.X, forest.Circle.Radius * 2); var zScale = Floor.SizeToScale(Axis.Z, forest.Circle.Radius * 2); Floor.transform.localScale = new Vector3(xScale, 1, zScale); }
// 自动查找生成Ui static string GetAutoInitUiStr(UiNode uiNode, string className) { string uiStr = ""; uiStr += "\r\nfunction " + className + ":AutoInitUi()\r\n"; AutoInitUi(uiNode, className, "", ref uiStr); uiStr += "end\r\n"; return(uiStr); }
void DrawUiNode(UiNode UiNode, int level = 0) { if (UiNode.Children.Count > 0) { using (new GUILayout.HorizontalScope()) { GUILayout.Box(GUIContent.none, "AnimationEventBackground", GUILayout.ExpandWidth(true), GUILayout.Height(1)); } } using (new GUILayout.HorizontalScope()) { GUILayout.Label(new GUIContent(""), GUILayout.Width(level * 50)); if (UiNode.Children.Count > 0) { if (GUILayout.Button(UiNode.ShowChildren ? new GUIContent("-") : new GUIContent("+"), EditorStyles.toolbarButton, GUILayout.Width(20))) { UiNode.ShowChildren = !UiNode.ShowChildren; } } GUILayout.Label(new GUIContent(UiNode.Name), GUILayout.Width(150)); if (level > 0) { UiNode.VarName = GUILayout.TextField(string.IsNullOrEmpty(UiNode.VarName) ? UiNode.Name : UiNode.VarName, GUILayout.Width(100)); UiNode.IgnoreCreate = GUILayout.Toggle(UiNode.IgnoreCreate, new GUIContent("忽略生成"), GUILayout.Width(100)); UiNode.MergeCreate = GUILayout.Toggle(UiNode.MergeCreate, new GUIContent("合并生成"), GUILayout.Width(100)); if (UiNode.NodeEvents != null && UiNode.NodeEvents.Length > 0) { for (int i = 0; i < UiNode.NodeEvents.Length; i++) { UiNodeEvent UiNodeEvent = UiNode.NodeEvents[i]; UiNode.NodeEvents[i].IsActive = GUILayout.Toggle(UiNodeEvent.IsActive, new GUIContent(UiNodeEvent.Type), GUILayout.Width(100)); } } } else { GUILayout.Label(new GUIContent("保存文件夹:"), GUILayout.Width(100)); SaveDirName = GUILayout.TextField(SaveDirName, GUILayout.Width(100)); } } if (UiNode.ShowChildren) { foreach (var child in UiNode.Children) { DrawUiNode(child.Value, level + 1); } } }
private static bool Filter(UiNode uiNode, IEnumerable <IExpressionExecutor> filters) { foreach (var filter in filters) { if (!filter.Execute(uiNode)) { return(false); } } return(true); }
public IEnumerable <UiNode> Search(UiNode root, IExpressionExecutor filter, int max = int.MaxValue) { try { //添加任务 return(SearchChild(root, filter, max)); } catch (Exception) { return(new List <UiNode>()); } }
public static void CreateScript(string saveDirName, UiNode uiNode) { string rootName = uiNode.Name; string className = GetClassName(rootName); string scriptFile = SCRIPT_FILE_PATH + className + ".lua"; if (!Directory.Exists(SCRIPT_FILE_PATH)) { Directory.CreateDirectory(SCRIPT_FILE_PATH); } string fileStr = ""; if (File.Exists(scriptFile)) { FileStream file = new FileStream(scriptFile, FileMode.Open, FileAccess.ReadWrite); StreamReader read = new StreamReader(file); fileStr = read.ReadToEnd(); read.Close(); file.Close(); } // 生成替换 -- auto 部分的代码 string[] strs = Regex.Split(fileStr, "-- auto\r\n", RegexOptions.IgnoreCase); string classStr = string.IsNullOrEmpty(strs[0]) ? GetClassStr(rootName) : strs[0]; classStr += "-- auto\r\n"; classStr += "-- Automatic generation of code, forbid to edit"; classStr += GetInitAutoScript(className); classStr += GetAutoInitUiStr(uiNode, className); //classStr += GetAutoKeyStr(className); classStr += GetAutoAddListenerStr(uiNode, className); classStr += "-- auto\r\n"; // 事件函数,函数体需要手动实现,不能直接被替换 classStr += GetEventFuncsStr(uiNode, fileStr, className); if (strs.Length >= 3) { for (int i = 2; i < strs.Length; ++i) { classStr += strs[i]; } } else { classStr += GetEndStr(rootName); } File.WriteAllText(scriptFile, classStr, new UTF8Encoding(false)); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); }
public async Task <string> GetValue(string nodeId, string name) { return(await Task.Run(() => { UiNode node = engine.GetUINode(nodeId); if (node == null) { return null; } return node.GetValue(name); })); }
public async Task <bool> SetValues(string nodeId, Dictionary <string, string> values) { return(await Task.Run(() => { UiNode node = engine.GetUINode(nodeId); if (node == null) { return false; } return node.SetValues(values); })); }
public Form1() { InitializeComponent(); //set default options ScrapeMethod = UiScrapingMethod.UI_AUTOMATIC; ScrapeMethod_Combo.SelectedIndex = 0; OCREngine = UiOCREngine.UI_OCR_TESSERACT; OCREngine_combo.SelectedIndex = 0; //create uiNode uiNode = UiFactory.Instance.NewUiNode(); }
public static UiNode CreateNewUiNode(Transform root) { NameDict.Clear(); string rootName = root.name; UiNode rootNode = new UiNode { Name = "root" }; CreateUiNode(root, root.name, "", ref rootNode); return(rootNode); }
static void CreateUiScript() { if (Selection.activeGameObject == null) { EditorUtility.DisplayDialog("错误", "当前未选中UI", "确认"); return; } rootGameObject = Selection.activeGameObject.gameObject; NewUiNode = AutoGenerateLua.CreateNewUiNode(rootGameObject.transform); string className = AutoGenerateLua.GetClassName(rootGameObject.name); string sceneName = rootGameObject.name; OpenWindow(sceneName, className, NewUiNode); }
static string GetAutoAddListenerStr(UiNode uiNode, string className) { string eventStr = string.Empty; //string eventStr = GetRegisterListenerStr(className); if (!uiNode.Name.StartsWith(ROOT_PANEL_PREFIX)) { eventStr += GetRegisterListenerStr(className); } eventStr += "\r\nfunction " + className + ":AutoAddListener()\r\n"; //eventStr += " self.AutoCreateListeners = {}\r\n"; AutoAddListener(uiNode, className, ref eventStr); eventStr += "end\r\n"; return(eventStr); }
private IEnumerable <UiNode> Execute(UiNode child = null, int max = int.MaxValue) { if (AutoAccessibilityService.Instance == null) { return(new List <UiNode>()); } if (!AutoAccessibilityService.Instance.Windows.ToList().Any()) { return(new List <UiNode>()); } var windows = AutoAccessibilityService.Instance.Windows .Where(x => x != null) .Select(x => new UiNode(x.Root)) .Where(x => x.VisibleToUser).ToList(); var list = new List <UiNode>(); if (child != null) { //查找给定节点的子节点是否有符合要求的 foreach (var window in windows) { var items = _uiNodeSearch.Search(child, _expressionExecutors).ToList(); list.AddRange(items); if (list.Count >= max) { break; } } } else { foreach (var node in windows) { var items = _uiNodeSearch.Search(node, _expressionExecutors).ToList(); list.AddRange(items); if (list.Count >= max) { break; } } } return(list); }
private void SelectCtrlBtn_Click(object sender, EventArgs e) { uiNode = UiFactory.Instance.NewUiNode(); try { WindowState = FormWindowState.Minimized; uiNode.SelectInteractive(UiSelectionType.UI_SELECT_NODE); SelectorTextBox.Text = uiNode.GetSelector(true); WindowState = FormWindowState.Normal; } catch (Exception ex) { WindowState = FormWindowState.Normal; MessageBox.Show(ex.Message); } }
public Form1() { InitializeComponent(); Monitor.SelectedIndex = 0; SpecialKey_Combo.SelectedIndex = 0; BTN_Combo.SelectedIndex = 0; KeyModifier_Combo.SelectedIndex = 0; EventType_Combo.SelectedIndex = 0; Blocking_Combo.SelectedIndex = 0; //instantiate UiEvents objects uiNodeEvents = UiFactory.Instance.NewUiNodeMonitor(); uiSystemEvents = UiFactory.Instance.NewUiSystem(); //instantiate UiNode object uiNode = UiFactory.Instance.NewUiNode(); }
private void InitUiPathObjects() { uiNode = UiFactory.Instance.NewUiNode(); uiImage = UiFactory.Instance.NewUiImage(); uiSystem = UiFactory.Instance.NewUiSystem(); }