Esempio n. 1
0
    void OnGUI()
    {
        toolbarOption0 = GUILayout.Toolbar(toolbarOption0, toolbarTexts0, GUILayout.Width(Screen.width));
        switch (toolbarOption0)
        {
        case 0:
            GUILayout.Space(8);
            ChooseFile();
            GUILayout.Space(5);
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            toolbarOption = GUILayout.Toolbar(toolbarOption, toolbarTexts, GUILayout.Width(Screen.width * 3 / 4f));
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
            GUILayout.Space(5);

            switch (toolbarOption)
            {
            case 0:
                DrawTableDataGUI();

                break;

            case 1:
                DrawFields();
                break;
            }

            GUILayout.FlexibleSpace();
            GUILayout.Space(5);
            if (GUILayout.Button("保存配置文件"))
            {
                CheckEditConfigData();
                TableConfigOtherInfo infos = TableConfigBase.tableConfigOtherInfo[chooseFileName];
                string content             = TableConfigTool.ConfigInfo2TableText(infos, currentEditConfigData);
                string path = CreateConfigClassEditor.SaveConfigFilePath + "/" + chooseFileName + ".txt";
                FileUtils.CreateTextFile(path, content);
                CreateConfigClassEditor.CreateConfigClassFile(content, chooseFileName);
                AssetDatabase.Refresh();
            }
            break;

        case 1:
            GUILayout.Space(5);
            NewTableConfig();
            break;
        }
    }
Esempio n. 2
0
    private void NewTableConfig()
    {
        GUILayout.BeginHorizontal("box");
        newFileName = EditorDrawGUIUtil.DrawBaseValue("新建配置文件:", newFileName).ToString();
        if (GUILayout.Button("确定", GUILayout.Width(50)))
        {
            if (ResourcePathManager.ContainsFileName(newFileName) || string.IsNullOrEmpty(newFileName))
            {
                EditorUtility.DisplayDialog("警告", "名字不能为空或重复", "OK");
            }
            else
            {
                chooseFileName = newFileName;
                fileNames.Add(newFileName);
            }
        }

        GUILayout.EndHorizontal();

        if (string.IsNullOrEmpty(newFileName))
        {
            return;
        }
        if (ResourcePathManager.ContainsFileName(newFileName))
        {
            EditorGUILayout.HelpBox("文件名重复!!", MessageType.Error);
            return;
        }
        if (newConfigInfo == null)
        {
            newConfigInfo = new TableConfigOtherInfo();
        }

        newConfigInfo.configDescription = EditorDrawGUIUtil.DrawBaseValue("配置文件描述:", newConfigInfo.configDescription).ToString();
        GUILayout.Space(5);
        GUILayout.BeginHorizontal("box");
        GUILayout.Box("添加字段:");
        GUILayout.FlexibleSpace();
        if (GUILayout.Button("+", GUILayout.Width(50)))
        {
            TableConfigFieldInfo f = new TableConfigFieldInfo();
            f.fieldName = "NewField" + newConfigInfo.fieldInfoDic.Count;
            while (newConfigInfo.fieldInfoDic.ContainsKey(f.fieldName))
            {
                f.fieldName += "_0";
            }
            newConfigInfo.fieldInfoDic.Add(f.fieldName, f);
        }
        GUILayout.EndHorizontal();

        DrawFieldData(newConfigInfo);

        if (newConfigInfo.fieldInfoDic.Count > 0 && GUILayout.Button("创建"))
        {
            GlobalEvent.AddEvent(EditorGlobalEventEnum.OnResourcesAssetsChange, (t) =>
            {
                Debug.Log("OnResourcesAssetsChange");
                AssetsSortManagement.SetLayer(newFileName, configLayerName);
                AssetsSortManagement.Save();

                newFileName   = "";
                newConfigInfo = null;
            }, true);
            string content = TableConfigTool.ConfigInfo2TableText(newConfigInfo, null);
            string path    = CreateConfigClassEditor.SaveConfigFilePath + "/" + newFileName + ".txt";
            FileUtils.CreateTextFile(path, content);
            CreateConfigClassEditor.CreateConfigClassFile(content, newFileName);
            AssetDatabase.Refresh();
        }
    }