/// <summary> /// Called when unity calcuates the height necessaty to display the attribute. /// </summary> /// <param name="property">The SerializedProperty of the attribute</param> /// <param name="label">The label of the attribute</param> public override float GetPropertyHeight(SerializedProperty property, GUIContent label) { if (serializedObjectReference == null) { serializedObjectReference = property.serializedObject.targetObject; serializedObjectType = property.serializedObject.targetObject.GetType(); } target = attribute as PopupAttribute; if (isInSearch && !string.IsNullOrEmpty(searchValue)) { searchResult = Options .Where(s => !string.IsNullOrEmpty(s) && s.ToLower().Contains(searchValue.ToLower())) .Take(5) .ToArray(); if (searchResult.Length > 0) { searchBoxHeight = EditorGUIUtility.singleLineHeight * searchResult.Length; return(searchBoxHeight + EditorGUIUtility.singleLineHeight); } } searchResult = null; return(base.GetPropertyHeight(property, label)); }
private void SetupPopup(XForm popup, PopupAttribute attribute) { switch (attribute.StartupLocation) { case StartupLocation.Manual: popup.StartPosition = FormStartPosition.Manual; popup.Top = (int)attribute.Top; popup.Left = (int)attribute.Left; break; case StartupLocation.MousePosition: popup.StartPosition = FormStartPosition.Manual; var position = Cursor.Position; popup.Top = position.Y; popup.Left = position.X; break; case StartupLocation.CenterScreen: popup.StartPosition = FormStartPosition.CenterScreen; break; case StartupLocation.CenterOwner: popup.StartPosition = FormStartPosition.CenterParent; break; } if (attribute.Width > 0) { popup.Width = (int)attribute.Width; } if (attribute.Height > 0) { popup.Height = (int)attribute.Height; } switch (attribute.ResizeMode) { case ResizeMode.AutoSize: popup.AutoSize = true; break; case ResizeMode.CanResizeWithGrip: popup.SizeGripStyle = SizeGripStyle.Show; break; case ResizeMode.CanResize: case ResizeMode.NoResize: popup.SizeGripStyle = SizeGripStyle.Hide; break; } if (!string.IsNullOrEmpty(attribute.Icon)) { popup.Icon = new Icon(attribute.Icon); } popup.TopMost = attribute.TopMost; }
public ScreenFactory(Type idType, Type viewType, Type logicType, Action <Type, Type> register, Func <Type, object> resolve, PopupAttribute popupAttribute) { _idType = idType; _resolve = resolve; PopupAttribute = popupAttribute; _factory = idType != viewType ? viewType.CreateFactory <TBaseView>(idType) : (p => (TBaseView)p); register(idType, logicType); }
protected override XWindow CreatePopup(FrameworkElement view, PopupAttribute attribute) { var popup = new XWindow { Owner = _mainWindow, Content = view }; if (attribute != null) { SetupPopup(popup, attribute); } return(popup); }
protected override IScreenHost CreatePopup(FrameworkElement view, PopupAttribute attribute) { var popup = new XWindow { Owner = mainWindow, Content = view }; if (attribute != null) { SetupPopup(popup, attribute); } popup.Show(); return(popup); }
protected override XForm CreatePopup(Control view, PopupAttribute attribute) { var popup = new XForm(); view.Dock = DockStyle.Fill; view.Anchor = AnchorStyles.Top | AnchorStyles.Left; popup.Controls.Add(view); if (attribute != null) { SetupPopup(popup, attribute); } return(popup); }
private void SetPropertyValue(SerializedProperty property, PopupAttribute attr) { switch (attr.popupType) { case PopupAttribute.PopUpType.STRING: property.stringValue = items[selectedIndex].text; break; case PopupAttribute.PopUpType.INT: property.intValue = (int)attr.Items[selectedIndex]; break; case PopupAttribute.PopUpType.FLOAT: property.floatValue = (float)attr.Items[selectedIndex]; break; } }
public ScreenHost(NamedType key, TBaseView view, IScreen screen, Func <TBaseView, IScreenHost> createScreen, Func <TBaseView, PopupAttribute, IScreenHost> createPopup, PopupAttribute popupAttribute) { _key = key; _view = view; _screen = screen; _createScreen = createScreen; _createPopup = createPopup; _popupAttribute = popupAttribute; _screen.PropertyChanged += OnPropertyChanged; }
public ScreenHost(NamedType key, TBaseView view, IScreen screen, Func <TBaseView, IScreenHost> createScreen, Func <TBaseView, PopupAttribute, IScreenHost> createPopup, PopupAttribute popupAttribute) { this.key = key; this.view = view; this.screen = screen; this.createScreen = createScreen; this.createPopup = createPopup; this.popupAttribute = popupAttribute; this.screen.TitleChanged += OnTitleChanged; }
protected override IScreenHost CreatePopup(Control view, PopupAttribute attribute) { var host = new XForm(); view.Dock = DockStyle.Fill; view.Anchor = AnchorStyles.Top | AnchorStyles.Left; host.Controls.Add(view); if (attribute != null) { SetupPopup(host, attribute); } host.Show(_mainForm); return(host); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { PopupAttribute attr = (PopupAttribute)attribute; int index = 0; for (int i = 0; i < attr.list.Length; i++) { if (attr.list[i].Equals(property.stringValue)) { index = i; break; } } int selected = EditorGUI.Popup(position, index, attr.list); property.stringValue = attr.list[selected]; }
public ScreenHost(NamedType key, TBaseView view, IScreen screen, Func <TBaseView, TScreen> createScreen, Action <TScreen> showScreen, Func <TBaseView, PopupAttribute, TPopup> createPopup, Action <TPopup> showPopup, PopupAttribute popupAttribute) { Key = key; _view = view; _screen = screen; _createScreen = createScreen; _showScreen = showScreen; _createPopup = createPopup; _showPopup = showPopup; _popupAttribute = popupAttribute; _screen.PropertyChanged += OnPropertyChanged; }
private void SelectAxis(SerializedProperty property, PopupAttribute attribute) { for (selectedIndex = items.Length - 1; selectedIndex >= 0; selectedIndex--) { switch (attribute.popupType) { case PopupAttribute.PopUpType.STRING: if (items[selectedIndex].text.Equals(property.stringValue)) return; break; case PopupAttribute.PopUpType.INT: if (items[selectedIndex].text.Equals(property.intValue.ToString())) return; break; case PopupAttribute.PopUpType.FLOAT: if (items[selectedIndex].text.Equals(property.floatValue.ToString())) return; break; } } }
private VisualElement CreatePopup <T>(SerializedProperty property, PopupAttribute popupAttribute, List <T> defaultValues) { var popup = new PopupField <T>(); void setValues(List <T> values) => popup.SetValues(values); void setValuesWithOptions(PopupValues <T> options) => popup.SetValues(options.Values, options.Options); if (!ReflectionHelper.SetupValueSourceCallback(popupAttribute.ValuesSource, fieldInfo.DeclaringType, property, popup, defaultValues, popupAttribute.AutoUpdate, setValues)) { var defaultOptions = new PopupValues <T> { Values = defaultValues, Options = popupAttribute.Options }; if (!ReflectionHelper.SetupValueSourceCallback(popupAttribute.ValuesSource, fieldInfo.DeclaringType, property, popup, defaultOptions, popupAttribute.AutoUpdate, setValuesWithOptions)) { Debug.LogWarningFormat(_invalidValuesSourceError, property.propertyPath, nameof(PopupValues <T>), popupAttribute.ValuesSource); } } return(popup.ConfigureProperty(property)); }
protected abstract TPopup CreatePopup(TBaseView view, PopupAttribute popupAttribute);
private void Show(Type idType, string instanceId, object parameter, bool isPopup, PopupAttribute popupAttribute = null) { var host = CreateScreenHost(idType, instanceId, s => parameter, isPopup, popupAttribute); host?.Show(isPopup); }
private ScreenHost CreateScreenHost(Type idType, string instanceId, Func <IInternalScreen, object> getParameter, bool isPopup, PopupAttribute popupAttribute = null) { var key = new NamedType(idType, instanceId); if (_screens.TryGetValue(key, out var host)) { host.BringToFront(isPopup); return(null); } if (!_factories.TryGetValue(key.Type, out var factory)) { return(null); } if (!factory.TryCreate(instanceId, getParameter, out var logic, out var view, out var e)) { OnException($"Unable to create screen: {key}", e); return(null); } popupAttribute = popupAttribute ?? factory.PopupAttribute; host = new ScreenHost(key, view, logic, CreateScreen, ShowScreen, CreatePopup, ShowPopup, popupAttribute); _screens.Add(key, host); host.Closed += OnHostClosed; if (logic is IInternalScreen internalScreen) { internalScreen.Setup(host.Close); } if (!host.Restore(_persistenceService, out e)) { OnException($"Unable to restore screen: {key}", e); } return(host); }
private void SetupPopup(Window popup, PopupAttribute attribute) { switch (attribute.StartupLocation) { case StartupLocation.Manual: popup.WindowStartupLocation = WindowStartupLocation.Manual; popup.Top = attribute.Top; popup.Left = attribute.Left; break; case StartupLocation.MousePosition: popup.WindowStartupLocation = WindowStartupLocation.Manual; var position = Mouse.GetPosition(Application.Current.MainWindow); position = Application.Current.MainWindow.PointToScreen(position); popup.Top = position.Y; popup.Left = position.X; break; case StartupLocation.CenterScreen: popup.WindowStartupLocation = WindowStartupLocation.CenterScreen; break; case StartupLocation.CenterOwner: popup.WindowStartupLocation = WindowStartupLocation.CenterOwner; break; } if (attribute.Width > 0) { popup.Width = attribute.Width; } if (attribute.Height > 0) { popup.Height = attribute.Height; } switch (attribute.ResizeMode) { case ResizeMode.AutoSize: popup.SizeToContent = SizeToContent.WidthAndHeight; break; case ResizeMode.NoResize: popup.ResizeMode = System.Windows.ResizeMode.NoResize; break; case ResizeMode.CanResizeWithGrip: popup.ResizeMode = System.Windows.ResizeMode.CanResizeWithGrip; break; case ResizeMode.CanResize: popup.ResizeMode = System.Windows.ResizeMode.CanResize; break; } if (!string.IsNullOrEmpty(attribute.Icon)) { popup.Icon = new BitmapImage(new Uri(attribute.Icon)); } popup.Topmost = attribute.TopMost; }
/// <summary> /// Called when unity draws the attribute. /// </summary> /// <param name="position">The position where to draw the attribute</param> /// <param name="property">The SerializedProperty of the attribute</param> /// <param name="label">The label of the attribute</param> public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { if (serializedObjectReference == null) { serializedObjectReference = property.serializedObject.targetObject; serializedObjectType = property.serializedObject.targetObject.GetType(); } target = attribute as PopupAttribute; Initialize(property.stringValue); EditorGUI.BeginProperty(position, GUIContent.none, property); position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label); if (!isInSearch) { target.selectedIndex = EditorGUI.Popup(position, target.selectedIndex, Options); } if (target.enableSearch) { if (GUI.Button(new Rect(position.x - 20, position.y, 20, 15), AssetReferences.SearchIcon, EditorStyles.label)) { isInSearch = !isInSearch; } if (isInSearch) { var rect = new Rect(position.x, position.y, position.width, position.height); rect.height = EditorGUIUtility.singleLineHeight; if (string.IsNullOrEmpty(searchValue)) { searchValue = String.Empty; } searchValue = GUI.TextField(rect, searchValue); if (!string.IsNullOrEmpty(searchValue) && searchResult != null) { rect.height = EditorGUIUtility.singleLineHeight; var searchBox = new Rect(rect.x, rect.y, rect.width, position.height); GUI.Box(searchBox, GUIContent.none, EditorStyles.helpBox); foreach (var s in searchResult) { rect.y += EditorGUIUtility.singleLineHeight; if (GUI.Button(rect, s, EditorStyles.boldLabel)) { target.selectedIndex = Options.IndexOf(s); isInSearch = false; } } } } } if (target.selectedIndex >= Options.Length || Options.Length == 0) { property.stringValue = String.Empty; } else { property.stringValue = Options[target.selectedIndex]; } EditorGUI.EndProperty(); }
private void RenderStackedArray(string name, SerializedProperty prop, SerializedProperty otherProp, PopupAttribute leftPopup, PopupAttribute rightPopup, string addMethod, string addText, string changedCallback) { prop.isExpanded = UTStyles.FoldoutHeader($"{name} [{prop.arraySize}]", prop.isExpanded); if (!prop.isExpanded) { return; } for (int i = 0; i < prop.arraySize; i++) { EditorGUILayout.BeginHorizontal(); if (RenderPositionControls(i, new[] { prop, otherProp })) { break; } // this code is very similar to PopupAttribute itself // but we have to handle it here directly because we are connecting two different props together // should probably refactor at some point EditorGUI.BeginChangeCheck(); // Left Field if (leftPopup == null) { EditorGUILayout.PropertyField(prop.GetArrayElementAtIndex(i), new GUIContent()); } else { string[] options; var sourceType = leftPopup.sourceType; var source = prop.GetArrayElementAtIndex(i); // Right Field if (sourceType == PopupAttribute.PopupSource.Animator) { options = UTUtils.GetAnimatorTriggers(source.objectReferenceValue as Animator); } else if (sourceType == PopupAttribute.PopupSource.UdonBehaviour) { options = UTUtils.GetUdonEvents(source.objectReferenceValue as UdonBehaviour); } else if (sourceType == PopupAttribute.PopupSource.Shader) { var propsSource = UTUtils.GetValueThroughAttribute(source, leftPopup.methodName, out _); options = UTUtils.GetShaderPropertiesByType(propsSource as Shader, leftPopup.shaderPropType); } else { options = (string[])UTUtils.GetValueThroughAttribute(prop, leftPopup.methodName, out _); } var selectedIndex = options.ToList().IndexOf(prop.GetArrayElementAtIndex(i).stringValue); if (selectedIndex >= options.Length || selectedIndex == -1) { selectedIndex = 0; } selectedIndex = EditorGUILayout.Popup(selectedIndex, options); prop.GetArrayElementAtIndex(i).stringValue = options[selectedIndex]; } if (rightPopup == null) { EditorGUILayout.PropertyField(otherProp.GetArrayElementAtIndex(i), new GUIContent()); } else { string[] options; var sourceType = rightPopup.sourceType; var source = prop.GetArrayElementAtIndex(i); // Right Field if (sourceType == PopupAttribute.PopupSource.Animator) { options = UTUtils.GetAnimatorTriggers(source.objectReferenceValue as Animator); } else if (sourceType == PopupAttribute.PopupSource.UdonBehaviour) { options = UTUtils.GetUdonEvents(source.objectReferenceValue as UdonBehaviour); } else if (sourceType == PopupAttribute.PopupSource.Shader) { var propsSource = UTUtils.GetValueThroughAttribute(source, rightPopup.methodName, out _); options = UTUtils.GetShaderPropertiesByType(propsSource as Shader, rightPopup.shaderPropType); } else { options = (string[])UTUtils.GetValueThroughAttribute(otherProp, rightPopup.methodName, out _); } var selectedIndex = options.ToList().IndexOf(otherProp.GetArrayElementAtIndex(i).stringValue); if (selectedIndex >= options.Length || selectedIndex == -1) { selectedIndex = 0; } selectedIndex = EditorGUILayout.Popup(selectedIndex, options); otherProp.GetArrayElementAtIndex(i).stringValue = options[selectedIndex]; } if (EditorGUI.EndChangeCheck()) { if (changedCallback != null) { var m = t.GetType().GetMethod(changedCallback); if (m != null) { m.Invoke(t, m.GetParameters().Length > 2 ? new object[] { prop.GetArrayElementAtIndex(i), otherProp.GetArrayElementAtIndex(i), i } : new object[] { prop, otherProp }); } } } if (RenderRemoveControls(i, new[] { prop, otherProp })) { if (changedCallback != null) { var m = t.GetType().GetMethod(changedCallback); if (m != null) { m.Invoke(t, m.GetParameters().Length > 2 ? new object[] { null, null, i } : new object[] { prop, otherProp }); } } break; } EditorGUILayout.EndHorizontal(); } if (RenderAddControls(new[] { prop, otherProp }, addText, addMethod)) { if (changedCallback != null) { var m = t.GetType().GetMethod(changedCallback); if (m != null) { m.Invoke(t, m.GetParameters().Length > 2 ? new object[] { prop.GetArrayElementAtIndex(prop.arraySize), otherProp.GetArrayElementAtIndex(prop.arraySize), prop.arraySize } : new object[] { prop, otherProp }); } } } }
protected abstract IScreenHost CreatePopup(TBaseView view, PopupAttribute popupAttribute);
public void Popup(Type idType, string instanceId = null, object parameter = null, PopupAttribute popupAttribute = null) { Show(idType, instanceId, parameter, true, popupAttribute); }
private void InitializeItems(PopupAttribute attr) { items = new GUIContent[attr.Items.Count]; for (int i = 0; i < items.Length; i++) items[i] = new GUIContent(attr.Items[i].ToString()); }