初始化

This commit is contained in:
come
2025-07-26 16:56:42 +08:00
parent 8291dbb91c
commit fa81439a8c
2574 changed files with 328492 additions and 2170 deletions

View File

@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: b3ddfe80d5274d25869bbd0ad6bae9f9
timeCreated: 1752637115

View File

@@ -1,154 +0,0 @@
using System.Linq;
using UnityEditor;
using UnityEngine;
using CreatGame.UI;
using UnityEditorInternal;
using Unity.VisualScripting;
using System.Collections.Generic;
[CustomEditor(typeof(UIComponentExport))]
public class UIComponentExportEditor : Editor
{
private ReorderableList reorderableList;
private void InitReorderableList()
{
reorderableList = new ReorderableList(
serializedObject,
serializedObject.FindProperty("entries"),
true, true, true, true);
reorderableList.drawHeaderCallback = (Rect rect) => { EditorGUI.LabelField(rect, "UI Prefab Entries"); };
reorderableList.elementHeightCallback = (int index) => { return EditorGUIUtility.singleLineHeight + 6f; };
reorderableList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) =>
{
SerializedProperty element = reorderableList.serializedProperty.GetArrayElementAtIndex(index);
// drawElementCallback 中的内容
SerializedProperty keyProp = element.FindPropertyRelative("key");
SerializedProperty prefabProp = element.FindPropertyRelative("prefab");
SerializedProperty selectedNameProp = element.FindPropertyRelative("selectedComponentName");
GameObject prefab = prefabProp.objectReferenceValue as GameObject;
// 查找组件类型
List<string> uguiComponentNames = new List<string>();
if (prefab != null)
{
uguiComponentNames = prefab.GetComponents<Component>()
.Where(c => c != null && UIViewExportEditor.IsUGUIComponent(c))
.Select(c => c.GetType().Name)
.Distinct()
.ToList();
if (prefab.GetComponent<UISelectList>() != null)
{
uguiComponentNames.Add("UISelectList");
}
if (uguiComponentNames.Count == 0)
{
uguiComponentNames.Add("GameObject");
}
}
float lineHeight = EditorGUIUtility.singleLineHeight;
float padding = 4f;
float thirdWidth = (rect.width - 2 * padding) / 3f;
Rect keyRect = new Rect(rect.x, rect.y + 2, thirdWidth, lineHeight);
Rect prefabRect = new Rect(rect.x + thirdWidth + padding, rect.y + 2, thirdWidth, lineHeight);
Rect popupRect = new Rect(rect.x + 2 * (thirdWidth + padding), rect.y + 2, thirdWidth, lineHeight);
// key 字段
EditorGUI.PropertyField(keyRect, keyProp, GUIContent.none);
// prefab 字段
EditorGUI.PropertyField(prefabRect, prefabProp, GUIContent.none);
// 下拉框
if (uguiComponentNames.Count > 0)
{
int selectedIndex = Mathf.Max(0, uguiComponentNames.IndexOf(selectedNameProp.stringValue));
selectedIndex = EditorGUI.Popup(popupRect, selectedIndex, uguiComponentNames.ToArray());
selectedNameProp.stringValue = uguiComponentNames[selectedIndex];
}
else
{
EditorGUI.LabelField(popupRect, "无UGUI组件");
}
};
}
public override void OnInspectorGUI()
{
serializedObject.Update();
if (reorderableList == null)
{
InitReorderableList();
}
reorderableList?.DoLayoutList();
serializedObject.ApplyModifiedProperties();
if (GUILayout.Button("导出代码"))
{
ExportCode();
}
}
/// <summary>
/// 导出代码
/// </summary>
private void ExportCode()
{
string savePath = Application.dataPath + "/Scripts/GameLogic/Export/UGUI/";
if (string.IsNullOrEmpty(savePath))
return;
string className = $"UI{target.GameObject().name}";
string filename = System.IO.Path.Combine(savePath, $"{className}.cs");
var sb = new System.Text.StringBuilder();
sb.AppendLine("using UnityEngine;");
sb.AppendLine("using UnityEngine.UI;");
sb.AppendLine();
sb.AppendLine("namespace CreatGame.UI");
sb.AppendLine("{");
sb.AppendLine($" public partial class {className} : UIComponentBase");
sb.AppendLine(" {");
// sb.AppendLine($" public override string PrefabPath => \"Prefabs/UI/{target.GameObject().name}\";");
// 字段定义
for (int i = 0; i < reorderableList.count; i++)
{
SerializedProperty element = reorderableList.serializedProperty.GetArrayElementAtIndex(i);
sb.AppendLine(" /// <summary>");
sb.AppendLine(" /// ");
sb.AppendLine(" /// </summary>");
sb.AppendLine($" public {element.FindPropertyRelative("selectedComponentName").stringValue} {element.FindPropertyRelative("key").stringValue};");
}
sb.AppendLine(" public override void PreLoad(GameObject view)");
sb.AppendLine(" {");
sb.AppendLine(" base.PreLoad(view);");
sb.AppendLine();
for (int i = 0; i < reorderableList.count; i++)
{
SerializedProperty element = reorderableList.serializedProperty.GetArrayElementAtIndex(i);
var filedName = element.FindPropertyRelative("key").stringValue;
var typeName = element.FindPropertyRelative("selectedComponentName").stringValue;
sb.AppendLine($" {filedName} = m_ViewExport.GetGameObject(nameof({filedName})).GetComponent<{typeName}>();");
}
sb.AppendLine(" }");
sb.AppendLine(" }");
sb.AppendLine("}");
Debug.Log(sb.ToString());
System.IO.File.WriteAllText(filename, sb.ToString());
Debug.Log($"✅ 导出成功:{filename}");
AssetDatabase.Refresh();
}
}

