private void CustomAddObjectsButton() { var usableGestures = GetUsableGestures() .Where(x => !CodeBlocks.Select(y => y.Gesture) .Contains(x.GetGesture <Gesture>())); var selector = new GenericSelector <ScriptableGesture>(null, true, x => x.name, usableGestures); selector.ShowInPopup(Event.current.mousePosition + Vector2.left * 135, 135); selector.SelectionTree.Config.DrawSearchToolbar = false; selector.SelectionConfirmed += sel => { var gestures = sel as IList <ScriptableGesture> ?? sel.ToList(); foreach (var gesture in gestures) { CodeBlocks.Add(new CodeBlock(gesture.GetGesture <Gesture>(), gesture.name)); } CodeBlocks[CodeBlocks.Count - 1].DisableConjunction = true; if (CodeBlocks.Count > 1) { CodeBlocks[CodeBlocks.Count - 2].DisableConjunction = false; } }; }
protected override void DrawPropertyLayout(GUIContent label) { if (Property.ValueEntry.TypeOfValue != typeof(string)) { DrawAsDefault(label); return; } if (!TryGetTarget(out var target)) { DrawAsDefault(label); return; } if (target != previousTarget) { OnTargetChanged(target); } previousTarget = target; var name = ((string)Property.ValueEntry.WeakSmartValue).Split('/').First(); if (GUILayout.Button(new GUIContent(name), EditorStyles.popup)) { if (target == null) { return; } var window = dropdown.ShowInPopup(); window.OnClose += dropdown.SelectionTree.Selection.ConfirmSelection; } }
public void Pick() { GenericSelector <string> selector = new GenericSelector <string>("", false, item => item, Table <T> .GetAllKeys()); var window = selector.ShowInPopup(); selector.SelectionConfirmed += selection => this.prettyName = Table <T> .Find(selection.FirstOrDefault(), true).PrettyName; selector.EnableSingleClickToSelect(); }
private OdinSelector <ValueDropdownItem <int> > DoSelector(Rect buttonRect) { var dropdownValues = SortingLayer.layers.Select(sortingLayer => new ValueDropdownItem <int>(sortingLayer.name, sortingLayer.id)); var genericSelector = new GenericSelector <ValueDropdownItem <int> >(dropdownValues); buttonRect.xMax = GUIHelper.GetCurrentLayoutRect().xMax; genericSelector.EnableSingleClickToSelect(); genericSelector.ShowInPopup(buttonRect); return(genericSelector); }
private void AddLanguage() { #if UNITY_EDITOR var source = Enum.GetValues(typeof(SystemLanguage)).Cast <SystemLanguage>(); GenericSelector <SystemLanguage> selector = new GenericSelector <SystemLanguage>("Language", false, x => x.ToString(), source); selector.SelectionConfirmed += (selection) => { var select = selection.FirstOrDefault(); if (!languages.Contains(select)) { languages.Add(select); OnAddLanguage(select); } }; selector.ShowInPopup(); #endif }
private void CustomAddObjectsButton() { // Gets all GestureObjeects not in TrackedObjects list and created a popup selector with support for multi-selection List <GestureObject> availableGestureObjects = GestureManager.Instance.GetGestureObjects(); var selector = new GenericSelector <GestureObject>(null, true, x => x.Skeleton.StructureName, availableGestureObjects); selector.ShowInPopup(Event.current.mousePosition + Vector2.left * 135, 135); selector.SelectionTree.Config.DrawSearchToolbar = false; selector.SelectionConfirmed += sel => { var gestureObjects = sel as IList <GestureObject> ?? sel.ToList(); foreach (var gestureObject in gestureObjects) { _gestureObjectsToTrack.Add(new DetectObjectStructure(gestureObject)); } }; }
protected override void DrawTree() { EditorGUILayout.BeginHorizontal(); var size = EditorGUIUtility.singleLineHeight; if (GUILayout.Button(type == null ? " None" : $" {GetEffectName(type)}", EditorStyles.popup)) { var rect = GUIHelper.GetCurrentLayoutRect(); var position = new Vector2(rect.x, rect.yMax); var window = dropdown.ShowInPopup(position, rect.width - size - 3f); window.OnClose += dropdown.SelectionTree.Selection.ConfirmSelection; } if (GUILayout.Button(EditorIcons.Plus.ActiveGUIContent, SirenixGUIStyles.IconButton, GUILayout.Width(size), GUILayout.Height(size))) { if (type == null) { return; } var component = target as Component; var addedComponent = component.gameObject.AddComponent(type); addedComponent.hideFlags = HideFlags.HideInInspector; var feedbacksProperty = serializedObject.FindProperty("feedbacks"); var index = feedbacksProperty.arraySize; feedbacksProperty.InsertArrayElementAtIndex(index); var element = feedbacksProperty.GetArrayElementAtIndex(index); element.objectReferenceValue = addedComponent; } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(size / 3f); Tree.DrawMonoScriptObjectField = false; InspectorUtilities.BeginDrawPropertyTree(Tree, true); InspectorUtilities.DrawPropertiesInTree(Tree); InspectorUtilities.EndDrawPropertyTree(Tree); }
private void CustomAddStatsButton() { // Finds all available stat-types and excludes the types that the statList already contains, so we don't get multiple entries of the same type. var availableStats = Enum.GetValues(typeof(StatType)) .Cast <StatType>() .Except(this.stats.Select(x => x.Type)) .Select(x => new StatValue() { Type = x }) .ToList(); // Here we then quickly make a popup selector, with no title, and support for multi-selection - because why not. var selector = new GenericSelector <StatValue>(null, true, x => x.Type.ToString().SplitPascalCase(), availableStats); selector.SelectionTree.Config.DrawSearchToolbar = false; selector.SelectionConfirmed += this.stats.AddRange; selector.ShowInPopup(Event.current.mousePosition + Vector2.left * 45, 90); }
public override void OnInspectorGUI() { base.OnInspectorGUI(); if (_odinTest.stringList.Count > 1) { int selectIndex = 0; if (_odinTest.stringList.Contains(_odinTest.selectString)) { for (int i = 0; i < _odinTest.stringList.Count; i++) { if (_odinTest.selectString == _odinTest.stringList[i]) { selectIndex = i; break; } } } //selectIndex = EditorGUILayout.Popup("SelectString", selectIndex, _odinTest.stringList.ToArray()); //_odinTest.selectString = _odinTest.stringList[selectIndex]; if (GUILayout.Button(_odinTest.selectString, "MiniPopup")) { GenericSelector <string> selector = new GenericSelector <string>("SelectString", false, _odinTest.stringList); selector.SetSelection(_odinTest.stringList[selectIndex]); selector.SelectionTree.DefaultMenuStyle.Height = 20; selector.SelectionConfirmed += stringList => { _odinTest.selectString = stringList.FirstOrDefault(); }; selector.SelectionTree.Config.DrawSearchToolbar = true; var window = selector.ShowInPopup(); window.OnClose += selector.SelectionTree.Selection.ConfirmSelection; } } }
private OdinSelector <string> CreateSelector(Rect buttonRect) { var eventInstance = FMODUnity.RuntimeManager.CreateInstance(eventPathResolver.GetValue()); eventInstance.getDescription(out var description); description.getParameterDescriptionCount(out var parameterDescriptionCount); var parameters = new List <string>(); for (var i = 0; i < parameterDescriptionCount; i++) { description.getParameterDescriptionByIndex(i, out var parameterDescription); parameters.Add(parameterDescription.name); } var selector = new GenericSelector <string>(parameters); buttonRect.xMax = GUIHelper.GetCurrentLayoutRect().xMax; selector.EnableSingleClickToSelect(); selector.ShowInPopup(buttonRect); return(selector); }
protected override void OnBeginDrawEditors() { var selected = this.MenuTree.Selection.FirstOrDefault(); var toolbarHeight = this.MenuTree.Config.SearchToolbarHeight; // Draws a toolbar with the name of the currently selected menu item. SirenixEditorGUI.BeginHorizontalToolbar(toolbarHeight); { if (selected != null) { GUILayout.Label(selected.Name); if (selected.Value.GetType() == typeof(Domain)) { Domain currentDomain = (Domain)selected.Value; if (SirenixEditorGUI.ToolbarButton(new GUIContent("Add New Feature"))) { // Add Feature Here EditorInputDialog.Show("New Feature", "Enter new Feature name", "", ret: val => { if (!string.IsNullOrEmpty(val)) { var newFeature = new Feature() { name = val, components = new List <Component>(), }; _currentFeatures.AddIfNotContains(newFeature); MenuTree.Add($"{currentDomain.name}/{newFeature.name}", newFeature); base.TrySelectMenuItemWithObject(newFeature); hasUnsavedChanges = true; } }); } if (SirenixEditorGUI.ToolbarButton(new GUIContent("Add Existing Feature"))) { // Add Feature Here var features = domains.Select(item => item.features).ToList(); var distinctFeatures = features.SelectMany(list => list).Distinct().ToList(); var distinctFeatureNames = distinctFeatures.Select(item => item.name).ToList(); string selectedFeatureName = distinctFeatureNames[0]; GenericSelector <string> selector = new GenericSelector <string>("Title", false, distinctFeatureNames); selector.SetSelection(selectedFeatureName); selector.SelectionTree.Config.DrawSearchToolbar = true; selector.SelectionTree.DefaultMenuStyle.Height = 22; selector.SelectionConfirmed += (selection) => { selectedFeatureName = selection.FirstOrDefault(); var selectedFeature = new Feature(distinctFeatures.FirstOrDefault(item => item.name == selectedFeatureName)); _currentFeatures.AddIfNotContains(selectedFeature); MenuTree.Add($"{currentDomain.name}/{selectedFeature.name}", selectedFeature); base.TrySelectMenuItemWithObject(selectedFeature); hasUnsavedChanges = true; }; var popup = selector.ShowInPopup(); } if (SirenixEditorGUI.ToolbarButton(new GUIContent("Delete Domain"))) { // Delete Domains Here EditorYesNoDialog.Show("Delete Domain?", "Are you sure, this will delete the\n domain with its entire hierarchy!", () => { domains.Remove(currentDomain); ForceMenuTreeRebuild(); hasUnsavedChanges = true; }, () => { // Do Nothing }); } } else if (selected.Value.GetType() == typeof(Feature)) { Domain currentDomain = (Domain)selected.Parent.Value; Feature currentFeature = (Feature)selected.Value; if (SirenixEditorGUI.ToolbarButton(new GUIContent("Add Component"))) { // Add Component Here EditorInputDialog.Show("New Component", "Enter new Component name", "", ret: val => { if (!string.IsNullOrEmpty(val)) { var newComponent = new Component() { name = val, asset = null, }; _currentComponents.Add(newComponent); MenuTree.Add($"{currentDomain.name}/{currentFeature.name}/{newComponent.name}", newComponent); base.TrySelectMenuItemWithObject(newComponent); hasUnsavedChanges = true; } }); } if (SirenixEditorGUI.ToolbarButton(new GUIContent("Delete Feature"))) { // Delete Domains Here EditorYesNoDialog.Show("Delete Feature?", "Are you sure, this will delete the\n feature with its entire hierarchy!", () => { currentDomain.features.Remove(currentFeature); ForceMenuTreeRebuild(); hasUnsavedChanges = true; }, () => { // Do Nothing }); } } else if (selected.Value.GetType() == typeof(Component)) { Domain currentDomain = (Domain)selected.Parent.Parent.Value; Feature currentFeature = (Feature)selected.Parent.Value; Component currentComponent = (Component)selected.Value; if (SirenixEditorGUI.ToolbarButton(new GUIContent("Delete Component"))) { // Delete Domains Here EditorYesNoDialog.Show("Delete Component?", "Are you sure, this will delete the component!", () => { currentFeature.components.Remove(currentComponent); ForceMenuTreeRebuild(); hasUnsavedChanges = true; }, () => { // Do Nothing }); } } } if (SirenixEditorGUI.ToolbarButton(new GUIContent("Add Domain"))) { // Add Domain Here EditorInputDialog.Show("New Domain", "Enter new Domain name", "", ret: val => { if (!string.IsNullOrEmpty(val)) { var newDomain = new Domain() { name = val, features = new List <Feature>(), }; domains.Add(newDomain); MenuTree.Add(newDomain.name, newDomain); base.TrySelectMenuItemWithObject(newDomain); hasUnsavedChanges = true; } }); } if (SirenixEditorGUI.ToolbarButton(new GUIContent("Save"))) { SaveChanges(); hasUnsavedChanges = false; } } SirenixEditorGUI.EndHorizontalToolbar(); }
private void DoProperty <TBase>(IPropertyValueEntry weakEntry, ValueDropdownAttribute attribute, GUIContent label) { var entry = (IPropertyValueEntry <TBase>)weakEntry; var config = entry.Property.Context.Get(this, "Config", (PropertyConfig <TBase>)null); if (config.Value == null) { config.Value = new PropertyConfig <TBase>(); Type parentType; if (entry.ValueCategory == PropertyValueCategory.Member) { parentType = entry.ParentType; config.Value.GetParentValuesFromProperty = entry.Property; } else { parentType = entry.Property.Parent.ParentType; config.Value.GetParentValuesFromProperty = entry.Property.Parent; } MemberInfo memberInfo = parentType.FindMember() .HasReturnType <IList <TBase> >(true) .HasNoParameters() .IsNamed(attribute.MemberName) .GetMember <MemberInfo>(out config.Value.ErrorMessage); if (config.Value.ErrorMessage == null) { string memberName = attribute.MemberName + ((memberInfo is MethodInfo) ? "()" : ""); if (memberInfo.IsStatic()) { config.Value.StaticValueDropdownGetter = DeepReflection.CreateValueGetter <IList <TBase> >(parentType, memberName); } else { config.Value.InstanceValueDropdownGetter = DeepReflection.CreateWeakInstanceValueGetter <IList <TBase> >(parentType, memberName); } config.Value.IsValueDropdown = false; } else { string errorMessage; memberInfo = parentType.FindMember() .HasReturnType <IList <ValueDropdownItem <TBase> > >(true) .HasNoParameters() .IsNamed(attribute.MemberName) .GetMember <MemberInfo>(out errorMessage); if (errorMessage == null) { string memberName = attribute.MemberName + ((memberInfo is MethodInfo) ? "()" : ""); if (memberInfo.IsStatic()) { config.Value.ValueDropdownStaticValueDropdownGetter = DeepReflection.CreateValueGetter <IList <ValueDropdownItem <TBase> > >(parentType, memberName); } else { config.Value.ValueDropdownInstanceValueDropdownGetter = DeepReflection.CreateWeakInstanceValueGetter <IList <ValueDropdownItem <TBase> > >(parentType, memberName); } config.Value.ErrorMessage = null; config.Value.IsValueDropdown = true; } else { if (config.Value.ErrorMessage != errorMessage) { config.Value.ErrorMessage += " or\n" + errorMessage; } if (IsStrongList) { memberInfo = parentType.FindMember() .HasReturnType(typeof(IList <>).MakeGenericType(StrongListElementType), true) .HasNoParameters() .IsNamed(attribute.MemberName) .GetMember <MemberInfo>(out errorMessage); if (errorMessage != null) { config.Value.ErrorMessage += " or\n" + errorMessage; Type valueDropdown = typeof(ValueDropdownItem <>).MakeGenericType(StrongListElementType); memberInfo = parentType.FindMember() .HasReturnType(typeof(IList <>).MakeGenericType(valueDropdown), true) .HasNoParameters() .IsNamed(attribute.MemberName) .GetMember <MemberInfo>(out errorMessage); if (errorMessage != null) { config.Value.ErrorMessage += " or\n" + errorMessage; } else { config.Value.ErrorMessage = null; config.Value.CallNextDrawer = true; } } else { config.Value.ErrorMessage = null; config.Value.CallNextDrawer = true; } } } } } if (config.Value.ErrorMessage != null) { if (entry.ValueCategory == PropertyValueCategory.Member) { SirenixEditorGUI.ErrorMessageBox(config.Value.ErrorMessage); } this.CallNextDrawer(entry, label); } else if (config.Value.CallNextDrawer) { this.CallNextDrawer(entry, label); } else { if (config.Value.IsValueDropdown) { IList <ValueDropdownItem <TBase> > selectList = config.Value.ValueDropdownStaticValueDropdownGetter != null? config.Value.ValueDropdownStaticValueDropdownGetter() : config.Value.ValueDropdownInstanceValueDropdownGetter(config.Value.GetParentValuesFromProperty.ParentValues[0]); selectedValuesBuffer.Clear(); if (selectList != null && selectList.Count > 0) { for (int i = 0; i < entry.Values.Count; i++) { var val = entry.Values[i]; for (int j = 0; j < selectList.Count; j++) { if (EqualityComparer <TBase> .Default.Equals((TBase)val, selectList[j].Value)) { selectedValuesBuffer.Add(j); } } } } if (SirenixEditorFields.Dropdown <ValueDropdownItem <TBase> >(label, selectedValuesBuffer, selectList, false)) { if (selectedValuesBuffer.Count > 0) { entry.SmartValue = selectList[selectedValuesBuffer[0]].Value; } } } else { IList <TBase> selectList = config.Value.StaticValueDropdownGetter != null? config.Value.StaticValueDropdownGetter() : config.Value.InstanceValueDropdownGetter(config.Value.GetParentValuesFromProperty.ParentValues[0]); if (GeneralDrawerConfig.Instance.UseImprovedEnumDropDown) { int id; bool hasFocus; Rect rect; Action <OdinSelector <TBase> > bindSelector; Func <IEnumerable <TBase> > getResult; TempFeatureRichControlRect(label, out id, out hasFocus, out rect); if (GenericSelector <TBase> .DrawSelectorButton(rect, entry.SmartValue + "", EditorStyles.popup, id, out bindSelector, out getResult)) { var selector = new GenericSelector <TBase>(selectList); selector.SetSelection(entry.SmartValue); selector.ShowInPopup(new Vector2(rect.xMin, rect.yMax)); bindSelector(selector); } if (getResult != null) { entry.SmartValue = getResult().FirstOrDefault(); } } else { entry.SmartValue = SirenixEditorFields.Dropdown(label, entry.SmartValue, selectList); } } } }
private void DrawHeader(MethodInfo current) { EditorGUILayout.BeginHorizontal(); var targetProperty = Property.Children[0]; var target = targetProperty.ValueEntry.WeakSmartValue as Object; target = EditorGUILayout.ObjectField(GUIContent.none, target, typeof(Object), true, GUILayout.Width(GUIHelper.BetterLabelWidth)); targetProperty.ValueEntry.WeakSmartValue = target; string name; if (target == null) { name = "None"; } else { if (current == null) { name = "None"; } else if (current.Name.Contains("set_")) { name = current.Name.Remove(0, 4); } else { name = current.Name; } } if (target != previousTarget) { BuildHierarchy(target); OnTargetChanged(target); } previousTarget = target; var width = GUIHelper.BetterLabelWidth; var size = EditorGUIUtility.singleLineHeight; if (hierarchy.Count > 0) { var names = new GUIContent[hierarchy.Count]; for (var i = 0; i < names.Length; i++) { names[i] = new GUIContent($"{i} - {hierarchy[i].GetType().GetNiceName()}"); } var selection = EditorGUILayout.Popup(GUIContent.none, hierarchyIndex, names, GUILayout.Width(size + 10f), GUILayout.Height(size)); if (selection != hierarchyIndex) { target = hierarchy[selection]; targetProperty.ValueEntry.WeakSmartValue = target; hierarchyIndex = selection; } width += size + 13f; } if (GUILayout.Button(name, EditorStyles.popup) && target != null) { var lastRect = GUIHelper.GetCurrentLayoutRect();; var position = new Vector2(lastRect.x + width + 3f, lastRect.yMax - 3f); var window = dropdown.ShowInPopup(position, lastRect.width - width - 2f); window.OnClose += dropdown.SelectionTree.Selection.ConfirmSelection; } EditorGUILayout.EndHorizontal(); }