46 lines
1.1 KiB
C#
46 lines
1.1 KiB
C#
|
|
using System;
|
||
|
|
using System.Reflection;
|
||
|
|
|
||
|
|
namespace XCEngine
|
||
|
|
{
|
||
|
|
public abstract class ScriptableObject : Object
|
||
|
|
{
|
||
|
|
protected ScriptableObject()
|
||
|
|
{
|
||
|
|
}
|
||
|
|
|
||
|
|
public static T CreateInstance<T>()
|
||
|
|
where T : ScriptableObject
|
||
|
|
{
|
||
|
|
return CreateInstance(typeof(T)) as T;
|
||
|
|
}
|
||
|
|
|
||
|
|
public static ScriptableObject CreateInstance(
|
||
|
|
Type scriptableObjectType)
|
||
|
|
{
|
||
|
|
if (scriptableObjectType == null ||
|
||
|
|
!typeof(ScriptableObject)
|
||
|
|
.IsAssignableFrom(scriptableObjectType))
|
||
|
|
{
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
|
||
|
|
try
|
||
|
|
{
|
||
|
|
return Activator.CreateInstance(
|
||
|
|
scriptableObjectType,
|
||
|
|
BindingFlags.Instance |
|
||
|
|
BindingFlags.Public |
|
||
|
|
BindingFlags.NonPublic,
|
||
|
|
binder: null,
|
||
|
|
args: Array.Empty<object>(),
|
||
|
|
culture: null) as ScriptableObject;
|
||
|
|
}
|
||
|
|
catch
|
||
|
|
{
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|