You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

118 lines
4.1 KiB


using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.IO;
using System.Text;
using ET;
public partial class UICodeSpawner
{
static public void SpawnLoopItemCode(GameObject gameObject)
{
Path2WidgetCachedDict?.Clear();
Path2WidgetCachedDict = new Dictionary<string, List<Component>>();
FindAllWidgets(gameObject.transform, "");
SpawnCodeForScrollLoopItemBehaviour(gameObject);
SpawnCodeForScrollLoopItemViewSystem(gameObject);
AssetDatabase.Refresh();
}
static void SpawnCodeForScrollLoopItemViewSystem(GameObject gameObject)
{
if (null == gameObject)
{
return;
}
string strDlgName = gameObject.name;
string strFilePath = Application.dataPath + "/../Codes/HotfixView/Demo/UIItemBehaviour";
if ( !System.IO.Directory.Exists(strFilePath) )
{
System.IO.Directory.CreateDirectory(strFilePath);
}
strFilePath = Application.dataPath + "/../Codes/HotfixView/Demo/UIItemBehaviour/" + strDlgName + "ViewSystem.cs";
StreamWriter sw = new StreamWriter(strFilePath, false, Encoding.UTF8);
StringBuilder strBuilder = new StringBuilder();
strBuilder.AppendLine()
.AppendLine("using UnityEngine;");
strBuilder.AppendLine("using UnityEngine.UI;");
strBuilder.AppendLine("namespace ET");
strBuilder.AppendLine("{");
strBuilder.AppendLine("\t[ObjectSystem]");
strBuilder.AppendFormat("\tpublic class Scroll_{0}DestroySystem : DestroySystem<Scroll_{1}> \r\n", strDlgName, strDlgName);
strBuilder.AppendLine("\t{");
strBuilder.AppendFormat("\t\tpublic override void Destroy( Scroll_{0} self )",strDlgName);
strBuilder.AppendLine("\n\t\t{");
strBuilder.AppendFormat("\t\t\tself.DestroyWidget();\r\n");
strBuilder.AppendLine("\t\t}");
strBuilder.AppendLine("\t}");
strBuilder.AppendLine("}");
sw.Write(strBuilder);
sw.Flush();
sw.Close();
}
static void SpawnCodeForScrollLoopItemBehaviour(GameObject gameObject)
{
if (null == gameObject)
{
return;
}
string strDlgName = gameObject.name;
string strFilePath = Application.dataPath + "/../Codes/ModelView/Demo/UIItemBehaviour";
if ( !System.IO.Directory.Exists(strFilePath) )
{
System.IO.Directory.CreateDirectory(strFilePath);
}
strFilePath = Application.dataPath + "/../Codes/ModelView/Demo/UIItemBehaviour/" + strDlgName + ".cs";
StreamWriter sw = new StreamWriter(strFilePath, false, Encoding.UTF8);
StringBuilder strBuilder = new StringBuilder();
strBuilder.AppendLine()
.AppendLine("using UnityEngine;");
strBuilder.AppendLine("using UnityEngine.UI;");
strBuilder.AppendLine("namespace ET");
strBuilder.AppendLine("{");
strBuilder.AppendFormat("\tpublic class Scroll_{0} : Entity,IAwake,IDestroy,IUIScrollItem \r\n", strDlgName)
.AppendLine("\t{");
strBuilder.AppendLine("\t\tprivate bool isCacheNode = false;");
strBuilder.AppendLine("\t\tpublic void SetCacheMode(bool isCache)");
strBuilder.AppendLine("\t\t{");
strBuilder.AppendLine("\t\t\tthis.isCacheNode = isCache;");
strBuilder.AppendLine("\t\t}\n");
strBuilder.AppendFormat("\t\tpublic Scroll_{0} BindTrans(Transform trans)\r\n",strDlgName);
strBuilder.AppendLine("\t\t{");
strBuilder.AppendLine("\t\t\tthis.uiTransform = trans;");
strBuilder.AppendLine("\t\t\treturn this;");
strBuilder.AppendLine("\t\t}\n");
CreateWidgetBindCode(ref strBuilder, gameObject.transform);
CreateDestroyWidgetCode(ref strBuilder);
CreateDeclareCode(ref strBuilder);
strBuilder.AppendLine("\t\tpublic Transform uiTransform = null;");
strBuilder.AppendLine("\t}");
strBuilder.AppendLine("}");
sw.Write(strBuilder);
sw.Flush();
sw.Close();
}
}