diff --git a/UnityProject/Assets/GameScripts/HotFix/GameBase.meta b/UnityProject/Assets/Editor/AssetBundleCollector.meta similarity index 77% rename from UnityProject/Assets/GameScripts/HotFix/GameBase.meta rename to UnityProject/Assets/Editor/AssetBundleCollector.meta index d546d960..e037c926 100644 --- a/UnityProject/Assets/GameScripts/HotFix/GameBase.meta +++ b/UnityProject/Assets/Editor/AssetBundleCollector.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 6635aa4e94cc66546b8b89c48f0a0099 +guid: 9afd4d88f7b567341823779947b83bd9 folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/UnityProject/Assets/TEngine/AssetSetting/AssetBundleCollectorConfig.xml b/UnityProject/Assets/Editor/AssetBundleCollector/AssetBundleCollectorConfig.xml similarity index 65% rename from UnityProject/Assets/TEngine/AssetSetting/AssetBundleCollectorConfig.xml rename to UnityProject/Assets/Editor/AssetBundleCollector/AssetBundleCollectorConfig.xml index 8a611403..4b6bfd7f 100644 --- a/UnityProject/Assets/TEngine/AssetSetting/AssetBundleCollectorConfig.xml +++ b/UnityProject/Assets/Editor/AssetBundleCollector/AssetBundleCollectorConfig.xml @@ -1,40 +1,48 @@  - - - - + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + \ No newline at end of file diff --git a/UnityProject/Assets/TEngine/AssetSetting/AssetBundleCollectorConfig.xml.meta b/UnityProject/Assets/Editor/AssetBundleCollector/AssetBundleCollectorConfig.xml.meta similarity index 75% rename from UnityProject/Assets/TEngine/AssetSetting/AssetBundleCollectorConfig.xml.meta rename to UnityProject/Assets/Editor/AssetBundleCollector/AssetBundleCollectorConfig.xml.meta index 3ae38d6b..f1155c31 100644 --- a/UnityProject/Assets/TEngine/AssetSetting/AssetBundleCollectorConfig.xml.meta +++ b/UnityProject/Assets/Editor/AssetBundleCollector/AssetBundleCollectorConfig.xml.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 218816e46e4f6304eaecd6fdc3a99f4d +guid: 40551812c908533438dbfc2b727c9950 TextScriptImporter: externalObjects: {} userData: diff --git a/UnityProject/Assets/TEngine/AssetSetting/AssetBundleCollectorSetting.asset b/UnityProject/Assets/Editor/AssetBundleCollector/AssetBundleCollectorSetting.asset similarity index 72% rename from UnityProject/Assets/TEngine/AssetSetting/AssetBundleCollectorSetting.asset rename to UnityProject/Assets/Editor/AssetBundleCollector/AssetBundleCollectorSetting.asset index 8d95bae6..97995c8b 100644 --- a/UnityProject/Assets/TEngine/AssetSetting/AssetBundleCollectorSetting.asset +++ b/UnityProject/Assets/Editor/AssetBundleCollector/AssetBundleCollectorSetting.asset @@ -12,12 +12,12 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 185f6993d5150494d98da50e26cb1c25, type: 3} m_Name: AssetBundleCollectorSetting m_EditorClassIdentifier: - ShowPackageView: 0 + ShowPackageView: 1 ShowEditorAlias: 0 - UniqueBundleName: 0 + UniqueBundleName: 1 Packages: - PackageName: DefaultPackage - PackageDesc: "\u9ED8\u8BA4\u8D44\u6E90\u5305" + PackageDesc: EnableAddressable: 1 LocationToLower: 0 IncludeAssetGUID: 0 @@ -25,8 +25,8 @@ MonoBehaviour: AutoCollectShaders: 1 Groups: - GroupName: Actor - GroupDesc: "\u89D2\u8272" - AssetTags: Actor + GroupDesc: + AssetTags: ActiveRuleName: EnableGroup Collectors: - CollectPath: Assets/AssetRaw/Actor @@ -37,9 +37,113 @@ MonoBehaviour: 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: "\u56FE\u7247\u8D44\u6E90" - AssetTags: UIRaw + GroupDesc: + AssetTags: ActiveRuleName: EnableGroup Collectors: - CollectPath: Assets/AssetRaw/UIRaw/Atlas @@ -58,120 +162,52 @@ MonoBehaviour: FilterRuleName: CollectAll AssetTags: UserData: - - GroupName: Audios - GroupDesc: "\u97F3\u9891" - AssetTags: Audios + - PackageName: OtherPackage + PackageDesc: + EnableAddressable: 1 + LocationToLower: 0 + IncludeAssetGUID: 0 + IgnoreDefaultType: 1 + AutoCollectShaders: 1 + Groups: + - GroupName: ModelGroup + GroupDesc: + AssetTags: models ActiveRuleName: EnableGroup - Collectors: - - CollectPath: Assets/AssetRaw/Audios - CollectorGUID: 8ef7a411b66e70f4cb65c2233c9a0868 - CollectorType: 0 - AddressRuleName: AddressByFileName - PackRuleName: PackDirectory - FilterRuleName: CollectAll - AssetTags: - UserData: - - GroupName: Configs - GroupDesc: "\u914D\u7F6E\u8868" - AssetTags: Configs + Collectors: [] + - GroupName: SceneGroup + GroupDesc: + AssetTags: scenes ActiveRuleName: EnableGroup - Collectors: - - CollectPath: Assets/AssetRaw/Configs - CollectorGUID: dd2928019aef34248af368b99bc53bea - CollectorType: 0 - AddressRuleName: AddressByFileName - PackRuleName: PackDirectory - FilterRuleName: CollectAll - AssetTags: WEBGL_PRELOAD - UserData: - - GroupName: DLL - GroupDesc: "\u4EE3\u7801" - AssetTags: DLL + Collectors: [] + - PackageName: Dlc1Package + PackageDesc: + EnableAddressable: 1 + LocationToLower: 0 + IncludeAssetGUID: 0 + IgnoreDefaultType: 1 + AutoCollectShaders: 1 + Groups: + - GroupName: ModelGroup + GroupDesc: + AssetTags: models ActiveRuleName: EnableGroup - Collectors: - - CollectPath: Assets/AssetRaw/DLL - CollectorGUID: 3aad79ec1ea08c24c891bd3c669d4125 - CollectorType: 0 - AddressRuleName: AddressByFileName - PackRuleName: PackDirectory - FilterRuleName: CollectAll - AssetTags: - UserData: - - GroupName: Effects - GroupDesc: "\u7279\u6548" - AssetTags: Effects + Collectors: [] + - GroupName: SceneGroup + GroupDesc: + AssetTags: scenes ActiveRuleName: EnableGroup - Collectors: - - CollectPath: Assets/AssetRaw/Effects - CollectorGUID: 0fe175e1e1bd49a4ca71e66b6a9b7237 - CollectorType: 0 - AddressRuleName: AddressByFileName - PackRuleName: PackDirectory - FilterRuleName: CollectAll - AssetTags: - UserData: - - GroupName: Materials - GroupDesc: "\u6750\u8D28\u7403" - AssetTags: Materials + Collectors: [] + - PackageName: Dlc2Package + PackageDesc: + EnableAddressable: 1 + LocationToLower: 0 + IncludeAssetGUID: 0 + IgnoreDefaultType: 1 + AutoCollectShaders: 1 + Groups: + - GroupName: ModelGroup + GroupDesc: + AssetTags: models ActiveRuleName: EnableGroup - Collectors: - - CollectPath: Assets/AssetRaw/Materials - CollectorGUID: 228b1547e7065d546ad0bf215fd6a276 - CollectorType: 0 - AddressRuleName: AddressByFileName - PackRuleName: PackDirectory - FilterRuleName: CollectAll - AssetTags: - UserData: - - GroupName: Scenes - GroupDesc: "\u573A\u666F" - AssetTags: Scenes - ActiveRuleName: EnableGroup - Collectors: - - CollectPath: Assets/AssetRaw/Scenes - CollectorGUID: cace6ee6539f661419b5e5f8ae1c0146 - CollectorType: 0 - AddressRuleName: AddressByFileName - PackRuleName: PackSeparately - FilterRuleName: CollectAll - AssetTags: - UserData: - - GroupName: Shaders - GroupDesc: "\u7740\u8272\u5668" - AssetTags: Shaders - ActiveRuleName: EnableGroup - Collectors: - - CollectPath: Assets/AssetRaw/Shaders - CollectorGUID: 2a4bceb84ed685447ace957f497eb810 - CollectorType: 0 - AddressRuleName: AddressByFileName - PackRuleName: PackShaderVariants - FilterRuleName: CollectShaderVariants - AssetTags: - UserData: - - GroupName: UI - GroupDesc: "UI\u9762\u677F" - AssetTags: UI - ActiveRuleName: EnableGroup - Collectors: - - CollectPath: Assets/AssetRaw/UI - CollectorGUID: 27e87d83814156648b58f380b834e046 - CollectorType: 0 - AddressRuleName: AddressByFileName - PackRuleName: PackSeparately - FilterRuleName: CollectAll - AssetTags: - UserData: - - GroupName: Fonts - GroupDesc: "\u5B57\u4F53" - AssetTags: Fonts - ActiveRuleName: EnableGroup - Collectors: - - CollectPath: Assets/AssetRaw/Fonts - CollectorGUID: 2473375c9ee163a4b861278b38091455 - CollectorType: 0 - AddressRuleName: AddressByFileName - PackRuleName: PackDirectory - FilterRuleName: CollectAll - AssetTags: - UserData: + Collectors: [] diff --git a/UnityProject/Assets/TEngine/AssetSetting/AssetBundleCollectorSetting.asset.meta b/UnityProject/Assets/Editor/AssetBundleCollector/AssetBundleCollectorSetting.asset.meta similarity index 79% rename from UnityProject/Assets/TEngine/AssetSetting/AssetBundleCollectorSetting.asset.meta rename to UnityProject/Assets/Editor/AssetBundleCollector/AssetBundleCollectorSetting.asset.meta index b35e5acb..34a50aaa 100644 --- a/UnityProject/Assets/TEngine/AssetSetting/AssetBundleCollectorSetting.asset.meta +++ b/UnityProject/Assets/Editor/AssetBundleCollector/AssetBundleCollectorSetting.asset.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 007a65bdc7416fd4a8823ff50f753d50 +guid: c0d90477c8489f0438ae73994ff045b9 NativeFormatImporter: externalObjects: {} mainObjectFileID: 11400000 diff --git a/UnityProject/Assets/Editor/I2Localization.meta b/UnityProject/Assets/Editor/I2Localization.meta index 7b739cf6..d63e7076 100644 --- a/UnityProject/Assets/Editor/I2Localization.meta +++ b/UnityProject/Assets/Editor/I2Localization.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 4c9eb26aee01e8643bd4e6dc965d3366 +guid: f183cc1bcf4014f4c80a8580caabcd3f folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/UnityProject/Assets/Editor/I2Localization/I2Languages.asset.meta b/UnityProject/Assets/Editor/I2Localization/I2Languages.asset.meta index c099f85f..57c0c7c2 100644 --- a/UnityProject/Assets/Editor/I2Localization/I2Languages.asset.meta +++ b/UnityProject/Assets/Editor/I2Localization/I2Languages.asset.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: f069f2f03dfa55843a74dedc551eefb2 +guid: 50fd67a84c64e184c85bf3e1e343ba87 NativeFormatImporter: externalObjects: {} mainObjectFileID: 11400000 diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SuperScrollView/Scripts/Common.meta b/UnityProject/Assets/Editor/TEngineSettingsProvider.meta similarity index 77% rename from UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SuperScrollView/Scripts/Common.meta rename to UnityProject/Assets/Editor/TEngineSettingsProvider.meta index e261ad68..fd9d1249 100644 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SuperScrollView/Scripts/Common.meta +++ b/UnityProject/Assets/Editor/TEngineSettingsProvider.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 0fcee77031f85f84dbc6735c875d64b8 +guid: cace8d5078f400048a8afde10e2bf41d folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/UnityProject/Assets/Editor/TEngineSettingsProvider/TEngineSettingsProvider.cs b/UnityProject/Assets/Editor/TEngineSettingsProvider/TEngineSettingsProvider.cs new file mode 100644 index 00000000..9e87336b --- /dev/null +++ b/UnityProject/Assets/Editor/TEngineSettingsProvider/TEngineSettingsProvider.cs @@ -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" } + }; + } +} diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SuperScrollView/Scripts/Common/ClickEventListener.cs.meta b/UnityProject/Assets/Editor/TEngineSettingsProvider/TEngineSettingsProvider.cs.meta similarity index 83% rename from UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SuperScrollView/Scripts/Common/ClickEventListener.cs.meta rename to UnityProject/Assets/Editor/TEngineSettingsProvider/TEngineSettingsProvider.cs.meta index df67811a..0750eb5a 100644 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SuperScrollView/Scripts/Common/ClickEventListener.cs.meta +++ b/UnityProject/Assets/Editor/TEngineSettingsProvider/TEngineSettingsProvider.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: aa13a2165836fda459a6c28562ac101a +guid: f1c738d23f551c84e9e12af687389aeb MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/UnityProject/Assets/Editor/TEngineSettingsProvider/TEngineUISettingsProvider.cs b/UnityProject/Assets/Editor/TEngineSettingsProvider/TEngineUISettingsProvider.cs new file mode 100644 index 00000000..de6a7ab6 --- /dev/null +++ b/UnityProject/Assets/Editor/TEngineSettingsProvider/TEngineUISettingsProvider.cs @@ -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" } + }; + } +} diff --git a/UnityProject/Assets/Editor/TEngineSettingsProvider/TEngineUISettingsProvider.cs.meta b/UnityProject/Assets/Editor/TEngineSettingsProvider/TEngineUISettingsProvider.cs.meta new file mode 100644 index 00000000..6cf578e8 --- /dev/null +++ b/UnityProject/Assets/Editor/TEngineSettingsProvider/TEngineUISettingsProvider.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 2672376ad13242bcb6869e90c4def052 +timeCreated: 1742814408 \ No newline at end of file diff --git a/UnityProject/Assets/TEngine/Editor/ToolbarExtender.meta b/UnityProject/Assets/Editor/ToolbarExtender.meta similarity index 77% rename from UnityProject/Assets/TEngine/Editor/ToolbarExtender.meta rename to UnityProject/Assets/Editor/ToolbarExtender.meta index 4c76858d..36d56074 100644 --- a/UnityProject/Assets/TEngine/Editor/ToolbarExtender.meta +++ b/UnityProject/Assets/Editor/ToolbarExtender.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 81dccabae12b7f64086d54bc04a85de0 +guid: 2982073ed28ef744e96be44c7f55f5f7 folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/UnityProject/Assets/TEngine/Editor/ToolbarExtender/Custom.meta b/UnityProject/Assets/Editor/ToolbarExtender/Custom.meta similarity index 100% rename from UnityProject/Assets/TEngine/Editor/ToolbarExtender/Custom.meta rename to UnityProject/Assets/Editor/ToolbarExtender/Custom.meta diff --git a/UnityProject/Assets/TEngine/Editor/ToolbarExtender/Custom/SceneSwitcher.meta b/UnityProject/Assets/Editor/ToolbarExtender/Custom/SceneSwitcher.meta similarity index 100% rename from UnityProject/Assets/TEngine/Editor/ToolbarExtender/Custom/SceneSwitcher.meta rename to UnityProject/Assets/Editor/ToolbarExtender/Custom/SceneSwitcher.meta diff --git a/UnityProject/Assets/TEngine/Editor/ToolbarExtender/Custom/SceneSwitcher/Editor.meta b/UnityProject/Assets/Editor/ToolbarExtender/Custom/SceneSwitcher/Editor.meta similarity index 100% rename from UnityProject/Assets/TEngine/Editor/ToolbarExtender/Custom/SceneSwitcher/Editor.meta rename to UnityProject/Assets/Editor/ToolbarExtender/Custom/SceneSwitcher/Editor.meta diff --git a/UnityProject/Assets/Editor/ToolbarExtender/Custom/SceneSwitcher/Editor/EditorPlayMode.cs b/UnityProject/Assets/Editor/ToolbarExtender/Custom/SceneSwitcher/Editor/EditorPlayMode.cs new file mode 100644 index 00000000..3395e5a0 --- /dev/null +++ b/UnityProject/Assets/Editor/ToolbarExtender/Custom/SceneSwitcher/Editor/EditorPlayMode.cs @@ -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(); + } + } +} \ No newline at end of file diff --git a/UnityProject/Assets/TEngine/Editor/ToolbarExtender/Custom/SceneSwitcher/Editor/EditorResourceMode.cs.meta b/UnityProject/Assets/Editor/ToolbarExtender/Custom/SceneSwitcher/Editor/EditorPlayMode.cs.meta similarity index 100% rename from UnityProject/Assets/TEngine/Editor/ToolbarExtender/Custom/SceneSwitcher/Editor/EditorResourceMode.cs.meta rename to UnityProject/Assets/Editor/ToolbarExtender/Custom/SceneSwitcher/Editor/EditorPlayMode.cs.meta diff --git a/UnityProject/Assets/Editor/ToolbarExtender/Custom/SceneSwitcher/Editor/SceneLauncher.cs b/UnityProject/Assets/Editor/ToolbarExtender/Custom/SceneSwitcher/Editor/SceneLauncher.cs new file mode 100644 index 00000000..9510ba77 --- /dev/null +++ b/UnityProject/Assets/Editor/ToolbarExtender/Custom/SceneSwitcher/Editor/SceneLauncher.cs @@ -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; + } + } + } +} \ No newline at end of file diff --git a/UnityProject/Assets/Editor/ToolbarExtender/Custom/SceneSwitcher/Editor/SceneLauncher.cs.meta b/UnityProject/Assets/Editor/ToolbarExtender/Custom/SceneSwitcher/Editor/SceneLauncher.cs.meta new file mode 100644 index 00000000..baab37f9 --- /dev/null +++ b/UnityProject/Assets/Editor/ToolbarExtender/Custom/SceneSwitcher/Editor/SceneLauncher.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 2f6d2ca3d3b34950a79294e49dd9d016 +timeCreated: 1742389721 \ No newline at end of file diff --git a/UnityProject/Assets/Editor/ToolbarExtender/Custom/SceneSwitcher/Editor/SceneSwitcher.cs b/UnityProject/Assets/Editor/ToolbarExtender/Custom/SceneSwitcher/Editor/SceneSwitcher.cs new file mode 100644 index 00000000..0e6ff2cd --- /dev/null +++ b/UnityProject/Assets/Editor/ToolbarExtender/Custom/SceneSwitcher/Editor/SceneSwitcher.cs @@ -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; + } + + /// + /// 获取项目中所有的场景文件,并以 (场景名, 场景路径) 的形式返回。 + /// + 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 \ No newline at end of file diff --git a/UnityProject/Assets/TEngine/Editor/ToolbarExtender/Custom/SceneSwitcher/Editor/SceneSwitcher.cs.meta b/UnityProject/Assets/Editor/ToolbarExtender/Custom/SceneSwitcher/Editor/SceneSwitcher.cs.meta similarity index 83% rename from UnityProject/Assets/TEngine/Editor/ToolbarExtender/Custom/SceneSwitcher/Editor/SceneSwitcher.cs.meta rename to UnityProject/Assets/Editor/ToolbarExtender/Custom/SceneSwitcher/Editor/SceneSwitcher.cs.meta index 262437c0..4702aa89 100644 --- a/UnityProject/Assets/TEngine/Editor/ToolbarExtender/Custom/SceneSwitcher/Editor/SceneSwitcher.cs.meta +++ b/UnityProject/Assets/Editor/ToolbarExtender/Custom/SceneSwitcher/Editor/SceneSwitcher.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 45017e4df12424c4fb16db4708d239f0 +guid: 1fb6885a187ff8449a9cc083b7fbee28 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/UnityProject/Assets/TEngine/Editor/ToolbarExtender/ToolbarCallback.cs b/UnityProject/Assets/Editor/ToolbarExtender/ToolbarCallback.cs similarity index 100% rename from UnityProject/Assets/TEngine/Editor/ToolbarExtender/ToolbarCallback.cs rename to UnityProject/Assets/Editor/ToolbarExtender/ToolbarCallback.cs diff --git a/UnityProject/Assets/TEngine/Editor/ToolbarExtender/ToolbarCallback.cs.meta b/UnityProject/Assets/Editor/ToolbarExtender/ToolbarCallback.cs.meta similarity index 100% rename from UnityProject/Assets/TEngine/Editor/ToolbarExtender/ToolbarCallback.cs.meta rename to UnityProject/Assets/Editor/ToolbarExtender/ToolbarCallback.cs.meta diff --git a/UnityProject/Assets/TEngine/Editor/ToolbarExtender/ToolbarExtender.cs b/UnityProject/Assets/Editor/ToolbarExtender/ToolbarExtender.cs similarity index 100% rename from UnityProject/Assets/TEngine/Editor/ToolbarExtender/ToolbarExtender.cs rename to UnityProject/Assets/Editor/ToolbarExtender/ToolbarExtender.cs diff --git a/UnityProject/Assets/TEngine/Editor/ToolbarExtender/ToolbarExtender.cs.meta b/UnityProject/Assets/Editor/ToolbarExtender/ToolbarExtender.cs.meta similarity index 100% rename from UnityProject/Assets/TEngine/Editor/ToolbarExtender/ToolbarExtender.cs.meta rename to UnityProject/Assets/Editor/ToolbarExtender/ToolbarExtender.cs.meta diff --git a/UnityProject/Assets/Editor/UIScriptGenerator.meta b/UnityProject/Assets/Editor/UIScriptGenerator.meta new file mode 100644 index 00000000..7540c63a --- /dev/null +++ b/UnityProject/Assets/Editor/UIScriptGenerator.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 12cde5e16fa64eab883975bd63fc5077 +timeCreated: 1741968067 \ No newline at end of file diff --git a/UnityProject/Assets/TEngine/Editor/UI/ScriptGenerator.cs b/UnityProject/Assets/Editor/UIScriptGenerator/ScriptGenerator.cs similarity index 68% rename from UnityProject/Assets/TEngine/Editor/UI/ScriptGenerator.cs rename to UnityProject/Assets/Editor/UIScriptGenerator/ScriptGenerator.cs index 9cc62fbe..89bffc7e 100644 --- a/UnityProject/Assets/TEngine/Editor/UI/ScriptGenerator.cs +++ b/UnityProject/Assets/Editor/UIScriptGenerator/ScriptGenerator.cs @@ -58,10 +58,20 @@ namespace TEngine.Editor.UI strFile.Append("using UnityEngine;\n"); strFile.Append("using UnityEngine.UI;\n"); strFile.Append("using TEngine;\n\n"); - strFile.Append($"namespace {SettingsUtils.GetUINameSpace()}\n"); + strFile.Append($"namespace {ScriptGeneratorSetting.GetUINameSpace()}\n"); strFile.Append("{\n"); - strFile.Append("\t[Window(UILayer.UI)]\n"); - strFile.Append("\tclass " + root.name + " : UIWindow\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"); } @@ -92,9 +102,11 @@ namespace TEngine.Editor.UI te.SelectAll(); te.Copy(); } + + Debug.Log($"脚本已生成到剪贴板,请自行Ctl+V粘贴"); } - private static void Ergodic(Transform root, Transform transform, ref StringBuilder strVar, ref StringBuilder strBind, ref StringBuilder strOnCreate, + 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) @@ -103,7 +115,6 @@ namespace TEngine.Editor.UI WriteScript(root, child, ref strVar, ref strBind, ref strOnCreate, ref strCallback, isUniTask); if (child.name.StartsWith("m_item")) { - // 子 Item 不再往下遍历 continue; } @@ -127,36 +138,95 @@ namespace TEngine.Editor.UI public static string GetBtnFuncName(string varName) { - return "OnClick" + varName.Replace("m_btn", string.Empty) + "Btn"; + 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) { - return "OnToggle" + varName.Replace("m_toggle", string.Empty) + "Change"; + 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) { - return "OnSlider" + varName.Replace("m_slider", string.Empty) + "Change"; + 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 = SettingsUtils.GetScriptGenerateRule().Find(t => varName.StartsWith(t.uiElementRegex)); + 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)) @@ -173,26 +243,11 @@ namespace TEngine.Editor.UI case "AnimationCurve": strBind.Append($"\t\t\t{varName} = FindChildComponent(\"{varPath}\").m_animCurve;\n"); break; - case "RichItemIcon": - case "CommonFightWidget": - case "PlayerHeadWidget": - strBind.Append($"\t\t\t{varName} = CreateWidgetByType<{componentName}>(\"{varPath}\");\n"); - break; - case "RedNoteBehaviour": - case "TextButtonItem": - case "SwitchTabItem": - case "UIActorWidget": - case "UIEffectWidget": - case "UISpineWidget": - strBind.Append($"\t\t\t{varName} = CreateWidget<{componentName}>(\"{varPath}\");\n"); - break; - case "ActorNameBinderText": - strBind.Append($"\t\t\t{varName} = FindTextBinder(\"{varPath}\");\n"); - break; - case "ActorNameBinderEffect": - strBind.Append($"\t\t\t{varName} = FindEffectBinder(\"{varPath}\");\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; } @@ -246,7 +301,7 @@ namespace TEngine.Editor.UI protected void OnGUI() { GUILayout.BeginVertical(); - foreach (var item in SettingsUtils.GetScriptGenerateRule()) + foreach (var item in ScriptGeneratorSetting.GetScriptGenerateRule()) { GUILayout.Label(item.uiElementRegex + ":\t" + item.componentName); } @@ -254,82 +309,5 @@ namespace TEngine.Editor.UI GUILayout.EndVertical(); } } - - public class SwitchGroupGenerator - { - private const string Condition = "m_switchGroup"; - - public static readonly SwitchGroupGenerator Instance = new SwitchGroupGenerator(); - - public string Process(Transform root) - { - var sbd = new StringBuilder(); - var list = new List(); - Collect(root, list); - foreach (var node in list) - { - sbd.AppendLine(Process(root, node)).AppendLine(); - } - - return sbd.ToString(); - } - - public void Collect(Transform node, List nodeList) - { - if (node.name.StartsWith(Condition)) - { - nodeList.Add(node); - return; - } - - var childCnt = node.childCount; - for (var i = 0; i < childCnt; i++) - { - var child = node.GetChild(i); - Collect(child, nodeList); - } - } - - private string Process(Transform root, Transform groupTf) - { - var parentPath = GetPath(root, groupTf); - var name = groupTf.name; - var sbd = new StringBuilder(@" -var _namePath = ""#parentPath""; -var _nameTf = FindChild(_namePath); -var childCnt = _nameTf.childCount; -SwitchTabItem[] _name; -_name = new SwitchTabItem[childCnt]; -for (var i = 0; i < childCnt; i++) -{ - var child = _nameTf.GetChild(i); - _name[i] = CreateWidget(_namePath + ""/"" + child.name); -}"); - sbd.Replace("_name", name); - sbd.Replace("#parentPath", parentPath); - return sbd.ToString(); - } - - public string GetPath(Transform root, Transform childTf) - { - if (childTf == null) - { - return string.Empty; - } - - if (childTf == root) - { - return childTf.name; - } - - var parentPath = GetPath(root, childTf.parent); - if (parentPath == string.Empty) - { - return childTf.name; - } - - return parentPath + "/" + childTf.name; - } - } } } \ No newline at end of file diff --git a/UnityProject/Assets/TEngine/Editor/UI/ScriptGenerator.cs.meta b/UnityProject/Assets/Editor/UIScriptGenerator/ScriptGenerator.cs.meta similarity index 83% rename from UnityProject/Assets/TEngine/Editor/UI/ScriptGenerator.cs.meta rename to UnityProject/Assets/Editor/UIScriptGenerator/ScriptGenerator.cs.meta index 5934b0f1..fcca71e2 100644 --- a/UnityProject/Assets/TEngine/Editor/UI/ScriptGenerator.cs.meta +++ b/UnityProject/Assets/Editor/UIScriptGenerator/ScriptGenerator.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 5cde6b81462affb4bac5ca8cd0862f38 +guid: 9e5b80682b2036f42b69fcb09c53863a MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/UnityProject/Assets/Editor/UIScriptGenerator/ScriptGeneratorSetting.asset b/UnityProject/Assets/Editor/UIScriptGenerator/ScriptGeneratorSetting.asset new file mode 100644 index 00000000..30c2dd80 --- /dev/null +++ b/UnityProject/Assets/Editor/UIScriptGenerator/ScriptGeneratorSetting.asset @@ -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 diff --git a/UnityProject/Assets/TEngine/ResRaw/AutoBindGlobalSetting.asset.meta b/UnityProject/Assets/Editor/UIScriptGenerator/ScriptGeneratorSetting.asset.meta similarity index 79% rename from UnityProject/Assets/TEngine/ResRaw/AutoBindGlobalSetting.asset.meta rename to UnityProject/Assets/Editor/UIScriptGenerator/ScriptGeneratorSetting.asset.meta index 8fe9d9be..3924a6d2 100644 --- a/UnityProject/Assets/TEngine/ResRaw/AutoBindGlobalSetting.asset.meta +++ b/UnityProject/Assets/Editor/UIScriptGenerator/ScriptGeneratorSetting.asset.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: eb33bb9d9cdf9484997cc91b0517ba4d +guid: fe8fecac349dd7a4cafb77822cdba64a NativeFormatImporter: externalObjects: {} mainObjectFileID: 11400000 diff --git a/UnityProject/Assets/Editor/UIScriptGenerator/ScriptGeneratorSetting.cs b/UnityProject/Assets/Editor/UIScriptGenerator/ScriptGeneratorSetting.cs new file mode 100644 index 00000000..24b33787 --- /dev/null +++ b/UnityProject/Assets/Editor/UIScriptGenerator/ScriptGeneratorSetting.cs @@ -0,0 +1,195 @@ +using System; +using System.Collections.Generic; +using UnityEditor; +using UnityEngine; + +namespace TEngine.Editor.UI +{ + public enum UIFieldCodeStyle + { + /// + /// Field names start with underscore (e.g., _variable) + /// + [InspectorName("Field names start with underscore (e.g., _variable)")] + UnderscorePrefix, + + /// + /// Field names start with m_ prefix (e.g., m_variable) + /// + [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(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 scriptGenerateRule = new List() + { + 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 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(); + AssetDatabase.CreateAsset(setting, "Assets/Editor/ScriptGeneratorSetting.asset"); + AssetDatabase.SaveAssets(); + AssetDatabase.Refresh(); + } + + public static List 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; + } + } +} \ No newline at end of file diff --git a/UnityProject/Assets/Editor/UIScriptGenerator/ScriptGeneratorSetting.cs.meta b/UnityProject/Assets/Editor/UIScriptGenerator/ScriptGeneratorSetting.cs.meta new file mode 100644 index 00000000..7474eca3 --- /dev/null +++ b/UnityProject/Assets/Editor/UIScriptGenerator/ScriptGeneratorSetting.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: f8a0dfbcd6854965bb6ae78627009a53 +timeCreated: 1741968155 \ No newline at end of file diff --git a/UnityProject/Assets/GameScripts/GameEntry.cs b/UnityProject/Assets/GameScripts/GameEntry.cs new file mode 100644 index 00000000..113c88f4 --- /dev/null +++ b/UnityProject/Assets/GameScripts/GameEntry.cs @@ -0,0 +1,15 @@ +using TEngine; +using UnityEngine; + +public class GameEntry : MonoBehaviour +{ + void Awake() + { + ModuleSystem.GetModule(); + ModuleSystem.GetModule(); + ModuleSystem.GetModule(); + ModuleSystem.GetModule(); + Settings.ProcedureSetting.StartProcedure().Forget(); + DontDestroyOnLoad(this); + } +} \ No newline at end of file diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SuperScrollView/Scripts/ListView/LoopListView.cs.meta b/UnityProject/Assets/GameScripts/GameEntry.cs.meta similarity index 83% rename from UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SuperScrollView/Scripts/ListView/LoopListView.cs.meta rename to UnityProject/Assets/GameScripts/GameEntry.cs.meta index c5c84906..b8bab124 100644 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SuperScrollView/Scripts/ListView/LoopListView.cs.meta +++ b/UnityProject/Assets/GameScripts/GameEntry.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: dd536d252034dd74b87b436507ec44f7 +guid: 9cdc4a1084443e8408c7e46ec9e661c7 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/UnityProject/Assets/GameScripts/HotFix/GameBase/BaseLogicSys.cs b/UnityProject/Assets/GameScripts/HotFix/GameBase/BaseLogicSys.cs deleted file mode 100644 index 48f7a493..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameBase/BaseLogicSys.cs +++ /dev/null @@ -1,79 +0,0 @@ -namespace TEngine -{ - /// - /// 基础LogicSys,生命周期由TEngine实现,推荐给系统实现, - /// 减少多余的Mono,保持系统层面只有一个Update。 - /// 用主Mono来驱动LogicSys的生命周期。 - /// - /// 逻辑系统类型。 - public abstract class BaseLogicSys : ILogicSys where T : new() - { - private static T _instance; - - public static bool HasInstance => _instance != null; - - public static T Instance - { - get - { - if (null == _instance) - { - _instance = new T(); - } - - return _instance; - } - } - - #region virtual function - public virtual bool OnInit() - { - if (null == _instance) - { - _instance = new T(); - } - return true; - } - - public virtual void OnStart() - { - } - - public virtual void OnUpdate() - { - } - - public virtual void OnLateUpdate() - { - } - - public virtual void OnFixedUpdate() - { - } - - public virtual void OnRoleLogin() - { - } - - public virtual void OnRoleLogout() - { - } - - public virtual void OnDestroy() - { - } - - public virtual void OnDrawGizmos() - { - } - - public virtual void OnApplicationPause(bool pause) - { - } - - public virtual void OnMapChanged() - { - } - #endregion - } -} \ No newline at end of file diff --git a/UnityProject/Assets/GameScripts/HotFix/GameBase/BaseLogicSys.cs.meta b/UnityProject/Assets/GameScripts/HotFix/GameBase/BaseLogicSys.cs.meta deleted file mode 100644 index c43cae84..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameBase/BaseLogicSys.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: fc4ce19b17fd4277951d189b66f503e2 -timeCreated: 1683120353 \ No newline at end of file diff --git a/UnityProject/Assets/GameScripts/HotFix/GameBase/BehaviourSingleton.cs b/UnityProject/Assets/GameScripts/HotFix/GameBase/BehaviourSingleton.cs deleted file mode 100644 index 398a3ba1..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameBase/BehaviourSingleton.cs +++ /dev/null @@ -1,309 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace TEngine -{ - /// - /// 通过LogicSys来驱动且具备Unity完整生命周期的单例(不继承MonoBehaviour)。 - /// Update、FixUpdate以及LateUpdate这些敏感帧更新需要加上对应的Attribute以最优化性能。 - /// - /// 完整生命周期的类型。 - public abstract class BehaviourSingleton : BaseBehaviourSingleton where T : BaseBehaviourSingleton, new() - { - private static T _instance; - - public static T Instance - { - get - { - if (null == _instance) - { - _instance = new T(); - Log.Assert(_instance != null); - _instance.Awake(); - RegSingleton(_instance); - } - - return _instance; - } - } - - private static void RegSingleton(BaseBehaviourSingleton inst) - { - BehaviourSingleSystem.Instance.RegSingleton(inst); - } - } - - #region Attribute - - /// - /// 帧更新属性。 - /// 适用于BehaviourSingleton。 - /// - [AttributeUsage(AttributeTargets.Class)] - public class UpdateAttribute : Attribute - { - } - - /// - /// 物理帧更新属性。 - /// 适用于BehaviourSingleton。 - /// - [AttributeUsage(AttributeTargets.Class)] - public class FixedUpdateAttribute : Attribute - { - } - - /// - /// 后帧更新属性。 - /// 适用于BehaviourSingleton。 - /// - [AttributeUsage(AttributeTargets.Class)] - public class LateUpdateAttribute : Attribute - { - } - - [AttributeUsage(AttributeTargets.Class)] - public class RoleLoginAttribute : Attribute - { - } - - [AttributeUsage(AttributeTargets.Class)] - public class RoleLogoutAttribute : Attribute - { - } - - #endregion - - /// - /// 基础Behaviour单例。 - /// (抽象类) - /// - public abstract class BaseBehaviourSingleton - { - /// - /// 是否已经Start。 - /// - public bool IsStart = false; - - public virtual void Awake() - { - } - - public virtual void Start() - { - } - - /// - /// 帧更新。 - /// 需要UpdateAttribute。 - /// - public virtual void Update() - { - } - - /// - /// 后帧更新。 - /// 需要LateUpdateAttribute。 - /// - public virtual void LateUpdate() - { - } - - /// - /// 物理帧更新。 - /// 需要FixedUpdateAttribute。 - /// - public virtual void FixedUpdate() - { - } - - public virtual void Destroy() - { - } - - public virtual void OnPause() - { - } - - public virtual void OnResume() - { - } - - public virtual void OnDrawGizmos() - { - } - } - - /// - /// 通过LogicSys来驱动且具备Unity完整生命周期的驱动系统(不继承MonoBehaviour)。 - /// - public sealed class BehaviourSingleSystem : BaseLogicSys - { - private readonly List _listInst = new List(); - private readonly List _listStart = new List(); - private readonly List _listUpdate = new List(); - private readonly List _listLateUpdate = new List(); - private readonly List _listFixedUpdate = new List(); - - /// - /// 注册单例。 - /// 调用Instance时自动调用。 - /// - /// 单例实例。 - internal void RegSingleton(BaseBehaviourSingleton inst) - { - Log.Assert(!_listInst.Contains(inst)); - _listInst.Add(inst); - _listStart.Add(inst); - if (HadAttribute(inst.GetType())) - { - _listUpdate.Add(inst); - } - - if (HadAttribute(inst.GetType())) - { - _listLateUpdate.Add(inst); - } - - if (HadAttribute(inst.GetType())) - { - _listFixedUpdate.Add(inst); - } - } - - public void UnRegSingleton(BaseBehaviourSingleton inst) - { - if (inst == null) - { - Log.Error($"BaseBehaviourSingleton Is Null"); - return; - } - - Log.Assert(_listInst.Contains(inst)); - if (_listInst.Contains(inst)) - { - _listInst.Remove(inst); - } - - if (_listStart.Contains(inst)) - { - _listStart.Remove(inst); - } - - if (_listUpdate.Contains(inst)) - { - _listUpdate.Remove(inst); - } - - if (_listLateUpdate.Contains(inst)) - { - _listLateUpdate.Remove(inst); - } - - inst.Destroy(); - inst = null; - } - - public override void OnUpdate() - { - var listStart = _listStart; - var listToUpdate = _listUpdate; - int count = listStart.Count; - if (count > 0) - { - for (int i = 0; i < count; i++) - { - var inst = listStart[i]; - Log.Assert(!inst.IsStart); - - inst.IsStart = true; - inst.Start(); - } - - listStart.Clear(); - } - - var listUpdateCnt = listToUpdate.Count; - for (int i = 0; i < listUpdateCnt; i++) - { - var inst = listToUpdate[i]; - - TProfiler.BeginFirstSample(inst.GetType().FullName); - inst.Update(); - TProfiler.EndFirstSample(); - } - } - - public override void OnLateUpdate() - { - var listLateUpdate = _listLateUpdate; - var listLateUpdateCnt = listLateUpdate.Count; - for (int i = 0; i < listLateUpdateCnt; i++) - { - var inst = listLateUpdate[i]; - - TProfiler.BeginFirstSample(inst.GetType().FullName); - inst.LateUpdate(); - TProfiler.EndFirstSample(); - } - } - - public override void OnFixedUpdate() - { - var listFixedUpdate = _listFixedUpdate; - var listFixedUpdateCnt = listFixedUpdate.Count; - for (int i = 0; i < listFixedUpdateCnt; i++) - { - var inst = listFixedUpdate[i]; - - TProfiler.BeginFirstSample(inst.GetType().FullName); - inst.FixedUpdate(); - TProfiler.EndFirstSample(); - } - } - - public override void OnDestroy() - { - int count = _listInst.Count; - for (int i = 0; i < count; i++) - { - var inst = _listInst[i]; - inst.Destroy(); - } - } - - public override void OnApplicationPause(bool pause) - { - int count = _listInst.Count; - for (int i = 0; i < count; i++) - { - var inst = _listInst[i]; - if (pause) - { - inst.OnPause(); - } - else - { - inst.OnResume(); - } - } - } - - public override void OnDrawGizmos() - { - int count = _listInst.Count; - for (int i = 0; i < count; i++) - { - var inst = _listInst[i]; - inst.OnDrawGizmos(); - } - } - - private bool HadAttribute(Type type) where T : Attribute - { - T attribute = Attribute.GetCustomAttribute(type, typeof(T)) as T; - return attribute != null; - } - } -} \ No newline at end of file diff --git a/UnityProject/Assets/GameScripts/HotFix/GameBase/BehaviourSingleton.cs.meta b/UnityProject/Assets/GameScripts/HotFix/GameBase/BehaviourSingleton.cs.meta deleted file mode 100644 index 4d688387..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameBase/BehaviourSingleton.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 5c0e9c1c8c9d4ce99a1c991fb62a0256 -timeCreated: 1683120460 \ No newline at end of file diff --git a/UnityProject/Assets/GameScripts/HotFix/GameBase/GameTickWatcher.cs b/UnityProject/Assets/GameScripts/HotFix/GameBase/GameTickWatcher.cs deleted file mode 100644 index 7c6f23fa..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameBase/GameTickWatcher.cs +++ /dev/null @@ -1,40 +0,0 @@ -using TEngine; - -namespace GameBase -{ - /// - /// 用于检测耗时。 - /// - public class GameTickWatcher - { - private long _startTick; - - public GameTickWatcher() - { - Refresh(); - } - - public void Refresh() - { - _startTick = System.DateTime.Now.Ticks; - } - - /// - /// 获取用时。 - /// - /// - public float ElapseTime() - { - long endTick = System.DateTime.Now.Ticks; - return (float)((endTick - _startTick) / 10000) / 1000.0f; - } - - /// - /// 输出用时。 - /// - public void LogUsedTime() - { - Log.Info($"Used Time: {this.ElapseTime()}"); - } - } -} \ No newline at end of file diff --git a/UnityProject/Assets/GameScripts/HotFix/GameBase/GameTickWatcher.cs.meta b/UnityProject/Assets/GameScripts/HotFix/GameBase/GameTickWatcher.cs.meta deleted file mode 100644 index e05fddec..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameBase/GameTickWatcher.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 7320165f7aa147a998a30fe2f7a5a5c2 -timeCreated: 1681989139 \ No newline at end of file diff --git a/UnityProject/Assets/GameScripts/HotFix/GameBase/ILogicSys.cs b/UnityProject/Assets/GameScripts/HotFix/GameBase/ILogicSys.cs deleted file mode 100644 index 095a3d5f..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameBase/ILogicSys.cs +++ /dev/null @@ -1,58 +0,0 @@ -/// -/// 定义通用的逻辑接口,统一生命期调用 -/// -public interface ILogicSys -{ - /// - /// 初始化接口 - /// - /// - bool OnInit(); - - /// - /// 销毁系统 - /// - void OnDestroy(); - - /// - /// 初始化后,第一帧统一调用 - /// - void OnStart(); - - /// - /// 更新接口 - /// - /// - void OnUpdate(); - - /// - /// 渲染后调用 - /// - void OnLateUpdate(); - - /// - /// 物理帧更新 - /// - void OnFixedUpdate(); - - /// - /// 登录账号/角色时调用 - /// - void OnRoleLogin(); - - /// - /// 清理数据接口,切换账号/角色时调用 - /// - void OnRoleLogout(); - - /// - /// 绘制调试接口 - /// - void OnDrawGizmos(); - - /// - /// 暂停游戏 - /// - /// - void OnApplicationPause(bool pause); -} \ No newline at end of file diff --git a/UnityProject/Assets/GameScripts/HotFix/GameBase/ILogicSys.cs.meta b/UnityProject/Assets/GameScripts/HotFix/GameBase/ILogicSys.cs.meta deleted file mode 100644 index 32ac0986..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameBase/ILogicSys.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 63ff6535a43f41d7ac793b8a153a37b6 -timeCreated: 1681213932 \ No newline at end of file diff --git a/UnityProject/Assets/GameScripts/HotFix/GameBase/Singleton.cs b/UnityProject/Assets/GameScripts/HotFix/GameBase/Singleton.cs deleted file mode 100644 index 2f14742f..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameBase/Singleton.cs +++ /dev/null @@ -1,27 +0,0 @@ -using TEngine; - -namespace GameBase -{ - /// - /// 通用单例。 - /// - /// 泛型T。 - public class Singleton where T : new() - { - private static T _instance; - - public static T Instance - { - get - { - if (null == _instance) - { - _instance = new T(); - Log.Assert(_instance != null); - } - - return _instance; - } - } - } -} \ No newline at end of file diff --git a/UnityProject/Assets/GameScripts/HotFix/GameBase/Singleton.cs.meta b/UnityProject/Assets/GameScripts/HotFix/GameBase/Singleton.cs.meta deleted file mode 100644 index 0c5d505a..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameBase/Singleton.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: b68a449df312429cbb27873984ec238e -timeCreated: 1681214042 \ No newline at end of file diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common.meta b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common.meta index 756de0bf..35d71b65 100644 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common.meta +++ b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common.meta @@ -1,3 +1,8 @@ fileFormatVersion: 2 guid: 3026f5e2510440618f6d4f28b37c5244 -timeCreated: 1695289286 \ No newline at end of file +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/CodeTypes.meta b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/CodeTypes.meta deleted file mode 100644 index 740b9d87..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/CodeTypes.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 40a878a415f34e7a855fc4916bbb8e6b -timeCreated: 1702479104 \ No newline at end of file diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/CodeTypes/Attribute.meta b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/CodeTypes/Attribute.meta deleted file mode 100644 index 21d15a96..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/CodeTypes/Attribute.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 1dcaa491f139438dbd963d8bbf0dba85 -timeCreated: 1702385397 \ No newline at end of file diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/CodeTypes/Attribute/BaseAttribute.cs b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/CodeTypes/Attribute/BaseAttribute.cs deleted file mode 100644 index 7697a10f..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/CodeTypes/Attribute/BaseAttribute.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System; - -namespace GameLogic -{ - [AttributeUsage(AttributeTargets.Class)] - public class BaseAttribute: Attribute - { - } -} \ No newline at end of file diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/CodeTypes/Attribute/BaseAttribute.cs.meta b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/CodeTypes/Attribute/BaseAttribute.cs.meta deleted file mode 100644 index 93772d85..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/CodeTypes/Attribute/BaseAttribute.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 819c4eaddddd4646a100da2e3f19c3c7 -timeCreated: 1702385397 \ No newline at end of file diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/CodeTypes/CodeTypes.cs b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/CodeTypes/CodeTypes.cs deleted file mode 100644 index 519fccdd..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/CodeTypes/CodeTypes.cs +++ /dev/null @@ -1,75 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Reflection; - -namespace GameLogic -{ - public class CodeTypes - { - private static CodeTypes _instance; - public static CodeTypes Instance => _instance ??= new CodeTypes(); - - private readonly Dictionary _allTypes = new(); - private readonly UnOrderMultiMapSet _types = new(); - - public void Init(Assembly[] assemblies) - { - Dictionary addTypes = GetAssemblyTypes(assemblies); - foreach ((string fullName, Type type) in addTypes) - { - _allTypes[fullName] = type; - - if (type.IsAbstract) - { - continue; - } - - // 记录所有的有BaseAttribute标记的的类型 - object[] objects = type.GetCustomAttributes(typeof(BaseAttribute), true); - - foreach (object o in objects) - { - _types.Add(o.GetType(), type); - } - } - } - - public HashSet GetTypes(Type systemAttributeType) - { - if (!_types.ContainsKey(systemAttributeType)) - { - return new HashSet(); - } - - return _types[systemAttributeType]; - } - - public Dictionary GetTypes() - { - return _allTypes; - } - - public Type GetType(string typeName) - { - return _allTypes[typeName]; - } - - public static Dictionary GetAssemblyTypes(params Assembly[] args) - { - Dictionary types = new Dictionary(); - - foreach (Assembly ass in args) - { - foreach (Type type in ass.GetTypes()) - { - if (type.FullName != null) - { - types[type.FullName] = type; - } - } - } - - return types; - } - } -} \ No newline at end of file diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/CodeTypes/CodeTypes.cs.meta b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/CodeTypes/CodeTypes.cs.meta deleted file mode 100644 index 14cb5f80..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/CodeTypes/CodeTypes.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 01fdfc4515314c579523ac3716005210 -timeCreated: 1702385429 \ No newline at end of file diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/CodeTypes/UnOrderMultiMapSet.cs b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/CodeTypes/UnOrderMultiMapSet.cs deleted file mode 100644 index f115d426..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/CodeTypes/UnOrderMultiMapSet.cs +++ /dev/null @@ -1,80 +0,0 @@ -using System.Collections.Generic; - -namespace GameLogic -{ - public class UnOrderMultiMapSet: Dictionary> - { - public new HashSet this[TKey t] - { - get - { - HashSet set; - if (!TryGetValue(t, out set)) - { - set = new HashSet(); - } - return set; - } - } - - public Dictionary> GetDictionary() - { - return this; - } - - public void Add(TKey t, TValue k) - { - HashSet set; - TryGetValue(t, out set); - if (set == null) - { - set = new HashSet(); - base[t] = set; - } - set.Add(k); - } - - public bool Remove(TKey t, TValue k) - { - HashSet set; - TryGetValue(t, out set); - if (set == null) - { - return false; - } - if (!set.Remove(k)) - { - return false; - } - if (set.Count == 0) - { - Remove(t); - } - return true; - } - - public bool Contains(TKey t, TValue k) - { - HashSet set; - TryGetValue(t, out set); - if (set == null) - { - return false; - } - return set.Contains(k); - } - - public new int Count - { - get - { - int count = 0; - foreach (KeyValuePair> kv in this) - { - count += kv.Value.Count; - } - return count; - } - } - } -} \ No newline at end of file diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/CodeTypes/UnOrderMultiMapSet.cs.meta b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/CodeTypes/UnOrderMultiMapSet.cs.meta deleted file mode 100644 index 253636f8..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/CodeTypes/UnOrderMultiMapSet.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: b798f0c1317c4caf9ace168f07b51d4f -timeCreated: 1702385485 \ No newline at end of file diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/RedNote.meta b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/RedNote.meta deleted file mode 100644 index 766eb47e..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/RedNote.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 6dd993a020654e8bbcc4e70ea0029447 -timeCreated: 1695289810 \ No newline at end of file diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/RedNote/RedNoteBehaviour.cs b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/RedNote/RedNoteBehaviour.cs deleted file mode 100644 index 6329105b..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/RedNote/RedNoteBehaviour.cs +++ /dev/null @@ -1,189 +0,0 @@ -using System; -using System.Collections.Generic; -using TEngine; -using UnityEngine; -using UnityEngine.UI; - -namespace GameLogic -{ - /// - /// 红点个体行为。 - /// - public class RedNoteBehaviour : UIWidget - { - public Action HaveRedNoteAction; - - //当前红点类型 - public RedNoteNotify RedNoteNotifyType { get; private set; } - - //启用时当作标记,解决带有ID,创建多个类似条目的情况 - public readonly List IdParamList = new List(); - private readonly List _tmpIdParam = new List(); - - private Image _image; - - private Image Image - { - get - { - if (_image == null && gameObject != null) - { - _image = gameObject.GetComponent(); - } - return _image; - } - } - - private Text _text; - private Text Text - { - get - { - if (_text == null && gameObject != null) - { - _text = FindChildComponent(rectTransform, "Text"); - } - return _text; - } - } - - private bool _state = false; - - /// - /// 当前红点状态。 - /// - public bool CurState - { - private set - { - _state = value; - - if (Image == null) - { - gameObject.SetActive(_state); - return; - } - - Color c = Image.color; - c.a = _state ? 1f : 0.01f; - Image.color = c; - - if (HaveRedNoteAction != null) - { - HaveRedNoteAction(_state); - } - } - get => _state; - } - - - //设置显示状态 - public void SetRedNoteState(bool state) - { - CurState = state; - } - - // 设置红点类型 - public void SetNotifyType(RedNoteNotify notifyType) - { - _tmpIdParam.Clear(); - SetNotifyType(notifyType, _tmpIdParam); - } - - #region 参数重载 - public void SetNotifyType(RedNoteNotify notifyType, ulong param1) - { - _tmpIdParam.Clear(); - _tmpIdParam.Add(param1); - SetNotifyType(notifyType, _tmpIdParam); - } - - public void SetNotifyType(RedNoteNotify notifyType, ulong param1, ulong param2) - { - _tmpIdParam.Clear(); - _tmpIdParam.Add(param1); - _tmpIdParam.Add(param2); - SetNotifyType(notifyType, _tmpIdParam); - } - - public void SetNotifyType(RedNoteNotify notifyType, ulong param1, ulong param2, ulong param3) - { - _tmpIdParam.Clear(); - _tmpIdParam.Add(param1); - _tmpIdParam.Add(param2); - _tmpIdParam.Add(param3); - SetNotifyType(notifyType, _tmpIdParam); - } - - public void SetNotifyType(RedNoteNotify notifyType, params ulong[] param) - { - _tmpIdParam.Clear(); - for (int i = 0; i < param.Length; i++) - { - _tmpIdParam.Add(param[i]); - } - SetNotifyType(notifyType, _tmpIdParam); - } - #endregion - - public void SetNotifyType(RedNoteNotify notifyType, List paramList) - { - RemoveNotifyBind(); - if (notifyType == RedNoteNotify.None) return; - - IdParamList.Clear(); - IdParamList.AddRange(paramList); - SetRedNoteNotifyProcess(notifyType); - } - - private void SetRedNoteNotifyProcess(RedNoteNotify notifyType) - { - // 移除红点通知的绑定 - if (Image != null) - { - Image.rectTransform.SetAsLastSibling(); - } - - RedNoteNotifyType = notifyType; - - RedNoteMgr.Instance.RegisterNotify(RedNoteNotifyType, this); - - if (!RedNoteMgr.Instance.IsNumType(notifyType, IdParamList)) - { - CurState = RedNoteMgr.Instance.GetNotifyValue(RedNoteNotifyType, IdParamList); - } - else - { - SetRedNotePointNum(RedNoteMgr.Instance.GetNotifyPointNum(RedNoteNotifyType, IdParamList)); - } - } - - /// - /// 移除红点通知的绑定。 - /// - public void RemoveNotifyBind() - { - if (RedNoteNotifyType != RedNoteNotify.None) - { - RedNoteMgr.Instance.UnRegisterNotify(RedNoteNotifyType, this); - } - - CurState = false; - } - - protected override void OnDestroy() - { - RemoveNotifyBind(); - } - - public void SetRedNotePointNum(int pointNum) - { - if (Text != null) - { - Text.text = pointNum > 0 ? pointNum.ToString() : string.Empty; - - CurState = pointNum > 0; - } - } - } -} diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/RedNote/RedNoteBehaviour.cs.meta b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/RedNote/RedNoteBehaviour.cs.meta deleted file mode 100644 index e7357ed7..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/RedNote/RedNoteBehaviour.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: dba30ea267ff4b988310dec14c0df1c3 -timeCreated: 1687263893 \ No newline at end of file diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/RedNote/RedNoteCheckMgr.cs b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/RedNote/RedNoteCheckMgr.cs deleted file mode 100644 index dd0c81ad..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/RedNote/RedNoteCheckMgr.cs +++ /dev/null @@ -1,85 +0,0 @@ -using System.Collections.Generic; - -namespace GameLogic -{ - /// 红点关联 - public class RedNoteCheckMgr - { - public string m_ownerStr; - public List m_childList { get; private set; } - - public RedNoteCheckMgr(RedNoteNotify ower, List childList) - { - m_ownerStr = ower.ToString(); - m_childList = new List(); - for (int i = 0; i < childList.Count; i++) - { - var value = childList[i]; - m_childList.Add(value.ToString()); - } - } - - public RedNoteCheckMgr(string paramKey) - { - m_ownerStr = paramKey; - } - - public bool AddChild(string childKey) - { - if (m_childList == null) - { - m_childList = new List(); - } - if (!m_childList.Contains(childKey)) - { - m_childList.Add(childKey); - return true; - } - - return false; - } - - public void CheckChildRedNote() - { - var valueItem = RedNoteMgr.Instance.GetNotifyValueItem(m_ownerStr); - - bool childHaveRed = false; - int childNotePointNum = 0; - - int count = m_childList.Count; - for (var index = 0; index < count; index++) - { - var child = m_childList[index]; - var childItem = RedNoteMgr.Instance.GetNotifyValueItem(child); - if (childItem.GetRedNoteType() == RedNoteType.Simple) - { - if (RedNoteMgr.Instance.GetNotifyValue(child)) - { - childHaveRed = true; - childNotePointNum++; - } - } - else - { - childNotePointNum += childItem.GetRedNotePointNum(); - } - } - - if (valueItem.GetRedNoteType() == RedNoteType.Simple) - { - RedNoteMgr.Instance.SetNotifyKeyValue(m_ownerStr, childHaveRed); - } - else - { - RedNoteMgr.Instance.SetNotifyKeyPointNum(m_ownerStr, childNotePointNum); - } - } - - - public bool CheckChild(string childKey) - { - bool red = RedNoteMgr.Instance.GetNotifyValue(childKey); - return red; - } - } -} diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/RedNote/RedNoteCheckMgr.cs.meta b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/RedNote/RedNoteCheckMgr.cs.meta deleted file mode 100644 index c5c72de4..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/RedNote/RedNoteCheckMgr.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 3dd181174bbf408e9932a6f9484e41a5 -timeCreated: 1687263893 \ No newline at end of file diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/RedNote/RedNoteMgr.cs b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/RedNote/RedNoteMgr.cs deleted file mode 100644 index f2ee60f7..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/RedNote/RedNoteMgr.cs +++ /dev/null @@ -1,669 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using GameBase; -using GameLogic; -using TEngine; -using UnityEngine; - -namespace GameLogic -{ - #region 红点添加步骤 - - /// 1,增加RedNoteNotify定义,加入新的红点枚举。 - /// 2,添加红点关联,关联定义在InitRelation,查看当前有的关联关系,确定是增加还是重新创建 - /// 3,把RedNoteBehaviour挂在红点图片上,红点图片一般放置在需要显示红点的按钮/页签上,设置脚本上的枚举类型 - /// 4,如果是带参数的红点类型,在红点所在的UI声明红点对象,对参数进行设置,参数统一为uint,一般用一个可以唯一区分的ID。 - /// 有多个参数时,每后一个参数节点都是前一个参数的子节点。 无参数为该层级的根节点。 - /// 5,红点激活/隐藏 - /// 在对应模块数据管理类中,检测达到红点激活条件,或红点消失条件,调用SetNotifyValue激活/隐藏红点 - #endregion - - public enum RedNoteNotify - { - None = 0, - CharacterMain, - ShopMain, - BagMain, - BagUseType, - ExploreMain, - HomeUI, - } - - /// - /// 红点指引 - /// - public class RedNoteMgr : Singleton - { - //红点状态记录 - private Dictionary _notifyMap; - - //红点关联 - private readonly Dictionary _checkDic = new Dictionary(); - - /// - /// child to parent list - /// - private readonly Dictionary> _checkOwnDic = new Dictionary>(); - - private readonly Dictionary _keyConvertDic = new Dictionary(); - private readonly Dictionary _keyDic = new Dictionary(); - - /// - /// 红点映射 - /// key => 红点名称 - /// val => 对应的红点类型 - /// - private Dictionary _dicRedNoteMap; - - private Dictionary _notifyStringMap; - - public void Init() - { - InitState(); - InitRedNoteConfig(); - InitRelation(); - InitRedNoteTween(); - } - - /// - /// 全局缓动缩放 - /// - public Vector3 GlobalTwScale { get; protected set; } - - /// - /// 初始化红点缓动 - /// - private void InitRedNoteTween() - { - // LeanTween.value(LeanTween.tweenEmpty, OnRedNoteTween, 1f, 0.75f, 0.5f).setLoopPingPong(); - } - - /// - /// 缓动 - /// - /// - private void OnRedNoteTween(float value) - { - GlobalTwScale = value * Vector3.one; - } - - //注册红点通知 - public void RegisterNotify(RedNoteNotify notify, RedNoteBehaviour redNote) - { - RedNoteValueItem redNoteValueItem = GetOrNewNotifyValueItem(notify, redNote.IdParamList); - redNoteValueItem.AddRedNote(redNote); - } - - //销毁红点通知 - public void UnRegisterNotify(RedNoteNotify notify, RedNoteBehaviour redNote) - { - RedNoteValueItem redNoteValueItem = GetOrNewNotifyValueItem(notify, redNote.IdParamList); - if (redNoteValueItem == null) - { - return; - } - - redNoteValueItem.RemoveRedNote(redNote); - } - - private readonly List _tmpRedNoteParams = new List(); - - /// - /// 设置红点状态。 - /// - /// - /// - public void SetNotifyValue(RedNoteNotify notify, bool value) - { - _tmpRedNoteParams.Clear(); - SetNotifyValue(notify, value, _tmpRedNoteParams); - } - - #region 参数重载 bool - - public void SetNotifyValue(RedNoteNotify notify, bool value, ulong param1) - { - _tmpRedNoteParams.Clear(); - _tmpRedNoteParams.Add(param1); - SetNotifyValue(notify, value, _tmpRedNoteParams); - } - - public void SetNotifyValue(RedNoteNotify notify, bool value, ulong param1, ulong param2) - { - _tmpRedNoteParams.Clear(); - _tmpRedNoteParams.Add(param1); - _tmpRedNoteParams.Add(param2); - SetNotifyValue(notify, value, _tmpRedNoteParams); - } - - public void SetNotifyValue(RedNoteNotify notify, bool value, params ulong[] param) - { - _tmpRedNoteParams.Clear(); - for (var i = 0; i < param.Length; i++) - { - _tmpRedNoteParams.Add(param[i]); - } - - SetNotifyValue(notify, value, _tmpRedNoteParams); - } - - #endregion - - public void SetNotifyValue(RedNoteNotify notify, bool value, List redNoteParamList) - { - var key = BuildKey(notify, redNoteParamList); - if (!value && !_notifyMap.TryGetValue(key, out var redNoteValueItem)) - { - return; - } - - GetOrNewNotifyValueItem(notify, redNoteParamList); - MarkNotifyKeyValueDirty(key, value); - } - - public void MarkNotifyKeyValueDirty(string key, bool value) - { - if (!_notifyMap.TryGetValue(key, out var redNoteValueItem)) - { - return; - } - redNoteValueItem.SetStateDirty(value); - } - - /// - /// 设置红点状态。 - /// - /// - /// - public void SetNotifyKeyValue(string key, bool value) - { - if (!_notifyMap.TryGetValue(key, out var redNoteValueItem)) - { - return; - } - - //设置红点状态 - if (redNoteValueItem.SetRedNoteState(value)) - { - //设置红点关联状态 - CalcRedNoteRelation(key); - } - } - - //设置红点状态数量 - public void SetNotifyKeyPointNum(string key, int pointNum) - { - if (!_notifyMap.TryGetValue(key, out var redNoteValueItem)) - { - return; - } - - if (redNoteValueItem.SetRedNotePoint(pointNum)) - { - //设置红点关联状态 - CalcRedNoteRelation(key); - } - } - - public bool GetNotifyValue(RedNoteNotify notify, ulong param1) - { - _tmpRedNoteParams.Clear(); - _tmpRedNoteParams.Add(param1); - return GetNotifyValue(notify, _tmpRedNoteParams); - } - - public bool GetNotifyValue(RedNoteNotify notify, ulong param1, ulong param2) - { - _tmpRedNoteParams.Clear(); - _tmpRedNoteParams.Add(param1); - _tmpRedNoteParams.Add(param2); - return GetNotifyValue(notify, _tmpRedNoteParams); - } - - /// - /// 获取红点状态。 - /// - /// - /// - /// - public bool GetNotifyValue(RedNoteNotify notify, List param = null) - { - if (notify == (uint)RedNoteNotify.None) - return false; - - RedNoteValueItem item = GetOrNewNotifyValueItem(notify, param); - return item.GetRedNoteState(); - } - - /// - /// 获取红点数量。 - /// - /// - /// - /// - public int GetNotifyPointNum(RedNoteNotify notify, List param) - { - if (notify == (uint)RedNoteNotify.None) - return 0; - - RedNoteValueItem item = GetOrNewNotifyValueItem(notify, param); - return item.GetRedNotePointNum(); - } - - public bool GetNotifyValue(string paramKey) - { - if (_notifyMap.TryGetValue(paramKey, out var redNoteValueItem)) - { - return redNoteValueItem.GetRedNoteState(); - } - - return false; - } - - /// - /// 清理红点状态. - /// - /// - public void ClearNotifyValue(RedNoteNotify notify) - { - var notifyStr = NotifyTypeToString(notify); - RecursiveClearNotifyKeyValue(notifyStr); - - RedNoteValueItem redNoteValueItem = GetNotifyValueItem(notifyStr); - redNoteValueItem.ClearRedNoteState(false); - CalcRedNoteRelation(notifyStr); - } - - public void RecursiveClearNotifyKeyValue(string key) - { - if (!_checkDic.TryGetValue(key, out var checkMgr)) - { - return; - } - - var childList = checkMgr.m_childList; - foreach (var childKey in childList) - { - RedNoteValueItem redNoteValueItem = GetNotifyValueItem(childKey); - redNoteValueItem.ClearRedNoteState(false); - - RecursiveClearNotifyKeyValue(childKey); - } - } - - /// - /// 清理数据。 - /// - public void OnRoleLogout() - { - var enumerator = _notifyMap.GetEnumerator(); - while (enumerator.MoveNext()) - { - enumerator.Current.Value.ClearRedNoteState(true); - } - - enumerator.Dispose(); - } - - public string NotifyTypeToString(RedNoteNotify notify) - { - _notifyStringMap.TryGetValue((int)notify, out var str); - return str; - } - - public string BuildKey(RedNoteNotify notifyType, List paramList) - { - var notifyStr = NotifyTypeToString(notifyType); - if (notifyStr == null) - { - Log.Error("RedNoteNotifyId :{0} Not Exit! Please Check", notifyType.ToString()); - return string.Empty; - } - - if (!_keyDic.TryGetValue(notifyStr, out var dicData)) - { - dicData = new RedNoteStructDic(); - _keyDic[notifyStr] = dicData; - } - - var key = dicData.TryGetKey(notifyStr, paramList); - return key; - } - - public static string GetKeyString(string notify, List paramList) - { - if (paramList == null || paramList.Count == 0) - { - return notify; - } - - string key; - if (paramList.Count <= 1) - { - key = $"{notify}-{paramList[0]}"; - } - else if (paramList.Count <= 2) - { - key = $"{notify}-{paramList[0]}-{paramList[1]}"; - } - else if (paramList.Count <= 3) - { - key = $"{notify}-{paramList[0]}-{paramList[1]}-{paramList[2]}"; - } - else - { - StringBuilder s = new StringBuilder(); - s.Append(notify + "-"); - for (var i = 0; i < paramList.Count; i++) - { - s.Append(paramList[i]); - if (i != paramList.Count - 1) - s.Append("-"); - } - - key = s.ToString(); - } - - return key; - } - - public void SetKeyConvertDic(string key, RedNoteKeyStruct keyStruct) - { - _keyConvertDic[key] = keyStruct; - } - - private readonly List _tmpParamList = new List(); - - /// - /// 计算红点关联. - /// - /// - private void CalcRedNoteRelation(string notifyKey) - { - var key = notifyKey; - if (_checkOwnDic.TryGetValue(key, out var ownerList)) - { - foreach (var owner in ownerList) - { - if (_checkDic.TryGetValue(owner, out var checker)) - { - checker.CheckChildRedNote(); - } - } - } - } - - /// - /// 初始化红点状态. - /// - private void InitState() - { - var array = (RedNoteNotify[])Enum.GetValues(typeof(RedNoteNotify)); - - var redNoteCnt = array.Length; - _notifyMap = new Dictionary(); - _dicRedNoteMap = new Dictionary(redNoteCnt); - _notifyStringMap = new Dictionary(redNoteCnt); - - foreach (var redNoteNotify in array) - { - var redNoteStr = redNoteNotify.ToString(); - _dicRedNoteMap.Add(redNoteStr, redNoteNotify); - _notifyStringMap.Add((int)redNoteNotify, redNoteStr); - - var key = BuildKey(redNoteNotify, _tmpParamList); - var redNoteValueItem = new RedNoteValueItem(); - bool isNumType = IsNumType(redNoteNotify, null); - redNoteValueItem.Init(key, isNumType ? RedNoteType.WithNum : RedNoteType.Simple); - _notifyMap.Add(key, redNoteValueItem); - } - } - - public RedNoteValueItem GetNotifyValueItem(string key) - { - _notifyMap.TryGetValue(key, out var redNoteValueItem); - return redNoteValueItem; - } - - private RedNoteValueItem GetOrNewNotifyValueItem(RedNoteNotify notify, List paramList) - { - var key = BuildKey(notify, paramList); - var redNoteValueItem = GetNotifyValueItem(key); - - if (redNoteValueItem == null) - { - List tmpParamList = new List(paramList); - - //从后往前创建item,如(A, 1, 2)会创建A-1-2,A-1,A。 - string lastChildKey = string.Empty; - int paramIndex = paramList.Count; - while (paramIndex >= 0) - { - var keyStr = BuildKey(notify, tmpParamList); - - if (!_notifyMap.ContainsKey(keyStr)) - { - RedNoteValueItem noteValueItem = new RedNoteValueItem(); - bool isNumType = IsNumType(notify, paramList); - noteValueItem.Init(keyStr, isNumType ? RedNoteType.WithNum : RedNoteType.Simple); - _notifyMap.Add(keyStr, noteValueItem); - } - - //叶子节点跳过(因为他没有子节点) - if (tmpParamList.Count < paramList.Count) - { - bool addedChild; - if (!_checkDic.TryGetValue(keyStr, out var checkMgr)) - { - checkMgr = new RedNoteCheckMgr(keyStr); - addedChild = checkMgr.AddChild(lastChildKey); - } - else - { - addedChild = checkMgr.AddChild(lastChildKey); - } - - if (addedChild) - { - AddDic(checkMgr); //重新生成父子关系 - } - } - - lastChildKey = keyStr; - paramIndex--; - if (paramIndex < tmpParamList.Count && tmpParamList.Count > 0) - { - tmpParamList.RemoveAt(paramIndex); - } - } - - redNoteValueItem = _notifyMap[key]; - } - - return redNoteValueItem; - } - - public void AddDic(RedNoteNotify owner, List childList) - { - AddDic(new RedNoteCheckMgr(owner, childList)); - } - - private void AddDic(RedNoteCheckMgr checker) - { - var owner = checker.m_ownerStr; - _checkDic[owner] = checker; - - var childList = checker.m_childList; - int count = childList.Count; - for (int i = 0; i < count; i++) - { - var child = childList[i]; - if (!_checkOwnDic.TryGetValue(child, out var ownerList)) - { - ownerList = new List(); - _checkOwnDic[child] = ownerList; - } - - if (!ownerList.Contains(owner)) - { - ownerList.Add(owner); - } - } - } - - public bool IsNumType(RedNoteNotify noteNotify, List paramList) - { - if (paramList is { Count: > 0 }) - { - return true; - } - - return false; - } - - // 通过名字获取红点类型 - public static RedNoteNotify GetRedNoteByName(string redNoteName) - { - Instance._dicRedNoteMap.TryGetValue(redNoteName, out var redNote); - - return redNote; - } - - public void OnUpdate() - { - foreach (var redNoteValueItem in _notifyMap) - { - redNoteValueItem.Value.CheckDirty(); - } - } - - #region 初始化红点 - - /// - /// 初始化红点配置表 - /// - private void InitRedNoteConfig() - { - // ResDictionaryList cfgs = new ResDictionaryList(); - // cfgs.Init(val => val.RedNoteParentID); - // List list = new List(); - // foreach (var kv in cfgs.Data) - // { - // list.Clear(); - // foreach (var cfg in kv.Value) - // { - // list.Add((RedNoteNotify)cfg.RedNoteID); - // } - // - // AddDic((RedNoteNotify)kv.Key, list); - // } - } - - //初始化红点关联 - private void InitRelation() - { - } - #endregion - } -} - -public class RedNoteStructDic -{ - private readonly List _keyStructList = new List(); - - public string TryGetKey(string notify, List paramList) - { - string key = string.Empty; - List list = _keyStructList; - { - int count = list.Count; - for (int i = 0; i < count; i++) - { - var keyStruct = list[i]; - if (keyStruct.IsSame(notify, paramList)) - { - key = keyStruct.Key; - break; - } - } - } - - - if (string.IsNullOrEmpty(key)) - { - var keyStruct = new RedNoteKeyStruct(notify, paramList); - key = keyStruct.Key; - RedNoteMgr.Instance.SetKeyConvertDic(key, keyStruct); - list.Add(keyStruct); - } - return key; - } -} - -public class RedNoteKeyStruct -{ - public string Notify; - public List ParamList; - - public RedNoteKeyStruct(string notify, List paramList) - { - Notify = notify; - if (paramList != null) - { - ParamList = new List(paramList); - } - else - { - ParamList = new List(); - } - } - - private string _key; - - public string Key - { - get - { - if (string.IsNullOrEmpty(_key)) - { - _key = RedNoteMgr.GetKeyString(Notify, ParamList); - } - return _key; - } - } - - public bool IsSame(string notify, List paramList) - { - if (notify != Notify) - { - return false; - } - - var list1 = paramList; - var list2 = ParamList; - - int cnt1 = list1?.Count ?? 0; - int cnt2 = list2?.Count ?? 0; - - if (cnt1 != cnt2) - { - return false; - } - - if (cnt1 == 0) - { - return true; - } - - for (int i = 0; i < cnt1; i++) - { - // ReSharper disable PossibleNullReferenceException - if (list1[i] != list2[i]) - { - return false; - } - } - return true; - } -} \ No newline at end of file diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/RedNote/RedNoteMgr.cs.meta b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/RedNote/RedNoteMgr.cs.meta deleted file mode 100644 index 06edf7d8..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/RedNote/RedNoteMgr.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 66ededab0a1e409588f150be58193032 -timeCreated: 1687263893 \ No newline at end of file diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/RedNote/RedNoteValueItem.cs b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/RedNote/RedNoteValueItem.cs deleted file mode 100644 index 5a5de7ae..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/RedNote/RedNoteValueItem.cs +++ /dev/null @@ -1,159 +0,0 @@ -using System.Collections.Generic; - -namespace GameLogic -{ - public class RedNoteValueItem - { - public string m_key; - //所有关联的红点UI - private HashSet m_redNoteDic = new HashSet(); - private bool m_state; - private int m_pointNum; - private RedNoteType m_noteType; - - private bool m_dirty; - private bool m_tmpState; - - public void Init(string keyStr, RedNoteType noteType) - { - m_key = keyStr; - m_noteType = noteType; - } - - //添加红点对象 - public void AddRedNote(RedNoteBehaviour redNote) - { - m_redNoteDic.Add(redNote); - } - - //移除对象 - public void RemoveRedNote(RedNoteBehaviour redNote) - { - m_redNoteDic.Remove(redNote); - } - - //获取具体对象的状态 - public bool GetRedNoteState() - { - if (m_dirty) - { - return m_tmpState; - } - - return m_state; - } - - //获取具体对象的红点数 - public int GetRedNotePointNum() - { - return m_pointNum; - } - - public RedNoteType GetRedNoteType() - { - return m_noteType; - } - - public void SetStateDirty(bool state) - { - m_dirty = m_state != state; - m_tmpState = state; - } - - //设置对象状态 - public bool SetRedNoteState(bool state) - { - bool chg = state != m_state; - m_state = state; - if (chg) - { - SetBehaviourState(state); - } - - return chg; - } - - public bool SetRedNotePoint(int num) - { - if (m_pointNum != num) - { - m_pointNum = num; - SetBehaviourPoint(num); - return true; - } - - return false; - } - - private void SetBehaviourState(bool state) - { - //检查是否注册过具体对象 - foreach (var redNote in m_redNoteDic) - { - if (redNote == null || redNote.gameObject == null) - continue; - - redNote.SetRedNoteState(state); - } - - // 移除空的红点 - ClearTheNullRedNote(); - } - - private void SetBehaviourPoint(int pointNum) - { - foreach (var redNote in m_redNoteDic) - { - if (redNote == null || redNote.gameObject == null) - continue; - - redNote.SetRedNotePointNum(pointNum); - } - - // 移除空的红点 - ClearTheNullRedNote(); - } - - // 移除空的红点 - private void ClearTheNullRedNote() - { - m_redNoteDic.RemoveWhere(redNote => redNote == null || redNote.gameObject == null); - } - - //清理状态 - public void ClearRedNoteState(bool clearBehavior) - { - foreach (var redNote in m_redNoteDic) - { - if (redNote != null) - { - redNote.SetRedNoteState(false); - } - } - - if (clearBehavior) - { - m_redNoteDic.Clear(); - } - - m_state = false; - m_dirty = false; - m_tmpState = false; - } - - public void CheckDirty() - { - if (m_dirty) - { - m_dirty = false; - RedNoteMgr.Instance.SetNotifyKeyValue(m_key, m_tmpState); - } - } - } - - public enum RedNoteType - { - Simple, - WithNum, - } -} diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/RedNote/RedNoteValueItem.cs.meta b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/RedNote/RedNoteValueItem.cs.meta deleted file mode 100644 index 9b0646fa..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/RedNote/RedNoteValueItem.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 3c29f4a552c34bd8ab9d2c64b5b2b49d -timeCreated: 1687263893 \ No newline at end of file diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/RedNote/RedNoteWidget.cs b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/RedNote/RedNoteWidget.cs deleted file mode 100644 index 9dd9384c..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/RedNote/RedNoteWidget.cs +++ /dev/null @@ -1,57 +0,0 @@ -using TEngine; -using UnityEngine; -using UnityEngine.UI; - -namespace GameLogic -{ - public class RedNoteWidget : UIWidget - { - #region 脚本工具生成的代码 - protected override void ScriptGenerator() - { - } - #endregion - - private Image m_image; - public RedNoteBehaviour m_redNote; - protected override void OnCreate() - { - m_redNote = CreateWidget(gameObject); - m_image = gameObject.GetComponent(); - rectTransform.anchoredPosition = Vector2.zero; - SetNotifyState(false); - } - - public void SetNotifyType(RedNoteNotify notifyType) - { - m_redNote.SetNotifyType(notifyType); - } - public void SetNotifyType(RedNoteNotify notifyType, ulong param1) - { - m_redNote.SetNotifyType(notifyType, param1); - } - public void SetNotifyType(RedNoteNotify notifyType, ulong param1, ulong param2) - { - m_redNote.SetNotifyType(notifyType, param1, param2); - } - - public void SetNotifyState(bool state) - { - m_redNote.SetRedNoteState(state); - } - - public void SetSprite(string sprite) - { - // m_image.SetSprite(sprite); - } - - protected override void OnUpdate() - { - /*if (!m_redNote.CurState) - { - return; - } - gameObject.transform.localScale = RedNoteMgr.Instance.GlobalTwScale;*/ - } - } -} \ No newline at end of file diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/RedNote/RedNoteWidget.cs.meta b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/RedNote/RedNoteWidget.cs.meta deleted file mode 100644 index bb8bdff6..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/RedNote/RedNoteWidget.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 2644c5700a07442a995008ee9fa8159d -timeCreated: 1695289825 \ No newline at end of file diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/Shader/ActorShaderGroup.cs b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/Shader/ActorShaderGroup.cs deleted file mode 100644 index 492b4a31..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/Shader/ActorShaderGroup.cs +++ /dev/null @@ -1,49 +0,0 @@ -using UnityEngine; - -namespace TEngine -{ - /// - /// 封装一个角色可能用到的各种shader场景。 - /// - class ActorShaderGroup - { - private readonly TShader[] _allShader = new TShader[(int)ActorShaderEnvType.EnvTypeMax]; - - /// - /// 增加Shader到角色Shader分组。 - /// - /// 当前环境类型。 - /// TShader。 - public void AddShader(ActorShaderEnvType shaderType, TShader shader) - { - _allShader[(int)shaderType] = shader; - } - - /// - /// 根据当前环境获取Shader。 - /// - /// 当前环境类型。 - /// TShader。 - public TShader GetShader(ActorShaderEnvType type) - { - return _allShader[(int)type]; - } - - /// - /// 判断是否符合shader集合。 - /// - /// Shader实例。 - /// 是否符合。 - public bool IsMatch(Shader shader) - { - foreach (var dodShader in _allShader) - { - if (dodShader != null && dodShader.Shader == shader) - { - return true; - } - } - return false; - } - } -} \ No newline at end of file diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/Shader/ActorShaderGroup.cs.meta b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/Shader/ActorShaderGroup.cs.meta deleted file mode 100644 index ee2d57fd..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/Shader/ActorShaderGroup.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 79b6e5be73e14c929b6a3b4a980976ac -timeCreated: 1701916950 \ No newline at end of file diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/Shader/ActorShaderMgr.cs b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/Shader/ActorShaderMgr.cs deleted file mode 100644 index ae4e118c..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/Shader/ActorShaderMgr.cs +++ /dev/null @@ -1,117 +0,0 @@ -using GameBase; -using UnityEngine; - -namespace TEngine -{ - enum ActorShaderGroupType - { - /// - /// 通用的角色shader - /// - Brdf = 0, - - /// - /// 眼睛 - /// - BrdfEye, - - ///可能后面扩展,比如特效的特殊角色材质 - GroupMax, - } - - enum ActorShaderEnvType - { - /// - /// 游戏内场景默认模型,不带阴影,不带xray,不透明效果 - /// - EnvNormal = 0, - - /// - /// 展示场景 - /// - EnvShow, - - /// - /// 带阴影 - /// - EnvShadow, - - /// - /// 带xray,默认也带Shadow - /// - EnvXRay, - - /// - /// 透明渐隐效果 - /// - EnvAlphaFade, - - /// - /// 展示场景没shadow - /// - EnvShow_NoShadow, - - EnvTypeMax - } - - /// - /// 角色Shader管理器。 - /// - class ActorShaderMgr : Singleton - { - private readonly ActorShaderGroup[] _allShaderGroup = new ActorShaderGroup[(int)ActorShaderGroupType.GroupMax]; - - public ActorShaderMgr() - { - CreateBrdfShader(); - } - - /// - /// 根据当前Render查找角色的Shader分组。 - /// - /// Render。 - /// 角色的Shader分组。 - public ActorShaderGroup FindShaderGroup(Renderer render) - { - var sharedMat = render.sharedMaterial; - if (sharedMat == null) - { - return null; - } - - var shader = sharedMat.shader; - foreach (var group in _allShaderGroup) - { - if (group != null && group.IsMatch(shader)) - { - return group; - } - } - return null; - } - - private void CreateBrdfShader() - { - //通用的效果 - var actorShader = new ActorShaderGroup(); - actorShader.AddShader(ActorShaderEnvType.EnvNormal, new TShader("TEngine/Actor/ActorBrdf",shaderLocation:"ActorBrdf")); - actorShader.AddShader(ActorShaderEnvType.EnvShow, new TShader("TEngine/Actor/Show/ActorBrdf",shaderLocation:"ActorBrdf_Show")); - actorShader.AddShader(ActorShaderEnvType.EnvShow_NoShadow, new TShader("TEngine/Actor/Show/ActorBrdf_NoShadow",shaderLocation:"ActorBrdf_NoShadow")); - actorShader.AddShader(ActorShaderEnvType.EnvShadow, new TShader("TEngine/Actor/ActorBrdf",shaderLocation:"ActorBrdf_Normal")); - actorShader.AddShader(ActorShaderEnvType.EnvXRay, new TShader("TEngine/Actor/X-Ray",shaderLocation:"X-Ray")); - actorShader.AddShader(ActorShaderEnvType.EnvAlphaFade, new TShader("TEngine/Actor/Fade/ActorBrdf",shaderLocation:"ActorBrdf_Fade")); - _allShaderGroup[(int)ActorShaderGroupType.Brdf] = actorShader; - - - //眼睛效果 - actorShader = new ActorShaderGroup(); - actorShader.AddShader(ActorShaderEnvType.EnvNormal, new TShader("TEngine/Actor/ActorEye",shaderLocation:"ActorEye")); - actorShader.AddShader(ActorShaderEnvType.EnvShow, new TShader("TEngine/Actor/Show/ActorEye",shaderLocation:"ActorEye_Show", "MRT_DISABLE", "MRT_ENABLE")); - actorShader.AddShader(ActorShaderEnvType.EnvShadow, new TShader("TEngine/Actor/ActorEye",shaderLocation:"ActorEye")); - actorShader.AddShader(ActorShaderEnvType.EnvXRay, new TShader("TEngine/Actor/ActorEye",shaderLocation:"ActorEye")); - actorShader.AddShader(ActorShaderEnvType.EnvAlphaFade, new TShader("TEngine/Actor/Fade/ActorEye",shaderLocation:"ActorEye_Fade")); - - _allShaderGroup[(int)ActorShaderGroupType.BrdfEye] = actorShader; - } - } -} \ No newline at end of file diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/Shader/ActorShaderMgr.cs.meta b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/Shader/ActorShaderMgr.cs.meta deleted file mode 100644 index d75c41bd..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/Shader/ActorShaderMgr.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 5a38b9b4bee84fabb1ef8db5292a6db6 -timeCreated: 1701916853 \ No newline at end of file diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/Shader/TShader.cs b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/Shader/TShader.cs deleted file mode 100644 index 1c2ac63a..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/Shader/TShader.cs +++ /dev/null @@ -1,154 +0,0 @@ -using System.Collections.Generic; -using UnityEngine; - -namespace TEngine -{ - /// - /// TShader scripts used for all rendering. - /// 统一封装对shader的管理。 - /// - public class TShader - { - private bool _loaded; - private Shader _shader; - private readonly string _shaderName; - private readonly string _shaderLocation; - private readonly List _keywordOn = new List(); - private readonly List _keywordOff = new List(); - - /// - /// Shader scripts used for all rendering. - /// - public Shader Shader - { - get - { - if (!_loaded) - { - _loaded = true; - _shader = FindShader(_shaderLocation,_shaderName); - - if (_shader == null) - { - Log.Error($"invalid shader path: {_shaderLocation}, shader name {_shaderName}"); - } - } - - return _shader; - } - } - - /// - /// 查找Shader。 - /// - /// Shader定位地址。 - /// Shader名称。 - /// Shader实例。 - public static Shader FindShader(string shaderLocation,string shaderName) - { - Shader shader = GameModule.Resource.LoadAsset(shaderLocation); - if (shader != null) - { - return shader; - } - return Shader.Find(shaderName); - } - - /// - /// TShader构造函数。 - /// - /// shader名称。 - /// shader路径。 - public TShader(string shaderName, string shaderLocation) - { - _shaderName = shaderName; - _shaderLocation = shaderLocation; - _shader = null; - } - - /// - /// TShader构造函数。 - /// - /// shader名称。 - /// shader路径。 - /// 开启选项。 - /// 关闭选项。 - public TShader(string shaderName, string shaderLocation, string keywordOn, string keywordOff) - { - _shaderName = shaderName; - _shaderLocation = shaderLocation; - _shader = null; - _keywordOn.Add(keywordOn); - _keywordOff.Add(keywordOff); - } - - /// - /// TShader构造函数。 - /// - /// shader名称。 - /// shader路径。 - /// 开启选项。 - /// 关闭选项。 - public TShader(string shaderName, string shaderLocation, string[] keywordOn, string[] keywordOff) - { - _shaderName = shaderName; - _shaderLocation = shaderLocation; - _shader = null; - _keywordOn.AddRange(keywordOn); - _keywordOff.AddRange(keywordOff); - } - - /// - /// 设置Shader效果。 - /// - /// 渲染对象。 - public void ApplyRender(Renderer render) - { - var sharedMat = render.sharedMaterial; - if (sharedMat != null) - { - //copy一份材质 - sharedMat = render.material; - sharedMat.shader = Shader; - - foreach (var keyword in _keywordOff) - { - sharedMat.DisableKeyword(keyword); - } - - foreach (var keyword in _keywordOn) - { - sharedMat.EnableKeyword(keyword); - } - } - } - - /// - /// 清除shader。 - /// - /// 渲染对象。 - public void ClearRender(Renderer render) - { - if (_keywordOff.Count <= 0 && _keywordOn.Count <= 0) - { - return; - } - - var sharedMat = render.sharedMaterial; - if (sharedMat != null) - { - //copy一份材质。 - sharedMat = render.material; - for (int k = 0; k < _keywordOn.Count; k++) - { - sharedMat.DisableKeyword(_keywordOn[k]); - } - - for (int k = 0; k < _keywordOff.Count; k++) - { - sharedMat.EnableKeyword(_keywordOff[k]); - } - } - } - } -} \ No newline at end of file diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/Shader/TShader.cs.meta b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/Shader/TShader.cs.meta deleted file mode 100644 index 73a0252d..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/Shader/TShader.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: e219233984c14f7d97bc744c07fe13d0 -timeCreated: 1698115491 \ No newline at end of file diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SuperScrollView.meta b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SuperScrollView.meta deleted file mode 100644 index 9b3e1fec..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SuperScrollView.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 0615e8b32d534bc48a60e42c973053ad -timeCreated: 1695289443 \ No newline at end of file diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SuperScrollView/Scripts/Common/ClickEventListener.cs b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SuperScrollView/Scripts/Common/ClickEventListener.cs deleted file mode 100644 index 8a98b216..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SuperScrollView/Scripts/Common/ClickEventListener.cs +++ /dev/null @@ -1,84 +0,0 @@ -using UnityEngine; -using UnityEngine.EventSystems; - -namespace GameLogic -{ - public class ClickEventListener : MonoBehaviour, IPointerClickHandler, IPointerDownHandler, IPointerUpHandler - { - public static ClickEventListener Get(GameObject obj) - { - ClickEventListener listener = obj.GetComponent(); - if (listener == null) - { - listener = obj.AddComponent(); - } - - return listener; - } - - private System.Action _clickedHandler = null; - private System.Action _doubleClickedHandler = null; - private System.Action _onPointerDownHandler = null; - private System.Action _onPointerUpHandler = null; - bool _isPressed = false; - - public bool IsPressed => _isPressed; - - public void OnPointerClick(PointerEventData eventData) - { - if (eventData.clickCount == 2) - { - if (_doubleClickedHandler != null) - { - _doubleClickedHandler(gameObject); - } - } - else - { - if (_clickedHandler != null) - { - _clickedHandler(gameObject); - } - } - } - - public void SetClickEventHandler(System.Action handler) - { - _clickedHandler = handler; - } - - public void SetDoubleClickEventHandler(System.Action handler) - { - _doubleClickedHandler = handler; - } - - public void SetPointerDownHandler(System.Action handler) - { - _onPointerDownHandler = handler; - } - - public void SetPointerUpHandler(System.Action handler) - { - _onPointerUpHandler = handler; - } - - - public void OnPointerDown(PointerEventData eventData) - { - _isPressed = true; - if (_onPointerDownHandler != null) - { - _onPointerDownHandler(gameObject); - } - } - - public void OnPointerUp(PointerEventData eventData) - { - _isPressed = false; - if (_onPointerUpHandler != null) - { - _onPointerUpHandler(gameObject); - } - } - } -} \ No newline at end of file diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SuperScrollView/Scripts/Common/CommonDefine.cs b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SuperScrollView/Scripts/Common/CommonDefine.cs deleted file mode 100644 index 236decdd..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SuperScrollView/Scripts/Common/CommonDefine.cs +++ /dev/null @@ -1,86 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace GameLogic -{ - - public enum SnapStatus - { - NoTargetSet = 0, - TargetHasSet = 1, - SnapMoving = 2, - SnapMoveFinish = 3 - } - - - public enum ItemCornerEnum - { - LeftBottom = 0, - LeftTop, - RightTop, - RightBottom, - } - - - public enum ListItemArrangeType - { - TopToBottom = 0, - BottomToTop, - LeftToRight, - RightToLeft, - } - - public enum GridItemArrangeType - { - TopLeftToBottomRight = 0, - BottomLeftToTopRight, - TopRightToBottomLeft, - BottomRightToTopLeft, - } - public enum GridFixedType - { - ColumnCountFixed = 0, - RowCountFixed, - } - - public struct RowColumnPair - { - public RowColumnPair(int row1, int column1) - { - mRow = row1; - mColumn = column1; - } - - public bool Equals(RowColumnPair other) - { - return this.mRow == other.mRow && this.mColumn == other.mColumn; - } - - public static bool operator ==(RowColumnPair a, RowColumnPair b) - { - return (a.mRow == b.mRow)&&(a.mColumn == b.mColumn); - } - public static bool operator !=(RowColumnPair a, RowColumnPair b) - { - return (a.mRow != b.mRow) || (a.mColumn != b.mColumn); ; - } - - public override int GetHashCode() - { - return 0; - } - - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) - { - return false; - } - return (obj is RowColumnPair) && Equals((RowColumnPair)obj); - } - - - public int mRow; - public int mColumn; - } -} diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SuperScrollView/Scripts/Common/CommonDefine.cs.meta b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SuperScrollView/Scripts/Common/CommonDefine.cs.meta deleted file mode 100644 index bac5dd80..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SuperScrollView/Scripts/Common/CommonDefine.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 19e4e487f35877f4b9bb864eb43484d6 -timeCreated: 1534508353 -licenseType: Store -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SuperScrollView/Scripts/Common/ItemPosMgr.cs b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SuperScrollView/Scripts/Common/ItemPosMgr.cs deleted file mode 100644 index 2957fac5..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SuperScrollView/Scripts/Common/ItemPosMgr.cs +++ /dev/null @@ -1,326 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace GameLogic -{ - public class ItemSizeGroup - { - public float[] ItemSizeArray = null; - public float[] ItemStartPosArray = null; - public int ItemCount = 0; - private int _dirtyBeginIndex = ItemPosMgr.ItemMaxCountPerGroup; - public float GroupSize = 0; - public float GroupStartPos = 0; - public float GroupEndPos = 0; - public int GroupIndex = 0; - public float ItemDefaultSize = 0; - - public ItemSizeGroup(int index, float itemDefaultSize) - { - GroupIndex = index; - ItemDefaultSize = itemDefaultSize; - Init(); - } - - public void Init() - { - ItemSizeArray = new float[ItemPosMgr.ItemMaxCountPerGroup]; - if (ItemDefaultSize != 0) - { - for (int i = 0; i < ItemSizeArray.Length; ++i) - { - ItemSizeArray[i] = ItemDefaultSize; - } - } - - ItemStartPosArray = new float[ItemPosMgr.ItemMaxCountPerGroup]; - ItemStartPosArray[0] = 0; - ItemCount = ItemPosMgr.ItemMaxCountPerGroup; - GroupSize = ItemDefaultSize * ItemSizeArray.Length; - if (ItemDefaultSize != 0) - { - _dirtyBeginIndex = 0; - } - else - { - _dirtyBeginIndex = ItemPosMgr.ItemMaxCountPerGroup; - } - } - - public float GetItemStartPos(int index) - { - return GroupStartPos + ItemStartPosArray[index]; - } - - public bool IsDirty - { - get { return (_dirtyBeginIndex < ItemCount); } - } - - public float SetItemSize(int index, float size) - { - float old = ItemSizeArray[index]; - if (Math.Abs(old - size) < 0.001f) - { - return 0; - } - - ItemSizeArray[index] = size; - if (index < _dirtyBeginIndex) - { - _dirtyBeginIndex = index; - } - - float ds = size - old; - GroupSize = GroupSize + ds; - return ds; - } - - public void SetItemCount(int count) - { - if (ItemCount == count) - { - return; - } - - ItemCount = count; - RecalcGroupSize(); - } - - public void RecalcGroupSize() - { - GroupSize = 0; - for (int i = 0; i < ItemCount; ++i) - { - GroupSize += ItemSizeArray[i]; - } - } - - public int GetItemIndexByPos(float pos) - { - if (ItemCount == 0) - { - return -1; - } - - int low = 0; - int high = ItemCount - 1; - while (low <= high) - { - int mid = (low + high) / 2; - float startPos = ItemStartPosArray[mid]; - float endPos = startPos + ItemSizeArray[mid]; - if (startPos <= pos && endPos >= pos) - { - return mid; - } - else if (pos > endPos) - { - low = mid + 1; - } - else - { - high = mid - 1; - } - } - - return -1; - } - - public void UpdateAllItemStartPos() - { - if (_dirtyBeginIndex >= ItemCount) - { - return; - } - - int startIndex = (_dirtyBeginIndex < 1) ? 1 : _dirtyBeginIndex; - for (int i = startIndex; i < ItemCount; ++i) - { - ItemStartPosArray[i] = ItemStartPosArray[i - 1] + ItemSizeArray[i - 1]; - } - - _dirtyBeginIndex = ItemCount; - } - } - - public class ItemPosMgr - { - public const int ItemMaxCountPerGroup = 100; - readonly List _itemSizeGroupList = new List(); - public int _dirtyBeginIndex = int.MaxValue; - public float TotalSize = 0; - public float ItemDefaultSize = 20; - - public ItemPosMgr(float itemDefaultSize) - { - ItemDefaultSize = itemDefaultSize; - } - - public void SetItemMaxCount(int maxCount) - { - _dirtyBeginIndex = 0; - TotalSize = 0; - int st = maxCount % ItemMaxCountPerGroup; - int lastGroupItemCount = st; - int needMaxGroupCount = maxCount / ItemMaxCountPerGroup; - if (st > 0) - { - needMaxGroupCount++; - } - else - { - lastGroupItemCount = ItemMaxCountPerGroup; - } - - int count = _itemSizeGroupList.Count; - if (count > needMaxGroupCount) - { - int d = count - needMaxGroupCount; - _itemSizeGroupList.RemoveRange(needMaxGroupCount, d); - } - else if (count < needMaxGroupCount) - { - int d = needMaxGroupCount - count; - for (int i = 0; i < d; ++i) - { - ItemSizeGroup tGroup = new ItemSizeGroup(count + i, ItemDefaultSize); - _itemSizeGroupList.Add(tGroup); - } - } - - count = _itemSizeGroupList.Count; - if (count == 0) - { - return; - } - - for (int i = 0; i < count - 1; ++i) - { - _itemSizeGroupList[i].SetItemCount(ItemMaxCountPerGroup); - } - - _itemSizeGroupList[count - 1].SetItemCount(lastGroupItemCount); - for (int i = 0; i < count; ++i) - { - TotalSize = TotalSize + _itemSizeGroupList[i].GroupSize; - } - } - - public void SetItemSize(int itemIndex, float size) - { - int groupIndex = itemIndex / ItemMaxCountPerGroup; - int indexInGroup = itemIndex % ItemMaxCountPerGroup; - ItemSizeGroup tGroup = _itemSizeGroupList[groupIndex]; - float changedSize = tGroup.SetItemSize(indexInGroup, size); - if (changedSize != 0f) - { - if (groupIndex < _dirtyBeginIndex) - { - _dirtyBeginIndex = groupIndex; - } - } - - TotalSize += changedSize; - } - - public float GetItemPos(int itemIndex) - { - Update(true); - int groupIndex = itemIndex / ItemMaxCountPerGroup; - int indexInGroup = itemIndex % ItemMaxCountPerGroup; - return _itemSizeGroupList[groupIndex].GetItemStartPos(indexInGroup); - } - - public void GetItemIndexAndPosAtGivenPos(float pos, ref int index, ref float itemPos) - { - Update(true); - index = 0; - itemPos = 0f; - int count = _itemSizeGroupList.Count; - if (count == 0) - { - return; - } - - ItemSizeGroup hitGroup = null; - - int low = 0; - int high = count - 1; - while (low <= high) - { - int mid = (low + high) / 2; - ItemSizeGroup tGroup = _itemSizeGroupList[mid]; - if (tGroup.GroupStartPos <= pos && tGroup.GroupEndPos >= pos) - { - hitGroup = tGroup; - break; - } - else if (pos > tGroup.GroupEndPos) - { - low = mid + 1; - } - else - { - high = mid - 1; - } - } - - int hitIndex = -1; - if (hitGroup != null) - { - hitIndex = hitGroup.GetItemIndexByPos(pos - hitGroup.GroupStartPos); - } - else - { - return; - } - - if (hitIndex < 0) - { - return; - } - - index = hitIndex + hitGroup.GroupIndex * ItemMaxCountPerGroup; - itemPos = hitGroup.GetItemStartPos(hitIndex); - } - - public void Update(bool updateAll) - { - int count = _itemSizeGroupList.Count; - if (count == 0) - { - return; - } - - if (_dirtyBeginIndex >= count) - { - return; - } - - int loopCount = 0; - for (int i = _dirtyBeginIndex; i < count; ++i) - { - loopCount++; - ItemSizeGroup tGroup = _itemSizeGroupList[i]; - _dirtyBeginIndex++; - tGroup.UpdateAllItemStartPos(); - if (i == 0) - { - tGroup.GroupStartPos = 0; - tGroup.GroupEndPos = tGroup.GroupSize; - } - else - { - tGroup.GroupStartPos = _itemSizeGroupList[i - 1].GroupEndPos; - tGroup.GroupEndPos = tGroup.GroupStartPos + tGroup.GroupSize; - } - - if (!updateAll && loopCount > 1) - { - return; - } - } - } - } -} \ No newline at end of file diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SuperScrollView/Scripts/GridView.meta b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SuperScrollView/Scripts/GridView.meta deleted file mode 100644 index 4494e8c8..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SuperScrollView/Scripts/GridView.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: d7f738dc5a266e94d9e9870fc76009c2 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SuperScrollView/Scripts/GridView/GridItemGroup.cs b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SuperScrollView/Scripts/GridView/GridItemGroup.cs deleted file mode 100644 index e7e40dd7..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SuperScrollView/Scripts/GridView/GridItemGroup.cs +++ /dev/null @@ -1,173 +0,0 @@ -namespace GameLogic -{ - //if GridFixedType is GridFixedType.ColumnCountFixed, then the GridItemGroup is one row of the gridview - //if GridFixedType is GridFixedType.RowCountFixed, then the GridItemGroup is one column of the gridview - public class GridItemGroup - { - private int _count = 0; - private int _groupIndex = -1;//the row index or the column index of this group - private LoopGridViewItem _first = null; - private LoopGridViewItem _last = null; - public int Count => _count; - - public LoopGridViewItem First => _first; - - public LoopGridViewItem Last => _last; - - public int GroupIndex - { - get => _groupIndex; - set => _groupIndex = value; - } - - - public LoopGridViewItem GetItemByColumn(int column) - { - LoopGridViewItem cur = _first; - while(cur != null) - { - if(cur.Column == column) - { - return cur; - } - cur = cur.NextItem; - } - return null; - } - public LoopGridViewItem GetItemByRow(int row) - { - LoopGridViewItem cur = _first; - while (cur != null) - { - if (cur.Row == row) - { - return cur; - } - cur = cur.NextItem; - } - return null; - } - - - public void ReplaceItem(LoopGridViewItem curItem,LoopGridViewItem newItem) - { - newItem.PrevItem = curItem.PrevItem; - newItem.NextItem = curItem.NextItem; - if(newItem.PrevItem != null) - { - newItem.PrevItem.NextItem = newItem; - } - if(newItem.NextItem != null) - { - newItem.NextItem.PrevItem = newItem; - } - if(_first == curItem) - { - _first = newItem; - } - if(_last == curItem) - { - _last = newItem; - } - } - - public void AddFirst(LoopGridViewItem newItem) - { - newItem.PrevItem = null; - newItem.NextItem = null; - if (_first == null) - { - _first = newItem; - _last = newItem; - _first.PrevItem = null; - _first.NextItem = null; - _count++; - } - else - { - _first.PrevItem = newItem; - newItem.PrevItem = null; - newItem.NextItem = _first; - _first = newItem; - _count++; - } - } - - public void AddLast(LoopGridViewItem newItem) - { - newItem.PrevItem = null; - newItem.NextItem = null; - if (_first == null) - { - _first = newItem; - _last = newItem; - _first.PrevItem = null; - _first.NextItem = null; - _count++; - } - else - { - _last.NextItem = newItem; - newItem.PrevItem = _last; - newItem.NextItem = null; - _last = newItem; - _count++; - } - } - - public LoopGridViewItem RemoveFirst() - { - LoopGridViewItem ret = _first; - if (_first == null) - { - return ret; - } - if(_first == _last) - { - _first = null; - _last = null; - --_count; - return ret; - } - _first = _first.NextItem; - _first.PrevItem = null; - --_count; - return ret; - } - public LoopGridViewItem RemoveLast() - { - LoopGridViewItem ret = _last; - if (_first == null) - { - return ret; - } - if (_first == _last) - { - _first = null; - _last = null; - --_count; - return ret; - } - _last = _last.PrevItem; - _last.NextItem = null; - --_count; - return ret; - } - - - public void Clear() - { - LoopGridViewItem current = _first; - while (current != null) - { - current.PrevItem = null; - current.NextItem = null; - current = current.NextItem; - } - _first = null; - _last = null; - _count = 0; - } - - } -} diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SuperScrollView/Scripts/GridView/GridItemGroup.cs.meta b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SuperScrollView/Scripts/GridView/GridItemGroup.cs.meta deleted file mode 100644 index 9b5bee46..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SuperScrollView/Scripts/GridView/GridItemGroup.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: f7e7eb25fe1319d4b8773ddfab7a240e -timeCreated: 1554538573 -licenseType: Store -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SuperScrollView/Scripts/GridView/LoopGridItemPool.cs b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SuperScrollView/Scripts/GridView/LoopGridItemPool.cs deleted file mode 100644 index d31c30d4..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SuperScrollView/Scripts/GridView/LoopGridItemPool.cs +++ /dev/null @@ -1,113 +0,0 @@ -using System; -using System.Collections.Generic; -using UnityEngine; - - -namespace GameLogic -{ - public class GridItemPool - { - private GameObject _prefabObj; - private string _prefabName; - private int _initCreateCount = 1; - private readonly List _tmpPooledItemList = new List(); - private readonly List _pooledItemList = new List(); - private static int _curItemIdCount = 0; - private RectTransform _itemParent = null; - public GridItemPool() - { - - } - public void Init(GameObject prefabObj, int createCount, RectTransform parent) - { - _prefabObj = prefabObj; - _prefabName = _prefabObj.name; - _initCreateCount = createCount; - _itemParent = parent; - _prefabObj.SetActive(false); - for (int i = 0; i < _initCreateCount; ++i) - { - LoopGridViewItem tViewItem = CreateItem(); - RecycleItemReal(tViewItem); - } - } - public LoopGridViewItem GetItem() - { - _curItemIdCount++; - LoopGridViewItem tItem = null; - if (_tmpPooledItemList.Count > 0) - { - int count = _tmpPooledItemList.Count; - tItem = _tmpPooledItemList[count - 1]; - _tmpPooledItemList.RemoveAt(count - 1); - tItem.gameObject.SetActive(true); - } - else - { - int count = _pooledItemList.Count; - if (count == 0) - { - tItem = CreateItem(); - } - else - { - tItem = _pooledItemList[count - 1]; - _pooledItemList.RemoveAt(count - 1); - tItem.gameObject.SetActive(true); - } - } - tItem.ItemId = _curItemIdCount; - return tItem; - - } - - public void DestroyAllItem() - { - ClearTmpRecycledItem(); - int count = _pooledItemList.Count; - for (int i = 0; i < count; ++i) - { - GameObject.DestroyImmediate(_pooledItemList[i].gameObject); - } - _pooledItemList.Clear(); - } - public LoopGridViewItem CreateItem() - { - - GameObject go = GameObject.Instantiate(_prefabObj, Vector3.zero, Quaternion.identity, _itemParent); - go.SetActive(true); - RectTransform rf = go.GetComponent(); - rf.localScale = Vector3.one; - rf.anchoredPosition3D = Vector3.zero; - rf.localEulerAngles = Vector3.zero; - LoopGridViewItem tViewItem = go.GetComponent(); - tViewItem.ItemPrefabName = _prefabName; - tViewItem.GoId = go.GetHashCode(); - return tViewItem; - } - void RecycleItemReal(LoopGridViewItem item) - { - item.gameObject.SetActive(false); - _pooledItemList.Add(item); - } - public void RecycleItem(LoopGridViewItem item) - { - item.PrevItem = null; - item.NextItem = null; - _tmpPooledItemList.Add(item); - } - public void ClearTmpRecycledItem() - { - int count = _tmpPooledItemList.Count; - if (count == 0) - { - return; - } - for (int i = 0; i < count; ++i) - { - RecycleItemReal(_tmpPooledItemList[i]); - } - _tmpPooledItemList.Clear(); - } - } -} diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SuperScrollView/Scripts/GridView/LoopGridItemPool.cs.meta b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SuperScrollView/Scripts/GridView/LoopGridItemPool.cs.meta deleted file mode 100644 index f81971a0..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SuperScrollView/Scripts/GridView/LoopGridItemPool.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: c1eb92a17e8cee642a2245950dfaabea -timeCreated: 1554538573 -licenseType: Store -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SuperScrollView/Scripts/GridView/LoopGridView.cs b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SuperScrollView/Scripts/GridView/LoopGridView.cs deleted file mode 100644 index 3ed3eea8..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SuperScrollView/Scripts/GridView/LoopGridView.cs +++ /dev/null @@ -1,2019 +0,0 @@ -using System.Collections.Generic; -using TEngine; -using UnityEngine; -using UnityEngine.UI; -using UnityEngine.EventSystems; - -namespace GameLogic -{ - [System.Serializable] - public class GridViewItemPrefabConfData - { - public GameObject itemPrefab = null; - public int initCreateCount = 0; - } - - - public class LoopGridViewInitParam - { - // all the default values - public float SmoothDumpRate = 0.3f; - public float SnapFinishThreshold = 0.01f; - public float SnapVecThreshold = 145; - - public static LoopGridViewInitParam CopyDefaultInitParam() - { - return new LoopGridViewInitParam(); - } - } - - - public class LoopGridViewSettingParam - { - public object ItemSize = null; - public object Padding = null; - public object ItemPadding = null; - public object GridFixedType = null; - public object FixedRowOrColumnCount = null; - } - - - public class LoopGridView : MonoBehaviour, IBeginDragHandler, IEndDragHandler, IDragHandler - { - class SnapData - { - public SnapStatus SnapStatus = SnapStatus.NoTargetSet; - public RowColumnPair SnapTarget; - public Vector2 SnapNeedMoveDir; - public float TargetSnapVal = 0; - public float CurSnapVal = 0; - public bool IsForceSnapTo = false; - - public void Clear() - { - SnapStatus = SnapStatus.NoTargetSet; - IsForceSnapTo = false; - } - } - - class ItemRangeData - { - public int MaxRow; - public int MinRow; - public int MaxColumn; - public int MinColumn; - public Vector2 CheckedPosition; - } - - private readonly Dictionary _itemPoolDict = new Dictionary(); - private readonly List _itemPoolList = new List(); - [SerializeField] private List mItemPrefabDataList = new List(); - - [SerializeField] private GridItemArrangeType mArrangeType = GridItemArrangeType.TopLeftToBottomRight; - - public GridItemArrangeType ArrangeType - { - get => mArrangeType; - set => mArrangeType = value; - } - - private RectTransform _containerTrans; - private ScrollRect _scrollRect = null; - private RectTransform _scrollRectTransform = null; - private RectTransform _viewPortRectTransform = null; - private int _itemTotalCount = 0; - [SerializeField] int mFixedRowOrColumnCount = 0; - [SerializeField] RectOffset mPadding = new RectOffset(); - [SerializeField] Vector2 mItemPadding = Vector2.zero; - [SerializeField] Vector2 mItemSize = Vector2.zero; - [SerializeField] Vector2 mItemRecycleDistance = new Vector2(50, 50); - private Vector2 _itemSizeWithPadding = Vector2.zero; - private Vector2 _startPadding; - private Vector2 _endPadding; - private System.Func _onGetItemByRowColumn; - private readonly List _itemGroupObjPool = new List(); - - //if GridFixedType is GridFixedType.ColumnCountFixed, then the GridItemGroup is one row of the GridView - //if GridFixedType is GridFixedType.RowCountFixed, then the GridItemGroup is one column of the GridView - //so mItemGroupList is current all shown rows or columns - private readonly List _itemGroupList = new List(); - - private bool _isDragging = false; - private int _rowCount = 0; - private int _columnCount = 0; - public System.Action OnBeginDragAction = null; - public System.Action OnDragingAction = null; - public System.Action OnEndDragAction = null; - private float _smoothDumpVel = 0; - private float _smoothDumpRate = 0.3f; - private float _snapFinishThreshold = 0.1f; - private float _snapVecThreshold = 145; - [SerializeField] bool mItemSnapEnable = false; - [SerializeField] GridFixedType mGridFixedType = GridFixedType.ColumnCountFixed; - - public System.Action OnSnapItemFinished = null; - - //in this callback, use CurSnapNearestItemRowColumn to get cur snaped item row column. - public System.Action OnSnapNearestChanged = null; - private int _leftSnapUpdateExtraCount = 1; - [SerializeField] Vector2 mViewPortSnapPivot = Vector2.zero; - [SerializeField] Vector2 mItemSnapPivot = Vector2.zero; - private SnapData _curSnapData = new SnapData(); - private Vector3 _lastSnapCheckPos = Vector3.zero; - private bool _listViewInited = false; - private int _listUpdateCheckFrameCount = 0; - private ItemRangeData _curFrameItemRangeData = new ItemRangeData(); - private int _needCheckContentPosLeftCount = 1; - private ClickEventListener _scrollBarClickEventListener1 = null; - private ClickEventListener _scrollBarClickEventListener2 = null; - - private RowColumnPair _curSnapNearestItemRowColumn; - - public List ItemPrefabDataList => mItemPrefabDataList; - - public int ItemTotalCount => _itemTotalCount; - - public RectTransform ContainerTrans => _containerTrans; - - public float ViewPortWidth => _viewPortRectTransform.rect.width; - - public float ViewPortHeight => _viewPortRectTransform.rect.height; - - public ScrollRect ScrollRect => _scrollRect; - - public bool IsDragging => _isDragging; - - public bool ItemSnapEnable - { - get => mItemSnapEnable; - set => mItemSnapEnable = value; - } - - public Vector2 ItemSize - { - get => mItemSize; - set => SetItemSize(value); - } - - public Vector2 ItemPadding - { - get => mItemPadding; - set => SetItemPadding(value); - } - - public Vector2 ItemSizeWithPadding => _itemSizeWithPadding; - - public RectOffset Padding - { - get => mPadding; - set => SetPadding(value); - } - - - public GridViewItemPrefabConfData GetItemPrefabConfData(string prefabName) - { - foreach (GridViewItemPrefabConfData data in mItemPrefabDataList) - { - if (data.itemPrefab == null) - { - Debug.LogError("A item prefab is null "); - continue; - } - - if (prefabName == data.itemPrefab.name) - { - return data; - } - } - - return null; - } - - /* - LoopGridView method is to initiate the LoopGridView component. There are 4 parameters: - itemTotalCount: the total item count in the GridView, this parameter must be set a value >=0 , then the ItemIndex can be from 0 to itemTotalCount -1. - onGetItemByRowColumn: when a item is getting in the ScrollRect viewport, and this Action will be called with the item' index and the row and column index as the parameters, to let you create the item and update its content. - settingParam: You can use this parameter to override the values in the Inspector Setting - */ - public void InitGridView(int itemTotalCount, - System.Func onGetItemByRowColumn, - LoopGridViewSettingParam settingParam = null, - LoopGridViewInitParam initParam = null) - { - if (_listViewInited == true) - { - Debug.LogError("LoopGridView.InitListView method can be called only once."); - return; - } - - _listViewInited = true; - if (itemTotalCount < 0) - { - Debug.LogError("itemTotalCount is < 0"); - itemTotalCount = 0; - } - - if (settingParam != null) - { - UpdateFromSettingParam(settingParam); - } - - if (initParam != null) - { - _smoothDumpRate = initParam.SmoothDumpRate; - _snapFinishThreshold = initParam.SnapFinishThreshold; - _snapVecThreshold = initParam.SnapVecThreshold; - } - - _scrollRect = gameObject.GetComponent(); - if (_scrollRect == null) - { - Debug.LogError("ListView Init Failed! ScrollRect component not found!"); - return; - } - - _curSnapData.Clear(); - _scrollRectTransform = _scrollRect.GetComponent(); - _containerTrans = _scrollRect.content; - _viewPortRectTransform = _scrollRect.viewport; - if (_viewPortRectTransform == null) - { - _viewPortRectTransform = _scrollRectTransform; - } - - if (_scrollRect.horizontalScrollbarVisibility == ScrollRect.ScrollbarVisibility.AutoHideAndExpandViewport && - _scrollRect.horizontalScrollbar != null) - { - Debug.LogError("ScrollRect.horizontalScrollbarVisibility cannot be set to AutoHideAndExpandViewport"); - } - - if (_scrollRect.verticalScrollbarVisibility == ScrollRect.ScrollbarVisibility.AutoHideAndExpandViewport && _scrollRect.verticalScrollbar != null) - { - Debug.LogError("ScrollRect.verticalScrollbarVisibility cannot be set to AutoHideAndExpandViewport"); - } - - SetScrollbarListener(); - AdjustViewPortPivot(); - AdjustContainerAnchorAndPivot(); - InitItemPool(); - _onGetItemByRowColumn = onGetItemByRowColumn; - _needCheckContentPosLeftCount = 4; - _curSnapData.Clear(); - _itemTotalCount = itemTotalCount; - UpdateAllGridSetting(); - } - - - /* - This method may use to set the item total count of the GridView at runtime. - this parameter must be set a value >=0 , and the ItemIndex can be from 0 to itemCount -1. - If resetPos is set false, then the ScrollRect’s content position will not changed after this method finished. - */ - public void SetListItemCount(int itemCount, bool resetPos = true) - { - if (itemCount < 0) - { - return; - } - - if (itemCount == _itemTotalCount) - { - return; - } - - _curSnapData.Clear(); - _itemTotalCount = itemCount; - UpdateColumnRowCount(); - UpdateContentSize(); - ForceToCheckContentPos(); - if (_itemTotalCount == 0) - { - RecycleAllItem(); - ClearAllTmpRecycledItem(); - return; - } - - VaildAndSetContainerPos(); - UpdateGridViewContent(); - ClearAllTmpRecycledItem(); - if (resetPos) - { - MovePanelToItemByRowColumn(0, 0); - return; - } - } - - //fetch or create a new item form the item pool. - public LoopGridViewItem NewListViewItem(string itemPrefabName) - { - GridItemPool pool = null; - if (_itemPoolDict.TryGetValue(itemPrefabName, out pool) == false) - { - return null; - } - - LoopGridViewItem item = pool.GetItem(); - RectTransform rf = item.GetComponent(); - rf.SetParent(_containerTrans); - rf.localScale = Vector3.one; - rf.anchoredPosition3D = Vector3.zero; - rf.localEulerAngles = Vector3.zero; - item.ParentGridView = this; - return item; - } - - public LoopGridViewItem AllocOrNewListViewItem(string itemPrefabName) - { - GridItemPool pool = null; - if (!string.IsNullOrEmpty(itemPrefabName)) - { - if (_itemPoolDict.TryGetValue(itemPrefabName, out pool) == false) - { - pool = TryCreateItemPool(itemPrefabName); - if (pool == null) - { - return null; - } - } - - return AllocOrNewListViewItem(pool); - } - - return null; - } - - public LoopGridViewItem AllocOrNewListViewItem(GameObject prefabGo) - { - GridItemPool pool = null; - if (prefabGo != null) - { - if (_itemPoolDict.TryGetValue(prefabGo.name, out pool) == false) - { - pool = TryCreateItemPool(prefabGo); - if (pool == null) - { - return null; - } - } - - return AllocOrNewListViewItem(pool); - } - - return null; - } - - private LoopGridViewItem AllocOrNewListViewItem(GridItemPool pool) - { - LoopGridViewItem item = pool.GetItem(); - RectTransform rf = item.GetComponent(); - rf.SetParent(_containerTrans); - rf.localScale = Vector3.one; - rf.localPosition = Vector3.zero; - rf.localEulerAngles = Vector3.zero; - item.ParentGridView = this; - return item; - } - - private GridItemPool TryCreateItemPool(string itemPrefabName) - { - string resPath = itemPrefabName; - GameObject go = GameModule.Resource.LoadGameObject(resPath, parent: _containerTrans); - if (go != null) - { - go.SetActive(false); - go.name = itemPrefabName; - GridItemPool pool = new GridItemPool(); - pool.Init(go, 0, _containerTrans); - _itemPoolDict.Add(itemPrefabName, pool); - _itemPoolList.Add(pool); - return pool; - } - - return null; - } - - private GridItemPool TryCreateItemPool(GameObject itemPrefab) - { - if (itemPrefab != null) - { - itemPrefab.SetActive(false); - GridItemPool pool = new GridItemPool(); - pool.Init(itemPrefab, 0, _containerTrans); - _itemPoolDict.Add(itemPrefab.name, pool); - _itemPoolList.Add(pool); - return pool; - } - - return null; - } - - - /* - To update a item by itemIndex.if the itemIndex-th item is not visible, then this method will do nothing. - Otherwise this method will call RefreshItemByRowColumn to do real work. - */ - public void RefreshItemByItemIndex(int itemIndex) - { - if (itemIndex < 0 || itemIndex >= ItemTotalCount) - { - return; - } - - int count = _itemGroupList.Count; - if (count == 0) - { - return; - } - - RowColumnPair val = GetRowColumnByItemIndex(itemIndex); - RefreshItemByRowColumn(val.mRow, val.mColumn); - } - - - /* - To update a item by (row,column).if the item is not visible, then this method will do nothing. - Otherwise this method will call mOnGetItemByRowColumn(row,column) to get a new updated item. - */ - public void RefreshItemByRowColumn(int row, int column) - { - int count = _itemGroupList.Count; - if (count == 0) - { - return; - } - - if (mGridFixedType == GridFixedType.ColumnCountFixed) - { - GridItemGroup group = GetShownGroup(row); - if (group == null) - { - return; - } - - LoopGridViewItem curItem = group.GetItemByColumn(column); - if (curItem == null) - { - return; - } - - LoopGridViewItem newItem = GetNewItemByRowColumn(row, column); - if (newItem == null) - { - return; - } - - Vector3 pos = curItem.CachedRectTransform.anchoredPosition3D; - group.ReplaceItem(curItem, newItem); - RecycleItemTmp(curItem); - newItem.CachedRectTransform.anchoredPosition3D = pos; - ClearAllTmpRecycledItem(); - } - else - { - GridItemGroup group = GetShownGroup(column); - if (group == null) - { - return; - } - - LoopGridViewItem curItem = group.GetItemByRow(row); - if (curItem == null) - { - return; - } - - LoopGridViewItem newItem = GetNewItemByRowColumn(row, column); - if (newItem == null) - { - return; - } - - Vector3 pos = curItem.CachedRectTransform.anchoredPosition3D; - group.ReplaceItem(curItem, newItem); - RecycleItemTmp(curItem); - newItem.CachedRectTransform.anchoredPosition3D = pos; - ClearAllTmpRecycledItem(); - } - } - - //Clear current snap target and then the GridView will auto snap to the CurSnapNearestItem. - public void ClearSnapData() - { - _curSnapData.Clear(); - } - - //set cur snap target - public void SetSnapTargetItemRowColumn(int row, int column) - { - if (row < 0) - { - row = 0; - } - - if (column < 0) - { - column = 0; - } - - _curSnapData.SnapTarget.mRow = row; - _curSnapData.SnapTarget.mColumn = column; - _curSnapData.SnapStatus = SnapStatus.TargetHasSet; - _curSnapData.IsForceSnapTo = true; - } - - //Get the nearest item row and column with the viewport snap point. - public RowColumnPair CurSnapNearestItemRowColumn => _curSnapNearestItemRowColumn; - - - //force to update the mCurSnapNearestItemRowColumn value - public void ForceSnapUpdateCheck() - { - if (_leftSnapUpdateExtraCount <= 0) - { - _leftSnapUpdateExtraCount = 1; - } - } - - //force to refresh the mCurFrameItemRangeData that what items should be shown in viewport. - public void ForceToCheckContentPos() - { - if (_needCheckContentPosLeftCount <= 0) - { - _needCheckContentPosLeftCount = 1; - } - } - - /* - This method will move the panel's position to ( the position of itemIndex'th item + offset ). - */ - public void MovePanelToItemByIndex(int itemIndex, float offsetX = 0, float offsetY = 0) - { - if (ItemTotalCount == 0) - { - return; - } - - if (itemIndex >= ItemTotalCount) - { - itemIndex = ItemTotalCount - 1; - } - - if (itemIndex < 0) - { - itemIndex = 0; - } - - RowColumnPair val = GetRowColumnByItemIndex(itemIndex); - MovePanelToItemByRowColumn(val.mRow, val.mColumn, offsetX, offsetY); - } - - /* - This method will move the panel's position to ( the position of (row,column) item + offset ). - */ - public void MovePanelToItemByRowColumn(int row, int column, float offsetX = 0, float offsetY = 0) - { - _scrollRect.StopMovement(); - _curSnapData.Clear(); - if (_itemTotalCount == 0) - { - return; - } - - Vector2 itemPos = GetItemPos(row, column); - Vector3 pos = _containerTrans.anchoredPosition3D; - if (_scrollRect.horizontal) - { - float maxCanMoveX = Mathf.Max(ContainerTrans.rect.width - ViewPortWidth, 0); - if (maxCanMoveX > 0) - { - float x = -itemPos.x + offsetX; - x = Mathf.Min(Mathf.Abs(x), maxCanMoveX) * Mathf.Sign(x); - pos.x = x; - } - } - - if (_scrollRect.vertical) - { - float maxCanMoveY = Mathf.Max(ContainerTrans.rect.height - ViewPortHeight, 0); - if (maxCanMoveY > 0) - { - float y = -itemPos.y + offsetY; - y = Mathf.Min(Mathf.Abs(y), maxCanMoveY) * Mathf.Sign(y); - pos.y = y; - } - } - - if (pos != _containerTrans.anchoredPosition3D) - { - _containerTrans.anchoredPosition3D = pos; - } - - VaildAndSetContainerPos(); - ForceToCheckContentPos(); - } - - //update all visible items. - public void RefreshAllShownItem() - { - int count = _itemGroupList.Count; - if (count == 0) - { - return; - } - - ForceToCheckContentPos(); - RecycleAllItem(); - UpdateGridViewContent(); - } - - - public virtual void OnBeginDrag(PointerEventData eventData) - { - if (eventData.button != PointerEventData.InputButton.Left) - { - return; - } - - _curSnapData.Clear(); - _isDragging = true; - if (OnBeginDragAction != null) - { - OnBeginDragAction(eventData); - } - } - - public virtual void OnEndDrag(PointerEventData eventData) - { - if (eventData.button != PointerEventData.InputButton.Left) - { - return; - } - - _isDragging = false; - ForceSnapUpdateCheck(); - if (OnEndDragAction != null) - { - OnEndDragAction(eventData); - } - } - - public virtual void OnDrag(PointerEventData eventData) - { - if (eventData.button != PointerEventData.InputButton.Left) - { - return; - } - - if (OnDragingAction != null) - { - OnDragingAction(eventData); - } - } - - - public int GetItemIndexByRowColumn(int row, int column) - { - if (mGridFixedType == GridFixedType.ColumnCountFixed) - { - return row * mFixedRowOrColumnCount + column; - } - else - { - return column * mFixedRowOrColumnCount + row; - } - } - - - public RowColumnPair GetRowColumnByItemIndex(int itemIndex) - { - if (itemIndex < 0) - { - itemIndex = 0; - } - - if (mGridFixedType == GridFixedType.ColumnCountFixed) - { - int row = itemIndex / mFixedRowOrColumnCount; - int column = itemIndex % mFixedRowOrColumnCount; - return new RowColumnPair(row, column); - } - else - { - int column = itemIndex / mFixedRowOrColumnCount; - int row = itemIndex % mFixedRowOrColumnCount; - return new RowColumnPair(row, column); - } - } - - - public Vector2 GetItemAbsPos(int row, int column) - { - float x = _startPadding.x + column * _itemSizeWithPadding.x; - float y = _startPadding.y + row * _itemSizeWithPadding.y; - return new Vector2(x, y); - } - - - public Vector2 GetItemPos(int row, int column) - { - Vector2 absPos = GetItemAbsPos(row, column); - float x = absPos.x; - float y = absPos.y; - if (ArrangeType == GridItemArrangeType.TopLeftToBottomRight) - { - return new Vector2(x, -y); - } - else if (ArrangeType == GridItemArrangeType.BottomLeftToTopRight) - { - return new Vector2(x, y); - } - else if (ArrangeType == GridItemArrangeType.TopRightToBottomLeft) - { - return new Vector2(-x, -y); - } - else if (ArrangeType == GridItemArrangeType.BottomRightToTopLeft) - { - return new Vector2(-x, y); - } - - return Vector2.zero; - } - - //get the shown item of itemIndex, if this item is not shown,then return null. - public LoopGridViewItem GetShownItemByItemIndex(int itemIndex) - { - if (itemIndex < 0 || itemIndex >= ItemTotalCount) - { - return null; - } - - if (_itemGroupList.Count == 0) - { - return null; - } - - RowColumnPair val = GetRowColumnByItemIndex(itemIndex); - return GetShownItemByRowColumn(val.mRow, val.mColumn); - } - - //get the shown item of (row, column), if this item is not shown,then return null. - public LoopGridViewItem GetShownItemByRowColumn(int row, int column) - { - if (_itemGroupList.Count == 0) - { - return null; - } - - if (mGridFixedType == GridFixedType.ColumnCountFixed) - { - GridItemGroup group = GetShownGroup(row); - if (group == null) - { - return null; - } - - return group.GetItemByColumn(column); - } - else - { - GridItemGroup group = GetShownGroup(column); - if (group == null) - { - return null; - } - - return group.GetItemByRow(row); - } - } - - public void UpdateAllGridSetting() - { - UpdateStartEndPadding(); - UpdateItemSize(); - UpdateColumnRowCount(); - UpdateContentSize(); - ForceSnapUpdateCheck(); - ForceToCheckContentPos(); - } - - //set mGridFixedType and mFixedRowOrColumnCount at runtime - public void SetGridFixedGroupCount(GridFixedType fixedType, int count) - { - if (mGridFixedType == fixedType && mFixedRowOrColumnCount == count) - { - return; - } - - mGridFixedType = fixedType; - mFixedRowOrColumnCount = count; - UpdateColumnRowCount(); - UpdateContentSize(); - if (_itemGroupList.Count == 0) - { - return; - } - - RecycleAllItem(); - ForceSnapUpdateCheck(); - ForceToCheckContentPos(); - } - - //change item size at runtime - public void SetItemSize(Vector2 newSize) - { - if (newSize == mItemSize) - { - return; - } - - mItemSize = newSize; - UpdateItemSize(); - UpdateContentSize(); - if (_itemGroupList.Count == 0) - { - return; - } - - RecycleAllItem(); - ForceSnapUpdateCheck(); - ForceToCheckContentPos(); - } - - //change item padding at runtime - public void SetItemPadding(Vector2 newPadding) - { - if (newPadding == mItemPadding) - { - return; - } - - mItemPadding = newPadding; - UpdateItemSize(); - UpdateContentSize(); - if (_itemGroupList.Count == 0) - { - return; - } - - RecycleAllItem(); - ForceSnapUpdateCheck(); - ForceToCheckContentPos(); - } - - //change padding at runtime - public void SetPadding(RectOffset newPadding) - { - if (newPadding == mPadding) - { - return; - } - - mPadding = newPadding; - UpdateStartEndPadding(); - UpdateContentSize(); - if (_itemGroupList.Count == 0) - { - return; - } - - RecycleAllItem(); - ForceSnapUpdateCheck(); - ForceToCheckContentPos(); - } - - - public void UpdateContentSize() - { - float width = _startPadding.x + _columnCount * _itemSizeWithPadding.x - mItemPadding.x + _endPadding.x; - float height = _startPadding.y + _rowCount * _itemSizeWithPadding.y - mItemPadding.y + _endPadding.y; - if (_containerTrans.rect.height != height) - { - _containerTrans.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, height); - } - - if (_containerTrans.rect.width != width) - { - _containerTrans.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, width); - } - } - - - public void VaildAndSetContainerPos() - { - Vector3 pos = _containerTrans.anchoredPosition3D; - _containerTrans.anchoredPosition3D = GetContainerVaildPos(pos.x, pos.y); - } - - public void ClearAllTmpRecycledItem() - { - int count = _itemPoolList.Count; - for (int i = 0; i < count; ++i) - { - _itemPoolList[i].ClearTmpRecycledItem(); - } - } - - - public void RecycleAllItem() - { - foreach (GridItemGroup group in _itemGroupList) - { - RecycleItemGroupTmp(group); - } - - _itemGroupList.Clear(); - } - - public void UpdateGridViewContent() - { - _listUpdateCheckFrameCount++; - if (_itemTotalCount == 0) - { - if (_itemGroupList.Count > 0) - { - RecycleAllItem(); - } - - return; - } - - UpdateCurFrameItemRangeData(); - if (mGridFixedType == GridFixedType.ColumnCountFixed) - { - int groupCount = _itemGroupList.Count; - int minRow = _curFrameItemRangeData.MinRow; - int maxRow = _curFrameItemRangeData.MaxRow; - for (int i = groupCount - 1; i >= 0; --i) - { - GridItemGroup group = _itemGroupList[i]; - if (group.GroupIndex < minRow || group.GroupIndex > maxRow) - { - RecycleItemGroupTmp(group); - _itemGroupList.RemoveAt(i); - } - } - - if (_itemGroupList.Count == 0) - { - GridItemGroup group = CreateItemGroup(minRow); - _itemGroupList.Add(group); - } - - while (_itemGroupList[0].GroupIndex > minRow) - { - GridItemGroup group = CreateItemGroup(_itemGroupList[0].GroupIndex - 1); - _itemGroupList.Insert(0, group); - } - - while (_itemGroupList[_itemGroupList.Count - 1].GroupIndex < maxRow) - { - GridItemGroup group = CreateItemGroup(_itemGroupList[_itemGroupList.Count - 1].GroupIndex + 1); - _itemGroupList.Add(group); - } - - int count = _itemGroupList.Count; - for (int i = 0; i < count; ++i) - { - UpdateRowItemGroupForRecycleAndNew(_itemGroupList[i]); - } - } - else - { - int groupCount = _itemGroupList.Count; - int minColumn = _curFrameItemRangeData.MinColumn; - int maxColumn = _curFrameItemRangeData.MaxColumn; - for (int i = groupCount - 1; i >= 0; --i) - { - GridItemGroup group = _itemGroupList[i]; - if (group.GroupIndex < minColumn || group.GroupIndex > maxColumn) - { - RecycleItemGroupTmp(group); - _itemGroupList.RemoveAt(i); - } - } - - if (_itemGroupList.Count == 0) - { - GridItemGroup group = CreateItemGroup(minColumn); - _itemGroupList.Add(group); - } - - while (_itemGroupList[0].GroupIndex > minColumn) - { - GridItemGroup group = CreateItemGroup(_itemGroupList[0].GroupIndex - 1); - _itemGroupList.Insert(0, group); - } - - while (_itemGroupList[_itemGroupList.Count - 1].GroupIndex < maxColumn) - { - GridItemGroup group = CreateItemGroup(_itemGroupList[_itemGroupList.Count - 1].GroupIndex + 1); - _itemGroupList.Add(group); - } - - int count = _itemGroupList.Count; - for (int i = 0; i < count; ++i) - { - UpdateColumnItemGroupForRecycleAndNew(_itemGroupList[i]); - } - } - } - - public void UpdateStartEndPadding() - { - if (ArrangeType == GridItemArrangeType.TopLeftToBottomRight) - { - _startPadding.x = mPadding.left; - _startPadding.y = mPadding.top; - _endPadding.x = mPadding.right; - _endPadding.y = mPadding.bottom; - } - else if (ArrangeType == GridItemArrangeType.BottomLeftToTopRight) - { - _startPadding.x = mPadding.left; - _startPadding.y = mPadding.bottom; - _endPadding.x = mPadding.right; - _endPadding.y = mPadding.top; - } - else if (ArrangeType == GridItemArrangeType.TopRightToBottomLeft) - { - _startPadding.x = mPadding.right; - _startPadding.y = mPadding.top; - _endPadding.x = mPadding.left; - _endPadding.y = mPadding.bottom; - } - else if (ArrangeType == GridItemArrangeType.BottomRightToTopLeft) - { - _startPadding.x = mPadding.right; - _startPadding.y = mPadding.bottom; - _endPadding.x = mPadding.left; - _endPadding.y = mPadding.top; - } - } - - - public void UpdateItemSize() - { - if (mItemSize.x > 0f && mItemSize.y > 0f) - { - _itemSizeWithPadding = mItemSize + mItemPadding; - return; - } - - do - { - if (mItemPrefabDataList.Count == 0) - { - break; - } - - GameObject obj = mItemPrefabDataList[0].itemPrefab; - if (obj == null) - { - break; - } - - RectTransform rtf = obj.GetComponent(); - if (rtf == null) - { - break; - } - - mItemSize = rtf.rect.size; - _itemSizeWithPadding = mItemSize + mItemPadding; - } while (false); - - if (mItemSize.x <= 0 || mItemSize.y <= 0) - { - Debug.LogError("Error, ItemSize is invaild."); - } - } - - public void UpdateColumnRowCount() - { - if (mGridFixedType == GridFixedType.ColumnCountFixed) - { - _columnCount = mFixedRowOrColumnCount; - _rowCount = _itemTotalCount / _columnCount; - if (_itemTotalCount % _columnCount > 0) - { - _rowCount++; - } - - if (_itemTotalCount <= _columnCount) - { - _columnCount = _itemTotalCount; - } - } - else - { - _rowCount = mFixedRowOrColumnCount; - _columnCount = _itemTotalCount / _rowCount; - if (_itemTotalCount % _rowCount > 0) - { - _columnCount++; - } - - if (_itemTotalCount <= _rowCount) - { - _rowCount = _itemTotalCount; - } - } - } - - - /// /////////////////////////////////////////////////////////////////////////////////////////////////////// - /// - bool IsContainerTransCanMove() - { - if (_itemTotalCount == 0) - { - return false; - } - - if (_scrollRect.horizontal && ContainerTrans.rect.width > ViewPortWidth) - { - return true; - } - - if (_scrollRect.vertical && ContainerTrans.rect.height > ViewPortHeight) - { - return true; - } - - return false; - } - - - void RecycleItemGroupTmp(GridItemGroup group) - { - if (group == null) - { - return; - } - - while (group.First != null) - { - LoopGridViewItem item = group.RemoveFirst(); - RecycleItemTmp(item); - } - - group.Clear(); - RecycleOneItemGroupObj(group); - } - - - void RecycleItemTmp(LoopGridViewItem item) - { - if (item == null) - { - return; - } - - if (string.IsNullOrEmpty(item.ItemPrefabName)) - { - return; - } - - GridItemPool pool = null; - if (_itemPoolDict.TryGetValue(item.ItemPrefabName, out pool) == false) - { - return; - } - - pool.RecycleItem(item); - } - - - void AdjustViewPortPivot() - { - RectTransform rtf = _viewPortRectTransform; - if (ArrangeType == GridItemArrangeType.TopLeftToBottomRight) - { - rtf.pivot = new Vector2(0, 1); - } - else if (ArrangeType == GridItemArrangeType.BottomLeftToTopRight) - { - rtf.pivot = new Vector2(0, 0); - } - else if (ArrangeType == GridItemArrangeType.TopRightToBottomLeft) - { - rtf.pivot = new Vector2(1, 1); - } - else if (ArrangeType == GridItemArrangeType.BottomRightToTopLeft) - { - rtf.pivot = new Vector2(1, 0); - } - } - - void AdjustContainerAnchorAndPivot() - { - RectTransform rtf = ContainerTrans; - - if (ArrangeType == GridItemArrangeType.TopLeftToBottomRight) - { - rtf.anchorMin = new Vector2(0, 1); - rtf.anchorMax = new Vector2(0, 1); - rtf.pivot = new Vector2(0, 1); - } - else if (ArrangeType == GridItemArrangeType.BottomLeftToTopRight) - { - rtf.anchorMin = new Vector2(0, 0); - rtf.anchorMax = new Vector2(0, 0); - rtf.pivot = new Vector2(0, 0); - } - else if (ArrangeType == GridItemArrangeType.TopRightToBottomLeft) - { - rtf.anchorMin = new Vector2(1, 1); - rtf.anchorMax = new Vector2(1, 1); - rtf.pivot = new Vector2(1, 1); - } - else if (ArrangeType == GridItemArrangeType.BottomRightToTopLeft) - { - rtf.anchorMin = new Vector2(1, 0); - rtf.anchorMax = new Vector2(1, 0); - rtf.pivot = new Vector2(1, 0); - } - } - - void AdjustItemAnchorAndPivot(RectTransform rtf) - { - if (ArrangeType == GridItemArrangeType.TopLeftToBottomRight) - { - rtf.anchorMin = new Vector2(0, 1); - rtf.anchorMax = new Vector2(0, 1); - rtf.pivot = new Vector2(0, 1); - } - else if (ArrangeType == GridItemArrangeType.BottomLeftToTopRight) - { - rtf.anchorMin = new Vector2(0, 0); - rtf.anchorMax = new Vector2(0, 0); - rtf.pivot = new Vector2(0, 0); - } - else if (ArrangeType == GridItemArrangeType.TopRightToBottomLeft) - { - rtf.anchorMin = new Vector2(1, 1); - rtf.anchorMax = new Vector2(1, 1); - rtf.pivot = new Vector2(1, 1); - } - else if (ArrangeType == GridItemArrangeType.BottomRightToTopLeft) - { - rtf.anchorMin = new Vector2(1, 0); - rtf.anchorMax = new Vector2(1, 0); - rtf.pivot = new Vector2(1, 0); - } - } - - - void InitItemPool() - { - foreach (GridViewItemPrefabConfData data in mItemPrefabDataList) - { - if (data.itemPrefab == null) - { - Debug.LogError("A item prefab is null "); - continue; - } - - string prefabName = data.itemPrefab.name; - if (_itemPoolDict.ContainsKey(prefabName)) - { - Debug.LogError("A item prefab with name " + prefabName + " has existed!"); - continue; - } - - RectTransform rtf = data.itemPrefab.GetComponent(); - if (rtf == null) - { - Debug.LogError("RectTransform component is not found in the prefab " + prefabName); - continue; - } - - AdjustItemAnchorAndPivot(rtf); - LoopGridViewItem tItem = data.itemPrefab.GetComponent(); - if (tItem == null) - { - data.itemPrefab.AddComponent(); - } - - GridItemPool pool = new GridItemPool(); - pool.Init(data.itemPrefab, data.initCreateCount, _containerTrans); - _itemPoolDict.Add(prefabName, pool); - _itemPoolList.Add(pool); - } - } - - - LoopGridViewItem GetNewItemByRowColumn(int row, int column) - { - int itemIndex = GetItemIndexByRowColumn(row, column); - if (itemIndex < 0 || itemIndex >= ItemTotalCount) - { - return null; - } - - LoopGridViewItem newItem = _onGetItemByRowColumn(this, itemIndex, row, column); - if (newItem == null) - { - return null; - } - - newItem.NextItem = null; - newItem.PrevItem = null; - newItem.Row = row; - newItem.Column = column; - newItem.ItemIndex = itemIndex; - newItem.ItemCreatedCheckFrameCount = _listUpdateCheckFrameCount; - return newItem; - } - - - RowColumnPair GetCeilItemRowColumnAtGivenAbsPos(float ax, float ay) - { - ax = Mathf.Abs(ax); - ay = Mathf.Abs(ay); - int row = Mathf.CeilToInt((ay - _startPadding.y) / _itemSizeWithPadding.y) - 1; - int column = Mathf.CeilToInt((ax - _startPadding.x) / _itemSizeWithPadding.x) - 1; - if (row < 0) - { - row = 0; - } - - if (row >= _rowCount) - { - row = _rowCount - 1; - } - - if (column < 0) - { - column = 0; - } - - if (column >= _columnCount) - { - column = _columnCount - 1; - } - - return new RowColumnPair(row, column); - } - - void Update() - { - if (_listViewInited == false) - { - return; - } - - UpdateSnapMove(); - UpdateGridViewContent(); - ClearAllTmpRecycledItem(); - } - - - GridItemGroup CreateItemGroup(int groupIndex) - { - GridItemGroup ret = GetOneItemGroupObj(); - ret.GroupIndex = groupIndex; - return ret; - } - - Vector2 GetContainerMovedDistance() - { - Vector2 pos = GetContainerVaildPos(ContainerTrans.anchoredPosition3D.x, ContainerTrans.anchoredPosition3D.y); - return new Vector2(Mathf.Abs(pos.x), Mathf.Abs(pos.y)); - } - - - Vector2 GetContainerVaildPos(float curX, float curY) - { - float maxCanMoveX = Mathf.Max(ContainerTrans.rect.width - ViewPortWidth, 0); - float maxCanMoveY = Mathf.Max(ContainerTrans.rect.height - ViewPortHeight, 0); - if (mArrangeType == GridItemArrangeType.TopLeftToBottomRight) - { - curX = Mathf.Clamp(curX, -maxCanMoveX, 0); - curY = Mathf.Clamp(curY, 0, maxCanMoveY); - } - else if (mArrangeType == GridItemArrangeType.BottomLeftToTopRight) - { - curX = Mathf.Clamp(curX, -maxCanMoveX, 0); - curY = Mathf.Clamp(curY, -maxCanMoveY, 0); - } - else if (mArrangeType == GridItemArrangeType.BottomRightToTopLeft) - { - curX = Mathf.Clamp(curX, 0, maxCanMoveX); - curY = Mathf.Clamp(curY, -maxCanMoveY, 0); - } - else if (mArrangeType == GridItemArrangeType.TopRightToBottomLeft) - { - curX = Mathf.Clamp(curX, 0, maxCanMoveX); - curY = Mathf.Clamp(curY, 0, maxCanMoveY); - } - - return new Vector2(curX, curY); - } - - - void UpdateCurFrameItemRangeData() - { - Vector2 distVector2 = GetContainerMovedDistance(); - if (_needCheckContentPosLeftCount <= 0 && _curFrameItemRangeData.CheckedPosition == distVector2) - { - return; - } - - if (_needCheckContentPosLeftCount > 0) - { - _needCheckContentPosLeftCount--; - } - - float distX = distVector2.x - mItemRecycleDistance.x; - float distY = distVector2.y - mItemRecycleDistance.y; - if (distX < 0) - { - distX = 0; - } - - if (distY < 0) - { - distY = 0; - } - - RowColumnPair val = GetCeilItemRowColumnAtGivenAbsPos(distX, distY); - _curFrameItemRangeData.MinColumn = val.mColumn; - _curFrameItemRangeData.MinRow = val.mRow; - distX = distVector2.x + mItemRecycleDistance.x + ViewPortWidth; - distY = distVector2.y + mItemRecycleDistance.y + ViewPortHeight; - val = GetCeilItemRowColumnAtGivenAbsPos(distX, distY); - _curFrameItemRangeData.MaxColumn = val.mColumn; - _curFrameItemRangeData.MaxRow = val.mRow; - _curFrameItemRangeData.CheckedPosition = distVector2; - } - - - void UpdateRowItemGroupForRecycleAndNew(GridItemGroup group) - { - int minColumn = _curFrameItemRangeData.MinColumn; - int maxColumn = _curFrameItemRangeData.MaxColumn; - int row = group.GroupIndex; - while (group.First != null && group.First.Column < minColumn) - { - RecycleItemTmp(group.RemoveFirst()); - } - - while (group.Last != null && ((group.Last.Column > maxColumn) || (group.Last.ItemIndex >= ItemTotalCount))) - { - RecycleItemTmp(group.RemoveLast()); - } - - if (group.First == null) - { - LoopGridViewItem item = GetNewItemByRowColumn(row, minColumn); - if (item == null) - { - return; - } - - item.CachedRectTransform.anchoredPosition3D = GetItemPos(item.Row, item.Column); - group.AddFirst(item); - } - - while (group.First.Column > minColumn) - { - LoopGridViewItem item = GetNewItemByRowColumn(row, group.First.Column - 1); - if (item == null) - { - break; - } - - item.CachedRectTransform.anchoredPosition3D = GetItemPos(item.Row, item.Column); - - group.AddFirst(item); - } - - while (group.Last.Column < maxColumn) - { - LoopGridViewItem item = GetNewItemByRowColumn(row, group.Last.Column + 1); - if (item == null) - { - break; - } - - item.CachedRectTransform.anchoredPosition3D = GetItemPos(item.Row, item.Column); - - group.AddLast(item); - } - } - - void UpdateColumnItemGroupForRecycleAndNew(GridItemGroup group) - { - int minRow = _curFrameItemRangeData.MinRow; - int maxRow = _curFrameItemRangeData.MaxRow; - int column = group.GroupIndex; - while (group.First != null && group.First.Row < minRow) - { - RecycleItemTmp(group.RemoveFirst()); - } - - while (group.Last != null && ((group.Last.Row > maxRow) || (group.Last.ItemIndex >= ItemTotalCount))) - { - RecycleItemTmp(group.RemoveLast()); - } - - if (group.First == null) - { - LoopGridViewItem item = GetNewItemByRowColumn(minRow, column); - if (item == null) - { - return; - } - - item.CachedRectTransform.anchoredPosition3D = GetItemPos(item.Row, item.Column); - group.AddFirst(item); - } - - while (group.First.Row > minRow) - { - LoopGridViewItem item = GetNewItemByRowColumn(group.First.Row - 1, column); - if (item == null) - { - break; - } - - item.CachedRectTransform.anchoredPosition3D = GetItemPos(item.Row, item.Column); - - group.AddFirst(item); - } - - while (group.Last.Row < maxRow) - { - LoopGridViewItem item = GetNewItemByRowColumn(group.Last.Row + 1, column); - if (item == null) - { - break; - } - - item.CachedRectTransform.anchoredPosition3D = GetItemPos(item.Row, item.Column); - - group.AddLast(item); - } - } - - - void SetScrollbarListener() - { - if (ItemSnapEnable == false) - { - return; - } - - _scrollBarClickEventListener1 = null; - _scrollBarClickEventListener2 = null; - Scrollbar curScrollBar1 = null; - Scrollbar curScrollBar2 = null; - if (_scrollRect.vertical && _scrollRect.verticalScrollbar != null) - { - curScrollBar1 = _scrollRect.verticalScrollbar; - } - - if (_scrollRect.horizontal && _scrollRect.horizontalScrollbar != null) - { - curScrollBar2 = _scrollRect.horizontalScrollbar; - } - - if (curScrollBar1 != null) - { - ClickEventListener listener = ClickEventListener.Get(curScrollBar1.gameObject); - _scrollBarClickEventListener1 = listener; - listener.SetPointerUpHandler(OnPointerUpInScrollBar); - listener.SetPointerDownHandler(OnPointerDownInScrollBar); - } - - if (curScrollBar2 != null) - { - ClickEventListener listener = ClickEventListener.Get(curScrollBar2.gameObject); - _scrollBarClickEventListener2 = listener; - listener.SetPointerUpHandler(OnPointerUpInScrollBar); - listener.SetPointerDownHandler(OnPointerDownInScrollBar); - } - } - - void OnPointerDownInScrollBar(GameObject obj) - { - _curSnapData.Clear(); - } - - void OnPointerUpInScrollBar(GameObject obj) - { - ForceSnapUpdateCheck(); - } - - RowColumnPair FindNearestItemWithLocalPos(float x, float y) - { - Vector2 targetPos = new Vector2(x, y); - RowColumnPair val = GetCeilItemRowColumnAtGivenAbsPos(targetPos.x, targetPos.y); - int row = val.mRow; - int column = val.mColumn; - float distance = 0; - RowColumnPair ret = new RowColumnPair(-1, -1); - Vector2 pos = Vector2.zero; - float minDistance = float.MaxValue; - for (int r = row - 1; r <= row + 1; ++r) - { - for (int c = column - 1; c <= column + 1; ++c) - { - if (r >= 0 && r < _rowCount && c >= 0 && c < _columnCount) - { - pos = GetItemSnapPivotLocalPos(r, c); - distance = (pos - targetPos).sqrMagnitude; - if (distance < minDistance) - { - minDistance = distance; - ret.mRow = r; - ret.mColumn = c; - } - } - } - } - - return ret; - } - - Vector2 GetItemSnapPivotLocalPos(int row, int column) - { - Vector2 absPos = GetItemAbsPos(row, column); - if (mArrangeType == GridItemArrangeType.TopLeftToBottomRight) - { - float x = absPos.x + mItemSize.x * mItemSnapPivot.x; - float y = -absPos.y - mItemSize.y * (1 - mItemSnapPivot.y); - return new Vector2(x, y); - } - else if (mArrangeType == GridItemArrangeType.BottomLeftToTopRight) - { - float x = absPos.x + mItemSize.x * mItemSnapPivot.x; - float y = absPos.y + mItemSize.y * mItemSnapPivot.y; - return new Vector2(x, y); - } - else if (mArrangeType == GridItemArrangeType.TopRightToBottomLeft) - { - float x = -absPos.x - mItemSize.x * (1 - mItemSnapPivot.x); - float y = -absPos.y - mItemSize.y * (1 - mItemSnapPivot.y); - return new Vector2(x, y); - } - else if (mArrangeType == GridItemArrangeType.BottomRightToTopLeft) - { - float x = -absPos.x - mItemSize.x * (1 - mItemSnapPivot.x); - float y = absPos.y + mItemSize.y * mItemSnapPivot.y; - return new Vector2(x, y); - } - - return Vector2.zero; - } - - Vector2 GetViewPortSnapPivotLocalPos(Vector2 pos) - { - float pivotLocalPosX = 0; - float pivotLocalPosY = 0; - if (mArrangeType == GridItemArrangeType.TopLeftToBottomRight) - { - pivotLocalPosX = -pos.x + ViewPortWidth * mViewPortSnapPivot.x; - pivotLocalPosY = -pos.y - ViewPortHeight * (1 - mViewPortSnapPivot.y); - } - else if (mArrangeType == GridItemArrangeType.BottomLeftToTopRight) - { - pivotLocalPosX = -pos.x + ViewPortWidth * mViewPortSnapPivot.x; - pivotLocalPosY = -pos.y + ViewPortHeight * mViewPortSnapPivot.y; - } - else if (mArrangeType == GridItemArrangeType.TopRightToBottomLeft) - { - pivotLocalPosX = -pos.x - ViewPortWidth * (1 - mViewPortSnapPivot.x); - pivotLocalPosY = -pos.y - ViewPortHeight * (1 - mViewPortSnapPivot.y); - } - else if (mArrangeType == GridItemArrangeType.BottomRightToTopLeft) - { - pivotLocalPosX = -pos.x - ViewPortWidth * (1 - mViewPortSnapPivot.x); - pivotLocalPosY = -pos.y + ViewPortHeight * mViewPortSnapPivot.y; - } - - return new Vector2(pivotLocalPosX, pivotLocalPosY); - } - - void UpdateNearestSnapItem(bool forceSendEvent) - { - if (mItemSnapEnable == false) - { - return; - } - - int count = _itemGroupList.Count; - if (count == 0) - { - return; - } - - if (IsContainerTransCanMove() == false) - { - return; - } - - Vector2 pos = GetContainerVaildPos(ContainerTrans.anchoredPosition3D.x, ContainerTrans.anchoredPosition3D.y); - bool needCheck = (pos.y != _lastSnapCheckPos.y || pos.x != _lastSnapCheckPos.x); - _lastSnapCheckPos = pos; - if (!needCheck) - { - if (_leftSnapUpdateExtraCount > 0) - { - _leftSnapUpdateExtraCount--; - needCheck = true; - } - } - - if (needCheck) - { - RowColumnPair curVal = new RowColumnPair(-1, -1); - Vector2 snapTartetPos = GetViewPortSnapPivotLocalPos(pos); - curVal = FindNearestItemWithLocalPos(snapTartetPos.x, snapTartetPos.y); - if (curVal.mRow >= 0) - { - RowColumnPair oldNearestItem = _curSnapNearestItemRowColumn; - _curSnapNearestItemRowColumn = curVal; - if (forceSendEvent || oldNearestItem != _curSnapNearestItemRowColumn) - { - if (OnSnapNearestChanged != null) - { - OnSnapNearestChanged(this); - } - } - } - else - { - _curSnapNearestItemRowColumn.mRow = -1; - _curSnapNearestItemRowColumn.mColumn = -1; - } - } - } - - void UpdateFromSettingParam(LoopGridViewSettingParam param) - { - if (param == null) - { - return; - } - - if (param.ItemSize != null) - { - mItemSize = (Vector2)(param.ItemSize); - } - - if (param.ItemPadding != null) - { - mItemPadding = (Vector2)(param.ItemPadding); - } - - if (param.Padding != null) - { - mPadding = (RectOffset)(param.Padding); - } - - if (param.GridFixedType != null) - { - mGridFixedType = (GridFixedType)(param.GridFixedType); - } - - if (param.FixedRowOrColumnCount != null) - { - mFixedRowOrColumnCount = (int)(param.FixedRowOrColumnCount); - } - } - - //snap move will finish at once. - public void FinishSnapImmediately() - { - UpdateSnapMove(true); - } - - //update snap move. if immediate is set true, then the snap move will finish at once. - void UpdateSnapMove(bool immediate = false, bool forceSendEvent = false) - { - if (mItemSnapEnable == false) - { - return; - } - - UpdateNearestSnapItem(false); - Vector2 pos = _containerTrans.anchoredPosition3D; - if (CanSnap() == false) - { - ClearSnapData(); - return; - } - - UpdateCurSnapData(); - if (_curSnapData.SnapStatus != SnapStatus.SnapMoving) - { - return; - } - - float v = Mathf.Abs(_scrollRect.velocity.x) + Mathf.Abs(_scrollRect.velocity.y); - if (v > 0) - { - _scrollRect.StopMovement(); - } - - float old = _curSnapData.CurSnapVal; - _curSnapData.CurSnapVal = Mathf.SmoothDamp(_curSnapData.CurSnapVal, _curSnapData.TargetSnapVal, ref _smoothDumpVel, _smoothDumpRate); - float dt = _curSnapData.CurSnapVal - old; - - if (immediate || Mathf.Abs(_curSnapData.TargetSnapVal - _curSnapData.CurSnapVal) < _snapFinishThreshold) - { - pos = pos + (_curSnapData.TargetSnapVal - old) * _curSnapData.SnapNeedMoveDir; - _curSnapData.SnapStatus = SnapStatus.SnapMoveFinish; - if (OnSnapItemFinished != null) - { - LoopGridViewItem targetItem = GetShownItemByRowColumn(_curSnapNearestItemRowColumn.mRow, _curSnapNearestItemRowColumn.mColumn); - if (targetItem != null) - { - OnSnapItemFinished(this, targetItem); - } - } - } - else - { - pos = pos + dt * _curSnapData.SnapNeedMoveDir; - } - - _containerTrans.anchoredPosition3D = GetContainerVaildPos(pos.x, pos.y); - } - - GridItemGroup GetShownGroup(int groupIndex) - { - if (groupIndex < 0) - { - return null; - } - - int count = _itemGroupList.Count; - if (count == 0) - { - return null; - } - - if (groupIndex < _itemGroupList[0].GroupIndex || groupIndex > _itemGroupList[count - 1].GroupIndex) - { - return null; - } - - int i = groupIndex - _itemGroupList[0].GroupIndex; - return _itemGroupList[i]; - } - - - void FillCurSnapData(int row, int column) - { - Vector2 itemSnapPivotLocalPos = GetItemSnapPivotLocalPos(row, column); - Vector2 containerPos = GetContainerVaildPos(ContainerTrans.anchoredPosition3D.x, ContainerTrans.anchoredPosition3D.y); - Vector2 snapTartetPos = GetViewPortSnapPivotLocalPos(containerPos); - Vector2 dir = snapTartetPos - itemSnapPivotLocalPos; - if (_scrollRect.horizontal == false) - { - dir.x = 0; - } - - if (_scrollRect.vertical == false) - { - dir.y = 0; - } - - _curSnapData.TargetSnapVal = dir.magnitude; - _curSnapData.CurSnapVal = 0; - _curSnapData.SnapNeedMoveDir = dir.normalized; - } - - - void UpdateCurSnapData() - { - int count = _itemGroupList.Count; - if (count == 0) - { - _curSnapData.Clear(); - return; - } - - if (_curSnapData.SnapStatus == SnapStatus.SnapMoveFinish) - { - if (_curSnapData.SnapTarget == _curSnapNearestItemRowColumn) - { - return; - } - - _curSnapData.SnapStatus = SnapStatus.NoTargetSet; - } - - if (_curSnapData.SnapStatus == SnapStatus.SnapMoving) - { - if ((_curSnapData.SnapTarget == _curSnapNearestItemRowColumn) || _curSnapData.IsForceSnapTo) - { - return; - } - - _curSnapData.SnapStatus = SnapStatus.NoTargetSet; - } - - if (_curSnapData.SnapStatus == SnapStatus.NoTargetSet) - { - LoopGridViewItem nearestItem = GetShownItemByRowColumn(_curSnapNearestItemRowColumn.mRow, _curSnapNearestItemRowColumn.mColumn); - if (nearestItem == null) - { - return; - } - - _curSnapData.SnapTarget = _curSnapNearestItemRowColumn; - _curSnapData.SnapStatus = SnapStatus.TargetHasSet; - _curSnapData.IsForceSnapTo = false; - } - - if (_curSnapData.SnapStatus == SnapStatus.TargetHasSet) - { - LoopGridViewItem targetItem = GetShownItemByRowColumn(_curSnapData.SnapTarget.mRow, _curSnapData.SnapTarget.mColumn); - if (targetItem == null) - { - _curSnapData.Clear(); - return; - } - - FillCurSnapData(targetItem.Row, targetItem.Column); - _curSnapData.SnapStatus = SnapStatus.SnapMoving; - } - } - - - bool CanSnap() - { - if (_isDragging) - { - return false; - } - - if (_scrollBarClickEventListener1 != null) - { - if (_scrollBarClickEventListener1.IsPressed) - { - return false; - } - } - - if (_scrollBarClickEventListener2 != null) - { - if (_scrollBarClickEventListener2.IsPressed) - { - return false; - } - } - - if (IsContainerTransCanMove() == false) - { - return false; - } - - if (Mathf.Abs(_scrollRect.velocity.x) > _snapVecThreshold) - { - return false; - } - - if (Mathf.Abs(_scrollRect.velocity.y) > _snapVecThreshold) - { - return false; - } - - Vector3 pos = _containerTrans.anchoredPosition3D; - Vector2 vPos = GetContainerVaildPos(pos.x, pos.y); - if (Mathf.Abs(pos.x - vPos.x) > 3) - { - return false; - } - - if (Mathf.Abs(pos.y - vPos.y) > 3) - { - return false; - } - - return true; - } - - GridItemGroup GetOneItemGroupObj() - { - int count = _itemGroupObjPool.Count; - if (count == 0) - { - return new GridItemGroup(); - } - - GridItemGroup ret = _itemGroupObjPool[count - 1]; - _itemGroupObjPool.RemoveAt(count - 1); - return ret; - } - - void RecycleOneItemGroupObj(GridItemGroup obj) - { - _itemGroupObjPool.Add(obj); - } - } -} \ No newline at end of file diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SuperScrollView/Scripts/GridView/LoopGridView.cs.meta b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SuperScrollView/Scripts/GridView/LoopGridView.cs.meta deleted file mode 100644 index 33af648a..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SuperScrollView/Scripts/GridView/LoopGridView.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 17e9881a7bce8124a8f855b96a8ca11a -timeCreated: 1554538573 -licenseType: Store -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SuperScrollView/Scripts/GridView/LoopGridViewItem.cs b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SuperScrollView/Scripts/GridView/LoopGridViewItem.cs deleted file mode 100644 index 97137e7e..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SuperScrollView/Scripts/GridView/LoopGridViewItem.cs +++ /dev/null @@ -1,184 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -namespace GameLogic -{ - - public class LoopGridViewItem : MonoBehaviour - { - // indicates the item’s index in the list the mItemIndex can only be from 0 to itemTotalCount -1. - int mItemIndex = -1; - // the row index, the item is in. starting from 0. - int mRow = -1; - // the column index, the item is in. starting from 0. - int mColumn = -1; - //indicates the item’s id. - //This property is set when the item is created or fetched from pool, - //and will no longer change until the item is recycled back to pool. - int mItemId = -1; - - private int _goId = 0; - - public int GoId - { - set => _goId = value; - get => _goId; - } - - LoopGridView mParentGridView = null; - bool mIsInitHandlerCalled = false; - string mItemPrefabName; - RectTransform mCachedRectTransform; - int mItemCreatedCheckFrameCount = 0; - - object mUserObjectData = null; - int mUserIntData1 = 0; - int mUserIntData2 = 0; - string mUserStringData1 = null; - string mUserStringData2 = null; - - LoopGridViewItem mPrevItem; - LoopGridViewItem mNextItem; - - public object UserObjectData - { - get { return mUserObjectData; } - set { mUserObjectData = value; } - } - public int UserIntData1 - { - get { return mUserIntData1; } - set { mUserIntData1 = value; } - } - public int UserIntData2 - { - get { return mUserIntData2; } - set { mUserIntData2 = value; } - } - public string UserStringData1 - { - get { return mUserStringData1; } - set { mUserStringData1 = value; } - } - public string UserStringData2 - { - get { return mUserStringData2; } - set { mUserStringData2 = value; } - } - - public int ItemCreatedCheckFrameCount - { - get { return mItemCreatedCheckFrameCount; } - set { mItemCreatedCheckFrameCount = value; } - } - - - public RectTransform CachedRectTransform - { - get - { - if (mCachedRectTransform == null) - { - mCachedRectTransform = gameObject.GetComponent(); - } - return mCachedRectTransform; - } - } - - public string ItemPrefabName - { - get - { - return mItemPrefabName; - } - set - { - mItemPrefabName = value; - } - } - - public int Row - { - get - { - return mRow; - } - set - { - mRow = value; - } - } - public int Column - { - get - { - return mColumn; - } - set - { - mColumn = value; - } - } - - public int ItemIndex - { - get - { - return mItemIndex; - } - set - { - mItemIndex = value; - } - } - public int ItemId - { - get - { - return mItemId; - } - set - { - mItemId = value; - } - } - - - public bool IsInitHandlerCalled - { - get - { - return mIsInitHandlerCalled; - } - set - { - mIsInitHandlerCalled = value; - } - } - - public LoopGridView ParentGridView - { - get - { - return mParentGridView; - } - set - { - mParentGridView = value; - } - } - - public LoopGridViewItem PrevItem - { - get { return mPrevItem; } - set { mPrevItem = value; } - } - public LoopGridViewItem NextItem - { - get { return mNextItem; } - set { mNextItem = value; } - } - - } -} diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SuperScrollView/Scripts/GridView/LoopGridViewItem.cs.meta b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SuperScrollView/Scripts/GridView/LoopGridViewItem.cs.meta deleted file mode 100644 index 7dda5f85..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SuperScrollView/Scripts/GridView/LoopGridViewItem.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: ec0432517adfcb84bb6163d7a44ab8c1 -timeCreated: 1554538573 -licenseType: Store -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SuperScrollView/Scripts/ListView.meta b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SuperScrollView/Scripts/ListView.meta deleted file mode 100644 index ff3a77e2..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SuperScrollView/Scripts/ListView.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: e9bbd48a4abc45c46a92b92d0df3ae07 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SuperScrollView/Scripts/ListView/LoopListView.cs b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SuperScrollView/Scripts/ListView/LoopListView.cs deleted file mode 100644 index ef82bdf2..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SuperScrollView/Scripts/ListView/LoopListView.cs +++ /dev/null @@ -1,3022 +0,0 @@ -using System; -using System.Collections.Generic; -using TEngine; -using UnityEngine; -using UnityEngine.UI; -using UnityEngine.EventSystems; -using UnityEngine.Serialization; -using Object = UnityEngine.Object; - -namespace GameLogic -{ - public class ItemPool - { - private GameObject _prefabObj; - private string _prefabName; - private int _initCreateCount = 1; - private float _startPosOffset = 0; - private List _tmpPooledItemList = new List(); - private List _pooledItemList = new List(); - private static int _curItemIdCount = 0; - private RectTransform _itemParent = null; - - public ItemPool() - { - } - - public void Init(GameObject prefabObj, float startPosOffset, int createCount, - RectTransform parent) - { - _prefabObj = prefabObj; - _prefabName = _prefabObj.name; - _initCreateCount = createCount; - _startPosOffset = startPosOffset; - _itemParent = parent; - _prefabObj.SetActive(false); - for (int i = 0; i < _initCreateCount; ++i) - { - LoopListViewItem tViewItem = CreateItem(); - RecycleItemReal(tViewItem); - } - } - - public LoopListViewItem GetItem() - { - _curItemIdCount++; - LoopListViewItem tItem = null; - if (_tmpPooledItemList.Count > 0) - { - int count = _tmpPooledItemList.Count; - tItem = _tmpPooledItemList[count - 1]; - _tmpPooledItemList.RemoveAt(count - 1); - tItem.gameObject.SetActive(true); - } - else - { - int count = _pooledItemList.Count; - if (count == 0) - { - tItem = CreateItem(); - } - else - { - tItem = _pooledItemList[count - 1]; - _pooledItemList.RemoveAt(count - 1); - tItem.gameObject.SetActive(true); - } - } - - tItem.ItemId = _curItemIdCount; - return tItem; - } - - public void DestroyAllItem() - { - ClearTmpRecycledItem(); - int count = _pooledItemList.Count; - for (int i = 0; i < count; ++i) - { - Object.DestroyImmediate(_pooledItemList[i].gameObject); - } - - _pooledItemList.Clear(); - } - - public LoopListViewItem CreateItem() - { - GameObject go = Object.Instantiate(_prefabObj, Vector3.zero, Quaternion.identity, _itemParent); - go.SetActive(true); - RectTransform rf = go.GetComponent(); - rf.localScale = Vector3.one; - rf.localPosition = Vector3.zero; - rf.localEulerAngles = Vector3.zero; - LoopListViewItem tViewItem = go.GetComponent(); - tViewItem.ItemPrefabName = _prefabName; - tViewItem.StartPosOffset = _startPosOffset; - tViewItem.GoId = go.GetHashCode(); - return tViewItem; - } - - void RecycleItemReal(LoopListViewItem item) - { - item.gameObject.SetActive(false); - _pooledItemList.Add(item); - } - - public void RecycleItem(LoopListViewItem item) - { - _tmpPooledItemList.Add(item); - } - - public void ClearTmpRecycledItem() - { - int count = _tmpPooledItemList.Count; - if (count == 0) - { - return; - } - - for (int i = 0; i < count; ++i) - { - RecycleItemReal(_tmpPooledItemList[i]); - } - - _tmpPooledItemList.Clear(); - } - } - - [System.Serializable] - public class ItemPrefabConfData - { - public GameObject mItemPrefab = null; - public int mInitCreateCount = 0; - public float mStartPosOffset = 0; - } - - - public class LoopListViewInitParam - { - // all the default values - public float DistanceForRecycle0 = 300; //mDistanceForRecycle0 should be larger than mDistanceForNew0 - public float DistanceForNew0 = 200; - public float DistanceForRecycle1 = 300; //mDistanceForRecycle1 should be larger than mDistanceForNew1 - public float DistanceForNew1 = 200; - public float SmoothDumpRate = 0.3f; - public float SnapFinishThreshold = 0.01f; - public float SnapVecThreshold = 145; - public float ItemDefaultWithPaddingSize = 20; - - public static LoopListViewInitParam CopyDefaultInitParam() - { - return new LoopListViewInitParam(); - } - } - - public delegate LoopListViewItem - OnGetItemByIndex(LoopListView listView, int index); // System.Func - - - public class LoopListView : MonoBehaviour, IBeginDragHandler, IEndDragHandler, IDragHandler - { - class SnapData - { - public SnapStatus SnapStatus = SnapStatus.NoTargetSet; - public int SnapTargetIndex = 0; - public float TargetSnapVal = 0; - public float CurSnapVal = 0; - public bool IsForceSnapTo = false; - - public void Clear() - { - SnapStatus = SnapStatus.NoTargetSet; - IsForceSnapTo = false; - } - } - - private readonly Dictionary _itemPoolDict = new Dictionary(); - private readonly List _itemPoolList = new List(); - [SerializeField] private List itemPrefabDataList = new List(); - [SerializeField] private ListItemArrangeType arrangeType = ListItemArrangeType.TopToBottom; - - public ListItemArrangeType ArrangeType - { - get => arrangeType; - set => arrangeType = value; - } - - private readonly List _itemList = new List(); - private RectTransform _containerTrans; - private ScrollRect _scrollRect = null; - private RectTransform _scrollRectTransform = null; - private RectTransform _viewPortRectTransform = null; - private float _itemDefaultWithPaddingSize = 20; - private int _itemTotalCount = 0; - private bool _isVertList = false; - private OnGetItemByIndex _onGetItemByIndex; - private readonly Vector3[] _itemWorldCorners = new Vector3[4]; - private readonly Vector3[] _viewPortRectLocalCorners = new Vector3[4]; - private int _curReadyMinItemIndex = 0; - private int _curReadyMaxItemIndex = 0; - private bool _needCheckNextMinItem = true; - private bool _needCheckNextMaxItem = true; - private ItemPosMgr _itemPosMgr = null; - private float _distanceForRecycle0 = 300; - private float _distanceForNew0 = 200; - private float _distanceForRecycle1 = 300; - private float _distanceForNew1 = 200; - [SerializeField] private bool supportScrollBar = true; - private bool _isDraging = false; - private PointerEventData _pointerEventData = null; - public System.Action OnBeginDragAction = null; - public System.Action OnDragingAction = null; - public System.Action OnEndDragAction = null; - private int _lastItemIndex = 0; - private float _lastItemPadding = 0; - private float _smoothDumpVel = 0; - private float _smoothDumpRate = 0.3f; - private float _snapFinishThreshold = 0.1f; - private float _snapVecThreshold = 145; - [SerializeField] private bool itemSnapEnable = false; - - - private Vector3 _lastFrameContainerPos = Vector3.zero; - public System.Action OnSnapItemFinished = null; - public System.Action OnSnapNearestChanged = null; - private int _curSnapNearestItemIndex = -1; - private Vector2 _adjustedVec; - private bool _needAdjustVec = false; - private int _leftSnapUpdateExtraCount = 1; - [SerializeField] Vector2 viewPortSnapPivot = Vector2.zero; - [SerializeField] Vector2 itemSnapPivot = Vector2.zero; - private ClickEventListener _scrollBarClickEventListener = null; - private SnapData _curSnapData = new SnapData(); - private Vector3 lastSnapCheckPos = Vector3.zero; - private bool _listViewInited = false; - private int _listUpdateCheckFrameCount = 0; - - public bool IsVertList => _isVertList; - - public int ItemTotalCount => _itemTotalCount; - - public RectTransform ContainerTrans => _containerTrans; - - public ScrollRect ScrollRect => _scrollRect; - - public bool IsDraging => _isDraging; - - public bool ItemSnapEnable - { - get => itemSnapEnable; - set => itemSnapEnable = value; - } - - public bool SupportScrollBar - { - get => supportScrollBar; - set => supportScrollBar = value; - } - - public ItemPrefabConfData GetItemPrefabConfData(string prefabName) - { - foreach (ItemPrefabConfData data in itemPrefabDataList) - { - if (data.mItemPrefab == null) - { - Debug.LogError("A item prefab is null "); - continue; - } - - if (prefabName == data.mItemPrefab.name) - { - return data; - } - } - - return null; - } - - public void OnItemPrefabChanged(string prefabName) - { - ItemPrefabConfData data = GetItemPrefabConfData(prefabName); - if (data == null) - { - return; - } - - if (_itemPoolDict.TryGetValue(prefabName, out var pool) == false) - { - return; - } - - int firstItemIndex = -1; - Vector3 pos = Vector3.zero; - if (_itemList.Count > 0) - { - firstItemIndex = _itemList[0].ItemIndex; - pos = _itemList[0].CachedRectTransform.localPosition; - } - - RecycleAllItem(); - ClearAllTmpRecycledItem(); - pool.DestroyAllItem(); - pool.Init(data.mItemPrefab, data.mStartPosOffset, data.mInitCreateCount, _containerTrans); - if (firstItemIndex >= 0) - { - RefreshAllShownItemWithFirstIndexAndPos(firstItemIndex, pos); - } - } - - /* - InitListView method is to initiate the LoopListView component. There are 3 parameters: - itemTotalCount: the total item count in the listview. If this parameter is set -1, then means there are infinite items, and scrollbar would not be supported, and the ItemIndex can be from –MaxInt to +MaxInt. If this parameter is set a value >=0 , then the ItemIndex can only be from 0 to itemTotalCount -1. - onGetItemByIndex: when a item is getting in the scrollrect viewport, and this Action will be called with the item’ index as a parameter, to let you create the item and update its content. - */ - public void InitListView(int itemTotalCount, OnGetItemByIndex - onGetItemByIndex, - LoopListViewInitParam initParam = null) - { - if (initParam != null) - { - _distanceForRecycle0 = initParam.DistanceForRecycle0; - _distanceForNew0 = initParam.DistanceForNew0; - _distanceForRecycle1 = initParam.DistanceForRecycle1; - _distanceForNew1 = initParam.DistanceForNew1; - _smoothDumpRate = initParam.SmoothDumpRate; - _snapFinishThreshold = initParam.SnapFinishThreshold; - _snapVecThreshold = initParam.SnapVecThreshold; - _itemDefaultWithPaddingSize = initParam.ItemDefaultWithPaddingSize; - } - - _scrollRect = gameObject.GetComponent(); - if (_scrollRect == null) - { - Debug.LogError("ListView Init Failed! ScrollRect component not found!"); - return; - } - - if (_distanceForRecycle0 <= _distanceForNew0) - { - Debug.LogError("mDistanceForRecycle0 should be bigger than mDistanceForNew0"); - } - - if (_distanceForRecycle1 <= _distanceForNew1) - { - Debug.LogError("mDistanceForRecycle1 should be bigger than mDistanceForNew1"); - } - - _curSnapData.Clear(); - _itemPosMgr = new ItemPosMgr(_itemDefaultWithPaddingSize); - _scrollRectTransform = _scrollRect.GetComponent(); - _containerTrans = _scrollRect.content; - _viewPortRectTransform = _scrollRect.viewport; - if (_viewPortRectTransform == null) - { - _viewPortRectTransform = _scrollRectTransform; - } - - if (_scrollRect.horizontalScrollbarVisibility == ScrollRect.ScrollbarVisibility.AutoHideAndExpandViewport && - _scrollRect.horizontalScrollbar != null) - { - Debug.LogError("ScrollRect.horizontalScrollbarVisibility cannot be set to AutoHideAndExpandViewport"); - } - - if (_scrollRect.verticalScrollbarVisibility == ScrollRect.ScrollbarVisibility.AutoHideAndExpandViewport && - _scrollRect.verticalScrollbar != null) - { - Debug.LogError("ScrollRect.verticalScrollbarVisibility cannot be set to AutoHideAndExpandViewport"); - } - - _isVertList = (arrangeType == ListItemArrangeType.TopToBottom || - arrangeType == ListItemArrangeType.BottomToTop); - _scrollRect.horizontal = !_isVertList; - _scrollRect.vertical = _isVertList; - SetScrollbarListener(); - AdjustPivot(_viewPortRectTransform); - AdjustAnchor(_containerTrans); - AdjustContainerPivot(_containerTrans); - InitItemPool(); - _onGetItemByIndex = onGetItemByIndex; - if (_listViewInited) - { - Debug.LogError("LoopListView.InitListView method can be called only once."); - } - - _listViewInited = true; - ResetListView(); - SetListItemCount(itemTotalCount, true); - } - - void SetScrollbarListener() - { - _scrollBarClickEventListener = null; - Scrollbar curScrollBar = null; - if (_isVertList && _scrollRect.verticalScrollbar != null) - { - curScrollBar = _scrollRect.verticalScrollbar; - } - - if (!_isVertList && _scrollRect.horizontalScrollbar != null) - { - curScrollBar = _scrollRect.horizontalScrollbar; - } - - if (curScrollBar == null) - { - return; - } - - ClickEventListener listener = ClickEventListener.Get(curScrollBar.gameObject); - _scrollBarClickEventListener = listener; - listener.SetPointerUpHandler(OnPointerUpInScrollBar); - listener.SetPointerDownHandler(OnPointerDownInScrollBar); - } - - void OnPointerDownInScrollBar(GameObject obj) - { - _curSnapData.Clear(); - } - - void OnPointerUpInScrollBar(GameObject obj) - { - ForceSnapUpdateCheck(); - } - - public void ResetListView() - { - _viewPortRectTransform.GetLocalCorners(_viewPortRectLocalCorners); - _containerTrans.localPosition = Vector3.zero; - ForceSnapUpdateCheck(); - } - - public void ResetListView(Vector3 vector3) - { - _viewPortRectTransform.GetLocalCorners(_viewPortRectLocalCorners); - _containerTrans.localPosition = vector3; - ForceSnapUpdateCheck(); - } - - public Vector3 GetContainerTrans() - { - return _containerTrans.localPosition; - } - - - /* - This method may use to set the item total count of the scrollview at runtime. - If this parameter is set -1, then means there are infinite items, - and scrollbar would not be supported, and the ItemIndex can be from –MaxInt to +MaxInt. - If this parameter is set a value >=0 , then the ItemIndex can only be from 0 to itemTotalCount -1. - If resetPos is set false, then the scrollrect’s content position will not changed after this method finished. - */ - public void SetListItemCount(int itemCount, bool resetPos = true) - { - if (itemCount == _itemTotalCount) - { - return; - } - - _curSnapData.Clear(); - _itemTotalCount = itemCount; - if (_itemTotalCount < 0) - { - supportScrollBar = false; - } - - if (supportScrollBar) - { - _itemPosMgr.SetItemMaxCount(_itemTotalCount); - } - else - { - _itemPosMgr.SetItemMaxCount(0); - } - - if (_itemTotalCount == 0) - { - _curReadyMaxItemIndex = 0; - _curReadyMinItemIndex = 0; - _needCheckNextMaxItem = false; - _needCheckNextMinItem = false; - RecycleAllItem(); - ClearAllTmpRecycledItem(); - UpdateContentSize(); - return; - } - - _leftSnapUpdateExtraCount = 1; - _needCheckNextMaxItem = true; - _needCheckNextMinItem = true; - if (resetPos) - { - MovePanelToItemIndex(0, 0); - return; - } - - if (_itemList.Count == 0) - { - MovePanelToItemIndex(0, 0); - return; - } - - int maxItemIndex = _itemTotalCount - 1; - int lastItemIndex = _itemList[^1].ItemIndex; - if (lastItemIndex <= maxItemIndex) - { - UpdateContentSize(); - UpdateAllShownItemsPos(); - return; - } - - MovePanelToItemIndex(maxItemIndex, 0); - } - - //To get the visible item by itemIndex. If the item is not visible, then this method return null. - public LoopListViewItem GetShownItemByItemIndex(int itemIndex) - { - int count = _itemList.Count; - if (count == 0) - { - return null; - } - - if (itemIndex < _itemList[0].ItemIndex || itemIndex > _itemList[count - 1].ItemIndex) - { - return null; - } - - int i = itemIndex - _itemList[0].ItemIndex; - return _itemList[i]; - } - - public int ShownItemCount => _itemList.Count; - - public float ViewPortSize - { - get - { - if (_isVertList) - { - return _viewPortRectTransform.rect.height; - } - else - { - return _viewPortRectTransform.rect.width; - } - } - } - - public float ViewPortWidth => _viewPortRectTransform.rect.width; - - public float ViewPortHeight => _viewPortRectTransform.rect.height; - - - /* - All visible items is stored in a List , which is named mItemList; - this method is to get the visible item by the index in visible items list. The parameter index is from 0 to mItemList.Count. - */ - public LoopListViewItem GetShownItemByIndex(int index) - { - int count = _itemList.Count; - if (index < 0 || index >= count) - { - return null; - } - - return _itemList[index]; - } - - public LoopListViewItem GetShownItemByIndexWithoutCheck(int index) - { - return _itemList[index]; - } - - public int GetIndexInShownItemList(LoopListViewItem item) - { - if (item == null) - { - return -1; - } - - int count = _itemList.Count; - if (count == 0) - { - return -1; - } - - for (int i = 0; i < count; ++i) - { - if (_itemList[i] == item) - { - return i; - } - } - - return -1; - } - - - public void DoActionForEachShownItem(System.Action action, object param) - { - if (action == null) - { - return; - } - - int count = _itemList.Count; - if (count == 0) - { - return; - } - - for (int i = 0; i < count; ++i) - { - action(_itemList[i], param); - } - } - - public LoopListViewItem AllocOrNewListViewItem(string itemPrefabName) - { - ItemPool pool = null; - if (!string.IsNullOrEmpty(itemPrefabName)) - { - if (_itemPoolDict.TryGetValue(itemPrefabName, out pool) == false) - { - pool = TryCreateItemPool(itemPrefabName); - if (pool == null) - { - return null; - } - } - - return AllocOrNewListViewItem(pool); - } - - return null; - } - - public LoopListViewItem AllocOrNewListViewItem(GameObject prefabGo) - { - ItemPool pool = null; - if (prefabGo != null) - { - if (_itemPoolDict.TryGetValue(prefabGo.name, out pool) == false) - { - pool = TryCreateItemPool(prefabGo); - if (pool == null) - { - return null; - } - } - - return AllocOrNewListViewItem(pool); - } - - return null; - } - - private LoopListViewItem AllocOrNewListViewItem(ItemPool pool) - { - LoopListViewItem item = pool.GetItem(); - RectTransform rf = item.GetComponent(); - rf.SetParent(_containerTrans); - rf.localScale = Vector3.one; - rf.localPosition = Vector3.zero; - rf.localEulerAngles = Vector3.zero; - item.ParentListView = this; - return item; - } - - private ItemPool TryCreateItemPool(string itemPrefabName) - { - string resPath = itemPrefabName; - GameObject go = GameModule.Resource.LoadGameObject(resPath, parent: _containerTrans); - if (go != null) - { - go.SetActive(false); - go.name = itemPrefabName; - ItemPool pool = new ItemPool(); - pool.Init(go, 0, 0, _containerTrans); - _itemPoolDict.Add(itemPrefabName, pool); - _itemPoolList.Add(pool); - return pool; - } - - return null; - } - - private ItemPool TryCreateItemPool(GameObject itemPrefab) - { - if (itemPrefab != null) - { - itemPrefab.SetActive(false); - ItemPool pool = new ItemPool(); - pool.Init(itemPrefab, 0, 0, _containerTrans); - _itemPoolDict.Add(itemPrefab.name, pool); - _itemPoolList.Add(pool); - return pool; - } - - return null; - } - - /* - For a vertical scrollrect, when a visible item’s height changed at runtime, then this method should be called to let the LoopListView component reposition all visible items’ position. - For a horizontal scrollrect, when a visible item’s width changed at runtime, then this method should be called to let the LoopListView component reposition all visible items’ position. - */ - public void OnItemSizeChanged(int itemIndex) - { - LoopListViewItem item = GetShownItemByItemIndex(itemIndex); - if (item == null) - { - return; - } - - if (supportScrollBar) - { - if (_isVertList) - { - SetItemSize(itemIndex, item.CachedRectTransform.rect.height, item.Padding); - } - else - { - SetItemSize(itemIndex, item.CachedRectTransform.rect.width, item.Padding); - } - } - - UpdateContentSize(); - UpdateAllShownItemsPos(); - } - - - /* - To update a item by itemIndex.if the itemIndex-th item is not visible, then this method will do nothing. - Otherwise this method will first call onGetItemByIndex(itemIndex) to get a updated item and then reposition all visible items'position. - */ - public void RefreshItemByItemIndex(int itemIndex) - { - int count = _itemList.Count; - if (count == 0) - { - return; - } - - if (itemIndex < _itemList[0].ItemIndex || itemIndex > _itemList[count - 1].ItemIndex) - { - return; - } - - int firstItemIndex = _itemList[0].ItemIndex; - int i = itemIndex - firstItemIndex; - LoopListViewItem curItem = _itemList[i]; - Vector3 pos = curItem.CachedRectTransform.localPosition; - RecycleItemTmp(curItem); - LoopListViewItem newItem = GetNewItemByIndex(itemIndex); - if (newItem == null) - { - RefreshAllShownItemWithFirstIndex(firstItemIndex); - return; - } - - _itemList[i] = newItem; - if (_isVertList) - { - pos.x = newItem.StartPosOffset; - } - else - { - pos.y = newItem.StartPosOffset; - } - - newItem.CachedRectTransform.localPosition = pos; - OnItemSizeChanged(itemIndex); - ClearAllTmpRecycledItem(); - } - - //snap move will finish at once. - public void FinishSnapImmediately() - { - UpdateSnapMove(true); - } - - /* - This method will move the scrollrect content’s position to ( the positon of itemIndex-th item + offset ), - and in current version the itemIndex is from 0 to MaxInt, offset is from 0 to scrollrect viewport size. - */ - public void MovePanelToItemIndex(int itemIndex, float offset = 0) - { - _scrollRect.StopMovement(); - _curSnapData.Clear(); - if (itemIndex < 0 || _itemTotalCount == 0) - { - return; - } - - if (_itemTotalCount > 0 && itemIndex >= _itemTotalCount) - { - itemIndex = _itemTotalCount - 1; - } - - if (offset < 0) - { - offset = 0; - } - - Vector3 pos = Vector3.zero; - float viewPortSize = ViewPortSize; - if (offset > viewPortSize) - { - offset = viewPortSize; - } - - if (arrangeType == ListItemArrangeType.TopToBottom) - { - float containerPos = _containerTrans.localPosition.y; - if (containerPos < 0) - { - containerPos = 0; - } - - pos.y = -containerPos - offset; - } - else if (arrangeType == ListItemArrangeType.BottomToTop) - { - float containerPos = _containerTrans.localPosition.y; - if (containerPos > 0) - { - containerPos = 0; - } - - pos.y = -containerPos + offset; - } - else if (arrangeType == ListItemArrangeType.LeftToRight) - { - float containerPos = _containerTrans.localPosition.x; - if (containerPos > 0) - { - containerPos = 0; - } - - pos.x = -containerPos + offset; - } - else if (arrangeType == ListItemArrangeType.RightToLeft) - { - float containerPos = _containerTrans.localPosition.x; - if (containerPos < 0) - { - containerPos = 0; - } - - pos.x = -containerPos - offset; - } - - RecycleAllItem(); - LoopListViewItem newItem = GetNewItemByIndex(itemIndex); - if (newItem == null) - { - ClearAllTmpRecycledItem(); - return; - } - - if (_isVertList) - { - pos.x = newItem.StartPosOffset; - } - else - { - pos.y = newItem.StartPosOffset; - } - - newItem.CachedRectTransform.localPosition = pos; - if (supportScrollBar) - { - if (_isVertList) - { - SetItemSize(itemIndex, newItem.CachedRectTransform.rect.height, newItem.Padding); - } - else - { - SetItemSize(itemIndex, newItem.CachedRectTransform.rect.width, newItem.Padding); - } - } - - _itemList.Add(newItem); - UpdateContentSize(); - UpdateListView(viewPortSize + 100, viewPortSize + 100, viewPortSize, viewPortSize); - AdjustPanelPos(); - ClearAllTmpRecycledItem(); - } - - //update all visible items. - public void RefreshAllShownItem() - { - int count = _itemList.Count; - if (count == 0) - { - return; - } - - RefreshAllShownItemWithFirstIndex(_itemList[0].ItemIndex); - } - - - public void RefreshAllShownItemWithFirstIndex(int firstItemIndex) - { - int count = _itemList.Count; - if (count == 0) - { - return; - } - - LoopListViewItem firstItem = _itemList[0]; - Vector3 pos = firstItem.CachedRectTransform.localPosition; - RecycleAllItem(); - for (int i = 0; i < count; ++i) - { - int curIndex = firstItemIndex + i; - LoopListViewItem newItem = GetNewItemByIndex(curIndex); - if (newItem == null) - { - break; - } - - if (_isVertList) - { - pos.x = newItem.StartPosOffset; - } - else - { - pos.y = newItem.StartPosOffset; - } - - newItem.CachedRectTransform.localPosition = pos; - if (supportScrollBar) - { - if (_isVertList) - { - SetItemSize(curIndex, newItem.CachedRectTransform.rect.height, newItem.Padding); - } - else - { - SetItemSize(curIndex, newItem.CachedRectTransform.rect.width, newItem.Padding); - } - } - - _itemList.Add(newItem); - } - - UpdateContentSize(); - UpdateAllShownItemsPos(); - ClearAllTmpRecycledItem(); - } - - - public void RefreshAllShownItemWithFirstIndexAndPos(int firstItemIndex, Vector3 pos) - { - RecycleAllItem(); - LoopListViewItem newItem = GetNewItemByIndex(firstItemIndex); - if (newItem == null) - { - return; - } - - if (_isVertList) - { - pos.x = newItem.StartPosOffset; - } - else - { - pos.y = newItem.StartPosOffset; - } - - newItem.CachedRectTransform.localPosition = pos; - if (supportScrollBar) - { - if (_isVertList) - { - SetItemSize(firstItemIndex, newItem.CachedRectTransform.rect.height, newItem.Padding); - } - else - { - SetItemSize(firstItemIndex, newItem.CachedRectTransform.rect.width, newItem.Padding); - } - } - - _itemList.Add(newItem); - UpdateContentSize(); - UpdateAllShownItemsPos(); - UpdateListView(_distanceForRecycle0, _distanceForRecycle1, _distanceForNew0, _distanceForNew1); - ClearAllTmpRecycledItem(); - } - - - void RecycleItemTmp(LoopListViewItem item) - { - if (item == null) - { - return; - } - - if (string.IsNullOrEmpty(item.ItemPrefabName)) - { - return; - } - - ItemPool pool = null; - if (_itemPoolDict.TryGetValue(item.ItemPrefabName, out pool) == false) - { - return; - } - - pool.RecycleItem(item); - } - - - void ClearAllTmpRecycledItem() - { - int count = _itemPoolList.Count; - for (int i = 0; i < count; ++i) - { - _itemPoolList[i].ClearTmpRecycledItem(); - } - } - - - void RecycleAllItem() - { - foreach (LoopListViewItem item in _itemList) - { - RecycleItemTmp(item); - } - - _itemList.Clear(); - } - - - void AdjustContainerPivot(RectTransform rtf) - { - Vector2 pivot = rtf.pivot; - if (arrangeType == ListItemArrangeType.BottomToTop) - { - pivot.y = 0; - } - else if (arrangeType == ListItemArrangeType.TopToBottom) - { - pivot.y = 1; - } - else if (arrangeType == ListItemArrangeType.LeftToRight) - { - pivot.x = 0; - } - else if (arrangeType == ListItemArrangeType.RightToLeft) - { - pivot.x = 1; - } - - rtf.pivot = pivot; - } - - - void AdjustPivot(RectTransform rtf) - { - Vector2 pivot = rtf.pivot; - - if (arrangeType == ListItemArrangeType.BottomToTop) - { - pivot.y = 0; - } - else if (arrangeType == ListItemArrangeType.TopToBottom) - { - pivot.y = 1; - } - else if (arrangeType == ListItemArrangeType.LeftToRight) - { - pivot.x = 0; - } - else if (arrangeType == ListItemArrangeType.RightToLeft) - { - pivot.x = 1; - } - - rtf.pivot = pivot; - } - - void AdjustContainerAnchor(RectTransform rtf) - { - Vector2 anchorMin = rtf.anchorMin; - Vector2 anchorMax = rtf.anchorMax; - if (arrangeType == ListItemArrangeType.BottomToTop) - { - anchorMin.y = 0; - anchorMax.y = 0; - } - else if (arrangeType == ListItemArrangeType.TopToBottom) - { - anchorMin.y = 1; - anchorMax.y = 1; - } - else if (arrangeType == ListItemArrangeType.LeftToRight) - { - anchorMin.x = 0; - anchorMax.x = 0; - } - else if (arrangeType == ListItemArrangeType.RightToLeft) - { - anchorMin.x = 1; - anchorMax.x = 1; - } - - rtf.anchorMin = anchorMin; - rtf.anchorMax = anchorMax; - } - - - void AdjustAnchor(RectTransform rtf) - { - Vector2 anchorMin = rtf.anchorMin; - Vector2 anchorMax = rtf.anchorMax; - if (arrangeType == ListItemArrangeType.BottomToTop) - { - anchorMin.y = 0; - anchorMax.y = 0; - } - else if (arrangeType == ListItemArrangeType.TopToBottom) - { - anchorMin.y = 1; - anchorMax.y = 1; - } - else if (arrangeType == ListItemArrangeType.LeftToRight) - { - anchorMin.x = 0; - anchorMax.x = 0; - } - else if (arrangeType == ListItemArrangeType.RightToLeft) - { - anchorMin.x = 1; - anchorMax.x = 1; - } - - rtf.anchorMin = anchorMin; - rtf.anchorMax = anchorMax; - } - - void InitItemPool() - { - foreach (ItemPrefabConfData data in itemPrefabDataList) - { - if (data.mItemPrefab == null) - { - Debug.LogError("A item prefab is null "); - continue; - } - - string prefabName = data.mItemPrefab.name; - if (_itemPoolDict.ContainsKey(prefabName)) - { - Debug.LogError("A item prefab with name " + prefabName + " has existed!"); - continue; - } - - RectTransform rtf = data.mItemPrefab.GetComponent(); - if (rtf == null) - { - Debug.LogError("RectTransform component is not found in the prefab " + prefabName); - continue; - } - - AdjustAnchor(rtf); - AdjustPivot(rtf); - LoopListViewItem tItem = data.mItemPrefab.GetComponent(); - if (tItem == null) - { - data.mItemPrefab.AddComponent(); - } - - ItemPool pool = new ItemPool(); - pool.Init(data.mItemPrefab, data.mStartPosOffset, data.mInitCreateCount, - _containerTrans); - _itemPoolDict.Add(prefabName, pool); - _itemPoolList.Add(pool); - } - } - - - public virtual void OnBeginDrag(PointerEventData eventData) - { - if (eventData.button != PointerEventData.InputButton.Left) - { - return; - } - - _isDraging = true; - CacheDragPointerEventData(eventData); - _curSnapData.Clear(); - if (OnBeginDragAction != null) - { - OnBeginDragAction(); - } - } - - public virtual void OnEndDrag(PointerEventData eventData) - { - if (eventData.button != PointerEventData.InputButton.Left) - { - return; - } - - _isDraging = false; - _pointerEventData = null; - if (OnEndDragAction != null) - { - OnEndDragAction(); - } - - ForceSnapUpdateCheck(); - } - - public virtual void OnDrag(PointerEventData eventData) - { - if (eventData.button != PointerEventData.InputButton.Left) - { - return; - } - - CacheDragPointerEventData(eventData); - if (OnDragingAction != null) - { - OnDragingAction(); - } - } - - void CacheDragPointerEventData(PointerEventData eventData) - { - if (_pointerEventData == null) - { - _pointerEventData = new PointerEventData(EventSystem.current); - } - - _pointerEventData.button = eventData.button; - _pointerEventData.position = eventData.position; - _pointerEventData.pointerPressRaycast = eventData.pointerPressRaycast; - _pointerEventData.pointerCurrentRaycast = eventData.pointerCurrentRaycast; - } - - LoopListViewItem GetNewItemByIndex(int index) - { - if (supportScrollBar && index < 0) - { - return null; - } - - if (_itemTotalCount > 0 && index >= _itemTotalCount) - { - return null; - } - - LoopListViewItem newItem = _onGetItemByIndex(this, index); - if (newItem == null) - { - return null; - } - - newItem.ItemIndex = index; - newItem.ItemCreatedCheckFrameCount = _listUpdateCheckFrameCount; - return newItem; - } - - - void SetItemSize(int itemIndex, float itemSize, float padding) - { - _itemPosMgr.SetItemSize(itemIndex, itemSize + padding); - if (itemIndex >= _lastItemIndex) - { - _lastItemIndex = itemIndex; - _lastItemPadding = padding; - } - } - - void GetPlusItemIndexAndPosAtGivenPos(float pos, ref int index, ref float itemPos) - { - _itemPosMgr.GetItemIndexAndPosAtGivenPos(pos, ref index, ref itemPos); - } - - - float GetItemPos(int itemIndex) - { - return _itemPosMgr.GetItemPos(itemIndex); - } - - - public Vector3 GetItemCornerPosInViewPort(LoopListViewItem item, - ItemCornerEnum corner = ItemCornerEnum.LeftBottom) - { - item.CachedRectTransform.GetWorldCorners(_itemWorldCorners); - return _viewPortRectTransform.InverseTransformPoint(_itemWorldCorners[(int)corner]); - } - - - void AdjustPanelPos() - { - int count = _itemList.Count; - if (count == 0) - { - return; - } - - UpdateAllShownItemsPos(); - float viewPortSize = ViewPortSize; - float contentSize = GetContentPanelSize(); - if (arrangeType == ListItemArrangeType.TopToBottom) - { - if (contentSize <= viewPortSize) - { - Vector3 pos = _containerTrans.localPosition; - pos.y = 0; - _containerTrans.localPosition = pos; - _itemList[0].CachedRectTransform.localPosition = new Vector3(_itemList[0].StartPosOffset, 0, 0); - UpdateAllShownItemsPos(); - return; - } - - LoopListViewItem tViewItem0 = _itemList[0]; - tViewItem0.CachedRectTransform.GetWorldCorners(_itemWorldCorners); - Vector3 topPos0 = _viewPortRectTransform.InverseTransformPoint(_itemWorldCorners[1]); - if (topPos0.y < _viewPortRectLocalCorners[1].y) - { - Vector3 pos = _containerTrans.localPosition; - pos.y = 0; - _containerTrans.localPosition = pos; - _itemList[0].CachedRectTransform.localPosition = new Vector3(_itemList[0].StartPosOffset, 0, 0); - UpdateAllShownItemsPos(); - return; - } - - LoopListViewItem tViewItem1 = _itemList[^1]; - tViewItem1.CachedRectTransform.GetWorldCorners(_itemWorldCorners); - Vector3 downPos1 = _viewPortRectTransform.InverseTransformPoint(_itemWorldCorners[0]); - float d = downPos1.y - _viewPortRectLocalCorners[0].y; - if (d > 0) - { - Vector3 pos = _itemList[0].CachedRectTransform.localPosition; - pos.y = pos.y - d; - _itemList[0].CachedRectTransform.localPosition = pos; - UpdateAllShownItemsPos(); - return; - } - } - else if (arrangeType == ListItemArrangeType.BottomToTop) - { - if (contentSize <= viewPortSize) - { - Vector3 pos = _containerTrans.localPosition; - pos.y = 0; - _containerTrans.localPosition = pos; - _itemList[0].CachedRectTransform.localPosition = new Vector3(_itemList[0].StartPosOffset, 0, 0); - UpdateAllShownItemsPos(); - return; - } - - LoopListViewItem tViewItem0 = _itemList[0]; - tViewItem0.CachedRectTransform.GetWorldCorners(_itemWorldCorners); - Vector3 downPos0 = _viewPortRectTransform.InverseTransformPoint(_itemWorldCorners[0]); - if (downPos0.y > _viewPortRectLocalCorners[0].y) - { - Vector3 pos = _containerTrans.localPosition; - pos.y = 0; - _containerTrans.localPosition = pos; - _itemList[0].CachedRectTransform.localPosition = new Vector3(_itemList[0].StartPosOffset, 0, 0); - UpdateAllShownItemsPos(); - return; - } - - LoopListViewItem tViewItem1 = _itemList[^1]; - tViewItem1.CachedRectTransform.GetWorldCorners(_itemWorldCorners); - Vector3 topPos1 = _viewPortRectTransform.InverseTransformPoint(_itemWorldCorners[1]); - float d = _viewPortRectLocalCorners[1].y - topPos1.y; - if (d > 0) - { - Vector3 pos = _itemList[0].CachedRectTransform.localPosition; - pos.y = pos.y + d; - _itemList[0].CachedRectTransform.localPosition = pos; - UpdateAllShownItemsPos(); - return; - } - } - else if (arrangeType == ListItemArrangeType.LeftToRight) - { - if (contentSize <= viewPortSize) - { - Vector3 pos = _containerTrans.localPosition; - pos.x = 0; - _containerTrans.localPosition = pos; - _itemList[0].CachedRectTransform.localPosition = new Vector3(0, _itemList[0].StartPosOffset, 0); - UpdateAllShownItemsPos(); - return; - } - - LoopListViewItem tViewItem0 = _itemList[0]; - tViewItem0.CachedRectTransform.GetWorldCorners(_itemWorldCorners); - Vector3 leftPos0 = _viewPortRectTransform.InverseTransformPoint(_itemWorldCorners[1]); - if (leftPos0.x > _viewPortRectLocalCorners[1].x) - { - Vector3 pos = _containerTrans.localPosition; - pos.x = 0; - _containerTrans.localPosition = pos; - _itemList[0].CachedRectTransform.localPosition = new Vector3(0, _itemList[0].StartPosOffset, 0); - UpdateAllShownItemsPos(); - return; - } - - LoopListViewItem tViewItem1 = _itemList[^1]; - tViewItem1.CachedRectTransform.GetWorldCorners(_itemWorldCorners); - Vector3 rightPos1 = _viewPortRectTransform.InverseTransformPoint(_itemWorldCorners[2]); - float d = _viewPortRectLocalCorners[2].x - rightPos1.x; - if (d > 0) - { - Vector3 pos = _itemList[0].CachedRectTransform.localPosition; - pos.x = pos.x + d; - _itemList[0].CachedRectTransform.localPosition = pos; - UpdateAllShownItemsPos(); - return; - } - } - else if (arrangeType == ListItemArrangeType.RightToLeft) - { - if (contentSize <= viewPortSize) - { - Vector3 pos = _containerTrans.localPosition; - pos.x = 0; - _containerTrans.localPosition = pos; - _itemList[0].CachedRectTransform.localPosition = new Vector3(0, _itemList[0].StartPosOffset, 0); - UpdateAllShownItemsPos(); - return; - } - - LoopListViewItem tViewItem0 = _itemList[0]; - tViewItem0.CachedRectTransform.GetWorldCorners(_itemWorldCorners); - Vector3 rightPos0 = _viewPortRectTransform.InverseTransformPoint(_itemWorldCorners[2]); - if (rightPos0.x < _viewPortRectLocalCorners[2].x) - { - Vector3 pos = _containerTrans.localPosition; - pos.x = 0; - _containerTrans.localPosition = pos; - _itemList[0].CachedRectTransform.localPosition = new Vector3(0, _itemList[0].StartPosOffset, 0); - UpdateAllShownItemsPos(); - return; - } - - LoopListViewItem tViewItem1 = _itemList[^1]; - tViewItem1.CachedRectTransform.GetWorldCorners(_itemWorldCorners); - Vector3 leftPos1 = _viewPortRectTransform.InverseTransformPoint(_itemWorldCorners[1]); - float d = leftPos1.x - _viewPortRectLocalCorners[1].x; - if (d > 0) - { - Vector3 pos = _itemList[0].CachedRectTransform.localPosition; - pos.x = pos.x - d; - _itemList[0].CachedRectTransform.localPosition = pos; - UpdateAllShownItemsPos(); - return; - } - } - } - - - void Update() - { - if (_listViewInited == false) - { - return; - } - - if (_needAdjustVec) - { - _needAdjustVec = false; - if (_isVertList) - { - if (_scrollRect.velocity.y * _adjustedVec.y > 0) - { - _scrollRect.velocity = _adjustedVec; - } - } - else - { - if (_scrollRect.velocity.x * _adjustedVec.x > 0) - { - _scrollRect.velocity = _adjustedVec; - } - } - } - - if (supportScrollBar) - { - _itemPosMgr.Update(false); - } - - UpdateSnapMove(); - UpdateListView(_distanceForRecycle0, _distanceForRecycle1, _distanceForNew0, _distanceForNew1); - ClearAllTmpRecycledItem(); - _lastFrameContainerPos = _containerTrans.localPosition; - } - - //update snap move. if immediate is set true, then the snap move will finish at once. - void UpdateSnapMove(bool immediate = false) - { - if (itemSnapEnable == false) - { - return; - } - - if (_isVertList) - { - UpdateSnapVertical(immediate); - } - else - { - UpdateSnapHorizontal(immediate); - } - } - - - public void UpdateAllShownItemSnapData() - { - if (itemSnapEnable == false) - { - return; - } - - int count = _itemList.Count; - if (count == 0) - { - return; - } - - Vector3 pos = _containerTrans.localPosition; - LoopListViewItem tViewItem0 = _itemList[0]; - tViewItem0.CachedRectTransform.GetWorldCorners(_itemWorldCorners); - float start = 0; - float end = 0; - float itemSnapCenter = 0; - float snapCenter = 0; - if (arrangeType == ListItemArrangeType.TopToBottom) - { - snapCenter = -(1 - viewPortSnapPivot.y) * _viewPortRectTransform.rect.height; - Vector3 topPos1 = _viewPortRectTransform.InverseTransformPoint(_itemWorldCorners[1]); - start = topPos1.y; - end = start - tViewItem0.ItemSizeWithPadding; - itemSnapCenter = start - tViewItem0.ItemSize * (1 - itemSnapPivot.y); - for (int i = 0; i < count; ++i) - { - _itemList[i].DistanceWithViewPortSnapCenter = snapCenter - itemSnapCenter; - if ((i + 1) < count) - { - start = end; - end = end - _itemList[i + 1].ItemSizeWithPadding; - itemSnapCenter = start - _itemList[i + 1].ItemSize * (1 - itemSnapPivot.y); - } - } - } - else if (arrangeType == ListItemArrangeType.BottomToTop) - { - snapCenter = viewPortSnapPivot.y * _viewPortRectTransform.rect.height; - Vector3 bottomPos1 = _viewPortRectTransform.InverseTransformPoint(_itemWorldCorners[0]); - start = bottomPos1.y; - end = start + tViewItem0.ItemSizeWithPadding; - itemSnapCenter = start + tViewItem0.ItemSize * itemSnapPivot.y; - for (int i = 0; i < count; ++i) - { - _itemList[i].DistanceWithViewPortSnapCenter = snapCenter - itemSnapCenter; - if ((i + 1) < count) - { - start = end; - end = end + _itemList[i + 1].ItemSizeWithPadding; - itemSnapCenter = start + _itemList[i + 1].ItemSize * itemSnapPivot.y; - } - } - } - else if (arrangeType == ListItemArrangeType.RightToLeft) - { - snapCenter = -(1 - viewPortSnapPivot.x) * _viewPortRectTransform.rect.width; - Vector3 rightPos1 = _viewPortRectTransform.InverseTransformPoint(_itemWorldCorners[2]); - start = rightPos1.x; - end = start - tViewItem0.ItemSizeWithPadding; - itemSnapCenter = start - tViewItem0.ItemSize * (1 - itemSnapPivot.x); - for (int i = 0; i < count; ++i) - { - _itemList[i].DistanceWithViewPortSnapCenter = snapCenter - itemSnapCenter; - if ((i + 1) < count) - { - start = end; - end = end - _itemList[i + 1].ItemSizeWithPadding; - itemSnapCenter = start - _itemList[i + 1].ItemSize * (1 - itemSnapPivot.x); - } - } - } - else if (arrangeType == ListItemArrangeType.LeftToRight) - { - snapCenter = viewPortSnapPivot.x * _viewPortRectTransform.rect.width; - Vector3 leftPos1 = _viewPortRectTransform.InverseTransformPoint(_itemWorldCorners[1]); - start = leftPos1.x; - end = start + tViewItem0.ItemSizeWithPadding; - itemSnapCenter = start + tViewItem0.ItemSize * itemSnapPivot.x; - for (int i = 0; i < count; ++i) - { - _itemList[i].DistanceWithViewPortSnapCenter = snapCenter - itemSnapCenter; - if ((i + 1) < count) - { - start = end; - end = end + _itemList[i + 1].ItemSizeWithPadding; - itemSnapCenter = start + _itemList[i + 1].ItemSize * itemSnapPivot.x; - } - } - } - } - - - void UpdateSnapVertical(bool immediate = false) - { - if (itemSnapEnable == false) - { - return; - } - - int count = _itemList.Count; - if (count == 0) - { - return; - } - - Vector3 pos = _containerTrans.localPosition; - bool needCheck = Math.Abs(pos.y - lastSnapCheckPos.y) > 0.001f; - lastSnapCheckPos = pos; - if (!needCheck) - { - if (_leftSnapUpdateExtraCount > 0) - { - _leftSnapUpdateExtraCount--; - needCheck = true; - } - } - - if (needCheck) - { - LoopListViewItem tViewItem0 = _itemList[0]; - tViewItem0.CachedRectTransform.GetWorldCorners(_itemWorldCorners); - int curIndex = -1; - float start = 0; - float end = 0; - float itemSnapCenter = 0; - float curMinDist = float.MaxValue; - float curDist = 0; - float curDistAbs = 0; - float snapCenter = 0; - if (arrangeType == ListItemArrangeType.TopToBottom) - { - snapCenter = -(1 - viewPortSnapPivot.y) * _viewPortRectTransform.rect.height; - Vector3 topPos1 = _viewPortRectTransform.InverseTransformPoint(_itemWorldCorners[1]); - start = topPos1.y; - end = start - tViewItem0.ItemSizeWithPadding; - itemSnapCenter = start - tViewItem0.ItemSize * (1 - itemSnapPivot.y); - for (int i = 0; i < count; ++i) - { - curDist = snapCenter - itemSnapCenter; - curDistAbs = Mathf.Abs(curDist); - if (curDistAbs < curMinDist) - { - curMinDist = curDistAbs; - curIndex = i; - } - else - { - break; - } - - if ((i + 1) < count) - { - start = end; - end = end - _itemList[i + 1].ItemSizeWithPadding; - itemSnapCenter = start - _itemList[i + 1].ItemSize * (1 - itemSnapPivot.y); - } - } - } - else if (arrangeType == ListItemArrangeType.BottomToTop) - { - snapCenter = viewPortSnapPivot.y * _viewPortRectTransform.rect.height; - Vector3 bottomPos1 = _viewPortRectTransform.InverseTransformPoint(_itemWorldCorners[0]); - start = bottomPos1.y; - end = start + tViewItem0.ItemSizeWithPadding; - itemSnapCenter = start + tViewItem0.ItemSize * itemSnapPivot.y; - for (int i = 0; i < count; ++i) - { - curDist = snapCenter - itemSnapCenter; - curDistAbs = Mathf.Abs(curDist); - if (curDistAbs < curMinDist) - { - curMinDist = curDistAbs; - curIndex = i; - } - else - { - break; - } - - if ((i + 1) < count) - { - start = end; - end = end + _itemList[i + 1].ItemSizeWithPadding; - itemSnapCenter = start + _itemList[i + 1].ItemSize * itemSnapPivot.y; - } - } - } - - if (curIndex >= 0) - { - int oldNearestItemIndex = _curSnapNearestItemIndex; - _curSnapNearestItemIndex = _itemList[curIndex].ItemIndex; - if (_itemList[curIndex].ItemIndex != oldNearestItemIndex) - { - if (OnSnapNearestChanged != null) - { - OnSnapNearestChanged(this, _itemList[curIndex]); - } - } - } - else - { - _curSnapNearestItemIndex = -1; - } - } - - bool canSnap = true; - if (_scrollBarClickEventListener != null) - { - canSnap = !(_scrollBarClickEventListener.IsPressed); - } - - float v = Mathf.Abs(_scrollRect.velocity.y); - if (canSnap && !_isDraging && v < _snapVecThreshold) - { - UpdateCurSnapData(); - if (_curSnapData.SnapStatus != SnapStatus.SnapMoving) - { - return; - } - - if (v > 0) - { - _scrollRect.StopMovement(); - } - - float old = _curSnapData.CurSnapVal; - _curSnapData.CurSnapVal = Mathf.SmoothDamp(_curSnapData.CurSnapVal, _curSnapData.TargetSnapVal, - ref _smoothDumpVel, _smoothDumpRate); - float dt = _curSnapData.CurSnapVal - old; - - if (immediate || Mathf.Abs(_curSnapData.TargetSnapVal - _curSnapData.CurSnapVal) < - _snapFinishThreshold) - { - pos.y = pos.y + _curSnapData.TargetSnapVal - _curSnapData.CurSnapVal; - _curSnapData.SnapStatus = SnapStatus.SnapMoveFinish; - if (OnSnapItemFinished != null) - { - LoopListViewItem targetItem = GetShownItemByItemIndex(_curSnapNearestItemIndex); - if (targetItem != null) - { - OnSnapItemFinished(this, targetItem); - } - } - } - else - { - pos.y = pos.y + dt; - } - - if (arrangeType == ListItemArrangeType.TopToBottom) - { - float maxY = _viewPortRectLocalCorners[0].y + _containerTrans.rect.height; - if (pos.y <= maxY && pos.y >= 0) - { - _containerTrans.localPosition = pos; - } - } - else if (arrangeType == ListItemArrangeType.BottomToTop) - { - float minY = _viewPortRectLocalCorners[1].y - _containerTrans.rect.height; - if (pos.y >= minY && pos.y <= 0) - { - _containerTrans.localPosition = pos; - } - } - } - } - - - void UpdateCurSnapData() - { - int count = _itemList.Count; - if (count == 0) - { - _curSnapData.Clear(); - return; - } - - if (_curSnapData.SnapStatus == SnapStatus.SnapMoveFinish) - { - if (_curSnapData.SnapTargetIndex == _curSnapNearestItemIndex) - { - return; - } - - _curSnapData.SnapStatus = SnapStatus.NoTargetSet; - } - - if (_curSnapData.SnapStatus == SnapStatus.SnapMoving) - { - if ((_curSnapData.SnapTargetIndex == _curSnapNearestItemIndex) || _curSnapData.IsForceSnapTo) - { - return; - } - - _curSnapData.SnapStatus = SnapStatus.NoTargetSet; - } - - if (_curSnapData.SnapStatus == SnapStatus.NoTargetSet) - { - LoopListViewItem nearestItem = GetShownItemByItemIndex(_curSnapNearestItemIndex); - if (nearestItem == null) - { - return; - } - - _curSnapData.SnapTargetIndex = _curSnapNearestItemIndex; - _curSnapData.SnapStatus = SnapStatus.TargetHasSet; - _curSnapData.IsForceSnapTo = false; - } - - if (_curSnapData.SnapStatus == SnapStatus.TargetHasSet) - { - LoopListViewItem targetItem = GetShownItemByItemIndex(_curSnapData.SnapTargetIndex); - if (targetItem == null) - { - _curSnapData.Clear(); - return; - } - - UpdateAllShownItemSnapData(); - _curSnapData.TargetSnapVal = targetItem.DistanceWithViewPortSnapCenter; - _curSnapData.CurSnapVal = 0; - _curSnapData.SnapStatus = SnapStatus.SnapMoving; - } - } - - //Clear current snap target and then the LoopScrollView2 will auto snap to the CurSnapNearestItemIndex. - public void ClearSnapData() - { - _curSnapData.Clear(); - } - - public void SetSnapTargetItemIndex(int itemIndex) - { - _curSnapData.SnapTargetIndex = itemIndex; - _curSnapData.SnapStatus = SnapStatus.TargetHasSet; - _curSnapData.IsForceSnapTo = true; - } - - //Get the nearest item index with the viewport snap point. - public int CurSnapNearestItemIndex => _curSnapNearestItemIndex; - - public void ForceSnapUpdateCheck() - { - if (_leftSnapUpdateExtraCount <= 0) - { - _leftSnapUpdateExtraCount = 1; - } - } - - void UpdateSnapHorizontal(bool immediate = false) - { - if (itemSnapEnable == false) - { - return; - } - - int count = _itemList.Count; - if (count == 0) - { - return; - } - - Vector3 pos = _containerTrans.localPosition; - bool needCheck = (pos.x != lastSnapCheckPos.x); - lastSnapCheckPos = pos; - if (!needCheck) - { - if (_leftSnapUpdateExtraCount > 0) - { - _leftSnapUpdateExtraCount--; - needCheck = true; - } - } - - if (needCheck) - { - LoopListViewItem tViewItem0 = _itemList[0]; - tViewItem0.CachedRectTransform.GetWorldCorners(_itemWorldCorners); - int curIndex = -1; - float start = 0; - float end = 0; - float itemSnapCenter = 0; - float curMinDist = float.MaxValue; - float curDist = 0; - float curDistAbs = 0; - float snapCenter = 0; - if (arrangeType == ListItemArrangeType.RightToLeft) - { - snapCenter = -(1 - viewPortSnapPivot.x) * _viewPortRectTransform.rect.width; - Vector3 rightPos1 = _viewPortRectTransform.InverseTransformPoint(_itemWorldCorners[2]); - start = rightPos1.x; - end = start - tViewItem0.ItemSizeWithPadding; - itemSnapCenter = start - tViewItem0.ItemSize * (1 - itemSnapPivot.x); - for (int i = 0; i < count; ++i) - { - curDist = snapCenter - itemSnapCenter; - curDistAbs = Mathf.Abs(curDist); - if (curDistAbs < curMinDist) - { - curMinDist = curDistAbs; - curIndex = i; - } - else - { - break; - } - - if ((i + 1) < count) - { - start = end; - end = end - _itemList[i + 1].ItemSizeWithPadding; - itemSnapCenter = start - _itemList[i + 1].ItemSize * (1 - itemSnapPivot.x); - } - } - } - else if (arrangeType == ListItemArrangeType.LeftToRight) - { - snapCenter = viewPortSnapPivot.x * _viewPortRectTransform.rect.width; - Vector3 leftPos1 = _viewPortRectTransform.InverseTransformPoint(_itemWorldCorners[1]); - start = leftPos1.x; - end = start + tViewItem0.ItemSizeWithPadding; - itemSnapCenter = start + tViewItem0.ItemSize * itemSnapPivot.x; - for (int i = 0; i < count; ++i) - { - curDist = snapCenter - itemSnapCenter; - curDistAbs = Mathf.Abs(curDist); - if (curDistAbs < curMinDist) - { - curMinDist = curDistAbs; - curIndex = i; - } - else - { - break; - } - - if ((i + 1) < count) - { - start = end; - end = end + _itemList[i + 1].ItemSizeWithPadding; - itemSnapCenter = start + _itemList[i + 1].ItemSize * itemSnapPivot.x; - } - } - } - - - if (curIndex >= 0) - { - int oldNearestItemIndex = _curSnapNearestItemIndex; - _curSnapNearestItemIndex = _itemList[curIndex].ItemIndex; - if (_itemList[curIndex].ItemIndex != oldNearestItemIndex) - { - if (OnSnapNearestChanged != null) - { - OnSnapNearestChanged(this, _itemList[curIndex]); - } - } - } - else - { - _curSnapNearestItemIndex = -1; - } - } - - bool canSnap = true; - if (_scrollBarClickEventListener != null) - { - canSnap = !(_scrollBarClickEventListener.IsPressed); - } - - float v = Mathf.Abs(_scrollRect.velocity.x); - if (canSnap && !_isDraging && v < _snapVecThreshold) - { - UpdateCurSnapData(); - if (_curSnapData.SnapStatus != SnapStatus.SnapMoving) - { - return; - } - - if (v > 0) - { - _scrollRect.StopMovement(); - } - - float old = _curSnapData.CurSnapVal; - _curSnapData.CurSnapVal = Mathf.SmoothDamp(_curSnapData.CurSnapVal, _curSnapData.TargetSnapVal, - ref _smoothDumpVel, _smoothDumpRate); - float dt = _curSnapData.CurSnapVal - old; - - if (immediate || Mathf.Abs(_curSnapData.TargetSnapVal - _curSnapData.CurSnapVal) < - _snapFinishThreshold) - { - pos.x = pos.x + _curSnapData.TargetSnapVal - _curSnapData.CurSnapVal; - _curSnapData.SnapStatus = SnapStatus.SnapMoveFinish; - if (OnSnapItemFinished != null) - { - LoopListViewItem targetItem = GetShownItemByItemIndex(_curSnapNearestItemIndex); - if (targetItem != null) - { - OnSnapItemFinished(this, targetItem); - } - } - } - else - { - pos.x = pos.x + dt; - } - - if (arrangeType == ListItemArrangeType.LeftToRight) - { - float minX = _viewPortRectLocalCorners[2].x - _containerTrans.rect.width; - if (pos.x >= minX && pos.x <= 0) - { - _containerTrans.localPosition = pos; - } - } - else if (arrangeType == ListItemArrangeType.RightToLeft) - { - float maxX = _viewPortRectLocalCorners[1].x + _containerTrans.rect.width; - if (pos.x <= maxX && pos.x >= 0) - { - _containerTrans.localPosition = pos; - } - } - } - } - - - public void UpdateListView(float distanceForRecycle0, float distanceForRecycle1, float distanceForNew0, - float distanceForNew1) - { - _listUpdateCheckFrameCount++; - if (_isVertList) - { - bool needContinueCheck = true; - int checkCount = 0; - int maxCount = 9999; - while (needContinueCheck) - { - checkCount++; - if (checkCount >= maxCount) - { - Debug.LogError("UpdateListView Vertical while loop " + checkCount + - " times! something is wrong!"); - break; - } - - needContinueCheck = UpdateForVertList(distanceForRecycle0, distanceForRecycle1, distanceForNew0, - distanceForNew1); - } - } - else - { - bool needContinueCheck = true; - int checkCount = 0; - int maxCount = 9999; - while (needContinueCheck) - { - checkCount++; - if (checkCount >= maxCount) - { - Debug.LogError("UpdateListView Horizontal while loop " + checkCount + - " times! something is wrong!"); - break; - } - - needContinueCheck = UpdateForHorizontalList(distanceForRecycle0, distanceForRecycle1, - distanceForNew0, distanceForNew1); - } - } - } - - - bool UpdateForVertList(float distanceForRecycle0, float distanceForRecycle1, float distanceForNew0, - float distanceForNew1) - { - if (_itemTotalCount == 0) - { - if (_itemList.Count > 0) - { - RecycleAllItem(); - } - - return false; - } - - if (arrangeType == ListItemArrangeType.TopToBottom) - { - int itemListCount = _itemList.Count; - if (itemListCount == 0) - { - float curY = _containerTrans.localPosition.y; - if (curY < 0) - { - curY = 0; - } - - int index = 0; - float pos = -curY; - if (supportScrollBar) - { - GetPlusItemIndexAndPosAtGivenPos(curY, ref index, ref pos); - pos = -pos; - } - - LoopListViewItem newItem = GetNewItemByIndex(index); - if (newItem == null) - { - return false; - } - - if (supportScrollBar) - { - SetItemSize(index, newItem.CachedRectTransform.rect.height, newItem.Padding); - } - - _itemList.Add(newItem); - newItem.CachedRectTransform.localPosition = new Vector3(newItem.StartPosOffset, pos, 0); - UpdateContentSize(); - return true; - } - - LoopListViewItem tViewItem0 = _itemList[0]; - tViewItem0.CachedRectTransform.GetWorldCorners(_itemWorldCorners); - Vector3 topPos0 = _viewPortRectTransform.InverseTransformPoint(_itemWorldCorners[1]); - Vector3 downPos0 = _viewPortRectTransform.InverseTransformPoint(_itemWorldCorners[0]); - - if (!_isDraging && tViewItem0.ItemCreatedCheckFrameCount != _listUpdateCheckFrameCount - && downPos0.y - _viewPortRectLocalCorners[1].y > distanceForRecycle0) - { - _itemList.RemoveAt(0); - RecycleItemTmp(tViewItem0); - if (!supportScrollBar) - { - UpdateContentSize(); - CheckIfNeedUpdateItemPos(); - } - - return true; - } - - LoopListViewItem tViewItem1 = _itemList[_itemList.Count - 1]; - tViewItem1.CachedRectTransform.GetWorldCorners(_itemWorldCorners); - Vector3 topPos1 = _viewPortRectTransform.InverseTransformPoint(_itemWorldCorners[1]); - Vector3 downPos1 = _viewPortRectTransform.InverseTransformPoint(_itemWorldCorners[0]); - if (!_isDraging && tViewItem1.ItemCreatedCheckFrameCount != _listUpdateCheckFrameCount - && _viewPortRectLocalCorners[0].y - topPos1.y > distanceForRecycle1) - { - _itemList.RemoveAt(_itemList.Count - 1); - RecycleItemTmp(tViewItem1); - if (!supportScrollBar) - { - UpdateContentSize(); - CheckIfNeedUpdateItemPos(); - } - - return true; - } - - - if (_viewPortRectLocalCorners[0].y - downPos1.y < distanceForNew1) - { - if (tViewItem1.ItemIndex > _curReadyMaxItemIndex) - { - _curReadyMaxItemIndex = tViewItem1.ItemIndex; - _needCheckNextMaxItem = true; - } - - int nIndex = tViewItem1.ItemIndex + 1; - if (nIndex <= _curReadyMaxItemIndex || _needCheckNextMaxItem) - { - LoopListViewItem newItem = GetNewItemByIndex(nIndex); - if (newItem == null) - { - _curReadyMaxItemIndex = tViewItem1.ItemIndex; - _needCheckNextMaxItem = false; - CheckIfNeedUpdateItemPos(); - } - else - { - if (supportScrollBar) - { - SetItemSize(nIndex, newItem.CachedRectTransform.rect.height, newItem.Padding); - } - - _itemList.Add(newItem); - float y = tViewItem1.CachedRectTransform.localPosition.y - - tViewItem1.CachedRectTransform.rect.height - tViewItem1.Padding; - newItem.CachedRectTransform.localPosition = new Vector3(newItem.StartPosOffset, y, 0); - UpdateContentSize(); - CheckIfNeedUpdateItemPos(); - - if (nIndex > _curReadyMaxItemIndex) - { - _curReadyMaxItemIndex = nIndex; - } - - return true; - } - } - } - - if (topPos0.y - _viewPortRectLocalCorners[1].y < distanceForNew0) - { - if (tViewItem0.ItemIndex < _curReadyMinItemIndex) - { - _curReadyMinItemIndex = tViewItem0.ItemIndex; - _needCheckNextMinItem = true; - } - - int nIndex = tViewItem0.ItemIndex - 1; - if (nIndex >= _curReadyMinItemIndex || _needCheckNextMinItem) - { - LoopListViewItem newItem = GetNewItemByIndex(nIndex); - if (newItem == null) - { - _curReadyMinItemIndex = tViewItem0.ItemIndex; - _needCheckNextMinItem = false; - } - else - { - if (supportScrollBar) - { - SetItemSize(nIndex, newItem.CachedRectTransform.rect.height, newItem.Padding); - } - - _itemList.Insert(0, newItem); - float y = tViewItem0.CachedRectTransform.localPosition.y + - newItem.CachedRectTransform.rect.height + newItem.Padding; - newItem.CachedRectTransform.localPosition = new Vector3(newItem.StartPosOffset, y, 0); - UpdateContentSize(); - CheckIfNeedUpdateItemPos(); - if (nIndex < _curReadyMinItemIndex) - { - _curReadyMinItemIndex = nIndex; - } - - return true; - } - } - } - } - else - { - if (_itemList.Count == 0) - { - float curY = _containerTrans.localPosition.y; - if (curY > 0) - { - curY = 0; - } - - int index = 0; - float pos = -curY; - if (supportScrollBar) - { - GetPlusItemIndexAndPosAtGivenPos(-curY, ref index, ref pos); - } - - LoopListViewItem newItem = GetNewItemByIndex(index); - if (newItem == null) - { - return false; - } - - if (supportScrollBar) - { - SetItemSize(index, newItem.CachedRectTransform.rect.height, newItem.Padding); - } - - _itemList.Add(newItem); - newItem.CachedRectTransform.localPosition = new Vector3(newItem.StartPosOffset, pos, 0); - UpdateContentSize(); - return true; - } - - LoopListViewItem tViewItem0 = _itemList[0]; - tViewItem0.CachedRectTransform.GetWorldCorners(_itemWorldCorners); - Vector3 topPos0 = _viewPortRectTransform.InverseTransformPoint(_itemWorldCorners[1]); - Vector3 downPos0 = _viewPortRectTransform.InverseTransformPoint(_itemWorldCorners[0]); - - if (!_isDraging && tViewItem0.ItemCreatedCheckFrameCount != _listUpdateCheckFrameCount - && _viewPortRectLocalCorners[0].y - topPos0.y > distanceForRecycle0) - { - _itemList.RemoveAt(0); - RecycleItemTmp(tViewItem0); - if (!supportScrollBar) - { - UpdateContentSize(); - CheckIfNeedUpdateItemPos(); - } - - return true; - } - - LoopListViewItem tViewItem1 = _itemList[_itemList.Count - 1]; - tViewItem1.CachedRectTransform.GetWorldCorners(_itemWorldCorners); - Vector3 topPos1 = _viewPortRectTransform.InverseTransformPoint(_itemWorldCorners[1]); - Vector3 downPos1 = _viewPortRectTransform.InverseTransformPoint(_itemWorldCorners[0]); - if (!_isDraging && tViewItem1.ItemCreatedCheckFrameCount != _listUpdateCheckFrameCount - && downPos1.y - _viewPortRectLocalCorners[1].y > distanceForRecycle1) - { - _itemList.RemoveAt(_itemList.Count - 1); - RecycleItemTmp(tViewItem1); - if (!supportScrollBar) - { - UpdateContentSize(); - CheckIfNeedUpdateItemPos(); - } - - return true; - } - - if (topPos1.y - _viewPortRectLocalCorners[1].y < distanceForNew1) - { - if (tViewItem1.ItemIndex > _curReadyMaxItemIndex) - { - _curReadyMaxItemIndex = tViewItem1.ItemIndex; - _needCheckNextMaxItem = true; - } - - int nIndex = tViewItem1.ItemIndex + 1; - if (nIndex <= _curReadyMaxItemIndex || _needCheckNextMaxItem) - { - LoopListViewItem newItem = GetNewItemByIndex(nIndex); - if (newItem == null) - { - _needCheckNextMaxItem = false; - CheckIfNeedUpdateItemPos(); - } - else - { - if (supportScrollBar) - { - SetItemSize(nIndex, newItem.CachedRectTransform.rect.height, newItem.Padding); - } - - _itemList.Add(newItem); - float y = tViewItem1.CachedRectTransform.localPosition.y + - tViewItem1.CachedRectTransform.rect.height + tViewItem1.Padding; - newItem.CachedRectTransform.localPosition = new Vector3(newItem.StartPosOffset, y, 0); - UpdateContentSize(); - CheckIfNeedUpdateItemPos(); - if (nIndex > _curReadyMaxItemIndex) - { - _curReadyMaxItemIndex = nIndex; - } - - return true; - } - } - } - - - if (_viewPortRectLocalCorners[0].y - downPos0.y < distanceForNew0) - { - if (tViewItem0.ItemIndex < _curReadyMinItemIndex) - { - _curReadyMinItemIndex = tViewItem0.ItemIndex; - _needCheckNextMinItem = true; - } - - int nIndex = tViewItem0.ItemIndex - 1; - if (nIndex >= _curReadyMinItemIndex || _needCheckNextMinItem) - { - LoopListViewItem newItem = GetNewItemByIndex(nIndex); - if (newItem == null) - { - _needCheckNextMinItem = false; - return false; - } - else - { - if (supportScrollBar) - { - SetItemSize(nIndex, newItem.CachedRectTransform.rect.height, newItem.Padding); - } - - _itemList.Insert(0, newItem); - float y = tViewItem0.CachedRectTransform.localPosition.y - - newItem.CachedRectTransform.rect.height - newItem.Padding; - newItem.CachedRectTransform.localPosition = new Vector3(newItem.StartPosOffset, y, 0); - UpdateContentSize(); - CheckIfNeedUpdateItemPos(); - if (nIndex < _curReadyMinItemIndex) - { - _curReadyMinItemIndex = nIndex; - } - - return true; - } - } - } - } - - return false; - } - - - bool UpdateForHorizontalList(float distanceForRecycle0, float distanceForRecycle1, float distanceForNew0, - float distanceForNew1) - { - if (_itemTotalCount == 0) - { - if (_itemList.Count > 0) - { - RecycleAllItem(); - } - - return false; - } - - if (arrangeType == ListItemArrangeType.LeftToRight) - { - if (_itemList.Count == 0) - { - float curX = _containerTrans.localPosition.x; - if (curX > 0) - { - curX = 0; - } - - int index = 0; - float pos = -curX; - if (supportScrollBar) - { - GetPlusItemIndexAndPosAtGivenPos(-curX, ref index, ref pos); - } - - LoopListViewItem newItem = GetNewItemByIndex(index); - if (newItem == null) - { - return false; - } - - if (supportScrollBar) - { - SetItemSize(index, newItem.CachedRectTransform.rect.width, newItem.Padding); - } - - _itemList.Add(newItem); - newItem.CachedRectTransform.localPosition = new Vector3(pos, newItem.StartPosOffset, 0); - UpdateContentSize(); - return true; - } - - LoopListViewItem tViewItem0 = _itemList[0]; - tViewItem0.CachedRectTransform.GetWorldCorners(_itemWorldCorners); - Vector3 leftPos0 = _viewPortRectTransform.InverseTransformPoint(_itemWorldCorners[1]); - Vector3 rightPos0 = _viewPortRectTransform.InverseTransformPoint(_itemWorldCorners[2]); - - if (!_isDraging && tViewItem0.ItemCreatedCheckFrameCount != _listUpdateCheckFrameCount - && _viewPortRectLocalCorners[1].x - rightPos0.x > distanceForRecycle0) - { - _itemList.RemoveAt(0); - RecycleItemTmp(tViewItem0); - if (!supportScrollBar) - { - UpdateContentSize(); - CheckIfNeedUpdateItemPos(); - } - - return true; - } - - LoopListViewItem tViewItem1 = _itemList[_itemList.Count - 1]; - tViewItem1.CachedRectTransform.GetWorldCorners(_itemWorldCorners); - Vector3 leftPos1 = _viewPortRectTransform.InverseTransformPoint(_itemWorldCorners[1]); - Vector3 rightPos1 = _viewPortRectTransform.InverseTransformPoint(_itemWorldCorners[2]); - if (!_isDraging && tViewItem1.ItemCreatedCheckFrameCount != _listUpdateCheckFrameCount - && leftPos1.x - _viewPortRectLocalCorners[2].x > distanceForRecycle1) - { - _itemList.RemoveAt(_itemList.Count - 1); - RecycleItemTmp(tViewItem1); - if (!supportScrollBar) - { - UpdateContentSize(); - CheckIfNeedUpdateItemPos(); - } - - return true; - } - - - if (rightPos1.x - _viewPortRectLocalCorners[2].x < distanceForNew1) - { - if (tViewItem1.ItemIndex > _curReadyMaxItemIndex) - { - _curReadyMaxItemIndex = tViewItem1.ItemIndex; - _needCheckNextMaxItem = true; - } - - int nIndex = tViewItem1.ItemIndex + 1; - if (nIndex <= _curReadyMaxItemIndex || _needCheckNextMaxItem) - { - LoopListViewItem newItem = GetNewItemByIndex(nIndex); - if (newItem == null) - { - _curReadyMaxItemIndex = tViewItem1.ItemIndex; - _needCheckNextMaxItem = false; - CheckIfNeedUpdateItemPos(); - } - else - { - if (supportScrollBar) - { - SetItemSize(nIndex, newItem.CachedRectTransform.rect.width, newItem.Padding); - } - - _itemList.Add(newItem); - float x = tViewItem1.CachedRectTransform.localPosition.x + - tViewItem1.CachedRectTransform.rect.width + tViewItem1.Padding; - newItem.CachedRectTransform.localPosition = new Vector3(x, newItem.StartPosOffset, 0); - UpdateContentSize(); - CheckIfNeedUpdateItemPos(); - - if (nIndex > _curReadyMaxItemIndex) - { - _curReadyMaxItemIndex = nIndex; - } - - return true; - } - } - } - - if (_viewPortRectLocalCorners[1].x - leftPos0.x < distanceForNew0) - { - if (tViewItem0.ItemIndex < _curReadyMinItemIndex) - { - _curReadyMinItemIndex = tViewItem0.ItemIndex; - _needCheckNextMinItem = true; - } - - int nIndex = tViewItem0.ItemIndex - 1; - if (nIndex >= _curReadyMinItemIndex || _needCheckNextMinItem) - { - LoopListViewItem newItem = GetNewItemByIndex(nIndex); - if (newItem == null) - { - _curReadyMinItemIndex = tViewItem0.ItemIndex; - _needCheckNextMinItem = false; - } - else - { - if (supportScrollBar) - { - SetItemSize(nIndex, newItem.CachedRectTransform.rect.width, newItem.Padding); - } - - _itemList.Insert(0, newItem); - float x = tViewItem0.CachedRectTransform.localPosition.x - - newItem.CachedRectTransform.rect.width - newItem.Padding; - newItem.CachedRectTransform.localPosition = new Vector3(x, newItem.StartPosOffset, 0); - UpdateContentSize(); - CheckIfNeedUpdateItemPos(); - if (nIndex < _curReadyMinItemIndex) - { - _curReadyMinItemIndex = nIndex; - } - - return true; - } - } - } - } - else - { - if (_itemList.Count == 0) - { - float curX = _containerTrans.localPosition.x; - if (curX < 0) - { - curX = 0; - } - - int index = 0; - float pos = -curX; - if (supportScrollBar) - { - GetPlusItemIndexAndPosAtGivenPos(curX, ref index, ref pos); - pos = -pos; - } - - LoopListViewItem newItem = GetNewItemByIndex(index); - if (newItem == null) - { - return false; - } - - if (supportScrollBar) - { - SetItemSize(index, newItem.CachedRectTransform.rect.width, newItem.Padding); - } - - _itemList.Add(newItem); - newItem.CachedRectTransform.localPosition = new Vector3(pos, newItem.StartPosOffset, 0); - UpdateContentSize(); - return true; - } - - LoopListViewItem tViewItem0 = _itemList[0]; - tViewItem0.CachedRectTransform.GetWorldCorners(_itemWorldCorners); - Vector3 leftPos0 = _viewPortRectTransform.InverseTransformPoint(_itemWorldCorners[1]); - Vector3 rightPos0 = _viewPortRectTransform.InverseTransformPoint(_itemWorldCorners[2]); - - if (!_isDraging && tViewItem0.ItemCreatedCheckFrameCount != _listUpdateCheckFrameCount - && leftPos0.x - _viewPortRectLocalCorners[2].x > distanceForRecycle0) - { - _itemList.RemoveAt(0); - RecycleItemTmp(tViewItem0); - if (!supportScrollBar) - { - UpdateContentSize(); - CheckIfNeedUpdateItemPos(); - } - - return true; - } - - LoopListViewItem tViewItem1 = _itemList[_itemList.Count - 1]; - tViewItem1.CachedRectTransform.GetWorldCorners(_itemWorldCorners); - Vector3 leftPos1 = _viewPortRectTransform.InverseTransformPoint(_itemWorldCorners[1]); - Vector3 rightPos1 = _viewPortRectTransform.InverseTransformPoint(_itemWorldCorners[2]); - if (!_isDraging && tViewItem1.ItemCreatedCheckFrameCount != _listUpdateCheckFrameCount - && _viewPortRectLocalCorners[1].x - rightPos1.x > distanceForRecycle1) - { - _itemList.RemoveAt(_itemList.Count - 1); - RecycleItemTmp(tViewItem1); - if (!supportScrollBar) - { - UpdateContentSize(); - CheckIfNeedUpdateItemPos(); - } - - return true; - } - - - if (_viewPortRectLocalCorners[1].x - leftPos1.x < distanceForNew1) - { - if (tViewItem1.ItemIndex > _curReadyMaxItemIndex) - { - _curReadyMaxItemIndex = tViewItem1.ItemIndex; - _needCheckNextMaxItem = true; - } - - int nIndex = tViewItem1.ItemIndex + 1; - if (nIndex <= _curReadyMaxItemIndex || _needCheckNextMaxItem) - { - LoopListViewItem newItem = GetNewItemByIndex(nIndex); - if (newItem == null) - { - _curReadyMaxItemIndex = tViewItem1.ItemIndex; - _needCheckNextMaxItem = false; - CheckIfNeedUpdateItemPos(); - } - else - { - if (supportScrollBar) - { - SetItemSize(nIndex, newItem.CachedRectTransform.rect.width, newItem.Padding); - } - - _itemList.Add(newItem); - float x = tViewItem1.CachedRectTransform.localPosition.x - - tViewItem1.CachedRectTransform.rect.width - tViewItem1.Padding; - newItem.CachedRectTransform.localPosition = new Vector3(x, newItem.StartPosOffset, 0); - UpdateContentSize(); - CheckIfNeedUpdateItemPos(); - - if (nIndex > _curReadyMaxItemIndex) - { - _curReadyMaxItemIndex = nIndex; - } - - return true; - } - } - } - - if (rightPos0.x - _viewPortRectLocalCorners[2].x < distanceForNew0) - { - if (tViewItem0.ItemIndex < _curReadyMinItemIndex) - { - _curReadyMinItemIndex = tViewItem0.ItemIndex; - _needCheckNextMinItem = true; - } - - int nIndex = tViewItem0.ItemIndex - 1; - if (nIndex >= _curReadyMinItemIndex || _needCheckNextMinItem) - { - LoopListViewItem newItem = GetNewItemByIndex(nIndex); - if (newItem == null) - { - _curReadyMinItemIndex = tViewItem0.ItemIndex; - _needCheckNextMinItem = false; - } - else - { - if (supportScrollBar) - { - SetItemSize(nIndex, newItem.CachedRectTransform.rect.width, newItem.Padding); - } - - _itemList.Insert(0, newItem); - float x = tViewItem0.CachedRectTransform.localPosition.x + - newItem.CachedRectTransform.rect.width + newItem.Padding; - newItem.CachedRectTransform.localPosition = new Vector3(x, newItem.StartPosOffset, 0); - UpdateContentSize(); - CheckIfNeedUpdateItemPos(); - if (nIndex < _curReadyMinItemIndex) - { - _curReadyMinItemIndex = nIndex; - } - - return true; - } - } - } - } - - return false; - } - - - float GetContentPanelSize() - { - if (supportScrollBar) - { - float tTotalSize = _itemPosMgr.TotalSize > 0 ? (_itemPosMgr.TotalSize - _lastItemPadding) : 0; - if (tTotalSize < 0) - { - tTotalSize = 0; - } - - return tTotalSize; - } - - int count = _itemList.Count; - if (count == 0) - { - return 0; - } - - if (count == 1) - { - return _itemList[0].ItemSize; - } - - if (count == 2) - { - return _itemList[0].ItemSizeWithPadding + _itemList[1].ItemSize; - } - - float s = 0; - for (int i = 0; i < count - 1; ++i) - { - s += _itemList[i].ItemSizeWithPadding; - } - - s += _itemList[count - 1].ItemSize; - return s; - } - - - private void CheckIfNeedUpdateItemPos() - { - int count = _itemList.Count; - if (count == 0) - { - return; - } - - if (arrangeType == ListItemArrangeType.TopToBottom) - { - LoopListViewItem firstItem = _itemList[0]; - LoopListViewItem lastItem = _itemList[^1]; - float viewMaxY = GetContentPanelSize(); - if (firstItem.TopY > 0 || (firstItem.ItemIndex == _curReadyMinItemIndex && firstItem.TopY != 0)) - { - UpdateAllShownItemsPos(); - return; - } - - if ((-lastItem.BottomY) > viewMaxY || - (lastItem.ItemIndex == _curReadyMaxItemIndex && Math.Abs(-lastItem.BottomY - viewMaxY) > 0.001f)) - { - UpdateAllShownItemsPos(); - return; - } - } - else if (arrangeType == ListItemArrangeType.BottomToTop) - { - LoopListViewItem firstItem = _itemList[0]; - LoopListViewItem lastItem = _itemList[^1]; - float viewMaxY = GetContentPanelSize(); - if (firstItem.BottomY < 0 || (firstItem.ItemIndex == _curReadyMinItemIndex && firstItem.BottomY != 0)) - { - UpdateAllShownItemsPos(); - return; - } - - if (lastItem.TopY > viewMaxY || - (lastItem.ItemIndex == _curReadyMaxItemIndex && Math.Abs(lastItem.TopY - viewMaxY) > 0.001f)) - { - UpdateAllShownItemsPos(); - return; - } - } - else if (arrangeType == ListItemArrangeType.LeftToRight) - { - LoopListViewItem firstItem = _itemList[0]; - LoopListViewItem lastItem = _itemList[^1]; - float viewMaxX = GetContentPanelSize(); - if (firstItem.LeftX < 0 || (firstItem.ItemIndex == _curReadyMinItemIndex && firstItem.LeftX != 0)) - { - UpdateAllShownItemsPos(); - return; - } - - if ((lastItem.RightX) > viewMaxX || - (lastItem.ItemIndex == _curReadyMaxItemIndex && Math.Abs(lastItem.RightX - viewMaxX) > 0.001f)) - { - UpdateAllShownItemsPos(); - return; - } - } - else if (arrangeType == ListItemArrangeType.RightToLeft) - { - LoopListViewItem firstItem = _itemList[0]; - LoopListViewItem lastItem = _itemList[^1]; - float viewMaxX = GetContentPanelSize(); - if (firstItem.RightX > 0 || (firstItem.ItemIndex == _curReadyMinItemIndex && firstItem.RightX != 0)) - { - UpdateAllShownItemsPos(); - return; - } - - if ((-lastItem.LeftX) > viewMaxX || - (lastItem.ItemIndex == _curReadyMaxItemIndex && Math.Abs((-lastItem.LeftX) - viewMaxX) > 0.001f)) - { - UpdateAllShownItemsPos(); - return; - } - } - } - - - private void UpdateAllShownItemsPos() - { - int count = _itemList.Count; - if (count == 0) - { - return; - } - - _adjustedVec = (_containerTrans.localPosition - _lastFrameContainerPos) / Time.deltaTime; - - if (arrangeType == ListItemArrangeType.TopToBottom) - { - float pos = 0; - if (supportScrollBar) - { - pos = -GetItemPos(_itemList[0].ItemIndex); - } - - float pos1 = _itemList[0].CachedRectTransform.localPosition.y; - float d = pos - pos1; - float curY = pos; - for (int i = 0; i < count; ++i) - { - LoopListViewItem item = _itemList[i]; - item.CachedRectTransform.localPosition = new Vector3(item.StartPosOffset, curY, 0); - curY = curY - item.CachedRectTransform.rect.height - item.Padding; - } - - if (d != 0) - { - Vector2 p = _containerTrans.localPosition; - p.y = p.y - d; - _containerTrans.localPosition = p; - } - } - else if (arrangeType == ListItemArrangeType.BottomToTop) - { - float pos = 0; - if (supportScrollBar) - { - pos = GetItemPos(_itemList[0].ItemIndex); - } - - float pos1 = _itemList[0].CachedRectTransform.localPosition.y; - float d = pos - pos1; - float curY = pos; - for (int i = 0; i < count; ++i) - { - LoopListViewItem item = _itemList[i]; - item.CachedRectTransform.localPosition = new Vector3(item.StartPosOffset, curY, 0); - curY = curY + item.CachedRectTransform.rect.height + item.Padding; - } - - if (d != 0) - { - Vector3 p = _containerTrans.localPosition; - p.y -= d; - _containerTrans.localPosition = p; - } - } - else if (arrangeType == ListItemArrangeType.LeftToRight) - { - float pos = 0; - if (supportScrollBar) - { - pos = GetItemPos(_itemList[0].ItemIndex); - } - - float pos1 = _itemList[0].CachedRectTransform.localPosition.x; - float d = pos - pos1; - float curX = pos; - for (int i = 0; i < count; ++i) - { - LoopListViewItem item = _itemList[i]; - item.CachedRectTransform.localPosition = new Vector3(curX, item.StartPosOffset, 0); - curX = curX + item.CachedRectTransform.rect.width + item.Padding; - } - - if (d != 0) - { - Vector3 p = _containerTrans.localPosition; - p.x -= d; - _containerTrans.localPosition = p; - } - } - else if (arrangeType == ListItemArrangeType.RightToLeft) - { - float pos = 0; - if (supportScrollBar) - { - pos = -GetItemPos(_itemList[0].ItemIndex); - } - - float pos1 = _itemList[0].CachedRectTransform.localPosition.x; - float d = pos - pos1; - float curX = pos; - for (int i = 0; i < count; ++i) - { - LoopListViewItem item = _itemList[i]; - item.CachedRectTransform.localPosition = new Vector3(curX, item.StartPosOffset, 0); - curX = curX - item.CachedRectTransform.rect.width - item.Padding; - } - - if (d != 0) - { - Vector3 p = _containerTrans.localPosition; - p.x = p.x - d; - _containerTrans.localPosition = p; - } - } - - if (_isDraging) - { - _scrollRect.OnBeginDrag(_pointerEventData); - _scrollRect.Rebuild(CanvasUpdate.PostLayout); - _scrollRect.velocity = _adjustedVec; - _needAdjustVec = true; - } - } - - private void UpdateContentSize() - { - float size = GetContentPanelSize(); - if (_isVertList) - { - if (Math.Abs(_containerTrans.rect.height - size) > 0.001f) - { - _containerTrans.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, size); - } - } - else - { - if (Math.Abs(_containerTrans.rect.width - size) > 0.001f) - { - _containerTrans.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, size); - } - } - } - - /// - /// 获取当前起始索引 - /// - /// - public int GetItemStartIndex() - { - return _itemList is { Count: > 0 } ? _itemList[0].ItemIndex : 0; - } - } -} \ No newline at end of file diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SuperScrollView/Scripts/ListView/LoopListViewItem.cs b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SuperScrollView/Scripts/ListView/LoopListViewItem.cs deleted file mode 100644 index 3673bc84..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SuperScrollView/Scripts/ListView/LoopListViewItem.cs +++ /dev/null @@ -1,216 +0,0 @@ -using UnityEngine; - -namespace GameLogic -{ - public class LoopListViewItem : MonoBehaviour - { - public float Padding; - - private int _itemIndex = -1; - private int _itemId = -1; - private LoopListView _parentListView = null; - private bool _isInitHandlerCalled = false; - private string _itemPrefabName; - private RectTransform _cachedRectTransform; - private float _padding; - private float _distanceWithViewPortSnapCenter = 0; - private int _itemCreatedCheckFrameCount = 0; - private float _startPosOffset = 0; - - private object _userObjectData = null; - private int _userIntData1 = 0; - private int _userIntData2 = 0; - private string _userStringData1 = null; - private string _userStringData2 = null; - - private int _goId = 0; - - public int GoId - { - set => _goId = value; - get => _goId; - } - - public object UserObjectData - { - get => _userObjectData; - set => _userObjectData = value; - } - - public int UserIntData1 - { - get => _userIntData1; - set => _userIntData1 = value; - } - - public int UserIntData2 - { - get => _userIntData2; - set => _userIntData2 = value; - } - - public string UserStringData1 - { - get => _userStringData1; - set => _userStringData1 = value; - } - - public string UserStringData2 - { - get => _userStringData2; - set => _userStringData2 = value; - } - - public float DistanceWithViewPortSnapCenter - { - get => _distanceWithViewPortSnapCenter; - set => _distanceWithViewPortSnapCenter = value; - } - - public float StartPosOffset - { - get => _startPosOffset; - set => _startPosOffset = value; - } - - public int ItemCreatedCheckFrameCount - { - get => _itemCreatedCheckFrameCount; - set => _itemCreatedCheckFrameCount = value; - } - - public RectTransform CachedRectTransform - { - get - { - if (_cachedRectTransform == null) - { - _cachedRectTransform = gameObject.GetComponent(); - } - - return _cachedRectTransform; - } - } - - public string ItemPrefabName - { - get => _itemPrefabName; - set => _itemPrefabName = value; - } - - public int ItemIndex - { - get => _itemIndex; - set => _itemIndex = value; - } - - public int ItemId - { - get => _itemId; - set => _itemId = value; - } - - - public bool IsInitHandlerCalled - { - get => _isInitHandlerCalled; - set => _isInitHandlerCalled = value; - } - - public LoopListView ParentListView - { - get => _parentListView; - set => _parentListView = value; - } - - public float TopY - { - get - { - ListItemArrangeType arrageType = ParentListView.ArrangeType; - if (arrageType == ListItemArrangeType.TopToBottom) - { - return CachedRectTransform.localPosition.y; - } - else if (arrageType == ListItemArrangeType.BottomToTop) - { - return CachedRectTransform.localPosition.y + CachedRectTransform.rect.height; - } - - return 0; - } - } - - public float BottomY - { - get - { - ListItemArrangeType arrageType = ParentListView.ArrangeType; - if (arrageType == ListItemArrangeType.TopToBottom) - { - return CachedRectTransform.localPosition.y - CachedRectTransform.rect.height; - } - else if (arrageType == ListItemArrangeType.BottomToTop) - { - return CachedRectTransform.localPosition.y; - } - - return 0; - } - } - - - public float LeftX - { - get - { - ListItemArrangeType arrageType = ParentListView.ArrangeType; - if (arrageType == ListItemArrangeType.LeftToRight) - { - return CachedRectTransform.localPosition.x; - } - else if (arrageType == ListItemArrangeType.RightToLeft) - { - return CachedRectTransform.localPosition.x - CachedRectTransform.rect.width; - } - - return 0; - } - } - - public float RightX - { - get - { - ListItemArrangeType arrageType = ParentListView.ArrangeType; - if (arrageType == ListItemArrangeType.LeftToRight) - { - return CachedRectTransform.localPosition.x + CachedRectTransform.rect.width; - } - else if (arrageType == ListItemArrangeType.RightToLeft) - { - return CachedRectTransform.localPosition.x; - } - - return 0; - } - } - - public float ItemSize - { - get - { - if (ParentListView.IsVertList) - { - return CachedRectTransform.rect.height; - } - else - { - return CachedRectTransform.rect.width; - } - } - } - - public float ItemSizeWithPadding => ItemSize + _padding; - } -} \ No newline at end of file diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SwitchPage.meta b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SwitchPage.meta deleted file mode 100644 index 2ced07aa..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SwitchPage.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 4f3fbd5ce2514056b72986a6dea2aec2 -timeCreated: 1695289443 \ No newline at end of file diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SwitchPage/ChildPageBase.cs b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SwitchPage/ChildPageBase.cs deleted file mode 100644 index 908d7ceb..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SwitchPage/ChildPageBase.cs +++ /dev/null @@ -1,71 +0,0 @@ -using TEngine; - -namespace GameLogic -{ - /// - /// 子界面之间共享的数据。 - /// - public class ChildPageSharData - { - private object[] m_arrParams = new object[3]; // 共享参数列表 - - public object Param1 { get { return m_arrParams[0]; } } - public object Param2 { get { return m_arrParams[1]; } } - public object Param3 { get { return m_arrParams[2]; } } - - /// - /// 设置指定索引的参数。 - /// - /// - /// - public void SetParam(int paramIdx, object param) - { - if (paramIdx >= m_arrParams.Length) - return; - - m_arrParams[paramIdx] = param; - } - } - - public class ChildPageBase : UIWidget - { - - protected ChildPageSharData m_shareObjData; // 共享数据 - - // 初始化数据 - public void InitData(ChildPageSharData shareObjData) - { - m_shareObjData = shareObjData; - } - - public virtual void OnPageShowed(int oldShowType, int newShowType) - { - - } - - // 无参数刷新当前子界面 - // 收到那些数据变动的消息的时候使用 - public virtual void RefreshPage() - { - - } - - public object ShareData1 - { - get => m_shareObjData.Param1; - set => m_shareObjData.SetParam(0, value); - } - - public object ShareData2 - { - get => m_shareObjData.Param2; - set => m_shareObjData.SetParam(1, value); - } - - public object ShareData3 - { - get => m_shareObjData.Param3; - set => m_shareObjData.SetParam(2, value); - } - } -} \ No newline at end of file diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SwitchPage/ChildPageBase.cs.meta b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SwitchPage/ChildPageBase.cs.meta deleted file mode 100644 index a00b4e15..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SwitchPage/ChildPageBase.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: e4b742d9af72478b9d6f7ebd2fa493a0 -timeCreated: 1687859782 \ No newline at end of file diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SwitchPage/SwitchPageMgr.cs b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SwitchPage/SwitchPageMgr.cs deleted file mode 100644 index 55bfb081..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SwitchPage/SwitchPageMgr.cs +++ /dev/null @@ -1,457 +0,0 @@ -using System; -using System.Collections.Generic; -using TEngine; -using UnityEngine; - -namespace GameLogic -{ - public class SwitchPageMgr - { - private event Action SwitchTabAction; - - public delegate bool SwitchTabCondition(int selectId); - - private SwitchTabCondition _switchTabCondition; - - /// - /// 页签Grid。 - /// - protected Transform m_tabGrid; - - /// - /// 子UI父节点。 - /// - public Transform ChildPageParent; - - /// - /// 存储子UI。 - /// - private readonly Dictionary> _switchPageDic = new Dictionary>(); - - /// - /// 子页签名字。 - /// - private readonly List _childPageNames = new List(); - - /// - /// 子页签字典。 - /// - private readonly Dictionary _childPageDic = new Dictionary(); - - /// - /// 存储页签。 - /// - private readonly Dictionary _tabDic = new Dictionary(); - - private readonly Dictionary _tabName = new Dictionary(); - - protected readonly List IDList = new List(); - - private readonly UIBase _owner; - - protected int CurrentChildID = -100; - - /// - /// 需要设置显示隐藏。 - /// - private readonly bool _needSetActive; - - /// - /// 子界面的共享数据。 - /// - private readonly ChildPageSharData _shareData = new ChildPageSharData(); - - public object ShareData1 => _shareData.Param1; - public object ShareData2 => _shareData.Param2; - public object ShareData3 => _shareData.Param3; - - public SwitchPageMgr(Transform grid, Transform childPageParent, UIBase owner, bool needSetActive = true) - { - m_tabGrid = grid; - ChildPageParent = childPageParent; - _owner = owner; - _needSetActive = needSetActive; - } - - public void AddSwitchAction(Action action) - { - SwitchTabAction += action; - } - - public void RemoveSwitchAction(Action action) - { - SwitchTabAction -= action; - } - - public void AddSwitchCondition(SwitchTabCondition action) - { - _switchTabCondition = action; - } - - public void BindChildPage(int childID) where T : ChildPageBase, new() - { - BindChildPage(childID, string.Empty); - } - - public void BindChildPage(int childID, string tabName) where T : ChildPageBase, new() - { - var pageName = typeof(T).Name; - - if (IDList.IndexOf(childID) < 0) - { - IDList.Add(childID); - } - - if (!_childPageDic.ContainsKey(pageName)) - { - _childPageDic[pageName] = new T(); - _childPageNames.Add(pageName); - } - - if (!_switchPageDic.ContainsKey(childID)) - { - _switchPageDic[childID] = new List(); - } - - if (_switchPageDic[childID].IndexOf(pageName) < 0) - { - _switchPageDic[childID].Add(pageName); - } - - _tabName[childID] = tabName; - } - - public T CreatTab(int initChildID, GameObject tabTemp = null) where T : SwitchTabItem, new() - { - T tab = null; - for (var index = 0; index < IDList.Count; index++) - { - var childID = IDList[index]; - if (!_tabDic.ContainsKey(childID)) - { - if (tabTemp != null) - { - tab = _owner.CreateWidgetByPrefab(tabTemp, m_tabGrid); - } - else - { - tab = _owner.CreateWidgetByType(m_tabGrid); - } - - tab.UpdateTabName(_tabName[childID]); - tab.BindClickEvent(TabOnClick, childID); - _tabDic[childID] = tab; - break; - } - } - - SwitchPage(initChildID); - return tab; - } - - public void CreatTabByItem(int initChildID, GameObject go) where T : SwitchTabItem, new() - { - if (!_tabDic.ContainsKey(initChildID)) - { - T tab = _owner.CreateWidgetByPrefab(go, m_tabGrid); - tab.UpdateTabName(_tabName[initChildID]); - tab.BindClickEvent(TabOnClick, initChildID); - _tabDic[initChildID] = tab; - } - } - - // 设置页签的自定义点击行为 - public void SetCustomTabClickAction(int tabIdx, Action clickAction, object param1 = null, - object param2 = null, object param3 = null) - { - _tabDic[tabIdx].BindClickEvent(clickAction, param1, param2, param3); - } - - public int TabCount => _tabDic.Count; - - public void SetTabRedNode(int tabId, bool isShow) - { - if (_tabDic.TryGetValue(tabId, out var value)) - { - value.SetRedNote(isShow); - } - } - - public void SetTabFontSize(int fontSize) - { - for (int i = 0; i < IDList.Count; i++) - { - var tabId = IDList[i]; - _tabDic[tabId].SetITabTextFontSize(fontSize); - } - } - - private void TabOnClick(SwitchTabItem tab) - { - var childID = (int)tab.EventParam1; - SwitchPage(childID); - } - - public virtual void SwitchPage(int selectID) - { - if (_switchTabCondition != null && !_switchTabCondition(selectID)) - { - return; - } - - if (CurrentChildID != selectID) - { - if (_switchPageDic.TryGetValue(selectID, out var pageLs)) - { - for (int i = 0; i < pageLs.Count; i++) - { - var pageName = pageLs[i]; - ChildPageBase page = GetChildPageByName(pageName); - if (page != null && page.gameObject == null) - { - page.CreateByPath(pageName, _owner, ChildPageParent); - page.InitData(_shareData); - } - } - - for (int i = 0; i < _childPageNames.Count; i++) - { - string pageName = _childPageNames[i]; - ChildPageBase page = GetChildPageByName(pageName); - bool beShow = pageLs.IndexOf(pageName) >= 0; - if (page != null && page.gameObject != null) - { - if (_needSetActive) - { - //page.Show(beShow); - if (beShow) - { - page.gameObject.SetActive(true); - // page.Visible = true; - } - else - { - page.gameObject.SetActive(false); - // page.Visible = false; - } - } - } - - // if (page != null && beShow) - if (page != null) - { - page.OnPageShowed(CurrentChildID, selectID); - } - } - } - - for (var index = 0; index < IDList.Count; index++) - { - var childID = IDList[index]; - SwitchTabItem tab; - if (_tabDic.TryGetValue(childID, out tab)) - { - tab.SetState(selectID == childID); - } - } - } - - var oldID = CurrentChildID; - CurrentChildID = selectID; - if (SwitchTabAction != null) - { - SwitchTabAction(oldID, selectID); - } - } - - public virtual void ShowPage(int selectID) - { - if (_switchPageDic.TryGetValue(selectID, out var pageLs)) - { - for (int i = 0; i < pageLs.Count; i++) - { - var pageName = pageLs[i]; - ChildPageBase page = GetChildPageByName(pageName); - if (page != null && page.gameObject == null) - { - page.CreateByPath(pageName, _owner, ChildPageParent); - page.InitData(_shareData); - } - } - - for (int i = 0; i < _childPageNames.Count; i++) - { - string pageName = _childPageNames[i]; - ChildPageBase page = GetChildPageByName(pageName); - bool beShow = pageLs.IndexOf(pageName) >= 0; - if (page != null && page.gameObject != null) - { - if (beShow) - { - page.gameObject.SetActive(true); - // page.Visible = true; - } - else - { - page.gameObject.SetActive(false); - // page.Visible = false; - } - } - } - } - - for (var index = 0; index < IDList.Count; index++) - { - var childID = IDList[index]; - SwitchTabItem tab; - if (_tabDic.TryGetValue(childID, out tab)) - { - tab.SetState(selectID == childID); - } - } - } - - public void RefreshCurrentChildPage() - { - if (_switchPageDic.TryGetValue(CurrentChildID, out var pageNames)) - { - for (int i = 0; i < pageNames.Count; i++) - { - ChildPageBase page = GetChildPageByName(pageNames[i]); - if (page != null && page.gameObject != null) - { - page.RefreshPage(); - } - } - } - } - - public void RefreshChildPage(int childID) - { - if (_switchPageDic.TryGetValue(childID, out var pageNames)) - { - for (int i = 0; i < pageNames.Count; i++) - { - ChildPageBase page = GetChildPageByName(pageNames[i]); - if (page != null && page.gameObject != null) - { - page.RefreshPage(); - } - } - } - } - - public bool TryGetChildPage(out T t) where T : ChildPageBase - { - t = GetChildPage(); - return t != null; - } - - public int GetCurShowType() - { - return CurrentChildID; - } - - public void ReductionShowType() - { - CurrentChildID = -100; - } - - #region 没有ChildPage,可通过m_switchTabAction来处理切页事件(也可以光展示用) - - public SwitchTabItem GetTabItem(int childId) - { - _tabDic.TryGetValue(childId, out var item); - return item; - } - - public void CreateJumpTab(int initChildID, string tabName, GameObject tabTemp = null) - where T : SwitchTabItem, new() - { - if (IDList.IndexOf(initChildID) < 0) - { - IDList.Add(initChildID); - } - - _tabName[initChildID] = tabName; - - for (var index = 0; index < IDList.Count; index++) - { - var childID = IDList[index]; - if (!_tabDic.ContainsKey(childID)) - { - T tab; - if (tabTemp != null) - { - tab = _owner.CreateWidgetByPrefab(tabTemp, m_tabGrid); - } - else - { - tab = _owner.CreateWidgetByType(m_tabGrid); - } - - tab.UpdateTabName(_tabName[childID]); - tab.BindClickEvent(TabOnClick, childID); - _tabDic[childID] = tab; - } - } - - SwitchPage(initChildID); - } - - #endregion - - /// - /// 设置共享参数。 - /// - /// - /// - public void SetShareParam(int paramIdx, object param) - { - _shareData.SetParam(paramIdx, param); - } - - public T GetChildPage() where T : ChildPageBase - { - var pageName = typeof(T).Name; - _childPageDic.TryGetValue(pageName, out var page); - return page as T; - } - - public ChildPageBase GetChildPageByName(string pageName) - { - _childPageDic.TryGetValue(pageName, out var page); - return page; - } - - public void BindChildPage(int childID, string tabName) - where T : ChildPageBase, new() - where U : ChildPageBase, new() - { - BindChildPage(childID, tabName); - BindChildPage(childID, tabName); - } - - public void BindChildPage(int childID, string tabName) - where T : ChildPageBase, new() - where U : ChildPageBase, new() - where V : ChildPageBase, new() - { - BindChildPage(childID, tabName); - BindChildPage(childID, tabName); - BindChildPage(childID, tabName); - } - - public void BindChildPage(int childID, string tabName) - where T : ChildPageBase, new() - where U : ChildPageBase, new() - where V : ChildPageBase, new() - where W : ChildPageBase, new() - { - BindChildPage(childID, tabName); - BindChildPage(childID, tabName); - BindChildPage(childID, tabName); - BindChildPage(childID, tabName); - } - } -} \ No newline at end of file diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SwitchPage/SwitchPageMgr.cs.meta b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SwitchPage/SwitchPageMgr.cs.meta deleted file mode 100644 index 68ad7b37..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SwitchPage/SwitchPageMgr.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: e04155ae1ce3448587a5e322477d0076 -timeCreated: 1687859725 \ No newline at end of file diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SwitchPage/SwitchTabItem.cs b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SwitchPage/SwitchTabItem.cs deleted file mode 100644 index e9c4e186..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SwitchPage/SwitchTabItem.cs +++ /dev/null @@ -1,263 +0,0 @@ -using System; -using TMPro; -using UnityEngine; -using UnityEngine.UI; - -namespace GameLogic -{ - public class SwitchTabItem : UIEventItem - { - //选中时的文本 - protected TextMeshProUGUI m_selectText; - //未选中时的文本 - protected TextMeshProUGUI m_noSelectText; - //选中时的图片 - protected Image m_selectImage; - //未选中时的图片 - protected Image m_noSelectImage; - //选中时的节点 - protected Transform m_selectNode; - //未选中时的节点 - protected Transform m_noSelectNode; - - //选中时的Icon - protected Image m_selectIcon; - //未选中时的Icon - protected Image m_noSelectIcon; - - protected GameObject m_goRedNote; - - //是否选中 - public bool IsSelect - { - get { return m_isSelect; } - set { SetState(value); } - } - - protected bool m_isSelect = false; - - //private RedNoteBehaviour m_redNote; - public RedNoteWidget m_redNote { get; private set; } - - public virtual Vector2 SelectRedPointPos - { - get - { - return Vector2.zero; - } - } - - public virtual Vector2 NoSelectRedPointPos - { - get - { - return Vector2.zero; - } - } - - protected override void BindMemberProperty() - { - m_selectNode = FindChild("SelectNode"); - m_noSelectNode = FindChild("NoSelectNode"); - if (m_selectNode != null) - { - m_selectText = FindChildComponent(m_selectNode, "SelectText"); - m_selectImage = FindChildComponent(m_selectNode, "SelectImage"); - m_selectIcon = FindChildComponent(m_selectNode, "SelectIcon"); - } - if (m_noSelectNode != null) - { - m_noSelectText = FindChildComponent(m_noSelectNode, "NoSelectText"); - m_noSelectImage = FindChildComponent(m_noSelectNode, "NoSelectImage"); - m_noSelectIcon = FindChildComponent(m_noSelectNode, "NoSelectIcon"); - } - - var tf = FindChild("m_goRedNote"); - if (tf != null) - { - m_goRedNote = tf.gameObject; - m_redNote = CreateWidgetByType(tf); - m_redNote.rectTransform.anchoredPosition = Vector2.zero; - SetRedNote(false); - //CreateDefaultRedNote(); - } - } - - #region 红点相关 - public void SetRedNoteType(RedNoteNotify type) - { - if (m_redNote != null) - { - m_redNote.m_redNote.SetNotifyType(type); - } - SetRedNote(true); - } - - public void SetRedNoteType(RedNoteNotify type, ulong param1) - { - if (m_redNote != null) - { - m_redNote.m_redNote.SetNotifyType(type, param1); - } - SetRedNote(true); - } - - public void SetRedNoteType(RedNoteNotify type, ulong param1, ulong param2) - { - if (m_redNote != null) - { - m_redNote.m_redNote.SetNotifyType(type, param1, param2); - } - SetRedNote(true); - } - - public void SetRedNoteType(RedNoteNotify type, ulong param1, ulong param2, ulong param3) - { - if (m_redNote != null) - { - m_redNote.m_redNote.SetNotifyType(type, param1, param2, param3); - } - SetRedNote(true); - } - - public void SetRedNoteState(bool state) - { - if (m_redNote != null) - { - m_redNote.m_redNote.SetRedNoteState(state); - } - SetRedNote(state); - } - - #endregion - - public void UpdateTabName(string tabName) - { - if (m_selectText != null) - { - m_selectText.text = tabName; - m_selectText.rectTransform.sizeDelta = new Vector2(m_selectText.preferredWidth, m_selectText.rectTransform.sizeDelta.y); - } - if (m_noSelectText != null) - { - m_noSelectText.text = tabName; - m_noSelectText.rectTransform.sizeDelta = new Vector2(m_noSelectText.preferredWidth, m_noSelectText - .rectTransform.sizeDelta.y); - } - } - - // public void UpdateTabImage(string selectImageName,string noSelectImageName) - // { - // if (m_selectImage != null) - // { - // UISpriteHelper.Instance.SetSprite(m_selectImage, selectImageName); - // } - // if (m_noSelectImage != null) - // { - // UISpriteHelper.Instance.SetSprite(m_noSelectImage, noSelectImageName); - // } - // } - // - // public void UpdateIcon(string selectIconName, string noSelectIconName) - // { - // if (m_selectIcon != null) - // { - // DUISpriteHelper.Instance.SetSprite(m_selectIcon, selectIconName, true); - // } - // if (m_noSelectIcon != null) - // { - // DUISpriteHelper.Instance.SetSprite(m_noSelectIcon, noSelectIconName, true); - // } - // } - // - // public virtual void CreateDefaultRedNote() - // { - // if (m_goRedNote != null) - // { - // UIEffectHelper.CreateUIEffectGoById((uint)CommonEffectID.EffectRedPoint, m_goRedNote.transform); - // } - // } - - public void SetRedNote(bool show) - { - if (m_goRedNote != null) - { - m_goRedNote.SetActive(show); - } - } - - public virtual void SetState(bool select) - { - m_isSelect = select; - if (m_selectNode != null) - { - m_selectNode.gameObject.SetActive(select); - } - if (m_noSelectNode != null) - { - m_noSelectNode.gameObject.SetActive(!select); - } - - if (m_goRedNote != null) - { - if (select) - { - if (SelectRedPointPos != Vector2.zero) - { - ((RectTransform)m_goRedNote.transform).anchoredPosition = SelectRedPointPos; - } - } - else - { - if (NoSelectRedPointPos != Vector2.zero) - { - ((RectTransform)m_goRedNote.transform).anchoredPosition = NoSelectRedPointPos; - } - } - } - } - - public void SetITabTextFontSize(int fontSize) - { - if (m_selectText != null) - { - m_selectText.fontSize = fontSize; - } - if (m_noSelectText != null) - { - m_noSelectText.fontSize = fontSize; - } - } - - #region UI-ID - /// - /// UI-ID - /// - public uint uiID; - - /// - /// UI标识 - /// - protected string m_uiFlag; - - /// - /// 检查方法 - /// - protected Func m_funcCheck; - - /// - /// 页签索引 - /// - public int tabIndex = -1; - - /// - /// UI标识 - /// - /// - public virtual string GetUiFlag() - { - return string.IsNullOrEmpty(m_uiFlag) ? uiID.ToString() : m_uiFlag; - } - #endregion - } -} \ No newline at end of file diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SwitchPage/SwitchTabItem.cs.meta b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SwitchPage/SwitchTabItem.cs.meta deleted file mode 100644 index aa178081..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/SwitchPage/SwitchTabItem.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 498417b8785d47249da952f77d069c33 -timeCreated: 1687667780 \ No newline at end of file diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/UGUIExtension.meta b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/UGUIExtension.meta deleted file mode 100644 index 7fa672ef..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/UGUIExtension.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: b50cf85b0f0d4e43b12cb694f6c07979 -timeCreated: 1695289335 \ No newline at end of file diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/UGUIExtension/EmptyGraph.cs b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/UGUIExtension/EmptyGraph.cs deleted file mode 100644 index 32ff9e2f..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/UGUIExtension/EmptyGraph.cs +++ /dev/null @@ -1,18 +0,0 @@ -using UnityEngine.UI; - -public class EmptyGraph : Graphic -{ - public bool m_debug = false; - - protected override void OnPopulateMesh(VertexHelper vbo) - { - vbo.Clear(); - -#if UNITY_EDITOR - if (m_debug) - { - base.OnPopulateMesh(vbo); - } -#endif - } -} \ No newline at end of file diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/UGUIExtension/EmptyGraph.cs.meta b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/UGUIExtension/EmptyGraph.cs.meta deleted file mode 100644 index fb4b1abc..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/UGUIExtension/EmptyGraph.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 21df3dfa358b498e8da3d169d736df58 -timeCreated: 1695289370 \ No newline at end of file diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/UGUIExtension/TScrollRect.cs b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/UGUIExtension/TScrollRect.cs deleted file mode 100644 index e98ae933..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/UGUIExtension/TScrollRect.cs +++ /dev/null @@ -1,138 +0,0 @@ -using System; -using System.Collections.Generic; -using UnityEngine; -using UnityEngine.EventSystems; -using UnityEngine.UI; - -namespace GameLogic -{ - [AddComponentMenu("UI/TScrollRect Rect", 37)] - [SelectionBase] - [ExecuteAlways] - [DisallowMultipleComponent] - [RequireComponent(typeof (RectTransform))] - public class TScrollRect : ScrollRect - { - private event Action ActionBeginDrag; - private event Action ActionOnDrag; - private event Action ActionEndDrag; - - public List parentScrollRectList; - - protected override void Awake() - { - base.Awake(); - if (parentScrollRectList != null && parentScrollRectList.Count > 0) - { - for (int i = 0; i < parentScrollRectList.Count; i++) - { - AddParentScrollRect(parentScrollRectList[i]); - } - } - } - - private List m_listParentScrollRect; - - public void AddParentScrollRect(ScrollRect parentScrollRect) - { - if (parentScrollRect == null) - { - return; - } - - if (m_listParentScrollRect == null) - { - m_listParentScrollRect = new List(); - } - - if (!m_listParentScrollRect.Contains(parentScrollRect)) - { - m_listParentScrollRect.Add(parentScrollRect); - } - } - - public void AddBeginDragListener(Action action) - { - ActionBeginDrag += action; - } - - public void RemoveBeginDragListener(Action action) - { - ActionBeginDrag -= action; - } - - public void AddOnDragListener(Action action) - { - ActionOnDrag += action; - } - - public void RemoveOnDragListener(Action action) - { - ActionOnDrag -= action; - } - - public void AddEndDragListener(Action action) - { - ActionEndDrag += action; - } - - public void RemoveEndDragListener(Action action) - { - ActionEndDrag -= action; - } - - public override void OnBeginDrag(PointerEventData eventData) - { - base.OnBeginDrag(eventData); - if (ActionBeginDrag != null) - { - ActionBeginDrag(); - } - - if (m_listParentScrollRect != null) - { - for (int i = 0; i < m_listParentScrollRect.Count; i++) - { - var parentScrollRect = m_listParentScrollRect[i]; - parentScrollRect.OnBeginDrag(eventData); - } - } - } - - public override void OnDrag(PointerEventData eventData) - { - base.OnDrag(eventData); - if (ActionOnDrag != null) - { - ActionOnDrag(); - } - - if (m_listParentScrollRect != null) - { - for (int i = 0; i < m_listParentScrollRect.Count; i++) - { - var parentScrollRect = m_listParentScrollRect[i]; - parentScrollRect.OnDrag(eventData); - } - } - } - - public override void OnEndDrag(PointerEventData eventData) - { - base.OnEndDrag(eventData); - if (ActionEndDrag != null) - { - ActionEndDrag(); - } - - if (m_listParentScrollRect != null) - { - for (int i = 0; i < m_listParentScrollRect.Count; i++) - { - var parentScrollRect = m_listParentScrollRect[i]; - parentScrollRect.OnEndDrag(eventData); - } - } - } - } -} \ No newline at end of file diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/UGUIExtension/TScrollRect.cs.meta b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/UGUIExtension/TScrollRect.cs.meta deleted file mode 100644 index b5bc63ff..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/UGUIExtension/TScrollRect.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: d322e77e03014f65a9ec277d50bd12f8 -timeCreated: 1695289370 \ No newline at end of file diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/UGUIExtension/UIButtonSound.cs b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/UGUIExtension/UIButtonSound.cs deleted file mode 100644 index 9a093470..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/UGUIExtension/UIButtonSound.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace GameLogic -{ - public class UIButtonSound : MonoBehaviour, IPointerClickHandler - { - private static Action _playSoundAction = null; - - public int clickSound = 2; - - public void OnPointerClick(PointerEventData eventData) - { - if (_playSoundAction != null) - { - _playSoundAction(clickSound); - } - } - - public static void AddPlaySoundAction(Action onClick) - { - _playSoundAction += onClick; - } - } -} \ No newline at end of file diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/UGUIExtension/UIButtonSound.cs.meta b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/UGUIExtension/UIButtonSound.cs.meta deleted file mode 100644 index b779f448..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/UGUIExtension/UIButtonSound.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: bb272eb1eec94625884e6e83889daa9a -timeCreated: 1695289370 \ No newline at end of file diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/UIEventItem.cs b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/UIEventItem.cs deleted file mode 100644 index 50ad3989..00000000 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/UIEventItem.cs +++ /dev/null @@ -1,226 +0,0 @@ -using System; -using TEngine; -using UnityEngine.EventSystems; -using UnityEngine.UI; - -namespace GameLogic -{ - public class UIEventItem : UIWidget where T : UIEventItem - { - private object m_eventParam1; - private object m_eventParam2; - private object m_eventParam3; - public object EventParam1 => m_eventParam1; - - public object EventParam2 => m_eventParam2; - - public object EventParam3 => m_eventParam3; - private Action m_clickAction; - private Action m_pressAction; - private Action m_beginDragAction; - private Action m_dragAction; - private Action m_endDragAction; - - public void BindClickEvent(Action clickAction, object eParam1 = null, object eParam2 = null, object eParam3 = null, - Selectable.Transition transition = Selectable.Transition.ColorTint) - { - if (m_clickAction != null) - { - m_clickAction = clickAction; - } - else - { - m_clickAction = clickAction; - var button = gameObject.GetOrAddComponent