Beispiel #1
0
    void DrawToolBar()
    {
        GUILayout.BeginHorizontal(EditorStyles.toolbar, GUILayout.ExpandWidth(true)); //2A+

        GUILayout.BeginHorizontal(GUILayout.Width(mLeftBarWidth - 6));                //2B+
        GUI.SetNextControlName("ForFouce");

        _mAsset         = mSelectionAsset;
        mSelectionAsset = (TextAsset)EditorGUILayout.ObjectField(mSelectionAsset, typeof(TextAsset), false);
        if (_mAsset != mSelectionAsset)
        {
            ReadFromTextAsset();
        }

        GUILayout.EndHorizontal();                              //2B-

        GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); //2C+

        if (mSelectionAsset != null)
        {
            if (GUILayout.Button("Import", EditorStyles.toolbarDropDown, GUILayout.Width(65)))
            {
                GUIContent[] menuItems = new GUIContent[] {
                    new GUIContent("from OOForm table..."),
                    new GUIContent("from Json..."),
                    new GUIContent("from XML..."),
                    new GUIContent("from CSV...")
                };

                EditorUtility.DisplayCustomMenu(new Rect(mLeftBarWidth, 16, 0, 0), menuItems, -1,
                                                delegate(object userData, string[] options, int selected)
                {
                    switch (selected)
                    {
                    case 0:
                        {
                            string path = EditorUtility.OpenFilePanel("Select file to import!", "", "txt");
                            if (path != "")
                            {
                                mSelectionTable = OOFormArray.ReadFromFile(path);
                                mIsModify       = true;
                            }
                        }
                        break;

                    case 1:
                        {
                            string path = EditorUtility.OpenFilePanel("Select file to import!", "", "txt");
                            if (path != "")
                            {
                                mSelectionTable = OOFormArray.ReadFromJsonFile(path);
                                mIsModify       = true;
                            }
                        }
                        break;

                    case 2:
                        {
                            string path = EditorUtility.OpenFilePanel("Select file to import!", "", "xml");
                            if (path != "")
                            {
                                mSelectionTable = OOFormArray.ReadFromXMLFile(path);
                                mIsModify       = true;
                            }
                        }
                        break;

                    case 3:
                        {
                            string path = EditorUtility.OpenFilePanel("Select file to import!", "", "csv");
                            if (path != "")
                            {
                                mSelectionTable = OOFormArray.ReadFormCSVFile(path);
                                mIsModify       = true;
                            }
                        }
                        break;
                    }
                }
                                                , null);
            }
            if (GUILayout.Button("Export", EditorStyles.toolbarDropDown, GUILayout.Width(65)))
            {
                GUIContent[] menuItems = new GUIContent[] {
                    new GUIContent("to OOForm table..."),
                    new GUIContent("to Json..."),
                    new GUIContent("to XML..."),
                    new GUIContent("to CSV...")
                };

                EditorUtility.DisplayCustomMenu(new Rect(mLeftBarWidth + 65, 16, 0, 0), menuItems, -1,
                                                delegate(object userData, string[] options, int selected)
                {
                    switch (selected)
                    {
                    case 0:
                        {
                            string path = EditorUtility.SaveFilePanel("Select file to save!", "", "", "txt");
                            if (path != "")
                            {
                                OOFormTools.WriteFileText(path, mSelectionTable.ToString());
                            }
                        }
                        break;

                    case 1:
                        {
                            string path = EditorUtility.SaveFilePanel("Select file to save!", "", "", "txt");
                            if (path != "")
                            {
                                OOFormTools.WriteFileText(path, mSelectionTable.ToJsonString());
                            }
                        }
                        break;

                    case 2:
                        {
                            string path = EditorUtility.SaveFilePanel("Select file to save!", "", "", "xml");
                            if (path != "")
                            {
                                OOFormTools.WriteFileText(path, mSelectionTable.ToXMLString(), System.Text.Encoding.UTF8);
                            }
                        }
                        break;

                    case 3:
                        {
                            string path = EditorUtility.SaveFilePanel("Select file to save!", "", "", "csv");
                            if (path != "")
                            {
                                OOFormTools.WriteFileText(path, mSelectionTable.ToCSVString(), System.Text.Encoding.UTF8);
                            }
                        }
                        break;
                    }
                }
                                                , null);
            }

            GUILayout.Label("");

            GUILayout.Label("Search:", GUILayout.Width(50));
            mSearchString = GUILayout.TextField(mSearchString, OOFormSkin.OStyle_ToolbarSearch, GUILayout.Width(120));
            GUILayout.Label("", OOFormSkin.OStyle_ToolbarSearchRightCap);

            GUILayout.Label("    Column Page:", GUILayout.ExpandWidth(false));
            if (GUILayout.Button("<", EditorStyles.toolbarButton, GUILayout.Width(40)))
            {
                mCurrentColumnPage--;
                mCurrentColumnPage = Mathf.Max(mCurrentColumnPage, 1);
                GUI.FocusControl("ForFouce");
            }
            int max_column_page = mSelectionTable.mColumnCount / mPageColumnCount + 1;
            GUILayout.Label(mCurrentColumnPage.ToString() + "/" + max_column_page.ToString(), EditorStyles.textField, GUILayout.Width(50));

            if (GUILayout.Button(">", EditorStyles.toolbarButton, GUILayout.Width(40)))
            {
                mCurrentColumnPage++;
                mCurrentColumnPage = Mathf.Min(mCurrentColumnPage, max_column_page);
                GUI.FocusControl("ForFouce");
            }
        }
        GUILayout.EndHorizontal();  //2C-

        GUILayout.EndHorizontal();  //2A-
    }
