private void Init(Vector2 pos, List <InputData> data, OnSelectCallback callback) { // Has to be done before calling Show / ShowWithMode //pos = GUIUtility.GUIToScreenPoint(pos); Rect buttonRect = new Rect(pos.x, pos.y - 16, 16, 16); // fake a button: we know we are showing it below the bottonRect if possible buttonRect = GUIUtility.GUIToScreenRect(buttonRect); data.Sort( delegate(InputData lhs, InputData rhs) { return(lhs.m_Name.CompareTo(rhs.m_Name)); }); m_Data = data; m_Callback = callback; if (s_Styles == null) { s_Styles = new Styles(); } var windowHeight = 2f * kFrameWidth + GetHeight(); var windowWidth = 2f * kFrameWidth + GetWidth(); var windowSize = new Vector2(windowWidth, windowHeight); ShowAsDropDown(buttonRect, windowSize); }
private void Init(Vector2 pos, List <InputData> data, OnSelectCallback callback) { Rect guiRect = new Rect(pos.x, pos.y - 16f, 16f, 16f); guiRect = GUIUtility.GUIToScreenRect(guiRect); if (< > f__am$cache0 == null) {
internal static bool ShowAtPosition(Vector2 pos, List <InputData> data, OnSelectCallback callback) { // We could not use realtimeSinceStartUp since it is set to 0 when entering/exitting playmode, we assume an increasing time when comparing time. long nowMilliSeconds = System.DateTime.Now.Ticks / System.TimeSpan.TicksPerMillisecond; bool justClosed = nowMilliSeconds < s_LastClosedTime + 50; if (!justClosed) { Event.current.Use(); if (s_SceneHierarchySortingWindow == null) { s_SceneHierarchySortingWindow = CreateInstance <SceneHierarchySortingWindow>(); } s_SceneHierarchySortingWindow.Init(pos, data, callback); return(true); } return(false); }
private void Initialize(IEnumerable <string> itemNames, string title, string selectButtonName, OnSelectCallback onSelectCB, OnCancelCallback onCancelCB) { m_txtTitle.text = title; m_txtSelectButtonName.text = selectButtonName; m_OnSelectCB = onSelectCB; m_OnCancelCB = onCancelCB; m_btnSelect.interactable = false; // Create list of items in scroll view from itemNames foreach (string name in itemNames) { GameObject item = Instantiate(m_ItemPrefab); item.GetComponentInChildren <Text>().text = name; item.transform.SetParent(m_ItemContainer); item.transform.localScale = Vector3.one; } }
/// <summary> /// Converts an IQueryable result to a paged result set and applies post query filters to it. /// </summary> /// <typeparam name="T">The entity type which is being queried.</typeparam> /// <param name="self">Self Iqueryable instance (Extension).</param> /// <param name="totalRecords">Total records in database for this entity based on previous paged query.</param> /// <param name="callback">Callback to execute code on memory projection selected by adapter.</param> /// <returns>WrapperEnumerator instance.</returns> public static IPagedDataResult <T> BuildUpResult <T>(this IQueryable <T> self, int totalRecords, OnSelectCallback callback = null) where T : class { return(new PagedDataResult <T>(totalRecords) { Result = (IList <T>)callback(self.ToList()) }); }
/// <summary> /// Creates and presents the selection dialog to the user. /// </summary> /// <param name="itemNames">The list of string items to present for selection.</param> /// <param name="title">The title of the dialog box.</param> /// <param name="selectButtonName">The text of the select button.</param> /// <param name="onSelectCB">The callback that receives the selected item.</param> /// <param name="onCancelCB">The callback for when the user cancels selection.</param> public static ListSelectDialog Create(IEnumerable <string> itemNames, string title, string selectButtonName, OnSelectCallback onSelectCB, OnCancelCallback onCancelCB = null) { GameObject goDialog = Instantiate(Resources.Load <GameObject>("Dialogs/ListSelectDialog")); ListSelectDialog dialog = goDialog.GetComponent <ListSelectDialog>(); dialog.Initialize(itemNames, title, selectButtonName, onSelectCB, onCancelCB); return(dialog); }
private void Init(Vector2 pos, List<InputData> data, OnSelectCallback callback) { Rect guiRect = new Rect(pos.x, pos.y - 16f, 16f, 16f); guiRect = GUIUtility.GUIToScreenRect(guiRect); if (<>f__am$cache5 == null) {
/// <summary> /// Opens the default label window /// </summary> /// <param name="position">The position where the window is going to be drawn</param> /// <param name="labels">Label array used to populate the list</param> /// <param name="selectedLabels">Selected labels</param> /// <param name="populateDefaultLabels">Should the default labels be included</param> /// <param name="allowMultipleSelection">Should the system allow more than 1 label selected</param> /// <param name="closeOnSelection">Should the window close on selection</param> /// <param name="allowCustom">Allow custom labels</param> /// <param name="maxCount">Max label count</param> /// <param name="sortAlphabetically">Should the labels be sorted</param> /// <param name="enableAutoCompletition">Should the window show auto completetion</param> public void OpenLabelWindow(Rect position, string[] labels, string[] selectedLabels, bool populateDefaultLabels = true, bool allowMultipleSelection = true, bool closeOnSelection = false, bool allowCustom = true, int maxCount = 15, bool sortAlphabetically = true, bool enableAutoCompletition = true) { if (labels == null) { labels = new string[] { } } ; if (selectedLabels == null) { selectedLabels = new string[] { } } ; this.allowMultipleSelection = allowMultipleSelection; this.allowCustom = allowCustom; //Cache the data required CacheData(labels, selectedLabels, populateDefaultLabels, closeOnSelection, maxCount, sortAlphabetically, enableAutoCompletition); //Create a reference of the window var popupListReference = Activator.CreateInstance(PopupList, new object[] { m_AssetLabels }); //Get the correct show method var showMethod = typeof(PopupWindow).GetMethods(BindingFlags.Static | BindingFlags.NonPublic).Where(x => x.Name.Equals("Show") && x.GetParameters().Length == 4).Single(); //Invoke the method with the correct arguments showMethod.Invoke(null, new object[] { position, popupListReference, null, 6 }); } void CacheData(string[] labels, string[] selectedLabels, bool populateDefaultLabels, bool closeOnSelection, int maxCount, bool sortAlphabetically, bool enableAutoCompletition) { //Create instance to the delegate Delegate action = Delegate.CreateDelegate(OnSelectCallback.FieldType, this, OnInternalSelectCallback); //Create instance of data to send to the popup window m_AssetLabels = Activator.CreateInstance(InputDataType); //Assign all the respective values, including the delegate callback CloseOnSelection.SetValue(m_AssetLabels, closeOnSelection); AllowCustom.SetValue(m_AssetLabels, true); OnSelectCallback.SetValue(m_AssetLabels, action); MaxCount.SetValue(m_AssetLabels, maxCount); SortAlphabetically.SetValue(m_AssetLabels, sortAlphabetically); EnableAutoCompletion.SetValue(m_AssetLabels, enableAutoCompletition); //Get all the labels available if (populateDefaultLabels) { allLabels = (Dictionary <string, float>) typeof(AssetDatabase).InvokeMember("GetAllLabels", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, null, null); } //Include any custom one sent on the array foreach (var tag in labels) { if (string.IsNullOrEmpty(tag)) { continue; } if (!allLabels.ContainsKey(tag)) { allLabels.Add(tag, 0); } } //Asing all the selected values foreach (var pair in allLabels) { var element = NewOrMatchingElement.Invoke(m_AssetLabels, new object[] { pair.Key }); if ((float)(FilterScore.GetValue(element, null)) < pair.Value) { FilterScore.SetValue(element, pair.Value, null); } Selected.SetValue(element, selectedLabels.Any(label => string.Equals(label, pair.Key, StringComparison.OrdinalIgnoreCase)), null); } } /// <summary> /// Function called by Unity when an element is selected /// </summary> /// <param name="data">Element data</param> void _OnInternalSelectCallback <T>(T data) { string selectedLabel = Text.GetValue(data, null).ToString(); if (!allowCustom && !allLabels.Keys.Any(x => x.ToLower().Equals(selectedLabel.ToLower()))) { return; } if (!allowMultipleSelection) { foreach (var pair in allLabels) { if (pair.Key.ToLower().Equals(selectedLabel.ToLower())) { continue; } var element = NewOrMatchingElement.Invoke(m_AssetLabels, new object[] { pair.Key }); Selected.SetValue(element, false, null); } } bool currentValue = (bool)(Selected.GetValue(data, null)); Selected.SetValue(data, !currentValue, null); if (OnSelect != null) { OnSelect.Invoke(selectedLabel, !currentValue); } } } }