Example #1
0
    internal static void GenerateItem()
    {
        try
        {
            if (!UIEditorUtils.CheckUIConfig())
            {
                EditorUtility.DisplayDialog("错误", "配置表路径没有配置,请配置与Asset同级的config文件", "OK");
                return;
            }
            InitData();

            if (!Directory.Exists(_itemCodePath))
            {
                Directory.CreateDirectory(_itemCodePath);
            }
            EditorUtility.DisplayProgressBar("生成Item", "正在生成Item", 0);
            UIEditorUtils.ErrorList = new List <string>();
            Thread.Sleep(200);
            string[] strs   = Directory.GetFiles(Path.Combine(Application.dataPath, _itemUIPath), "*.prefab");
            float    length = strs.Length;
            float    index  = 0;
            foreach (var item in strs)
            {
                index++;
                EditorUtility.DisplayProgressBar("生成Item", $"正在生成{Path.GetFileNameWithoutExtension(item)}", index / length);
                GameObject     obj   = AssetDatabase.LoadAssetAtPath <GameObject>(Path.Combine("Assets", _itemUIPath, Path.GetFileName(item)));
                List <TranDto> trans = new List <TranDto>();
                UIEditorUtils.GetTrans(obj.transform, "", trans);
                trans.Reverse();
                GenerateUserCode(obj.name);
                GenerateCode(obj.name + ".gen.cs", ItemTemplate, trans, _itemCodePath, Path.Combine(_itemUIResPath, Path.GetFileNameWithoutExtension(item)));
                Thread.Sleep(200);
            }
            EditorUtility.DisplayProgressBar("生成Item", "生成Item完成", 1);
            Thread.Sleep(200);
            EditorUtility.ClearProgressBar();
            if (UIEditorUtils.ErrorList.Count > 0)
            {
                foreach (var item in UIEditorUtils.ErrorList)
                {
                    EditorUtility.DisplayDialog("警告", item, "OK");
                }
            }
            AssetDatabase.Refresh();
        }
        catch (Exception ex)
        {
            Debug.LogError(ex);
        }
        finally
        {
            if (_iniTool != null)
            {
                _iniTool.Close();
            }
            _iniTool = null;
            EditorUtility.ClearProgressBar();
        }
    }