本文整理汇总了C#中UnityEditor.GenericMenu.GetItemCount方法的典型用法代码示例。如果您正苦于以下问题:C# GenericMenu.GetItemCount方法的具体用法?C# GenericMenu.GetItemCount怎么用?C# GenericMenu.GetItemCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEditor.GenericMenu
的用法示例。
在下文中一共展示了GenericMenu.GetItemCount方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnGUI
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
var left = position; left.xMax -= 40;
var right = position; right.xMin = left.xMax + 2;
EditorGUI.PropertyField(left, property);
if (GUI.Button(right, "List") == true)
{
var menu = new GenericMenu();
if (LeanLocalization.Instance != null)
{
for (var j = 0; j < LeanLocalization.Instance.Languages.Count; j++)
{
var language = LeanLocalization.Instance.Languages[j];
menu.AddItem(new GUIContent(language), property.stringValue == language, () => { property.stringValue = language; property.serializedObject.ApplyModifiedProperties(); });
}
}
if (menu.GetItemCount() > 0)
{
menu.DropDown(right);
}
else
{
Debug.LogWarning("Your scene doesn't contain any languages, so the language name list couldn't be created.");
}
}
}
示例2: AddDefaultItemsToMenu
protected override void AddDefaultItemsToMenu(GenericMenu menu, EditorWindow view)
{
if (menu.GetItemCount() != 0)
{
menu.AddSeparator(string.Empty);
}
if (base.parent.window.showMode == ShowMode.MainWindow)
{
menu.AddItem(EditorGUIUtility.TextContent("Maximize"), !(base.parent is SplitView), new GenericMenu.MenuFunction2(this.Maximize), view);
}
else
{
menu.AddDisabledItem(EditorGUIUtility.TextContent("Maximize"));
}
menu.AddItem(EditorGUIUtility.TextContent("Close Tab"), false, new GenericMenu.MenuFunction2(this.Close), view);
menu.AddSeparator(string.Empty);
System.Type[] paneTypes = base.GetPaneTypes();
GUIContent content = EditorGUIUtility.TextContent("Add Tab");
foreach (System.Type type in paneTypes)
{
if (type != null)
{
GUIContent content2;
content2 = new GUIContent(EditorWindow.GetLocalizedTitleContentFromType(type)) {
text = content.text + "/" + content2.text
};
menu.AddItem(content2, false, new GenericMenu.MenuFunction2(this.AddTabToHere), type);
}
}
}
示例3: AddDefaultItemsToMenu
protected override void AddDefaultItemsToMenu(GenericMenu menu, EditorWindow view)
{
if (menu.GetItemCount() != 0)
menu.AddSeparator(string.Empty);
menu.AddItem(EditorGUIUtility.TextContent("Maximize"), !(this.parent is SplitView), new GenericMenu.MenuFunction2(this.Unmaximize), (object) view);
menu.AddDisabledItem(EditorGUIUtility.TextContent("Close Tab"));
menu.AddSeparator(string.Empty);
System.Type[] paneTypes = this.GetPaneTypes();
GUIContent guiContent = EditorGUIUtility.TextContent("Add Tab");
foreach (System.Type t in paneTypes)
{
if (t != null)
{
GUIContent content = new GUIContent(EditorWindow.GetLocalizedTitleContentFromType(t));
content.text = guiContent.text + "/" + content.text;
menu.AddDisabledItem(content);
}
}
}
示例4: AddDefaultItemsToMenu
protected override void AddDefaultItemsToMenu(GenericMenu menu, EditorWindow view)
{
if (menu.GetItemCount() != 0)
{
menu.AddSeparator("");
}
menu.AddItem(EditorGUIUtility.TextContent("Maximize"), !(base.parent is SplitView), new GenericMenu.MenuFunction2(this.Unmaximize), view);
menu.AddDisabledItem(EditorGUIUtility.TextContent("Close Tab"));
menu.AddSeparator("");
Type[] paneTypes = base.GetPaneTypes();
GUIContent content = EditorGUIUtility.TextContent("Add Tab");
foreach (Type type in paneTypes)
{
if (type != null)
{
GUIContent content2 = new GUIContent(EditorWindow.GetLocalizedTitleContentFromType(type));
content2.text = content.text + "/" + content2.text;
menu.AddDisabledItem(content2);
}
}
}
示例5: AddDefaultItemsToMenu
protected override void AddDefaultItemsToMenu(GenericMenu menu, EditorWindow view)
{
if (menu.GetItemCount() != 0)
{
menu.AddSeparator(string.Empty);
}
menu.AddItem(EditorGUIUtility.TextContent("DockAreaMaximize"), !(base.parent is SplitView), new GenericMenu.MenuFunction2(this.Unmaximize), view);
menu.AddDisabledItem(EditorGUIUtility.TextContent("DockAreaCloseTab"));
menu.AddSeparator(string.Empty);
Type[] paneTypes = base.GetPaneTypes();
GUIContent gUIContent = EditorGUIUtility.TextContent("DockAreaAddTab");
Type[] array = paneTypes;
for (int i = 0; i < array.Length; i++)
{
Type type = array[i];
if (type != null)
{
GUIContent gUIContent2 = new GUIContent(EditorGUIUtility.TextContent(type.ToString()));
gUIContent2.text = gUIContent.text + "/" + gUIContent2.text;
menu.AddDisabledItem(gUIContent2);
}
}
}
示例6: AddItemsToMenu
/// <summary>
/// Invoked to generate context menu for list item.
/// </summary>
/// <param name="menu">Menu which can be populated.</param>
/// <param name="itemIndex">Zero-based index of item which was right-clicked.</param>
/// <param name="adaptor">Reorderable list adaptor.</param>
protected virtual void AddItemsToMenu(GenericMenu menu, int itemIndex, IReorderableListAdaptor adaptor) {
if ((Flags & ReorderableListFlags.DisableReordering) == 0) {
if (itemIndex > 0)
menu.AddItem(CommandMoveToTop, false, DefaultContextHandler, CommandMoveToTop);
else
menu.AddDisabledItem(CommandMoveToTop);
if (itemIndex + 1 < adaptor.Count)
menu.AddItem(CommandMoveToBottom, false, DefaultContextHandler, CommandMoveToBottom);
else
menu.AddDisabledItem(CommandMoveToBottom);
if (HasAddButton) {
menu.AddSeparator("");
menu.AddItem(CommandInsertAbove, false, DefaultContextHandler, CommandInsertAbove);
menu.AddItem(CommandInsertBelow, false, DefaultContextHandler, CommandInsertBelow);
if ((Flags & ReorderableListFlags.DisableDuplicateCommand) == 0)
menu.AddItem(CommandDuplicate, false, DefaultContextHandler, CommandDuplicate);
}
}
if (HasRemoveButtons) {
if (menu.GetItemCount() > 0)
menu.AddSeparator("");
menu.AddItem(CommandRemove, false, DefaultContextHandler, CommandRemove);
menu.AddSeparator("");
menu.AddItem(CommandClearAll, false, DefaultContextHandler, CommandClearAll);
}
}
示例7: ShowContextMenu
private void ShowContextMenu(int controlID, int itemIndex, IReorderableListAdaptor adaptor) {
GenericMenu menu = new GenericMenu();
s_ContextControlID = controlID;
s_ContextItemIndex = itemIndex;
AddItemsToMenu(menu, itemIndex, adaptor);
if (menu.GetItemCount() > 0)
menu.ShowAsContext();
}
示例8: DoPopupMenu
private void DoPopupMenu(EditorWindow console)
{
var listView = consoleListViewField.GetValue(console);
int listViewRow = listView != null ? (int) listViewStateRowField.GetValue(listView) : -1;
if (listViewRow < 0)
return;
string text = (string)consoleActiveTextField.GetValue(console);
if (string.IsNullOrEmpty(text))
return;
GenericMenu codeViewPopupMenu = new GenericMenu();
string[] lines = text.Split('\n');
foreach (string line in lines)
{
int atAssetsIndex = line.IndexOf("(at Assets/");
if (atAssetsIndex < 0)
continue;
int functionNameEnd = line.IndexOf('(');
if (functionNameEnd < 0)
continue;
string functionName = line.Substring(0, functionNameEnd).TrimEnd(' ');
int lineIndex = line.LastIndexOf(':');
if (lineIndex <= atAssetsIndex)
continue;
int atLine = 0;
for (int i = lineIndex + 1; i < line.Length; ++i)
{
char c = line[i];
if (c < '0' || c > '9')
break;
atLine = atLine * 10 + (c - '0');
}
atAssetsIndex += "(at ".Length;
string assetPath = line.Substring(atAssetsIndex, lineIndex - atAssetsIndex);
string scriptName = assetPath.Substring(assetPath.LastIndexOf('/') + 1);
string guid = AssetDatabase.AssetPathToGUID(assetPath);
if (!string.IsNullOrEmpty(guid))
{
codeViewPopupMenu.AddItem(
new GUIContent(scriptName + " - " + functionName.Replace(':', '.') + ", line " + atLine),
false,
() => FGCodeWindow.OpenAssetInTab(guid, atLine));
}
}
if (codeViewPopupMenu.GetItemCount() > 0)
codeViewPopupMenu.ShowAsContext();
}
示例9: ShowBusPopupMenu
private static void ShowBusPopupMenu(int effectIndex, AudioMixerGroupController group, List<AudioMixerGroupController> allGroups, Dictionary<AudioMixerEffectController, AudioMixerGroupController> effectMap, AudioMixerEffectController effect, Rect buttonRect)
{
GenericMenu pm = new GenericMenu();
pm.AddItem(new GUIContent("None"), false, new GenericMenu.MenuFunction2(AudioMixerChannelStripView.ConnectSendPopupCallback), (object) new AudioMixerChannelStripView.ConnectSendContext(effect, (AudioMixerEffectController) null));
pm.AddSeparator(string.Empty);
AudioMixerChannelStripView.AddMenuItemsForReturns(pm, string.Empty, effectIndex, group, allGroups, effectMap, effect, true);
if (pm.GetItemCount() == 2)
pm.AddDisabledItem(new GUIContent("No valid Receive targets found"));
pm.DropDown(buttonRect);
}
示例10: HandleAnchorContext
private void HandleAnchorContext(int controlID, JointHelpers.AnchorBias bias, AnchoredJoint2D joint,
Joint2DSettingsBase joint2DSettings, Vector2 anchorPosition,
Rigidbody2D connectedBody)
{
EditorHelpers.ContextClick(controlID, () => {
var menu = new GenericMenu();
menu.AddDisabledItem(new GUIContent(joint.GetType()
.Name));
menu.AddSeparator("");
if (WantsLocking()) {
menu.AddItem(new GUIContent("Lock Anchors", GetAnchorLockTooltip()),
joint2DSettings.lockAnchors, () => {
EditorHelpers.RecordUndo(
joint2DSettings.lockAnchors ? "Unlock Anchors" : "Lock Anchors", joint2DSettings,
joint);
if (!joint2DSettings.lockAnchors) {
ReAlignAnchors(joint, bias);
}
joint2DSettings.lockAnchors = !joint2DSettings.lockAnchors;
EditorUtility.SetDirty(joint2DSettings);
EditorUtility.SetDirty(joint);
});
}
{
var otherBias = JointHelpers.GetOppositeBias(bias);
var otherPosition = JointHelpers.GetAnchorPosition(joint, otherBias);
if (Vector2.Distance(otherPosition, anchorPosition) <= AnchorEpsilon) {
menu.AddDisabledItem(new GUIContent("Bring other anchor here"));
} else {
menu.AddItem(new GUIContent("Bring other anchor here"), false, () => {
EditorHelpers.RecordUndo("Move Joint Anchor", joint);
JointHelpers.SetWorldAnchorPosition(joint, anchorPosition, otherBias);
EditorUtility.SetDirty(joint);
});
}
}
menu.AddItem(new GUIContent("Enable Collision",
"Should rigid bodies connected with this joint collide?"), joint.enableCollision,
() => {
EditorHelpers.RecordUndo("Move Joint Anchor", joint);
joint.enableCollision = !joint.enableCollision;
EditorUtility.SetDirty(joint);
});
menu.AddSeparator("");
var itemCount = menu.GetItemCount();
ExtraMenuItems(menu, joint);
if (itemCount != menu.GetItemCount()) {
menu.AddSeparator("");
}
if (connectedBody) {
var connectedBodyName = connectedBody.name;
var selectConnectedBodyContent = new GUIContent(string.Format("Select '{0}'", connectedBodyName));
if (isCreatedByTarget) {
menu.AddDisabledItem(selectConnectedBodyContent);
} else {
menu.AddItem(selectConnectedBodyContent, false,
() => { Selection.activeGameObject = connectedBody.gameObject; });
}
menu.AddItem(new GUIContent(string.Format("Move ownership to '{0}'", connectedBodyName)), false, () => {
var connectedObject = connectedBody.gameObject;
var cloneJoint =
Undo.AddComponent(connectedObject, joint.GetType()) as AnchoredJoint2D;
if (!cloneJoint) {
return;
}
EditorUtility.CopySerialized(joint, cloneJoint);
cloneJoint.connectedBody = joint.GetComponent<Rigidbody2D>();
JointHelpers.SetWorldAnchorPosition(cloneJoint,
JointHelpers.GetAnchorPosition(joint, JointHelpers.AnchorBias.Main),
JointHelpers.AnchorBias.Connected);
JointHelpers.SetWorldAnchorPosition(cloneJoint,
JointHelpers.GetAnchorPosition(joint, JointHelpers.AnchorBias.Connected),
JointHelpers.AnchorBias.Main);
var jointSettings = SettingsHelper.GetOrCreate(joint);
var cloneSettings =
Undo.AddComponent(connectedObject, jointSettings.GetType()) as Joint2DSettingsBase;
if (cloneSettings == null) {
return;
}
cloneSettings.hideFlags = HideFlags.HideInInspector;
EditorUtility.CopySerialized(jointSettings, cloneSettings);
cloneSettings.Setup(cloneJoint);
cloneSettings.SetOffset(JointHelpers.AnchorBias.Main,
jointSettings.GetOffset(JointHelpers.AnchorBias.Connected));
cloneSettings.SetOffset(JointHelpers.AnchorBias.Connected,
jointSettings.GetOffset(JointHelpers.AnchorBias.Main));
if (!Selection.Contains(connectedObject)) {
//.........这里部分代码省略.........
示例11: DoPropertyContextMenu
private static void DoPropertyContextMenu(SerializedProperty property)
{
GenericMenu menu = new GenericMenu();
SerializedProperty property1 = property.serializedObject.FindProperty(property.propertyPath);
ScriptAttributeUtility.GetHandler(property).AddMenuItems(property, menu);
if (property.hasMultipleDifferentValues && !property.hasVisibleChildren)
TargetChoiceHandler.AddSetToValueOfTargetMenuItems(menu, property1, new TargetChoiceHandler.TargetChoiceMenuFunction(TargetChoiceHandler.SetToValueOfTarget));
if (property.serializedObject.targetObjects.Length == 1 && property.isInstantiatedPrefab)
menu.AddItem(EditorGUIUtility.TextContent("Revert Value to Prefab"), false, new GenericMenu.MenuFunction2(TargetChoiceHandler.SetPrefabOverride), (object) property1);
if (property.propertyPath.LastIndexOf(']') == property.propertyPath.Length - 1)
{
if (menu.GetItemCount() > 0)
menu.AddSeparator(string.Empty);
menu.AddItem(EditorGUIUtility.TextContent("Duplicate Array Element"), false, new GenericMenu.MenuFunction2(TargetChoiceHandler.DuplicateArrayElement), (object) property1);
menu.AddItem(EditorGUIUtility.TextContent("Delete Array Element"), false, new GenericMenu.MenuFunction2(TargetChoiceHandler.DeleteArrayElement), (object) property1);
}
if (Event.current.shift)
{
if (menu.GetItemCount() > 0)
menu.AddSeparator(string.Empty);
menu.AddItem(EditorGUIUtility.TextContent("Print Property Path"), false, (GenericMenu.MenuFunction2) (e => Debug.Log((object) ((SerializedProperty) e).propertyPath)), (object) property1);
}
Event.current.Use();
if (menu.GetItemCount() == 0)
return;
menu.ShowAsContext();
}
示例12: ShowPopup
private static void ShowPopup(Event evt, UTNodeEditorModel model)
{
var menu = new GenericMenu ();
if (!model.HasPlan) {
menu.AddDisabledItem (new GUIContent ("Please select an automation plan."));
menu.ShowAsContext ();
return;
}
var hotNode = GetNodeUnderMouse (model, evt.mousePosition);
var hotConnector = GetConnectorUnderMouse (model, evt.mousePosition);
var data = new NodeEventData (evt, model, hotConnector);
if (hotNode == null && hotConnector == null) {
#if UTOMATE_DEMO
if (!model.CanAddEntriesToPlan) {
menu.AddDisabledItem (new GUIContent ("You cannot add any more entries in the demo version."));
}
else {
#endif
menu.AddItem (new GUIContent ("Add Action Entry"), false, AddActionNode, data);
menu.AddItem (new GUIContent ("Add Decision Entry"), false, AddDecisionNode, data);
menu.AddItem (new GUIContent ("Add For-Each Entry"), false, AddForEachNode, data);
menu.AddItem (new GUIContent ("Add For-Each File Entry"), false, AddForEachFileNode, data);
menu.AddItem (new GUIContent ("Add Sub-Plan Entry"), false, AddPlanNode, data);
menu.AddItem (new GUIContent ("Add Note"), false, AddNote, data);
#if UTOMATE_DEMO
}
#endif
}
if (hotNode != null) {
if (!model.SelectedNodes.Contains (hotNode)) {
model.SelectNode (hotNode, UTNodeEditorModel.SelectionMode.Replace);
}
if (menu.GetItemCount () > 0) {
menu.AddSeparator ("");
}
var isMultiSelection = model.SelectedNodes.Count > 1;
if (!model.IsFirstNode (hotNode) && !isMultiSelection) {
menu.AddItem (new GUIContent ("Set As First Entry"), false, SetAsFirstNode, data);
}
menu.AddItem (new GUIContent (isMultiSelection ? "Delete Entries" : "Delete Entry"), false, DeleteNode, data);
}
if (hotConnector != null && hotConnector.isConnected) {
if (menu.GetItemCount () > 0) {
menu.AddSeparator ("");
}
menu.AddItem (new GUIContent ("Delete Connection"), false, DeleteConnection, data);
}
menu.ShowAsContext ();
}
示例13: DoPopupMenu
private void DoPopupMenu(EditorWindow console)
{
var listView = consoleListViewField.GetValue(console);
int listViewRow = listView != null ? (int) listViewStateRowField.GetValue(listView) : -1;
if (listViewRow < 0)
return;
string text = (string)consoleActiveTextField.GetValue(console);
if (string.IsNullOrEmpty(text))
return;
GenericMenu codeViewPopupMenu = new GenericMenu();
string[] lines = text.Split('\n');
foreach (string line in lines)
{
int atAssetsIndex = line.IndexOf("(at Assets/");
if (atAssetsIndex < 0)
continue;
int functionNameEnd = line.IndexOf('(');
if (functionNameEnd < 0)
continue;
string functionName = line.Substring(0, functionNameEnd).TrimEnd(' ');
int lineIndex = line.LastIndexOf(':');
if (lineIndex <= atAssetsIndex)
continue;
int atLine = 0;
for (int i = lineIndex + 1; i < line.Length; ++i)
{
char c = line[i];
if (c < '0' || c > '9')
break;
atLine = atLine * 10 + (c - '0');
}
atAssetsIndex += "(at ".Length;
string assetPath = line.Substring(atAssetsIndex, lineIndex - atAssetsIndex);
string scriptName = assetPath.Substring(assetPath.LastIndexOf('/') + 1);
string guid = AssetDatabase.AssetPathToGUID(assetPath);
if (!string.IsNullOrEmpty(guid))
{
codeViewPopupMenu.AddItem(
new GUIContent(scriptName + " - " + functionName.Replace(':', '.') + ", line " + atLine),
false,
() => {
if (openLogEntriesInSi2)
{
FGCodeWindow.addRecentLocationForNextAsset = true;
FGCodeWindow.OpenAssetInTab(guid, atLine);
}
else
{
FGCodeWindow.openInExternalIDE = true;
AssetDatabase.OpenAsset(AssetDatabase.LoadMainAssetAtPath(assetPath), atLine);
}
});
}
}
if (codeViewPopupMenu.GetItemCount() > 0)
{
codeViewPopupMenu.AddSeparator(string.Empty);
codeViewPopupMenu.AddItem(
new GUIContent("Open Call-Stack Entries in Script Inspector"),
openLogEntriesInSi2,
() => { openLogEntriesInSi2 = !openLogEntriesInSi2; }
);
GUIUtility.hotControl = 0;
codeViewPopupMenu.ShowAsContext();
GUIUtility.ExitGUI();
}
}
示例14: ShowReplaceHistory
private void ShowReplaceHistory()
{
#if UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7 || UNITY_5_0 || UNITY_5_1 || UNITY_5_2
string suffix = " _";
#else
string suffix = "";
#endif
GenericMenu menu = new GenericMenu();
if (replaceText != initialFindText && initialFindText.Trim() != "" && initialFindText.IndexOfAny(new [] {'_', '/'}) < 0)
menu.AddItem(new GUIContent(initialFindText + suffix), false, SelectReplaceHistory, initialFindText);
for (var i = 0; i < replaceHistory.Length && replaceHistory[i] != null; i++)
if (replaceText != replaceHistory[i] && replaceHistory[i].IndexOfAny(new [] {'_', '/'}) < 0)
menu.AddItem(new GUIContent(replaceHistory[i] + suffix), false, SelectReplaceHistory, replaceHistory[i]);
if (menu.GetItemCount() > 0)
menu.DropDown(new Rect(14f, 96f, Screen.width - 10f, 18f));
Event.current.Use();
}