public MenuItem(GUIContent _content, bool _separator, bool _on, GenericMenu.MenuFunction _func) { this.content = _content; this.separator = _separator; this.on = _on; this.func = _func; }
public WorldPopup(WorldSelectionGetter getWorld, WorldSelectionSetter setWorld, ShowInactiveSystemsGetter getShowSystems, GenericMenu.MenuFunction setShowSystems, Func <bool> getShowAllWorlds, Action <bool> setShowAllWorlds) { getWorldSelection = getWorld; setWorldSelection = setWorld; getShowInactiveSystems = getShowSystems; setShowInactiveSystems = setShowSystems; this.getShowAllWorlds = getShowAllWorlds; this.setShowAllWorlds = setShowAllWorlds; }
public GenericMenuView AddMenu(string menuPath, GenericMenu.MenuFunction click) { mMenu.AddItem(new GUIContent(menuPath), false, click); return(this); }
void HandlePendingEvents(Rect Canvas, List <DataStreamMeta> Streams) { System.Func <Vector2, TimeUnit?> CanvasPositionToTime = (Position) => { return(PositionToTime(Canvas, Position)); }; System.Func <Vector2, StreamAndTime> CanvasPositionToStreamAndTime = (Position) => { int?StreamIndex; var Time = PositionToTime(Canvas, Position, Streams, out StreamIndex); return(new StreamAndTime(Streams[StreamIndex.Value], Time.Value)); }; Input.ProcessScroll((ScrollTime) => { ScrollTimeLeft.Time += ScrollTime.Time; StickyScroll = false; }); Input.ProcessSelect(CanvasPositionToTime, (SelectTime) => { LastStickySelectTime = null; if (SelectTime.HasValue) { OnSelectTime(SelectTime.Value); } }); Input.ProcessHover(CanvasPositionToTime, (HoverTime) => { OnMouseHover(HoverTime); }); if (Input.MouseDragCurrentPosition.HasValue) { // new drag if (CurrentDrag == null) { CurrentDrag = new DragMeta(); CurrentDrag.DragAmount = new TimeUnit(0); CurrentDrag.GrabTime = PositionToTime(Canvas, Input.MouseDragCurrentPosition.Value, Streams, out CurrentDrag.StreamIndex); // check is draggable CurrentDrag.Draggable = false; try { var Stream = Streams[CurrentDrag.StreamIndex.Value]; CurrentDrag.Draggable = Stream.Draggable; } catch { CurrentDrag.Draggable = false; } } else { if (CurrentDrag.Draggable) { // update drag var NewDragTime = PositionToTime(Canvas, Input.MouseDragCurrentPosition.Value); if (CurrentDrag.GrabTime.HasValue && NewDragTime.HasValue) { CurrentDrag.DragAmount = new TimeUnit(NewDragTime.Value.Time - CurrentDrag.GrabTime.Value.Time); } } } Input.MouseDragCurrentPosition = null; } // drag released if (Input.MouseDragEndPosition.HasValue) { // invoke the drag try { var Stream = Streams[CurrentDrag.StreamIndex.Value]; if (Stream.OnDragged != null) { Stream.OnDragged(CurrentDrag.GrabTime.Value, CurrentDrag.DragAmount); } } catch (System.Exception e) { Debug.LogException(e); } CurrentDrag = null; Input.MouseDragEndPosition = null; } if (Input.MouseJumpPrevPos.HasValue) { try { int?StreamIndex; var JumpFromTime = PositionToTime(Canvas, Input.MouseJumpPrevPos.Value, Streams, out StreamIndex); // get prev pos in stream var PrevItemTime = new TimeUnit(JumpFromTime.Value.Time - 1); var PrevItem = Bridge.GetNearestOrPrevStreamData(Streams[StreamIndex.Value], ref PrevItemTime); // want the item to appear under mouse (where we clicked) var ScrollOffset = JumpFromTime.Value.Time - ScrollTimeLeft.Time; var PrevTimeLeft = PrevItemTime.Time - ScrollOffset; ScrollTimeLeft = new TimeUnit(PrevTimeLeft); } catch (System.Exception) { // probably no more data EditorApplication.Beep(); //Debug.LogException(e); } finally { Input.MouseJumpPrevPos = null; } } if (Input.MouseJumpNextPos.HasValue) { try { int?StreamIndex; var JumpFromTime = PositionToTime(Canvas, Input.MouseJumpNextPos.Value, Streams, out StreamIndex); var NextItemTime = new TimeUnit(JumpFromTime.Value.Time + 1); var NextItem = Bridge.GetNearestOrNextStreamData(Streams[StreamIndex.Value], ref NextItemTime); // want the item to appear under mouse (where we clicked) var ScrollOffset = JumpFromTime.Value.Time - ScrollTimeLeft.Time; var NextTimeLeft = NextItemTime.Time - ScrollOffset; ScrollTimeLeft = new TimeUnit(NextTimeLeft); } catch (System.Exception) { // probably no more data EditorApplication.Beep(); //Debug.LogException(e); } finally { Input.MouseJumpNextPos = null; } } Input.ProcessMenuClick(CanvasPositionToStreamAndTime, (StreamAndTime) => { if (StreamAndTime.Stream.OnCreateContextMenu == null) { EditorApplication.Beep(); return; } // create the menu and add items to it var Menu = new GenericMenu(); EnumCommand AppendMenuItem = (Label, Lambda) => { if (string.IsNullOrEmpty(Label) || Label.EndsWith("-")) { // todo; use path Menu.AddSeparator(null); } else if (Lambda == null) { Menu.AddDisabledItem(new GUIContent(Label)); } else { // argh damned delegates GenericMenu.MenuFunction Callback = () => { Lambda(); }; Menu.AddItem(new GUIContent(Label), false, Callback); } }; StreamAndTime.Stream.OnCreateContextMenu(StreamAndTime.Time, AppendMenuItem); Menu.ShowAsContext(); }); }
public void AddItem(string itemName, GenericMenu.MenuFunction callback) { m_tabMenu.AddItem(new GUIContent(itemName), false, callback); }
public static void DropdownMultiple ( Vector2 position, MultipleCallback callback, IEnumerable <DropdownOption <T> > options, IEnumerable <T> selectedOptions, bool hasMultipleDifferentValues ) { selectedOptions = SanitizeMultipleOptions(options, selectedOptions); bool hasOptions = options != null && options.Any(); GenericMenu menu = new GenericMenu(); GenericMenu.MenuFunction2 switchCallback = (o) => { GUI.changed = true; var switchOption = (T)o; var newSelectedOptions = selectedOptions.ToList(); if (newSelectedOptions.Contains(switchOption)) { newSelectedOptions.Remove(switchOption); } else { newSelectedOptions.Add(switchOption); } callback(newSelectedOptions); }; GenericMenu.MenuFunction nothingCallback = () => { GUI.changed = true; callback(Enumerable.Empty <T>()); }; GenericMenu.MenuFunction everythingCallback = () => { GUI.changed = true; callback(options.Select((o) => o.value)); }; menu.AddItem(new GUIContent("Nothing"), !hasMultipleDifferentValues && !selectedOptions.Any(), nothingCallback); menu.AddItem(new GUIContent("Everything"), !hasMultipleDifferentValues && selectedOptions.Count() == options.Count() && Enumerable.SequenceEqual(selectedOptions.OrderBy(t => t), options.Select(o => o.value).OrderBy(t => t)), everythingCallback); if (hasOptions) { menu.AddSeparator(""); // Not in Unity default, but pretty foreach (var option in options) { bool on = !hasMultipleDifferentValues && (selectedOptions.Any(selectedOption => EqualityComparer <T> .Default.Equals(selectedOption, option.value))); menu.AddItem(new GUIContent(option.label), on, switchCallback, option.value); } } menu.DropDown(new Rect(position, Vector2.zero)); }
protected void AddAchieveItem(string menuName, GenericMenu.MenuFunction function, Func <bool> able = null) { m_MenuItems.Add(menuName, new MenuItem(menuName, function, able)); }
/// <summary> /// Adds an item to the menu /// </summary> /// <param name="content">The content to display</param> /// <param name="showTick">Should the item show a check in front of it</param> /// <param name="func">The function to call when this item is clicked</param> public GenericMenuBuilder AddItem(string content, bool showTick, GenericMenu.MenuFunction func) { Menu.AddItem(new GUIContent(content), showTick, func); return(this); }
public static void BuildNewTracksContextMenu(List <MenuActionItem> menuItems, ICollection <TrackAsset> parentTracks, WindowState state, string format = null) { if (parentTracks == null) { parentTracks = new TrackAsset[0]; } if (string.IsNullOrEmpty(format)) { format = "{0}"; } // Add Group or SubGroup var title = string.Format(format, parentTracks.Any(t => t != null) ? Styles.trackSubGroup : Styles.trackGroup); var menuState = ActionValidity.Valid; if (state.editSequence.isReadOnly) { menuState = ActionValidity.Invalid; } if (parentTracks.Any() && parentTracks.Any(t => t != null && t.lockedInHierarchy)) { menuState = ActionValidity.Invalid; } GenericMenu.MenuFunction command = () => { SelectionManager.Clear(); if (parentTracks.Count == 0) { Selection.Add(TimelineHelpers.CreateTrack <GroupTrack>(null, title)); } foreach (var parentTrack in parentTracks) { Selection.Add(TimelineHelpers.CreateTrack <GroupTrack>(parentTrack, title)); } TimelineEditor.Refresh(RefreshReason.ContentsAddedOrRemoved); }; menuItems.Add( new MenuActionItem() { category = string.Empty, entryName = title, isActiveInMode = true, priority = MenuPriority.AddItem.addGroup, state = menuState, isChecked = false, callback = command } ); var allTypes = TypeUtility.AllTrackTypes().Where(x => x != typeof(GroupTrack) && !TypeUtility.IsHiddenInMenu(x)).ToList(); int builtInPriority = MenuPriority.AddItem.addTrack; int customPriority = MenuPriority.AddItem.addCustomTrack; foreach (var trackType in allTypes) { var trackItemType = trackType; command = () => { SelectionManager.Clear(); if (parentTracks.Count == 0) { SelectionManager.Add(TimelineHelpers.CreateTrack((Type)trackItemType, null)); } foreach (var parentTrack in parentTracks) { SelectionManager.Add(TimelineHelpers.CreateTrack((Type)trackItemType, parentTrack)); } }; menuItems.Add( new MenuActionItem() { category = TimelineHelpers.GetTrackCategoryName(trackType), entryName = string.Format(format, TimelineHelpers.GetTrackMenuName(trackItemType)), isActiveInMode = true, priority = TypeUtility.IsBuiltIn(trackType) ? builtInPriority++ : customPriority++, state = menuState, callback = command } ); } }
static void AddClipMenuCommands(List <MenuActionItem> menuItems, ICollection <TrackAsset> tracks, double candidateTime) { if (!tracks.Any()) { return; } var trackAsset = tracks.First(); var trackType = trackAsset.GetType(); if (tracks.Any(t => t.GetType() != trackType)) { return; } var enabled = tracks.All(t => t != null && !t.lockedInHierarchy) && !TimelineWindow.instance.state.editSequence.isReadOnly; var assetTypes = TypeUtility.GetPlayableAssetsHandledByTrack(trackType); var visibleAssetTypes = TypeUtility.GetVisiblePlayableAssetsHandledByTrack(trackType); // skips the name if there is only a single type var commandNameTemplate = assetTypes.Count() == 1 ? Styles.addSingleItemFromAssetTemplate : Styles.addItemFromAssetTemplate; int builtInPriority = MenuPriority.AddItem.addClip; int customPriority = MenuPriority.AddItem.addCustomClip; foreach (var assetType in assetTypes) { var assetItemType = assetType; var category = TimelineHelpers.GetItemCategoryName(assetType); Action <Object> onObjectChanged = obj => { if (obj != null) { foreach (var t in tracks) { TimelineHelpers.CreateClipOnTrack(assetItemType, obj, t, candidateTime); } } }; foreach (var objectReference in TypeUtility.ObjectReferencesForType(assetType)) { var isSceneReference = objectReference.isSceneReference; var dataType = objectReference.type; GenericMenu.MenuFunction menuCallback = () => { ObjectSelector.get.Show(null, dataType, null, isSceneReference, null, (obj) => onObjectChanged(obj), null); ObjectSelector.get.titleContent = EditorGUIUtility.TrTextContent(string.Format(Styles.typeSelectorTemplate, TypeUtility.GetDisplayName(dataType))); }; menuItems.Add( new MenuActionItem() { category = category, entryName = string.Format(commandNameTemplate, TypeUtility.GetDisplayName(assetType), TypeUtility.GetDisplayName(objectReference.type)), isActiveInMode = true, priority = TypeUtility.IsBuiltIn(assetType) ? builtInPriority++ : customPriority++, state = enabled ? ActionValidity.Valid : ActionValidity.Invalid, callback = menuCallback } ); } } foreach (var assetType in visibleAssetTypes) { var assetItemType = assetType; var category = TimelineHelpers.GetItemCategoryName(assetType); var commandName = string.Format(Styles.addItemTemplate, TypeUtility.GetDisplayName(assetType)); GenericMenu.MenuFunction command = () => { foreach (var t in tracks) { TimelineHelpers.CreateClipOnTrack(assetItemType, t, candidateTime); } }; menuItems.Add( new MenuActionItem() { category = category, entryName = commandName, isActiveInMode = true, priority = TypeUtility.IsBuiltIn(assetItemType) ? builtInPriority++ : customPriority++, state = enabled ? ActionValidity.Valid : ActionValidity.Invalid, callback = command } ); } }
public ContextMenuItem(string label, string tooltip, GenericMenu.MenuFunction action = null) { this.label = new GUIContent(label, tooltip); this.action = action; }
public WorldPopup(WorldSelectionGetter getWorld, WorldSelectionSetter setWorld, ShowInactiveSystemsGetter getShowSystems, GenericMenu.MenuFunction setShowSystems) { getWorldSelection = getWorld; setWorldSelection = setWorld; getShowInactiveSystems = getShowSystems; setShowInactiveSystems = setShowSystems; }
private void RegisterUnityObject(GenericMenu menu, IPropertyValueEntry <T> entry, string path, UnityEngine.Object obj, Type returnType, Type[] parameters) { MethodInfo[] methods = obj.GetType() .GetAllMembers <MethodInfo>(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance) .Where(n => { if (n.ReturnType != returnType) { return(false); } var methodParams = n.GetParameters(); if (methodParams.Length != parameters.Length) { return(false); } for (int i = 0; i < methodParams.Length; i++) { if (methodParams[i].ParameterType != parameters[i]) { return(false); } } return(true); }) .ToArray(); var context = entry.Context.Get(this, "GameObject", (UnityEngine.Object)null); foreach (var method in methods) { string name = method.GetFullName(); MethodInfo closureMethod = method; // For lambda capture if (method.DeclaringType != obj.GetType()) { name = method.DeclaringType.GetNiceName() + "/" + name; } if (method.IsStatic) { name += " (static)"; } GenericMenu.MenuFunction func = () => { entry.Property.Tree.DelayActionUntilRepaint(() => { Delegate del; if (closureMethod.IsStatic) { del = Delegate.CreateDelegate(typeof(T), null, closureMethod); } else { del = Delegate.CreateDelegate(typeof(T), obj, closureMethod); } for (int i = 0; i < entry.ValueCount; i++) { entry.Values[i] = (T)(object)del; } // Apply changes is called immediately after this is invoked in repaint, during EndDrawPropertyTree //entry.ApplyChanges(); context.Value = null; }); }; menu.AddItem(new GUIContent((path + "/" + name).TrimStart('/')), false, func); } }
public static void SetFunc(object menuItem, GenericMenu.MenuFunction func) { menuItemFunc.SetValue(menuItem, func); }
public BuildSettingCreator(string name, GenericMenu.MenuFunction function) { DisplayName = name; Function = function; }
static void GetCopyPasteAction(MaterialProperty prop, out GenericMenu.MenuFunction copyAction, out GenericMenu.MenuFunction pasteAction) { bool canCopy = !capturedProperties[0].hasMixedValue; bool canPaste = GUI.enabled; copyAction = null; pasteAction = null; switch (prop.type) { case PropType.Float: case PropType.Range: if (canCopy) { copyAction = () => Clipboard.floatValue = prop.floatValue; } if (canPaste && Clipboard.hasFloat) { pasteAction = () => prop.floatValue = Clipboard.floatValue; } break; case PropType.Int: if (canCopy) { copyAction = () => Clipboard.integerValue = prop.intValue; } if (canPaste && Clipboard.hasInteger) { pasteAction = () => prop.intValue = Clipboard.integerValue; } break; case PropType.Color: if (canCopy) { copyAction = () => Clipboard.colorValue = prop.colorValue; } if (canPaste && Clipboard.hasColor) { pasteAction = () => prop.colorValue = Clipboard.colorValue; } break; case PropType.Vector: if (canCopy) { copyAction = () => Clipboard.vector4Value = prop.vectorValue; } if (canPaste && Clipboard.hasVector4) { pasteAction = () => prop.vectorValue = Clipboard.vector4Value; } break; case PropType.Texture: if (canCopy) { copyAction = () => Clipboard.guidValue = AssetDatabase.GUIDFromAssetPath(AssetDatabase.GetAssetPath(prop.textureValue)); } if (canPaste && Clipboard.hasGuid) { pasteAction = () => prop.textureValue = AssetDatabase.LoadMainAssetAtPath(AssetDatabase.GUIDToAssetPath(Clipboard.guidValue)) as Texture; } break; } }
public static void AddItem(this GenericMenu menu, string s, GenericMenu.MenuFunction func) { menu.AddItem(s, false, func); }
/// <summary> /// Adds an item to the menu /// </summary> /// <param name="content">The content to display</param> /// <param name="showTick">Should the item show a check in front of it</param> /// <param name="func">The function to call when this item is clicked</param> public GenericMenuBuilder AddItem(GUIContent content, bool showTick, GenericMenu.MenuFunction func) { Menu.AddItem(content, showTick, func); return(this); }
public static void AddItem(this GenericMenu menu, string s1, string s2, bool on, GenericMenu.MenuFunction func) { menu.AddItem(new GUIContent(s1, s2), on, func); }
protected void AddAchieveItem(string menuName, GenericMenu.MenuFunction function, bool able) { m_MenuItems.Add(menuName, new MenuItem(menuName, function, () => able)); }
public static void AddItemAndDisable(this GenericMenu menu, bool b, string s, GenericMenu.MenuFunction func) { if (b) { menu.AddItem(s, false, func); } else { menu.AddDisabledItem(s); } }
public static ReorderableList CreateTileViewReorderableList(Tileset tileset) { ReorderableList tileViewRList = new ReorderableList( tileset.TileViews, typeof(TileView), true, true, true, true); tileViewRList.onAddDropdownCallback = (Rect buttonRect, ReorderableList l) => { GenericMenu menu = new GenericMenu(); GenericMenu.MenuFunction addTileSelectionFunc = () => { TileSelection tileSelection = tileset.TileSelection.Clone(); tileSelection.FlipVertical(); // flip vertical to fit the tileset coordinate system ( from top to bottom ) tileset.AddTileView("new TileView", tileSelection); EditorUtility.SetDirty(tileset); }; GenericMenu.MenuFunction addBrushSelectionFunc = () => { TileSelection tileSelection = BrushBehaviour.CreateTileSelection(); tileset.AddTileView("new TileView", tileSelection); EditorUtility.SetDirty(tileset); }; GenericMenu.MenuFunction removeAllTileViewsFunc = () => { if (EditorUtility.DisplayDialog("Warning!", "Are you sure you want to delete all the TileViews?", "Yes", "No")) { tileset.RemoveAllTileViews(); EditorUtility.SetDirty(tileset); } }; if (tileset.TileSelection != null) menu.AddItem(new GUIContent("Add Tile Selection"), false, addTileSelectionFunc); else menu.AddDisabledItem(new GUIContent("Add Tile Selection to TileView")); if (BrushBehaviour.GetBrushTileset() == tileset && BrushBehaviour.CreateTileSelection() != null) menu.AddItem(new GUIContent("Add Brush Selection"), false, addBrushSelectionFunc); menu.AddSeparator(""); menu.AddItem(new GUIContent("Remove All TileViews"), false, removeAllTileViewsFunc); menu.AddSeparator(""); menu.AddItem(new GUIContent("Sort By Name"), false, tileset.SortTileViewsByName); menu.ShowAsContext(); }; tileViewRList.onRemoveCallback = (ReorderableList list) => { if (EditorUtility.DisplayDialog("Warning!", "Are you sure you want to delete the TileView?", "Yes", "No")) { ReorderableList.defaultBehaviours.DoRemoveButton(list); EditorUtility.SetDirty(tileset); } }; tileViewRList.drawHeaderCallback = (Rect rect) => { EditorGUI.LabelField(rect, "TileViews", EditorStyles.boldLabel); Texture2D btnTexture = tileViewRList.elementHeight == 0f ? EditorGUIUtility.FindTexture("winbtn_win_max_h") : EditorGUIUtility.FindTexture("winbtn_win_min_h"); if (GUI.Button(new Rect(rect.width - rect.height, rect.y, rect.height, rect.height), btnTexture, EditorStyles.label)) { tileViewRList.elementHeight = tileViewRList.elementHeight == 0f ? EditorGUIUtility.singleLineHeight : 0f; tileViewRList.draggable = tileViewRList.elementHeight > 0f; } }; tileViewRList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => { if (tileViewRList.elementHeight == 0f) return; Rect rLabel = new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight); TileView tileView = tileViewRList.list[index] as TileView; if (index == tileViewRList.index) { string newName = EditorGUI.TextField(rLabel, tileView.name); if (newName != tileView.name) { tileset.RenameTileView(tileView.name, newName); } } else { EditorGUI.LabelField(rLabel, tileView.name); } }; return tileViewRList; }
public void AddItem(GUIContent content, bool on, GenericMenu.MenuFunction func) { this.menuItems.Add(new GenericMenu.MenuItem(content, false, on, func)); }
public static void AddOptionalItem(this GenericMenu menu, bool isEnabled, GUIContent content, bool isOn, GenericMenu.MenuFunction handler) { if (isEnabled) { menu.AddItem(content, isOn, handler); } else { menu.AddDisabledItem(content); } }
public void DrawGenericMenu() { if (GUILayout.Button(SkillEditTempData.settingTex, EditorStyles.toolbarButton, GUILayout.MaxWidth(20))) { int cur_tl_index = parent.timglineGroup.TimeLines.IndexOf(timeline); GenericMenu toolsMenu = new GenericMenu(); GenericMenu.MenuFunction moveUpFunc = () => { var tempTl = this.timeline; parent.timglineGroup.TimeLines[cur_tl_index] = parent.timglineGroup.TimeLines[cur_tl_index - 1]; parent.timglineGroup.TimeLines[cur_tl_index - 1] = tempTl; }; if (cur_tl_index != 0) { toolsMenu.AddItem(new GUIContent("向上"), false, moveUpFunc); } GenericMenu.MenuFunction moveDownFunc = () => { var tempTl = parent.timglineGroup.TimeLines[cur_tl_index]; parent.timglineGroup.TimeLines[cur_tl_index] = parent.timglineGroup.TimeLines[cur_tl_index + 1]; parent.timglineGroup.TimeLines[cur_tl_index + 1] = tempTl; }; if (cur_tl_index != parent.timglineGroup.TimeLines.Count - 1) { toolsMenu.AddItem(new GUIContent("向下"), false, moveDownFunc); } GenericMenu.MenuFunction copyFunc = () => { SkillEditTempData.copyItem = SkillEditorUtility.Clone(parent.timglineGroup.TimeLines[cur_tl_index]); }; toolsMenu.AddItem(new GUIContent("复制"), false, copyFunc); GenericMenu.MenuFunction pasteFunc = () => { timeline.BaseActions.Add(SkillEditTempData.copyItem as BaseAction); list.Add(new EActionControl(this, SkillEditTempData.copyItem as BaseAction)); }; if (SkillEditTempData.copyItem != null && SkillEditTempData.copyItem is BaseAction) { toolsMenu.AddItem(new GUIContent("粘贴"), false, pasteFunc); } for (int j = 0; j < SkillEditorUtility.actionTypes.Count; j++) { int copyj = j; var display = SkillEditorUtility.GetDisplayAttr(SkillEditorUtility.actionTypes[j]); if (display != null) { GenericMenu.MenuFunction func = () => { var new_action = Activator.CreateInstance(SkillEditorUtility.actionTypes[copyj]) as BaseAction; timeline.BaseActions.Add(new_action); this.list.Add(new EActionControl(this, new_action)); }; if (typeof(DisplayAction).IsAssignableFrom(SkillEditorUtility.actionTypes[j])) { toolsMenu.AddItem(new GUIContent("添加/表现/" + display.DisplayName), false, func); } else { toolsMenu.AddItem(new GUIContent("添加/逻辑/" + display.DisplayName), false, func); } } } GenericMenu.MenuFunction del_func = () => { if (SkillEditTempData.editingItem == timeline) { SkillEditTempData.editingItem = null; } parent.RemoveTimeline(this); }; toolsMenu.AddItem(new GUIContent("删除"), false, del_func); Event e = Event.current; toolsMenu.DropDown(new Rect(e.mousePosition.x, e.mousePosition.y, 0, 0)); EditorGUIUtility.ExitGUI(); } }
public void AddItem(GUIContent content, GenericMenu.MenuFunction handler) { _innerMenu.AddItem(content, false, handler); }
public static void AddItem(this GenericMenu current, string label, bool state, GenericMenu.MenuFunction method) { current.AddItem(new GUIContent(label), state, method); }
public MenuItem(string path, string name, GenericMenu.MenuFunction action) { this.action = action; this.label = new GUIContent(path + '/' + name); this.path = path; }
/************************************************************************************************************************/ #endregion /************************************************************************************************************************/ #region Context Menus /************************************************************************************************************************/ /// <summary> /// Adds a menu function which is disabled if 'isEnabled' is false. /// </summary> public static void AddMenuItem(GenericMenu menu, string label, bool isEnabled, GenericMenu.MenuFunction func) { if (!isEnabled) { menu.AddDisabledItem(new GUIContent(label)); return; } menu.AddItem(new GUIContent(label), false, func); }
private void DrawFieldGUI(Rect rect, string valueName, object record) { var current = Event.current; var value = masterController.GetValue(record, valueName); var valueType = masterController.GetValueType(valueName); Action <object> onUpdateValue = x => { masterController.UpdateValue(record, valueName, x); if (onChangeRecord != null) { onChangeRecord.OnNext(Unit.Default); } RefreshCustomRowHeights(); }; var color = masterController.IsChanged(record, valueName) ? EditedColor : Color.white; rect.height = EditorGUIUtility.singleLineHeight; using (new BackgroundColorScope(color)) { if (EditorRecordFieldUtility.IsArrayType(valueType)) { var builder = new StringBuilder(); if (value != null) { foreach (var item in (IEnumerable)value) { builder.AppendFormat("{0},", item); } } var text = builder.ToString().TrimEnd(','); EditorGUI.LabelField(rect, text, EditorStyles.textField); if (MasterController.CanEdit || !string.IsNullOrEmpty(text)) { // メニュー表示と干渉するのでGUILayout.Buttonを使わない. if (rect.Contains(current.mousePosition) && current.type == EventType.MouseDown && current.button == 0) { var mouseRect = new Rect(current.mousePosition, Vector2.one); var arrayFieldPopupWindow = new ArrayFieldPopupWindow(); arrayFieldPopupWindow.SetContents(valueType, value); arrayFieldPopupWindow.OnUpdateElementsAsObservable() .Subscribe(x => onUpdateValue(x)) .AddTo(lifetimeDisposable.Disposable); PopupWindow.Show(mouseRect, arrayFieldPopupWindow); current.Use(); } } } else { if (valueType == typeof(string)) { rect.height = EditorRecordFieldUtility.GetTextFieldHight(value as string); } EditorGUI.BeginChangeCheck(); try { value = EditorRecordFieldUtility.DrawField(rect, value, valueType); } catch (Exception e) { Debug.LogErrorFormat("Error: {0}\nValueName = {1}\nValueType = {2}\nValue = {3}\n", e.Message, valueName, valueType, value); } if (EditorGUI.EndChangeCheck() && MasterController.CanEdit) { onUpdateValue(value); } } } // 右クリックでメニュー表示. if (rect.Contains(current.mousePosition) && current.type == EventType.MouseDown && current.button == 1) { if (masterController.IsChanged(record, valueName)) { var menu = new GenericMenu(); GenericMenu.MenuFunction onResetMenuClick = () => { masterController.ResetValue(record, valueName); }; menu.AddItem(new GUIContent("Reset"), false, onResetMenuClick); menu.ShowAsContext(); GUI.FocusControl(string.Empty); current.Use(); } } }
public GGenericMenuItem(string name, bool isOn, GenericMenu.MenuFunction action) { Name = name; IsOn = isOn; Action = action; }