/// <summary> /// Loads and creates a new UI element (e.g. SampleMessage : UIElement). /// </summary> /// <typeparam name="TUIElement">The UI element type.</typeparam> /// <param name="uiCanvasLayer">The canvas layer.</param> /// <param name="uiIndex">The UI index.</param> /// <param name="parent">The parent of the UI element.</param> /// <returns>The UI element.</returns> public TUIElement Create <TUIElement>( UICanvasLayer uiCanvasLayer = UICanvasLayer.Foreground, UIIndex uiIndex = UIIndex.Start, Transform uiParent = null, string uiPath = UIConstants.UIResources) where TUIElement : UIElement { if (uiCanvas == null) { var uiBackground = Utils.CreateCanvas(UICanvasType.Background); var uiForeground = Utils.CreateCanvas(UICanvasType.Foreground); uiCanvas = new UICanvas(uiBackground, uiForeground); } var name = typeof(TUIElement).Name; var path = string.Format(uiPath, name); var uiElement = Utils.LoadAndCreate <TUIElement>(path); if (uiElement != null) { uiElement.transform.SetParent(uiParent ?? uiCanvas.GetCanvas(uiCanvasLayer), worldPositionStays: false); if (uiIndex == UIIndex.Start) { uiElement.transform.SetAsFirstSibling(); } else { uiElement.transform.SetAsLastSibling(); } } return(uiElement); }
public TUIElement Create <TUIElement>(UILayer uiLayer = UILayer.Foreground, UIIndex uiIndex = UIIndex.Start, Transform parent = null) where TUIElement : UIElement { parent = parent ?? uiLayers.GetLayer(uiLayer); var uiElement = UIUtils.LoadAndCreateUIElement <TUIElement>(); uiElement.transform.SetParent(parent, false); if (uiIndex == UIIndex.Start) { uiElement.transform.SetAsFirstSibling(); } else { uiElement.transform.SetAsLastSibling(); } return(uiElement); }