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()
{
}
}