public static T GetManager <T>(Scene scene) where T : Manager { T manager = null; ManagerContainer sceneContainer = null; if (ManagerAttributeCache.IsManagerAlwaysGlobal(typeof(T))) { return(GetGlobalManager <T>()); } if (!s_managerContainers.TryGetValue(scene, out sceneContainer)) { // if a a global container exists, check it before creating a scene one // while creating a blank scene manager would be valid, it is unexpected beahaviour. if (s_globalContainer != null) { manager = s_globalContainer.LookupManager(typeof(T)) as T; if (manager != null) { return(manager); } } var gameObject = new GameObject(scene.name + " ManagerContainer (autogenerated)"); sceneContainer = gameObject.AddComponent <ManagerContainer>(); } manager = sceneContainer.LookupManager(typeof(T)) as T; if (manager != null) { return(manager); } if (s_globalContainer != null) { manager = s_globalContainer.LookupManager(typeof(T)) as T; if (manager != null) { return(manager); } } if (sceneContainer != null) { manager = sceneContainer.AutoconstructManager(typeof(T)) as T; if (manager != null) { return(manager); } } return(null); }
public static T GetManager <T>(Scene scene) where T : Manager { T manager = null; ManagerContainer sceneContainer = null; if (!s_managerContainers.TryGetValue(scene, out sceneContainer)) { var gameObject = new GameObject(scene.name + " ManagerContainer (autogenerated)"); sceneContainer = gameObject.AddComponent <ManagerContainer>(); } manager = sceneContainer.LookupManager(typeof(T)) as T; if (manager == null && s_globalContainer != null) { manager = s_globalContainer.LookupManager(typeof(T)) as T; } if (manager == null && sceneContainer != null) { manager = sceneContainer.AutoconstructManager(typeof(T)) as T; } return(manager); }