private static bool CheckBeforeConstraints(Type parentType, UpdateBeforeAttribute dep, Type systemType) { if (!typeof(ComponentSystemBase).IsAssignableFrom(dep.SystemType)) { Debug.LogWarning( $"Ignoring invalid [UpdateBefore] attribute on {SysName(systemType)} because {SysName(dep.SystemType)} is not a subclass of {nameof(ComponentSystemBase)}.\n" + $"Set the target parameter of [UpdateBefore] to a system class in the same {nameof(ComponentSystemGroup)} as {SysName(systemType)}."); return(true); } if (dep.SystemType == systemType) { Debug.LogWarning( $"Ignoring invalid [UpdateBefore] attribute on {SysName(systemType)} because a system cannot be updated before itself.\n" + $"Set the target parameter of [UpdateBefore] to a different system class in the same {nameof(ComponentSystemGroup)} as {SysName(systemType)}."); return(true); } int systemBucket = ComponentSystemGroup.ComputeSystemOrdering(systemType, parentType); int depBucket = ComponentSystemGroup.ComputeSystemOrdering(dep.SystemType, parentType); if (depBucket > systemBucket) { // This constraint is redundant, but harmless; it is accounted for by the bucketing order, and can be quietly ignored. return(true); } if (depBucket < systemBucket) { Debug.LogWarning( $"Ignoring invalid [UpdateBefore({SysName(dep.SystemType)})] attribute on {SysName(systemType)} because OrderFirst/OrderLast has higher precedence."); return(true); } return(false); }
public ScriptBehaviourGroup(Type grpType, IDictionary <Type, ScriptBehaviourUpdateOrder.ScriptBehaviourGroup> allGroups, HashSet <Type> circularCheck = null) { this.m_GroupType = grpType; foreach (object obj2 in grpType.GetCustomAttributes(typeof(UpdateAfterAttribute), true)) { UpdateAfterAttribute attribute = obj2 as UpdateAfterAttribute; this.UpdateAfter.Add(attribute.SystemType); } foreach (object obj3 in grpType.GetCustomAttributes(typeof(UpdateBeforeAttribute), true)) { UpdateBeforeAttribute attribute2 = obj3 as UpdateBeforeAttribute; this.UpdateBefore.Add(attribute2.SystemType); } allGroups.Add(this.m_GroupType, this); foreach (object obj4 in this.m_GroupType.GetCustomAttributes(typeof(UpdateInGroupAttribute), true)) { ScriptBehaviourUpdateOrder.ScriptBehaviourGroup group; if (circularCheck == null) { HashSet <Type> set1 = new HashSet <Type>(); set1.Add(this.m_GroupType); circularCheck = set1; } UpdateInGroupAttribute attribute3 = obj4 as UpdateInGroupAttribute; if (!circularCheck.Add(attribute3.GroupType)) { string message = "Found circular chain in update groups involving: "; bool flag3 = true; foreach (Type type in circularCheck) { message = message + (flag3 ? "" : ", ") + type; flag3 = false; } Debug.LogError(message); } if (!allGroups.TryGetValue(attribute3.GroupType, out group)) { group = new ScriptBehaviourUpdateOrder.ScriptBehaviourGroup(attribute3.GroupType, allGroups, circularCheck); } circularCheck.Remove(attribute3.GroupType); group.m_Groups.Add(this); this.m_Parents.Add(group); foreach (Type type2 in group.UpdateBefore) { this.UpdateBefore.Add(type2); } foreach (Type type3 in group.UpdateAfter) { this.UpdateAfter.Add(type3); } } }
private static bool CheckBeforeConstraints(Type parentType, UpdateBeforeAttribute dep, Type systemType) { if (!typeof(ComponentSystemBase).IsAssignableFrom(dep.SystemType)) { Debug.LogWarning( $"Ignoring invalid [UpdateBefore] attribute on {systemType} because {dep.SystemType} is not a subclass of {nameof(ComponentSystemBase)}.\n" + $"Set the target parameter of [UpdateBefore] to a system class in the same {nameof(ComponentSystemGroup)} as {systemType}."); return(true); } if (dep.SystemType == systemType) { Debug.LogWarning( $"Ignoring invalid [UpdateBefore] attribute on {systemType} because a system cannot be updated before itself.\n" + $"Set the target parameter of [UpdateBefore] to a different system class in the same {nameof(ComponentSystemGroup)} as {systemType}."); return(true); } return(false); }
private static void AddDependencies(DependantBehavior targetSystem, IReadOnlyDictionary <Type, DependantBehavior> dependencies, IReadOnlyDictionary <Type, ScriptBehaviourGroup> allGroups, PlayerLoopSystem defaultPlayerLoop) { Type item = targetSystem.Manager.GetType(); foreach (object obj2 in item.GetCustomAttributes(typeof(UpdateAfterAttribute), true)) { DependantBehavior behavior; UpdateAfterAttribute attribute = obj2 as UpdateAfterAttribute; if (dependencies.TryGetValue(attribute.SystemType, out behavior)) { targetSystem.UpdateAfter.Add(attribute.SystemType); behavior.UpdateBefore.Add(item); } else { ScriptBehaviourGroup group; if (allGroups.TryGetValue(attribute.SystemType, out group)) { group.AddUpdateBeforeToAllChildBehaviours(targetSystem, dependencies); } else { UpdateInsertionPos(targetSystem, attribute.SystemType, defaultPlayerLoop, true); } } } foreach (object obj3 in item.GetCustomAttributes(typeof(UpdateBeforeAttribute), true)) { DependantBehavior behavior2; UpdateBeforeAttribute attribute2 = obj3 as UpdateBeforeAttribute; if (dependencies.TryGetValue(attribute2.SystemType, out behavior2)) { targetSystem.UpdateBefore.Add(attribute2.SystemType); behavior2.UpdateAfter.Add(item); } else { ScriptBehaviourGroup group2; if (allGroups.TryGetValue(attribute2.SystemType, out group2)) { group2.AddUpdateAfterToAllChildBehaviours(targetSystem, dependencies); } else { UpdateInsertionPos(targetSystem, attribute2.SystemType, defaultPlayerLoop, false); } } } foreach (object obj4 in item.GetCustomAttributes(typeof(UpdateInGroupAttribute), true)) { ScriptBehaviourGroup group3; UpdateInGroupAttribute attribute3 = obj4 as UpdateInGroupAttribute; if (allGroups.TryGetValue(attribute3.GroupType, out group3)) { DependantBehavior behavior3; ScriptBehaviourGroup group4; foreach (Type type2 in group3.UpdateAfter) { if (dependencies.TryGetValue(type2, out behavior3)) { targetSystem.UpdateAfter.Add(type2); behavior3.UpdateBefore.Add(item); continue; } if (allGroups.TryGetValue(type2, out group4)) { group4.AddUpdateBeforeToAllChildBehaviours(targetSystem, dependencies); continue; } UpdateInsertionPos(targetSystem, type2, defaultPlayerLoop, true); } foreach (Type type3 in group3.UpdateBefore) { if (dependencies.TryGetValue(type3, out behavior3)) { targetSystem.UpdateBefore.Add(type3); behavior3.UpdateAfter.Add(item); continue; } if (allGroups.TryGetValue(type3, out group4)) { group4.AddUpdateAfterToAllChildBehaviours(targetSystem, dependencies); continue; } UpdateInsertionPos(targetSystem, type3, defaultPlayerLoop, false); } } } }