Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Packages/src/Editor/AnimatablePropertyEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,19 @@ public static void Draw(SerializedProperty sp, List<Material> mats)
var mat = mats[j];
if (mat == null || mat.shader == null) continue;

#if UNITY_6000_5_OR_NEWER
for (var i = 0; i < mat.shader.GetPropertyCount(); i++)
#else
for (var i = 0; i < ShaderUtil.GetPropertyCount(mat.shader); i++)
#endif
{
#if UNITY_6000_5_OR_NEWER
var name = mat.shader.GetPropertyName(i);
var type = (AnimatableProperty.ShaderPropertyType)mat.shader.GetPropertyType(i);
#else
var name = ShaderUtil.GetPropertyName(mat.shader, i);
var type = (AnimatableProperty.ShaderPropertyType)ShaderUtil.GetPropertyType(mat.shader, i);
#endif
if (!s_Names.Add(name)) continue;

AddMenu(gm, sp, new ShaderProperty(name, type), true);
Expand Down
16 changes: 16 additions & 0 deletions Packages/src/Editor/UIParticleMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,19 @@ namespace Coffee.UIExtensions
{
internal class UIParticleMenu
{
#if UNITY_6000_5_OR_NEWER
[MenuItem("GameObject/UI (Canvas)/Particle System (Empty)", false, 2018)]
#else
[MenuItem("GameObject/UI/Particle System (Empty)", false, 2018)]
#endif
private static void AddParticleEmpty(MenuCommand menuCommand)
{
// Create empty UI element.
#if UNITY_6000_5_OR_NEWER
EditorApplication.ExecuteMenuItem("GameObject/UI (Canvas)/Image");
#else
EditorApplication.ExecuteMenuItem("GameObject/UI/Image");
#endif
var ui = Selection.activeGameObject;
Object.DestroyImmediate(ui.GetComponent<Image>());

Expand All @@ -21,15 +29,23 @@ private static void AddParticleEmpty(MenuCommand menuCommand)
uiParticle.rectTransform.sizeDelta = Vector2.zero;
}

#if UNITY_6000_5_OR_NEWER
[MenuItem("GameObject/UI (Canvas)/Particle System", false, 2019)]
#else
[MenuItem("GameObject/UI/Particle System", false, 2019)]
#endif
private static void AddParticle(MenuCommand menuCommand)
{
// Create empty UIEffect.
AddParticleEmpty(menuCommand);
var uiParticle = Selection.activeGameObject.GetComponent<UIParticle>();

// Create ParticleSystem.
#if UNITY_6000_5_OR_NEWER
EditorApplication.ExecuteMenuItem("GameObject/Visual Effects/Particle System");
#else
EditorApplication.ExecuteMenuItem("GameObject/Effects/Particle System");
#endif
var ps = Selection.activeGameObject;
ps.transform.SetParent(uiParticle.transform, false);
ps.transform.localPosition = Vector3.zero;
Expand Down
4 changes: 3 additions & 1 deletion Packages/src/Runtime/Internal/Utilities/Misc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ internal static class Misc
{
public static T[] FindObjectsOfType<T>() where T : Object
{
#if UNITY_2023_1_OR_NEWER
#if UNITY_6000_5_OR_NEWER
return Object.FindObjectsByType<T>(FindObjectsInactive.Include);
#elif UNITY_2023_1_OR_NEWER
return Object.FindObjectsByType<T>(FindObjectsInactive.Include, FindObjectsSortMode.None);
#else
return Object.FindObjectsOfType<T>();
Expand Down
12 changes: 12 additions & 0 deletions Packages/src/Runtime/Internal/Utilities/ObjectRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,11 @@ private void Add(Hash128 hash, ref T obj, T newObject)
newEntry.hash = hash;
newEntry.reference = 1;
_cache[hash] = newEntry;
#if UNITY_6000_5_OR_NEWER
_objectKey[newObject.GetEntityId().GetHashCode()] = hash;
#else
_objectKey[newObject.GetInstanceID()] = hash;
#endif
Logging.Log(_name, $"<color=#03c700>Add</color>(total#{count}): {newEntry}");
Release(ref obj);
obj = newObject;
Expand All @@ -146,7 +150,11 @@ public void Release(ref T obj)

// Find and release the entry.
Profiler.BeginSample("(COF)[ObjectRepository] Release");
#if UNITY_6000_5_OR_NEWER
var id = obj.GetEntityId().GetHashCode();
#else
var id = obj.GetInstanceID();
#endif
if (_objectKey.TryGetValue(id, out var hash)
&& _cache.TryGetValue(hash, out var entry))
{
Expand Down Expand Up @@ -175,7 +183,11 @@ private void Remove(Entry entry)

Profiler.BeginSample("(COF)[ObjectRepository] Remove");
_cache.Remove(entry.hash);
#if UNITY_6000_5_OR_NEWER
_objectKey.Remove(entry.storedObject.GetEntityId().GetHashCode());
#else
_objectKey.Remove(entry.storedObject.GetInstanceID());
#endif
_pool.Push(entry);
entry.reference = 0;
Logging.Log(_name, $"<color=#f29e03>Remove</color>(total#{_cache.Count}): {entry}");
Expand Down
7 changes: 7 additions & 0 deletions Packages/src/Runtime/UIParticleRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,17 @@ public override Material GetModifiedMaterial(Material baseMaterial)
return modifiedMaterial;
}

#if UNITY_6000_5_OR_NEWER
var hash = new Hash128(
modifiedMaterial ? (uint)modifiedMaterial.GetEntityId().GetHashCode() : 0,
texture ? (uint)texture.GetEntityId().GetHashCode() : 0,
0 < _parent.m_AnimatableProperties.Length ? (uint)GetEntityId().GetHashCode() : 0,
#else
var hash = new Hash128(
modifiedMaterial ? (uint)modifiedMaterial.GetInstanceID() : 0,
texture ? (uint)texture.GetInstanceID() : 0,
0 < _parent.m_AnimatableProperties.Length ? (uint)GetInstanceID() : 0,
#endif
#if UNITY_EDITOR
(uint)EditorJsonUtility.ToJson(modifiedMaterial).GetHashCode()
#else
Expand Down
8 changes: 8 additions & 0 deletions Packages/src/Runtime/Utilities/ParticleSystemExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ public static void SortForRendering(this List<ParticleSystem> self, Transform tr

if (sortByMaterial)
{
#if UNITY_6000_5_OR_NEWER
return aMat.GetEntityId().GetHashCode() - bMat.GetEntityId().GetHashCode();
#else
return aMat.GetInstanceID() - bMat.GetInstanceID();
#endif
}

if (aMat.renderQueue != bMat.renderQueue)
Expand Down Expand Up @@ -131,7 +135,11 @@ private static int GetIndex(IList<ParticleSystem> list, Object ps)
{
for (var i = 0; i < list.Count; i++)
{
#if UNITY_6000_5_OR_NEWER
if (list[i].GetEntityId().GetHashCode() == ps.GetEntityId().GetHashCode())
#else
if (list[i].GetInstanceID() == ps.GetInstanceID())
#endif
{
return i;
}
Expand Down