public static Type[] GetAllTypesThatImplement(Type type, bool creatableTypesOnly)
        {
            var assemblies = AppDomain.CurrentDomain.GetAssemblies();
//            var assemblyList = new List<Assembly>();
//            foreach (var assembly in assemblies)
//            {
//                if (assembly.FullName.StartsWith("Mono.Cecil") ||
//                    assembly.FullName.StartsWith("UnityScript") ||
//                    assembly.FullName.StartsWith("Boo.Lan") ||
//                    assembly.FullName.StartsWith("System") ||
//                    assembly.FullName.StartsWith("JetBrains") ||
//                    assembly.FullName.StartsWith("nunit") ||
//                    assembly.FullName.StartsWith("NUnit") ||
//                    assembly.FullName.StartsWith("I18N") ||
////                    assembly.FullName.StartsWith("UnityEngine") ||
//                    //assembly.FullName.StartsWith("UnityEditor") ||
//                    assembly.FullName.StartsWith("mscorlib"))
//                {
//                    continue;
//                }

//                assemblyList.Add(assembly);
//            }

            var types = new List <Type>(assemblies.Length);

            foreach (var assembly in assemblies)
            {
                try
                {
                    types.AddRange(assembly.GetTypes());
                }
                catch (Exception e)
                {
                    DevdogLogger.LogError(e.Message);
                }
            }

            types = types.Where(o => type.IsAssignableFrom(o)).ToList();
            if (creatableTypesOnly)
            {
                types = types.Where(o => o.IsAbstract == false && o.IsInterface == false).ToList();
            }

            return(types.ToArray());
        }
예제 #2
0
        public static void DeserializeTo(ref object obj, Type type, string json, List <UnityEngine.Object> objectReferences)
        {
            lock (_lockObject)
            {
                try
                {
                    fsData data = fsJsonParser.Parse(json);
                    SetObjectReferences(objectReferences);
                    currentRootType = type;
                    _serializer.TryDeserialize(data, type, ref obj).AssertSuccessWithoutWarnings();
                }
                catch (Exception e)
                {
                    DevdogLogger.LogError(e.Message + "\n" + e.StackTrace);
//                    throw;
                }
            }
        }
        public override fsResult TryDeserialize(fsData data, ref object instance, Type storageType)
        {
            try
            {
                var db = Serializer.Context.Get <List <UnityEngine.Object> >();
                if (data.IsNull == false)
                {
                    int index = (int)data.AsInt64;
                    if (index == -1 || index >= db.Count)
                    {
                        DevdogLogger.LogError("Couldn't deserialize UnityEngine.Object : " + instance + " - not found in database. (index: " + index + ")");
                        return(fsResult.Fail("Index out of range " + index));
                    }

                    if (IsAssetWrapper(storageType))
                    {
                        var def = typeof(Asset <>);
                        var t   = def.MakeGenericType(storageType.GetGenericArguments()[0]);

                        var inst = (IAsset)Activator.CreateInstance(t);
                        inst.objectVal = db[index];
                        instance       = inst;
                    }
                    else if (typeof(UnityEngine.Object).IsAssignableFrom(storageType))
                    {
                        instance = db[index];
                    }
                }
                else
                {
                    instance = null;
                }
            }
            catch (Exception e)
            {
                DevdogLogger.LogError(e.Message + "\n" + e.StackTrace);
                return(fsResult.Fail(e.Message));
            }

            return(fsResult.Success);
        }