Exemple #1
0
    //保存UIViewCache信息
    UIViewCache SaveUIViewCache()
    {
        UIViewCache record = ScriptableObject.CreateInstance <UIViewCache>();

        record.codePath = _codeGeneratePath;

        record.componentInfoList = new List <UIComponentInfo>(_exportInfoDic.Values);

        //EditorHelper.CreateScriptableObjectAsset (record, VIEW_CACHE_PATH, UIPrefabRoot.name);

        return(record);
    }
Exemple #2
0
    public void GenerateCSharpCode(UIViewCache source)
    {
        // Build the generator with the class name and data source.
        UIViewCodeTemplate generator = new UIViewCodeTemplate(source.name, source.componentInfoList);

        // Generate output (class definition).
        var classDefintion = generator.TransformText();

        if (string.IsNullOrEmpty(_codeGeneratePath) && !Directory.Exists(_codeGeneratePath))
        {
            var outputPath = EditorUtility.SaveFilePanel("Save C# UIView Code",
                                                         VIEWCODE_GENERATED_PATH,
                                                         source.name,
                                                         "cs");

            outputPath = outputPath.Replace(Application.dataPath, "");

            _codeGeneratePath = outputPath;
            source.codePath   = _codeGeneratePath;
        }

        if (string.IsNullOrEmpty(_codeGeneratePath))
        {
            return;
        }

        try
        {
            // Save new class to assets folder.
            File.WriteAllText(Application.dataPath + _codeGeneratePath, classDefintion);

            ShowNotification(new GUIContent("Success 生成C#代码完毕"));
            // Refresh assets.
            //          AssetDatabase.Refresh ();
        }
        catch (System.Exception e)
        {
            Debug.Log("An error occurred while saving file: " + e);
        }
    }