protected override void ContextClicked() { base.ContextClicked(); GenericMenu menu = new GenericMenu(); this.OnContextMenu(menu); if (menu.GetItemCount() > 0) { menu.ShowAsContext(); } UnityEngine.Event.current.Use(); }
private void DrawMaterials(P3dPaintable paintable, Material[] materials, P3dPaintableTexture[] paintableTextures) { for (var i = 0; i < materials.Length; i++) { var material = materials[i]; EditorGUILayout.BeginHorizontal(); EditorGUI.BeginDisabledGroup(true); EditorGUILayout.ObjectField(GUIContent.none, material, typeof(Material), true, GUILayout.MinWidth(10)); EditorGUI.EndDisabledGroup(); if (GUILayout.Button("+Preset", EditorStyles.miniButton, GUILayout.ExpandWidth(false)) == true) { var menu = new GenericMenu(); var stateLimit = Settings.OverrideStateLimit == true ? Settings.StateLimit : -1; foreach (var cachedPreset in P3dPreset.CachedPresets) { if (cachedPreset != null && material != null && cachedPreset.Targets(material.shader) == true) { var preset = cachedPreset; var index = i; if (preset.CanAddTo(paintable, index) == true) { menu.AddItem(new GUIContent(preset.FinalName), false, () => preset.AddTo(paintable, material.shader, index, stateLimit)); } else { menu.AddDisabledItem(new GUIContent(preset.FinalName)); } } } if (menu.GetItemCount() == 0) { menu.AddDisabledItem(new GUIContent("Failed to find any presets for this material or shader.")); } menu.ShowAsContext(); } EditorGUILayout.EndHorizontal(); foreach (var paintableTexture in paintableTextures) { if (paintableTexture.Slot.Index == i) { EditorGUI.indentLevel++; DrawPaintableTexture(paintableTexture, material); EditorGUI.indentLevel--; } } } }
private void ShowMethodSelectMenu() { GenericMenu genericMenu = new GenericMenu(); MethodInfo[] methods = node.method.DeclaringType.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static); genericMenu.AddDisabledItem(new GUIContent("Select a method...")); foreach (MethodInfo method in methods) { if (method.IsGenericMethod) { continue; } if (!method.Name.StartsWith(searchString)) { continue; } ParameterInfo[] parameters = method.GetParameters(); string paramString = ""; if (parameters.Any(x => !SerializabeArgs.IsSupported(x.ParameterType))) { continue; } if (parameters != null && parameters.Length > 0) { foreach (ParameterInfo parameter in parameters) { paramString += parameter.ParameterType.Name + " " + parameter.Name + ", "; } } if (paramString == "") { genericMenu.AddItem(new GUIContent(method.Name + "()"), false, () => OnSelectMethod(method, parameters)); } else { genericMenu.AddItem(new GUIContent(method.Name + "(" + paramString.Remove(paramString.Length - 2) + ")"), false, () => OnSelectMethod(method, parameters)); } } if (genericMenu.GetItemCount() <= 1) { genericMenu = new GenericMenu(); genericMenu.AddDisabledItem(new GUIContent("No matching methods found.")); } genericMenu.ShowAsContext(); }
internal static void Initiate() { // Populate Asset menu if (m_AssetPopupMenu == null) { m_AssetPopupMenu = new GenericMenu(); // Traverse assemblies foreach (var asm in AppDomain.CurrentDomain.GetAssemblies()) { // Filter by assembly var root = asm.GetName().Name.Split('.')[0]; if (!m_ExcludeAssemblies.Contains(root)) { // Traverse types foreach (var type in asm.GetTypes()) { // Filter by type if (type.IsClass && !type.IsAbstract && IsScriptableObject(type)) { // Convert namespace to path var path = type.FullName.Replace('.', '/'); // Append type to menu m_AssetPopupMenu.AddItem(new GUIContent(path), false, () => { CreateAsset(type); }); } } } } } // Display when populated if (m_AssetPopupMenu.GetItemCount() > 0) { var window = CreateInstance <AssetMenu>(); window.position = new Rect(0f, 0f, 2f, 2f); window.ShowPopup(); } // Otherwise alert user else if (EditorUtility.DisplayDialog("Error", "No Scriptable Object Found", "OK")) { // And display the Script menu ScriptMenu.Initiate(); } }
void OpenMenu(Event evt) { var menu = new GenericMenu(); if (!@readonly) { if (canDisable) { menu.AddItem(EditorGUIUtility.TrTextContent("Enable"), !disabled, ToggleDisabled); } if (canExclude) { menu.AddItem(EditorGUIUtility.TrTextContent("Exclude"), excluded, ToggleExcluded); } } if (menu.GetItemCount() > 0) { menu.AddSeparator(""); } var bc = menu.GetItemCount(); AddContextualMenuItems(menu); if (!@readonly) { if (menu.GetItemCount() != bc) { menu.AddSeparator(""); } menu.AddItem(EditorGUIUtility.TrTextContent("Delete"), false, Delete); } if (menu.GetItemCount() > 0) { menu.ShowAsContext(); evt.Use(); } }
void DrawTableNameField(JsonExtensionPropertyDrawerData data, ref Rect position) { #region inner EditorGUI.BeginDisabledGroup(string.IsNullOrEmpty(data.m_TableId.stringValue)); var sheetNamePos = position.SplitHorizontal(); var buttonPos = sheetNamePos.right.SplitHorizontal(); data.m_TableId.stringValue = EditorGUI.TextField(sheetNamePos.left, data.m_TableId.stringValue); if (GUI.Button(buttonPos.left, Styles.openTable)) { JsonTableSync.OpenTableInBrowser(data.m_TableId.stringValue); } EditorGUI.EndDisabledGroup(); #endregion inner if (EditorGUI.DropdownButton(buttonPos.right, Styles.SelectFile, FocusType.Passive)) { try { var google = GetTableContent(data); var files = HelperClass.GetDataFiles(); var menu = new GenericMenu(); foreach (var s in files) { menu.AddItem(new GUIContent(s.name), false, () => { data.m_TableId.stringValue = s.fileName; data.m_TableId.serializedObject.ApplyModifiedProperties(); }); } if (menu.GetItemCount() == 0) { menu.AddDisabledItem(Styles.NoFileFound); } menu.DropDown(sheetNamePos.right); } catch (Exception e) { Debug.LogException(e); } finally { EditorUtility.ClearProgressBar(); } } position.MoveToNextLine(); }
// This code is mostly copied from Unity's HDRP repository /// <summary> /// Intialize a reoderable list /// </summary> void InitList(ref ReorderableList reorderableList, List <string> elements, string headerName, CustomPostProcessInjectionPoint injectionPoint, CustomPostProcess feature) { reorderableList = new ReorderableList(elements, typeof(string), true, true, true, true); reorderableList.drawHeaderCallback = (rect) => EditorGUI.LabelField(rect, headerName, EditorStyles.boldLabel); reorderableList.drawElementCallback = (rect, index, isActive, isFocused) => { rect.height = EditorGUIUtility.singleLineHeight; var elemType = Type.GetType(elements[index]); EditorGUI.LabelField(rect, GetName(elemType), EditorStyles.boldLabel); }; reorderableList.onAddCallback = (list) => { var menu = new GenericMenu(); foreach (var type in _availableRenderers[injectionPoint]) { if (!elements.Contains(type.AssemblyQualifiedName)) { menu.AddItem(new GUIContent(GetName(type)), false, () => { Undo.RegisterCompleteObjectUndo(feature, $"Added {type.ToString()} Custom Post Process"); elements.Add(type.AssemblyQualifiedName); forceRecreate(feature); // This is done since OnValidate doesn't get called. }); } } if (menu.GetItemCount() == 0) { menu.AddDisabledItem(new GUIContent("No Custom Post Process Availble")); } menu.ShowAsContext(); EditorUtility.SetDirty(feature); }; reorderableList.onRemoveCallback = (list) => { Undo.RegisterCompleteObjectUndo(feature, $"Removed {list.list[list.index].ToString()} Custom Post Process"); elements.RemoveAt(list.index); EditorUtility.SetDirty(feature); forceRecreate(feature); // This is done since OnValidate doesn't get called. }; reorderableList.elementHeightCallback = _ => EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; reorderableList.onReorderCallback = (list) => { EditorUtility.SetDirty(feature); forceRecreate(feature); // This is done since OnValidate doesn't get called. }; }
void OnEnable() { m_DefaultPresets = serializedObject.FindProperty("m_DefaultList"); m_List = new ReorderableList(serializedObject, m_DefaultPresets); m_List.draggable = false; m_List.drawHeaderCallback = rect => EditorGUI.LabelField(rect, GUIContent.Temp("Default Presets")); m_List.drawElementCallback = DrawElementCallback; m_List.onAddDropdownCallback = OnAddDropdownCallback; m_List.onRemoveCallback = OnRemoveCallback; RefreshAddList(); m_List.onCanAddCallback = (list => m_AddingMenu.GetItemCount() > 0); }
public virtual void AddItemsToMenu(GenericMenu menu) { bool floating = ProBuilderSettings.Get <bool>(utilityWindowKey, SettingsScope.Project, false); if (menu.GetItemCount() > 1) { menu.AddSeparator(""); } menu.AddItem(new GUIContent("Open as Floating Window", ""), floating, () => SetIsUtilityWindow(true)); menu.AddItem(new GUIContent("Open as Dockable Window", ""), !floating, () => SetIsUtilityWindow(false)); menu.AddSeparator(""); }
void DisplayBehaviours(Event evt, GameObject _go, Rect position = default(Rect)) { var components = new Component[0]; if ((BehaviourTarget.ActionType)action.enumValueIndex == BehaviourTarget.ActionType.InvokeMethod) { components = _go.GetComponents <MonoBehaviour>(); } else { var comps = new List <Component>(_go.GetComponents <Behaviour>()); comps.AddRange(_go.GetComponents <Collider>()); comps.AddRange(_go.GetComponents <Cloth>()); comps.AddRange(_go.GetComponents <LODGroup>()); comps.AddRange(_go.GetComponents <Renderer>()); components = comps.ToArray(); } var behaviourMenu = new GenericMenu(); if (components.Length == 1) { SetComponent(components[0], _go); } else { for (int i = 0; i < components.Length; i++) { var _comp = components[i]; if (_comp == null) { continue; } var content = new GUIContent(_comp.GetType().Name, AssetPreview.GetMiniThumbnail(_comp)); behaviourMenu.AddItem(content, false, () => { SetComponent(_comp, _go); }); } if (position == default(Rect)) { behaviourMenu.ShowAsContext(); } else { position.y += behaviourMenu.GetItemCount() * EditorGUIUtility.singleLineHeight; behaviourMenu.DropDown(position); } } }
//---------------------------------------------------------------------- private void DoElementContextMenu(Rect position, int elementIndex) { position.x += 1; position.height = elementHeight - 1; var menu = new GenericMenu(); PopulateElementContextMenu(menu, elementIndex); if (menu.GetItemCount() > 0) { menu.DropDown(position); } }
/************************************************************************************************************************/ /// <summary> /// Draws a dropdown menu to select the name of a parameter in the `controller`. /// </summary> protected void DoParameterGUI(Rect area, AnimatorController controller, SerializedProperty property) { var parameterName = property.stringValue; var parameters = controller.parameters; var label = Editor.AnimancerGUI.TempContent(property); label = EditorGUI.BeginProperty(area, label, property); var xMax = area.xMax; area.width = EditorGUIUtility.labelWidth; EditorGUI.PrefixLabel(area, label); area.x += area.width; area.xMax = xMax; var color = GUI.color; if (!HasFloatParameter(controller, parameterName)) GUI.color = Editor.AnimancerGUI.ErrorFieldColor; var content = Editor.AnimancerGUI.TempContent(parameterName); if (EditorGUI.DropdownButton(area, content, FocusType.Passive)) { property = property.Copy(); var menu = new GenericMenu(); for (int i = 0; i < parameters.Length; i++) { var parameter = parameters[i]; Editor.AnimancerEditorUtilities.AddMenuItem(menu, parameter.name, parameter.type == AnimatorControllerParameterType.Float, () => { Editor.Serialization.ForEachTarget(property, (targetProperty) => { targetProperty.stringValue = parameter.name; }); }); } if (menu.GetItemCount() == 0) menu.AddDisabledItem(new GUIContent("No Parameters")); menu.ShowAsContext(); } GUI.color = color; EditorGUI.EndProperty(); }
private static void ShowMenu(GenericMenu menu) { if (menu.GetItemCount() == 0) { return; } // cache the original matrix(we assume this is scaled) Matrix4x4 m4 = GUI.matrix; //reset to non-scaled GUI.matrix = Matrix4x4.identity; menu.ShowAsContext(); GUI.matrix = m4; }
public static void ShowObjectContextMenu(Skill fsm, SkillState state, Object obj, SkillStateAction beforeAction = null) { if (obj == null) { return; } Actions.BuildListIfNeeded(); ActionUtility.ActionCreationParams actionCreationParams = new ActionUtility.ActionCreationParams { state = state, parameter = obj, beforeAction = beforeAction }; GenericMenu genericMenu = new GenericMenu(); GameObject gameObject = obj as GameObject; if (gameObject != null) { if (EditorUtility.IsPersistent(gameObject)) { ActionUtility.AddMenuTitle(ref genericMenu, Strings.get_Menu_Prefab_Actions()); ActionUtility.AddPrefabMenuItems(ref genericMenu, actionCreationParams); } else { ActionUtility.AddMenuTitle(ref genericMenu, Strings.get_Menu_GameObject_Actions()); ActionUtility.AddObjectMenuItems(ref genericMenu, actionCreationParams, true); Component[] components = gameObject.GetComponents <Component>(); Component[] array = components; for (int i = 0; i < array.Length; i++) { Component parameter = array[i]; actionCreationParams.parameter = parameter; ActionUtility.AddObjectMenuItems(ref genericMenu, actionCreationParams, true); } } } else { ActionUtility.AddMenuTitle(ref genericMenu, string.Format(Strings.get_Menu_Type_Actions(), obj.GetType().get_Name())); ActionUtility.AddObjectMenuItems(ref genericMenu, actionCreationParams, false); } if (genericMenu.GetItemCount() == 2) { genericMenu.AddDisabledItem(new GUIContent(Strings.get_Menu_No_Context_Actions_Found())); } genericMenu.ShowAsContext(); }
// The method defined in IDefinesGenericMenuItems allows us to add our own functions to the context menu. // This function is called everytime the context menu is opened, which allows you to modify the the context menu. public void PopulateGenericMenu(InspectorProperty property, GenericMenu genericMenu) { if (genericMenu.GetItemCount() > 0) { genericMenu.AddSeparator(""); } genericMenu.AddItem(new GUIContent("Colors/Red"), false, () => this.SetColor(Color.red)); genericMenu.AddItem(new GUIContent("Colors/Green"), false, () => this.SetColor(Color.green)); genericMenu.AddItem(new GUIContent("Colors/Blue"), false, () => this.SetColor(Color.blue)); genericMenu.AddItem(new GUIContent("Colors/Yellow"), false, () => this.SetColor(Color.yellow)); genericMenu.AddItem(new GUIContent("Colors/Cyan"), false, () => this.SetColor(Color.cyan)); genericMenu.AddItem(new GUIContent("Colors/White"), false, () => this.SetColor(Color.white)); genericMenu.AddItem(new GUIContent("Colors/Black"), false, () => this.SetColor(Color.black)); genericMenu.AddDisabledItem(new GUIContent("Colors/Magenta")); }
/// <summary> /// Populates the generic menu for the property. /// </summary> public void PopulateGenericMenu(InspectorProperty property, GenericMenu genericMenu) { Vector2Int value = (Vector2Int)property.ValueEntry.WeakSmartValue; if (genericMenu.GetItemCount() > 0) { genericMenu.AddSeparator(""); } genericMenu.AddItem(new GUIContent("Zero", "Set the vector to (0, 0)"), value == Vector2Int.zero, () => SetVector(property, Vector2Int.zero)); genericMenu.AddItem(new GUIContent("One", "Set the vector to (1, 1)"), value == Vector2Int.one, () => SetVector(property, Vector2Int.one)); genericMenu.AddSeparator(""); genericMenu.AddItem(new GUIContent("Right", "Set the vector to (1, 0)"), value == Vector2Int.right, () => SetVector(property, Vector2Int.right)); genericMenu.AddItem(new GUIContent("Left", "Set the vector to (-1, 0)"), value == Vector2Int.left, () => SetVector(property, Vector2Int.left)); genericMenu.AddItem(new GUIContent("Up", "Set the vector to (0, 1)"), value == Vector2Int.up, () => SetVector(property, Vector2Int.up)); genericMenu.AddItem(new GUIContent("Down", "Set the vector to (0, -1)"), value == Vector2Int.down, () => SetVector(property, Vector2Int.down)); }
protected override void ContextClickedItem(int id) { contextOnItem = true; var selectIds = GetSelection(); if (selectIds.Count > 0) { GenericMenu menu = new GenericMenu(); menu.AddItem(new GUIContent("Remove"), false, OnRemoveFolder, selectIds); if (menu.GetItemCount() > 0) { menu.ShowAsContext(); } } }
public void AddToGenericMenu([NotNull] ref GenericMenu menu, bool addSeparator) { if (menu.GetItemCount() == 0) { addSeparator = false; } for (int n = 0, count = Count; n < count; n++) { var item = items[n]; if (item.IsSeparator) { addSeparator = false; menu.AddSeparator(item.Text); } else { if (addSeparator) { addSeparator = false; menu.AddSeparator(""); } var effect = item.effect; if (effect != null) { menu.AddItem(item.Label, item.on, effect); } else { var effectWithParameter = item.effectWithParameter; if (effectWithParameter != null) { menu.AddItem(item.Label, item.on, effectWithParameter, item.effectParameterValue); } else { #if UNITY_2018_3_OR_NEWER menu.AddDisabledItem(item.Label, item.on); #else menu.AddDisabledItem(item.Label); #endif } } } } }
/// <summary> /// Populates the generic menu for the property. /// </summary> public void PopulateGenericMenu(InspectorProperty property, GenericMenu genericMenu) { Vector2 value = (Vector2)property.ValueEntry.WeakSmartValue; if (genericMenu.GetItemCount() > 0) { genericMenu.AddSeparator(""); } genericMenu.AddItem(new GUIContent("Normalize"), Mathf.Approximately(value.magnitude, 1f), () => NormalizeEntries(property)); genericMenu.AddItem(new GUIContent("Zero", "Set the vector to (0, 0)"), value == Vector2.zero, () => SetVector(property, Vector2.zero)); genericMenu.AddItem(new GUIContent("One", "Set the vector to (1, 1)"), value == Vector2.one, () => SetVector(property, Vector2.one)); genericMenu.AddSeparator(""); genericMenu.AddItem(new GUIContent("Right", "Set the vector to (1, 0)"), value == Vector2.right, () => SetVector(property, Vector2.right)); genericMenu.AddItem(new GUIContent("Left", "Set the vector to (-1, 0)"), value == Vector2.left, () => SetVector(property, Vector2.left)); genericMenu.AddItem(new GUIContent("Up", "Set the vector to (0, 1)"), value == Vector2.up, () => SetVector(property, Vector2.up)); genericMenu.AddItem(new GUIContent("Down", "Set the vector to (0, -1)"), value == Vector2.down, () => SetVector(property, Vector2.down)); }
protected override void ContextClicked() { if (contextOnItem) { contextOnItem = false; return; } GenericMenu menu = new GenericMenu(); menu.AddItem(new GUIContent("拖拽文件夹添加配置"), false, null); if (menu.GetItemCount() > 0) { menu.ShowAsContext(); } }
private static void DrawSystemDropdown(Rect position, Type managedType, SerializedProperty systemObject) { if (!EditorGUI.DropdownButton(position, NewLabel, FocusType.Passive)) { return; } void handleItemClicked(object parameter) { systemObject.serializedObject.Update(); systemObject.managedReferenceValue = Activator.CreateInstance((Type)parameter, true); systemObject.isExpanded = true; systemObject.serializedObject.ApplyModifiedProperties(); } GenericMenu menu = new GenericMenu { allowDuplicateNames = false, }; foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies()) { foreach (Type type in assembly.GetTypes()) { if (type.IsAbstract || !managedType.IsAssignableFrom(type) || type.IsSubclassOf(typeof(UnityEngine.Object))) { continue; } if (type.IsValueType || type.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, Type.EmptyTypes, null) != null) { menu.AddItem(new GUIContent(type.FullName), false, handleItemClicked, type); } } } if (menu.GetItemCount() == 0) { Debug.LogWarning($"No type that implements {managedType} was found! The type also needs to be a non-abstract type with parameterless constructor and can't be a subclass of UnityEngine.Object."); } else { menu.DropDown(position); } }
protected void ShowConstructorSelector(SerializedProperty property) { // base type constraint Type baseType = SerializableClassConstructor.GetTypeFromName( property.FindPropertyRelative("baseTypeString").stringValue); var subclassTypes = ReflectionUtilities.GetAllSubTypes(baseType); List <MenuItem> menuItems = new List <MenuItem>(); for (int i = 0; i < subclassTypes.Count; i++) { Type t = subclassTypes[i]; ConstructorInfo[] constructors = t.GetConstructors(); foreach (var constructor in constructors) { Type[] parms = constructor.GetParameters().Select(x => x.ParameterType).ToArray(); // Skip methods with unsupported args if (parms.Any(x => !SerializableArgument.IsSupported(x))) { continue; } string constructorPrettyName = GetConstructorShowString(constructor); menuItems.Add(new MenuItem(t.Name, constructorPrettyName, () => SetConstructor(property, constructor))); } } // Construct and display context menu GenericMenu menu = new GenericMenu(); for (int i = 0; i < menuItems.Count; i++) { menu.AddItem(menuItems[i].label, false, menuItems[i].action); } if (menu.GetItemCount() == 0) { menu.AddDisabledItem(new GUIContent("No supported constructor.")); } menu.ShowAsContext(); }
public GenericMenu GetTypeMenu() { GenericMenu menu = new GenericMenu(); foreach (Type type in AppDomain.CurrentDomain.GetAssemblies().AsParallel().SelectMany(p => p.GetTypes())) { if (isUsable(type) && type.FullName.IndexOf(filter, StringComparison.OrdinalIgnoreCase) >= 0) { string path = type.FullName.Replace('.', '/'); menu.AddItem(new GUIContent(path), false, SetType, type); } } if (menu.GetItemCount() == 0) { menu.AddDisabledItem(new GUIContent($"'{filter}' not found")); } return(menu); }
private static void DoAnimatorParameterMenu(GameObject go, AnimatorControllerParameterType parameterType) { GenericMenu genericMenu = new GenericMenu(); IEnumerable <string> animatorParameterNames = StringEditor.GetAnimatorParameterNames(go, parameterType); using (IEnumerator <string> enumerator = animatorParameterNames.GetEnumerator()) { while (enumerator.MoveNext()) { string current = enumerator.get_Current(); genericMenu.AddItem(new GUIContent(current), false, new GenericMenu.MenuFunction2(StringEditor.SetStringValue), current); } } if (genericMenu.GetItemCount() == 0) { genericMenu.AddDisabledItem(new GUIContent(string.Format(Strings.get_Menu_No_Animator_Parameters(), parameterType))); } genericMenu.ShowAsContext(); }
/// <summary> /// Populates the generic menu for the property. /// </summary> public void PopulateGenericMenu(InspectorProperty property, GenericMenu genericMenu) { var populated = property.Context.GetGlobal("CustomContextMenu_Populated", false); if (populated.Value) { return; } else { populated.Value = true; } var contextMenuInfos = property.Context.GetGlobal("CustomContextMenu", (Dictionary <CustomContextMenuAttribute, ContextMenuInfo>)null); if (contextMenuInfos.Value != null && contextMenuInfos.Value.Count > 0) { if (genericMenu.GetItemCount() > 0) { genericMenu.AddSeparator(""); } foreach (var item in contextMenuInfos.Value.OrderBy(n => n.Key.MenuItem ?? "")) { var info = item.Value; if (info.MethodCaller == null) { genericMenu.AddDisabledItem(new GUIContent(item.Key.MenuItem + " (Invalid)")); } else { genericMenu.AddItem(new GUIContent(info.Name), false, () => { for (int i = 0; i < property.ParentValues.Count; i++) { info.MethodCaller(property.ParentValues[i]); } }); } } } }
void RefreshAddList() { m_AddedTypes.Clear(); for (int i = 0; i < m_DefaultPresets.arraySize; i++) { m_AddedTypes.Add(target.GetPresetTypeNameAtIndex(i)); } var assets = AssetDatabase.FindAssets("t:Preset") .Select(a => AssetDatabase.LoadAssetAtPath <Preset>(AssetDatabase.GUIDToAssetPath(a))); m_DiscoveredPresets.Clear(); foreach (var preset in assets) { string presetclass = preset.GetTargetFullTypeName(); if (preset.IsValid() && !Preset.IsPresetExcludedFromDefaultPresets(preset)) { if (!m_DiscoveredPresets.ContainsKey(presetclass)) { m_DiscoveredPresets.Add(presetclass, new List <Preset>()); } m_DiscoveredPresets[presetclass].Add(preset); } } m_AddingMenu = new GenericMenu(); foreach (var discoveredPreset in m_DiscoveredPresets) { if (!m_AddedTypes.Contains(discoveredPreset.Key)) { foreach (var preset in discoveredPreset.Value) { m_AddingMenu.AddItem(new GUIContent(discoveredPreset.Key.Replace(".", "/") + "/" + preset.name), false, OnAddingPreset, preset); } } } if (m_AddingMenu.GetItemCount() == 0) { m_AddingMenu.AddDisabledItem(EditorGUIUtility.TrTextContent("No Preset to add")); } }
/// <summary> /// Populates the generic menu for the property. /// </summary> public void PopulateGenericMenu(InspectorProperty property, GenericMenu genericMenu) { double4 value = (double4)property.ValueEntry.WeakSmartValue; var vec = new Vector4((float)value.x, (float)value.y, (float)value.z, (float)value.w); if (genericMenu.GetItemCount() > 0) { genericMenu.AddSeparator(""); } genericMenu.AddItem(new GUIContent("Normalize"), Mathf.Approximately(vec.magnitude, 1f), () => NormalizeEntries(property)); genericMenu.AddItem(new GUIContent("Zero", "Set the vector to (0, 0, 0, 0)"), vec == Vector4.zero, () => SetVector(property, Vector3.zero)); genericMenu.AddItem(new GUIContent("One", "Set the vector to (1, 1, 1, 1)"), vec == Vector4.one, () => SetVector(property, Vector4.one)); genericMenu.AddSeparator(""); genericMenu.AddItem(new GUIContent("Right", "Set the vector to (1, 0, 0, 0)"), (Vector3)vec == Vector3.right, () => SetVector(property, Vector3.right)); genericMenu.AddItem(new GUIContent("Left", "Set the vector to (-1, 0, 0, 0)"), (Vector3)vec == Vector3.left, () => SetVector(property, Vector3.left)); genericMenu.AddItem(new GUIContent("Up", "Set the vector to (0, 1, 0, 0)"), (Vector3)vec == Vector3.up, () => SetVector(property, Vector3.up)); genericMenu.AddItem(new GUIContent("Down", "Set the vector to (0, -1, 0, 0)"), (Vector3)vec == Vector3.down, () => SetVector(property, Vector3.down)); genericMenu.AddItem(new GUIContent("Forward", "Set the vector property to (0, 0, 1, 0)"), (Vector3)vec == Vector3.forward, () => SetVector(property, Vector3.forward)); genericMenu.AddItem(new GUIContent("Back", "Set the vector property to (0, 0, -1, 0)"), (Vector3)vec == Vector3.back, () => SetVector(property, Vector3.back)); }
private static void DoAnimationNameMenu(GameObject go) { GenericMenu genericMenu = new GenericMenu(); AnimationClip[] animationClips = AnimationUtility.GetAnimationClips(go); AnimationClip[] array = animationClips; for (int i = 0; i < array.Length; i++) { AnimationClip animationClip = array[i]; if (animationClip != null) { genericMenu.AddItem(new GUIContent(animationClip.get_name()), false, new GenericMenu.MenuFunction2(StringEditor.SetStringValue), animationClip.get_name()); } } if (genericMenu.GetItemCount() == 0) { genericMenu.AddDisabledItem(new GUIContent(Strings.get_Label_No_Animations_On_Object())); } genericMenu.ShowAsContext(); }
void ShowAddMenu(Rect rect, ReorderableList lst) { var menu = new GenericMenu(); TypeUtility.PopulateMenuWithCreateItems(menu, m_AddType, type => { var element = serializedProperty.AddArrayElement(); element.managedReferenceValue = CreateNewInstance(type); serializedProperty.serializedObject.ApplyModifiedProperties(); }, RequiredAttribute); AddMenuItems?.Invoke(menu); if (menu.GetItemCount() == 0 && NoItemMenuItem != null) { menu.AddDisabledItem(NoItemMenuItem); } menu.ShowAsContext(); }
public void AddRange(GenericMenu itemsFromMenu) { int count = itemsFromMenu.GetItemCount(); if (count == 0) { return; } SetupGenericMenuFields(); var menuItems = genericMenuItemsField.GetValue(itemsFromMenu) as ArrayList; for (int n = 0; n < count; n++) { //GenericMenu.MenuItem is a private class, so can't cast it directly object menuItem = menuItems[n]; var separator = (bool)genericMenuSeparatorField.GetValue(menuItem); if (separator) { AddSeparatorIfNotRedundant(); } else { var label = genericMenuContentField.GetValue(menuItem) as GUIContent; var on = (bool)genericMenuOnField.GetValue(menuItem); var func = genericMenuFuncField.GetValue(menuItem) as OnActivateItem; if (func != null) { Add(label.text, label.tooltip, func, on); } else { var func2 = genericMenuFunc2Field.GetValue(menuItem) as OnActivateItemWithParameter; var userData = genericMenuUserDataField.GetValue(menuItem); Add(label.text, label.tooltip, func2, userData, on); } } } }