diff --git a/QFramework.Unity2018+/Assets/QFramework/Framework/PackageVersion.json b/QFramework.Unity2018+/Assets/QFramework/Framework/PackageVersion.json index 1e22064f7..f14dbed4c 100755 --- a/QFramework.Unity2018+/Assets/QFramework/Framework/PackageVersion.json +++ b/QFramework.Unity2018+/Assets/QFramework/Framework/PackageVersion.json @@ -1,6 +1,6 @@ { "Id": "", - "Version": "v1.0.129", + "Version": "v1.0.131", "Type": 0, "AccessRight": 0, "DownloadUrl": "", @@ -11,10 +11,10 @@ ], "DocUrl": "https://liangxiegame.com", "Readme": { - "version": "v1.0.129", - "content": "FluentAPI: 增加 ToAngle 和 AngleToDirection2D", + "version": "v1.0.131", + "content": "补充文档", "author": "liangxie", - "date": "2024 年 05 月 08 日 16:11", + "date": "2024 年 05 月 08 日 16:34", "PackageId": "" } } \ No newline at end of file diff --git a/QFramework.Unity2018+/Assets/QFramework/Toolkits/_CoreKit/CodeGenKit/Editor/CodeGenKitPipeline.cs b/QFramework.Unity2018+/Assets/QFramework/Toolkits/_CoreKit/CodeGenKit/Editor/CodeGenKitPipeline.cs index af43353eb..71ceced40 100755 --- a/QFramework.Unity2018+/Assets/QFramework/Toolkits/_CoreKit/CodeGenKit/Editor/CodeGenKitPipeline.cs +++ b/QFramework.Unity2018+/Assets/QFramework/Toolkits/_CoreKit/CodeGenKit/Editor/CodeGenKitPipeline.cs @@ -68,6 +68,7 @@ public void Generate(CodeGenTask task) CurrentTask.Status = CodeGenTaskStatus.Search; BindSearchHelper.Search(task); CurrentTask.Status = CodeGenTaskStatus.Gen; + var viewController = task.GameObject.GetComponent(); var writer = new StringBuilder(); writer.AppendLine("using UnityEngine;"); @@ -83,8 +84,15 @@ public void Generate(CodeGenTask task) writer.AppendLine( $"namespace {((string.IsNullOrWhiteSpace(task.Namespace)) ? CodeGenKit.Setting.Namespace : task.Namespace)}"); writer.AppendLine("{"); - writer.AppendLine($"\tpublic partial class {task.ClassName} : ViewController"); - writer.AppendLine("\t{"); + if (viewController.ViewControllerFullTypeName.IsNotNullAndEmpty()) + { + writer.AppendLine( + $"\tpublic partial class {task.ClassName} : {viewController.ViewControllerFullTypeName}"); + } + else + { + writer.AppendLine($"\tpublic partial class {task.ClassName} : ViewController"); + } writer.AppendLine("\t{"); writer.AppendLine("\t\tvoid Start()"); writer.AppendLine("\t\t{"); writer.AppendLine("\t\t\t// Code Here"); @@ -108,7 +116,6 @@ public void Generate(CodeGenTask task) writer.AppendLine( $"namespace {(string.IsNullOrWhiteSpace(task.Namespace) ? CodeGenKit.Setting.Namespace : task.Namespace)}"); writer.AppendLine("{"); - var viewController = task.GameObject.GetComponent(); if (viewController.ArchitectureFullTypeName.IsNotNullAndEmpty()) { writer.AppendLine($"\tpublic partial class {task.ClassName} : QFramework.IController"); diff --git a/QFramework.Unity2018+/Assets/QFramework/Toolkits/_CoreKit/CodeGenKit/Editor/ViewControllerInspector.cs b/QFramework.Unity2018+/Assets/QFramework/Toolkits/_CoreKit/CodeGenKit/Editor/ViewControllerInspector.cs index ffc69cd7f..e31b13122 100755 --- a/QFramework.Unity2018+/Assets/QFramework/Toolkits/_CoreKit/CodeGenKit/Editor/ViewControllerInspector.cs +++ b/QFramework.Unity2018+/Assets/QFramework/Toolkits/_CoreKit/CodeGenKit/Editor/ViewControllerInspector.cs @@ -1,6 +1,6 @@ /**************************************************************************** * Copyright (c) 2017 xiaojun - * Copyright (c) 2015 ~ 2022 liangxiegame UNDER MIT LICENSE + * Copyright (c) 2015 ~ 2024 liangxiegame UNDER MIT LICENSE * * https://qframework.cn * https://github.com/liangxiegame/QFramework @@ -100,6 +100,9 @@ private void OnEnable() mArchitectureTypes = SearchAllArchitectureTypes(); mArchitectureTypeMenus = mArchitectureTypes.Select(t => t.FullName).Append("None").ToArray(); + mViewControllerTypes = SearchAllViewControllerTypes(); + mViewControllerTypeMenus = mViewControllerTypes.Select(t => t.FullName).Append("QFramework.ViewController").ToArray(); + } private static Type[] SearchAllArchitectureTypes() @@ -110,9 +113,21 @@ private static Type[] SearchAllArchitectureTypes() .SelectMany(a => a.GetTypes()) .Where(type => !type.IsAbstract && architectureType.IsAssignableFrom(type)).ToArray(); } + + private static Type[] SearchAllViewControllerTypes() + { + var viewControllerType = typeof(ViewController); + + return AppDomain.CurrentDomain.GetAssemblies().Where(a => + !a.FullName.Contains("UnityEngine")) + .SelectMany(a => a.GetTypes()) + .Where(type => type.GetAttribute() != null && viewControllerType.IsAssignableFrom(type)).ToArray(); + } private Type[] mArchitectureTypes; + private Type[] mViewControllerTypes; private string[] mArchitectureTypeMenus; + private string[] mViewControllerTypeMenus; private readonly ViewControllerInspectorStyle mStyle = new ViewControllerInspectorStyle(); @@ -151,7 +166,33 @@ public override void OnInspectorGUI() } GUILayout.EndHorizontal(); } + if (mViewControllerTypes.Length > 0) + { + var index = Array.FindIndex(mViewControllerTypes, + (t) => t.FullName == ViewController.ViewControllerFullTypeName); + if (index == -1) + { + index = mViewControllerTypeMenus.Length - 1; + } + + GUILayout.BeginHorizontal(); + GUILayout.Label(mLocaleText.ViewControllerType, GUILayout.Width(150)); + EditorGUI.BeginChangeCheck(); + index = EditorGUILayout.Popup(index, mViewControllerTypeMenus); + if (EditorGUI.EndChangeCheck()) + { + if (index == mViewControllerTypeMenus.Length - 1) + { + ViewController.ViewControllerFullTypeName = string.Empty; + } + else + { + ViewController.ViewControllerFullTypeName = mViewControllerTypes[index].FullName; + } + } + GUILayout.EndHorizontal(); + } GUILayout.BeginHorizontal(); GUILayout.Label(mLocaleText.Namespace, GUILayout.Width(150)); diff --git a/QFramework.Unity2018+/Assets/QFramework/Toolkits/_CoreKit/CodeGenKit/Editor/ViewControllerInspectorLocale.cs b/QFramework.Unity2018+/Assets/QFramework/Toolkits/_CoreKit/CodeGenKit/Editor/ViewControllerInspectorLocale.cs index b24b4e348..8807d484c 100755 --- a/QFramework.Unity2018+/Assets/QFramework/Toolkits/_CoreKit/CodeGenKit/Editor/ViewControllerInspectorLocale.cs +++ b/QFramework.Unity2018+/Assets/QFramework/Toolkits/_CoreKit/CodeGenKit/Editor/ViewControllerInspectorLocale.cs @@ -19,6 +19,7 @@ public bool CN public string CodegenPart => CN ? " 代码生成设置" : " Code Generate Setting"; public string ArchitectureType => CN ? "架构:" : "Architecture :"; + public string ViewControllerType => CN ? "继承:" : "Inherit :"; public string Namespace => CN ? "命名空间:" : "Namespace :"; public string ScriptName => CN ? "生成脚本名:" : "Script name:"; public string ScriptsFolder => CN ? "脚本生成目录:" : "Scripts Generate Folder:"; diff --git a/QFramework.Unity2018+/Assets/QFramework/Toolkits/_CoreKit/CodeGenKit/Scripts/Components/Bind/AbstractBind.cs b/QFramework.Unity2018+/Assets/QFramework/Toolkits/_CoreKit/CodeGenKit/Scripts/Components/Bind/AbstractBind.cs index 854ac6dc5..5f59b518c 100755 --- a/QFramework.Unity2018+/Assets/QFramework/Toolkits/_CoreKit/CodeGenKit/Scripts/Components/Bind/AbstractBind.cs +++ b/QFramework.Unity2018+/Assets/QFramework/Toolkits/_CoreKit/CodeGenKit/Scripts/Components/Bind/AbstractBind.cs @@ -6,6 +6,7 @@ * https://gitee.com/liangxiegame/QFramework ****************************************************************************/ +using System.Linq; using UnityEngine; using UnityEngine.UI; @@ -41,6 +42,10 @@ public virtual string TypeName { mComponentName = GetDefaultComponentName(); } + else if (!GetComponent(mComponentName) && !GetComponent(mComponentName.Split('.').Last())) + { + mComponentName = GetDefaultComponentName(); + } return mComponentName; } diff --git a/QFramework.Unity2018+/Assets/QFramework/Toolkits/_CoreKit/CodeGenKit/Scripts/Components/ViewController.cs b/QFramework.Unity2018+/Assets/QFramework/Toolkits/_CoreKit/CodeGenKit/Scripts/Components/ViewController.cs index fb66ab376..6fcb010f4 100755 --- a/QFramework.Unity2018+/Assets/QFramework/Toolkits/_CoreKit/CodeGenKit/Scripts/Components/ViewController.cs +++ b/QFramework.Unity2018+/Assets/QFramework/Toolkits/_CoreKit/CodeGenKit/Scripts/Components/ViewController.cs @@ -1,6 +1,6 @@ /**************************************************************************** * Copyright (c) 2017 xiaojun - * Copyright (c) 2015 ~ 2023 liangxiegame UNDER MIT LICENSE + * Copyright (c) 2015 ~ 2024 liangxiegame UNDER MIT LICENSE * * https://qframework.cn * https://github.com/liangxiegame/QFramework @@ -8,6 +8,7 @@ ****************************************************************************/ +using System; using UnityEngine; namespace QFramework @@ -25,7 +26,13 @@ public class ViewController : MonoBehaviour, IBindGroup [HideInInspector] public string PrefabFolder = string.Empty; [HideInInspector] public string ArchitectureFullTypeName = string.Empty; + + [HideInInspector] public string ViewControllerFullTypeName = string.Empty; public string TemplateName => nameof(ViewController); } + + public class ViewControllerChildAttribute : Attribute + { + } } \ No newline at end of file diff --git "a/QFramework.Unity2018+/Assets/QFramework/Toolkits/_CoreKit/Internal/Guidline/Editor/Resources/EditorGuideline/3. \345\267\245\345\205\267\347\257\207\357\274\232QFramework.Toolkits/03. CodeGenKit \350\204\232\346\234\254\347\224\237\346\210\220/07. \345\246\202\344\275\225\350\256\276\347\275\256 ViewController \347\232\204\347\210\266\347\261\273.md" "b/QFramework.Unity2018+/Assets/QFramework/Toolkits/_CoreKit/Internal/Guidline/Editor/Resources/EditorGuideline/3. \345\267\245\345\205\267\347\257\207\357\274\232QFramework.Toolkits/03. CodeGenKit \350\204\232\346\234\254\347\224\237\346\210\220/07. \345\246\202\344\275\225\350\256\276\347\275\256 ViewController \347\232\204\347\210\266\347\261\273.md" new file mode 100644 index 000000000..a399bc016 --- /dev/null +++ "b/QFramework.Unity2018+/Assets/QFramework/Toolkits/_CoreKit/Internal/Guidline/Editor/Resources/EditorGuideline/3. \345\267\245\345\205\267\347\257\207\357\274\232QFramework.Toolkits/03. CodeGenKit \350\204\232\346\234\254\347\224\237\346\210\220/07. \345\246\202\344\275\225\350\256\276\347\275\256 ViewController \347\232\204\347\210\266\347\261\273.md" @@ -0,0 +1,27 @@ +## 如何设置 ViewController 的父类 + +当我们给 GameObject 挂上 ViewController 之后,我们就会看到如下图: + +![image-20240508162552269](https://file.liangxiegame.com/59a62ce9-a4a9-4de0-b1b8-9d31e3a5ec72.png) + +图中我们默认继承了 ViewController。 + +在很多情况下,我们是有需要设置公共父类的需求的,要想设置公共父类非常简单。 + +只需要继承 ViewController 的同时,加上 ViewControllerChildAttribute 即可,代码如下: +```csharp +namespace QFramework.Gungeon +{ + [ViewControllerChild] + public abstract class PowerUp : ViewController + { + + } +} +``` + +等待编译后,就可以选择了,结果如下: +![img.png](https://file.liangxiegame.com/5fa3e200-832b-45a1-abf2-0c54e25fcc65.png) + + + diff --git "a/QFramework.Unity2018+/Assets/QFramework/Toolkits/_CoreKit/Internal/Guidline/Editor/Resources/EditorGuideline/3. \345\267\245\345\205\267\347\257\207\357\274\232QFramework.Toolkits/03. CodeGenKit \350\204\232\346\234\254\347\224\237\346\210\220/07. \345\246\202\344\275\225\350\256\276\347\275\256 ViewController \347\232\204\347\210\266\347\261\273.md.meta" "b/QFramework.Unity2018+/Assets/QFramework/Toolkits/_CoreKit/Internal/Guidline/Editor/Resources/EditorGuideline/3. \345\267\245\345\205\267\347\257\207\357\274\232QFramework.Toolkits/03. CodeGenKit \350\204\232\346\234\254\347\224\237\346\210\220/07. \345\246\202\344\275\225\350\256\276\347\275\256 ViewController \347\232\204\347\210\266\347\261\273.md.meta" new file mode 100644 index 000000000..bd07fa314 --- /dev/null +++ "b/QFramework.Unity2018+/Assets/QFramework/Toolkits/_CoreKit/Internal/Guidline/Editor/Resources/EditorGuideline/3. \345\267\245\345\205\267\347\257\207\357\274\232QFramework.Toolkits/03. CodeGenKit \350\204\232\346\234\254\347\224\237\346\210\220/07. \345\246\202\344\275\225\350\256\276\347\275\256 ViewController \347\232\204\347\210\266\347\261\273.md.meta" @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: ab90d8b1497b4c0c94a9567097232544 +timeCreated: 1715156650 \ No newline at end of file