diff --git a/Packages/src/Runtime/Internal/Utilities/Misc.cs b/Packages/src/Runtime/Internal/Utilities/Misc.cs index 7b3f0ba..2412588 100644 --- a/Packages/src/Runtime/Internal/Utilities/Misc.cs +++ b/Packages/src/Runtime/Internal/Utilities/Misc.cs @@ -20,7 +20,9 @@ internal static class Misc { public static T[] FindObjectsOfType() where T : Object { -#if UNITY_2023_1_OR_NEWER +#if UNITY_6000_4_OR_NEWER + return Object.FindObjectsByType(FindObjectsInactive.Include); +#elif UNITY_2023_1_OR_NEWER return Object.FindObjectsByType(FindObjectsInactive.Include, FindObjectsSortMode.None); #else return Object.FindObjectsOfType(); diff --git a/Packages/src/Runtime/Internal/Utilities/ObjectRepository.cs b/Packages/src/Runtime/Internal/Utilities/ObjectRepository.cs index 227b4da..7fa9cce 100644 --- a/Packages/src/Runtime/Internal/Utilities/ObjectRepository.cs +++ b/Packages/src/Runtime/Internal/Utilities/ObjectRepository.cs @@ -9,7 +9,11 @@ namespace Coffee.UIEffectInternal internal class ObjectRepository where T : Object { private readonly Dictionary _cache = new Dictionary(8); +#if UNITY_6000_4_OR_NEWER + private readonly Dictionary _objectKey = new Dictionary(8); +#else private readonly Dictionary _objectKey = new Dictionary(8); +#endif private readonly string _name; private readonly Action _onRelease; private readonly Stack _pool = new Stack(8); @@ -130,7 +134,11 @@ private void Add(Hash128 hash, ref T obj, T newObject) newEntry.hash = hash; newEntry.reference = 1; _cache[hash] = newEntry; +#if UNITY_6000_4_OR_NEWER + _objectKey[newObject.GetEntityId()] = hash; +#else _objectKey[newObject.GetInstanceID()] = hash; +#endif Logging.Log(_name, $"Add(total#{count}): {newEntry}"); Release(ref obj); obj = newObject; @@ -146,7 +154,11 @@ public void Release(ref T obj) // Find and release the entry. Profiler.BeginSample("(COF)[ObjectRepository] Release"); +#if UNITY_6000_4_OR_NEWER + var id = obj.GetEntityId(); +#else var id = obj.GetInstanceID(); +#endif if (_objectKey.TryGetValue(id, out var hash) && _cache.TryGetValue(hash, out var entry)) { @@ -175,7 +187,11 @@ private void Remove(Entry entry) Profiler.BeginSample("(COF)[ObjectRepository] Remove"); _cache.Remove(entry.hash); +#if UNITY_6000_4_OR_NEWER + _objectKey.Remove(entry.storedObject.GetEntityId()); +#else _objectKey.Remove(entry.storedObject.GetInstanceID()); +#endif _pool.Push(entry); entry.reference = 0; Logging.Log(_name, $"Remove(total#{_cache.Count}): {entry}"); diff --git a/Packages/src/Runtime/Internal/Utilities/ShaderVariantRegistry.cs b/Packages/src/Runtime/Internal/Utilities/ShaderVariantRegistry.cs index 7408934..04ded3f 100644 --- a/Packages/src/Runtime/Internal/Utilities/ShaderVariantRegistry.cs +++ b/Packages/src/Runtime/Internal/Utilities/ShaderVariantRegistry.cs @@ -44,7 +44,11 @@ public override int GetHashCode() } } +#if UNITY_6000_4_OR_NEWER + private Dictionary _cachedOptionalShaders = new Dictionary(); +#else private Dictionary _cachedOptionalShaders = new Dictionary(); +#endif [SerializeField] private List m_OptionalShaders = new List(); @@ -71,7 +75,11 @@ public Shader FindOptionalShader(Shader shader, if (!shader) return null; // Already cached. +#if UNITY_6000_4_OR_NEWER + var id = shader.GetEntityId(); +#else var id = shader.GetInstanceID(); +#endif if (_cachedOptionalShaders.TryGetValue(id, out var optionalShaderName)) { return Shader.Find(optionalShaderName); @@ -270,7 +278,13 @@ internal void RegisterVariant(Material material, string path) _sb.Length--; // Remove last space. } - var hash = new Hash128((uint)shader.GetInstanceID(), (uint)GetContentsHash(_sb), 0, 0); +#if UNITY_6000_4_OR_NEWER + ulong shaderIdFull = EntityId.ToULong(shader.GetEntityId()); + uint shaderId = (uint)(shaderIdFull ^ (shaderIdFull >>32)); +#else + uint shaderId = (uint)shader.GetInstanceID(); +#endif + var hash = new Hash128(shaderId, (uint)GetContentsHash(_sb), 0, 0); if (_cachedVariants.TryGetValue(hash, out var result)) { Profiler.EndSample(); diff --git a/Packages/src/Runtime/UIEffectBase.cs b/Packages/src/Runtime/UIEffectBase.cs index 486f0e9..acf24ef 100644 --- a/Packages/src/Runtime/UIEffectBase.cs +++ b/Packages/src/Runtime/UIEffectBase.cs @@ -37,7 +37,11 @@ public abstract class UIEffectBase : UIBehaviour, IMeshModifier, IMaterialModifi public Material effectMaterial => _material; public Graphic graphic => _graphic ? _graphic : _graphic = GetComponent(); +#if UNITY_6000_4_OR_NEWER + public virtual EntityId effectId => GetEntityId(); +#else public virtual uint effectId => (uint)GetInstanceID(); +#endif public virtual float actualSamplingScale => 1; public virtual bool canModifyShape => true; @@ -188,8 +192,19 @@ public virtual Material GetModifiedMaterial(Material baseMaterial) Profiler.BeginSample("(UIE)[UIEffect] GetModifiedMaterial"); var samplingScaleId = (uint)(Mathf.InverseLerp(0.01f, 100, actualSamplingScale) * uint.MaxValue); - var rootId = (uint)(transitionRoot ? transitionRoot.GetInstanceID() : 0); - var hash = new Hash128((uint)baseMaterial.GetInstanceID(), effectId, samplingScaleId, rootId); +#if UNITY_6000_4_OR_NEWER + ulong matIdFull = EntityId.ToULong(baseMaterial.GetEntityId()); + uint matId = (uint)(matIdFull ^ (matIdFull >> 32)); + ulong rootIdFull = transitionRoot ? EntityId.ToULong(transitionRoot.GetEntityId()) : 0; + uint rootId = (uint)(rootIdFull ^ (rootIdFull >> 32)); + ulong effIdFull = EntityId.ToULong(effectId); + uint effId = (uint)(effIdFull ^ (effIdFull >>32)); + var hash = new Hash128(matId, effId, samplingScaleId, rootId); +#else + uint matId = (uint)baseMaterial.GetInstanceID(); + uint rootId = transitionRoot ? (uint)transitionRoot.GetInstanceID() : 0; + var hash = new Hash128(matId, effectId, samplingScaleId, rootId); +#endif if (!MaterialRepository.Valid(hash, _material)) { Profiler.BeginSample("(UIE)[UIEffect] GetModifiedMaterial > Get or create material"); diff --git a/Packages/src/Runtime/UIEffectReplica.cs b/Packages/src/Runtime/UIEffectReplica.cs index 9ae5dbb..c3347c8 100644 --- a/Packages/src/Runtime/UIEffectReplica.cs +++ b/Packages/src/Runtime/UIEffectReplica.cs @@ -1,4 +1,4 @@ -using System.Linq; +using System.Linq; using Coffee.UIEffectInternal; using UnityEngine; @@ -99,11 +99,19 @@ public bool allowToModifyMeshShape public override bool canModifyShape => m_AllowToModifyMeshShape; +#if UNITY_6000_4_OR_NEWER + public override EntityId effectId => target + ? target.effectId + : preset + ? preset.GetEntityId() + : GetEntityId(); +#else public override uint effectId => target ? target.effectId : preset ? (uint)preset.GetInstanceID() : (uint)GetInstanceID(); +#endif public override UIEffectContext context