void TravelDown(Transform transform, string pLuaName, List <string> namesInPath)
 {
     foreach (Transform childTrans in transform)
     {
         if (!checkNeedExport(childTrans))
         {
             continue;
         }
         bool needExport = (childTrans.gameObject.name[0] == '@');
         var  curName    = ComponentNameHelper.generateNameFromGameObjectName(childTrans);
         curName = ComponentNameHelper.rebuildNameForGameObject(curName, _nameMap, namesInPath);
         _nameMap.Add(curName, true);
         TransformInfo info = new TransformInfo();
         info.needExport = needExport;
         info.luaName    = curName;
         info.transform  = childTrans;
         if (!_treeMap.ContainsKey(pLuaName))
         {
             _treeMap[pLuaName] = new List <TransformInfo>();
         }
         _treeMap[pLuaName].Add(info);
         namesInPath.Add(childTrans.gameObject.name);
         TravelDown(childTrans, curName, namesInPath);
         namesInPath.RemoveAt(namesInPath.Count - 1);
     }
 }
        static void DoTask(bool isWin)
        {
            var list = Selection.gameObjects;

            if (list.Length < 1)
            {
                return;
            }
            GameObject go           = Selection.gameObjects[0];
            var        travelHelper = new GameObjectTravelHelper(go.transform, isWin);
            Dictionary <string, List <TransformInfo> > tree = travelHelper.GetTree();
            string rootName;

            if (isWin)
            {
                rootName = "window_";
            }
            else
            {
                rootName = "go";
            }
            LuaWriter luaWriter = new LuaWriter(tree, ComponentNameHelper.generateNameFromGameObjectName(go.transform), rootName, isWin);

            luaWriter.Write();
        }
        public static string rebuildNameForGameObject(string name, Dictionary <string, bool> map, List <string> names)
        {
            string resName = name;
            int    index   = names.Count;

            for (int i = index - 1; i >= 0; i--)
            {
                if (map.ContainsKey(resName))
                {
                    resName = ComponentNameHelper.generateNameFromGameObjectName(names[i]) + resName;
                }
                else
                {
                    break;
                }
            }
            return(resName);
        }
        private Tuple <bool, string> WriteComponent(string parentClassName, TransformInfo info, bool parentIsSelf)
        {
            var    list          = info.transform.gameObject.GetComponents <Component>();
            string className     = info.luaName;
            bool   hasExportNode = false;
            bool   isSelf        = true;
            string nodeName      = null;

            parentClassName = ComponentNameHelper.changeFirstToSmall(parentClassName);
            if (parentIsSelf)
            {
                parentClassName = "self." + parentClassName;
            }
            foreach (var comp in list)
            {
                if (_componentMap.ContainsKey(comp.GetType().Name))
                {
                    string prefix = _componentMap[comp.GetType().Name];
                    DoWriteComponent(parentClassName, prefix + className, info.transform.gameObject.name, comp.GetType().Name, info.needExport);
                }

                if (_nodeMap.ContainsKey(comp.GetType().Name) && !hasExportNode)
                {
                    string prefix = _nodeMap[comp.GetType().Name];
                    DoWriteComponent(parentClassName, prefix + className, info.transform.gameObject.name, info.needExport);
                    hasExportNode = true;
                    nodeName      = prefix + className;
                }
            }
            if (!info.needExport && !hasExportNode)
            {
                isSelf = false;
                DoWriteComponent(parentClassName, ComponentNameHelper.changeFirstToSmall(className), info.transform.gameObject.name, info.needExport);
            }
            return(new Tuple <bool, string>(isSelf, nodeName));
        }
        public static string generateNameFromGameObjectName(Transform t)
        {
            var curName = t.gameObject.name;

            return(ComponentNameHelper.generateNameFromGameObjectName(curName));
        }