View File

@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 75e425207f8b4c369bf1a58bd14d8cb4
timeCreated: 1752945208

View File

@@ -1,181 +0,0 @@
using System.Collections.Generic;
using System.Linq;
using CreatGame.UI;
using Unity.VisualScripting;
using UnityEditor;
using UnityEditorInternal;
using UnityEngine;
using UnityEngine.UI;
[CustomEditor(typeof(UIViewExport))]
public class UIViewExportEditor : Editor
{
private ReorderableList reorderableList;
private void OnEnable()
{
}
private void InitReorderableList()
{
reorderableList = new ReorderableList(
serializedObject,
serializedObject.FindProperty("entries"),
true, true, true, true);
reorderableList.drawHeaderCallback = (Rect rect) =>
{
EditorGUI.LabelField(rect, "UI Prefab Entries");
};
reorderableList.elementHeightCallback = (int index) =>
{
return EditorGUIUtility.singleLineHeight + 6f;
};
reorderableList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) =>
{
SerializedProperty element = reorderableList.serializedProperty.GetArrayElementAtIndex(index);
// drawElementCallback 中的内容
SerializedProperty keyProp = element.FindPropertyRelative("key");
SerializedProperty prefabProp = element.FindPropertyRelative("prefab");
SerializedProperty selectedNameProp = element.FindPropertyRelative("selectedComponentName");
GameObject prefab = prefabProp.objectReferenceValue as GameObject;
// 查找组件类型
List<string> uguiComponentNames = new List<string>();
if (prefab != null)
{
uguiComponentNames = prefab.GetComponents<Component>()
.Where(c => c != null && IsUGUIComponent(c))
.Select(c => c.GetType().Name)
.Distinct()
.ToList();
if (prefab.GetComponent<UISelectList>() != null)
{
uguiComponentNames.Add("UISelectList");
}
if (uguiComponentNames.Count == 0)
{
uguiComponentNames.Add("GameObject");
}
}
float lineHeight = EditorGUIUtility.singleLineHeight;
float padding = 4f;
float thirdWidth = (rect.width - 2 * padding) / 3f;
Rect keyRect = new Rect(rect.x, rect.y + 2, thirdWidth, lineHeight);
Rect prefabRect = new Rect(rect.x + thirdWidth + padding, rect.y + 2, thirdWidth, lineHeight);
Rect popupRect = new Rect(rect.x + 2 * (thirdWidth + padding), rect.y + 2, thirdWidth, lineHeight);
// key 字段
EditorGUI.PropertyField(keyRect, keyProp, GUIContent.none);
// prefab 字段
EditorGUI.PropertyField(prefabRect, prefabProp, GUIContent.none);
// 下拉框
if (uguiComponentNames.Count > 0)
{
int selectedIndex = Mathf.Max(0, uguiComponentNames.IndexOf(selectedNameProp.stringValue));
selectedIndex = EditorGUI.Popup(popupRect, selectedIndex, uguiComponentNames.ToArray());
selectedNameProp.stringValue = uguiComponentNames[selectedIndex];
}
else
{
EditorGUI.LabelField(popupRect, "无UGUI组件");
}
};
}
public override void OnInspectorGUI()
{
serializedObject.Update();
if (reorderableList == null)
{
InitReorderableList();
}
reorderableList?.DoLayoutList();
serializedObject.ApplyModifiedProperties();
if (GUILayout.Button("导出代码"))
{
ExportCode();
}
}
/// <summary>
/// 判断是否是常见UGUI组件你可以自行扩展
/// </summary>
public static bool IsUGUIComponent(Component component)
{
return component is Graphic // 基类,包含 Image、Text、RawImage
|| component is Button
|| component is Toggle
|| component is Slider
|| component is ScrollRect
|| component is Dropdown
|| component is InputField
|| component is UILoopList;
}
/// <summary>
/// 导出代码
/// </summary>
private void ExportCode()
{
string savePath = Application.dataPath + "/Scripts/GameLogic/Export/UGUI/";
if (string.IsNullOrEmpty(savePath))
return;
string className = $"UI{target.GameObject().name}";
string filename = System.IO.Path.Combine(savePath, $"{className}.cs");
var sb = new System.Text.StringBuilder();
sb.AppendLine("using UnityEngine;");
sb.AppendLine("using UnityEngine.UI;");
sb.AppendLine();
sb.AppendLine("namespace CreatGame.UI");
sb.AppendLine("{");
sb.AppendLine($" public partial class {className} : UIViewBase");
sb.AppendLine(" {");
sb.AppendLine($" public override string PrefabPath => \"Prefabs/UI/{target.GameObject().name}\";");
// 字段定义
for (int i = 0; i < reorderableList.count; i++)
{
SerializedProperty element = reorderableList.serializedProperty.GetArrayElementAtIndex(i);
sb.AppendLine(" /// <summary>");
sb.AppendLine(" /// ");
sb.AppendLine(" /// </summary>");
sb.AppendLine($" public {element.FindPropertyRelative("selectedComponentName").stringValue} {element.FindPropertyRelative("key").stringValue};");
}
sb.AppendLine(" public override void PreLoad(GameObject view)");
sb.AppendLine(" {");
sb.AppendLine(" base.PreLoad(view);");
sb.AppendLine();
for (int i = 0; i < reorderableList.count; i++)
{
SerializedProperty element = reorderableList.serializedProperty.GetArrayElementAtIndex(i);
var filedName = element.FindPropertyRelative("key").stringValue;
var typeName = element.FindPropertyRelative("selectedComponentName").stringValue;
sb.AppendLine($" {filedName} = m_ViewExport.GetGameObject(nameof({filedName})).GetComponent<{typeName}>();");
}
sb.AppendLine(" }");
sb.AppendLine(" }");
sb.AppendLine("}");
Debug.Log(sb.ToString());
System.IO.File.WriteAllText(filename, sb.ToString());
Debug.Log($"✅ 导出成功:{filename}");
AssetDatabase.Refresh();
}
}

