예제 #1
0
        void Lookup(Transform node, string path, Dictionary <string, FieldExpr> clsInfo, bool skip)
        {
            if (_nodeDict.ContainsKey(node.tag) && !skip)
            {
                string goName    = node.gameObject.name;
                UINode uiNode    = _nodeDict[node.tag];
                var    fieldName = goName;
                var    fieldType = uiNode.typeName;

                if (goName.IndexOf("|") != -1)
                {
                    var arr = goName.Split('|');
                    if (arr.Length >= 2)
                    {
                        fieldName = arr[1];
                        fieldType = arr[0];
                    }
                }

                if (clsInfo.ContainsKey(fieldName))
                {
                    Debug.LogWarning(string.Format("field <{0}> repeated. at different layer", goName));
                }
                else if (!string.IsNullOrEmpty(fieldName) && !string.IsNullOrEmpty(fieldType))
                {
                    clsInfo.Add(fieldName, new FieldExpr {
                        path      = path,
                        fieldName = fieldName,
                        fieldType = fieldType
                    });
                }

                if (uiNode.UIType == UIType.Component)
                {
                    //Component 节点自成一体, 不再向下查询
                    return;
                }
            }

            for (int i = 0; i < node.childCount; i++)
            {
                var  child   = node.GetChild(i);
                bool isGroup = new Regex("[a-zA-Z|]+_[0-9]+$").IsMatch(child.name);
                Lookup(child, string.IsNullOrEmpty(path) ? child.name : string.Format("{0}/{1}", path, child.name), clsInfo, false);
                if (isGroup)
                {
                    var fieldName = new Regex("[a-zA-Z|]+_[0-9]+$").Match(child.name).Value;
                    if (fieldName.IndexOf("|") != -1)
                    {
                        var arr = fieldName.Split('|');
                        if (arr.Length < 2)
                        {
                            Debug.LogWarning("Error GameObject Name");
                            continue;
                        }
                        fieldName = arr[1];
                    }

                    FieldExpr childField;
                    if (clsInfo.TryGetValue(fieldName, out childField))
                    {
                        fieldName = new Regex("[a-zA-Z]+").Match(fieldName).Value;
                        FieldExpr lst;
                        if (clsInfo.TryGetValue(fieldName, out lst))
                        {
                            lst.isList = true;
                            lst.pathes.Add(childField.path);
                        }
                        else
                        {
                            clsInfo.Add(fieldName, new FieldExpr()
                            {
                                isList = true,
                                pathes = new List <string>()
                                {
                                    childField.path
                                },
                                fieldName = fieldName,
                                fieldType = childField.fieldType
                            });
                        }
                        clsInfo.Remove(childField.fieldName);
                    }
                }
            }
        }