Beispiel #2
0
    public void ApplyMenu()
    {
        string script_path = OOFormSkin.FindAsset("OOFormMenuApply.cs");

        if (script_path == "")
        {
        }
        else
        {
            string script_start =
                @"//Created by MenuManager ...
using UnityEngine;
using System.Collections;
using UnityEditor;

public class OOFormMenuApply
{

";
            string script_end = "\n}";

            string script_menu_item = @"
    [MenuItem(""__MenuName__"")]
    static void __FunctionName__()
    {
        string path = ""__ManagerPath__"";
        OOFormManager manager = AssetDatabase.LoadAssetAtPath(path, typeof(OOFormManager)) as OOFormManager;
        if (manager)
        {
            OOFormManagerPop.InitWithManager(manager);
        }
    }

";

            string script_menu_item_table = @"
    [MenuItem(""__MenuName__"")]
    static void __FunctionName__()
    {
        string path = ""__TablePath__"";
        TextAsset text_asset = AssetDatabase.LoadAssetAtPath(path, typeof(TextAsset)) as TextAsset;
        if(text_asset)
        {
            OOFormEditor.OpenWithAsset(text_asset);
        }
    }
";

            string script_menu = "";
            for (int i = 0; i < mMenuTarget.mTableManagerList.Count; i++)
            {
                string script_txt = script_menu_item.Replace("__MenuName__", mMenuTarget.mTableMenuItemList[i]);
                script_txt   = script_txt.Replace("__FunctionName__", "MenuFunction" + i.ToString());
                script_txt   = script_txt.Replace("__ManagerPath__", AssetDatabase.GetAssetPath(mMenuTarget.mTableManagerList[i]));
                script_menu += script_txt;
            }


            for (int i = 0; i < mMenuTarget.mTableList.Count; i++)
            {
                string script_text = script_menu_item_table.Replace("__MenuName__", mMenuTarget.mTableMenuList[i]);
                script_text  = script_text.Replace("__FunctionName__", "TableMenuFunction" + i.ToString());
                script_text  = script_text.Replace("__TablePath__", AssetDatabase.GetAssetPath(mMenuTarget.mTableList[i]));
                script_menu += script_text;
            }

            OOFormTools.WriteFileText(script_path, script_start + script_menu + script_end);
            AssetDatabase.Refresh();
        }
    }
Beispiel #3
0
    /// <summary>
    /// Read form data from json file
    /// </summary>
    /// <param name="formPath"></param>
    /// <returns></returns>
    public static OOFormArray ReadFromJsonFile(string formPath)
    {
        string form_string = OOFormTools.ReadFileText(formPath);

        return(GetFormByJsonString(form_string));
    }
Beispiel #4
0
    /// <summary>
    /// Read form data from csv file
    /// </summary>
    /// <param name="formPath"></param>
    /// <returns></returns>
    public static OOFormArray ReadFormCSVFile(string formPath)
    {
        string form_string = OOFormTools.ReadFileText(formPath);

        return(GetFormByCSVString(form_string));
    }
Beispiel #5
0
 /// <summary>
 /// Save form data to a file
 /// </summary>
 /// <param name="fileName"></param>
 public void SaveFormFile(string fileName)
 {
     OOFormTools.WriteFileText(fileName, ToString());
 }