View File

@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 7580782f3f2c4729bb6f9c136708540c
timeCreated: 1752637136

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 2b32b7b6f992de44fbd9f12565e6176d
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,39 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 2f0b0c553be8edd4682e9180fdd13e37, type: 3}
m_Name: I2Languages
m_EditorClassIdentifier:
mSource:
UserAgreesToHaveItOnTheScene: 0
UserAgreesToHaveItInsideThePluginsFolder: 0
GoogleLiveSyncIsUptoDate: 1
mTerms: []
CaseInsensitiveTerms: 0
OnMissingTranslation: 1
mTerm_AppName:
mLanguages: []
IgnoreDeviceLanguage: 0
_AllowUnloadingLanguages: 0
Google_WebServiceURL:
Google_SpreadsheetKey:
Google_SpreadsheetName:
Google_LastUpdatedVersion:
Google_Password: change_this
GoogleUpdateFrequency: 3
GoogleInEditorCheckFrequency: 2
GoogleUpdateSynchronization: 1
GoogleUpdateDelay: 0
Assets: []
Spreadsheet_LocalFileName:
Spreadsheet_LocalCSVSeparator: ','
Spreadsheet_LocalCSVEncoding: utf-8
Spreadsheet_SpecializationAsRows: 1

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: cac0d3bc373cde948b3f5412ed44a32d
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant: