This commit is contained in:
2025-09-24 17:16:12 +08:00
parent 5e7c399e4d
commit f9575180f3
2 changed files with 21 additions and 12 deletions

View File

@@ -51,6 +51,7 @@ public class UICreateWindow : EditorWindow
private string _uiViewTemplate = "UIViewTemplate"; private string _uiViewTemplate = "UIViewTemplate";
private string _uiConfig = "UIConfig"; private string _uiConfig = "UIConfig";
private string _uiName; private string _uiName;
private string _saveUIPath;
public GameObject uiPrefab; public GameObject uiPrefab;
private Dictionary<string, string> _uiNames = new Dictionary<string, string>(); private Dictionary<string, string> _uiNames = new Dictionary<string, string>();
private Dictionary<string, UIConfigJson> _uiJsonDatas = new Dictionary<string, UIConfigJson>(); private Dictionary<string, UIConfigJson> _uiJsonDatas = new Dictionary<string, UIConfigJson>();
@@ -77,6 +78,7 @@ public class UICreateWindow : EditorWindow
_uiJsonDatas.Clear(); _uiJsonDatas.Clear();
_uiNames.Clear(); _uiNames.Clear();
uiViews = ReflectionHelper.GetAllUIViewTypes(_domainNames[_domainIndex]); uiViews = ReflectionHelper.GetAllUIViewTypes(_domainNames[_domainIndex]);
_saveUIPath = EditorPrefs.GetString(nameof(_saveUIPath));
DomainPathField(); DomainPathField();
foreach (var uiView in uiViews) foreach (var uiView in uiViews)
{ {
@@ -89,6 +91,7 @@ public class UICreateWindow : EditorWindow
_uiNames.AddOrUpdate(str, scriptPath); _uiNames.AddOrUpdate(str, scriptPath);
} }
} }
private void OnGUI() private void OnGUI()
{ {
EditorGUILayout.LabelField("通过[Evo/UI管理]可以打开"); EditorGUILayout.LabelField("通过[Evo/UI管理]可以打开");
@@ -106,12 +109,13 @@ public class UICreateWindow : EditorWindow
{ {
_scroll2 = EditorGUILayout.BeginScrollView(_scroll2, "box", GUILayout.Width(position.width * 0.4f - 6)); _scroll2 = EditorGUILayout.BeginScrollView(_scroll2, "box", GUILayout.Width(position.width * 0.4f - 6));
{ {
var tempIndex =EditorGUILayout.Popup("Domain", _domainIndex, _domainNames); var tempIndex = EditorGUILayout.Popup("Domain", _domainIndex, _domainNames);
if (tempIndex != _domainIndex) if (tempIndex != _domainIndex)
{ {
ValueChang(); ValueChang();
_domainIndex = tempIndex; _domainIndex = tempIndex;
} }
EditorGUILayout.HelpBox("已创建的UI", MessageType.Info); EditorGUILayout.HelpBox("已创建的UI", MessageType.Info);
_mInput = EditorGUILayout.TextField(_mInput, EditorStyles.toolbarSearchField, GUILayout.Height(20)); _mInput = EditorGUILayout.TextField(_mInput, EditorStyles.toolbarSearchField, GUILayout.Height(20));
@@ -127,6 +131,7 @@ public class UICreateWindow : EditorWindow
{ {
jsonData = new UIConfigJson(); jsonData = new UIConfigJson();
} }
if (string.IsNullOrEmpty(scriptPath)) continue; if (string.IsNullOrEmpty(scriptPath)) continue;
var defaultColor = GUI.color; var defaultColor = GUI.color;
@@ -160,16 +165,21 @@ public class UICreateWindow : EditorWindow
var uiScriptPath = GetUIScript(_uiName); var uiScriptPath = GetUIScript(_uiName);
if (string.IsNullOrEmpty(uiScriptPath)) if (string.IsNullOrEmpty(uiScriptPath))
{ {
var saveUIPath= $"Assets/Domain/{_domainNames[_domainIndex]}/Scripts/UI"; if (string.IsNullOrEmpty(_saveUIPath))
if (GUILayout.Button($"选择创建路径:{saveUIPath}"))
{ {
var newPath = EditorUtility.OpenFolderPanel("UI生成路径", saveUIPath, ""); _saveUIPath = $"Assets/Domain/{_domainNames[_domainIndex]}/HotUpdate/UI";
saveUIPath = newPath.Replace(Application.dataPath, "Assets"); }
if (GUILayout.Button($"选择创建路径:{_saveUIPath}"))
{
var newPath = EditorUtility.OpenFolderPanel("UI生成路径", _saveUIPath, "");
_saveUIPath = newPath.Replace(Application.dataPath, "Assets");
EditorPrefs.SetString(nameof(_saveUIPath), _saveUIPath);
} }
if (uiPrefab != null) if (uiPrefab != null)
{ {
EditorGUILayout.TextField("UI生成路径", $"{saveUIPath}/{_uiName}.cs"); EditorGUILayout.TextField("UI生成路径", $"{_saveUIPath}/{_uiName}.cs");
} }
_isWindow = EditorGUILayout.Toggle("是否为窗口", _isWindow); _isWindow = EditorGUILayout.Toggle("是否为窗口", _isWindow);
@@ -189,7 +199,7 @@ public class UICreateWindow : EditorWindow
str = Regex.Replace(str, "//UIControlData", str = Regex.Replace(str, "//UIControlData",
uiControlData != null ? UnityEngine.GUIUtility.systemCopyBuffer : ""); uiControlData != null ? UnityEngine.GUIUtility.systemCopyBuffer : "");
string newPath = $"{saveUIPath}/{_uiName}.cs"; string newPath = $"{_saveUIPath}/{_uiName}.cs";
File.WriteAllText(newPath, str); File.WriteAllText(newPath, str);
var jsonData = new UIConfigJson var jsonData = new UIConfigJson
@@ -227,6 +237,7 @@ public class UICreateWindow : EditorWindow
jsonData.uiType = _uiName; jsonData.uiType = _uiName;
_uiJsonDatas.AddOrUpdate(_uiName, jsonData); _uiJsonDatas.AddOrUpdate(_uiName, jsonData);
} }
if (UnityEditor.PrefabUtility.IsPartOfPrefabAsset(uiPrefab)) if (UnityEditor.PrefabUtility.IsPartOfPrefabAsset(uiPrefab))
{ {
// 预制体资源就是自身 // 预制体资源就是自身
@@ -335,7 +346,7 @@ public class UICreateWindow : EditorWindow
return string.Empty; return string.Empty;
} }
// if (GetUIJson(name) == null) return string.Empty; // if (GetUIJson(name) == null) return string.Empty;
string[] ids = AssetDatabase.FindAssets(name); string[] ids = AssetDatabase.FindAssets(name);
if (ids != null) if (ids != null)
@@ -438,6 +449,7 @@ static class ReflectionHelper
Debug.LogError($"未找到名为HotUpdate_{domainName}的程序集"); Debug.LogError($"未找到名为HotUpdate_{domainName}的程序集");
return null; return null;
} }
try try
{ {
result.AddRange(targetAssembly.GetTypes() result.AddRange(targetAssembly.GetTypes()
@@ -465,7 +477,4 @@ static class ReflectionHelper
return result; return result;
} }
} }

View File

@@ -1,7 +1,7 @@
{ {
"name": "com.staryevo.uifarme", "name": "com.staryevo.uifarme",
"displayName": "06.UIFarme", "displayName": "06.UIFarme",
"version": "2.0.3", "version": "2.0.4",
"description": "UI框架工具", "description": "UI框架工具",
"unity": "2021.3", "unity": "2021.3",
"unityRelease": "30f1", "unityRelease": "30f1",