GenericRegisterObject (Camera objectToRegister, bool objectIsAPrefab, InitialisationDelegate initialisationCallback, int Index) { Camera Instance; if (objectIsAPrefab) { GameObject Prefab = objectToRegister.gameObject; GameObject Obj = GameObject.Instantiate(Prefab); Instance = Obj.GetComponent <Camera>(); MyContract.RequireArgumentNotNull(Instance, "Camera Component"); } else { Instance = objectToRegister; Debug.Assert(Instance != null, "Provided object was null"); } if (initialisationCallback != null) { initialisationCallback(Instance, Index); } IGameObjectRegistryKeyComponent KeyComponent = Instance.GetComponent <IGameObjectRegistryKeyComponent>(); int element = KeyComponent.Key; //Debug.Log("Adding element " + element.ToString() + " to the dictionary."); if (RegisteredObjects.ContainsKey(element) && RetrieveObject(element) != null) { throw new InvalidOperationException( "Trying to register a second GameObject " + " with element identifier " + PrintKey(element) ); } else if (RegisteredObjects.ContainsKey(element) && RetrieveObject(element) == null) { // assume a deliberate replace intent RegisteredObjects[element] = Instance; } else { RegisteredObjects.Add(element, Instance); } if (PersistThroughScenes) { GameObject.DontDestroyOnLoad(Instance); GameObject.DontDestroyOnLoad(Instance.gameObject); } }
GenericRegisterObject (GameObject originalObject, bool objectIsAPrefab, InitialisationDelegate initialisationCallback, int Index) { GameObject Instance; if (objectIsAPrefab) { GameObject Prefab = originalObject; Instance = GameObject.Instantiate(Prefab); Debug.Assert(Instance != null, "Instantiate returned null"); } else { Instance = originalObject; Debug.Assert(Instance != null, "Provided object was null"); } if (initialisationCallback != null) { initialisationCallback(Instance, Index); } IGameObjectRegistryKeyComponent KeyComponent = Instance.GetComponent <IGameObjectRegistryKeyComponent>(); int element = KeyComponent.Key; //Debug.Log("Adding element " + element.ToString() + " to the dictionary."); if (RegisteredObjects.ContainsKey(element) && RetrieveObject(element) != null) { throw new InvalidOperationException( "Trying to register a second GameObject " + " with element identifier " + PrintKey(element) ); } else { RegisteredObjects.Add(element, Instance); } if (PersistThroughScenes) { GameObject.DontDestroyOnLoad(Instance); } }