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); } }
InitialiseAndRegisterUiPrefabs (List <GameObject> prefabs, IScreenSizeBreakpointRegister register, Canvas parentCanvas) { InitialisationDelegate Callback = CreateFreshUIComponentSetupCallback( parentCanvas.GetComponent <RectTransform>(), prefabs, CreateBreakpointRegistrationCallback(register) ); GenericRegisterFromList(prefabs, true, Callback); }
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); } }
/// <summary> /// The big one - contains all the shared logic /// </summary> /// <param name="objectsToRegister"></param> /// <param name="objectsArePrefabs"></param> /// <param name="initialisationCallback"></param> protected void GenericRegisterFromList (List <RegisteredType> objectsToRegister, bool objectsArePrefabs, InitialisationDelegate initialisationCallback) { for (int Index = 0; Index < objectsToRegister.Count; Index++) { RegisteredType OriginalObject = objectsToRegister[Index]; MyContract.RequireArgumentNotNull( OriginalObject, "Provided object at index " + Index ); GenericRegisterObject(OriginalObject, objectsArePrefabs, initialisationCallback, Index); } //Debug.Log("Registered indices: " + PrintRegistry()); }
CreateFreshUIComponentSetupCallback (Transform parentTransform, List <GameObject> prefabs, InitialisationDelegate breakpointRegistrationCallback) { return(delegate(GameObject NewObj, int index) { //Debug.Log( // "Setting up fresh UI component with elementid " // + NewObj // .GetComponent<UIComponentStem>() // .ElementIdentifier //); RectTransform NewTransform = NewObj.GetComponent <RectTransform>(); RectTransform PrefabTransform = prefabs[index].GetComponent <RectTransform>(); MyContract.RequireArgumentNotNull(NewTransform, "Prefab's RectTransform"); MyContract.RequireArgumentNotNull(PrefabTransform, "Prefab's RectTransform"); NewTransform.SetParent(parentTransform, false); // don't know why but special case UIElements NewElementId = NewObj .GetComponent <UIComponentStem>() .ElementIdentifier; if (NewElementId == UIElements.SettingsMenu || NewElementId == UIElements.Scoreboard) { NewTransform.anchorMin = PrefabTransform.anchorMin; NewTransform.anchorMax = PrefabTransform.anchorMax; NewTransform.offsetMin = PrefabTransform.offsetMin; NewTransform.offsetMax = PrefabTransform.offsetMax; } NewTransform.localScale = new Vector3(1, 1, 1); breakpointRegistrationCallback(NewObj, index); }); }
GenericRegisterObject (RegisteredType objectToRegister, bool objectIsAPrefab, InitialisationDelegate initialisationCallback, int Index);