unity和xlua 第四步如何代码生成lua文件

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif


public class Testss : MonoBehaviour
{
   

    // Start is called before the first frame update
    void Start()
    {
      
        //第二步:如何代码生成lua文件
        var curGo = "qwe";
        var viewName = $"{curGo}Model";
        //C#  引入了字符串前缀$的字符串插值。
        var template = $@"
--自动生成{DateTime.Now}
local {viewName} = {{
__CUSTOM__
}};

return {viewName}
";

    //    local options = {
    //    {path = 'ImgPlayerBox', components = {'RectTransform',}, binding = 'ImgPlayerBox_transform' },
    //}

        var tmpCustom = "";
        var modelList = new List<string>();
        string path = "121";string com1 = "Transform";  string binding = "Image_transform";
        string o1 = $@"path = '{path}',components = {{'{com1}'}} , binding = '{binding}'";
        string o2 = $@"{{path = '{path}',components = {{'{com1}'}} , binding = '{binding}'}}";
        Debug.Log(o1);
        Debug.Log(o2);
        modelList.Add(o1);
        modelList.Add(o2);

        for (int i = 0; i < modelList.Count; i++)
        {
            tmpCustom = tmpCustom + modelList[i].ToString() + "\n";
        }

         template = template.Replace("__CUSTOM__", tmpCustom);

        //如何生成指定内容文件
        System.IO.File.WriteAllText(System.IO.Path.Combine(Application.dataPath, $"{viewName}.lua"), template);
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值