static void CreateCanvas(UnityEditor.MenuCommand menuCommand) { string canvasName = MASTER_CANVAS_NAME; UICanvas[] searchResults = FindObjectsOfType <UICanvas>(); if (searchResults != null && searchResults.Length > 0) { bool renameRequired = true; int canvasCount = 0; while (renameRequired) { renameRequired = false; for (int i = 0; i < searchResults.Length; i++) { if (canvasName.Equals(searchResults[i].canvasName)) { canvasCount++; canvasName = "UICanvas " + canvasCount; renameRequired = true; break; } } } } UICanvas canvas = UIManager.CreateCanvas(canvasName); UnityEditor.Undo.RegisterCreatedObjectUndo(canvas.gameObject, "Create " + canvas.gameObject.name); UnityEditor.Selection.activeObject = canvas.gameObject; }
/// <summary> /// Creates an UICanvas with the given canvas name and retuns the reference to it. /// </summary> /// <param name="canvasName">The canvas name for the new UICanvas.</param> /// <returns></returns> public static UICanvas CreateCanvas(string canvasName) { //Look for the EventSystem EventSystem es = GameObject.FindObjectOfType <EventSystem>(); if (es != null) { es.transform.SetParent(null); } else { new GameObject("EventSystem", typeof(EventSystem), typeof(StandaloneInputModule)); } if (string.IsNullOrEmpty(canvasName)) { Debug.Log("[DoozyUI] You cannot create a new UICanvas without entering a name. The canvasName you provided, when calling CreateCanvas, was an empty string. No canvas was created and this method returned null."); return(null); } if (Database.ContainsKey(canvasName)) { if (UIManager.Instance.debugUICanvases) { Debug.Log("[DoozyUI] Cannot create a new UICanvas with the '" + canvasName + "' canvas name because another UICanvas with the same name already exists in the Database. Returned the existing one instead."); } return(Database[canvasName]); } GameObject go = new GameObject(canvasName, typeof(RectTransform), typeof(Canvas), typeof(CanvasScaler), typeof(GraphicRaycaster)); go.GetComponent <Canvas>().renderMode = RenderMode.ScreenSpaceOverlay; UICanvas canvas = go.AddComponent <UICanvas>(); canvas.canvasName = canvasName; canvas.customCanvasName = true; return(canvas); }
static void GetUICanvasesReferences() { if (!DUI.DUISettings.HierarchyManager_UICanvas_Enabled) { return; } uiCanvasIDs.Clear(); for (int i = 0; i < allTheGameObjectsInScene.Length; i++) { uic = null; uic = allTheGameObjectsInScene[i].GetComponent <UICanvas>(); if (uic == null) { continue; } uiCanvasIDs.Add(allTheGameObjectsInScene[i].GetInstanceID(), uic); } }
static void CreateElement(UnityEditor.MenuCommand menuCommand) { UICanvas targetCanvas = null; GameObject selectedGO = menuCommand.context as GameObject; if (selectedGO != null) //check that a gameObject is selected { targetCanvas = selectedGO.GetComponent <UICanvas>(); //check if the selected gameObject is an UICanvas, otherwise get the root and check if (targetCanvas == null) { targetCanvas = selectedGO.transform.root.GetComponent <UICanvas>(); //check if there is an UICanvas on the root of the selected gameOhject } } if (targetCanvas == null) //because we did not find any UICanvas on the selected gameObject (or on it's root transform), we get the MasterCanvas; if the MasterCanvas does not exist, it will be created automatically by the system { targetCanvas = UIManager.GetMasterCanvas(); } GameObject go = new GameObject("UIElement", typeof(RectTransform), typeof(UIElement)); UnityEditor.GameObjectUtility.SetParentAndAlign(go, targetCanvas.gameObject); UnityEditor.Undo.RegisterCreatedObjectUndo(go, "Create " + go.name); go.GetComponent <UIElement>().Reset(); go.GetComponent <RectTransform>().localScale = Vector3.one; go.GetComponent <RectTransform>().anchorMin = Vector2.zero; go.GetComponent <RectTransform>().anchorMax = Vector2.one; go.GetComponent <RectTransform>().sizeDelta = Vector2.zero; go.GetComponent <RectTransform>().pivot = new Vector2(0.5f, 0.5f); GameObject background = new GameObject("Background", typeof(RectTransform), typeof(Image)); UnityEditor.GameObjectUtility.SetParentAndAlign(background, go); background.GetComponent <RectTransform>().localScale = Vector3.one; background.GetComponent <RectTransform>().anchorMin = Vector2.zero; background.GetComponent <RectTransform>().anchorMax = Vector2.one; background.GetComponent <RectTransform>().sizeDelta = Vector2.zero; background.GetComponent <RectTransform>().pivot = new Vector2(0.5f, 0.5f); background.GetComponent <Image>().sprite = DUI.Background; background.GetComponent <Image>().type = Image.Type.Sliced; background.GetComponent <Image>().fillCenter = true; background.GetComponent <Image>().color = new Color(31f / 255f, 136f / 255f, 201f / 255f, 100f / 255f); UnityEditor.Selection.activeObject = go; }
static void CreateElement(UnityEditor.MenuCommand menuCommand) { UICanvas targetCanvas = null; GameObject selectedGO = menuCommand.context as GameObject; if (selectedGO != null) //check that a gameObject is selected { targetCanvas = selectedGO.GetComponent <UICanvas>(); //check if the selected gameObject is an UICanvas, otherwise get the root and check if (targetCanvas == null) { targetCanvas = selectedGO.transform.root.GetComponent <UICanvas>(); //check if there is an UICanvas on the root of the selected gameOhject } } if (targetCanvas == null) //because we did not find any UICanvas on the selected gameObject (or on it's root transform), we get the MasterCanvas; if the MasterCanvas does not exist, it will be created automatically by the system { targetCanvas = UIManager.GetMasterCanvas(); } GameObject go = new GameObject("New UIElement", typeof(RectTransform), typeof(UIElement)); UnityEditor.GameObjectUtility.SetParentAndAlign(go, targetCanvas.gameObject); UnityEditor.Undo.RegisterCreatedObjectUndo(go, "Create " + go.name); go.GetComponent <UIElement>().Reset(); UnityEditor.Selection.activeObject = go; }
/// <summary> /// Returns a reference to an UICanvas that is considered and used as a 'MasterCanvas'. If no such canvas exists, one will get created automatically by default. /// </summary> /// <param name="createMasterCanvasIfNotFound">Should a 'MasterCanvas' be created if it is missing.</param> public static UICanvas GetMasterCanvas(bool createMasterCanvasIfNotFound = true) { if (masterCanvas != null) { return(masterCanvas); } //MasterCanvas has already been found if (Database.Count == 0) //CanvasDatabase is empty -> check if there is an UICanvas named MasterCanvas, in the scene, that did not register (sanity check) { UICanvas[] searchResults = FindObjectsOfType <UICanvas>(); //Look for the MasterCanvas using find (inefficient, but necessary) int searchResultsLength = searchResults.Length; if (searchResults != null && searchResultsLength > 0) { for (int i = 0; i < searchResultsLength; i++) { if (searchResults[i].canvasName == MASTER_CANVAS_NAME) { masterCanvas = searchResults[i]; return(masterCanvas); } } } } else if (Database.ContainsKey(MASTER_CANVAS_NAME)) //Check CanvasDatabase for the MasterCanvas { masterCanvas = Database[MASTER_CANVAS_NAME]; return(masterCanvas); } //MasterCanvas not found! if (!createMasterCanvasIfNotFound) { return(null); } //Create a MasterCanvas masterCanvas = CreateCanvas(MASTER_CANVAS_NAME); return(masterCanvas); }
/// <summary> /// Shows the notification taking into account the NotificationData value. /// </summary> public void ShowNotification(NotificationData ndata, UICanvas targetCanvas) { foreach (Transform t in transform) //in case we have a child that is not on the proper layer, we set it here so it shows up in the target camera { t.gameObject.layer = gameObject.layer; Canvas c = t.gameObject.GetComponent <Canvas>(); if (c != null) { c.sortingLayerName = targetCanvas.Canvas.sortingLayerName; c.overrideSorting = true; c.sortingOrder += 10000; } Renderer r = t.gameObject.GetComponent <Renderer>(); if (r != null) { r.sortingLayerName = targetCanvas.Canvas.sortingLayerName; r.sortingOrder += 10000; } } data = ndata; //we save this data to use it if we need to unregister from the Notification Queue if (icon != null && ndata.icon != null) //if this notification has an icon slot and the show notification passed a new icon, we update it { icon.sprite = ndata.icon; } if (ndata.buttonTexts == null || ndata.buttonTexts.Length == 0) { closeOnClick = true; //if there are no button texts we let the user close this notification just by ckicking it } if (ndata.buttonNames == null || ndata.buttonNames.Length == 0) { closeOnClick = true; //if there are no button names we let the user close this notification just by ckicking it } if (closeButton != null && closeOnClick) //if we linked the closeOnClickButton, we configure it to close the notification window on click { UIButton b = closeButton.GetComponent <UIButton>(); float onClickDelay = 0f; if (b != null) //we check if we have an UIButton attached (we do this so that if the button has an onClick animation, we show it and after that we hide the notification) { onClickDelay = b.onClickPunch.TotalDuration; //this creates a more pleasent user experience (UX) by letthing the OnClick animation play before hiding the notification } closeButton.onClick.AddListener(() => { StartCoroutine(HideNotification(onClickDelay)); //Destroy(gameObject, GetOutAnimationsTimeAndDelay() + onClickDelay); //we destroy this notification after the Out animation finished StartCoroutine(DestroyAfterTime(GetOutAnimationsTimeAndDelay() + onClickDelay)); }); } if (ndata.lifetime > 0) //We look for the lifetime (if it's -1 we do not auto hide the notification. We wait for the player to hit a button. { StartCoroutine(HideNotification(GetInAnimationsTimeAndDelay() + ndata.lifetime)); //Destroy(gameObject, GetInAnimationsTimeAndDelay() + ndata.lifetime + GetOutAnimationsTimeAndDelay()); //We wait for the in animations + the specified lifetime + the out animations and then we destroy the object StartCoroutine(DestroyAfterTime(GetInAnimationsTimeAndDelay() + ndata.lifetime + GetOutAnimationsTimeAndDelay())); } if (UIManager.usesTMPro) //If we are using the TextMeshPro plugin we will look for TextMeshProUGUI component otherwise we look for the native Text component { #if dUI_TextMeshPro if (this.title != null) { this.title.GetComponent <TMPro.TextMeshProUGUI>().text = ndata.title; } if (this.message != null) { this.message.GetComponent <TMPro.TextMeshProUGUI>().text = ndata.message; } #endif } else { if (this.title != null) { this.title.GetComponent <Text>().text = ndata.title; } if (this.message != null) { this.message.GetComponent <Text>().text = ndata.message; } } if (buttons != null && ndata.buttonNames != null) //If this notification prefab has buttons and buttonNames is not null (those are the buttonNames we are listening for) we start adding the buttons { for (int i = 0; i < buttons.Length; i++) { var index = i; buttons[i].GetComponent <Button>().onClick.AddListener(() => { if (ndata.buttonCallback != null && index < ndata.buttonCallback.Length && ndata.buttonCallback[index] != null) { ndata.buttonCallback[index].Invoke(); } StartCoroutine(HideNotification(0.2f)); StartCoroutine(DestroyAfterTime(GetOutAnimationsTimeAndDelay() + 0.2f)); //We destroy this notification after the Out animation finished }); if (ndata.buttonNames.Length > i && string.IsNullOrEmpty(ndata.buttonNames[i]) == false) //If we have a buttonName we make the button active and set the buttonName to the UIButton compoenent { buttons[i].gameObject.SetActive(true); buttons[i].buttonName = ndata.buttonNames[i]; //We set the buttonName if (ndata.buttonTexts != null) //We might not have a text for the button (it might be an image or an icon) so we check if we wanted a text on it { if (ndata.buttonTexts.Length > i && !string.IsNullOrEmpty(ndata.buttonTexts[i])) { if (UIManager.usesTMPro) { #if dUI_TextMeshPro if (buttons[i].GetComponentInChildren <TMPro.TextMeshProUGUI>() != null) { buttons[i].GetComponentInChildren <TMPro.TextMeshProUGUI>().text = ndata.buttonTexts[i]; } #endif } else { if (buttons[i].GetComponentInChildren <Text>() != null) { buttons[i].GetComponentInChildren <Text>().text = ndata.buttonTexts[i]; } } } } } else { buttons[i].gameObject.SetActive(false); //if we still have unused buttons on this notification prefab, we hide them } } } UIManager.ShowUiElement(notificationName); }
static void CreateNotification(UnityEditor.MenuCommand menuCommand) { UICanvas targetCanvas = null; GameObject selectedGO = menuCommand.context as GameObject; if (selectedGO != null) //check that a gameObject is selected { targetCanvas = selectedGO.GetComponent <UICanvas>(); //check if the selected gameObject is an UICanvas, otherwise get the root and check if (targetCanvas == null) { targetCanvas = selectedGO.transform.root.GetComponent <UICanvas>(); //check if there is an UICanvas on the root of the selected gameOhject } } if (targetCanvas == null) //because we did not find any UICanvas on the selected gameObject (or on it's root transform), we get the MasterCanvas; if the MasterCanvas does not exist, it will be created automatically by the system { targetCanvas = UIManager.GetMasterCanvas(); } GameObject notification = new GameObject("New UINotification", typeof(RectTransform), typeof(UINotification)); UnityEditor.GameObjectUtility.SetParentAndAlign(notification, targetCanvas.gameObject); notification.GetComponent <UINotification>().Reset(); UnityEditor.Undo.RegisterCreatedObjectUndo(notification, "Create " + notification.name); GameObject overlay = new GameObject("UIE - Background Overlay", typeof(RectTransform), typeof(UIElement)); UnityEditor.GameObjectUtility.SetParentAndAlign(overlay, notification); overlay.GetComponent <UIElement>().Reset(); overlay.GetComponent <UIElement>().inAnimationsPresetCategoryName = "Basic"; overlay.GetComponent <UIElement>().inAnimationsPresetName = "QuickFadeIn"; overlay.GetComponent <UIElement>().loadInAnimationsPresetAtRuntime = true; overlay.GetComponent <UIElement>().outAnimationsPresetCategoryName = "Basic"; overlay.GetComponent <UIElement>().outAnimationsPresetName = "QuickFadeOut"; overlay.GetComponent <UIElement>().loadOutAnimationsPresetAtRuntime = true; overlay.GetComponent <UIElement>().Canvas.sortingOrder = 0; GameObject overlayBackground = new GameObject("Background", typeof(RectTransform), typeof(Image)); UnityEditor.GameObjectUtility.SetParentAndAlign(overlayBackground, overlay); overlayBackground.GetComponent <RectTransform>().localScale = new Vector3(1, 1, 1); overlayBackground.GetComponent <RectTransform>().anchorMin = new Vector2(0, 0); overlayBackground.GetComponent <RectTransform>().anchorMax = new Vector2(1, 1); overlayBackground.GetComponent <RectTransform>().anchoredPosition = new Vector2(0, 0); overlayBackground.GetComponent <RectTransform>().sizeDelta = new Vector2(0, 0); overlayBackground.GetComponent <RectTransform>().pivot = new Vector2(0.5f, 0.5f); overlayBackground.GetComponent <Image>().color = new Color(0f, 0f, 0f, 0.6f); GameObject notificationContainer = new GameObject("UIE - Notification Container", typeof(RectTransform), typeof(UIElement), typeof(Button)); UnityEditor.GameObjectUtility.SetParentAndAlign(notificationContainer, notification); notificationContainer.GetComponent <Button>().transition = Selectable.Transition.None; notificationContainer.GetComponent <UIElement>().Reset(); notificationContainer.GetComponent <UIElement>().inAnimationsPresetCategoryName = "Basic"; notificationContainer.GetComponent <UIElement>().inAnimationsPresetName = "PunchIn"; notificationContainer.GetComponent <UIElement>().loadInAnimationsPresetAtRuntime = true; notificationContainer.GetComponent <UIElement>().outAnimationsPresetCategoryName = "Basic"; notificationContainer.GetComponent <UIElement>().outAnimationsPresetName = "PunchOut"; notificationContainer.GetComponent <UIElement>().loadOutAnimationsPresetAtRuntime = true; notificationContainer.GetComponent <UIElement>().Canvas.sortingOrder = 1; notificationContainer.GetComponent <RectTransform>().localScale = Vector3.one; notificationContainer.GetComponent <RectTransform>().anchorMin = new Vector2(0.5f, 0.5f); notificationContainer.GetComponent <RectTransform>().anchorMax = new Vector2(0.5f, 0.5f); notificationContainer.GetComponent <RectTransform>().anchoredPosition = new Vector2(0, 0); notificationContainer.GetComponent <RectTransform>().sizeDelta = new Vector2(512f, 256f); notificationContainer.GetComponent <RectTransform>().pivot = new Vector2(0.5f, 0.5f); GameObject notificationContainerBackground = new GameObject("Background", typeof(RectTransform), typeof(Image)); UnityEditor.GameObjectUtility.SetParentAndAlign(notificationContainerBackground, notificationContainer); notificationContainerBackground.GetComponent <RectTransform>().localScale = new Vector3(1, 1, 1); notificationContainerBackground.GetComponent <RectTransform>().anchorMin = new Vector2(0, 0); notificationContainerBackground.GetComponent <RectTransform>().anchorMax = new Vector2(1, 1); notificationContainerBackground.GetComponent <RectTransform>().anchoredPosition = new Vector2(0, 0); notificationContainerBackground.GetComponent <RectTransform>().sizeDelta = new Vector2(0, 0); notificationContainerBackground.GetComponent <RectTransform>().pivot = new Vector2(0.5f, 0.5f); notificationContainerBackground.GetComponent <Image>().color = ColorExtensions.ColorFrom256(15, 73, 108, 256); GameObject notificationTitleContainer = new GameObject("Notification Title Container", typeof(RectTransform), typeof(Image), typeof(Shadow)); UnityEditor.GameObjectUtility.SetParentAndAlign(notificationTitleContainer, notificationContainer); notificationTitleContainer.GetComponent <RectTransform>().localScale = new Vector3(1, 1, 1); notificationTitleContainer.GetComponent <RectTransform>().anchorMin = new Vector2(0, 1); notificationTitleContainer.GetComponent <RectTransform>().anchorMax = new Vector2(1, 1); notificationTitleContainer.GetComponent <RectTransform>().anchoredPosition = new Vector2(0, -28); notificationTitleContainer.GetComponent <RectTransform>().sizeDelta = new Vector2(16, 56); notificationTitleContainer.GetComponent <RectTransform>().pivot = new Vector2(0.5f, 1f); GameObject notificationTitle = new GameObject("Notification Title", typeof(RectTransform), typeof(Text)); UnityEditor.GameObjectUtility.SetParentAndAlign(notificationTitle, notificationTitleContainer); notificationTitle.GetComponent <RectTransform>().localScale = new Vector3(1, 1, 1); notificationTitle.GetComponent <RectTransform>().anchorMin = new Vector2(0, 0); notificationTitle.GetComponent <RectTransform>().anchorMax = new Vector2(1, 1); notificationTitle.GetComponent <RectTransform>().anchoredPosition = new Vector2(0, 0); notificationTitle.GetComponent <RectTransform>().sizeDelta = new Vector2(-32, -16); notificationTitle.GetComponent <RectTransform>().pivot = new Vector2(0.5f, 0.5f); notificationTitle.GetComponent <Text>().color = ColorExtensions.ColorFrom256(15, 70, 105, 256); notificationTitle.GetComponent <Text>().fontSize = 14; notificationTitle.GetComponent <Text>().fontStyle = FontStyle.Bold; notificationTitle.GetComponent <Text>().resizeTextForBestFit = true; notificationTitle.GetComponent <Text>().resizeTextMinSize = 14; notificationTitle.GetComponent <Text>().resizeTextMaxSize = 40; notificationTitle.GetComponent <Text>().alignment = TextAnchor.MiddleCenter; notificationTitle.GetComponent <Text>().alignByGeometry = true; notificationTitle.GetComponent <Text>().supportRichText = true; notificationTitle.GetComponent <Text>().text = "notification title"; GameObject notificationMessage = new GameObject("Notification Message", typeof(RectTransform), typeof(Text)); UnityEditor.GameObjectUtility.SetParentAndAlign(notificationMessage, notificationContainer); notificationMessage.GetComponent <RectTransform>().localScale = new Vector3(1, 1, 1); notificationMessage.GetComponent <RectTransform>().anchorMin = new Vector2(0, 0); notificationMessage.GetComponent <RectTransform>().anchorMax = new Vector2(1, 1); notificationMessage.GetComponent <RectTransform>().anchoredPosition = new Vector2(0, -48); notificationMessage.GetComponent <RectTransform>().sizeDelta = new Vector2(-48, -128); notificationMessage.GetComponent <RectTransform>().pivot = new Vector2(0.5f, 0.5f); notificationMessage.GetComponent <Text>().fontSize = 14; notificationMessage.GetComponent <Text>().fontStyle = FontStyle.Italic; notificationMessage.GetComponent <Text>().resizeTextForBestFit = true; notificationMessage.GetComponent <Text>().resizeTextMinSize = 24; notificationMessage.GetComponent <Text>().resizeTextMaxSize = 28; notificationMessage.GetComponent <Text>().alignment = TextAnchor.MiddleCenter; notificationMessage.GetComponent <Text>().alignByGeometry = true; notificationMessage.GetComponent <Text>().supportRichText = true; notificationMessage.GetComponent <Text>().text = "notification message example"; notification.GetComponent <UINotification>().notificationContainer = notificationContainer.GetComponent <UIElement>(); notification.GetComponent <UINotification>().overlay = overlay.GetComponent <UIElement>(); notification.GetComponent <UINotification>().title = notificationTitle; notification.GetComponent <UINotification>().message = notificationMessage; notification.GetComponent <UINotification>().closeButton = notificationContainer.GetComponent <Button>(); UnityEditor.Selection.activeObject = notification; }
static void HierarchyCustomizer(int instanceID, Rect selectionRect) { if (!DUI.DUISettings.HierarchyManager_Enabled) { return; } string label = ""; float labelWidth = 0; Rect rect = new Rect(selectionRect); rect.x = rect.xMax - iconWidth; rect.width = iconWidth; rect.height = iconHeight; #if dUI_PlayMaker if (DUI.DUISettings.HierarchyManager_PlaymakerEventDispatcher_ShowIcon && playmakerEventDispatcherIDs.ContainsKey(instanceID) && playmakerEventDispatcherIDs[instanceID] != null) { GUI.Label(rect, DUIResources.iconPlayMakerEventDispatcher128x128.texture); rect.x -= iconWidth; } #endif if (DUI.DUISettings.HierarchyManager_UITrigger_ShowIcon && uiTriggerIDs.ContainsKey(instanceID) && uiTriggerIDs[instanceID] != null) { GUI.Label(rect, DUIResources.iconUITrigger128x128.texture); rect.x -= iconWidth; } if (DUI.DUISettings.HierarchyManager_UIManager_ShowIcon && UIManagerID == instanceID) { GUI.Label(rect, DUIResources.iconUIManager128x128.texture); rect.x -= iconWidth; } if (DUI.DUISettings.HierarchyManager_Soundy_ShowIcon && SoundyID == instanceID) { GUI.Label(rect, DUIResources.iconSoundy128x128.texture); rect.x -= iconWidth; } if (DUI.DUISettings.HierarchyManager_UINotificationManager_ShowIcon && UINotificationManagerID == instanceID) { GUI.Label(rect, DUIResources.iconUINotificationManager128x128.texture); rect.x -= iconWidth; } if (DUI.DUISettings.HierarchyManager_OrientationManager_ShowIcon && OrientationManagerID == instanceID) { GUI.Label(rect, DUIResources.iconOrientationManager128x128.texture); rect.x -= iconWidth; } if (DUI.DUISettings.HierarchyManager_SceneLoader_ShowIcon && SceneLoaderID == instanceID) { GUI.Label(rect, DUIResources.iconSceneLoader128x128.texture); rect.x -= iconWidth; } if (DUI.DUISettings.HierarchyManager_UICanvas_Enabled && uiCanvasIDs.ContainsKey(instanceID) && uiCanvasIDs[instanceID] != null) { if (DUI.DUISettings.HierarchyManager_UICanvas_ShowIcon) { GUI.Label(rect, DUIResources.iconUICanvas128x128.texture); } else { rect.x += iconWidth; } UICanvas uic = uiCanvasIDs[instanceID]; label = ""; label = (DUI.DUISettings.HierarchyManager_UICanvas_ShowCanvasName ? "[ " + uic.canvasName + " ]" : "") + (DUI.DUISettings.HierarchyManager_UICanvas_ShowSortingLayerNameAndOrder ? " " + uic.Canvas.sortingLayerName + " " + uic.Canvas.sortingOrder : ""); if (!string.IsNullOrEmpty(label)) { labelWidth = DUIStyles.GetStyle(DUIStyles.TextStyle.LabelSmall).CalcSize(new GUIContent(label)).x; rect.x -= labelWidth; rect.width = labelWidth; GUI.Label(rect, label, DUIStyles.GetStyle(DUIStyles.TextStyle.LabelSmall)); } } if (DUI.DUISettings.HierarchyManager_UIButton_Enabled && uiButtonIDs.ContainsKey(instanceID) && uiButtonIDs[instanceID] != null) { if (DUI.DUISettings.HierarchyManager_UIButton_ShowIcon) { GUI.Label(rect, DUIResources.iconUIButton128x128.texture); } else { rect.x += iconWidth; } UIButton uib = uiButtonIDs[instanceID]; label = ""; label = (DUI.DUISettings.HierarchyManager_UIButton_ShowButtonCategory ? "[ " + uib.buttonCategory + " ]" : "") + (DUI.DUISettings.HierarchyManager_UIButton_ShowButtonName ? "[ " + uib.buttonName + " ]" : ""); if (!string.IsNullOrEmpty(label)) { labelWidth = DUIStyles.GetStyle(DUIStyles.TextStyle.LabelSmall).CalcSize(new GUIContent(label)).x; rect.x -= labelWidth; rect.width = labelWidth; GUI.Label(rect, label, DUIStyles.GetStyle(DUIStyles.TextStyle.LabelSmall)); } } if (DUI.DUISettings.HierarchyManager_UINotification_ShowIcon && uiNotificationIDs.ContainsKey(instanceID)) { GUI.Label(rect, DUIResources.iconUINotification128x128.texture); rect.x -= iconWidth; } if (DUI.DUISettings.HierarchyManager_UIElement_Enabled && uiElementIDs.ContainsKey(instanceID) && uiElementIDs[instanceID] != null) { if (DUI.DUISettings.HierarchyManager_UIElement_ShowIcon) { GUI.Label(rect, DUIResources.iconUIElement128x128.texture); } else { rect.x += iconWidth; } UIElement uie = uiElementIDs[instanceID]; label = ""; if (uie.linkedToNotification) { label = "linked to notification"; } else { label = (DUI.DUISettings.HierarchyManager_UIElement_ShowElementCategory ? "[ " + uie.elementCategory + " ]" : "") + (DUI.DUISettings.HierarchyManager_UIElement_ShowElementName ? "[ " + uie.elementName + " ]" : "") + (DUI.DUISettings.HierarchyManager_UIElement_ShowSortingLayerNameAndOrder ? " " + uie.Canvas.sortingLayerName + " " + uie.Canvas.sortingOrder : ""); } if (!string.IsNullOrEmpty(label)) { labelWidth = DUIStyles.GetStyle(DUIStyles.TextStyle.LabelSmall).CalcSize(new GUIContent(label)).x; rect.x -= labelWidth; rect.width = labelWidth; GUI.Label(rect, label, DUIStyles.GetStyle(DUIStyles.TextStyle.LabelSmall)); } } if (DUI.DUISettings.HierarchyManager_UIEffect_Enabled && uiEffectIDs.ContainsKey(instanceID) && uiEffectIDs[instanceID] != null) { if (DUI.DUISettings.HierarchyManager_UIEffect_ShowIcon) { GUI.Label(rect, DUIResources.iconUIEffect128x128.texture); } else { rect.x += iconWidth; } UIEffect uie = uiEffectIDs[instanceID]; if (DUI.DUISettings.HierarchyManager_UIEffect_ShowSortingLayerNameAndOrder) { if (uie.targetUIElement != null) { if (uie.targetUIElement.linkedToNotification) { label = "linked to notification"; } else { label = (uie.useCustomSortingLayerName ? uie.customSortingLayerName : uie.targetUIElement.Canvas.overrideSorting ? uie.targetUIElement.Canvas.sortingLayerName : uie.targetUIElement.Canvas.rootCanvas.sortingLayerName) + " " + (uie.useCustomOrderInLayer ? uie.customOrderInLayer : uie.targetUIElement.Canvas.overrideSorting ? uie.targetUIElement.Canvas.sortingOrder : uie.targetUIElement.Canvas.rootCanvas.sortingOrder); } } else { label = "DISABLED"; } labelWidth = DUIStyles.GetStyle(DUIStyles.TextStyle.LabelSmall).CalcSize(new GUIContent(label)).x; rect.x -= labelWidth; rect.width = labelWidth; GUI.Label(rect, label, DUIStyles.GetStyle(DUIStyles.TextStyle.LabelSmall)); } } }
static void CreateNotification(UnityEditor.MenuCommand menuCommand) { UICanvas targetCanvas = null; GameObject selectedGO = menuCommand.context as GameObject; if (selectedGO != null) //check that a gameObject is selected { targetCanvas = selectedGO.GetComponent <UICanvas>(); //check if the selected gameObject is an UICanvas, otherwise get the root and check if (targetCanvas == null) { targetCanvas = selectedGO.transform.root.GetComponent <UICanvas>(); //check if there is an UICanvas on the root of the selected gameOhject } } if (targetCanvas == null) //because we did not find any UICanvas on the selected gameObject (or on it's root transform), we get the MasterCanvas; if the MasterCanvas does not exist, it will be created automatically by the system { targetCanvas = UIManager.GetMasterCanvas(); } GameObject notification = new GameObject("UINotification", typeof(RectTransform), typeof(UINotification)); UnityEditor.GameObjectUtility.SetParentAndAlign(notification, targetCanvas.gameObject); notification.GetComponent <UINotification>().Reset(); UnityEditor.Undo.RegisterCreatedObjectUndo(notification, "Create " + notification.name); GameObject overlay = new GameObject("UIE - Background Overlay", typeof(RectTransform), typeof(UIElement)); UnityEditor.GameObjectUtility.SetParentAndAlign(overlay, notification); overlay.GetComponent <UIElement>().Reset(); overlay.GetComponent <UIElement>().startHidden = true; overlay.GetComponent <UIElement>().inAnimationsPresetCategoryName = "Fade"; overlay.GetComponent <UIElement>().inAnimationsPresetName = "InFast"; overlay.GetComponent <UIElement>().loadInAnimationsPresetAtRuntime = true; overlay.GetComponent <UIElement>().outAnimationsPresetCategoryName = "Fade"; overlay.GetComponent <UIElement>().outAnimationsPresetName = "OutFast"; overlay.GetComponent <UIElement>().loadOutAnimationsPresetAtRuntime = true; overlay.GetComponent <UIElement>().Canvas.sortingOrder = 0; GameObject overlayBackground = new GameObject("Background", typeof(RectTransform), typeof(Image)); UnityEditor.GameObjectUtility.SetParentAndAlign(overlayBackground, overlay); overlayBackground.GetComponent <RectTransform>().localScale = new Vector3(1, 1, 1); overlayBackground.GetComponent <RectTransform>().anchorMin = new Vector2(0, 0); overlayBackground.GetComponent <RectTransform>().anchorMax = new Vector2(1, 1); overlayBackground.GetComponent <RectTransform>().anchoredPosition = new Vector2(0, 0); overlayBackground.GetComponent <RectTransform>().sizeDelta = new Vector2(0, 0); overlayBackground.GetComponent <RectTransform>().pivot = new Vector2(0.5f, 0.5f); overlayBackground.GetComponent <Image>().color = ColorExtensions.ColorFrom256(11, 50, 74, 200); GameObject notificationContainer = new GameObject("UIE - Notification Container", typeof(RectTransform), typeof(UIElement), typeof(Button)); UnityEditor.GameObjectUtility.SetParentAndAlign(notificationContainer, notification); notificationContainer.GetComponent <Button>().transition = Selectable.Transition.None; notificationContainer.GetComponent <UIElement>().Reset(); notificationContainer.GetComponent <UIElement>().startHidden = true; notificationContainer.GetComponent <UIElement>().inAnimationsPresetCategoryName = "Basic"; notificationContainer.GetComponent <UIElement>().inAnimationsPresetName = "Punch"; notificationContainer.GetComponent <UIElement>().loadInAnimationsPresetAtRuntime = true; notificationContainer.GetComponent <UIElement>().outAnimationsPresetCategoryName = "Basic"; notificationContainer.GetComponent <UIElement>().outAnimationsPresetName = "Punch"; notificationContainer.GetComponent <UIElement>().loadOutAnimationsPresetAtRuntime = true; notificationContainer.GetComponent <UIElement>().Canvas.sortingOrder = 1; notificationContainer.GetComponent <RectTransform>().localScale = Vector3.one; notificationContainer.GetComponent <RectTransform>().anchorMin = new Vector2(0.5f, 0.5f); notificationContainer.GetComponent <RectTransform>().anchorMax = new Vector2(0.5f, 0.5f); notificationContainer.GetComponent <RectTransform>().anchoredPosition = new Vector2(0, 0); notificationContainer.GetComponent <RectTransform>().sizeDelta = new Vector2(300f, 200f); notificationContainer.GetComponent <RectTransform>().pivot = new Vector2(0.5f, 0.5f); GameObject notificationContainerBackground = new GameObject("Background", typeof(RectTransform), typeof(Image)); UnityEditor.GameObjectUtility.SetParentAndAlign(notificationContainerBackground, notificationContainer); notificationContainerBackground.GetComponent <RectTransform>().localScale = new Vector3(1, 1, 1); notificationContainerBackground.GetComponent <RectTransform>().anchorMin = new Vector2(0, 0); notificationContainerBackground.GetComponent <RectTransform>().anchorMax = new Vector2(1, 1); notificationContainerBackground.GetComponent <RectTransform>().anchoredPosition = new Vector2(0, 0); notificationContainerBackground.GetComponent <RectTransform>().sizeDelta = new Vector2(0, 0); notificationContainerBackground.GetComponent <RectTransform>().pivot = new Vector2(0.5f, 0.5f); notificationContainerBackground.GetComponent <Image>().sprite = DUI.Background; notificationContainerBackground.GetComponent <Image>().type = Image.Type.Sliced; notificationContainerBackground.GetComponent <Image>().fillCenter = true; notificationContainerBackground.GetComponent <Image>().color = ColorExtensions.ColorFrom256(11, 50, 74, 255); GameObject notificationTitleContainer = new GameObject("Notification Title Container", typeof(RectTransform), typeof(Image)); UnityEditor.GameObjectUtility.SetParentAndAlign(notificationTitleContainer, notificationContainer); notificationTitleContainer.GetComponent <RectTransform>().localScale = new Vector3(1, 1, 1); notificationTitleContainer.GetComponent <RectTransform>().anchorMin = new Vector2(0, 1); notificationTitleContainer.GetComponent <RectTransform>().anchorMax = new Vector2(1, 1); notificationTitleContainer.GetComponent <RectTransform>().anchoredPosition = new Vector2(0, -16); notificationTitleContainer.GetComponent <RectTransform>().sizeDelta = new Vector2(16, 32); notificationTitleContainer.GetComponent <RectTransform>().pivot = new Vector2(0.5f, 1f); notificationTitleContainer.GetComponent <Image>().sprite = DUI.Background; notificationTitleContainer.GetComponent <Image>().type = Image.Type.Sliced; notificationTitleContainer.GetComponent <Image>().fillCenter = true; notificationTitleContainer.GetComponent <Image>().color = ColorExtensions.ColorFrom256(31, 136, 201, 255); #if dUI_TextMeshPro GameObject notificationTitle = new GameObject("Notification Title TMPro", typeof(RectTransform), typeof(TMPro.TextMeshProUGUI)); UnityEditor.GameObjectUtility.SetParentAndAlign(notificationTitle, notificationTitleContainer); notificationTitle.GetComponent <RectTransform>().localScale = new Vector3(1, 1, 1); notificationTitle.GetComponent <RectTransform>().anchorMin = new Vector2(0, 0); notificationTitle.GetComponent <RectTransform>().anchorMax = new Vector2(1, 1); notificationTitle.GetComponent <RectTransform>().anchoredPosition = new Vector2(0, 0); notificationTitle.GetComponent <RectTransform>().sizeDelta = new Vector2(-32, -8); notificationTitle.GetComponent <RectTransform>().pivot = new Vector2(0.5f, 0.5f); notificationTitle.GetComponent <TMPro.TextMeshProUGUI>().color = ColorExtensions.ColorFrom256(11, 50, 74, 255); notificationTitle.GetComponent <TMPro.TextMeshProUGUI>().fontSize = 18; notificationTitle.GetComponent <TMPro.TextMeshProUGUI>().fontStyle = TMPro.FontStyles.Bold; notificationTitle.GetComponent <TMPro.TextMeshProUGUI>().alignment = TMPro.TextAlignmentOptions.Center; notificationTitle.GetComponent <TMPro.TextMeshProUGUI>().text = "notification title"; #else GameObject notificationTitle = new GameObject("Notification Title", typeof(RectTransform), typeof(Text)); UnityEditor.GameObjectUtility.SetParentAndAlign(notificationTitle, notificationTitleContainer); notificationTitle.GetComponent <RectTransform>().localScale = new Vector3(1, 1, 1); notificationTitle.GetComponent <RectTransform>().anchorMin = new Vector2(0, 0); notificationTitle.GetComponent <RectTransform>().anchorMax = new Vector2(1, 1); notificationTitle.GetComponent <RectTransform>().anchoredPosition = new Vector2(0, 0); notificationTitle.GetComponent <RectTransform>().sizeDelta = new Vector2(-32, -4); notificationTitle.GetComponent <RectTransform>().pivot = new Vector2(0.5f, 0.5f); notificationTitle.GetComponent <Text>().color = ColorExtensions.ColorFrom256(11, 50, 74, 255); notificationTitle.GetComponent <Text>().fontSize = 14; notificationTitle.GetComponent <Text>().fontStyle = FontStyle.Bold; notificationTitle.GetComponent <Text>().resizeTextForBestFit = true; notificationTitle.GetComponent <Text>().resizeTextMinSize = 14; notificationTitle.GetComponent <Text>().resizeTextMaxSize = 40; notificationTitle.GetComponent <Text>().alignment = TextAnchor.MiddleCenter; notificationTitle.GetComponent <Text>().alignByGeometry = true; notificationTitle.GetComponent <Text>().supportRichText = true; notificationTitle.GetComponent <Text>().text = "notification title"; #endif #if dUI_TextMeshPro GameObject notificationMessage = new GameObject("Notification Message TMPro", typeof(RectTransform), typeof(TMPro.TextMeshProUGUI)); UnityEditor.GameObjectUtility.SetParentAndAlign(notificationMessage, notificationContainer); notificationMessage.GetComponent <RectTransform>().localScale = new Vector3(1, 1, 1); notificationMessage.GetComponent <RectTransform>().anchorMin = new Vector2(0, 0); notificationMessage.GetComponent <RectTransform>().anchorMax = new Vector2(1, 1); notificationMessage.GetComponent <RectTransform>().anchoredPosition = new Vector2(0, -24); notificationMessage.GetComponent <RectTransform>().sizeDelta = new Vector2(-32, -80); notificationMessage.GetComponent <RectTransform>().pivot = new Vector2(0.5f, 0.5f); notificationMessage.GetComponent <TMPro.TextMeshProUGUI>().color = ColorExtensions.ColorFrom256(31, 136, 201, 255); notificationMessage.GetComponent <TMPro.TextMeshProUGUI>().fontSize = 14; notificationMessage.GetComponent <TMPro.TextMeshProUGUI>().fontStyle = TMPro.FontStyles.Italic; notificationMessage.GetComponent <TMPro.TextMeshProUGUI>().alignment = TMPro.TextAlignmentOptions.Center; notificationMessage.GetComponent <TMPro.TextMeshProUGUI>().text = "notification message example"; #else GameObject notificationMessage = new GameObject("Notification Message", typeof(RectTransform), typeof(Text)); UnityEditor.GameObjectUtility.SetParentAndAlign(notificationMessage, notificationContainer); notificationMessage.GetComponent <RectTransform>().localScale = new Vector3(1, 1, 1); notificationMessage.GetComponent <RectTransform>().anchorMin = new Vector2(0, 0); notificationMessage.GetComponent <RectTransform>().anchorMax = new Vector2(1, 1); notificationMessage.GetComponent <RectTransform>().anchoredPosition = new Vector2(0, -24); notificationMessage.GetComponent <RectTransform>().sizeDelta = new Vector2(-48, -80); notificationMessage.GetComponent <RectTransform>().pivot = new Vector2(0.5f, 0.5f); notificationMessage.GetComponent <Text>().color = ColorExtensions.ColorFrom256(31, 136, 201, 255); notificationMessage.GetComponent <Text>().fontSize = 14; notificationMessage.GetComponent <Text>().fontStyle = FontStyle.Italic; notificationMessage.GetComponent <Text>().resizeTextForBestFit = true; notificationMessage.GetComponent <Text>().resizeTextMinSize = 12; notificationMessage.GetComponent <Text>().resizeTextMaxSize = 18; notificationMessage.GetComponent <Text>().alignment = TextAnchor.MiddleCenter; notificationMessage.GetComponent <Text>().alignByGeometry = true; notificationMessage.GetComponent <Text>().supportRichText = true; notificationMessage.GetComponent <Text>().text = "notification message example"; #endif notification.GetComponent <UINotification>().notificationContainer = notificationContainer.GetComponent <UIElement>(); notification.GetComponent <UINotification>().overlay = overlay.GetComponent <UIElement>(); notification.GetComponent <UINotification>().title = notificationTitle; notification.GetComponent <UINotification>().message = notificationMessage; notification.GetComponent <UINotification>().closeButton = notificationContainer.GetComponent <Button>(); UnityEditor.Selection.activeObject = notification; }
static void HierarchyCustomizer(int instanceID, Rect selectionRect) { if (DUI.DUISettings == null || !DUI.DUISettings.HierarchyManager_Enabled) { return; } QLabel = new QLabel("", Style.Text.Small); rect = new Rect(selectionRect); rect.x = rect.xMax - iconWidth; rect.width = iconWidth; rect.height = iconHeight; #if dUI_PlayMaker if (DUI.DUISettings.HierarchyManager_PlaymakerEventDispatcher_ShowIcon && playmakerEventDispatcherIDs.ContainsKey(instanceID) && playmakerEventDispatcherIDs[instanceID] != null) { GUI.Label(rect, DUIResources.iconPlayMakerEventDispatcher.texture); rect.x -= iconWidth; } #endif if (DUI.DUISettings.HierarchyManager_UITrigger_ShowIcon && uiTriggerIDs.ContainsKey(instanceID) && uiTriggerIDs[instanceID] != null) { GUI.Label(rect, DUIResources.iconUITrigger.texture); rect.x -= iconWidth; } if (DUI.DUISettings.HierarchyManager_UIManager_ShowIcon && UIManagerID == instanceID) { GUI.Label(rect, DUIResources.iconUIManager.texture); rect.x -= iconWidth; } if (DUI.DUISettings.HierarchyManager_Soundy_ShowIcon && SoundyID == instanceID) { GUI.Label(rect, DUIResources.iconSoundy.texture); rect.x -= iconWidth; } if (DUI.DUISettings.HierarchyManager_UINotificationManager_ShowIcon && UINotificationManagerID == instanceID) { GUI.Label(rect, DUIResources.iconUINotificationManager.texture); rect.x -= iconWidth; } if (DUI.DUISettings.HierarchyManager_OrientationManager_ShowIcon && OrientationManagerID == instanceID) { GUI.Label(rect, DUIResources.iconOrientationManager.texture); rect.x -= iconWidth; } if (DUI.DUISettings.HierarchyManager_SceneLoader_ShowIcon && SceneLoaderID == instanceID) { GUI.Label(rect, DUIResources.iconSceneLoader.texture); rect.x -= iconWidth; } if (DUI.DUISettings.HierarchyManager_UICanvas_Enabled && uiCanvasIDs.ContainsKey(instanceID) && uiCanvasIDs[instanceID] != null) { if (DUI.DUISettings.HierarchyManager_UICanvas_ShowIcon) { GUI.Label(rect, DUIResources.iconUICanvas.texture); } else { rect.x += iconWidth; } uic = uiCanvasIDs[instanceID]; QLabel.text = ""; QLabel.style = Style.Text.Small; QLabel.text = (DUI.DUISettings.HierarchyManager_UICanvas_ShowCanvasName ? "[ " + uic.canvasName + " ]" : "") + (DUI.DUISettings.HierarchyManager_UICanvas_ShowSortingLayerNameAndOrder ? " " + uic.Canvas.sortingLayerName + " " + uic.Canvas.sortingOrder : ""); if (!string.IsNullOrEmpty(QLabel.text)) { rect.x -= QLabel.x; rect.width = QLabel.x; GUI.Label(rect, QLabel.text, QStyles.GetStyle(QStyles.GetStyleName(QLabel.style))); } } if (DUI.DUISettings.HierarchyManager_UIButton_Enabled && uiButtonIDs.ContainsKey(instanceID) && uiButtonIDs[instanceID] != null) { if (DUI.DUISettings.HierarchyManager_UIButton_ShowIcon) { GUI.Label(rect, DUIResources.iconUIButton.texture); } else { rect.x += iconWidth; } uib = uiButtonIDs[instanceID]; QLabel.text = ""; QLabel.style = Style.Text.Small; QLabel.text = (DUI.DUISettings.HierarchyManager_UIButton_ShowButtonCategory ? "[ " + uib.buttonCategory + " ]" : "") + (DUI.DUISettings.HierarchyManager_UIButton_ShowButtonName ? "[ " + uib.buttonName + " ]" : ""); if (!string.IsNullOrEmpty(QLabel.text)) { rect.x -= QLabel.x; rect.width = QLabel.x; GUI.Label(rect, QLabel.text, QStyles.GetStyle(QStyles.GetStyleName(QLabel.style))); } } if (DUI.DUISettings.HierarchyManager_UINotification_ShowIcon && uiNotificationIDs.ContainsKey(instanceID)) { GUI.Label(rect, DUIResources.iconUINotification.texture); rect.x -= iconWidth; } if (DUI.DUISettings.HierarchyManager_UIElement_Enabled && uiElementIDs.ContainsKey(instanceID) && uiElementIDs[instanceID] != null) { if (DUI.DUISettings.HierarchyManager_UIElement_ShowIcon) { GUI.Label(rect, DUIResources.iconUIElement.texture); } else { rect.x += iconWidth; } uie = uiElementIDs[instanceID]; QLabel.text = ""; QLabel.style = Style.Text.Small; if (uie.linkedToNotification) { QLabel.text = "linked to notification"; } else { QLabel.text = (DUI.DUISettings.HierarchyManager_UIElement_ShowElementCategory ? "[ " + uie.elementCategory + " ]" : "") + (DUI.DUISettings.HierarchyManager_UIElement_ShowElementName ? "[ " + uie.elementName + " ]" : "") + (DUI.DUISettings.HierarchyManager_UIElement_ShowSortingLayerNameAndOrder ? " " + uie.Canvas.sortingLayerName + " " + uie.Canvas.sortingOrder : ""); } if (!string.IsNullOrEmpty(QLabel.text)) { rect.x -= QLabel.x; rect.width = QLabel.x; GUI.Label(rect, QLabel.text, QStyles.GetStyle(QStyles.GetStyleName(QLabel.style))); } } if (DUI.DUISettings.HierarchyManager_UIEffect_Enabled && uiEffectIDs.ContainsKey(instanceID) && uiEffectIDs[instanceID] != null) { if (DUI.DUISettings.HierarchyManager_UIEffect_ShowIcon) { GUI.Label(rect, DUIResources.iconUIEffect.texture); } else { rect.x += iconWidth; } uief = uiEffectIDs[instanceID]; if (DUI.DUISettings.HierarchyManager_UIEffect_ShowSortingLayerNameAndOrder) { if (uief.targetUIElement != null) { if (uief.targetUIElement.linkedToNotification) { QLabel.text = "linked to notification"; } else { QLabel.text = (uief.useCustomSortingLayerName ? uief.customSortingLayerName : uief.targetUIElement.Canvas.overrideSorting ? uief.targetUIElement.Canvas.sortingLayerName : uief.targetUIElement.Canvas.rootCanvas.sortingLayerName) + " " + (uief.useCustomOrderInLayer ? uief.customOrderInLayer : uief.targetUIElement.Canvas.overrideSorting ? uief.targetUIElement.Canvas.sortingOrder : uief.targetUIElement.Canvas.rootCanvas.sortingOrder); } } else { QLabel.text = "DISABLED"; } rect.x -= QLabel.x; rect.width = QLabel.x; GUI.Label(rect, QLabel.text, QStyles.GetStyle(QStyles.GetStyleName(QLabel.style))); } } }