Ejemplo n.º 1
0
    public void Generate()
    {
        if (string.IsNullOrEmpty(input.text))
        {
            return;
        }

        string code = TableCodeGen.Generate(input.text, "SampleTable");

        output.text = code;
    }
Ejemplo n.º 2
0
    private void CreateScriptFromTable()
    {
        var folder = Application.streamingAssetsPath;

        if (PlayerPrefs.HasKey(Pref_lastCsFolder))
        {
            folder = PlayerPrefs.GetString(Pref_lastCsFolder);
        }
        var fileName = System.IO.Path.GetFileNameWithoutExtension(filePath);
        var path     = EditorUtility.SaveFilePanel("保存C#文件", folder, fileName, "cs");

        if (!string.IsNullOrEmpty(path))
        {
            fileName = System.IO.Path.GetFileNameWithoutExtension(path);
            var script = TableCodeGen.Generate(ListToArray(arr), types.ConvertAll <string>(x => x.ToString().ToLower()).ToArray(), fileName);
            System.IO.File.WriteAllText(path, script);
            AssetDatabase.Refresh();
        }
    }
Ejemplo n.º 3
0
    public static MonoScript CreateScript(TextAsset csv, string path)
    {
        if (csv == null || string.IsNullOrEmpty(csv.text))
        {
            return(null);
        }

        string className = Path.GetFileNameWithoutExtension(path);
        string code      = TableCodeGen.Generate(csv.text, className);

        File.WriteAllText(path, code);
        Debug.Log("Table script generated: " + path);

        AssetDatabase.Refresh();

        // absolute path to relative
        if (path.StartsWith(Application.dataPath))
        {
            path = "Assets" + path.Substring(Application.dataPath.Length);
        }

        return(AssetDatabase.LoadAssetAtPath(path, typeof(MonoScript)) as MonoScript);
    }