Skip to content

Commit

Permalink
v1.0.131 release
Browse files Browse the repository at this point in the history
  • Loading branch information
liangxiegame committed May 8, 2024
1 parent 34c4ba8 commit 93190db
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"Id": "",
"Version": "v1.0.129",
"Version": "v1.0.131",
"Type": 0,
"AccessRight": 0,
"DownloadUrl": "",
Expand All @@ -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": ""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<ViewController>();

var writer = new StringBuilder();
writer.AppendLine("using UnityEngine;");
Expand All @@ -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");
Expand All @@ -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<ViewController>();
if (viewController.ArchitectureFullTypeName.IsNotNullAndEmpty())
{
writer.AppendLine($"\tpublic partial class {task.ClassName} : QFramework.IController");
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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<ViewControllerChildAttribute>() != null && viewControllerType.IsAssignableFrom(type)).ToArray();
}

private Type[] mArchitectureTypes;
private Type[] mViewControllerTypes;
private string[] mArchitectureTypeMenus;
private string[] mViewControllerTypeMenus;

private readonly ViewControllerInspectorStyle mStyle = new ViewControllerInspectorStyle();

Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* https://gitee.com/liangxiegame/QFramework
****************************************************************************/

using System.Linq;
using UnityEngine;
using UnityEngine.UI;

Expand Down Expand Up @@ -41,6 +42,10 @@ public virtual string TypeName
{
mComponentName = GetDefaultComponentName();
}
else if (!GetComponent(mComponentName) && !GetComponent(mComponentName.Split('.').Last()))
{
mComponentName = GetDefaultComponentName();
}

return mComponentName;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
/****************************************************************************
* 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
* https://gitee.com/liangxiegame/QFramework
****************************************************************************/


using System;
using UnityEngine;

namespace QFramework
Expand All @@ -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
{
}
}
Original file line number Diff line number Diff line change
@@ -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)



Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 93190db

Please sign in to comment.