/// <summary> /// Init this instance. /// </summary> public void Init() { canvasRect = Utilites.FindTopmostCanvas(transform) as RectTransform; canvas = canvasRect.GetComponent <Canvas>(); foreach (Transform child in transform) { var cell = Utilites.GetOrAddComponent <ResizableHeaderDragCell>(child); if (cell.Position == -1) { cell.Position = CellsInfo.Count; cell.ResizableHeader = this; cell.AllowDropCursor = AllowDropCursor; cell.AllowDropCursorHotSpot = AllowDropCursorHotSpot; cell.DeniedDropCursor = DeniedDropCursor; cell.DeniedDropCursorHotSpot = DeniedDropCursorHotSpot; var events = Utilites.GetOrAddComponent <ResizableHeaderCell>(child); events.OnInitializePotentialDragEvent.AddListener(OnInitializePotentialDrag); events.OnBeginDragEvent.AddListener(OnBeginDrag); events.OnDragEvent.AddListener(OnDrag); events.OnEndDragEvent.AddListener(OnEndDrag); CellsInfo.Add(new ResizableHeaderCellInfo() { Rect = child as RectTransform, LayoutElement = Utilites.GetOrAddComponent <LayoutElement>(child), Position = CellsInfo.Count }); } } }
/// <summary> /// Init this instance. /// </summary> public void Init() { canvas = Utilites.FindTopmostCanvas(transform).GetComponent <Canvas>(); LayoutUtilites.UpdateLayout(transform.parent.GetComponent <LayoutGroup>()); transform.parent.GetComponentsInChildren <Splitter>().ForEach(x => x.InitSizes()); }
/// <summary> /// Display specified image. /// </summary> /// <param name="image">Image to display.</param> /// <param name="modalSprite">Modal background sprite.</param> /// <param name="modalColor">Modal background color.</param> /// <param name="canvas">Canvas.</param> public virtual void Show( Sprite image, Sprite modalSprite = null, Color?modalColor = null, Canvas canvas = null) { GetComponent <Image>().sprite = image; var parent = (canvas != null) ? canvas.transform : Utilites.FindTopmostCanvas(gameObject.transform); if (parent != null) { transform.SetParent(parent, false); } if (modalColor == null) { modalColor = new Color(0, 0, 0, 0.8f); } ModalKey = ModalHelper.Open(this, modalSprite, modalColor, Close); transform.SetAsLastSibling(); gameObject.SetActive(true); }
/// <summary> /// Show picker. /// </summary> /// <param name="defaultValue">Default value.</param> /// <param name="onSelect">Callback with selected value.</param> /// <param name="onCancel">Callback when picker closed without any value selected.</param> /// <param name="modalSprite">Modal sprite.</param> /// <param name="modalColor">Modal color.</param> /// <param name="canvas">Canvas.</param> public virtual void Show( TValue defaultValue, Action <TValue> onSelect, Action onCancel = null, Sprite modalSprite = null, Color?modalColor = null, Canvas canvas = null) { OnSelect = onSelect; OnCancel = onCancel; var parent = (canvas != null) ? canvas.transform : Utilites.FindTopmostCanvas(gameObject.transform); if (parent != null) { transform.SetParent(parent, false); } if (modalColor == null) { modalColor = new Color(0, 0, 0, 0.8f); } ModalKey = ModalHelper.Open(this, modalSprite, modalColor, Close); transform.SetAsLastSibling(); gameObject.SetActive(true); BeforeOpen(defaultValue); }
/// <summary> /// Hide indicator. /// </summary> public virtual void Hide() { var canvas = Utilites.FindTopmostCanvas(gameObject.transform); gameObject.transform.SetParent(canvas, false); gameObject.SetActive(false); }
/// <summary> /// Init this instance. /// </summary> protected virtual void Init() { TooltipObject = tooltipObject; if (TooltipObject != null) { canvasTransform = Utilites.FindTopmostCanvas(tooltipObjectParent); TooltipObject.SetActive(false); } }
/// <summary> /// Shows the options. /// </summary> protected virtual void ShowOptions() { CanvasTransform = Utilites.FindTopmostCanvas(DisplayListView.transform); if (CanvasTransform != null) { Utilites.GetOrAddComponent <HierarchyToggle>(DisplayListView).SetParent(CanvasTransform); } DisplayListView.gameObject.SetActive(true); }
/// <summary> /// Shows the options. /// </summary> protected virtual void ShowOptions() { CanvasTransform = Utilites.FindTopmostCanvas(DisplayListView.transform); if (CanvasTransform != null) { DisplayListViewAnchoredPosition = (DisplayListView.transform as RectTransform).anchoredPosition; DisplayListViewParent = DisplayListView.transform.parent; DisplayListView.transform.SetParent(CanvasTransform); } DisplayListView.gameObject.SetActive(true); }
/// <summary> /// Show dialog. /// </summary> /// <param name="title">Title.</param> /// <param name="message">Message.</param> /// <param name="buttons">Buttons.</param> /// <param name="focusButton">Set focus on button with specified name.</param> /// <param name="position">Position.</param> /// <param name="icon">Icon.</param> /// <param name="modal">If set to <c>true</c> modal.</param> /// <param name="modalSprite">Modal sprite.</param> /// <param name="modalColor">Modal color.</param> /// <param name="canvas">Canvas.</param> /// <param name="content">Content.</param> /// <param name="onClose">On close callback.</param> /// <param name="onCancel">On cancel callback.</param> public virtual void Show( string title = null, string message = null, IList <DialogButton> buttons = null, string focusButton = null, Vector3?position = null, Sprite icon = null, bool modal = false, Sprite modalSprite = null, Color?modalColor = null, Canvas canvas = null, RectTransform content = null, Action onClose = null, Func <int, bool> onCancel = null) { if (IsTemplate) { Debug.LogWarning("Use the template clone, not the template itself: DialogTemplate.Clone().Show(...), not DialogTemplate.Show(...)"); } if (position == null) { position = new Vector3(0, 0, 0); } OnClose = onClose; OnCancel = onCancel; SetInfo(title, message, icon); SetContent(content); var parent = (canvas != null) ? canvas.transform : Utilites.FindTopmostCanvas(gameObject.transform); if (parent != null) { transform.SetParent(parent, false); } if (modal) { ModalKey = ModalHelper.Open(this, modalSprite, modalColor); } else { ModalKey = null; } transform.SetAsLastSibling(); transform.localPosition = (Vector3)position; gameObject.SetActive(true); CreateButtons(buttons, focusButton); }
/// <summary> /// Create modal helper with the specified parent, sprite and color. /// </summary> /// <param name="parent">Parent.</param> /// <param name="sprite">Sprite.</param> /// <param name="color">Color.</param> /// <param name="onClick">onClick callback</param> /// <returns>Modal helper index</returns> public static int Open(MonoBehaviour parent, Sprite sprite = null, Color?color = null, UnityAction onClick = null, RectTransform _tModalTarget = null) { //check if in cache if (!Templates.Exists(key)) { Templates.FindTemplates(); CreateTemplate(); } var modal = Templates.Instance(key); modal.transform.SetParent(Utilites.FindTopmostCanvas(parent.transform), false); modal.gameObject.SetActive(true); modal.transform.SetAsLastSibling(); var rect = modal.transform as RectTransform; rect.sizeDelta = new Vector2(0, 0); rect.anchorMin = new Vector2(0, 0); rect.anchorMax = new Vector2(1, 1); rect.anchoredPosition = new Vector2(0, 0); var img = modal.GetComponent <ModalGraphic>(); //if (sprite!=null) //{ // img.sprite = sprite; //} if (color != null) { img.color = (Color)color; } else { img.color = new Color(0, 0, 0, 200f / 255f); } img.TargetTransform = _tModalTarget; img.DoOnceUpdate = true; img.OnUpdate(); modal.OnClick.RemoveAllListeners(); if (onClick != null) { modal.OnClick.AddListener(onClick); } used.Add(modal.GetInstanceID(), modal); return(modal.GetInstanceID()); }
/// <summary> /// Init this instance. /// </summary> public virtual void Init() { if (isComboboxCustomInited) { return; } ListView.Sort = false; isComboboxCustomInited = true; #pragma warning disable 0618 onSelectCallback = index => OnSelect.Invoke(index, listView.DataSource[index]); #pragma warning restore 0618 CanSetData = current is IViewData <TItem>; SetToggleButton(toggleButton); SetListView(listView); if (listView != null) { current.gameObject.SetActive(false); listView.OnSelectObject.RemoveListener(UpdateView); listView.OnDeselectObject.RemoveListener(UpdateView); listCanvas = Utilites.FindTopmostCanvas(listParent); listView.gameObject.SetActive(true); listView.Init(); if ((listView.SelectedIndex == -1) && (listView.DataSource.Count > 0) && (!listView.MultipleSelect)) { listView.SelectedIndex = 0; } if (listView.SelectedIndex != -1) { UpdateView(); } listView.gameObject.SetActive(false); listView.OnSelectObject.AddListener(UpdateView); listView.OnDeselectObject.AddListener(UpdateView); } }
/// <summary> /// Start this instance. /// </summary> public virtual void Start() { if (isStartedComboboxCustom) { //创建的执行Awake的时候View还没添加到Canvas上,所以Start这里再找一次 if (!listCanvas) { listCanvas = Utilites.FindTopmostCanvas(listParent); } return; } isStartedComboboxCustom = true; onSelectCallback = index => OnSelect.Invoke(index, listView.DataSource[index]); SetToggleButton(toggleButton); SetListView(listView); if (listView != null) { current.gameObject.SetActive(false); listView.OnSelectObject.RemoveListener(UpdateView); listView.OnDeselectObject.RemoveListener(UpdateView); listCanvas = Utilites.FindTopmostCanvas(listParent); listView.gameObject.SetActive(true); listView.Start(); if ((listView.SelectedIndex == -1) && (listView.DataSource.Count > 0) && (!listView.Multiple)) { listView.SelectedIndex = 0; } if (listView.SelectedIndex != -1) { UpdateView(); } listView.gameObject.SetActive(false); listView.OnSelectObject.AddListener(UpdateView); listView.OnDeselectObject.AddListener(UpdateView); } }
/// <summary> /// Show popup. /// </summary> /// <param name="title">Title.</param> /// <param name="message">Message.</param> /// <param name="position">Position.</param> /// <param name="icon">Icon.</param> /// <param name="modal">If set to <c>true</c> modal.</param> /// <param name="modalSprite">Modal sprite.</param> /// <param name="modalColor">Modal color.</param> /// <param name="canvas">Canvas.</param> public virtual void Show(string title = null, string message = null, Vector3?position = null, Sprite icon = null, bool modal = false, Sprite modalSprite = null, Color?modalColor = null, Canvas canvas = null) { if (ClosedEvent == null) { ClosedEvent = new UnityEvent(); } if (position == null) { position = new Vector3(0, 0, 0); } SetInfo(title, message, icon); var parent = (canvas != null) ? canvas.transform : Utilites.FindTopmostCanvas(gameObject.transform); if (parent != null) { transform.SetParent(parent, false); } if (modal) { ModalKey = ModalHelper.Open(this, modalSprite, modalColor, Close); } else { ModalKey = null; } transform.SetAsLastSibling(); //transform.localPosition = (Vector3)position; //gameObject.SetActive(true); }
/// <summary> /// Open DrivesListView. /// </summary> public void Open() { if (!DrivesLoaded) { Load(); } DrivesModalKey = ModalHelper.Open(this, null, new Color(0, 0, 0, 0f), Close); DrivesParent = transform.parent; var canvas = Utilites.FindTopmostCanvas(transform); transform.SetParent(canvas); SelectedIndices.ForEach(Deselect); gameObject.SetActive(true); }
/// <summary> /// Show popup. /// </summary> /// <param name="title">Title.</param> /// <param name="message">Message.</param> /// <param name="position">Position.</param> /// <param name="icon">Icon.</param> /// <param name="modal">If set to <c>true</c> modal.</param> /// <param name="modalSprite">Modal sprite.</param> /// <param name="modalColor">Modal color.</param> /// <param name="canvas">Canvas.</param> public virtual void Show(string title = null, string message = null, Vector3?position = null, Sprite icon = null, bool modal = false, Sprite modalSprite = null, Color?modalColor = null, Canvas canvas = null) { if (IsTemplate) { Debug.LogWarning("Use the template clone, not the template itself: PopupTemplate.Clone().Show(...), not PopupTemplate.Show(...)"); } if (position == null) { position = new Vector3(0, 0, 0); } SetInfo(title, message, icon); var parent = (canvas != null) ? canvas.transform : Utilites.FindTopmostCanvas(gameObject.transform); if (parent != null) { transform.SetParent(parent, false); } if (modal) { ModalKey = ModalHelper.Open(this, modalSprite, modalColor, Close); } else { ModalKey = null; } transform.SetAsLastSibling(); transform.localPosition = (Vector3)position; gameObject.SetActive(true); }
/// <summary> /// Create modal helper with the specified parent, sprite and color. /// </summary> /// <param name="parentGameObject">Parent.</param> /// <param name="sprite">Sprite.</param> /// <param name="color">Color.</param> /// <param name="onClick">onClick callback</param> /// <returns>Modal helper index</returns> public static int Open(Component parentGameObject, Sprite sprite = null, Color?color = null, UnityAction onClick = null) { // check if in cache if (!Templates.Exists(key)) { Templates.FindTemplates(); CreateTemplate(); } var modal = Templates.Instance(key); modal.transform.SetParent(Utilites.FindTopmostCanvas(parentGameObject.transform), false); modal.gameObject.SetActive(true); modal.transform.SetAsLastSibling(); var rect = modal.transform as RectTransform; rect.sizeDelta = new Vector2(0, 0); rect.anchorMin = new Vector2(0, 0); rect.anchorMax = new Vector2(1, 1); rect.anchoredPosition = new Vector2(0, 0); var img = modal.GetComponent <Image>(); if (sprite != null) { img.sprite = sprite; } if (color != null) { img.color = (Color)color; } modal.OnClick.RemoveAllListeners(); if (onClick != null) { modal.OnClick.AddListener(onClick); } used.Add(modal.GetInstanceID(), modal); return(modal.GetInstanceID()); }
/// <summary> /// Init this instance. /// </summary> public void Init() { canvasRect = Utilites.FindTopmostCanvas(transform) as RectTransform; canvas = canvasRect.GetComponent <Canvas>(); children.Clear(); childrenLayouts.Clear(); int i = 0; foreach (Transform child in transform) { var element = child.GetComponent <LayoutElement>(); if (element == null) { element = child.gameObject.AddComponent <LayoutElement>(); } children.Add(child as RectTransform); childrenLayouts.Add(element); var cell = child.gameObject.AddComponent <ResizableHeaderDragCell>(); cell.Position = i; cell.ResizableHeader = this; cell.AllowDropCursor = AllowDropCursor; cell.AllowDropCursorHotSpot = AllowDropCursorHotSpot; cell.DeniedDropCursor = DeniedDropCursor; cell.DeniedDropCursorHotSpot = DeniedDropCursorHotSpot; var events = child.gameObject.AddComponent <ResizableHeaderCell>(); events.OnInitializePotentialDragEvent.AddListener(OnInitializePotentialDrag); events.OnBeginDragEvent.AddListener(OnBeginDrag); events.OnDragEvent.AddListener(OnDrag); events.OnEndDragEvent.AddListener(OnEndDrag); i++; } positions = Enumerable.Range(0, i).ToList(); CalculateWidths(); //ResetChildren(); //Resize(); }
/// <summary> /// Show picker. /// </summary> /// <param name="defaultValue">Default value.</param> /// <param name="onSelect">Callback with selected value.</param> /// <param name="onCancel">Callback when picker closed without any value selected.</param> /// <param name="modalSprite">Modal sprite.</param> /// <param name="modalColor">Modal color.</param> /// <param name="canvas">Canvas.</param> public virtual void Show( TValue defaultValue, Action <TValue> onSelect, Action onCancel = null, Sprite modalSprite = null, Color?modalColor = null, Canvas canvas = null) { if (IsTemplate) { Debug.LogWarning("Use the template clone, not the template itself: PickerTemplate.Clone().Show(...), not PickerTemplate.Show(...)"); } OnSelect = onSelect; OnCancel = onCancel; var parent = (canvas != null) ? canvas.transform : Utilites.FindTopmostCanvas(gameObject.transform); if (parent != null) { transform.SetParent(parent, false); } if (modalColor == null) { modalColor = new Color(0, 0, 0, 0.8f); } ModalKey = ModalHelper.Open(this, modalSprite, modalColor, Close); transform.SetAsLastSibling(); gameObject.SetActive(true); BeforeOpen(defaultValue); }
/// <summary> /// Show dialog. /// </summary> /// <param name="title">Title.</param> /// <param name="message">Message.</param> /// <param name="buttons">Buttons.</param> /// <param name="focusButton">Set focus on button with specified name.</param> /// <param name="position">Position.</param> /// <param name="icon">Icon.</param> /// <param name="modal">If set to <c>true</c> modal.</param> /// <param name="modalSprite">Modal sprite.</param> /// <param name="modalColor">Modal color.</param> /// <param name="canvas">Canvas.</param> public virtual void Show(string title = null, string message = null, DialogActions buttons = null, string focusButton = null, Vector3?position = null, Sprite icon = null, bool modal = false, bool hideByModalClick = true, Sprite modalSprite = null, Color?modalColor = null, Transform canvas = null, UnityAction closeBtnAction = null, UnityAction modalclickAction = null) { if (position == null) { position = new Vector3(0, 0, 0); } SetInfo(title, message, icon); ParentTrans = canvas; var topCanvas = Utilites.FindTopmostCanvas(ParentTrans); if (topCanvas != null) { transform.SetParent(topCanvas, false); } if (modal) { if (hideByModalClick) { ModalKey = ModalHelper.Open(this, modalSprite, modalColor, Hide, transform as RectTransform); } else { ModalKey = ModalHelper.Open(this, modalSprite, modalColor, null, transform as RectTransform); } m_actionModalClick = modalclickAction; } else { ModalKey = null; } transform.SetAsLastSibling(); transform.localPosition = (Vector3)position; gameObject.SetActive(true); CreateButtons(buttons, focusButton); if (CloseButton != null) { CloseButton.onClick.AddListener(Hide); if (closeBtnAction != null) { CloseButton.onClick.AddListener(closeBtnAction); } } }
/// <summary> /// Raises the initialize potential drag event. /// </summary> /// <param name="eventData">Event data.</param> public virtual void OnInitializePotentialDrag(PointerEventData eventData) { canvasRect = Utilites.FindTopmostCanvas(transform) as RectTransform; canvas = canvasRect.GetComponent <Canvas>(); }
/// <summary> /// Init this instance. /// </summary> public void Init() { canvasRect = Utilites.FindTopmostCanvas(transform) as RectTransform; canvas = canvasRect.GetComponent <Canvas>(); }
/// <summary> /// Init this instance. /// </summary> public void Init() { canvas = Utilites.FindTopmostCanvas(transform).GetComponent <Canvas>(); }