static void GetUINotificationsReferences() { if (!DUI.DUISettings.HierarchyManager_UINotification_ShowIcon) { return; } uiNotificationIDs.Clear(); for (int i = 0; i < allTheGameObjectsInScene.Length; i++) { uin = null; uin = allTheGameObjectsInScene[i].GetComponent <UINotification>(); if (uin == null) { continue; } uiNotificationIDs.Add(allTheGameObjectsInScene[i].GetInstanceID(), uin); } }
/// <summary> /// Loads the notification by instatiating the prefab and doing the initial setup to it /// </summary> private UINotification LoadNotification(UINotification.NotificationData nData) { GameObject notification = null; UINotification componentReference = null; string targetCanvasName; UICanvas targetCanvas; if (nData.prefab != null) //we have a prefab reference { componentReference = nData.prefab.GetComponent <UINotification>(); if (componentReference == null) //make sure the notification gameobject has an UINotification component attached (this is a fail safe in case the developer links the wrong prefab) { Debug.Log("[DoozyUI] [SetupNotification] [Error]: The notification prefab named " + notification.name + " does not have an UINotification component attached. Check if this prefab is really a notification or not."); return(null); } targetCanvasName = (string.IsNullOrEmpty(componentReference.targetCanvasName) || componentReference.targetCanvasName.Equals(UICanvas.DEFAULT_CANVAS_NAME)) //make sure the target canvas name is not an empty string ? DUI.DEFAULT_CANVAS_NAME : componentReference.targetCanvasName; targetCanvas = UIManager.GetCanvas(targetCanvasName); notification = Instantiate(nData.prefab, targetCanvas.transform.position, Quaternion.identity); } else if (!string.IsNullOrEmpty(nData.prefabName)) //we don't have a prefab reference and we check if we have a prefabName we should be looking for in Resources { if (GetUINotification(nData.prefabName) != null) //look for the notification in the UI Notification manager { componentReference = GetUINotification(nData.prefabName); targetCanvasName = (string.IsNullOrEmpty(componentReference.targetCanvasName) || componentReference.targetCanvasName.Equals(UICanvas.DEFAULT_CANVAS_NAME)) //make sure the target canvas name is not an empty string ? DUI.DEFAULT_CANVAS_NAME : componentReference.targetCanvasName; targetCanvas = UIManager.GetCanvas(targetCanvasName); notification = Instantiate(GetUINotification(nData.prefabName).gameObject, targetCanvas.transform.position, Quaternion.identity); } else // the notification does not exist in the UINotification --> look for it in the resources { GameObject notificationPrefab = null; //look for the notification prefab; do this in a 'try catch' just in case the name was mispelled or the prefab does not exist try { notificationPrefab = Resources.Load(nData.prefabName) as GameObject; } catch (UnityException e) { Debug.Log("[DoozyUI] [SetupNotification] [Error]: " + e); } if (notificationPrefab == null) { Debug.Log("[DoozyUI] [SetupNotification]: The notification named [" + nData.prefabName + "] prefab does not exist or is not located under a Resources folder"); return(null); } componentReference = notificationPrefab.GetComponent <UINotification>(); if (componentReference == null) //make sure the notification gameobject has an UINotification component attached (this is a fail safe in case the developer links the wrong prefab) { Debug.Log("[DoozyUI] [SetupNotification] [Error]: The notification prefab named " + notification.name + " does not have an UINotification component attached. Check if this prefab is really a notification or not."); return(null); } targetCanvasName = (string.IsNullOrEmpty(componentReference.targetCanvasName) || componentReference.targetCanvasName.Equals(UICanvas.DEFAULT_CANVAS_NAME)) //make sure the target canvas name is not an empty string ? DUI.DEFAULT_CANVAS_NAME : componentReference.targetCanvasName; targetCanvas = UIManager.GetCanvas(targetCanvasName); notification = Instantiate(notificationPrefab, targetCanvas.transform.position, Quaternion.identity); } } else //the developer didn't link a prefab, nor did he set a prefabName; this is a fail safe option { Debug.Log("[DoozyUI] [SetupNotification] [Error]: You are trying to show a notification, but you didn't set neither a prefab reference, nor a prefabName. This is a fail safe debug log. Check your ShowNotification method call and fix this."); return(null); } if (notification.GetComponent <UINotification>() == null) //make sure the notification gameobject has an UINotification component attached (this is a fail safe in case the developer links the wrong prefab) { Debug.Log("[DoozyUI] [SetupNotification] [Error]: The notification prefab named " + notification.name + " does not have an UINotification component attached. Check if this prefab is really a notification or not."); return(null); } notification.transform.SetParent(targetCanvas.transform, false); notification.gameObject.layer = notification.transform.parent.gameObject.layer; //set the physics layer (just in case the camera is set to see another layer) UIManager.UpdateCanvasSortingLayerName(notification.gameObject, targetCanvas.Canvas.sortingLayerName); //update the sorting layers for all the canvases (just in case) UIManager.UpdateRendererSortingLayerName(notification.gameObject, targetCanvas.Canvas.sortingLayerName); //update the sorting layers for all the rendereres (just in case) RectTransform rt = notification.GetComponent <RectTransform>(); rt.anchoredPosition = targetCanvas.RectTransform.anchoredPosition; if (targetCanvas.Canvas.renderMode == RenderMode.ScreenSpaceOverlay) { rt.offsetMin = Vector2.zero; rt.offsetMax = Vector2.zero; } notification.GetComponent <UINotification>().ShowNotification(nData, targetCanvas); return(notification.GetComponent <UINotification>()); }