diff --git a/Packages/src/Runtime/Internal/Extensions/ComponentExtensions.cs b/Packages/src/Runtime/Internal/Extensions/ComponentExtensions.cs index 9a2b1f8..b13d8b4 100644 --- a/Packages/src/Runtime/Internal/Extensions/ComponentExtensions.cs +++ b/Packages/src/Runtime/Internal/Extensions/ComponentExtensions.cs @@ -38,7 +38,7 @@ namespace Coffee.UIEffectInternal private static void GetComponentsInChildren_Internal(this Component self, List results, int depth) where T : Component { - if (!self || results == null || depth < 0) return; + if (self == null || results == null || depth < 0) return; var tr = self.transform; if (tr.TryGetComponent(out var t)) @@ -59,7 +59,7 @@ namespace Coffee.UIEffectInternal /// public static T GetOrAddComponent(this Component self) where T : Component { - if (!self) return null; + if (self == null) return null; return self.TryGetComponent(out var component) ? component : self.gameObject.AddComponent(); @@ -166,7 +166,7 @@ namespace Coffee.UIEffectInternal #if !UNITY_2021_2_OR_NEWER && !UNITY_2020_3_45 && !UNITY_2020_3_46 && !UNITY_2020_3_47 && !UNITY_2020_3_48 public static T GetComponentInParent(this Component self, bool includeInactive) where T : Component { - if (!self) return null; + if (self == null) return null; if (!includeInactive) return self.GetComponentInParent(); var current = self.transform; @@ -186,7 +186,7 @@ namespace Coffee.UIEffectInternal /// internal static bool CanConvertTo(this Object context) where T : MonoBehaviour { - return context && context.GetType() != typeof(T); + return context != null && context.GetType() != typeof(T); } /// diff --git a/Packages/src/Runtime/Internal/ProjectSettings/PreloadedProjectSettings.cs b/Packages/src/Runtime/Internal/ProjectSettings/PreloadedProjectSettings.cs index c38a483..94b2fe9 100644 --- a/Packages/src/Runtime/Internal/ProjectSettings/PreloadedProjectSettings.cs +++ b/Packages/src/Runtime/Internal/ProjectSettings/PreloadedProjectSettings.cs @@ -37,7 +37,7 @@ namespace Coffee.UIEffectInternal foreach (var t in TypeCache.GetTypesDerivedFrom(typeof(PreloadedProjectSettings<>))) { var defaultSettings = GetDefaultSettings(t); - if (!defaultSettings) + if (defaultSettings == null) { // When create a new instance, automatically set it as default settings. defaultSettings = CreateInstance(t) as PreloadedProjectSettings; @@ -48,7 +48,7 @@ namespace Coffee.UIEffectInternal SetDefaultSettings(defaultSettings); } - if (defaultSettings) + if (defaultSettings != null) { defaultSettings.OnInitialize(); } @@ -66,7 +66,7 @@ namespace Coffee.UIEffectInternal private static Object[] GetPreloadedSettings(Type type) { return PlayerSettings.GetPreloadedAssets() - .Where(x => x && x.GetType() == type) + .Where(x => x != null && x.GetType() == type) .ToArray(); } @@ -76,12 +76,12 @@ namespace Coffee.UIEffectInternal ?? AssetDatabase.FindAssets($"t:{nameof(PreloadedProjectSettings)}") .Select(AssetDatabase.GUIDToAssetPath) .Select(AssetDatabase.LoadAssetAtPath) - .FirstOrDefault(x => x && x.GetType() == type); + .FirstOrDefault(x => x != null && x.GetType() == type); } protected static void SetDefaultSettings(PreloadedProjectSettings asset) { - if (!asset) return; + if (asset == null) return; var type = asset.GetType(); if (string.IsNullOrEmpty(AssetDatabase.GetAssetPath(asset))) @@ -103,7 +103,7 @@ namespace Coffee.UIEffectInternal var preloadedAssets = PlayerSettings.GetPreloadedAssets(); var projectSettings = GetPreloadedSettings(type); PlayerSettings.SetPreloadedAssets(preloadedAssets - .Where(x => x) + .Where(x => x != null) .Except(projectSettings.Except(new[] { asset })) .Append(asset) .Distinct() @@ -133,19 +133,19 @@ namespace Coffee.UIEffectInternal #if UNITY_EDITOR private string _jsonText; - public static bool hasInstance => s_Instance; + public static bool hasInstance => s_Instance != null; public static T instance { get { - if (s_Instance) return s_Instance; + if (s_Instance != null) return s_Instance; s_Instance = GetDefaultSettings(typeof(T)) as T; - if (s_Instance) return s_Instance; + if (s_Instance != null) return s_Instance; s_Instance = CreateInstance(); - if (!s_Instance) + if (s_Instance == null) { s_Instance = null; return s_Instance; @@ -176,7 +176,7 @@ namespace Coffee.UIEffectInternal } } #else - public static T instance => s_Instance ? s_Instance : s_Instance = CreateInstance(); + public static T instance => s_Instance != null ? s_Instance : s_Instance = CreateInstance(); #endif /// @@ -185,7 +185,7 @@ namespace Coffee.UIEffectInternal protected virtual void OnEnable() { #if UNITY_EDITOR - var isDefaultSettings = !s_Instance || s_Instance == this || GetDefaultSettings(typeof(T)) == this; + var isDefaultSettings = s_Instance == null || s_Instance == this || GetDefaultSettings(typeof(T)) == this; if (!isDefaultSettings) { DestroyImmediate(this, true); @@ -195,7 +195,7 @@ namespace Coffee.UIEffectInternal EditorApplication.playModeStateChanged += OnPlayModeStateChanged; #endif - if (s_Instance) return; + if (s_Instance != null) return; s_Instance = this as T; } @@ -224,7 +224,7 @@ namespace Coffee.UIEffectInternal public override void OnGUI(string searchContext) { - if (!_target) + if (_target == null) { if (_editor) { diff --git a/Packages/src/Runtime/Internal/Utilities/Logging.cs b/Packages/src/Runtime/Internal/Utilities/Logger.cs similarity index 95% rename from Packages/src/Runtime/Internal/Utilities/Logging.cs rename to Packages/src/Runtime/Internal/Utilities/Logger.cs index 6730b5a..4bd9fed 100644 --- a/Packages/src/Runtime/Internal/Utilities/Logging.cs +++ b/Packages/src/Runtime/Internal/Utilities/Logger.cs @@ -11,7 +11,7 @@ using Conditional = System.Diagnostics.ConditionalAttribute; namespace Coffee.UIEffectInternal { - internal static class Logging + internal static class Logger { #if !ENABLE_COFFEE_LOGGER private const string k_DisableSymbol = "DISABLE_COFFEE_LOGGER"; @@ -48,7 +48,7 @@ namespace Coffee.UIEffectInternal public static void LogIf(bool enable, object tag, object message, Object context = null) { if (!enable) return; - Log_Internal(LogType.Log, tag, message, context ? context : tag as Object); + Log_Internal(LogType.Log, tag, message, context != null ? context : tag as Object); } #if !ENABLE_COFFEE_LOGGER @@ -56,7 +56,7 @@ namespace Coffee.UIEffectInternal #endif public static void Log(object tag, object message, Object context = null) { - Log_Internal(LogType.Log, tag, message, context ? context : tag as Object); + Log_Internal(LogType.Log, tag, message, context != null ? context : tag as Object); } #if !ENABLE_COFFEE_LOGGER @@ -64,13 +64,13 @@ namespace Coffee.UIEffectInternal #endif public static void LogWarning(object tag, object message, Object context = null) { - Log_Internal(LogType.Warning, tag, message, context ? context : tag as Object); + Log_Internal(LogType.Warning, tag, message, context != null ? context : tag as Object); } public static void LogError(object tag, object message, Object context = null) { #if ENABLE_COFFEE_LOGGER - Log_Internal(LogType.Error, tag, message, context ? context : tag as Object); + Log_Internal(LogType.Error, tag, message, context != null ? context : tag as Object); #else Debug.LogError($"{tag}: {message}", context); #endif diff --git a/Packages/src/Runtime/Internal/Utilities/Logger.cs.meta b/Packages/src/Runtime/Internal/Utilities/Logger.cs.meta new file mode 100644 index 0000000..6d91ea0 --- /dev/null +++ b/Packages/src/Runtime/Internal/Utilities/Logger.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: a2fa34e76bcd14489a1af18b393c3e65 \ No newline at end of file diff --git a/Packages/src/Runtime/Internal/Utilities/Logging.cs.meta b/Packages/src/Runtime/Internal/Utilities/Logging.cs.meta deleted file mode 100644 index af9c6da..0000000 --- a/Packages/src/Runtime/Internal/Utilities/Logging.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 7f0dee01a862040a58ac6b6057944cd3 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/src/Runtime/Internal/Utilities/Misc.cs b/Packages/src/Runtime/Internal/Utilities/Misc.cs index 2412588..543a9e5 100644 --- a/Packages/src/Runtime/Internal/Utilities/Misc.cs +++ b/Packages/src/Runtime/Internal/Utilities/Misc.cs @@ -31,7 +31,7 @@ namespace Coffee.UIEffectInternal public static void Destroy(Object obj) { - if (!obj) return; + if (obj == null) return; #if UNITY_EDITOR if (!Application.isPlaying) { @@ -46,7 +46,7 @@ namespace Coffee.UIEffectInternal public static void DestroyImmediate(Object obj) { - if (!obj) return; + if (obj == null) return; #if UNITY_EDITOR if (Application.isEditor) { @@ -63,7 +63,7 @@ namespace Coffee.UIEffectInternal public static void SetDirty(Object obj) { #if UNITY_EDITOR - if (!obj) return; + if (obj == null) return; EditorUtility.SetDirty(obj); #endif } @@ -119,11 +119,11 @@ namespace Coffee.UIEffectInternal foreach (var type in types) { var script = scripts.FirstOrDefault(x => x.GetClass() == type); - if (!script) continue; + if (script == null) continue; var path = type.GetCustomAttribute()?._path; var icon = AssetDatabase.LoadAssetAtPath(path); - if (!icon) continue; + if (icon == null) continue; s_SetIconForObject(script, icon); } diff --git a/Packages/src/Runtime/Internal/Utilities/ObjectPool.cs b/Packages/src/Runtime/Internal/Utilities/ObjectPool.cs index a203df2..04316a9 100644 --- a/Packages/src/Runtime/Internal/Utilities/ObjectPool.cs +++ b/Packages/src/Runtime/Internal/Utilities/ObjectPool.cs @@ -6,7 +6,7 @@ namespace Coffee.UIEffectInternal /// /// Object pool. /// - internal sealed class InternalObjectPool where T : class + internal class InternalObjectPool where T : class { #if UNITY_2021_1_OR_NEWER private readonly Predicate _onValid; // Delegate for checking if instances are valid @@ -34,7 +34,7 @@ namespace Coffee.UIEffectInternal } // If there are no instances in the pool, create a new one. - Logging.Log(this, $"A new instance is created (pooled: {_pool.CountInactive}, created: {_pool.CountAll})."); + Logger.Log(this, $"A new instance is created (pooled: {_pool.CountInactive}, created: {_pool.CountAll})."); return _pool.Get(); } @@ -47,7 +47,7 @@ namespace Coffee.UIEffectInternal if (instance == null) return; // Ignore if already pooled or null. _pool.Release(instance); - Logging.Log(this, $"An instance is released (pooled: {_pool.CountInactive}, created: {_pool.CountAll})."); + Logger.Log(this, $"An instance is released (pooled: {_pool.CountInactive}, created: {_pool.CountAll})."); instance = default; // Set the reference to null. } #else @@ -80,7 +80,7 @@ namespace Coffee.UIEffectInternal } // If there are no instances in the pool, create a new one. - Logging.Log(this, $"A new instance is created (pooled: {_pool.Count}, created: {++_count})."); + Logger.Log(this, $"A new instance is created (pooled: {_pool.Count}, created: {++_count})."); return _onCreate(); } @@ -94,7 +94,7 @@ namespace Coffee.UIEffectInternal _onReturn(instance); // Return the instance to the pool. _pool.Push(instance); - Logging.Log(this, $"An instance is released (pooled: {_pool.Count}, created: {_count})."); + Logger.Log(this, $"An instance is released (pooled: {_pool.Count}, created: {_count})."); instance = default; // Set the reference to null. } #endif diff --git a/Packages/src/Runtime/Internal/Utilities/ObjectRepository.cs b/Packages/src/Runtime/Internal/Utilities/ObjectRepository.cs index e00e0f8..cd6ee57 100644 --- a/Packages/src/Runtime/Internal/Utilities/ObjectRepository.cs +++ b/Packages/src/Runtime/Internal/Utilities/ObjectRepository.cs @@ -90,7 +90,7 @@ namespace Coffee.UIEffectInternal Profiler.BeginSample("(COF)[ObjectRepository] GetFromCache"); if (_cache.TryGetValue(hash, out var entry)) { - if (!entry.storedObject) + if (entry.storedObject == null) { Release(ref entry.storedObject); Profiler.EndSample(); @@ -103,7 +103,7 @@ namespace Coffee.UIEffectInternal Release(ref obj); ++entry.reference; obj = entry.storedObject; - Logging.Log(_name, $"Get(total#{count}): {entry}"); + Logger.Log(_name, $"Get(total#{count}): {entry}"); } Profiler.EndSample(); @@ -116,7 +116,7 @@ namespace Coffee.UIEffectInternal private void Add(Hash128 hash, ref T obj, T newObject) { - if (!newObject) + if (newObject == null) { Release(ref obj); obj = newObject; @@ -131,7 +131,7 @@ namespace Coffee.UIEffectInternal newEntry.reference = 1; _cache[hash] = newEntry; _objectKey[newObject.GetHashCode()] = hash; - Logging.Log(_name, $"Add(total#{count}): {newEntry}"); + Logger.Log(_name, $"Add(total#{count}): {newEntry}"); Release(ref obj); obj = newObject; Profiler.EndSample(); @@ -151,18 +151,18 @@ namespace Coffee.UIEffectInternal && _cache.TryGetValue(hash, out var entry)) { entry.reference--; - if (entry.reference <= 0 || !entry.storedObject) + if (entry.reference <= 0 || entry.storedObject == null) { Remove(entry); } else { - Logging.Log(_name, $"Release(total#{_cache.Count}): {entry}"); + Logger.Log(_name, $"Release(total#{_cache.Count}): {entry}"); } } else { - Logging.Log(_name, $"Release(total#{_cache.Count}): Already released: {obj}"); + Logger.Log(_name, $"Release(total#{_cache.Count}): Already released: {obj}"); } obj = null; @@ -178,7 +178,7 @@ namespace Coffee.UIEffectInternal _objectKey.Remove(entry.storedObject.GetHashCode()); _pool.Push(entry); entry.reference = 0; - Logging.Log(_name, $"Remove(total#{_cache.Count}): {entry}"); + Logger.Log(_name, $"Remove(total#{_cache.Count}): {entry}"); entry.Release(_onRelease); Profiler.EndSample(); } @@ -192,7 +192,7 @@ namespace Coffee.UIEffectInternal public void Release(Action onRelease) { reference = 0; - if (storedObject) + if (storedObject != null) { onRelease?.Invoke(storedObject); } diff --git a/Packages/src/Runtime/Internal/Utilities/ShaderVariantRegistry.cs b/Packages/src/Runtime/Internal/Utilities/ShaderVariantRegistry.cs index 518425d..0253238 100644 --- a/Packages/src/Runtime/Internal/Utilities/ShaderVariantRegistry.cs +++ b/Packages/src/Runtime/Internal/Utilities/ShaderVariantRegistry.cs @@ -270,7 +270,7 @@ namespace Coffee.UIEffectInternal _sb.Length--; // Remove last space. } - var hash = new Hash128((uint)shader.GetHashCode(), (uint)GetContentsHash(_sb), 0, 0); + var hash = new Hash128((uint)shader.GetHashCode(), (uint)GetContentsHashCode(_sb), 0, 0); if (_cachedVariants.TryGetValue(hash, out var result)) { Profiler.EndSample(); @@ -289,7 +289,7 @@ namespace Coffee.UIEffectInternal return (variant, pair); } - private static int GetContentsHash(StringBuilder sb) + private static int GetContentsHashCode(StringBuilder sb) { var hash = 17; for (var i = 0; i < sb.Length; i++) diff --git a/Packages/src/Runtime/Internal/Utilities/UIExtraCallbacks.cs b/Packages/src/Runtime/Internal/Utilities/UIExtraCallbacks.cs index 7dabb33..0dd9ac6 100755 --- a/Packages/src/Runtime/Internal/Utilities/UIExtraCallbacks.cs +++ b/Packages/src/Runtime/Internal/Utilities/UIExtraCallbacks.cs @@ -1,8 +1,8 @@ using System; +using System.Reflection; using UnityEditor; using UnityEngine; using UnityEngine.UI; -using System.Reflection; namespace Coffee.UIEffectInternal { @@ -21,7 +21,7 @@ namespace Coffee.UIEffectInternal static UIExtraCallbacks() { Canvas.willRenderCanvases += OnBeforeCanvasRebuild; - Logging.LogMulticast(typeof(Canvas), "willRenderCanvases", message: "ctor"); + Logger.LogMulticast(typeof(Canvas), "willRenderCanvases", message: "ctor"); } /// @@ -78,7 +78,7 @@ namespace Coffee.UIEffectInternal #endif Canvas.willRenderCanvases -= OnAfterCanvasRebuild; Canvas.willRenderCanvases += OnAfterCanvasRebuild; - Logging.LogMulticast(typeof(Canvas), "willRenderCanvases", + Logger.LogMulticast(typeof(Canvas), "willRenderCanvases", message: "InitializeAfterCanvasRebuild"); }