static void FindTagWidgets(Transform root) { //只寻找带有此标签的组件 if (root.tag == "ui_control") { WidgetMeta wm = new WidgetMeta(); wm.uitype = GetControlType(root); GetEventParam(root,wm); GetWidgetPath(root.gameObject, ref wm.control_path); try { ms_widget_dict.Add(wm.control_name, wm); Debug.Log("add :" + wm.control_name ); } catch (Exception e) { Debug.LogError(e.ToString()); Debug.LogError("控件名有重复: " + wm.control_name); return; } } foreach (Transform child in root) { FindTagWidgets(child); } }
static void GetEventParam(Transform control, WidgetMeta meta) { meta.control_name = control.name; UIControlMeta meta_def = control.GetComponent<UIControlMeta>(); if (meta_def != null) { meta.event_name = meta_def.trigger.ToString(); meta.event_func = meta_def.FunctionName; if (meta_def.VarName != null) { meta_def.VarName = meta_def.VarName.Trim(); if (string.IsNullOrEmpty(meta_def.VarName) == false) meta.var_name = meta_def.VarName; } } else { if (meta.uitype == "UIButton") { //按钮默认是有单击事件的 meta.event_name = "onClick"; } } if (string.IsNullOrEmpty(meta.var_name)) { string prefix = GetVarPrefix(meta.uitype); if (prefix != null) meta.var_name = "m_" + prefix + "_" + control.name; else meta.var_name = "m_" + control.name; } }