コード例 #1
0
    public static T GetScriptableObjectInterface <T>(this UnityEngine.ScriptableObject o)
    {
        var targetType = typeof(T);
        var objectType = o.GetType();

        foreach (var objectInterface in objectType.GetInterfaces())
        {
            if (objectInterface == targetType)
            {
                return(o.To <T>());
            }
        }

        return(default(T));
    }
コード例 #2
0
    public static List <T> GetScriptableObjectInterfaces <T>(this UnityEngine.ScriptableObject o)
    {
        var result     = new List <T>();
        var targetType = typeof(T);
        var objectType = o.GetType();

        foreach (var objectInterface in objectType.GetInterfaces())
        {
            if (objectInterface == targetType)
            {
                result.Add(o.To <T>());
            }
        }

        return(result);
    }