public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { var content = MapSerializedPropertyContent(property); var c = GUI.color; GUI.color = Color.clear; var show_editor = GUI.Button(position, ""); GUI.color = c; var prop = property.FindPropertyRelative("content"); var labelPosition = position; labelPosition.height = EditorGUIUtility.singleLineHeight; position.height -= labelPosition.height; position.y += labelPosition.height; EditorGUI.LabelField(labelPosition, label); EditorGUI.LabelField(position, content, GetStyle()); if (show_editor) { position.center = EditorGUIUtility.GUIToScreenPoint(position.center); position.y -= 1; CustomTextEditorWindow.Show(position, property); } }
private void DrawAISelector(int idx) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("AI", _aiNames[idx]); if (GUILayout.Button(SharedStyles.changeSelectionTooltip, SharedStyles.BuiltIn.changeButtonSmall)) { GUI.changed = false; var aiCfg = _target.aiConfigs[idx]; var screenPos = EditorGUIUtility.GUIToScreenPoint(Event.current.mousePosition); var win = AISelectorWindow.Get( screenPos, (ai) => { if (aiCfg.aiId != ai.aiId) { if (_target.aiConfigs.Any(cfg => cfg.aiId == ai.aiId)) { EditorUtility.DisplayDialog("Duplicate AI", "The selected AI is already part of this client.", "OK"); return; } _aiNames[idx] = ai.name; aiCfg.aiId = ai.aiId; EditorUtility.SetDirty(_target); } }); var curSelectedId = aiCfg.aiId; win.Preselect((ai) => ai.aiId == curSelectedId); } EditorGUILayout.EndHorizontal(); }
public static void TagMaskDropdown(SerializedProperty tagMaskProperty, SerializedProperty tagMaskValueProperty, ImpactTagNameList tagNames, Rect controlRect) { string selectedTags = GetSelectedTags(tagMaskValueProperty.intValue, tagNames, false); string selectedTagsTooltip = GetSelectedTags(tagMaskValueProperty.intValue, tagNames, true); if (GUI.Button(controlRect, new GUIContent(selectedTags, selectedTagsTooltip), EditorStyles.layerMaskField)) { ImpactTagSelectionDropdown tagMaskPopup = ScriptableObject.CreateInstance <ImpactTagSelectionDropdown>(); tagMaskPopup.Initialize(tagMaskValueProperty, tagNames, true, (int pos, bool selected) => { if (selected) { tagMaskValueProperty.intValue = tagMaskValueProperty.intValue.SetBit(pos); } else { tagMaskValueProperty.intValue = tagMaskValueProperty.intValue.UnsetBit(pos); } tagMaskProperty.serializedObject.ApplyModifiedProperties(); }); Rect buttonRect = controlRect; Vector2 adjustedPosition = EditorGUIUtility.GUIToScreenPoint(buttonRect.position); buttonRect.position = adjustedPosition; tagMaskPopup.ShowAsDropDown(buttonRect, tagMaskPopup.GetWindowSize(controlRect)); } }
public static void ShowAsDropDown(Rect buttonRect, int mask, Action <int> onClose) { window = ScriptableObject.CreateInstance <LayerMaskWindow>(); window.wantsMouseMove = true; LayerMaskWindow.mask = mask; LayerMaskWindow.onClose = onClose; layerNames.SetValues(null); hover = -1; int count = 0; string name; for (int i = 0; i < 32; i++) { name = LayerMask.LayerToName(i); if (!string.IsNullOrEmpty(name)) { layerNames[i] = ' ' + name; count++; } } size.x = buttonRect.x; size.y = buttonRect.y; size = EditorGUIUtility.GUIToScreenPoint(size); buttonRect.x = size.x; buttonRect.y = size.y; size.x = windowWidth; size.y = buttonHeight + lineHeight * count + 4 * interval; window.ShowAsDropDown(buttonRect, size); }
public static void TagDropdown(SerializedProperty tagProperty, SerializedProperty tagValueProperty, ImpactTagNameList tagNames, Rect controlRect) { string selectedTagName = ""; int tagValue = tagValueProperty.intValue; if (tagValue >= 0 && tagValue < tagNames.Length) { selectedTagName = tagNames[tagValue]; } if (GUI.Button(controlRect, selectedTagName, EditorStyles.layerMaskField)) { ImpactTagSelectionDropdown tagMaskPopup = ScriptableObject.CreateInstance <ImpactTagSelectionDropdown>(); tagMaskPopup.Initialize(tagValueProperty, tagNames, false, (int pos, bool selected) => { tagValueProperty.intValue = pos; tagProperty.serializedObject.ApplyModifiedProperties(); }); Rect buttonRect = controlRect; Vector2 adjustedPosition = EditorGUIUtility.GUIToScreenPoint(buttonRect.position); buttonRect.position = adjustedPosition; tagMaskPopup.ShowAsDropDown(buttonRect, tagMaskPopup.GetWindowSize(controlRect)); } }
internal static void ShowCanvasMenu(AIUI ui, Vector2 mousePos) { var menu = new GenericMenu(); var screenPos = EditorGUIUtility.GUIToScreenPoint(mousePos); menu.AddItem(new GUIContent("Add Selector"), false, () => AIEntitySelectorWindow.Get <Selector>(screenPos, (selectorType) => { ui.AddSelector(mousePos, selectorType); })); menu.AddItem(new GUIContent("Add AI Link"), false, () => AISelectorWindow.Get(screenPos, (storedAI) => { ui.AddAILink(mousePos, storedAI.aiId); })); AddSharedItems(menu, ui, true, mousePos); }
private void DrawSchemeSelection() { var buttonGUI = m_ControlSchemes.LengthSafe() > 0 ? new GUIContent(selectedControlScheme?.name ?? "All Control Schemes") : new GUIContent("No Control Schemes"); var buttonRect = GUILayoutUtility.GetRect(buttonGUI, EditorStyles.toolbarPopup, GUILayout.MinWidth(k_MinimumButtonWidth)); if (GUI.Button(buttonRect, buttonGUI, EditorStyles.toolbarPopup)) { // PopupWindow.Show already takes the current OnGUI EditorWindow context into account for window coordinates. // However, on macOS, menu commands are performed asynchronously, so we don't have a current OnGUI context. // So in that case, we need to translate the rect to screen coordinates. Don't do that on windows, as we will // overcompensate otherwise. if (Application.platform == RuntimePlatform.OSXEditor) { buttonRect = new Rect(EditorGUIUtility.GUIToScreenPoint(new Vector2(buttonRect.x, buttonRect.y)), Vector2.zero); } var menu = new GenericMenu(); // Add entries to select control scheme, if we have some. if (m_ControlSchemes.LengthSafe() > 0) { menu.AddItem(s_AllControlSchemes, m_SelectedControlSchemeIndex == -1, OnControlSchemeSelected, null); var selectedControlSchemeName = m_SelectedControlSchemeIndex == -1 ? null : m_ControlSchemes[m_SelectedControlSchemeIndex].name; foreach (var controlScheme in m_ControlSchemes.OrderBy(x => x.name)) { menu.AddItem(new GUIContent(controlScheme.name), controlScheme.name == selectedControlSchemeName, OnControlSchemeSelected, controlScheme.name); } menu.AddSeparator(string.Empty); } // Add entries to add/edit/duplicate/delete control schemes. menu.AddItem(s_AddControlSchemeLabel, false, OnAddControlScheme, buttonRect); if (m_SelectedControlSchemeIndex >= 0) { menu.AddItem(s_EditControlSchemeLabel, false, OnEditSelectedControlScheme, buttonRect); menu.AddItem(s_DuplicateControlSchemeLabel, false, OnDuplicateControlScheme, buttonRect); menu.AddItem(s_DeleteControlSchemeLabel, false, OnDeleteControlScheme); } else { menu.AddDisabledItem(s_EditControlSchemeLabel, false); menu.AddDisabledItem(s_DuplicateControlSchemeLabel, false); menu.AddDisabledItem(s_DeleteControlSchemeLabel, false); } menu.ShowAsContext(); } }
internal static bool IsCurrentHierachyFocused(Rect itemPosition) { Vector2 screenPosition = EditorGUIUtility.GUIToScreenPoint(itemPosition.position); if (EditorWindow.focusedWindow == null || itemPosition == null) { return(false); } return(EditorWindow.focusedWindow.position.Contains(screenPosition)); }
private void ShowChangeLinkMenu(AILinkView lv) { Action <AIStorage> cb = (ai) => { lv.parent.ChangeAILink(lv, new Guid(ai.aiId)); }; // We do not want the button click itself to count as a change. GUI.changed = false; var screenPos = EditorGUIUtility.GUIToScreenPoint(Event.current.mousePosition); AISelectorWindow.Get(screenPos, cb); }
public override void OnGUI(Rect position, UnityEditor.SerializedProperty property, GUIContent label) { var foldoutRect = new Rect(position.position.x - HEADER_HEIGHT + 3 + EditorGUI.indentLevel * 15, position.position.y, HEADER_HEIGHT, HEADER_HEIGHT - 4); EditorGUI.BeginChangeCheck(); bool foldout = window != null; if (!foldout) { if (property.objectReferenceValue == null || property.hasMultipleDifferentValues) { foldout = false; } else { foldout = GUI.Button(foldoutRect, "", "OL Plus"); } } var objFieldRect = new Rect(position.x, position.y, position.width, HEADER_HEIGHT); EditorGUI.ObjectField(objFieldRect, property, label); if (foldout) { var rect = new Rect(new Vector2(position.position.x, position.position.y + HEADER_HEIGHT), new Vector2(position.width, EDITOR_HEIGHT)); //Debug.Log(rect.ToString()); rect.position = EditorGUIUtility.GUIToScreenPoint(rect.position); if (window == null) { window = PopupEditorWindow.Create(property.objectReferenceValue, position, new Vector2(position.width, EDITOR_HEIGHT)); } if (window) { window.position = rect; } } else { if (window) { window.Close(); window = null; } } }
private void ShowChangeTypeMenu <T>(T current, Action <T> replacerAction) { Action <Type> cb = (selectedType) => { var newInstance = (T)Activator.CreateInstance(selectedType); replacerAction(newInstance); }; // We do not want the button click itself to count as a change. GUI.changed = false; var screenPos = EditorGUIUtility.GUIToScreenPoint(Event.current.mousePosition); AIEntitySelectorWindow.Get <T>(screenPos, cb); }
private void DrawSchemeSelection() { var buttonGUI = m_ControlSchemes.LengthSafe() > 0 ? new GUIContent(selectedControlScheme?.name ?? "All Control Schemes") : new GUIContent("No Control Schemes"); var buttonRect = GUILayoutUtility.GetRect(buttonGUI, EditorStyles.toolbarPopup, GUILayout.MinWidth(k_MinimumButtonWidth)); if (GUI.Button(buttonRect, buttonGUI, EditorStyles.toolbarPopup)) { buttonRect = new Rect(EditorGUIUtility.GUIToScreenPoint(new Vector2(buttonRect.x, buttonRect.y)), Vector2.zero); var menu = new GenericMenu(); // Add entries to select control scheme, if we have some. if (m_ControlSchemes.LengthSafe() > 0) { menu.AddItem(s_AllControlSchemes, m_SelectedControlSchemeIndex == -1, OnControlSchemeSelected, null); var selectedControlSchemeName = m_SelectedControlSchemeIndex == -1 ? null : m_ControlSchemes[m_SelectedControlSchemeIndex].name; foreach (var controlScheme in m_ControlSchemes.OrderBy(x => x.name)) { menu.AddItem(new GUIContent(controlScheme.name), controlScheme.name == selectedControlSchemeName, OnControlSchemeSelected, controlScheme.name); } menu.AddSeparator(string.Empty); } // Add entries to add/edit/duplicate/delete control schemes. menu.AddItem(s_AddControlSchemeLabel, false, OnAddControlScheme, buttonRect); if (m_SelectedControlSchemeIndex >= 0) { menu.AddItem(s_EditControlSchemeLabel, false, OnEditSelectedControlScheme, buttonRect); menu.AddItem(s_DuplicateControlSchemeLabel, false, OnDuplicateControlScheme, buttonRect); menu.AddItem(s_DeleteControlSchemeLabel, false, OnDeleteControlScheme); } else { menu.AddDisabledItem(s_EditControlSchemeLabel, false); menu.AddDisabledItem(s_DuplicateControlSchemeLabel, false); menu.AddDisabledItem(s_DeleteControlSchemeLabel, false); } menu.ShowAsContext(); } }
public static void Show(Vector2 guiPos, FSequence sequence, UnityAction <FSequence, int, bool> callback) { FChangeFrameRateWindow window = CreateInstance <FChangeFrameRateWindow>(); Rect r = new Rect(); r.min = EditorGUIUtility.GUIToScreenPoint(guiPos); r.width = 0; r.height = 0; window._sequence = sequence; window._frameRate = 25; // window.OnChange.AddListener( callback ); window.OnChange = callback; window.ShowAsDropDown(r, new Vector2(200, 100)); }
public override void RenderField(AIInspectorState state) { if (string.IsNullOrEmpty(_aiName)) { _nameLabel.text = "None"; } else { _nameLabel.text = _aiName; } EditorGUILayout.BeginHorizontal(); EditorGUIUtility.labelWidth = 60f; EditorGUILayout.LabelField(_label, _nameLabel); EditorGUIUtility.labelWidth = 0f; if (GUILayout.Button("...", EditorStyling.Skinned.fixedButton)) { GUI.changed = false; var screenPos = EditorGUIUtility.GUIToScreenPoint(Event.current.mousePosition); AISelectorWindow.Get( screenPos, (ai) => { var newVal = (ai == null) ? Guid.Empty : new Guid(ai.aiId); if (_curValue != newVal) { if (newVal == state.currentAIUI.ai.id) { EditorUtility.DisplayDialog("Invalid AI", "You cannot execute an AI from within itself.", "OK"); return; } _aiName = (ai == null) ? null : ai.name; UpdateValue(newVal, state); } }); } EditorGUILayout.EndHorizontal(); }
private void DrawAISelector() { EditorGUILayout.BeginHorizontal(); _relevantAIValue.text = _relevantAiName; EditorGUILayout.LabelField(_relevantAILabel, _relevantAIValue); if (GUILayout.Button(SharedStyles.changeSelectionTooltip, SharedStyles.BuiltIn.changeButtonSmall)) { GUI.changed = false; var screenPos = EditorGUIUtility.GUIToScreenPoint(Event.current.mousePosition); var win = AISelectorWindow.Get( screenPos, (ai) => { if (ai == null) { if (!string.IsNullOrEmpty(_target.relevantAIId)) { _relevantAiName = "All"; _target.relevantAIId = null; EditorUtility.SetDirty(_target); } } else if (_target.relevantAIId != ai.aiId) { _relevantAiName = ai.name; _target.relevantAIId = ai.aiId; EditorUtility.SetDirty(_target); } }, true); var curSelectedId = _target.relevantAIId; win.Preselect((ai) => ai.aiId == curSelectedId); } EditorGUILayout.EndHorizontal(); }
private void DrawSchemaSelection() { var selectedSchema = selectedControlSchemeName; if (selectedSchema == null) { selectedSchema = "No Control Scheme"; } var buttonGUI = new GUIContent(selectedSchema); var buttonRect = GUILayoutUtility.GetRect(buttonGUI, EditorStyles.toolbarPopup, GUILayout.MinWidth(m_MininumButtonWidth)); if (GUI.Button(buttonRect, buttonGUI, EditorStyles.toolbarPopup)) { buttonRect = new Rect(EditorGUIUtility.GUIToScreenPoint(new Vector2(buttonRect.x, buttonRect.y)), Vector2.zero); var menu = new GenericMenu(); menu.AddItem(m_NoControlScheme, m_SelectedControlSchemeIndex == -1, OnControlSchemeSelected, -1); for (int i = 0; i < m_AllControlSchemeNames.Length; i++) { menu.AddItem(new GUIContent(m_AllControlSchemeNames[i]), m_SelectedControlSchemeIndex == i, OnControlSchemeSelected, i); } menu.AddSeparator(""); menu.AddItem(m_AddSchemeGUI, false, AddControlScheme, buttonRect); if (m_SelectedControlSchemeIndex >= 0) { menu.AddItem(m_EditGUI, false, EditSelectedControlScheme, buttonRect); menu.AddItem(m_DuplicateGUI, false, DuplicateControlScheme, buttonRect); menu.AddItem(m_DeleteGUI, false, DeleteControlScheme); } else { menu.AddDisabledItem(m_EditGUI, false); menu.AddDisabledItem(m_DuplicateGUI, false); menu.AddDisabledItem(m_DeleteGUI, false); } menu.ShowAsContext(); } }
internal static void ShowRuntimeViewMenu(AIUI ui, Vector2 mousePos) { if (!ui.isVisualizing) { return; } var menu = new GenericMenu(); var screenPos = EditorGUIUtility.GUIToScreenPoint(mousePos); if (ui.currentQualifier != null) { var visualizedQualifier = (IQualifierVisualizer)ui.currentQualifier.qualifier; if (visualizedQualifier.isBreakPoint) { menu.AddItem(new GUIContent("Remove Breakpoint"), false, () => visualizedQualifier.isBreakPoint = false); } else { menu.AddItem(new GUIContent("Set Breakpoint"), false, () => visualizedQualifier.isBreakPoint = true); } menu.AddItem(new GUIContent("Set Conditional Breakpoint"), false, () => BreakpointConditionWindow.Open(screenPos, visualizedQualifier)); } else if (ui.currentSelector != null) { var visualizedSelector = (SelectorVisualizer)ui.currentSelector.selector; menu.AddItem(new GUIContent("Clear Breakpoints"), false, () => visualizedSelector.ClearBreakpoints()); } else if (ui.currentAILink == null) { var visualizedAI = (UtilityAIVisualizer)ui.visualizedAI; menu.AddItem(new GUIContent("Clear All Breakpoints"), false, () => visualizedAI.ClearBreakpoints()); } menu.ShowAsContext(); }
public static void Open(string title, string[] options, System.Action <string> onSelection = null, bool closeOnSelect = true) { Vector2 mousePosition; if (Event.current != null) { mousePosition = EditorGUIUtility.GUIToScreenPoint(Event.current.mousePosition); } else { mousePosition = new Vector2(Screen.height - 100, Screen.width * 0.5f - _defaultWidth * 0.5f); } //float x = mousePosition.x < Screen.width - _defaultWidth ? mousePosition.x : mousePosition.x - _defaultWidth; //float y = mousePosition.y > _defaultHeight ? mousePosition.y : _defaultHeight; Rect windowRect = new Rect(mousePosition.x, mousePosition.y, _defaultWidth, _defaultHeight); ListViewWindow window = EditorWindow.GetWindowWithRect <ListViewWindow>(windowRect, true, title, true); window.position = windowRect; window._options = options; window._onSelection = onSelection; window._closeOnSelect = closeOnSelect; }
private void show(string key, Action <string> callBack) { pageList.dataProvider = dataList = DataSource.Get(key); Rect rect = this.position; w.ShowAuxWindow(); Vector2 v = EditorGUIUtility.GUIToScreenPoint(Event.current.mousePosition); rect.x = v.x; if (v.x + rect.width > stage.screenWidth) { rect.x = v.x - rect.width; } rect.y = v.y + 50; if (rect.y + rect.height > stage.screenHeight) { rect.y -= rect.height; } this.callBack = callBack; this.position = rect; }
private static Rect Resizer(HUMEvents.Data.Mouse mouse, Rect handleRect, Rect rect, Vector2 minSize, Vector2 maxSize, HUMEvents_Children.Side side, bool mouseDown, ref bool isUsing) { var mousePosition = EditorGUIUtility.GUIToScreenPoint(mouse.e.mousePosition); var delta = HUMEvents.mouseDelta; var handleContains = handleRect.Contains(mousePosition); if (mouse.Left().Clicked() && handleContains) { isUsing = true; HUMEvents_Children.lastLeftClickPosition = mousePosition; } if (mouse.Left().Released()) { isUsing = false; } if (handleContains && !mouseDown) { if (side == HUMEvents_Children.Side.Bottom || side == HUMEvents_Children.Side.Top) { EditorGUIUtility.AddCursorRect(new Rect(mouse.e.mousePosition, new Vector2(34, 34)), MouseCursor.ResizeVertical); } else { EditorGUIUtility.AddCursorRect(new Rect(mouse.e.mousePosition, new Vector2(34, 34)), MouseCursor.ResizeHorizontal); } } if (!mouseDown) { HUMEvents_Children.lastLeftClickPosition = mousePosition; } else { if (isUsing) { if (side == HUMEvents_Children.Side.Bottom || side == HUMEvents_Children.Side.Top) { EditorGUIUtility.AddCursorRect(new Rect(mouse.e.mousePosition, new Vector2(34, 34)), MouseCursor.ResizeVertical); } else { EditorGUIUtility.AddCursorRect(new Rect(mouse.e.mousePosition, new Vector2(34, 34)), MouseCursor.ResizeHorizontal); } var yDeltaMax = (mousePosition.y - rect.y) - (rect.yMax - rect.y); var xDeltaMax = (mousePosition.x - rect.x) - (rect.xMax - rect.x); var yDeltaMin = (mousePosition.y - rect.y) - (rect.yMin - rect.y); var xDeltaMin = (mousePosition.x - rect.x) - (rect.xMin - rect.x); if (mouse.e.type == EventType.MouseDrag) { if (side == HUMEvents_Children.Side.Bottom) { if ((rect.height + yDeltaMax < maxSize.y && rect.height + yDeltaMax > minSize.y) || yDeltaMax > 0) { mouse.e.Use(); return(rect.Add().Height(yDeltaMax)); } } if (side == HUMEvents_Children.Side.Top) { if ((rect.height + yDeltaMin < maxSize.y && rect.height + yDeltaMin > minSize.y) || yDeltaMin < 0) { mouse.e.Use(); return(rect.Subtract().Height(yDeltaMin).Add().Y(yDeltaMin)); } } if (side == HUMEvents_Children.Side.Left) { if ((rect.width + xDeltaMin < maxSize.x && rect.width + xDeltaMin > minSize.x) || xDeltaMin < 0) { mouse.e.Use(); return(rect.Subtract().Width(xDeltaMin).Add().X(xDeltaMin)); } } if (side == HUMEvents_Children.Side.Right) { if ((rect.width + xDeltaMax < maxSize.x && rect.width + xDeltaMax > minSize.x) || xDeltaMax > 0) { mouse.e.Use(); return(rect.Add().Width(xDeltaMax)); } } mouse.e.Use(); } } } return(rect); }
internal static void ShowViewMenu(AIUI ui, Vector2 mousePos) { var menu = new GenericMenu(); var screenPos = EditorGUIUtility.GUIToScreenPoint(mousePos); bool allowDelete = true; if (ui.currentAction != null) { var qv = ui.currentQualifier; Action <Type> cb = (t) => { var newInstance = (IAction)Activator.CreateInstance(t); ui.ReplaceAction(qv, newInstance); }; menu.AddItem(new GUIContent("Change Type"), false, () => AIEntitySelectorWindow.Get <IAction>(screenPos, cb)); } else if (ui.currentQualifier != null) { string label = (ui.currentAction == null && ui.currentQualifier.actionView == null) ? "Add Action" : "Replace Action"; menu.AddItem(new GUIContent(label), false, () => AIEntitySelectorWindow.Get <IAction>(screenPos, (actionType) => { ui.SetAction(actionType); })); menu.AddItem(new GUIContent("Add Qualifier (sibling)"), false, () => AIEntitySelectorWindow.Get <IQualifier>(screenPos, (qualifierType) => { ui.AddQualifier(qualifierType); })); var qv = ui.currentQualifier; if (qv.isDefault) { allowDelete = false; } else { Action <Type> cb = (t) => { var newInstance = (IQualifier)Activator.CreateInstance(t); ui.ReplaceQualifier(qv, newInstance); }; menu.AddSeparator(string.Empty); menu.AddItem(new GUIContent("Change Type"), false, () => AIEntitySelectorWindow.Get <IQualifier>(screenPos, cb)); } } else if (ui.currentSelector != null) { var sv = ui.currentSelector; menu.AddItem(new GUIContent("Add Qualifier"), false, () => AIEntitySelectorWindow.Get <IQualifier>(screenPos, (qualifierType) => { ui.AddQualifier(qualifierType); })); menu.AddSeparator(string.Empty); if (sv.isRoot) { allowDelete = false; } else { menu.AddItem(new GUIContent("Set as Root"), false, () => ui.SetRoot(sv.selector)); } Action <Type> cb = (t) => { var newInstance = (Selector)Activator.CreateInstance(t); ui.ReplaceSelector(sv, newInstance); }; menu.AddItem(new GUIContent("Change Type"), false, () => AIEntitySelectorWindow.Get <Selector>(screenPos, cb)); } else if (ui.currentAILink != null) { var alv = ui.currentAILink; Action <AIStorage> cb = (ai) => { ui.ChangeAILink(alv, new Guid(ai.aiId)); }; menu.AddItem(new GUIContent("Change AI"), false, () => AISelectorWindow.Get(screenPos, cb)); } AddSharedItems(menu, ui, allowDelete, mousePos); }
public static Color GetColorAtGUIPos(Vector2 pos) { pos = EditorGUIUtility.GUIToScreenPoint(pos); //pos.x = Screen.height - pos.x; return(GetColorAtScreenPos(pos)); }
public void RenderField(AIInspectorState state) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(_label); if (GUILayout.Button(SharedStyles.changeSelectionTooltip, SharedStyles.BuiltIn.changeButtonSmall)) { Action <Type> cb = (selectedType) => { if (_itemType.IsGenericType && selectedType.IsGenericType) { var genArgs = _itemType.GetGenericArguments(); selectedType = selectedType.GetGenericTypeDefinition().MakeGenericType(genArgs); } var old = _item; _item = Activator.CreateInstance(selectedType); _editorItem = ReflectMaster.Reflect(_item); _setter(_item); state.currentAIUI.undoRedo.Do(new CustomEditorFieldOperation(old, _item, _setter)); state.MarkDirty(); }; //We do not want the button click itself to count as a change.. same as above. GUI.changed = false; var screenPos = EditorGUIUtility.GUIToScreenPoint(Event.current.mousePosition); AIEntitySelectorWindow.Get(screenPos, _itemType, cb); } EditorGUILayout.EndHorizontal(); bool doDelete = false; if (_item != null) { EditorGUILayout.BeginVertical("Box"); EditorGUILayout.BeginHorizontal(SharedStyles.BuiltIn.listItemHeader); EditorGUILayout.LabelField(_editorItem.name, SharedStyles.BuiltIn.normalText); if (GUILayout.Button(SharedStyles.deleteTooltip, SharedStyles.BuiltIn.deleteButtonSmall)) { GUI.changed = false; if (DisplayHelper.ConfirmDelete("item")) { doDelete = true; } } EditorGUILayout.EndHorizontal(); _editorItem.Render(state); EditorGUILayout.EndVertical(); } EditorGUILayout.Separator(); //We do the delete outside any layout stuff to ensure we don't get weird warnings. if (doDelete) { state.currentAIUI.undoRedo.Do(new CustomEditorFieldOperation(_item, null, _setter)); _setter(null); _item = null; _editorItem = null; state.MarkDirty(); } }
/// <summary> /// Draw Property. /// </summary> public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { EditorGUI.BeginChangeCheck(); if (property.isArray) { // cache for Right-Click-Menu's callback. string targetPropertyPath = property.propertyPath; Object targetObject = property.serializedObject.targetObject; // draw header. DrawArrayExpander(ref position, property, label); if (property.isExpanded) { // want open menu?. bool openMenu = WantOpenMenu(); Vector3 mousePos = Event.current.mousePosition; // draw array size. EditorGUI.indentLevel++; DrawArraySize(ref position, property, targetObject, targetPropertyPath, openMenu, mousePos); // draw array elements. int size = property.arraySize; for (int i = 0; i < size; ++i) { SerializedProperty propElement = property.GetArrayElementAtIndex(i); SerializedProperty propEnd = propElement.GetEndProperty(); bool isFirst = true; // draw array elements internal. do { position.height = EditorGUI.GetPropertyHeight(propElement, label, false); Vector2 pos = EditorGUIUtility.GUIToScreenPoint(new Vector3(position.xMin, position.yMin)); // draw only inside of screen. if (0 < pos.y && pos.y < Screen.currentResolution.height + position.height) { EditorGUI.PropertyField(position, propElement); } // Right-Click-Menu collision on element header only. if (isFirst) { if (openMenu && position.Contains(mousePos)) { OpenArrayElementMenu(targetObject, targetPropertyPath, i, mousePos); } isFirst = false; } position.y += position.height; }while (propElement.NextVisible(propElement.isExpanded) && !SerializedProperty.EqualContents(propElement, propEnd)); } EditorGUI.indentLevel--; } } else { EditorGUI.BeginProperty(position, label, property); EditorGUI.HelpBox(position, "[ERROR:SmartArray] '" + label.text + "' field is not Array or List.", MessageType.Error); position.y += c_helpboxHeight; EditorGUI.EndProperty(); } if (EditorGUI.EndChangeCheck()) { heightIsChanged = true; } }
override public void OnInspectorGUI() { GA_HeatMapDataFilter heatmap = target as GA_HeatMapDataFilter; if (heatmap == null) { return; } if (!EditorUtility.IsPersistent(target)) { PrefabUtility.DisconnectPrefabInstance(heatmap.gameObject); } EditorGUI.indentLevel = 1; EditorGUILayout.Space(); GUILayout.BeginHorizontal(); EditorGUILayout.LabelField(" ", GUILayout.Width(155)); //layout hack to align. if (GUILayout.Button("Update index", GUILayout.Height(30))) { heatmap.UpdateIndexData(); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Current index:"); EditorGUILayout.LabelField((heatmap.AvailableBuilds != null && heatmap.AvailableAreas != null && heatmap.AvailableEvents != null?/*heatmap.AvailableBuilds.Count+" build(s). "+*/ heatmap.AvailableAreas.Count + " area(s). " + heatmap.AvailableEvents.Count + " event(s).":"No index data loaded")); GUILayout.EndHorizontal(); EditorGUILayout.Space(); //Version /* Removed until implemented on backend * * GUILayout.BeginHorizontal(); * EditorGUILayout.PrefixLabel("Build:"); * * heatmap.CurrentBuildIndex = EditorGUILayout.Popup(heatmap.CurrentBuildIndex, heatmap.AvailableBuilds.ToArray()); * * GUILayout.EndHorizontal(); * * * EditorGUILayout.Space();*/ //Area GUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Area:"); heatmap.CurrentAreaIndex = EditorGUILayout.Popup(heatmap.CurrentAreaIndex, heatmap.AvailableAreas.ToArray()); GUILayout.EndHorizontal(); EditorGUILayout.Space(); GUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Events:", GUILayout.Width(155)); if (heatmap.AvailableEvents.Count > 0) { //Setting some easy to understand label values for the select button int selectedEventsCount = heatmap.CurrentEventFlag.Count(b => b); string btnEventsLabel = "Mixed (" + selectedEventsCount + ")"; if (selectedEventsCount == 1) { btnEventsLabel = heatmap.AvailableEvents[heatmap.CurrentEventFlag.FindIndex(b => b)]; } if (selectedEventsCount == 0) { btnEventsLabel = "None"; } if (GUILayout.Button(btnEventsLabel, EditorStyles.popup)) { GA_EventPicker events = ScriptableObject.CreateInstance <GA_EventPicker>(); events.AvailableEvents = heatmap.AvailableEvents; events.Selected = heatmap.CurrentEventFlag; events.ShowUtility(); events.OnPicked += HandleEventsOnPicked; events.OnClosed += HandleEventsOnPicked; } } else { // no events to select from. No need to make the button EditorGUILayout.LabelField("No events"); } GUILayout.EndHorizontal(); EditorGUILayout.Space(); EditorGUILayout.Space(); GUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Select for all dates:"); heatmap.IgnoreDates = EditorGUILayout.Toggle(heatmap.IgnoreDates); GUILayout.EndHorizontal(); #if UNITY_EDITOR //Start Date GUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Start Date:", GUILayout.Width(155)); string startDateDisplay = heatmap.IgnoreDates?"All":heatmap.StartDateTime.Value.ToString("yyyy-MM-dd"); if (GUILayout.Button(startDateDisplay, EditorStyles.popup)) { GA_DatePicker date = ScriptableObject.CreateInstance <GA_DatePicker>(); date.CurrentDate = heatmap.StartDateTime.Value; date.ShowUtility(); date.OnPicked += HandleStartDateOnPicked; date.OnClosed += HandleStartDateOnClosed; } GUILayout.EndHorizontal(); EditorGUILayout.Space(); //End Date GUILayout.BeginHorizontal(); EditorGUILayout.LabelField("End Date:", GUILayout.Width(155)); string endDateDisplay = heatmap.IgnoreDates?"All":heatmap.EndDateTime.Value.ToString("yyyy-MM-dd"); if (GUILayout.Button(endDateDisplay, EditorStyles.popup)) { GA_DatePicker date = ScriptableObject.CreateInstance <GA_DatePicker>(); date.CurrentDate = heatmap.EndDateTime.Value; date.ShowUtility(); date.OnPicked += HandleEndDateOnPicked; date.OnClosed += HandleEndDateOnClosed; } GUILayout.EndHorizontal(); #endif EditorGUILayout.Space(); EditorGUILayout.Space(); GUILayout.BeginHorizontal(); EditorGUILayout.LabelField(" ", GUILayout.Width(155)); if (heatmap.Loading) { //GA_TODO: We never know how much data we are downloading right now. With a better index or a GetCount method we could estimate the download time. /* //Progress bar doesn't really contain any info when we don't know how much data we are downloading * GUILayout.Box("",GUILayout.Height(50),GUILayout.Width(200));. * if(Event.current.type == EventType.Repaint) * { * var lastrect = GUILayoutUtility.GetLastRect(); * EditorGUI.ProgressBar(lastrect,heatmap.LoadProgress,"Downloading"); * }*/ EditorGUILayout.HelpBox("Downloading data. Please wait.", MessageType.Info); } else { if (heatmap.DownloadingData) { EditorGUILayout.HelpBox("Downloading data. Please wait.", MessageType.Info); } else if (heatmap.BuildingHeatmap) { EditorGUILayout.HelpBox("Building heatmap. " + heatmap.BuildHeatmapPercentage + "%", MessageType.Info); } else if (GUILayout.Button("Download heatmap", GUILayout.Height(30))) { if (heatmap.DataContainer == null) { GA.Log("Downloading heatmap data. This might take some time.."); heatmap.DownloadUpdate(); } else { GA_HeatmapCombineTypePicker combine = ScriptableObject.CreateInstance <GA_HeatmapCombineTypePicker>(); combine.ShowUtility(); Vector2 pos = EditorGUIUtility.GUIToScreenPoint(new Vector2(GUILayoutUtility.GetLastRect().x + 150, Event.current.mousePosition.y - 25)); combine.position = new Rect(pos.x, pos.y, 300, 145); combine.OnPicked += HandleCombineOnPicked; } } } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Current dataset:"); EditorGUILayout.LabelField((heatmap.GetData() != null?+heatmap.GetData().Count + " samples":"No data loaded")); GUILayout.EndHorizontal(); EditorGUILayout.Space(); GUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Redownload in build:"); heatmap.RedownloadDataOnPlay = EditorGUILayout.Toggle(heatmap.RedownloadDataOnPlay); GUILayout.EndHorizontal(); EditorGUILayout.Space(); }
override public void OnInspectorGUI() { GA_HeatMapRenderer render = target as GA_HeatMapRenderer; if (render == null || render.Histogram == null) { return; } if (!EditorUtility.IsPersistent(target)) { PrefabUtility.DisconnectPrefabInstance(render.gameObject); } EditorGUIUtility.LookLikeControls(); EditorGUI.indentLevel = 1; EditorGUILayout.Space(); #if !UNITY_3_0 && !UNITY_3_0_0 && !UNITY_3_1 && !UNITY_3_2 && !UNITY_3_3 && !UNITY_3_4 && !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2 if (GameObject.FindObjectOfType(typeof(SpriteRenderer))) { EditorGUILayout.HelpBox("In order to render the heatmap in front of any 2D sprites you must go to: Edit > Project Settings > Tags and Layers, and move the Default Layer to the bottom of the Sorting Layers list.", MessageType.Warning); EditorGUILayout.Space(); } #endif if (render.transform.position != Vector3.zero) { // not placed in zero and heatmap data is off. It might be useful to move the heatmap to create layers, but we should warn the user. EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Heatmap is not in (0,0,0) - the visualization will be offset!"); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Reset position")) { render.transform.position = Vector3.zero; } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); } EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Histogram of dataset", EditorStyles.largeLabel); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Shows the data point count for event occurrences in the dataset", EditorStyles.miniLabel); EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); GUILayout.Box("", GUIStyle.none, GUILayout.Width(20)); //layout hack GUILayout.Box("", GUILayout.MinWidth(50), GUILayout.MaxWidth(700), GUILayout.MinHeight(200)); if (Event.current.type == EventType.Repaint) { lastrect = GUILayoutUtility.GetLastRect(); } GUILayout.Box("", GUIStyle.none, GUILayout.Width(15)); //layout hack to get right margin if (render.Histogram != null && (render.Histogram.Data == null || render.Histogram.Data.Length == 0)) { GUI.Label(new Rect(lastrect.x + lastrect.width / 2 - 50, lastrect.y + lastrect.height / 2, 100, 40), "No data loaded", EditorStyles.largeLabel); } else if (render.Histogram != null && render.Histogram.Data != null && render.Histogram.Data.Length < 3) { GUI.Label(new Rect(lastrect.x + lastrect.width / 2 - 105, lastrect.y + lastrect.height / 2, 300, 40), "Not enough data to show histogram", EditorStyles.largeLabel); } Vector2 textPos = new Vector2(lastrect.xMin + lastrect.height / 2 - 63, lastrect.yMax - 20); Vector2 textGuiPos = EditorGUIUtility.GUIToScreenPoint(textPos); GUIUtility.RotateAroundPivot(-90f, new Vector2(lastrect.xMin, lastrect.yMax)); if (textGuiPos.y > 125) { int maxChars = ((int)textGuiPos.y - 125) / 5; GUI.Label(new Rect(textPos.x, textPos.y, 200, 20), "Number of data points".Substring(0, Mathf.Max(0, Mathf.Min(maxChars, 21))), EditorStyles.label); } GUIUtility.RotateAroundPivot(90f, new Vector2(lastrect.xMin, lastrect.yMax)); GUI.Label(new Rect(lastrect.xMin + lastrect.width / 2 - 85, lastrect.yMax + 40, 200, 20), "Frequency / event occurrences", EditorStyles.label); if (render.Histogram.Data != null && render.Histogram.Data.Length >= 3) { float margin = lastrect.width / (render.Histogram.Data.Length); int numLabels = 10; int labelInterval = Mathf.FloorToInt(render.Histogram.Data.Length / (float)numLabels); labelInterval = Mathf.Max(1, labelInterval); for (int i = 0; i < render.Histogram.Data.Length; i++) { float lineWidth = Mathf.Max(2, margin - 2); if (Screen.width > 90 + i * lineWidth) { float c = render.Histogram.Data[i] * lastrect.height; float x = lastrect.x + (i + 0.5f) * margin; float y = lastrect.y + lastrect.height; float pct = i / (float)render.Histogram.Data.Length; Color nonSelectedColor = new Color(0.6f, 0.6f, 0.6f, 0.3f); float rangePct = (pct - render.RangeMin) / (render.RangeMax - render.RangeMin); float line, linePct, colorPct, barHeight; Color color = Color.white; for (int xline = 0; xline < lineWidth; xline++) { Vector2 guiPos = EditorGUIUtility.GUIToScreenPoint(new Vector2(x, y)); barHeight = Mathf.Min(c, guiPos.y - 93); //cut bar height if too high for inspector window barHeight = Mathf.Max(0f, barHeight); line = x - lineWidth / 2 + xline; linePct = pct + 1f / render.Histogram.Data.Length * (xline / lineWidth); if (render.Histogram.RealDataMin >= 0) { colorPct = rangePct + 1f / render.Histogram.Data.Length * (xline / lineWidth); color = Color.Lerp(render.MinColor, render.MaxColor, colorPct); } else { float zeroNorm = (0 - render.Histogram.RealDataMin) / (render.Histogram.RealDataMax - render.Histogram.RealDataMin); if (pct >= zeroNorm * 0.9f && pct <= zeroNorm * 1.1f) { color = Color.white; } else if (pct < zeroNorm) { float newNorm = pct / zeroNorm * (1 - render.RangeMin / zeroNorm); color = Color.Lerp(render.MinColor, Color.white, newNorm); } else { float newNorm = zeroNorm / pct * render.RangeMax; color = Color.Lerp(Color.white, render.MaxColor, 1 - newNorm); } } if (linePct <= render.RangeMin || linePct >= render.RangeMax) { color = nonSelectedColor; } GA_GUIHelper.DrawLine(new Vector2(line, y), new Vector2(line, y - barHeight), color); } } } } /// 0% label Vector2 label = new Vector2(lastrect.xMin, lastrect.yMax + 10); GUIUtility.RotateAroundPivot(50f, label); GUI.Label(new Rect(label.x, label.y, 40, 20), "0%", EditorStyles.miniLabel); GUIUtility.RotateAroundPivot(-50f, label); // 50% label label = new Vector2(lastrect.center.x, lastrect.yMax + 10); GUIUtility.RotateAroundPivot(50f, label); GUI.Label(new Rect(label.x, label.y, 40, 20), "50%", EditorStyles.miniLabel); GUIUtility.RotateAroundPivot(-50f, label); // 100% label label = new Vector2(lastrect.xMax - 14, lastrect.yMax + 10); GUIUtility.RotateAroundPivot(50f, label); GUI.Label(new Rect(label.x, label.y, 40, 20), "100%", EditorStyles.miniLabel); GUIUtility.RotateAroundPivot(-50f, label); // 100% label. real value label = new Vector2(lastrect.xMax - (10 + Mathf.Pow(render.Histogram.RealDataMax, 0.25f)), lastrect.yMin - 15); GUI.Label(new Rect(label.x, label.y, 75, 20), render.Histogram.RealDataMax.ToString("G5"), EditorStyles.miniLabel); // 0% label. real value label = new Vector2(lastrect.xMin, lastrect.yMin - 15); GUI.Label(new Rect(label.x, label.y, 75, 20), render.Histogram.RealDataMin.ToString("G5"), EditorStyles.miniLabel); /*if (render.Histogram.RealDataMin < 0) * { * // if minimum count is below zero then also show zero real value point * float zeroNorm = (0 - render.Histogram.RealDataMin) / (render.Histogram.RealDataMax - render.Histogram.RealDataMin); * label = new Vector2((zeroNorm * lastrect.xMax),lastrect.yMin-15); * GUI.Label(new Rect(label.x,label.y,75,20),"0",EditorStyles.miniLabel); * }*/ GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Box("", GUIStyle.none, GUILayout.Width(8)); //layout hack EditorGUILayout.MinMaxSlider(ref render.RangeMin, ref render.RangeMax, 0f, 1f, GUILayout.Width(lastrect.width + 15)); GUILayout.EndHorizontal(); render.MinColor = EditorGUI.ColorField(new Rect(lastrect.xMin - 10, lastrect.yMax + 44, 50, 18), render.MinColor); render.MaxColor = EditorGUI.ColorField(new Rect(lastrect.xMax - 45, lastrect.yMax + 44, 50, 18), render.MaxColor); GUILayout.BeginHorizontal(); GUILayout.Box("", GUIStyle.none, GUILayout.Height(70)); //layout hack GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Show heatmap:"); if (render.BillBoard != null) { render.BillBoard.GetComponent <MeshRenderer>().enabled = EditorGUILayout.Toggle(render.BillBoard.GetComponent <MeshRenderer>().enabled); } else { EditorGUILayout.Toggle(true); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Preset Colors:", GUILayout.Width(155)); if (GUILayout.Button("Select Color Preset")) { GA_HeatmapColorPresetPicker colorpresetpicker = ScriptableObject.CreateInstance <GA_HeatmapColorPresetPicker>(); colorpresetpicker.ShowUtility(); Vector2 pos = EditorGUIUtility.GUIToScreenPoint(new Vector2(GUILayoutUtility.GetLastRect().x + 150, Event.current.mousePosition.y - 25)); colorpresetpicker.position = new Rect(pos.x, pos.y, 180, 145); colorpresetpicker.OnPicked += HandleColorPresetPicker; } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Histogram scale:"); GA_Histogram.HistogramScale oldScale = render.HistogramScale; render.HistogramScale = (GA_Histogram.HistogramScale)EditorGUILayout.EnumPopup(render.HistogramScale); if (render.HistogramScale != oldScale) { render.OnScaleChanged(); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Render model:"); GA_HeatMapRenderer.RenderModel oldRenderModel = render.CurrentRenderModel; render.CurrentRenderModel = (GA_HeatMapRenderer.RenderModel)EditorGUILayout.EnumPopup(render.CurrentRenderModel); if (render.CurrentRenderModel != oldRenderModel) { render.RenderModelChanged(); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Point radius:"); float oldMaxRadius = render.MaxRadius; render.MaxRadius = EditorGUILayout.Slider(render.MaxRadius, 0f, 10f); if (render.MaxRadius != oldMaxRadius) { render.SetMaterialVariables(); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Show values (slow):"); render.ShowValueLabels = EditorGUILayout.Toggle(render.ShowValueLabels); GUILayout.EndHorizontal(); EditorGUILayout.Space(); if (GUI.changed) { if (SystemInfo.graphicsShaderLevel < 20) { GA.Log("GameAnalytics: GPU does not support shader needed"); } EditorUtility.SetDirty(target); render.SetMaterialVariables(); } }
public static string DatePicker(string value, GUIStyle fieldStyle, EditorGUIBinding.TextFieldChangeHandler change, EditorGUIBinding.TextFieldFailureHandler failure = null, EditorGUIBinding.TextFieldValidationHandler validate = null) { int controlID = GUIUtility.GetControlID(FocusType.Keyboard); Rect controlRect = EditorGUILayout.GetControlRect(false); fieldStyle.contentOffset = fieldOffset; fieldStyle.clipping = TextClipping.Overflow; EditorGUI.BeginChangeCheck(); EditorGUI.LabelField(controlRect, value, fieldStyle); DatePickerWindow window = null; switch (Event.current.GetTypeForControl(controlID)) { case EventType.MouseDown: if (controlRect.Contains(Event.current.mousePosition) && Event.current.button == 0) { GUIUtility.hotControl = controlID; Event.current.Use(); } break; case EventType.MouseUp: if (GUIUtility.hotControl == controlID && Event.current.button == 0 && controlRect.Contains(Event.current.mousePosition)) { s_DoDropDown = true; Event.current.Use(); } break; case EventType.Repaint: if (GUIUtility.hotControl == controlID && s_DoDropDown) { s_DoDropDown = false; s_CachedControlId = controlID; GUIUtility.hotControl = 0; Vector2 position = EditorGUIUtility.GUIToScreenPoint(new Vector2(controlRect.x, controlRect.y + controlRect.height)); window = ScriptableObject.CreateInstance <DatePickerWindow>(); window.ShowAsDropDown(new Rect(position.x, position.y - winSize.y, winSize.x, winSize.y), winSize, value); } break; } if (s_CachedControlId == controlID && s_CachedValue != null) { value = s_CachedValue; s_CachedControlId = 0; s_CachedValue = null; GUI.changed = true; } if (EditorGUI.EndChangeCheck()) { DatePickerApplyChangeHandlers(value, change, failure, validate); } return(value); }
public override void OnGUI(Rect rect, SerializedProperty property, GUIContent label) { TryInitialize(property); EditorGUI.BeginProperty(rect, label, property); var header = new Rect(rect.position, new Vector2(rect.width, EditorGUIUtility.singleLineHeight)); Rect buttonRect; var isArrayElement = property.name == "data"; if (!isArrayElement) { var layout = header.GetLayout(); property.isExpanded = EditorGUI.Foldout(layout.label, property.isExpanded, label); buttonRect = layout.value; } else { var type = property.type; var firstIndex = type.IndexOf('<'); var secondIndex = type.IndexOf('>'); if (secondIndex - firstIndex <= 1) { buttonRect = header; } else { buttonRect = EditorGUI.IndentedRect(header); var foldoutRect = new Rect(buttonRect.position, Vector2.one * buttonRect.height); property.isExpanded = EditorGUI.Foldout(foldoutRect, property.isExpanded, GUIContent.none); buttonRect = buttonRect.Indent(DrawingUtilities.Margin); } } var style = EditorStyles.textField; var name = property.type.Split('<')[1]; name = name.Remove(name.Length - 1); if (GUI.Button(buttonRect, $" {name}", style)) { var x = buttonRect.x + buttonRect.width * 0.5f; var y = buttonRect.yMax + buttonRect.height * 0.75f; var anchor = EditorGUIUtility.GUIToScreenPoint(new Vector2(x, y)); var window = windows[fieldType]; window.Ticket = property; SearchWindow.Open(new SearchWindowContext(anchor, buttonRect.width), windows[fieldType]); } var iconRect = new Rect(buttonRect.position, Vector2.one * buttonRect.height).Expand(-1.0f); GUI.DrawTexture(iconRect, EditorGUIUtility.IconContent("Collab@2x").image, ScaleMode.StretchToFill); if (!property.isExpanded) { End(property); return; } if (property.TryGetTypedDrawer(out var drawer)) { var rest = new Rect(new Vector2(rect.x, header.yMax + DrawingUtilities.Margin), new Vector2(rect.width, rect.height - header.height)); drawer.OnGUI(rest, property, label); } else { var start = header.position + Vector2.up * (header.height + DrawingUtilities.Margin); property.DrawValues(start, rect.width, !isArrayElement); } End(property); }
/// <summary> /// Convert rectangle from window space to screen space. /// </summary> /// <param name="guiRect">GUI Rectangle.</param> /// <returns> /// Screen rectangle. /// </returns> public static Rect GUIToScreenRect(Rect guiRect) { Vector2 screenPoint = EditorGUIUtility.GUIToScreenPoint(new Vector2(guiRect.x, guiRect.y)); return(new Rect(screenPoint.x, screenPoint.y, guiRect.width, guiRect.height)); }
private void AddNew(Vector2 mousePos, AIInspectorState state) { if (_isSimpleType) { if (_list == null) { _setter(CreateList()); } if (_simpleItemCreator == null) { _simpleItemCreator = new SimpleItemConstructor(_list, _itemType); } var item = Activator.CreateInstance(_itemType); DoAdd(item, state); var itemWrapper = _simpleItemCreator.Conctruct(_list.Count - 1, item); _editorItems.Add(ReflectMaster.Reflect(itemWrapper)); return; } Action <Type[]> cb = (selectedTypes) => { if (_list == null) { _setter(CreateList()); } using (state.currentAIUI.undoRedo.bulkOperation) { for (int i = 0; i < selectedTypes.Length; i++) { var selectedType = selectedTypes[i]; if (_itemType.IsGenericType && selectedType.IsGenericType) { var genArgs = _itemType.GetGenericArguments(); selectedType = selectedType.GetGenericTypeDefinition().MakeGenericType(genArgs); } var item = Activator.CreateInstance(selectedType); DoAdd(item, state); _editorItems.Add(ReflectMaster.Reflect(item)); if (Application.isPlaying) { HandleVisualizerAdd(state, item); } } state.MarkDirty(); } }; // We do not want the button click itself to count as a change.. same as above. GUI.changed = false; var screenPos = EditorGUIUtility.GUIToScreenPoint(mousePos); AIEntitySelectorWindow.Get(screenPos, _itemType, cb); }