private void UnsubscribeFromManagers(WorldObject worldObject) { if (worldObject is ICollidable) { CollisionManager.AddCollidable(worldObject as ICollidable); } else if (worldObject is IDrawManageable) { DrawManager.Remove(worldObject as IDrawManageable); } // unsubscribe the components recursively foreach (WorldObject wo in worldObject.GetComponents()) { UnsubscribeFromManagers(wo); } }
private void SubscribeToManagers(WorldObject worldObject) { if (worldObject is ICollidable) { CollisionManager.AddCollidable(worldObject as ICollidable); } else if (worldObject is IDrawManageable) { DrawManager.AddDrawable(worldObject as IDrawManageable); } // subscribe components recursively foreach (WorldObject wo in worldObject.GetComponents()) { SubscribeToManagers(wo); } }
private static bool CircularComponentCheck(WorldObject root, HashSet <WorldObject> log) { // check if the root is in the log, if it is, that means that we have a loop if (log.Contains(root)) { return(false); } // otherwise add the root, and perform a recursive call on all of the components. log.Add(root); foreach (WorldObject wo in root.GetComponents()) { // if any fail, then stop checking. if (!CircularComponentCheck(wo, log)) { return(false); } } // if none failed, then it checks out return(true); }
private static bool CircularComponentCheck(WorldObject root, HashSet<WorldObject> log) { // check if the root is in the log, if it is, that means that we have a loop if (log.Contains(root)) return false; // otherwise add the root, and perform a recursive call on all of the components. log.Add(root); foreach(WorldObject wo in root.GetComponents()) { // if any fail, then stop checking. if (!CircularComponentCheck(wo, log)) return false; } // if none failed, then it checks out return true; }
private void UnsubscribeFromManagers(WorldObject worldObject) { if (worldObject is ICollidable) CollisionManager.AddCollidable(worldObject as ICollidable); else if (worldObject is IDrawManageable) DrawManager.Remove(worldObject as IDrawManageable); // unsubscribe the components recursively foreach (WorldObject wo in worldObject.GetComponents()) { UnsubscribeFromManagers(wo); } }
private void SubscribeToManagers(WorldObject worldObject) { if (worldObject is ICollidable) CollisionManager.AddCollidable(worldObject as ICollidable); else if (worldObject is IDrawManageable) DrawManager.AddDrawable(worldObject as IDrawManageable); // subscribe components recursively foreach (WorldObject wo in worldObject.GetComponents()) { SubscribeToManagers(wo); } }