mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
TE6 打飞机Demo
TE6 打飞机Demo
This commit is contained in:
8
UnityProject/Assets/Editor/AssetBundleCollector.meta
Normal file
8
UnityProject/Assets/Editor/AssetBundleCollector.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9afd4d88f7b567341823779947b83bd9
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root Version="v2.0.0">
|
||||
<Common ShowPackageView="True" ShowEditorAlias="False" UniqueBundleName="True" />
|
||||
<Package PackageName="DefaultPackage" PackageDesc="" AutoAddressable="True" LocationToLower="False" IncludeAssetGUID="False" IgnoreDefaultType="True">
|
||||
<Group GroupActiveRule="EnableGroup" GroupName="Actor" GroupDesc="" AssetTags="">
|
||||
<Collector CollectPath="Assets/AssetRaw/Actor" CollectGUID="9c67ce0c9edfd4e4aa1006ee39846d66" CollectType="MainAssetCollector" AddressRule="AddressByFileName" PackRule="PackDirectory" FilterRule="CollectAll" UserData="" AssetTags="" />
|
||||
</Group>
|
||||
<Group GroupActiveRule="EnableGroup" GroupName="Audios" GroupDesc="" AssetTags="">
|
||||
<Collector CollectPath="Assets/AssetRaw/Audios" CollectGUID="8ef7a411b66e70f4cb65c2233c9a0868" CollectType="MainAssetCollector" AddressRule="AddressByFileName" PackRule="PackDirectory" FilterRule="CollectAll" UserData="" AssetTags="" />
|
||||
</Group>
|
||||
<Group GroupActiveRule="EnableGroup" GroupName="Configs" GroupDesc="" AssetTags="">
|
||||
<Collector CollectPath="Assets/AssetRaw/Configs" CollectGUID="dd2928019aef34248af368b99bc53bea" CollectType="MainAssetCollector" AddressRule="AddressByFileName" PackRule="PackDirectory" FilterRule="CollectAll" UserData="" AssetTags="" />
|
||||
</Group>
|
||||
<Group GroupActiveRule="EnableGroup" GroupName="DLL" GroupDesc="" AssetTags="">
|
||||
<Collector CollectPath="Assets/AssetRaw/DLL" CollectGUID="3aad79ec1ea08c24c891bd3c669d4125" CollectType="MainAssetCollector" AddressRule="AddressByFileName" PackRule="PackDirectory" FilterRule="CollectAll" UserData="" AssetTags="" />
|
||||
</Group>
|
||||
<Group GroupActiveRule="EnableGroup" GroupName="Effects" GroupDesc="" AssetTags="">
|
||||
<Collector CollectPath="Assets/AssetRaw/Effects" CollectGUID="0fe175e1e1bd49a4ca71e66b6a9b7237" CollectType="MainAssetCollector" AddressRule="AddressByFileName" PackRule="PackDirectory" FilterRule="CollectAll" UserData="" AssetTags="" />
|
||||
</Group>
|
||||
<Group GroupActiveRule="EnableGroup" GroupName="Fonts" GroupDesc="" AssetTags="">
|
||||
<Collector CollectPath="Assets/AssetRaw/Fonts" CollectGUID="2473375c9ee163a4b861278b38091455" CollectType="MainAssetCollector" AddressRule="AddressByFileName" PackRule="PackDirectory" FilterRule="CollectAll" UserData="" AssetTags="" />
|
||||
</Group>
|
||||
<Group GroupActiveRule="EnableGroup" GroupName="Materials" GroupDesc="" AssetTags="">
|
||||
<Collector CollectPath="Assets/AssetRaw/Materials" CollectGUID="228b1547e7065d546ad0bf215fd6a276" CollectType="MainAssetCollector" AddressRule="AddressByFileName" PackRule="PackDirectory" FilterRule="CollectAll" UserData="" AssetTags="" />
|
||||
</Group>
|
||||
<Group GroupActiveRule="EnableGroup" GroupName="Scenes" GroupDesc="" AssetTags="">
|
||||
<Collector CollectPath="Assets/AssetRaw/Scenes" CollectGUID="cace6ee6539f661419b5e5f8ae1c0146" CollectType="MainAssetCollector" AddressRule="AddressByFileName" PackRule="PackDirectory" FilterRule="CollectAll" UserData="" AssetTags="" />
|
||||
</Group>
|
||||
<Group GroupActiveRule="EnableGroup" GroupName="UI" GroupDesc="" AssetTags="">
|
||||
<Collector CollectPath="Assets/AssetRaw/UI" CollectGUID="27e87d83814156648b58f380b834e046" CollectType="MainAssetCollector" AddressRule="AddressByFileName" PackRule="PackDirectory" FilterRule="CollectAll" UserData="" AssetTags="" />
|
||||
</Group>
|
||||
<Group GroupActiveRule="EnableGroup" GroupName="UIRaw" GroupDesc="" AssetTags="">
|
||||
<Collector CollectPath="Assets/AssetRaw/UIRaw/Atlas" CollectGUID="6d11fa91acc253840a648b58f23db139" CollectType="MainAssetCollector" AddressRule="AddressByFileName" PackRule="PackDirectory" FilterRule="CollectAll" UserData="" AssetTags="" />
|
||||
<Collector CollectPath="Assets/AssetRaw/UIRaw/Raw" CollectGUID="6bc134b912ac6bb4399ea1bec4c11636" CollectType="MainAssetCollector" AddressRule="AddressByFileName" PackRule="PackDirectory" FilterRule="CollectAll" UserData="" AssetTags="" />
|
||||
</Group>
|
||||
</Package>
|
||||
<Package PackageName="OtherPackage" PackageDesc="" AutoAddressable="True" LocationToLower="False" IncludeAssetGUID="False" IgnoreDefaultType="True">
|
||||
<Group GroupActiveRule="EnableGroup" GroupName="ModelGroup" GroupDesc="" AssetTags="models" />
|
||||
<Group GroupActiveRule="EnableGroup" GroupName="SceneGroup" GroupDesc="" AssetTags="scenes" />
|
||||
</Package>
|
||||
<Package PackageName="Dlc1Package" PackageDesc="" AutoAddressable="True" LocationToLower="False" IncludeAssetGUID="False" IgnoreDefaultType="True">
|
||||
<Group GroupActiveRule="EnableGroup" GroupName="ModelGroup" GroupDesc="" AssetTags="models" />
|
||||
<Group GroupActiveRule="EnableGroup" GroupName="SceneGroup" GroupDesc="" AssetTags="scenes" />
|
||||
</Package>
|
||||
<Package PackageName="Dlc2Package" PackageDesc="" AutoAddressable="True" LocationToLower="False" IncludeAssetGUID="False" IgnoreDefaultType="True">
|
||||
<Group GroupActiveRule="EnableGroup" GroupName="ModelGroup" GroupDesc="" AssetTags="models" />
|
||||
</Package>
|
||||
</root>
|
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 40551812c908533438dbfc2b727c9950
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,213 @@
|
||||
%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: 185f6993d5150494d98da50e26cb1c25, type: 3}
|
||||
m_Name: AssetBundleCollectorSetting
|
||||
m_EditorClassIdentifier:
|
||||
ShowPackageView: 1
|
||||
ShowEditorAlias: 0
|
||||
UniqueBundleName: 1
|
||||
Packages:
|
||||
- PackageName: DefaultPackage
|
||||
PackageDesc:
|
||||
EnableAddressable: 1
|
||||
LocationToLower: 0
|
||||
IncludeAssetGUID: 0
|
||||
IgnoreDefaultType: 1
|
||||
AutoCollectShaders: 1
|
||||
Groups:
|
||||
- GroupName: Actor
|
||||
GroupDesc:
|
||||
AssetTags:
|
||||
ActiveRuleName: EnableGroup
|
||||
Collectors:
|
||||
- CollectPath: Assets/AssetRaw/Actor
|
||||
CollectorGUID: 9c67ce0c9edfd4e4aa1006ee39846d66
|
||||
CollectorType: 0
|
||||
AddressRuleName: AddressByFileName
|
||||
PackRuleName: PackDirectory
|
||||
FilterRuleName: CollectAll
|
||||
AssetTags:
|
||||
UserData:
|
||||
- GroupName: Audios
|
||||
GroupDesc:
|
||||
AssetTags:
|
||||
ActiveRuleName: EnableGroup
|
||||
Collectors:
|
||||
- CollectPath: Assets/AssetRaw/Audios
|
||||
CollectorGUID: 8ef7a411b66e70f4cb65c2233c9a0868
|
||||
CollectorType: 0
|
||||
AddressRuleName: AddressByFileName
|
||||
PackRuleName: PackDirectory
|
||||
FilterRuleName: CollectAll
|
||||
AssetTags:
|
||||
UserData:
|
||||
- GroupName: Configs
|
||||
GroupDesc:
|
||||
AssetTags:
|
||||
ActiveRuleName: EnableGroup
|
||||
Collectors:
|
||||
- CollectPath: Assets/AssetRaw/Configs
|
||||
CollectorGUID: dd2928019aef34248af368b99bc53bea
|
||||
CollectorType: 0
|
||||
AddressRuleName: AddressByFileName
|
||||
PackRuleName: PackDirectory
|
||||
FilterRuleName: CollectAll
|
||||
AssetTags:
|
||||
UserData:
|
||||
- GroupName: DLL
|
||||
GroupDesc:
|
||||
AssetTags:
|
||||
ActiveRuleName: EnableGroup
|
||||
Collectors:
|
||||
- CollectPath: Assets/AssetRaw/DLL
|
||||
CollectorGUID: 3aad79ec1ea08c24c891bd3c669d4125
|
||||
CollectorType: 0
|
||||
AddressRuleName: AddressByFileName
|
||||
PackRuleName: PackDirectory
|
||||
FilterRuleName: CollectAll
|
||||
AssetTags:
|
||||
UserData:
|
||||
- GroupName: Effects
|
||||
GroupDesc:
|
||||
AssetTags:
|
||||
ActiveRuleName: EnableGroup
|
||||
Collectors:
|
||||
- CollectPath: Assets/AssetRaw/Effects
|
||||
CollectorGUID: 0fe175e1e1bd49a4ca71e66b6a9b7237
|
||||
CollectorType: 0
|
||||
AddressRuleName: AddressByFileName
|
||||
PackRuleName: PackDirectory
|
||||
FilterRuleName: CollectAll
|
||||
AssetTags:
|
||||
UserData:
|
||||
- GroupName: Fonts
|
||||
GroupDesc:
|
||||
AssetTags:
|
||||
ActiveRuleName: EnableGroup
|
||||
Collectors:
|
||||
- CollectPath: Assets/AssetRaw/Fonts
|
||||
CollectorGUID: 2473375c9ee163a4b861278b38091455
|
||||
CollectorType: 0
|
||||
AddressRuleName: AddressByFileName
|
||||
PackRuleName: PackDirectory
|
||||
FilterRuleName: CollectAll
|
||||
AssetTags:
|
||||
UserData:
|
||||
- GroupName: Materials
|
||||
GroupDesc:
|
||||
AssetTags:
|
||||
ActiveRuleName: EnableGroup
|
||||
Collectors:
|
||||
- CollectPath: Assets/AssetRaw/Materials
|
||||
CollectorGUID: 228b1547e7065d546ad0bf215fd6a276
|
||||
CollectorType: 0
|
||||
AddressRuleName: AddressByFileName
|
||||
PackRuleName: PackDirectory
|
||||
FilterRuleName: CollectAll
|
||||
AssetTags:
|
||||
UserData:
|
||||
- GroupName: Scenes
|
||||
GroupDesc:
|
||||
AssetTags:
|
||||
ActiveRuleName: EnableGroup
|
||||
Collectors:
|
||||
- CollectPath: Assets/AssetRaw/Scenes
|
||||
CollectorGUID: cace6ee6539f661419b5e5f8ae1c0146
|
||||
CollectorType: 0
|
||||
AddressRuleName: AddressByFileName
|
||||
PackRuleName: PackDirectory
|
||||
FilterRuleName: CollectAll
|
||||
AssetTags:
|
||||
UserData:
|
||||
- GroupName: UI
|
||||
GroupDesc:
|
||||
AssetTags:
|
||||
ActiveRuleName: EnableGroup
|
||||
Collectors:
|
||||
- CollectPath: Assets/AssetRaw/UI
|
||||
CollectorGUID: 27e87d83814156648b58f380b834e046
|
||||
CollectorType: 0
|
||||
AddressRuleName: AddressByFileName
|
||||
PackRuleName: PackDirectory
|
||||
FilterRuleName: CollectAll
|
||||
AssetTags:
|
||||
UserData:
|
||||
- GroupName: UIRaw
|
||||
GroupDesc:
|
||||
AssetTags:
|
||||
ActiveRuleName: EnableGroup
|
||||
Collectors:
|
||||
- CollectPath: Assets/AssetRaw/UIRaw/Atlas
|
||||
CollectorGUID: 6d11fa91acc253840a648b58f23db139
|
||||
CollectorType: 0
|
||||
AddressRuleName: AddressByFileName
|
||||
PackRuleName: PackDirectory
|
||||
FilterRuleName: CollectAll
|
||||
AssetTags:
|
||||
UserData:
|
||||
- CollectPath: Assets/AssetRaw/UIRaw/Raw
|
||||
CollectorGUID: 6bc134b912ac6bb4399ea1bec4c11636
|
||||
CollectorType: 0
|
||||
AddressRuleName: AddressByFileName
|
||||
PackRuleName: PackDirectory
|
||||
FilterRuleName: CollectAll
|
||||
AssetTags:
|
||||
UserData:
|
||||
- PackageName: OtherPackage
|
||||
PackageDesc:
|
||||
EnableAddressable: 1
|
||||
LocationToLower: 0
|
||||
IncludeAssetGUID: 0
|
||||
IgnoreDefaultType: 1
|
||||
AutoCollectShaders: 1
|
||||
Groups:
|
||||
- GroupName: ModelGroup
|
||||
GroupDesc:
|
||||
AssetTags: models
|
||||
ActiveRuleName: EnableGroup
|
||||
Collectors: []
|
||||
- GroupName: SceneGroup
|
||||
GroupDesc:
|
||||
AssetTags: scenes
|
||||
ActiveRuleName: EnableGroup
|
||||
Collectors: []
|
||||
- PackageName: Dlc1Package
|
||||
PackageDesc:
|
||||
EnableAddressable: 1
|
||||
LocationToLower: 0
|
||||
IncludeAssetGUID: 0
|
||||
IgnoreDefaultType: 1
|
||||
AutoCollectShaders: 1
|
||||
Groups:
|
||||
- GroupName: ModelGroup
|
||||
GroupDesc:
|
||||
AssetTags: models
|
||||
ActiveRuleName: EnableGroup
|
||||
Collectors: []
|
||||
- GroupName: SceneGroup
|
||||
GroupDesc:
|
||||
AssetTags: scenes
|
||||
ActiveRuleName: EnableGroup
|
||||
Collectors: []
|
||||
- PackageName: Dlc2Package
|
||||
PackageDesc:
|
||||
EnableAddressable: 1
|
||||
LocationToLower: 0
|
||||
IncludeAssetGUID: 0
|
||||
IgnoreDefaultType: 1
|
||||
AutoCollectShaders: 1
|
||||
Groups:
|
||||
- GroupName: ModelGroup
|
||||
GroupDesc:
|
||||
AssetTags: models
|
||||
ActiveRuleName: EnableGroup
|
||||
Collectors: []
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c0d90477c8489f0438ae73994ff045b9
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4c9eb26aee01e8643bd4e6dc965d3366
|
||||
guid: f183cc1bcf4014f4c80a8580caabcd3f
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f069f2f03dfa55843a74dedc551eefb2
|
||||
guid: 50fd67a84c64e184c85bf3e1e343ba87
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
|
8
UnityProject/Assets/Editor/TEngineSettingsProvider.meta
Normal file
8
UnityProject/Assets/Editor/TEngineSettingsProvider.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cace8d5078f400048a8afde10e2bf41d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,36 @@
|
||||
using TEngine;
|
||||
using UnityEditor;
|
||||
|
||||
public static class TEngineSettingsProvider
|
||||
{
|
||||
[MenuItem("TEngine/Settings/TEngine UpdateSettings", priority = -1)]
|
||||
public static void OpenSettings() => SettingsService.OpenProjectSettings("Project/TEngine/UpdateSettings");
|
||||
|
||||
private const string SettingsPath = "Project/TEngine/UpdateSettings";
|
||||
|
||||
[SettingsProvider]
|
||||
public static SettingsProvider CreateMySettingsProvider()
|
||||
{
|
||||
return new SettingsProvider(SettingsPath, SettingsScope.Project)
|
||||
{
|
||||
label = "TEngine/UpdateSettings",
|
||||
guiHandler = (searchContext) =>
|
||||
{
|
||||
var settings = Settings.UpdateSetting;
|
||||
var serializedObject = new SerializedObject(settings);
|
||||
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("projectName"));
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("HotUpdateAssemblies"));
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("AOTMetaAssemblies"));
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("LogicMainDllName"));
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("AssemblyTextAssetExtension"));
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("AssemblyTextAssetPath"));
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("UpdateStyle"));
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("ResDownLoadPath"));
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("FallbackResDownLoadPath"));
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
},
|
||||
keywords = new[] { "TEngine", "Settings", "Custom" }
|
||||
};
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f1c738d23f551c84e9e12af687389aeb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,32 @@
|
||||
using TEngine.Editor.UI;
|
||||
using UnityEditor;
|
||||
|
||||
public static class TEngineUISettingsProvider
|
||||
{
|
||||
[MenuItem("TEngine/Settings/TEngineUISettings", priority = -1)]
|
||||
public static void OpenSettings() => SettingsService.OpenProjectSettings("Project/TEngine/UISettings");
|
||||
|
||||
private const string SettingsPath = "Project/TEngine/UISettings";
|
||||
|
||||
[SettingsProvider]
|
||||
public static SettingsProvider CreateMySettingsProvider()
|
||||
{
|
||||
return new SettingsProvider(SettingsPath, SettingsScope.Project)
|
||||
{
|
||||
label = "TEngine/UISettings",
|
||||
guiHandler = (searchContext) =>
|
||||
{
|
||||
var scriptGeneratorSetting = ScriptGeneratorSetting.Instance;
|
||||
var scriptGenerator = new SerializedObject(scriptGeneratorSetting);
|
||||
|
||||
EditorGUILayout.PropertyField(scriptGenerator.FindProperty("_codePath"));
|
||||
EditorGUILayout.PropertyField(scriptGenerator.FindProperty("_namespace"));
|
||||
EditorGUILayout.PropertyField(scriptGenerator.FindProperty("_widgetName"));
|
||||
EditorGUILayout.PropertyField(scriptGenerator.FindProperty("CodeStyle"));
|
||||
EditorGUILayout.PropertyField(scriptGenerator.FindProperty("scriptGenerateRule"));
|
||||
scriptGenerator.ApplyModifiedProperties();
|
||||
},
|
||||
keywords = new[] { "TEngine", "Settings", "Custom" }
|
||||
};
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2672376ad13242bcb6869e90c4def052
|
||||
timeCreated: 1742814408
|
8
UnityProject/Assets/Editor/ToolbarExtender.meta
Normal file
8
UnityProject/Assets/Editor/ToolbarExtender.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2982073ed28ef744e96be44c7f55f5f7
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
UnityProject/Assets/Editor/ToolbarExtender/Custom.meta
Normal file
8
UnityProject/Assets/Editor/ToolbarExtender/Custom.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 075130c21aee41b49b3977adc2bfa288
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 20dbf6614352aaf488de29690deeab68
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fb0502859d7561142a3408d0ce2a19d8
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,88 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityToolbarExtender;
|
||||
|
||||
namespace TEngine
|
||||
{
|
||||
[InitializeOnLoad]
|
||||
public class EditorPlayMode
|
||||
{
|
||||
static class ToolbarStyles
|
||||
{
|
||||
public static readonly GUIStyle ToolBarExtenderBtnStyle;
|
||||
|
||||
public static readonly GUIStyle ToolBarTextStyle;
|
||||
|
||||
public static readonly GUIStyle ToolBarButtonGuiStyle;
|
||||
|
||||
static ToolbarStyles()
|
||||
{
|
||||
ToolBarExtenderBtnStyle = new GUIStyle("Command")
|
||||
{
|
||||
fontSize = 12,
|
||||
alignment = TextAnchor.MiddleCenter,
|
||||
imagePosition = ImagePosition.ImageAbove,
|
||||
fontStyle = FontStyle.Normal,
|
||||
fixedWidth = 60
|
||||
};
|
||||
|
||||
ToolBarTextStyle = new GUIStyle(BUTTON_STYLE_NAME)
|
||||
{
|
||||
padding = new RectOffset(2, 8, 2, 2),
|
||||
alignment = TextAnchor.MiddleCenter,
|
||||
fontStyle = FontStyle.Bold
|
||||
};
|
||||
|
||||
ToolBarButtonGuiStyle = new GUIStyle(BUTTON_STYLE_NAME)
|
||||
{
|
||||
padding = new RectOffset(2, 8, 2, 2),
|
||||
alignment = TextAnchor.MiddleCenter,
|
||||
fontStyle = FontStyle.Bold
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
static EditorPlayMode()
|
||||
{
|
||||
ToolbarExtender.RightToolbarGUI.Add(OnToolbarGUI);
|
||||
_resourceModeIndex = EditorPrefs.GetInt("EditorPlayMode", 0);
|
||||
}
|
||||
|
||||
private const string BUTTON_STYLE_NAME = "Tab middle";
|
||||
static GUIStyle _buttonGuiStyle;
|
||||
|
||||
private static readonly string[] _resourceModeNames =
|
||||
{
|
||||
"EditorMode (编辑器下的模拟模式)",
|
||||
"OfflinePlayMode (单机模式)",
|
||||
"HostPlayMode (联机运行模式)",
|
||||
"WebPlayMode (WebGL运行模式)"
|
||||
};
|
||||
|
||||
private static int _resourceModeIndex = 0;
|
||||
public static int ResourceModeIndex => _resourceModeIndex;
|
||||
|
||||
static void OnToolbarGUI()
|
||||
{
|
||||
EditorGUI.BeginDisabledGroup(EditorApplication.isPlayingOrWillChangePlaymode);
|
||||
{
|
||||
// GUILayout.Label("资源加载模式:",ToolbarStyles.ToolBarTextStyle);
|
||||
//GUILayout.Space(10);
|
||||
//GUILayout.FlexibleSpace();
|
||||
|
||||
// 资源模式
|
||||
int selectedIndex = EditorGUILayout.Popup("", _resourceModeIndex, _resourceModeNames, ToolbarStyles.ToolBarButtonGuiStyle);
|
||||
// ReSharper disable once RedundantCheckBeforeAssignment
|
||||
if (selectedIndex != _resourceModeIndex)
|
||||
{
|
||||
Debug.Log($"更改编辑器资源运行模式 : {_resourceModeNames[selectedIndex]}");
|
||||
_resourceModeIndex = selectedIndex;
|
||||
EditorPrefs.SetInt("EditorPlayMode", selectedIndex);
|
||||
}
|
||||
//GUILayout.FlexibleSpace();
|
||||
//GUILayout.Space(400);
|
||||
}
|
||||
EditorGUI.EndDisabledGroup();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ab26dd2998d84a08b35c0132e1814199
|
||||
timeCreated: 1683857308
|
@@ -0,0 +1,126 @@
|
||||
using UnityEditor;
|
||||
using UnityEditor.SceneManagement;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityToolbarExtender;
|
||||
|
||||
namespace TEngine.SceneLauncher
|
||||
{
|
||||
[InitializeOnLoad]
|
||||
public class SceneSwitchLeftButton
|
||||
{
|
||||
private const string PreviousSceneKey = "TEngine_PreviousScenePath"; // 用于存储之前场景路径的键
|
||||
private const string IsLauncherBtn = "TEngine_IsLauncher"; // 用于存储之前是否按下launcher
|
||||
|
||||
private static readonly string SceneMain = "main";
|
||||
|
||||
private static readonly string ButtonStyleName = "Tab middle";
|
||||
private static GUIStyle _buttonGuiStyle;
|
||||
|
||||
static SceneSwitchLeftButton()
|
||||
{
|
||||
ToolbarExtender.LeftToolbarGUI.Add(OnToolbarGUI);
|
||||
EditorApplication.playModeStateChanged += OnPlayModeStateChanged;
|
||||
EditorApplication.quitting += OnEditorQuit;
|
||||
}
|
||||
|
||||
private static void OnToolbarGUI()
|
||||
{
|
||||
_buttonGuiStyle ??= new GUIStyle(ButtonStyleName)
|
||||
{
|
||||
padding = new RectOffset(2, 8, 2, 2),
|
||||
alignment = TextAnchor.MiddleCenter,
|
||||
fontStyle = FontStyle.Bold
|
||||
};
|
||||
|
||||
GUILayout.FlexibleSpace();
|
||||
if (GUILayout.Button(
|
||||
new GUIContent("Launcher", EditorGUIUtility.FindTexture("PlayButton"), "Start Scene Launcher"),
|
||||
_buttonGuiStyle))
|
||||
SceneHelper.StartScene(SceneMain);
|
||||
}
|
||||
|
||||
private static void OnPlayModeStateChanged(PlayModeStateChange state)
|
||||
{
|
||||
if (state == PlayModeStateChange.EnteredEditMode)
|
||||
{
|
||||
// 从 EditorPrefs 读取之前的场景路径
|
||||
var previousScenePath = EditorPrefs.GetString(PreviousSceneKey, string.Empty);
|
||||
if (!string.IsNullOrEmpty(previousScenePath) && EditorPrefs.GetBool(IsLauncherBtn))
|
||||
{
|
||||
EditorApplication.delayCall += () =>
|
||||
{
|
||||
if (EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
|
||||
EditorSceneManager.OpenScene(previousScenePath);
|
||||
};
|
||||
}
|
||||
|
||||
EditorPrefs.SetBool(IsLauncherBtn, false);
|
||||
}
|
||||
}
|
||||
|
||||
private static void OnEditorQuit()
|
||||
{
|
||||
EditorPrefs.SetString(PreviousSceneKey, "");
|
||||
EditorPrefs.SetBool(IsLauncherBtn, false);
|
||||
}
|
||||
|
||||
private static class SceneHelper
|
||||
{
|
||||
private static string _sceneToOpen;
|
||||
|
||||
public static void StartScene(string sceneName)
|
||||
{
|
||||
if (EditorApplication.isPlaying) EditorApplication.isPlaying = false;
|
||||
|
||||
// 记录当前场景路径到 EditorPrefs
|
||||
var activeScene = SceneManager.GetActiveScene();
|
||||
if (activeScene.isLoaded && activeScene.name != SceneMain)
|
||||
{
|
||||
EditorPrefs.SetString(PreviousSceneKey, activeScene.path);
|
||||
EditorPrefs.SetBool(IsLauncherBtn, true);
|
||||
}
|
||||
|
||||
_sceneToOpen = sceneName;
|
||||
EditorApplication.update += OnUpdate;
|
||||
}
|
||||
|
||||
private static void OnUpdate()
|
||||
{
|
||||
if (_sceneToOpen == null ||
|
||||
EditorApplication.isPlaying || EditorApplication.isPaused ||
|
||||
EditorApplication.isCompiling || EditorApplication.isPlayingOrWillChangePlaymode)
|
||||
return;
|
||||
|
||||
EditorApplication.update -= OnUpdate;
|
||||
|
||||
if (EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
|
||||
{
|
||||
string[] guids = AssetDatabase.FindAssets("t:scene " + _sceneToOpen, null);
|
||||
if (guids.Length == 0)
|
||||
{
|
||||
Debug.LogWarning("Couldn't find scene file");
|
||||
}
|
||||
else
|
||||
{
|
||||
string scenePath = null;
|
||||
// 优先打开完全匹配_sceneToOpen的场景
|
||||
for (var i = 0; i < guids.Length; i++)
|
||||
{
|
||||
scenePath = AssetDatabase.GUIDToAssetPath(guids[i]);
|
||||
if (scenePath.EndsWith("/" + _sceneToOpen + ".unity")) break;
|
||||
}
|
||||
|
||||
// 如果没有完全匹配的场景,默认显示找到的第一个场景
|
||||
if (string.IsNullOrEmpty(scenePath)) scenePath = AssetDatabase.GUIDToAssetPath(guids[0]);
|
||||
|
||||
EditorSceneManager.OpenScene(scenePath);
|
||||
EditorApplication.isPlaying = true;
|
||||
}
|
||||
}
|
||||
|
||||
_sceneToOpen = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2f6d2ca3d3b34950a79294e49dd9d016
|
||||
timeCreated: 1742389721
|
@@ -0,0 +1,115 @@
|
||||
#if UNITY_EDITOR
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEditor.SceneManagement;
|
||||
|
||||
namespace UnityToolbarExtender.Examples
|
||||
{
|
||||
[InitializeOnLoad]
|
||||
public sealed class SceneSwitchLeftButton
|
||||
{
|
||||
private static List<(string sceneName, string scenePath)> m_Scenes;
|
||||
private static string[] m_SceneName;
|
||||
private static string[] m_ScenePath;
|
||||
private static int sceneSelected = 0;
|
||||
|
||||
static SceneSwitchLeftButton()
|
||||
{
|
||||
EditorApplication.projectChanged += UpdateCurrent;
|
||||
UpdateCurrent();
|
||||
ToolbarExtender.RightToolbarGUI.Add(OnToolbarGUI);
|
||||
}
|
||||
|
||||
static void UpdateCurrent()
|
||||
{
|
||||
m_Scenes = SceneSwitcher.GetAllScenesInProject();
|
||||
m_SceneName = new string[m_Scenes.Count];
|
||||
m_ScenePath = new string[m_Scenes.Count];
|
||||
for (int i = 0; i < m_Scenes.Count; i++)
|
||||
{
|
||||
var (name, path) = m_Scenes[i];
|
||||
m_SceneName[i] = name;
|
||||
m_ScenePath[i] = path;
|
||||
if (SceneManager.GetActiveScene().path == path)
|
||||
sceneSelected = i;
|
||||
}
|
||||
}
|
||||
|
||||
static void OnToolbarGUI()
|
||||
{
|
||||
if (sceneSelected >= m_SceneName.Length) //空项目0场景判断
|
||||
return;
|
||||
var size = EditorStyles.popup.CalcSize(new GUIContent(m_SceneName[sceneSelected]));
|
||||
// 创建水平布局
|
||||
//EditorGUILayout.BeginHorizontal();
|
||||
GUILayout.Space(20);
|
||||
// 将控件推到左边和右边
|
||||
//GUILayout.FlexibleSpace(); // 先占用左边的所有空间
|
||||
EditorGUILayout.LabelField("当前场景:", GUILayout.Width(55));
|
||||
int sceneSelectedNew = EditorGUILayout.Popup(sceneSelected, m_SceneName, GUILayout.Width(size.x + 5f),
|
||||
GUILayout.MinWidth(55));
|
||||
GUILayout.FlexibleSpace();
|
||||
// 结束水平布局
|
||||
//EditorGUILayout.EndHorizontal();
|
||||
if (sceneSelectedNew != sceneSelected)
|
||||
{
|
||||
sceneSelected = sceneSelectedNew;
|
||||
SceneSwitcher.PromptSaveCurrentScene();
|
||||
EditorSceneManager.OpenScene(m_ScenePath[sceneSelectedNew]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static class SceneSwitcher
|
||||
{
|
||||
public static bool PromptSaveCurrentScene()
|
||||
{
|
||||
// 检查当前场景是否已保存
|
||||
if (SceneManager.GetActiveScene().isDirty)
|
||||
{
|
||||
// 提示用户是否要保存当前场景
|
||||
bool saveScene = EditorUtility.DisplayDialog(
|
||||
"Save Current Scene",
|
||||
"The current scene has unsaved changes. Do you want to save it?",
|
||||
"Save",
|
||||
"Cancel"
|
||||
);
|
||||
|
||||
// 如果用户选择“保存”,则保存当前场景
|
||||
if (saveScene)
|
||||
{
|
||||
EditorSceneManager.SaveScene(SceneManager.GetActiveScene());
|
||||
}
|
||||
|
||||
return saveScene;
|
||||
}
|
||||
|
||||
// 如果场景已保存或者用户选择了“取消”,则返回 true,表示继续执行后续操作
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取项目中所有的场景文件,并以 (场景名, 场景路径) 的形式返回。
|
||||
/// </summary>
|
||||
public static List<(string sceneName, string scenePath)> GetAllScenesInProject()
|
||||
{
|
||||
List<(string sceneName, string scenePath)> scenes = new List<(string sceneName, string scenePath)>();
|
||||
|
||||
// 查找所有场景文件
|
||||
string[] guids = AssetDatabase.FindAssets("t:Scene");
|
||||
for (int i = 0; i < guids.Length; i++)
|
||||
{
|
||||
var guid = guids[i];
|
||||
string path = AssetDatabase.GUIDToAssetPath(guid);
|
||||
string sceneName = $"{i + 1}_{Path.GetFileNameWithoutExtension(path)}";
|
||||
scenes.Add((sceneName, path));
|
||||
}
|
||||
|
||||
return scenes;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1fb6885a187ff8449a9cc083b7fbee28
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
111
UnityProject/Assets/Editor/ToolbarExtender/ToolbarCallback.cs
Normal file
111
UnityProject/Assets/Editor/ToolbarExtender/ToolbarCallback.cs
Normal file
@@ -0,0 +1,111 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.Reflection;
|
||||
|
||||
#if UNITY_2019_1_OR_NEWER
|
||||
using UnityEngine.UIElements;
|
||||
#else
|
||||
using UnityEngine.Experimental.UIElements;
|
||||
#endif
|
||||
|
||||
namespace UnityToolbarExtender
|
||||
{
|
||||
public static class ToolbarCallback
|
||||
{
|
||||
static Type m_toolbarType = typeof(Editor).Assembly.GetType("UnityEditor.Toolbar");
|
||||
static Type m_guiViewType = typeof(Editor).Assembly.GetType("UnityEditor.GUIView");
|
||||
#if UNITY_2020_1_OR_NEWER
|
||||
static Type m_iWindowBackendType = typeof(Editor).Assembly.GetType("UnityEditor.IWindowBackend");
|
||||
static PropertyInfo m_windowBackend = m_guiViewType.GetProperty("windowBackend",
|
||||
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
static PropertyInfo m_viewVisualTree = m_iWindowBackendType.GetProperty("visualTree",
|
||||
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
#else
|
||||
static PropertyInfo m_viewVisualTree = m_guiViewType.GetProperty("visualTree",
|
||||
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
#endif
|
||||
static FieldInfo m_imguiContainerOnGui = typeof(IMGUIContainer).GetField("m_OnGUIHandler",
|
||||
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
static ScriptableObject m_currentToolbar;
|
||||
|
||||
/// <summary>
|
||||
/// Callback for toolbar OnGUI method.
|
||||
/// </summary>
|
||||
public static Action OnToolbarGUI;
|
||||
public static Action OnToolbarGUILeft;
|
||||
public static Action OnToolbarGUIRight;
|
||||
|
||||
static ToolbarCallback()
|
||||
{
|
||||
EditorApplication.update -= OnUpdate;
|
||||
EditorApplication.update += OnUpdate;
|
||||
}
|
||||
|
||||
static void OnUpdate()
|
||||
{
|
||||
// Relying on the fact that toolbar is ScriptableObject and gets deleted when layout changes
|
||||
if (m_currentToolbar == null)
|
||||
{
|
||||
// Find toolbar
|
||||
var toolbars = Resources.FindObjectsOfTypeAll(m_toolbarType);
|
||||
m_currentToolbar = toolbars.Length > 0 ? (ScriptableObject) toolbars[0] : null;
|
||||
if (m_currentToolbar != null)
|
||||
{
|
||||
#if UNITY_2021_1_OR_NEWER
|
||||
var root = m_currentToolbar.GetType().GetField("m_Root", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
var rawRoot = root.GetValue(m_currentToolbar);
|
||||
var mRoot = rawRoot as VisualElement;
|
||||
RegisterCallback("ToolbarZoneLeftAlign", OnToolbarGUILeft);
|
||||
RegisterCallback("ToolbarZoneRightAlign", OnToolbarGUIRight);
|
||||
|
||||
void RegisterCallback(string root, Action cb) {
|
||||
var toolbarZone = mRoot.Q(root);
|
||||
|
||||
var parent = new VisualElement()
|
||||
{
|
||||
style = {
|
||||
flexGrow = 1,
|
||||
flexDirection = FlexDirection.Row,
|
||||
}
|
||||
};
|
||||
var container = new IMGUIContainer();
|
||||
container.style.flexGrow = 1;
|
||||
container.onGUIHandler += () => {
|
||||
cb?.Invoke();
|
||||
};
|
||||
parent.Add(container);
|
||||
toolbarZone.Add(parent);
|
||||
}
|
||||
#else
|
||||
#if UNITY_2020_1_OR_NEWER
|
||||
var windowBackend = m_windowBackend.GetValue(m_currentToolbar);
|
||||
|
||||
// Get it's visual tree
|
||||
var visualTree = (VisualElement) m_viewVisualTree.GetValue(windowBackend, null);
|
||||
#else
|
||||
// Get it's visual tree
|
||||
var visualTree = (VisualElement) m_viewVisualTree.GetValue(m_currentToolbar, null);
|
||||
#endif
|
||||
|
||||
// Get first child which 'happens' to be toolbar IMGUIContainer
|
||||
var container = (IMGUIContainer) visualTree[0];
|
||||
|
||||
// (Re)attach handler
|
||||
var handler = (Action) m_imguiContainerOnGui.GetValue(container);
|
||||
handler -= OnGUI;
|
||||
handler += OnGUI;
|
||||
m_imguiContainerOnGui.SetValue(container, handler);
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void OnGUI()
|
||||
{
|
||||
var handler = OnToolbarGUI;
|
||||
if (handler != null) handler();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4314ecffdfd1d90488e39e9ae35d14a1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
169
UnityProject/Assets/Editor/ToolbarExtender/ToolbarExtender.cs
Normal file
169
UnityProject/Assets/Editor/ToolbarExtender/ToolbarExtender.cs
Normal file
@@ -0,0 +1,169 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityToolbarExtender
|
||||
{
|
||||
[InitializeOnLoad]
|
||||
public static class ToolbarExtender
|
||||
{
|
||||
static int m_toolCount;
|
||||
static GUIStyle m_commandStyle = null;
|
||||
|
||||
public static readonly List<Action> LeftToolbarGUI = new List<Action>();
|
||||
public static readonly List<Action> RightToolbarGUI = new List<Action>();
|
||||
|
||||
static ToolbarExtender()
|
||||
{
|
||||
Type toolbarType = typeof(Editor).Assembly.GetType("UnityEditor.Toolbar");
|
||||
|
||||
#if UNITY_2019_1_OR_NEWER
|
||||
string fieldName = "k_ToolCount";
|
||||
#else
|
||||
string fieldName = "s_ShownToolIcons";
|
||||
#endif
|
||||
|
||||
FieldInfo toolIcons = toolbarType.GetField(fieldName,
|
||||
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
|
||||
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
m_toolCount = toolIcons != null ? ((int) toolIcons.GetValue(null)) : 8;
|
||||
#elif UNITY_2019_1_OR_NEWER
|
||||
m_toolCount = toolIcons != null ? ((int) toolIcons.GetValue(null)) : 7;
|
||||
#elif UNITY_2018_1_OR_NEWER
|
||||
m_toolCount = toolIcons != null ? ((Array) toolIcons.GetValue(null)).Length : 6;
|
||||
#else
|
||||
m_toolCount = toolIcons != null ? ((Array) toolIcons.GetValue(null)).Length : 5;
|
||||
#endif
|
||||
|
||||
ToolbarCallback.OnToolbarGUI = OnGUI;
|
||||
ToolbarCallback.OnToolbarGUILeft = GUILeft;
|
||||
ToolbarCallback.OnToolbarGUIRight = GUIRight;
|
||||
}
|
||||
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
public const float space = 8;
|
||||
#else
|
||||
public const float space = 10;
|
||||
#endif
|
||||
public const float largeSpace = 20;
|
||||
public const float buttonWidth = 32;
|
||||
public const float dropdownWidth = 80;
|
||||
#if UNITY_2019_1_OR_NEWER
|
||||
public const float playPauseStopWidth = 140;
|
||||
#else
|
||||
public const float playPauseStopWidth = 100;
|
||||
#endif
|
||||
|
||||
static void OnGUI()
|
||||
{
|
||||
// Create two containers, left and right
|
||||
// Screen is whole toolbar
|
||||
|
||||
if (m_commandStyle == null)
|
||||
{
|
||||
m_commandStyle = new GUIStyle("CommandLeft");
|
||||
}
|
||||
|
||||
var screenWidth = EditorGUIUtility.currentViewWidth;
|
||||
|
||||
// Following calculations match code reflected from Toolbar.OldOnGUI()
|
||||
float playButtonsPosition = Mathf.RoundToInt ((screenWidth - playPauseStopWidth) / 2);
|
||||
|
||||
Rect leftRect = new Rect(0, 0, screenWidth, Screen.height);
|
||||
leftRect.xMin += space; // Spacing left
|
||||
leftRect.xMin += buttonWidth * m_toolCount; // Tool buttons
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
leftRect.xMin += space; // Spacing between tools and pivot
|
||||
#else
|
||||
leftRect.xMin += largeSpace; // Spacing between tools and pivot
|
||||
#endif
|
||||
leftRect.xMin += 64 * 2; // Pivot buttons
|
||||
leftRect.xMax = playButtonsPosition;
|
||||
|
||||
Rect rightRect = new Rect(0, 0, screenWidth, Screen.height);
|
||||
rightRect.xMin = playButtonsPosition;
|
||||
rightRect.xMin += m_commandStyle.fixedWidth * 3; // Play buttons
|
||||
rightRect.xMax = screenWidth;
|
||||
rightRect.xMax -= space; // Spacing right
|
||||
rightRect.xMax -= dropdownWidth; // Layout
|
||||
rightRect.xMax -= space; // Spacing between layout and layers
|
||||
rightRect.xMax -= dropdownWidth; // Layers
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
rightRect.xMax -= space; // Spacing between layers and account
|
||||
#else
|
||||
rightRect.xMax -= largeSpace; // Spacing between layers and account
|
||||
#endif
|
||||
rightRect.xMax -= dropdownWidth; // Account
|
||||
rightRect.xMax -= space; // Spacing between account and cloud
|
||||
rightRect.xMax -= buttonWidth; // Cloud
|
||||
rightRect.xMax -= space; // Spacing between cloud and collab
|
||||
rightRect.xMax -= 78; // Colab
|
||||
|
||||
// Add spacing around existing controls
|
||||
leftRect.xMin += space;
|
||||
leftRect.xMax -= space;
|
||||
rightRect.xMin += space;
|
||||
rightRect.xMax -= space;
|
||||
|
||||
// Add top and bottom margins
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
leftRect.y = 4;
|
||||
leftRect.height = 22;
|
||||
rightRect.y = 4;
|
||||
rightRect.height = 22;
|
||||
#else
|
||||
leftRect.y = 5;
|
||||
leftRect.height = 24;
|
||||
rightRect.y = 5;
|
||||
rightRect.height = 24;
|
||||
#endif
|
||||
|
||||
if (leftRect.width > 0)
|
||||
{
|
||||
GUILayout.BeginArea(leftRect);
|
||||
GUILayout.BeginHorizontal();
|
||||
foreach (var handler in LeftToolbarGUI)
|
||||
{
|
||||
handler();
|
||||
}
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.EndArea();
|
||||
}
|
||||
|
||||
if (rightRect.width > 0)
|
||||
{
|
||||
GUILayout.BeginArea(rightRect);
|
||||
GUILayout.BeginHorizontal();
|
||||
foreach (var handler in RightToolbarGUI)
|
||||
{
|
||||
handler();
|
||||
}
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.EndArea();
|
||||
}
|
||||
}
|
||||
|
||||
public static void GUILeft() {
|
||||
GUILayout.BeginHorizontal();
|
||||
foreach (var handler in LeftToolbarGUI)
|
||||
{
|
||||
handler();
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
public static void GUIRight() {
|
||||
GUILayout.BeginHorizontal();
|
||||
foreach (var handler in RightToolbarGUI)
|
||||
{
|
||||
handler();
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7b71421f0295dfa4f9c32f3ace45690d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
3
UnityProject/Assets/Editor/UIScriptGenerator.meta
Normal file
3
UnityProject/Assets/Editor/UIScriptGenerator.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 12cde5e16fa64eab883975bd63fc5077
|
||||
timeCreated: 1741968067
|
313
UnityProject/Assets/Editor/UIScriptGenerator/ScriptGenerator.cs
Normal file
313
UnityProject/Assets/Editor/UIScriptGenerator/ScriptGenerator.cs
Normal file
@@ -0,0 +1,313 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TEngine.Editor.UI
|
||||
{
|
||||
public class ScriptGenerator
|
||||
{
|
||||
private const string Gap = "/";
|
||||
|
||||
[MenuItem("GameObject/ScriptGenerator/UIProperty", priority = 41)]
|
||||
public static void MemberProperty()
|
||||
{
|
||||
Generate(false);
|
||||
}
|
||||
|
||||
[MenuItem("GameObject/ScriptGenerator/UIProperty - UniTask", priority = 43)]
|
||||
public static void MemberPropertyUniTask()
|
||||
{
|
||||
Generate(false, true);
|
||||
}
|
||||
|
||||
[MenuItem("GameObject/ScriptGenerator/UIPropertyAndListener", priority = 42)]
|
||||
public static void MemberPropertyAndListener()
|
||||
{
|
||||
Generate(true);
|
||||
}
|
||||
|
||||
[MenuItem("GameObject/ScriptGenerator/UIPropertyAndListener - UniTask", priority = 44)]
|
||||
public static void MemberPropertyAndListenerUniTask()
|
||||
{
|
||||
Generate(true, true);
|
||||
}
|
||||
|
||||
private static void Generate(bool includeListener, bool isUniTask = false)
|
||||
{
|
||||
var root = Selection.activeTransform;
|
||||
if (root != null)
|
||||
{
|
||||
StringBuilder strVar = new StringBuilder();
|
||||
StringBuilder strBind = new StringBuilder();
|
||||
StringBuilder strOnCreate = new StringBuilder();
|
||||
StringBuilder strCallback = new StringBuilder();
|
||||
Ergodic(root, root, ref strVar, ref strBind, ref strOnCreate, ref strCallback, isUniTask);
|
||||
StringBuilder strFile = new StringBuilder();
|
||||
|
||||
if (includeListener)
|
||||
{
|
||||
#if ENABLE_TEXTMESHPRO
|
||||
strFile.Append("using TMPro;\n");
|
||||
#endif
|
||||
if (isUniTask)
|
||||
{
|
||||
strFile.Append("using Cysharp.Threading.Tasks;\n");
|
||||
}
|
||||
|
||||
strFile.Append("using UnityEngine;\n");
|
||||
strFile.Append("using UnityEngine.UI;\n");
|
||||
strFile.Append("using TEngine;\n\n");
|
||||
strFile.Append($"namespace {ScriptGeneratorSetting.GetUINameSpace()}\n");
|
||||
strFile.Append("{\n");
|
||||
|
||||
var widgetPrefix = $"{(ScriptGeneratorSetting.GetCodeStyle() == UIFieldCodeStyle.MPrefix ? "m_" : "_")}{ScriptGeneratorSetting.GetWidgetName()}";
|
||||
if (root.name.StartsWith(widgetPrefix))
|
||||
{
|
||||
strFile.Append("\tclass " + root.name.Replace(widgetPrefix, "") + " : UIWidget\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
strFile.Append("\t[Window(UILayer.UI)]\n");
|
||||
strFile.Append("\tclass " + root.name + " : UIWindow\n");
|
||||
}
|
||||
|
||||
strFile.Append("\t{\n");
|
||||
}
|
||||
|
||||
// 脚本工具生成的代码
|
||||
strFile.Append("\t\t#region 脚本工具生成的代码\n");
|
||||
strFile.Append(strVar);
|
||||
strFile.Append("\t\tprotected override void ScriptGenerator()\n");
|
||||
strFile.Append("\t\t{\n");
|
||||
strFile.Append(strBind);
|
||||
strFile.Append(strOnCreate);
|
||||
strFile.Append("\t\t}\n");
|
||||
strFile.Append("\t\t#endregion");
|
||||
|
||||
if (includeListener)
|
||||
{
|
||||
strFile.Append("\n\n");
|
||||
// #region 事件
|
||||
strFile.Append("\t\t#region 事件\n");
|
||||
strFile.Append(strCallback);
|
||||
strFile.Append("\t\t#endregion\n\n");
|
||||
|
||||
strFile.Append("\t}\n");
|
||||
strFile.Append("}\n");
|
||||
}
|
||||
|
||||
TextEditor te = new TextEditor();
|
||||
te.text = strFile.ToString();
|
||||
te.SelectAll();
|
||||
te.Copy();
|
||||
}
|
||||
|
||||
Debug.Log($"脚本已生成到剪贴板,请自行Ctl+V粘贴");
|
||||
}
|
||||
|
||||
public static void Ergodic(Transform root, Transform transform, ref StringBuilder strVar, ref StringBuilder strBind, ref StringBuilder strOnCreate,
|
||||
ref StringBuilder strCallback, bool isUniTask)
|
||||
{
|
||||
for (int i = 0; i < transform.childCount; ++i)
|
||||
{
|
||||
Transform child = transform.GetChild(i);
|
||||
WriteScript(root, child, ref strVar, ref strBind, ref strOnCreate, ref strCallback, isUniTask);
|
||||
if (child.name.StartsWith("m_item"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Ergodic(root, child, ref strVar, ref strBind, ref strOnCreate, ref strCallback, isUniTask);
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetRelativePath(Transform child, Transform root)
|
||||
{
|
||||
StringBuilder path = new StringBuilder();
|
||||
path.Append(child.name);
|
||||
while (child.parent != null && child.parent != root)
|
||||
{
|
||||
child = child.parent;
|
||||
path.Insert(0, Gap);
|
||||
path.Insert(0, child.name);
|
||||
}
|
||||
|
||||
return path.ToString();
|
||||
}
|
||||
|
||||
public static string GetBtnFuncName(string varName)
|
||||
{
|
||||
var codeStyle = ScriptGeneratorSetting.Instance.CodeStyle;
|
||||
if (codeStyle == UIFieldCodeStyle.MPrefix)
|
||||
{
|
||||
return "OnClick" + varName.Replace("m_btn", string.Empty) + "Btn";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "OnClick" + varName.Replace("_btn", string.Empty) + "Btn";
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetToggleFuncName(string varName)
|
||||
{
|
||||
var codeStyle = ScriptGeneratorSetting.Instance.CodeStyle;
|
||||
if (codeStyle == UIFieldCodeStyle.MPrefix)
|
||||
{
|
||||
return "OnToggle" + varName.Replace("m_toggle", string.Empty) + "Change";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "OnToggle" + varName.Replace("_toggle", string.Empty) + "Change";
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetSliderFuncName(string varName)
|
||||
{
|
||||
var codeStyle = ScriptGeneratorSetting.Instance.CodeStyle;
|
||||
if (codeStyle == UIFieldCodeStyle.MPrefix)
|
||||
{
|
||||
return "OnSlider" + varName.Replace("m_slider", string.Empty) + "Change";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "OnSlider" + varName.Replace("_slider", string.Empty) + "Change";
|
||||
}
|
||||
}
|
||||
|
||||
private static void WriteScript(Transform root, Transform child, ref StringBuilder strVar, ref StringBuilder strBind, ref StringBuilder strOnCreate,
|
||||
ref StringBuilder strCallback, bool isUniTask)
|
||||
{
|
||||
string varName = child.name;
|
||||
|
||||
string componentName = string.Empty;
|
||||
|
||||
var rule = ScriptGeneratorSetting.GetScriptGenerateRule().Find(t => varName.StartsWith(t.uiElementRegex));
|
||||
|
||||
if (rule != null)
|
||||
{
|
||||
componentName = rule.componentName;
|
||||
}
|
||||
|
||||
bool isUIWidget = rule is { isUIWidget: true };
|
||||
|
||||
if (componentName == string.Empty)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var codeStyle = ScriptGeneratorSetting.Instance.CodeStyle;
|
||||
if (codeStyle == UIFieldCodeStyle.UnderscorePrefix)
|
||||
{
|
||||
if (varName.StartsWith("_"))
|
||||
{
|
||||
|
||||
}
|
||||
else if(varName.StartsWith("m_"))
|
||||
{
|
||||
varName = varName.Substring(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
varName = $"_{varName}";
|
||||
}
|
||||
}
|
||||
else if (codeStyle == UIFieldCodeStyle.MPrefix)
|
||||
{
|
||||
if (varName.StartsWith("m_"))
|
||||
{
|
||||
|
||||
}
|
||||
else if (varName.StartsWith("_"))
|
||||
{
|
||||
varName = $"m{varName}";
|
||||
}
|
||||
else
|
||||
{
|
||||
varName = $"m_{varName}";
|
||||
}
|
||||
}
|
||||
|
||||
string varPath = GetRelativePath(child, root);
|
||||
if (!string.IsNullOrEmpty(varName))
|
||||
{
|
||||
strVar.Append("\t\tprivate " + componentName + " " + varName + ";\n");
|
||||
switch (componentName)
|
||||
{
|
||||
case "Transform":
|
||||
strBind.Append($"\t\t\t{varName} = FindChild(\"{varPath}\");\n");
|
||||
break;
|
||||
case "GameObject":
|
||||
strBind.Append($"\t\t\t{varName} = FindChild(\"{varPath}\").gameObject;\n");
|
||||
break;
|
||||
case "AnimationCurve":
|
||||
strBind.Append($"\t\t\t{varName} = FindChildComponent<AnimCurveObject>(\"{varPath}\").m_animCurve;\n");
|
||||
break;
|
||||
default:
|
||||
if (isUIWidget)
|
||||
{
|
||||
strBind.Append($"\t\t\t{varName} = CreateWidgetByType<{componentName}>(\"{varPath}\");\n");
|
||||
}
|
||||
strBind.Append($"\t\t\t{varName} = FindChildComponent<{componentName}>(\"{varPath}\");\n");
|
||||
break;
|
||||
}
|
||||
|
||||
if (componentName == "Button")
|
||||
{
|
||||
string varFuncName = GetBtnFuncName(varName);
|
||||
if (isUniTask)
|
||||
{
|
||||
strOnCreate.Append($"\t\t\t{varName}.onClick.AddListener(UniTask.UnityAction({varFuncName}));\n");
|
||||
strCallback.Append($"\t\tprivate async UniTaskVoid {varFuncName}()\n");
|
||||
strCallback.Append("\t\t{\n await UniTask.Yield();\n\t\t}\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
strOnCreate.Append($"\t\t\t{varName}.onClick.AddListener({varFuncName});\n");
|
||||
strCallback.Append($"\t\tprivate void {varFuncName}()\n");
|
||||
strCallback.Append("\t\t{\n\t\t}\n");
|
||||
}
|
||||
}
|
||||
else if (componentName == "Toggle")
|
||||
{
|
||||
string varFuncName = GetToggleFuncName(varName);
|
||||
strOnCreate.Append($"\t\t\t{varName}.onValueChanged.AddListener({varFuncName});\n");
|
||||
strCallback.Append($"\t\tprivate void {varFuncName}(bool isOn)\n");
|
||||
strCallback.Append("\t\t{\n\t\t}\n");
|
||||
}
|
||||
else if (componentName == "Slider")
|
||||
{
|
||||
string varFuncName = GetSliderFuncName(varName);
|
||||
strOnCreate.Append($"\t\t\t{varName}.onValueChanged.AddListener({varFuncName});\n");
|
||||
strCallback.Append($"\t\tprivate void {varFuncName}(float value)\n");
|
||||
strCallback.Append("\t\t{\n\t\t}\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class GeneratorHelper : EditorWindow
|
||||
{
|
||||
[MenuItem("GameObject/ScriptGenerator/About", priority = 49)]
|
||||
public static void About()
|
||||
{
|
||||
GeneratorHelper welcomeWindow = (GeneratorHelper)EditorWindow.GetWindow(typeof(GeneratorHelper), false, "About");
|
||||
}
|
||||
|
||||
public void Awake()
|
||||
{
|
||||
minSize = new Vector2(400, 600);
|
||||
}
|
||||
|
||||
protected void OnGUI()
|
||||
{
|
||||
GUILayout.BeginVertical();
|
||||
foreach (var item in ScriptGeneratorSetting.GetScriptGenerateRule())
|
||||
{
|
||||
GUILayout.Label(item.uiElementRegex + ":\t" + item.componentName);
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9e5b80682b2036f42b69fcb09c53863a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,82 @@
|
||||
%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: f8a0dfbcd6854965bb6ae78627009a53, type: 3}
|
||||
m_Name: ScriptGeneratorSetting
|
||||
m_EditorClassIdentifier:
|
||||
_codePath:
|
||||
_namespace: GameLogic
|
||||
_widgetName: item
|
||||
CodeStyle: 0
|
||||
scriptGenerateRule:
|
||||
- uiElementRegex: m_go
|
||||
componentName: GameObject
|
||||
isUIWidget: 0
|
||||
- uiElementRegex: m_item
|
||||
componentName: GameObject
|
||||
isUIWidget: 0
|
||||
- uiElementRegex: m_tf
|
||||
componentName: Transform
|
||||
isUIWidget: 0
|
||||
- uiElementRegex: m_rect
|
||||
componentName: RectTransform
|
||||
isUIWidget: 0
|
||||
- uiElementRegex: m_text
|
||||
componentName: Text
|
||||
isUIWidget: 0
|
||||
- uiElementRegex: m_richText
|
||||
componentName: RichTextItem
|
||||
isUIWidget: 0
|
||||
- uiElementRegex: m_btn
|
||||
componentName: Button
|
||||
isUIWidget: 0
|
||||
- uiElementRegex: m_img
|
||||
componentName: Image
|
||||
isUIWidget: 0
|
||||
- uiElementRegex: m_rimg
|
||||
componentName: RawImage
|
||||
isUIWidget: 0
|
||||
- uiElementRegex: m_scrollBar
|
||||
componentName: Scrollbar
|
||||
isUIWidget: 0
|
||||
- uiElementRegex: m_scroll
|
||||
componentName: ScrollRect
|
||||
isUIWidget: 0
|
||||
- uiElementRegex: m_input
|
||||
componentName: InputField
|
||||
isUIWidget: 0
|
||||
- uiElementRegex: m_grid
|
||||
componentName: GridLayoutGroup
|
||||
isUIWidget: 0
|
||||
- uiElementRegex: m_hlay
|
||||
componentName: HorizontalLayoutGroup
|
||||
isUIWidget: 0
|
||||
- uiElementRegex: m_vlay
|
||||
componentName: VerticalLayoutGroup
|
||||
isUIWidget: 0
|
||||
- uiElementRegex: m_slider
|
||||
componentName: Slider
|
||||
isUIWidget: 0
|
||||
- uiElementRegex: m_toggle
|
||||
componentName: Toggle
|
||||
isUIWidget: 0
|
||||
- uiElementRegex: m_group
|
||||
componentName: ToggleGroup
|
||||
isUIWidget: 0
|
||||
- uiElementRegex: m_curve
|
||||
componentName: AnimationCurve
|
||||
isUIWidget: 0
|
||||
- uiElementRegex: m_canvasGroup
|
||||
componentName: CanvasGroup
|
||||
isUIWidget: 0
|
||||
- uiElementRegex: m_tmp
|
||||
componentName: TextMeshProUGUI
|
||||
isUIWidget: 0
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fe8fecac349dd7a4cafb77822cdba64a
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,195 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TEngine.Editor.UI
|
||||
{
|
||||
public enum UIFieldCodeStyle
|
||||
{
|
||||
/// <summary>
|
||||
/// Field names start with underscore (e.g., _variable)
|
||||
/// </summary>
|
||||
[InspectorName("Field names start with underscore (e.g., _variable)")]
|
||||
UnderscorePrefix,
|
||||
|
||||
/// <summary>
|
||||
/// Field names start with m_ prefix (e.g., m_variable)
|
||||
/// </summary>
|
||||
[InspectorName("Field names start with m_ prefix (e.g., m_variable)")]
|
||||
MPrefix,
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class ScriptGenerateRuler
|
||||
{
|
||||
public string uiElementRegex;
|
||||
public string componentName;
|
||||
public bool isUIWidget = false;
|
||||
|
||||
public ScriptGenerateRuler(string uiElementRegex, string componentName, bool isUIWidget = false)
|
||||
{
|
||||
this.uiElementRegex = uiElementRegex;
|
||||
this.componentName = componentName;
|
||||
this.isUIWidget = isUIWidget;
|
||||
}
|
||||
}
|
||||
|
||||
[CustomPropertyDrawer(typeof(ScriptGenerateRuler))]
|
||||
public class ScriptGenerateRulerDrawer : PropertyDrawer
|
||||
{
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
EditorGUI.BeginProperty(position, label, property);
|
||||
position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);
|
||||
var indent = EditorGUI.indentLevel;
|
||||
EditorGUI.indentLevel = 0;
|
||||
var uiElementRegexRect = new Rect(position.x, position.y, 120, position.height);
|
||||
var componentNameRect = new Rect(position.x + 125, position.y, 150, position.height);
|
||||
var isUIWidgetRect = new Rect(position.x + 325, position.y, 150, position.height);
|
||||
EditorGUI.PropertyField(uiElementRegexRect, property.FindPropertyRelative("uiElementRegex"), GUIContent.none);
|
||||
EditorGUI.PropertyField(componentNameRect, property.FindPropertyRelative("componentName"), GUIContent.none);
|
||||
EditorGUI.PropertyField(isUIWidgetRect, property.FindPropertyRelative("isUIWidget"), GUIContent.none);
|
||||
EditorGUI.indentLevel = indent;
|
||||
EditorGUI.EndProperty();
|
||||
}
|
||||
}
|
||||
|
||||
[CreateAssetMenu(menuName = "TEngine/ScriptGeneratorSetting", fileName = "ScriptGeneratorSetting")]
|
||||
public class ScriptGeneratorSetting : ScriptableObject
|
||||
{
|
||||
private static ScriptGeneratorSetting _instance;
|
||||
|
||||
public static ScriptGeneratorSetting Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_instance == null)
|
||||
{
|
||||
string[] guids = AssetDatabase.FindAssets("t:ScriptGeneratorSetting");
|
||||
if (guids.Length >= 1)
|
||||
{
|
||||
string path = AssetDatabase.GUIDToAssetPath(guids[0]);
|
||||
_instance = AssetDatabase.LoadAssetAtPath<ScriptGeneratorSetting>(path);
|
||||
}
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
|
||||
// [FolderPath]
|
||||
// [LabelText("默认组件代码保存路径")]
|
||||
[SerializeField]
|
||||
private string _codePath;
|
||||
|
||||
// [LabelText("绑定代码命名空间")]
|
||||
[SerializeField]
|
||||
private string _namespace = "GameLogic";
|
||||
|
||||
// [LabelText("子组件名称(不会往下继续遍历)")]
|
||||
[SerializeField]
|
||||
private string _widgetName = "item";
|
||||
|
||||
public string CodePath => _codePath;
|
||||
|
||||
public string Namespace => _namespace;
|
||||
|
||||
public string WidgetName => _widgetName;
|
||||
|
||||
public UIFieldCodeStyle CodeStyle = UIFieldCodeStyle.UnderscorePrefix;
|
||||
|
||||
[SerializeField]
|
||||
private List<ScriptGenerateRuler> scriptGenerateRule = new List<ScriptGenerateRuler>()
|
||||
{
|
||||
new ScriptGenerateRuler("m_go", "GameObject"),
|
||||
new ScriptGenerateRuler("m_item", "GameObject"),
|
||||
new ScriptGenerateRuler("m_tf", "Transform"),
|
||||
new ScriptGenerateRuler("m_rect", "RectTransform"),
|
||||
new ScriptGenerateRuler("m_text", "Text"),
|
||||
new ScriptGenerateRuler("m_richText", "RichTextItem"),
|
||||
new ScriptGenerateRuler("m_btn", "Button"),
|
||||
new ScriptGenerateRuler("m_img", "Image"),
|
||||
new ScriptGenerateRuler("m_rimg", "RawImage"),
|
||||
new ScriptGenerateRuler("m_scrollBar", "Scrollbar"),
|
||||
new ScriptGenerateRuler("m_scroll", "ScrollRect"),
|
||||
new ScriptGenerateRuler("m_input", "InputField"),
|
||||
new ScriptGenerateRuler("m_grid", "GridLayoutGroup"),
|
||||
new ScriptGenerateRuler("m_hlay", "HorizontalLayoutGroup"),
|
||||
new ScriptGenerateRuler("m_vlay", "VerticalLayoutGroup"),
|
||||
new ScriptGenerateRuler("m_slider", "Slider"),
|
||||
new ScriptGenerateRuler("m_group", "ToggleGroup"),
|
||||
new ScriptGenerateRuler("m_curve", "AnimationCurve"),
|
||||
new ScriptGenerateRuler("m_canvasGroup", "CanvasGroup"),
|
||||
new ScriptGenerateRuler("m_tmp","TextMeshProUGUI"),
|
||||
};
|
||||
|
||||
public List<ScriptGenerateRuler> ScriptGenerateRule => scriptGenerateRule;
|
||||
|
||||
|
||||
[MenuItem("TEngine/Create ScriptGeneratorSetting")]
|
||||
private static void CreateAutoBindGlobalSetting()
|
||||
{
|
||||
string[] paths = AssetDatabase.FindAssets("t:ScriptGeneratorSetting");
|
||||
if (paths.Length >= 1)
|
||||
{
|
||||
string path = AssetDatabase.GUIDToAssetPath(paths[0]);
|
||||
EditorUtility.DisplayDialog("警告", $"已存在ScriptGeneratorSetting,路径:{path}", "确认");
|
||||
return;
|
||||
}
|
||||
|
||||
ScriptGeneratorSetting setting = CreateInstance<ScriptGeneratorSetting>();
|
||||
AssetDatabase.CreateAsset(setting, "Assets/Editor/ScriptGeneratorSetting.asset");
|
||||
AssetDatabase.SaveAssets();
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
|
||||
public static List<ScriptGenerateRuler> GetScriptGenerateRule()
|
||||
{
|
||||
if (Instance == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return Instance.ScriptGenerateRule;
|
||||
}
|
||||
|
||||
public static string GetUINameSpace()
|
||||
{
|
||||
if (Instance == null)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
return Instance.Namespace;
|
||||
}
|
||||
|
||||
public static UIFieldCodeStyle GetCodeStyle()
|
||||
{
|
||||
if (Instance == null)
|
||||
{
|
||||
return UIFieldCodeStyle.UnderscorePrefix;
|
||||
}
|
||||
|
||||
return Instance.CodeStyle;
|
||||
}
|
||||
|
||||
public static string GetCodePath()
|
||||
{
|
||||
if (Instance == null)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
return Instance.CodePath;
|
||||
}
|
||||
|
||||
public static string GetWidgetName()
|
||||
{
|
||||
if (Instance == null)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
return Instance.WidgetName;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f8a0dfbcd6854965bb6ae78627009a53
|
||||
timeCreated: 1741968155
|
Reference in New Issue
Block a user