Skip to content

Commit 898b5e3

Browse files
committed
Added some backwards compatability support
1 parent 632e1ef commit 898b5e3

File tree

5 files changed

+25
-17
lines changed

5 files changed

+25
-17
lines changed
Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
11
{
22
"name": "Lachee.Utilities.Editor",
3-
"rootNamespace": "",
43
"references": [
5-
"GUID:aa08d19502347e74bb216b7098a7c7c9"
4+
"Lachee.Utilities.Runtime"
65
],
6+
"optionalUnityReferences": [],
77
"includePlatforms": [
88
"Editor"
99
],
1010
"excludePlatforms": [],
11-
"allowUnsafeCode": false,
12-
"overrideReferences": false,
13-
"precompiledReferences": [],
14-
"autoReferenced": true,
15-
"defineConstraints": [],
16-
"versionDefines": [],
17-
"noEngineReferences": false
11+
"allowUnsafeCode": false
1812
}

Runtime/Utilities/Linq.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public static class Linq
2525
public static TSource Random<TSource>(this IEnumerable<TSource> source, int upperBounds = int.MaxValue)
2626
{
2727
// The enumerator to iterate over
28-
using var enumerator = source.GetEnumerator();
28+
var enumerator = source.GetEnumerator();
2929

3030
// The number of items we have found.
3131
// If we loop over, then we will reset the counter to a random number within this range.

Runtime/Utilities/Serialization/TextureSurrogate.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@ public class Texture2DSurrogate : ISerializationSurrogate
1919
public void GetObjectData(object obj, SerializationInfo info, StreamingContext context)
2020
{
2121
Texture2D texture = (Texture2D)obj;
22+
23+
#if UNITY_2018_3_OR_NEWER
2224
if (!texture.isReadable)
2325
throw new System.NotSupportedException("Textures must be readable to serialize");
26+
#endif
2427

2528
var data = texture.GetRawTextureData();
2629
info.AddValue(ValueName, texture.name);
@@ -36,13 +39,23 @@ public void GetObjectData(object obj, SerializationInfo info, StreamingContext c
3639

3740
public object SetObjectData(object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector)
3841
{
42+
#if UNITY_2021_OR_NEWER
3943
Texture2D texture = new Texture2D(
4044
info.GetInt32(ValueWidth),
4145
info.GetInt32(ValueHeight),
4246
(TextureFormat) info.GetInt32(ValueFormat),
4347
info.GetInt32(ValueMipmap),
4448
false
4549
);
50+
#else
51+
Texture2D texture = new Texture2D(
52+
info.GetInt32(ValueWidth),
53+
info.GetInt32(ValueHeight),
54+
(TextureFormat)info.GetInt32(ValueFormat),
55+
true,
56+
false
57+
);
58+
#endif
4659

4760
texture.filterMode = (FilterMode) info.GetInt32(ValueFilter);
4861
texture.wrapMode = (TextureWrapMode) info.GetInt32(ValueWrap);

Runtime/Utilities/Singleton.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@ public abstract class Singleton<T> : MonoBehaviour where T : Singleton<T>
2323
internal static T _instance;
2424
private static bool _isquitting = false;
2525

26+
#if UNITY_2019_2_OR_NEWER
2627
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
2728
static void Init()
2829
{
2930
_instance = null;
3031
_isquitting = false;
3132
}
32-
33+
#endif
3334

3435
/// <summary>
3536
/// The current type that belongs to this singleton. Alias of <code>typeof(T)</code>.
@@ -65,13 +66,13 @@ public static T instance
6566
//We do not have one available, lets create it as a new gameobject.
6667
if (Application.isPlaying)
6768
{
68-
#if !DONT_CREATE_SINGLETONS
69+
#if !DONT_CREATE_SINGLETONS
6970
GameObject obj = new GameObject($"[ {type} INSTANCE ]");
7071
_instance = obj.AddComponent<T>();
7172
Debug.LogWarning("Singleton " + type + " does not exist. A new instance has been created instead.", _instance);
72-
#else
73+
#else
7374
Debug.LogError($"Singleton {type} cannot be created because DONT_CREATE_SINGLETONS is defined");
74-
#endif
75+
#endif
7576
}
7677
else
7778
{
@@ -170,9 +171,9 @@ protected virtual void OnApplicationQuit()
170171
/// </summary>
171172
protected virtual void Awake()
172173
{
173-
#if UNITY_EDITOR
174+
#if UNITY_EDITOR
174175
if (Application.isPlaying)
175-
#endif
176+
#endif
176177
if (dontDestroyOnLoad)
177178
DontDestroyOnLoad(gameObject);
178179
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "com.lachee.utilities",
3-
"version": "1.3.7",
3+
"version": "1.3.8",
44
"displayName": "Lachee's Utilities",
55
"description": "Bunch of utility functionality",
66
"unity": "2019.1",

0 commit comments

Comments
 (0)