Skip to content

Commit

Permalink
Added some backwards compatability support
Browse files Browse the repository at this point in the history
  • Loading branch information
Lachee committed Aug 15, 2022
1 parent 632e1ef commit 898b5e3
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 17 deletions.
12 changes: 3 additions & 9 deletions Editor/Lachee.Utilities.Editor.asmdef
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 1 addition & 1 deletion Runtime/Utilities/Linq.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static class Linq
public static TSource Random<TSource>(this IEnumerable<TSource> 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.
Expand Down
13 changes: 13 additions & 0 deletions Runtime/Utilities/Serialization/TextureSurrogate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -36,13 +39,23 @@ 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),
(TextureFormat) info.GetInt32(ValueFormat),
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);
Expand Down
13 changes: 7 additions & 6 deletions Runtime/Utilities/Singleton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ public abstract class Singleton<T> : MonoBehaviour where T : Singleton<T>
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

/// <summary>
/// The current type that belongs to this singleton. Alias of <code>typeof(T)</code>.
Expand Down Expand Up @@ -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<T>();
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
{
Expand Down Expand Up @@ -170,9 +171,9 @@ protected virtual void OnApplicationQuit()
/// </summary>
protected virtual void Awake()
{
#if UNITY_EDITOR
#if UNITY_EDITOR
if (Application.isPlaying)
#endif
#endif
if (dontDestroyOnLoad)
DontDestroyOnLoad(gameObject);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 898b5e3

Please sign in to comment.