You've already forked ParticleEffectForUGUI
mirror of
https://github.com/mob-sakai/ParticleEffectForUGUI.git
synced 2026-06-25 16:04:05 +00:00
fix: there is a compilation error in Unity 2019.2 or earlier
close #407
This commit is contained in:
@@ -13,9 +13,7 @@ using Object = UnityEngine.Object;
|
||||
#if UNITY_2021_2_OR_NEWER
|
||||
using UnityEditor.Overlays;
|
||||
#else
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using Object = UnityEngine.Object;
|
||||
#endif
|
||||
#if UNITY_2021_2_OR_NEWER
|
||||
using UnityEditor.SceneManagement;
|
||||
@@ -207,7 +205,10 @@ namespace Coffee.UIExtensions
|
||||
serializedObject.Update();
|
||||
|
||||
// Maskable
|
||||
EditorGUILayout.PropertyField(_maskable);
|
||||
if (_maskable != null)
|
||||
{
|
||||
EditorGUILayout.PropertyField(_maskable);
|
||||
}
|
||||
|
||||
// Scale
|
||||
EditorGUI.BeginDisabledGroup(!_meshSharing.hasMultipleDifferentValues && _meshSharing.intValue == 4);
|
||||
|
||||
@@ -12,6 +12,33 @@ namespace Coffee.UIParticleInternal
|
||||
/// </summary>
|
||||
internal static class ComponentExtensions
|
||||
{
|
||||
#if !UNITY_2019_2_OR_NEWER
|
||||
public static bool TryGetComponent<T>(this GameObject self, out T component)
|
||||
where T : Component
|
||||
{
|
||||
if (self == null)
|
||||
{
|
||||
component = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
component = self.GetComponent<T>();
|
||||
return component != null;
|
||||
}
|
||||
|
||||
public static bool TryGetComponent<T>(this Component self, out T component)
|
||||
where T : Component
|
||||
{
|
||||
if (self == null)
|
||||
{
|
||||
component = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
return self.gameObject.TryGetComponent(out component);
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Get components in children of a specific type in the hierarchy of a GameObject.
|
||||
/// </summary>
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace Coffee.UIParticleInternal
|
||||
UIExtraCallbacks.onLateAfterCanvasRebuild += ClearAllCache;
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
#if UNITY_EDITOR && UNITY_2019_3_OR_NEWER
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
|
||||
private static void Clear()
|
||||
{
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Coffee.UIParticleInternal
|
||||
|
||||
public static Func<string, Shader> onShaderFind = Shader.Find;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
#if UNITY_EDITOR && UNITY_2019_3_OR_NEWER
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
|
||||
public static void Clear()
|
||||
{
|
||||
|
||||
@@ -109,7 +109,7 @@ namespace Coffee.UIParticleInternal
|
||||
{
|
||||
if (Misc.isBatchOrBuilding) return;
|
||||
|
||||
var types = TypeCache.GetTypesWithAttribute<IconAttribute>();
|
||||
var types = TypeCache.GetTypesWithAttribute(typeof(IconAttribute));
|
||||
var scripts = MonoImporter.GetAllRuntimeMonoScripts();
|
||||
foreach (var type in types)
|
||||
{
|
||||
|
||||
88
Packages/src/Runtime/Internal/Utilities/TypeCache.cs
Normal file
88
Packages/src/Runtime/Internal/Utilities/TypeCache.cs
Normal file
@@ -0,0 +1,88 @@
|
||||
#if !UNITY_2019_2_OR_NEWER
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Coffee.UIParticleInternal
|
||||
{
|
||||
public static class TypeCache
|
||||
{
|
||||
private static readonly object s_Lock = new object();
|
||||
private static readonly Dictionary<Type, Type[]> s_DerivedTypesCache = new Dictionary<Type, Type[]>();
|
||||
private static readonly Dictionary<Type, Type[]> s_AttributeTypesCache = new Dictionary<Type, Type[]>();
|
||||
|
||||
public static IEnumerable<Type> GetTypesDerivedFrom(Type baseType)
|
||||
{
|
||||
lock (s_Lock)
|
||||
{
|
||||
if (s_DerivedTypesCache.TryGetValue(baseType, out var cached))
|
||||
{
|
||||
return cached;
|
||||
}
|
||||
|
||||
var types = new List<Type>();
|
||||
foreach (var t in GetAllLoadableTypes())
|
||||
{
|
||||
if (t != baseType && baseType.IsAssignableFrom(t))
|
||||
{
|
||||
types.Add(t);
|
||||
}
|
||||
}
|
||||
|
||||
return s_DerivedTypesCache[baseType] = types.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerable<Type> GetTypesWithAttribute(Type attr)
|
||||
{
|
||||
lock (s_Lock)
|
||||
{
|
||||
if (s_AttributeTypesCache.TryGetValue(attr, out var cached))
|
||||
{
|
||||
return cached;
|
||||
}
|
||||
|
||||
var types = new List<Type>();
|
||||
foreach (var t in GetAllLoadableTypes())
|
||||
{
|
||||
if (t.GetCustomAttributes(attr, inherit: true).Length > 0)
|
||||
{
|
||||
types.Add(t);
|
||||
}
|
||||
}
|
||||
|
||||
return s_AttributeTypesCache[attr] = types.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
private static IEnumerable<Type> GetAllLoadableTypes()
|
||||
{
|
||||
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
|
||||
{
|
||||
Type[] types;
|
||||
try
|
||||
{
|
||||
types = assembly.GetTypes();
|
||||
}
|
||||
catch (ReflectionTypeLoadException ex)
|
||||
{
|
||||
types = ex.Types;
|
||||
}
|
||||
|
||||
if (types == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (var t in types)
|
||||
{
|
||||
if (t != null)
|
||||
{
|
||||
yield return t;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
11
Packages/src/Runtime/Internal/Utilities/TypeCache.cs.meta
Normal file
11
Packages/src/Runtime/Internal/Utilities/TypeCache.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bc1207b657ed74ec19e459664d06925f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user