Ejemplo n.º 1
0
 private static void CollectGroups(IEnumerable <ScriptBehaviourManager> activeManagers, out Dictionary <Type, ScriptBehaviourGroup> allGroups, out Dictionary <Type, DependantBehavior> dependencies)
 {
     allGroups    = new Dictionary <Type, ScriptBehaviourGroup>();
     dependencies = new Dictionary <Type, DependantBehavior>();
     foreach (ScriptBehaviourManager manager in activeManagers)
     {
         object[] objArray2 = manager.GetType().GetCustomAttributes(typeof(UpdateInGroupAttribute), true);
         int      index     = 0;
         while (true)
         {
             ScriptBehaviourGroup group;
             if (index >= objArray2.Length)
             {
                 DependantBehavior behavior = new DependantBehavior(manager);
                 dependencies.Add(manager.GetType(), behavior);
                 break;
             }
             object obj2 = objArray2[index];
             UpdateInGroupAttribute attribute = obj2 as UpdateInGroupAttribute;
             if (!allGroups.TryGetValue(attribute.GroupType, out group))
             {
                 group = new ScriptBehaviourGroup(attribute.GroupType, allGroups, null);
             }
             group.Managers.Add(manager.GetType());
             index++;
         }
     }
 }
Ejemplo n.º 2
0
        public static void CollectGroups(IEnumerable <ScriptBehaviourManager> activeManagers, out Dictionary <Type, ScriptBehaviourGroup> allGroups, out Dictionary <Type, DependantBehavior> dependencies)
        {
            allGroups    = new Dictionary <Type, ScriptBehaviourGroup>();
            dependencies = new Dictionary <Type, DependantBehavior>();
            foreach (var manager in activeManagers)
            {
                var attribs = manager.GetType().GetCustomAttributes(typeof(UpdateInGroupAttribute), true);
                foreach (var attr in attribs)
                {
                    var grp = attr as UpdateInGroupAttribute;
                    ScriptBehaviourGroup groupData;
                    if (!allGroups.TryGetValue(grp.GroupType, out groupData))
                    {
                        groupData = new ScriptBehaviourGroup(grp.GroupType, allGroups);
                    }
                    groupData.Managers.Add(manager.GetType());
                }

                var dep = new DependantBehavior(manager);
                dependencies.Add(manager.GetType(), dep);
            }
        }
        static Dictionary <Type, DependantBehavior> BuildSystemGraph(IEnumerable <ScriptBehaviourManager> activeManagers, PlayerLoopSystem defaultPlayerLoop)
        {
            // Collect all groups and create empty dependency data
            var allGroups    = new Dictionary <Type, ScriptBehaviourGroup>();
            var dependencies = new Dictionary <Type, DependantBehavior>();

            foreach (var manager in activeManagers)
            {
                var attribs = manager.GetType().GetCustomAttributes(typeof(UpdateInGroupAttribute), true);
                foreach (var attr in attribs)
                {
                    var grp = attr as UpdateInGroupAttribute;
                    ScriptBehaviourGroup groupData;
                    if (!allGroups.TryGetValue(grp.GroupType, out groupData))
                    {
                        groupData = new ScriptBehaviourGroup(grp.GroupType, allGroups);
                    }
                    groupData.Managers.Add(manager.GetType());
                }

                var dep = new DependantBehavior(manager);
                dependencies.Add(manager.GetType(), dep);
            }

            // @TODO: apply additional sideloaded constraints here

            // Apply the update before / after dependencies
            foreach (var manager in dependencies)
            {
                // @TODO: need to deal with extracting dependencies for GenericProcessComponentSystem
                AddDependencies(manager.Value, dependencies, allGroups, defaultPlayerLoop);
            }

            ValidateAndFixSystemGraph(dependencies);

            return(dependencies);
        }
Ejemplo n.º 4
0
            public ScriptBehaviourGroup(Type grpType, IDictionary <Type, ScriptBehaviourGroup> allGroups, HashSet <Type> circularCheck = null)
            {
                m_GroupType = grpType;

                var attribs = grpType.GetCustomAttributes(typeof(UpdateAfterAttribute), true);

                foreach (var attr in attribs)
                {
                    var attribDep = attr as UpdateAfterAttribute;
                    UpdateAfter.Add(attribDep.SystemType);
                }
                attribs = grpType.GetCustomAttributes(typeof(UpdateBeforeAttribute), true);
                foreach (var attr in attribs)
                {
                    var attribDep = attr as UpdateAfterAttribute;
                    UpdateBefore.Add(attribDep.SystemType);
                }

                allGroups.Add(m_GroupType, this);

                attribs = m_GroupType.GetCustomAttributes(typeof(UpdateInGroupAttribute), true);
                foreach (var attr in attribs)
                {
                    if (circularCheck == null)
                    {
                        circularCheck = new HashSet <Type> {
                            m_GroupType
                        };
                    }
                    var parentGrp = attr as UpdateInGroupAttribute;
                    if (!circularCheck.Add(parentGrp.GroupType))
                    {
                        // Found circular dependency
                        var msg       = "Found circular chain in update groups involving: ";
                        var firstType = true;
                        foreach (var circularType in circularCheck)
                        {
                            msg      += (firstType ? "" : ", ") + circularType;
                            firstType = false;
                        }
                        Debug.LogError(msg);
                    }
                    ScriptBehaviourGroup parentGroupData;
                    if (!allGroups.TryGetValue(parentGrp.GroupType, out parentGroupData))
                    {
                        parentGroupData = new ScriptBehaviourGroup(parentGrp.GroupType, allGroups, circularCheck);
                    }
                    circularCheck.Remove(parentGrp.GroupType);
                    parentGroupData.m_Groups.Add(this);
                    m_Parents.Add(parentGroupData);

                    foreach (var dep in parentGroupData.UpdateBefore)
                    {
                        UpdateBefore.Add(dep);
                    }
                    foreach (var dep in parentGroupData.UpdateAfter)
                    {
                        UpdateAfter.Add(dep);
                    }
                }
            }