Compare commits
2 Commits
548e1bccbb
...
cbd3ba86b8
Author | SHA1 | Date |
---|---|---|
|
cbd3ba86b8 | |
|
80c1178b95 |
|
@ -0,0 +1,10 @@
|
|||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ZC
|
||||
{
|
||||
[Procedure(ProcedureType.#CLASSNAME#)]
|
||||
class #CLASSNAME# : ProcedureBase
|
||||
{
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 91e9b42addbc4e5ea673fb5d36a7a685
|
||||
timeCreated: 1732263928
|
|
@ -0,0 +1,35 @@
|
|||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
|
||||
namespace ZC
|
||||
{
|
||||
[UIType(UIType.#CLASSNAME#)]
|
||||
public class #CLASSNAME# : UIBase
|
||||
{
|
||||
#VARIABLEDEFINITION#
|
||||
public override void OnInit()
|
||||
{
|
||||
base.OnInit();
|
||||
#region AutoGen_Init
|
||||
|
||||
#INITFIND#
|
||||
#INITADDLISTENER#
|
||||
#endregion
|
||||
}
|
||||
|
||||
#region AutoGen_Method
|
||||
|
||||
#METHOD#
|
||||
#endregion
|
||||
|
||||
public override void OnDispose()
|
||||
{
|
||||
base.OnDispose();
|
||||
#region AutoGen_Dispose
|
||||
|
||||
#DISPOSE#
|
||||
#DISPOSEISNULL#
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0885d93c09f04445a5cd95b6c9f7c1a0
|
||||
timeCreated: 1732263033
|
|
@ -0,0 +1,54 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using Sirenix.OdinInspector;
|
||||
using Sirenix.OdinInspector.Editor;
|
||||
using TMPro;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using ZC;
|
||||
|
||||
namespace ZEditor
|
||||
{
|
||||
public class GenProcedureEditor : OdinEditorWindow
|
||||
{
|
||||
public string logicFolderPath = $"{Application.dataPath}/DemoGame/GameScript/Hotfix/Procedure/Logic";
|
||||
public string templatePath = $"{Application.dataPath}/DemoGame/GameRes/ProcedureLogicTemplate.txt";
|
||||
|
||||
public string className;
|
||||
|
||||
[MenuItem("Tool/ProcedureTool")]
|
||||
public static void OpenWin()
|
||||
{
|
||||
GetWindow<GenProcedureEditor>().Show();
|
||||
}
|
||||
|
||||
[Button("创建")]
|
||||
void Gen()
|
||||
{
|
||||
if (string.IsNullOrEmpty(className))
|
||||
{
|
||||
Debug.LogError($"{className} is null !!! ");
|
||||
return;
|
||||
}
|
||||
|
||||
var tmpName = $"{this.className}Procedure";
|
||||
string filePath = $"{logicFolderPath}/{tmpName}.cs";
|
||||
string allText;
|
||||
if (!File.Exists(filePath))
|
||||
{
|
||||
File.Create(filePath).Dispose();
|
||||
allText = File.ReadAllText(templatePath);
|
||||
allText = allText.Replace("#CLASSNAME#", tmpName);
|
||||
File.WriteAllText(filePath, allText);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"重复!已存在{tmpName}.cs文件!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6fb1eb88d4e040b7bb68dc16235c1e7b
|
||||
timeCreated: 1732263264
|
|
@ -0,0 +1,248 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using TMPro;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using ZC;
|
||||
|
||||
namespace ZEditor
|
||||
{
|
||||
public class GenUIDataEditor : Editor
|
||||
{
|
||||
private static string logicFolderPath = $"{Application.dataPath}/DemoGame/GameScript/Hotfix/UI/Logic";
|
||||
private static string templatePath = $"{Application.dataPath}/DemoGame/GameRes/UILogicTemplate.txt";
|
||||
|
||||
[MenuItem("GameObject/ZTool/UITool/自动绑定数据")]
|
||||
public static void AutoBindData()
|
||||
{
|
||||
foreach (var go in Selection.gameObjects)
|
||||
{
|
||||
List<Transform> list = new List<Transform>();
|
||||
FindUI(go.transform, ref list);
|
||||
|
||||
var binding = go.GetComponent<GameObjectBinding>();
|
||||
foreach (var transform in list)
|
||||
{
|
||||
binding.AddValue(transform);
|
||||
}
|
||||
|
||||
EditorUtility.SetDirty(go);
|
||||
Debug.Log("自动绑定数据 完成");
|
||||
}
|
||||
}
|
||||
|
||||
[MenuItem("GameObject/ZTool/UITool/清空并自动绑定数据")]
|
||||
public static void ClearAndAutoBindData()
|
||||
{
|
||||
foreach (var go in Selection.gameObjects)
|
||||
{
|
||||
List<Transform> list = new List<Transform>();
|
||||
FindUI(go.transform, ref list);
|
||||
|
||||
var binding = go.GetComponent<GameObjectBinding>();
|
||||
binding.ClearValue();
|
||||
foreach (var transform in list)
|
||||
{
|
||||
binding.AddValue(transform);
|
||||
}
|
||||
|
||||
EditorUtility.SetDirty(go);
|
||||
Debug.Log("清空并自动绑定数据 完成");
|
||||
}
|
||||
}
|
||||
|
||||
static void FindUI(Transform go, ref List<Transform> list)
|
||||
{
|
||||
if (go.name.Contains("txt_") ||
|
||||
go.name.Contains("btn_") ||
|
||||
go.name.Contains("tog_") ||
|
||||
go.name.Contains("img_") ||
|
||||
go.name.Contains("inp_") ||
|
||||
go.name.Contains("panel_") ||
|
||||
go.name.Contains("sli_"))
|
||||
{
|
||||
list.Add(go);
|
||||
}
|
||||
|
||||
for (var i = 0; i < go.childCount; i++)
|
||||
{
|
||||
FindUI(go.GetChild(i), ref list);
|
||||
}
|
||||
}
|
||||
|
||||
[MenuItem("GameObject/ZTool/UITool/自动生成绑定数据")]
|
||||
public static void FindClassAndGenBindData()
|
||||
{
|
||||
// var go = Selection.activeObject as GameObject;
|
||||
foreach (var go in Selection.gameObjects)
|
||||
{
|
||||
var binding = go.GetComponent<GameObjectBinding>();
|
||||
var substring = go.name.Replace("UI", "");
|
||||
Debug.Log(substring);
|
||||
substring = $"{substring}UI";
|
||||
|
||||
string filePath = $"{logicFolderPath}/{substring}.cs";
|
||||
string allText;
|
||||
if (!File.Exists(filePath))
|
||||
{
|
||||
File.Create(filePath).Dispose();
|
||||
allText = File.ReadAllText(templatePath);
|
||||
}
|
||||
else
|
||||
{
|
||||
allText = File.ReadAllText(filePath);
|
||||
}
|
||||
|
||||
allText = allText.Replace("#CLASSNAME#", substring);
|
||||
|
||||
allText = allText.Replace("#VARIABLEDEFINITION#", ReplaceVD(binding.AllData));
|
||||
allText = allText.Replace("#INITFIND#", ReplaceInitBind(binding.AllData));
|
||||
allText = allText.Replace("#INITADDLISTENER#", ReplaceInitAddListener(binding.AllData));
|
||||
allText = allText.Replace("#METHOD#", ReplaceAddMethod(binding.AllData));
|
||||
allText = allText.Replace("#DISPOSE#", ReplaceDisposeRemoveListener(binding.AllData));
|
||||
allText = allText.Replace("#DISPOSEISNULL#", ReplaceDisposeIsNull(binding.AllData));
|
||||
|
||||
File.WriteAllText(filePath, allText);
|
||||
Debug.Log("自动生成绑定数据 完成");
|
||||
}
|
||||
}
|
||||
|
||||
static string ReplaceVD(IReadOnlyList<GameObjectBindingData> AllData) // 定义
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach (var data in AllData)
|
||||
{
|
||||
var typeStr = CheckType(data);
|
||||
sb.AppendLine($"public {typeStr} {data.name};");
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
static string ReplaceInitBind(IReadOnlyList<GameObjectBindingData> AllData) // 定义
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach (var data in AllData)
|
||||
{
|
||||
var typeStr = CheckType(data);
|
||||
sb.AppendLine($"{data.name} = GetValue<{typeStr}>(\"{data.name}\");");
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
static string ReplaceInitAddListener(IReadOnlyList<GameObjectBindingData> AllData) // 定义
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach (var data in AllData)
|
||||
{
|
||||
var typeStr = CheckType(data);
|
||||
if (typeStr == nameof(Button))
|
||||
{
|
||||
sb.AppendLine($"{data.name}.onClick.AddListener(OnClick{data.name});");
|
||||
}
|
||||
else if (typeStr == nameof(Slider) || typeStr == nameof(Toggle))
|
||||
{
|
||||
sb.AppendLine($"{data.name}.onValueChanged.AddListener(OnValueChanged{data.name});");
|
||||
}
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
static string ReplaceAddMethod(IReadOnlyList<GameObjectBindingData> AllData) // 定义
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach (var data in AllData)
|
||||
{
|
||||
var typeStr = CheckType(data);
|
||||
if (typeStr == nameof(Button))
|
||||
{
|
||||
sb.AppendLine($"private void OnClick{data.name}() {{}}");
|
||||
}
|
||||
else if (typeStr == nameof(Slider))
|
||||
{
|
||||
sb.AppendLine($"private void OnValueChanged{data.name}(float f) {{}}");
|
||||
}
|
||||
else if (typeStr == nameof(Toggle))
|
||||
{
|
||||
sb.AppendLine($"private void OnValueChanged{data.name}(bool b) {{}}");
|
||||
}
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
static string ReplaceDisposeRemoveListener(IReadOnlyList<GameObjectBindingData> AllData) // 定义
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach (var data in AllData)
|
||||
{
|
||||
var typeStr = CheckType(data);
|
||||
if (typeStr == nameof(Button))
|
||||
{
|
||||
sb.AppendLine($"{data.name}.onClick.RemoveListener(OnClick{data.name});");
|
||||
}
|
||||
else if (typeStr == nameof(Slider) || typeStr == nameof(Toggle))
|
||||
{
|
||||
sb.AppendLine($"{data.name}.onValueChanged.RemoveListener(OnValueChanged{data.name});");
|
||||
}
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
static string ReplaceDisposeIsNull(IReadOnlyList<GameObjectBindingData> AllData) // 定义
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach (var data in AllData)
|
||||
{
|
||||
var typeStr = CheckType(data);
|
||||
sb.AppendLine($"{data.name} = null;");
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
static string CheckType(GameObjectBindingData data)
|
||||
{
|
||||
if (data.go.TryGetComponent(out Button button))
|
||||
{
|
||||
return nameof(Button);
|
||||
}
|
||||
else if (data.go.TryGetComponent(out TMP_InputField inputField_TMP))
|
||||
{
|
||||
return nameof(TMP_InputField);
|
||||
}
|
||||
else if (data.go.TryGetComponent(out InputField inputField))
|
||||
{
|
||||
return nameof(InputField);
|
||||
}
|
||||
else if (data.go.TryGetComponent(out Slider slider))
|
||||
{
|
||||
return nameof(Slider);
|
||||
}
|
||||
else if (data.go.TryGetComponent(out Toggle toggle))
|
||||
{
|
||||
return nameof(Toggle);
|
||||
}
|
||||
else if (data.go.TryGetComponent(out TMP_Text tmpText))
|
||||
{
|
||||
return nameof(TMP_Text);
|
||||
}
|
||||
else if (data.go.TryGetComponent(out Text text))
|
||||
{
|
||||
return nameof(Text);
|
||||
}
|
||||
else if (data.go.TryGetComponent(out Image image))
|
||||
{
|
||||
return nameof(Image);
|
||||
}
|
||||
|
||||
return String.Empty;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 35f6268f26ad42dd9f6bd467f06e0829
|
||||
timeCreated: 1732263042
|
|
@ -3,7 +3,7 @@
|
|||
namespace ZC
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
class ProcedureAttribute: Attribute
|
||||
public class ProcedureAttribute: Attribute
|
||||
{
|
||||
public ProcedureType ProcedureType { get; set; }
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ using UnityEngine;
|
|||
|
||||
namespace ZC
|
||||
{
|
||||
abstract class ProcedureBase : IProcedure
|
||||
public abstract class ProcedureBase : IProcedure
|
||||
{
|
||||
private ProcedureType _procedureType;
|
||||
|
||||
|
|
|
@ -9,6 +9,28 @@ namespace ZC
|
|||
{
|
||||
[SerializeField] private List<GameObjectBindingData> Datas = new List<GameObjectBindingData>();
|
||||
|
||||
#if UNITY_EDITOR
|
||||
public IReadOnlyList<GameObjectBindingData> AllData => Datas;
|
||||
|
||||
public void ClearValue()
|
||||
{
|
||||
Datas.Clear();
|
||||
}
|
||||
|
||||
public void AddValue(Transform trans)
|
||||
{
|
||||
foreach (var data in Datas)
|
||||
{
|
||||
if (data.name == trans.name)
|
||||
{
|
||||
throw new ArgumentException($"重复添加了, {trans.name}");
|
||||
}
|
||||
}
|
||||
|
||||
Datas.Add(new GameObjectBindingData() { name = trans.name, go = trans.gameObject });
|
||||
}
|
||||
#endif
|
||||
|
||||
public GameObject GetValue(string nameStr)
|
||||
{
|
||||
foreach (var data in Datas)
|
||||
|
@ -21,7 +43,8 @@ namespace ZC
|
|||
|
||||
throw new NullReferenceException($"没有找到绑定这个名字的物体,name:{nameStr}");
|
||||
}
|
||||
public T GetValue<T>(string nameStr)where T: Component
|
||||
|
||||
public T GetValue<T>(string nameStr) where T : Component
|
||||
{
|
||||
foreach (var data in Datas)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue