Esempio n. 1
0
 private static void EnumerateDependencies(BindingProfile profile, List <BindingProfile> dependencies)
 {
     dependencies.Add(profile);
     foreach (var dependence in GetDependencies(profile))
     {
         EnumerateDependencies(dependence, dependencies);
     }
 }
Esempio n. 2
0
        private static List <BindingProfile> GetDependencies(BindingProfile profile)
        {
            if (!Cache.Dependencies.TryGetValue(profile, out var dependencies))
            {
                dependencies = new List <BindingProfile>();
            }

            return(dependencies);
        }
Esempio n. 3
0
        private static IEnumerable <BindingProfile> EnumerateDependencies(BindingProfile profile)
        {
            yield return(profile);

            foreach (var dependence in GetDependencies(profile).SelectMany(EnumerateDependencies))
            {
                yield return(dependence);
            }
        }
Esempio n. 4
0
            static Cache()
            {
                s_ProfileDependencies = new Dictionary <BindingProfile, List <BindingProfile> >();
                var allProfiles = new List <BindingProfile>();

                var partialBindingTypeToInstance = new Dictionary <Type, IEntityBinding>();

                var types                    = new HashSet <Type>();
                var subTypes                 = new HashSet <Type>();
                var bindingsDependencies     = new List <IEntityBinding>();
                var profileDependencies      = new Dictionary <BindingProfile, List <IEntityBinding> >();
                var bindingInstanceToProfile = new Dictionary <IEntityBinding, BindingProfile>();

                var collection = UnityEditor.TypeCache.GetTypesDerivedFrom <IEntityBinding>()
                                 .Where(t => !t.IsAbstract && !t.ContainsGenericParameters && !t.IsGenericType).ToList();

                RegisterBindingProfiles(collection, partialBindingTypeToInstance);

                for (var i = 0; i < collection.Count; ++i)
                {
                    var type = collection[i];

                    if (type.IsAbstract || type.ContainsGenericParameters)
                    {
                        continue;
                    }

                    var interfaces = type.GetInterfaces();
                    foreach (var @interface in interfaces)
                    {
                        if ([email protected])
                        {
                            continue;
                        }

                        var genericTypeDefinition = @interface.GetGenericTypeDefinition();
                        var arguments             = @interface.GetGenericArguments();
                        if (IsComponentBindingType(genericTypeDefinition))
                        {
                            foreach (var argument in arguments)
                            {
                                types.Add(argument);
                            }
                        }

                        if (IsSubtractiveBindingType(genericTypeDefinition))
                        {
                            foreach (var argument in arguments)
                            {
                                subTypes.Add(argument);
                            }
                        }

                        if (IsDependencyType(genericTypeDefinition))
                        {
                            foreach (var argument in arguments)
                            {
                                if (partialBindingTypeToInstance.TryGetValue(argument, out var instance))
                                {
                                    bindingsDependencies.Add(instance);
                                }
                            }
                        }
                    }

                    var profile = new BindingProfile(partialBindingTypeToInstance[type],
                                                     types.Select(TypeManager.GetTypeIndex).ToArray(), subTypes.Select(TypeManager.GetTypeIndex).ToArray());
                    allProfiles.Add(profile);
                    bindingInstanceToProfile.Add(partialBindingTypeToInstance[type], profile);
                    profileDependencies.Add(profile, new List <IEntityBinding>(bindingsDependencies));

                    // TODO: Check for test data
                    // ...

                    types.Clear();
                    subTypes.Clear();
                    bindingsDependencies.Clear();
                }

                // Set up dependencies
                foreach (var kvp in profileDependencies)
                {
                    var profile      = kvp.Key;
                    var dependencies = kvp.Value;

                    s_ProfileDependencies.Add(profile,
                                              new List <BindingProfile>(dependencies.Select(d => bindingInstanceToProfile[d])));
                }

                s_AllProfiles = allProfiles.ToArray();
            }