diff --git a/Editor/Lachee.Utilities.Editor.asmdef b/Editor/Lachee.Utilities.Editor.asmdef index a47ce2c..58def51 100644 --- a/Editor/Lachee.Utilities.Editor.asmdef +++ b/Editor/Lachee.Utilities.Editor.asmdef @@ -1,18 +1,12 @@ { "name": "Lachee.Utilities.Editor", - "rootNamespace": "", "references": [ - "GUID:aa08d19502347e74bb216b7098a7c7c9" + "Lachee.Utilities.Runtime" ], + "optionalUnityReferences": [], "includePlatforms": [ "Editor" ], "excludePlatforms": [], - "allowUnsafeCode": false, - "overrideReferences": false, - "precompiledReferences": [], - "autoReferenced": true, - "defineConstraints": [], - "versionDefines": [], - "noEngineReferences": false + "allowUnsafeCode": false } \ No newline at end of file diff --git a/Runtime/Utilities/Linq.cs b/Runtime/Utilities/Linq.cs index e62e394..d6fc527 100644 --- a/Runtime/Utilities/Linq.cs +++ b/Runtime/Utilities/Linq.cs @@ -25,7 +25,7 @@ public static class Linq public static TSource Random(this IEnumerable source, int upperBounds = int.MaxValue) { // The enumerator to iterate over - using var enumerator = source.GetEnumerator(); + var enumerator = source.GetEnumerator(); // The number of items we have found. // If we loop over, then we will reset the counter to a random number within this range. diff --git a/Runtime/Utilities/Serialization/TextureSurrogate.cs b/Runtime/Utilities/Serialization/TextureSurrogate.cs index 4c7584a..dfe3650 100644 --- a/Runtime/Utilities/Serialization/TextureSurrogate.cs +++ b/Runtime/Utilities/Serialization/TextureSurrogate.cs @@ -19,8 +19,11 @@ public class Texture2DSurrogate : ISerializationSurrogate public void GetObjectData(object obj, SerializationInfo info, StreamingContext context) { Texture2D texture = (Texture2D)obj; + +#if UNITY_2018_3_OR_NEWER if (!texture.isReadable) throw new System.NotSupportedException("Textures must be readable to serialize"); +#endif var data = texture.GetRawTextureData(); info.AddValue(ValueName, texture.name); @@ -36,6 +39,7 @@ public void GetObjectData(object obj, SerializationInfo info, StreamingContext c public object SetObjectData(object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector) { +#if UNITY_2021_OR_NEWER Texture2D texture = new Texture2D( info.GetInt32(ValueWidth), info.GetInt32(ValueHeight), @@ -43,6 +47,15 @@ public object SetObjectData(object obj, SerializationInfo info, StreamingContext info.GetInt32(ValueMipmap), false ); +#else + Texture2D texture = new Texture2D( + info.GetInt32(ValueWidth), + info.GetInt32(ValueHeight), + (TextureFormat)info.GetInt32(ValueFormat), + true, + false + ); +#endif texture.filterMode = (FilterMode) info.GetInt32(ValueFilter); texture.wrapMode = (TextureWrapMode) info.GetInt32(ValueWrap); diff --git a/Runtime/Utilities/Singleton.cs b/Runtime/Utilities/Singleton.cs index 2725978..cf1b922 100644 --- a/Runtime/Utilities/Singleton.cs +++ b/Runtime/Utilities/Singleton.cs @@ -23,13 +23,14 @@ public abstract class Singleton : MonoBehaviour where T : Singleton internal static T _instance; private static bool _isquitting = false; +#if UNITY_2019_2_OR_NEWER [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)] static void Init() { _instance = null; _isquitting = false; } - +#endif /// /// The current type that belongs to this singleton. Alias of typeof(T). @@ -65,13 +66,13 @@ public static T instance //We do not have one available, lets create it as a new gameobject. if (Application.isPlaying) { - #if !DONT_CREATE_SINGLETONS +#if !DONT_CREATE_SINGLETONS GameObject obj = new GameObject($"[ {type} INSTANCE ]"); _instance = obj.AddComponent(); Debug.LogWarning("Singleton " + type + " does not exist. A new instance has been created instead.", _instance); - #else +#else Debug.LogError($"Singleton {type} cannot be created because DONT_CREATE_SINGLETONS is defined"); - #endif +#endif } else { @@ -170,9 +171,9 @@ protected virtual void OnApplicationQuit() /// protected virtual void Awake() { - #if UNITY_EDITOR +#if UNITY_EDITOR if (Application.isPlaying) - #endif +#endif if (dontDestroyOnLoad) DontDestroyOnLoad(gameObject); } diff --git a/package.json b/package.json index 4135abd..436f809 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.lachee.utilities", - "version": "1.3.7", + "version": "1.3.8", "displayName": "Lachee's Utilities", "description": "Bunch of utility functionality", "unity": "2019.1",