diff --git a/Editor/DomainReloadHandler.cs b/Editor/DomainReloadHandler.cs
index 59353fe..4b03d6f 100644
--- a/Editor/DomainReloadHandler.cs
+++ b/Editor/DomainReloadHandler.cs
@@ -34,12 +34,13 @@ private static void OnRuntimeLoad()
if (valueToAssign != null) {
value = Convert.ChangeType(valueToAssign, fieldType);
if (value == null)
- Debug.LogWarning("Unable to assign value of type {valueToAssign.GetType()} to field {field.Name} of type {fieldType}.");
+ Debug.LogWarning($"Unable to assign value of type {valueToAssign.GetType()} to field {field.Name} of type {fieldType}.");
}
// If assignNewTypeInstance is set, create a new instance of this type and assign it to the field
- if (assignNewTypeInstance)
- value = Activator.CreateInstance(fieldType);
+ if (assignNewTypeInstance){
+ value = Activator.CreateInstance(fieldType, reloadAttribute.arguments);
+ }
try {
field.SetValue(null, value);
@@ -47,13 +48,13 @@ private static void OnRuntimeLoad()
}
catch {
if (valueToAssign == null)
- Debug.LogWarning("Unable to clear field {field.Name}.");
+ Debug.LogWarning($"Unable to clear field {field.Name}.");
else
- Debug.LogWarning("Unable to assign field {field.Name}.");
+ Debug.LogWarning($"Unable to assign field {field.Name}.");
}
} else {
- Debug.LogWarning("Inapplicable field {field.Name} to clear; must be static and non-generic.");
+ Debug.LogWarning($"Inapplicable field {field.Name} to clear; must be static and non-generic.");
}
}
diff --git a/Runtime/DomainReloadAttributes.cs b/Runtime/DomainReloadAttributes.cs
index 6315eb1..081888d 100644
--- a/Runtime/DomainReloadAttributes.cs
+++ b/Runtime/DomainReloadAttributes.cs
@@ -5,6 +5,7 @@ public class ClearOnReloadAttribute : Attribute
{
public readonly object valueToAssign;
public readonly bool assignNewTypeInstance;
+ public readonly object[] arguments;
///
/// Marks field, property or event to be cleared on reload.
@@ -29,10 +30,12 @@ public ClearOnReloadAttribute(object valueToAssign)
/// Marks field of property to be cleared or re-initialized on reload.
///
/// If true, field/property will be assigned a newly created object of its type on reload. Has no effect on events.
- public ClearOnReloadAttribute(bool assignNewTypeInstance = false)
+ /// Pass arguments to the constructor of the new type instance.
+ public ClearOnReloadAttribute(bool assignNewTypeInstance = false, params object[] arguments)
{
this.valueToAssign = null;
this.assignNewTypeInstance = assignNewTypeInstance;
+ this.arguments = arguments;
}
}
@@ -43,4 +46,4 @@ public class ExecuteOnReloadAttribute : Attribute
/// Marks method to be executed on reload.
///
public ExecuteOnReloadAttribute() {}
-}
\ No newline at end of file
+}
diff --git a/package.json b/package.json
index 5330d96..5229948 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "com.jsteinhauer.unitydomainreloadhelper",
- "version": "1.0.0",
+ "version": "1.0.2",
"displayName": "Unity Domain Reload Helper",
"description": "A couple of attributes that help disabling Domain Reloading in Unity easier.",
"unity": "2019.3",