public AddItem ( |
||
content | ||
on | bool | |
func | MenuFunction | |
return | void |
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); } } }
public static void CreateVCContextMenu(ref GenericMenu menu, string assetPath, Object instance = null) { if (VCUtility.ValidAssetPath(assetPath)) { bool ready = VCCommands.Instance.Ready; if (ready) { var assetStatus = VCCommands.Instance.GetAssetStatus(assetPath); if (instance && ObjectUtilities.ChangesStoredInScene(instance)) assetPath = SceneManagerUtilities.GetCurrentScenePath(); var validActions = GetValidActions(assetPath, instance); if (validActions.showDiff) menu.AddItem(new GUIContent(Terminology.diff), false, () => VCUtility.DiffWithBase(assetPath)); if (validActions.showAdd) menu.AddItem(new GUIContent(Terminology.add), false, () => VCCommands.Instance.Add(new[] { assetPath })); if (validActions.showOpen) menu.AddItem(new GUIContent(Terminology.getlock), false, () => GetLock(assetPath, instance)); if (validActions.showOpenLocal) menu.AddItem(new GUIContent(Terminology.allowLocalEdit), false, () => AllowLocalEdit(assetPath, instance)); if (validActions.showForceOpen) menu.AddItem(new GUIContent("Force " + Terminology.getlock),false, () => GetLock(assetPath, instance, OperationMode.Force)); if (validActions.showCommit) menu.AddItem(new GUIContent(Terminology.commit), false, () => Commit(assetPath, instance)); if (validActions.showUnlock) menu.AddItem(new GUIContent(Terminology.unlock), false, () => VCCommands.Instance.ReleaseLock(new[] { assetPath })); if (validActions.showDisconnect)menu.AddItem(new GUIContent("Disconnect"), false, () => PrefabHelper.DisconnectPrefab(instance as GameObject)); if (validActions.showDelete) menu.AddItem(new GUIContent(Terminology.delete), false, () => VCCommands.Instance.Delete(new[] { assetPath })); if (validActions.showRevert) menu.AddItem(new GUIContent(Terminology.revert), false, () => Revert(assetPath, instance)); } else { menu.AddDisabledItem(new GUIContent("..Busy..")); } } }
// ================================================================================================================ public SystemEditor() { addSceneMenu = new GenericMenu(); addSceneMenu.AddItem(new GUIContent("Browse"), false, OnAddScene, 0); addSceneMenu.AddItem(new GUIContent("New Scene"), false, OnAddScene, 1); for (int i = 0; i < inputSettingsFoldout.Length; i++) inputSettingsFoldout[i] = true; }
public void AddItemsToMenu(GenericMenu menu) { if (Application.platform == RuntimePlatform.OSXEditor) { menu.AddItem(new GUIContent("Open Player Log"), false, new GenericMenu.MenuFunction(InternalEditorUtility.OpenPlayerConsole)); } menu.AddItem(new GUIContent("Open Editor Log"), false, new GenericMenu.MenuFunction(InternalEditorUtility.OpenEditorConsole)); IEnumerator enumerator = Enum.GetValues(typeof(StackTraceLogType)).GetEnumerator(); try { while (enumerator.MoveNext()) { StackTraceLogType current = (StackTraceLogType) ((int) enumerator.Current); menu.AddItem(new GUIContent("Stack Trace Logging/" + current), Application.stackTraceLogType == current, new GenericMenu.MenuFunction2(this.ToggleLogStackTraces), current); } } finally { IDisposable disposable = enumerator as IDisposable; if (disposable == null) { } disposable.Dispose(); } }
public override void AddNodesItem(UnityEditor.GenericMenu menu) { base.AddNodesItem(menu); menu.AddItem(new GUIContent("Main Menu"), false, ContextCallback, "mainmenuNode"); menu.AddItem(new GUIContent("Single Player"), false, ContextCallback, "singleplayerNode"); menu.AddItem(new GUIContent("Quit Confirm"), false, ContextCallback, "quitconfirmNode"); }
public void OnContextClick(int itemIndex) { GenericMenu genericMenu = new GenericMenu(); genericMenu.AddItem(new GUIContent("Unexpose"), false, (GenericMenu.MenuFunction2) (data => this.Delete((int) data)), (object) itemIndex); genericMenu.AddItem(new GUIContent("Rename"), false, (GenericMenu.MenuFunction2) (data => this.m_ReorderableListWithRenameAndScrollView.BeginRename((int) data, 0.0f)), (object) itemIndex); genericMenu.ShowAsContext(); }
private void ContextMenu(Model instance) { var menu = new GenericMenu(); menu.AddItem(new GUIContent("New"), false, New); if (instance != null) { menu.AddItem(new GUIContent("Edit"), false, ShowEditWindow, instance); } else { menu.AddDisabledItem(new GUIContent("Edit")); } menu.AddSeparator(""); if (instance != null) { menu.AddItem(new GUIContent("Copy"), false, Copy, instance); } else { menu.AddDisabledItem(new GUIContent("Copy")); } if (CanPaste()) { menu.AddItem(new GUIContent("Paste"), false, Paste); } else { menu.AddDisabledItem(new GUIContent("Paste")); } if (instance != null) { menu.AddItem(new GUIContent("Delete"), false, Delete, instance); } else { menu.AddDisabledItem(new GUIContent("Delete")); } menu.ShowAsContext(); }
public static void CreateVCContextMenu(ref GenericMenu menu, IEnumerable<string> assetPaths) { menu.AddItem(new GUIContent(Terminology.add), false, () => VCCommands.Instance.Add(assetPaths)); menu.AddItem(new GUIContent(Terminology.getlock), false, () => VCCommands.Instance.GetLock(assetPaths)); menu.AddItem(new GUIContent(Terminology.commit), false, () => VCCommands.Instance.CommitDialog(assetPaths)); menu.AddItem(new GUIContent(Terminology.revert), false, () => VCCommands.Instance.Revert(assetPaths)); menu.AddItem(new GUIContent(Terminology.delete), false, () => VCCommands.Instance.Delete(assetPaths)); }
/// <summary> /// Shows a context menu to add a new parent. /// </summary> void OnContextMenu() { var menu = new UnityEditor.GenericMenu(); // Get the active game object var gameObject = Selection.activeGameObject; // The selected game object is not null? if (gameObject != null) { // Gets all scripts that inherits from ParentBehaviour class MonoScript[] scripts = FileUtility.GetScripts <ParentBehaviour>(); for (int i = 0; i < scripts.Length; i++) { var type = scripts[i].GetClass(); // Get the component path string componentPath = "Add Parent/"; AddComponentMenu componentMenu = AttributeUtility.GetAttribute <AddComponentMenu>(type, false); if (componentMenu == null || componentMenu.componentMenu != string.Empty) { componentMenu = AttributeUtility.GetAttribute <AddComponentMenu>(type, true); if (componentMenu != null && componentMenu.componentMenu != string.Empty) { componentPath += componentMenu.componentMenu; } else { componentPath += type.ToString().Replace('.', '/'); } // Add to menu menu.AddItem(new GUIContent(componentPath), false, delegate() { BehaviourWindow.activeParent = StateUtility.AddState(gameObject, type) as ParentBehaviour; }); } } } else { menu.AddDisabledItem(new GUIContent("Add Parent/")); ShowNotification(new GUIContent("Select a Game Object and right click in this window!")); } // Add option to paste states if (Selection.activeGameObject != null && StateUtility.statesToPaste != null && StateUtility.statesToPaste.Length > 0) { menu.AddItem(new GUIContent("Paste State"), false, delegate() { StateUtility.CloneStates(Selection.activeGameObject, StateUtility.statesToPaste, null); }); } else { menu.AddDisabledItem(new GUIContent("Paste State")); } // Refresh window? // menu.AddSeparator(""); // menu.AddItem(new GUIContent("Refresh"), false ,Refresh); // Shows the controller menu menu.ShowAsContext(); }
public static void Show(int itemIndex, FlexibleMenu caller) { FlexibleMenu.ItemContextMenu.s_Caller = caller; GenericMenu genericMenu = new GenericMenu(); genericMenu.AddItem(new GUIContent("Edit..."), false, new GenericMenu.MenuFunction2(FlexibleMenu.ItemContextMenu.Edit), itemIndex); genericMenu.AddItem(new GUIContent("Delete"), false, new GenericMenu.MenuFunction2(FlexibleMenu.ItemContextMenu.Delete), itemIndex); genericMenu.ShowAsContext(); GUIUtility.ExitGUI(); }
public virtual void AddItemsToMenu(GenericMenu menu) { if (RenderDoc.IsInstalled() && !RenderDoc.IsLoaded()) { menu.AddItem(Styles.loadRenderDocContent, false, new GenericMenu.MenuFunction(this.LoadRenderDoc)); } menu.AddItem(Styles.noCameraWarningContextMenuContent, this.m_NoCameraWarning, new GenericMenu.MenuFunction(this.ToggleNoCameraWarning)); menu.AddItem(Styles.clearEveryFrameContextMenuContent, this.m_ClearInEditMode, new GenericMenu.MenuFunction(this.ToggleClearInEditMode)); }
protected override void OnRightClick(Vector2 mousePosition) { base.OnRightClick(mousePosition); GenericMenu menu = new GenericMenu(); menu.AddItem(new GUIContent("Add State Transition"), false, AddEdge); menu.AddItem(new GUIContent("Delete State"), false, Delete); menu.ShowAsContext(); }
void ShowButton(Rect position) { Event e = Event.current; if (GUI.Button(position, EditorPlus.EditorPlusIcon, new GUIStyle(GUI.skin.label))) { if (e.button != 0) return; GenericMenu menu = new GenericMenu(); menu.AddItem(new GUIContent("Text Limit/Short Text"), (textLimit == 3), SetTextLimit, 3); menu.AddItem(new GUIContent("Text Limit/Full Text"), (textLimit == int.MaxValue), SetTextLimit, int.MaxValue); menu.AddItem(new GUIContent("Text Limit/No Text"), (textLimit == 0), SetTextLimit, 0); //menu.AddSeparator("Scale"); menu.AddItem(new GUIContent("Scale/0.5"), (widgetHost.WidgetScale == 0.5f), ChangeScale, 0.5f); menu.AddItem(new GUIContent("Scale/0.75"), (widgetHost.WidgetScale == 0.75f), ChangeScale, 0.75f); menu.AddItem(new GUIContent("Scale/1.0"), (widgetHost.WidgetScale == 1f), ChangeScale, 1f); menu.AddItem(new GUIContent("Scale/1.25"), (widgetHost.WidgetScale == 1.25f), ChangeScale, 1.25f); menu.AddItem(new GUIContent("Scale/1.5"), (widgetHost.WidgetScale == 1.5f), ChangeScale, 1.5f); menu.AddItem(new GUIContent("Scale/2"), (widgetHost.WidgetScale == 2f), ChangeScale, 2f); menu.AddItem(new GUIContent("Scale/3"), (widgetHost.WidgetScale == 3f), ChangeScale, 3f); menu.AddItem(new GUIContent("Tooltip/Show"), useTooltip, SetTooltipMode, true); menu.AddItem(new GUIContent("Tooltip/Hide"), !useTooltip, SetTooltipMode, false); menu.AddSeparator(""); if (savedHotbars.Count == 0) { menu.AddDisabledItem(new GUIContent("Saving/Load")); } else { foreach (string bar in savedHotbars) { menu.AddItem(new GUIContent("Saving/Load/" + bar), false, LoadHotbar, bar); } } menu.AddItem(new GUIContent("Saving/Save"), false, SaveHotbar); menu.AddItem(new GUIContent("Saving/Autosave/On"), useAutoSave, SetAutoSave, true); menu.AddItem(new GUIContent("Saving/Autosave/Off"), !useAutoSave, SetAutoSave, false); menu.AddItem(new GUIContent("Saving/Clear Saves"), false, ClearAllSaves); menu.AddSeparator(""); menu.AddItem(new GUIContent("Rename"), false, EditorPlusTitleWindow.Init, this); menu.AddItem(new GUIContent("Clear Bar"), false, ClearHotbar); menu.ShowAsContext(); } }
public void AddItemsToMenu(GenericMenu menu) { menu.AddItem(m_GUIRunOnRecompile, m_Settings.runOnRecompilation, ToggleRunOnRecompilation); menu.AddItem(m_GUIRunTestsOnNewScene, m_Settings.runTestOnANewScene, m_Settings.ToggleRunTestOnANewScene); if(!m_Settings.runTestOnANewScene) menu.AddDisabledItem(m_GUIAutoSaveSceneBeforeRun); else menu.AddItem(m_GUIAutoSaveSceneBeforeRun, m_Settings.autoSaveSceneBeforeRun, m_Settings.ToggleAutoSaveSceneBeforeRun); menu.AddItem(m_GUIShowDetailsBelowTests, m_Settings.horizontalSplit, m_Settings.ToggleHorizontalSplit); }
/// <summary> /// Draws the gui control. /// <param name="position">Rectangle on the screen to use for the property GUI.</param> /// <param name="property">The SerializedProperty to make the custom GUI for.</param> /// <param name="label">The label of this property.</param> /// </summary> public override void OnGUI (Rect position, SerializedProperty property, GUIContent label) { // Get state var targetState = property.serializedObject.targetObject as InternalStateBehaviour; // It's a valid state? if (targetState != null) { // Draw prefix label #if UNITY_4_0_0 || UNITY_4_1 || UNITY_4_2 Rect controlPosition = EditorGUI.PrefixLabel(position, EditorGUIUtility.GetControlID(FocusType.Passive, position), label); #else Rect controlPosition = EditorGUI.PrefixLabel(position, label); #endif // Get the parent ParentBehaviour parent = targetState.parent; // Draw button as popup if (GUI.Button(controlPosition, parent != null ? parent.stateName : "Null", EditorStyles.popup)) { // Get valid parents for the state List<ParentBehaviour> validParents = new List<ParentBehaviour>(); var targetParent = targetState as ParentBehaviour; validParents.AddRange(targetState.GetComponents<ParentBehaviour>()); // The target state is a parent behaviour? if (targetParent != null) { for (int i = validParents.Count - 1; i >= 0; i--) { // it's the targetParent? if (validParents[i] == targetParent) validParents.RemoveAt(i); // The parent is a child of the target parent? else if (validParents[i].IsAncestor(targetParent)) validParents.RemoveAt(i); } } // Create menu var menu = new GenericMenu(); // Add null item menu.AddItem(new GUIContent("Null"), parent == null, this.OnSetNewParent, new SetParent(targetState, null)); // Add menu items var parentNames = new List<string>(); for (int i = 0; i < validParents.Count; i++) { string parentName = StringHelper.GetUniqueNameInList(parentNames, validParents[i].fullStateName); parentNames.Add(parentName); menu.AddItem(new GUIContent(parentName), parent == validParents[i], this.OnSetNewParent, new SetParent(targetState, validParents[i])); } // Show context menu menu.ShowAsContext(); } } }
private void DrawToolbarGUI() { Rect rect = new Rect(0, 0, Screen.width, 50f); //rect.height = 50f; GUILayout.BeginArea(rect, MapEditor.toolbar); GUILayout.BeginHorizontal(); //float curToolbarWidth = 0; //if (isEditorMap) { if (GUILayout.Button("File", MapEditor.toolbarDropdown, GUILayout.Width(50))) { GenericMenu menu = new UnityEditor.GenericMenu(); //menu.AddSeparator(""); menu.AddItem(new GUIContent("LoadTex"), false, () => { MapEditor.BgTexture = EditorTool.LoadTexture(); }); //menu.DropDown(new Rect(0, 0, 20, 30)); menu.ShowAsContext(); } if (GUILayout.Button("工具", MapEditor.toolbarDropdown, GUILayout.Width(75))) { GenericMenu menu = new UnityEditor.GenericMenu(); //menu.AddSeparator(""); menu.AddItem(new GUIContent("鼠标"), false, () => { this.SetState(0); }); menu.AddItem(new GUIContent("笔刷"), false, () => { this.SetState(1); }); menu.AddItem(new GUIContent("移动"), false, () => { this.SetState(2); }); //menu.DropDown(new Rect(0, 0, 20, 30)); menu.ShowAsContext(); } string state = GetToolName();//new GUIContent(state, "当前编辑状态") GUILayout.Label("当前编辑状态:" + state, GUILayout.Width(200)); } if ((Pagetype == PageType.Editor || Pagetype == PageType.EditorSub) && EditorType == ToolType.Brush) { if (GUILayout.Button("选择格子类型", MapEditor.toolbarDropdown, GUILayout.Width(100))) { GenericMenu menu = new UnityEditor.GenericMenu(); //menu.AddSeparator(""); menu.AddItem(new GUIContent("不可见"), false, () => { this.SetCellType(0); }); menu.AddItem(new GUIContent("阻挡"), false, () => { this.SetCellType(1); }); menu.AddItem(new GUIContent("可编辑"), false, () => { this.SetCellType(2); }); //menu.DropDown(new Rect(0, 0, 20, 30)); menu.ShowAsContext(); } string state = GetCellName();//new GUIContent(state, "当前编辑状态") GUILayout.Label("选定格子:" + state); } GUILayout.EndHorizontal(); GUILayout.EndArea(); }
private void DrawTemplateMenu() { if (GUILayout.Button("Menu", "MiniPullDown", GUILayout.Width(56))) { GenericMenu menu = new GenericMenu(); menu.AddItem(new GUIContent("Export XML..."), false, ExportTemplate); menu.AddItem(new GUIContent("Import XML..."), false, ImportTemplate); menu.AddItem(new GUIContent("Update From Assets"), false, ConfirmUpdateFromAssets); menu.AddItem(new GUIContent("Reset"), false, ResetTemplate); menu.ShowAsContext(); } }
private void DrawLocationMenu() { if (GUILayout.Button("Menu", "MiniPullDown", GUILayout.Width(56))) { GenericMenu menu = new GenericMenu(); menu.AddItem(new GUIContent("New Location"), false, AddNewLocation); menu.AddItem(new GUIContent("Sort/By Name"), false, SortLocationsByName); menu.AddItem(new GUIContent("Sort/By ID"), false, SortLocationsByID); menu.AddItem(new GUIContent("Sync From DB"), database.syncInfo.syncLocations, ToggleSyncLocationsFromDB); menu.ShowAsContext(); } }
internal static void Show(SerializedProperty prop) { GUIContent content1 = new GUIContent("Copy"); GUIContent content2 = new GUIContent("Paste"); GenericMenu genericMenu = new GenericMenu(); genericMenu.AddItem(content1, false, new GenericMenu.MenuFunction(new GradientContextMenu(prop).Copy)); if (ParticleSystemClipboard.HasSingleGradient()) genericMenu.AddItem(content2, false, new GenericMenu.MenuFunction(new GradientContextMenu(prop).Paste)); else genericMenu.AddDisabledItem(content2); genericMenu.ShowAsContext(); }
private void DrawNodeEditorMenu() { if (GUILayout.Button("Menu", "MiniPullDown", GUILayout.Width(56))) { GenericMenu menu = new GenericMenu(); menu.AddItem(new GUIContent("New Conversation"), false, AddNewConversationToNodeEditor); menu.AddItem(new GUIContent("Sort/By Title"), false, SortConversationsByTitle); menu.AddItem(new GUIContent("Sort/By ID"), false, SortConversationsByID); menu.AddItem(new GUIContent("Actor Names"), showActorNames, ToggleShowActorNames); menu.AddItem(new GUIContent("Outline Mode"), false, ActivateOutlineMode); menu.ShowAsContext(); } }
public void OnContextClick(int itemIndex) { GenericMenu genericMenu = new GenericMenu(); genericMenu.AddItem(new GUIContent("Unexpose"), false, delegate(object data) { this.Delete((int)data); }, itemIndex); genericMenu.AddItem(new GUIContent("Rename"), false, delegate(object data) { this.m_ReorderableListWithRenameAndScrollView.BeginRename((int)data, 0f); }, itemIndex); genericMenu.ShowAsContext(); }
public static void Show(Rect buttonRect, int viewIndex, AudioMixerGroupViewList list) { GenericMenu genericMenu = new GenericMenu(); AudioMixerGroupViewList.ViewsContexttMenu.data userData = new AudioMixerGroupViewList.ViewsContexttMenu.data { viewIndex = viewIndex, list = list }; genericMenu.AddItem(new GUIContent("Rename"), false, new GenericMenu.MenuFunction2(AudioMixerGroupViewList.ViewsContexttMenu.Rename), userData); genericMenu.AddItem(new GUIContent("Duplicate"), false, new GenericMenu.MenuFunction2(AudioMixerGroupViewList.ViewsContexttMenu.Duplicate), userData); genericMenu.AddItem(new GUIContent("Delete"), false, new GenericMenu.MenuFunction2(AudioMixerGroupViewList.ViewsContexttMenu.Delete), userData); genericMenu.DropDown(buttonRect); }
public static bool Slider(GUIContent label, ref float value, float displayScale, float displayExponent, string unit, float leftValue, float rightValue, AudioMixerController controller, AudioParameterPath path, params GUILayoutOption[] options) { EditorGUI.BeginChangeCheck(); float fieldWidth = EditorGUIUtility.fieldWidth; string kFloatFieldFormatString = EditorGUI.kFloatFieldFormatString; bool flag = controller.ContainsExposedParameter(path.parameter); EditorGUIUtility.fieldWidth = 70f; EditorGUI.kFloatFieldFormatString = "F2"; EditorGUI.s_UnitString = unit; GUIContent label2 = label; if (flag) { label2 = GUIContent.Temp(label.text + " ➔", label.tooltip); } float num = value * displayScale; num = EditorGUILayout.PowerSlider(label2, num, leftValue * displayScale, rightValue * displayScale, displayExponent, options); EditorGUI.s_UnitString = null; EditorGUI.kFloatFieldFormatString = kFloatFieldFormatString; EditorGUIUtility.fieldWidth = fieldWidth; if (Event.current.type == EventType.ContextClick && GUILayoutUtility.topLevel.GetLast().Contains(Event.current.mousePosition)) { Event.current.Use(); GenericMenu genericMenu = new GenericMenu(); if (!flag) { genericMenu.AddItem(new GUIContent("Expose '" + path.ResolveStringPath(false) + "' to script"), false, new GenericMenu.MenuFunction2(AudioMixerEffectGUI.ExposePopupCallback), new AudioMixerEffectGUI.ExposedParamContext(controller, path)); } else { genericMenu.AddItem(new GUIContent("Unexpose"), false, new GenericMenu.MenuFunction2(AudioMixerEffectGUI.UnexposePopupCallback), new AudioMixerEffectGUI.ExposedParamContext(controller, path)); } ParameterTransitionType parameterTransitionType; bool transitionTypeOverride = controller.TargetSnapshot.GetTransitionTypeOverride(path.parameter, out parameterTransitionType); genericMenu.AddSeparator(string.Empty); genericMenu.AddItem(new GUIContent("Linear Snapshot Transition"), parameterTransitionType == ParameterTransitionType.Lerp, new GenericMenu.MenuFunction2(AudioMixerEffectGUI.ParameterTransitionOverrideCallback), new AudioMixerEffectGUI.ParameterTransitionOverrideContext(controller, path.parameter, ParameterTransitionType.Lerp)); genericMenu.AddItem(new GUIContent("Smoothstep Snapshot Transition"), parameterTransitionType == ParameterTransitionType.Smoothstep, new GenericMenu.MenuFunction2(AudioMixerEffectGUI.ParameterTransitionOverrideCallback), new AudioMixerEffectGUI.ParameterTransitionOverrideContext(controller, path.parameter, ParameterTransitionType.Smoothstep)); genericMenu.AddItem(new GUIContent("Squared Snapshot Transition"), parameterTransitionType == ParameterTransitionType.Squared, new GenericMenu.MenuFunction2(AudioMixerEffectGUI.ParameterTransitionOverrideCallback), new AudioMixerEffectGUI.ParameterTransitionOverrideContext(controller, path.parameter, ParameterTransitionType.Squared)); genericMenu.AddItem(new GUIContent("SquareRoot Snapshot Transition"), parameterTransitionType == ParameterTransitionType.SquareRoot, new GenericMenu.MenuFunction2(AudioMixerEffectGUI.ParameterTransitionOverrideCallback), new AudioMixerEffectGUI.ParameterTransitionOverrideContext(controller, path.parameter, ParameterTransitionType.SquareRoot)); genericMenu.AddItem(new GUIContent("BrickwallStart Snapshot Transition"), parameterTransitionType == ParameterTransitionType.BrickwallStart, new GenericMenu.MenuFunction2(AudioMixerEffectGUI.ParameterTransitionOverrideCallback), new AudioMixerEffectGUI.ParameterTransitionOverrideContext(controller, path.parameter, ParameterTransitionType.BrickwallStart)); genericMenu.AddItem(new GUIContent("BrickwallEnd Snapshot Transition"), parameterTransitionType == ParameterTransitionType.BrickwallEnd, new GenericMenu.MenuFunction2(AudioMixerEffectGUI.ParameterTransitionOverrideCallback), new AudioMixerEffectGUI.ParameterTransitionOverrideContext(controller, path.parameter, ParameterTransitionType.BrickwallEnd)); genericMenu.AddSeparator(string.Empty); genericMenu.ShowAsContext(); } if (EditorGUI.EndChangeCheck()) { value = num / displayScale; return true; } return false; }
/************************************************************************************************************************/ /// <summary>Adds the details of this state to the menu.</summary> protected override void AddContextMenuFunctions(UnityEditor.GenericMenu menu) { menu.AddDisabledItem(new GUIContent(DetailsPrefix + "Animation Type: " + Editor.AnimancerEditorUtilities.GetAnimationType(Target._Clip))); base.AddContextMenuFunctions(menu); menu.AddItem(new GUIContent("Inverse Kinematics/Apply Animator IK"), Target.ApplyAnimatorIK, () => Target.ApplyAnimatorIK = !Target.ApplyAnimatorIK); menu.AddItem(new GUIContent("Inverse Kinematics/Apply Foot IK"), Target.ApplyFootIK, () => Target.ApplyFootIK = !Target.ApplyFootIK); }
void OnGUI(){ EditorGUILayout.HelpBox("Here you can specify frequently used types for your game for easier access wherever you need to select a type.\nFor example when you create a new blackboard variable or using any refelection based actions.", MessageType.Info); if (GUILayout.Button("Add New Type")){ GenericMenu.MenuFunction2 Selected = delegate(object t){ if (!typeList.Contains( (System.Type)t)){ typeList.Add( (System.Type)t); Save(); } else { ShowNotification(new GUIContent("Type already in list") ); } }; var menu = new UnityEditor.GenericMenu(); menu.AddItem(new GUIContent("Classes/System/Object"), false, Selected, typeof(object)); foreach(var t in EditorUtils.GetAssemblyTypes(typeof(object))){ var friendlyName = (string.IsNullOrEmpty(t.Namespace)? "No Namespace/" : t.Namespace.Replace(".", "/") + "/") + t.FriendlyName(); var category = "Classes/"; if (t.IsInterface) category = "Interfaces/"; if (t.IsEnum) category = "Enumerations/"; menu.AddItem(new GUIContent( category + friendlyName), false, Selected, t); } menu.ShowAsContext(); Event.current.Use(); } if (GUILayout.Button("RESET DEFAULTS")){ UserTypePrefs.ResetTypeConfiguration(); typeList = UserTypePrefs.GetPreferedTypesList(typeof(object), true); Save(); } scrollPos = GUILayout.BeginScrollView(scrollPos); for (int i = 0; i < typeList.Count; i++){ GUILayout.BeginHorizontal("box"); EditorGUILayout.LabelField(typeList[i].Name, typeList[i].Namespace); if (GUILayout.Button("X", GUILayout.Width(18))){ typeList.RemoveAt(i); Save(); } GUILayout.EndHorizontal(); } GUILayout.EndScrollView(); Repaint(); }
internal static void Show(Rect position, SerializedProperty property, SerializedProperty property2, SerializedProperty scalar, Rect curveRanges, ParticleSystemCurveEditor curveEditor) { GUIContent content1 = new GUIContent("Copy"); GUIContent content2 = new GUIContent("Paste"); GenericMenu genericMenu = new GenericMenu(); bool flag1 = property != null && property2 != null; bool flag2 = flag1 && ParticleSystemClipboard.HasDoubleAnimationCurve() || !flag1 && ParticleSystemClipboard.HasSingleAnimationCurve(); AnimationCurveContextMenu curveContextMenu = new AnimationCurveContextMenu(property, property2, scalar, curveRanges, curveEditor); genericMenu.AddItem(content1, false, new GenericMenu.MenuFunction(curveContextMenu.Copy)); if (flag2) genericMenu.AddItem(content2, false, new GenericMenu.MenuFunction(curveContextMenu.Paste)); else genericMenu.AddDisabledItem(content2); genericMenu.DropDown(position); }
public static void Show(Rect buttonRect, AudioMixerSnapshotController snapshot, AudioMixerSnapshotListView list) { GenericMenu genericMenu = new GenericMenu(); AudioMixerSnapshotListView.SnapshotMenu.data userData = new AudioMixerSnapshotListView.SnapshotMenu.data { snapshot = snapshot, list = list }; genericMenu.AddItem(new GUIContent("Set as start Snapshot"), false, new GenericMenu.MenuFunction2(AudioMixerSnapshotListView.SnapshotMenu.SetAsStartupSnapshot), userData); genericMenu.AddSeparator(string.Empty); genericMenu.AddItem(new GUIContent("Rename"), false, new GenericMenu.MenuFunction2(AudioMixerSnapshotListView.SnapshotMenu.Rename), userData); genericMenu.AddItem(new GUIContent("Duplicate"), false, new GenericMenu.MenuFunction2(AudioMixerSnapshotListView.SnapshotMenu.Duplicate), userData); genericMenu.AddItem(new GUIContent("Delete"), false, new GenericMenu.MenuFunction2(AudioMixerSnapshotListView.SnapshotMenu.Delete), userData); genericMenu.DropDown(buttonRect); }
public virtual void AddItemsToMenu(GenericMenu menu) { menu.AddItem(new GUIContent("Sort groups alphabetically"), this.m_SortGroupsAlphabetically, (GenericMenu.MenuFunction) (() => (this.m_SortGroupsAlphabetically = !this.m_SortGroupsAlphabetically))); menu.AddItem(new GUIContent("Show referenced groups"), this.m_ShowReferencedBuses, (GenericMenu.MenuFunction) (() => (this.m_ShowReferencedBuses = !this.m_ShowReferencedBuses))); menu.AddItem(new GUIContent("Show group connections"), this.m_ShowBusConnections, (GenericMenu.MenuFunction) (() => (this.m_ShowBusConnections = !this.m_ShowBusConnections))); if (this.m_ShowBusConnections) { menu.AddItem(new GUIContent("Only highlight selected group connections"), this.m_ShowBusConnectionsOfSelection, (GenericMenu.MenuFunction) (() => (this.m_ShowBusConnectionsOfSelection = !this.m_ShowBusConnectionsOfSelection))); } menu.AddSeparator(string.Empty); menu.AddItem(new GUIContent("Vertical layout"), this.layoutMode == LayoutMode.Vertical, (GenericMenu.MenuFunction) (() => (this.layoutMode = LayoutMode.Vertical))); menu.AddItem(new GUIContent("Horizontal layout"), this.layoutMode == LayoutMode.Horizontal, (GenericMenu.MenuFunction) (() => (this.layoutMode = LayoutMode.Horizontal))); menu.AddSeparator(string.Empty); if (<>f__am$cache1E == null) {
private void SelectBehaviorBrain() { GUIContent content = new GUIContent(BehaviorTreeEditor.active != null ? BehaviorTreeEditor.active.name : "[None Selected]"); float width = EditorStyles.toolbarDropDown.CalcSize(content).x; width = Mathf.Clamp(width, 100f, width); if (GUILayout.Button(content, EditorStyles.toolbarDropDown, GUILayout.Width(width))) { GenericMenu menu = new GenericMenu(); if (BehaviorTreeEditor.active != null) SelectBehaviorBrainMenu(BehaviorTreeEditor.active, ref menu); menu.AddItem(new GUIContent("[Craete New]"), false, delegate () { BehaviorTree bt = AssetCreator.CreateAsset<BehaviorTree>(true); if (bt != null) { bt.Name = bt.name; Root root = BehaviorTreeEditorUtility.AddNode<Root>(BehaviorTreeEditor.center, bt); bt.rootNode = root; root.Name = "Root"; AssetDatabase.SaveAssets(); BehaviorTreeEditor.SelectBehaviorTrees(bt); } }); menu.ShowAsContext(); } }
/// <summary> /// Callback to add a new node. /// </summary> private void OnAddNode(ReorderableList list) { // Get all node scripts var nodeTypes = new List <System.Type>(); foreach (System.Type type in BehaviourTreeUtility.GetNodeTypes()) { if (!type.IsSubclassOf(typeof(BranchNode))) { nodeTypes.Add(type); } } // Create the menu var menu = new UnityEditor.GenericMenu(); // Add node types to the menu for (int i = 0; i < nodeTypes.Count; i++) { var nodeType = nodeTypes[i]; var nodeInfo = AttributeUtility.GetAttribute <NodeInfoAttribute>(nodeType, false) ?? new NodeInfoAttribute(); menu.AddItem(new GUIContent(nodeInfo.category + nodeType.Name), false, delegate() { ActionStateUtility.AddNode(m_ActionState, nodeType); RegisterEditorOnGUI(); }); } // Show the context menu menu.ShowAsContext(); }
public static void ShowOutputSlotsMenu(GenericMenu.MenuFunction2 func, System.Type filterSlotDataType = null) { var mnu = new GenericMenu(); var generators = Component.FindObjectsOfType<CurvyGenerator>(); mnu.AddItem(new GUIContent("none"), false, func,null); foreach (var gen in generators) { var slots = findOutputSlots(gen, filterSlotDataType); foreach (CGModuleOutputSlot slot in slots) mnu.AddItem(new GUIContent(gen.name + "/" + slot.Module.ModuleName+"/"+slot.Info.Name), false, func, slot); } mnu.ShowAsContext(); }
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."); } } }
void AddMenuItem(GenericMenu mnu, string item, GenericMenu.MenuFunction func, bool enabled=true) { if (enabled) mnu.AddItem(new GUIContent(item), false, func); else mnu.AddDisabledItem(new GUIContent(item)); }
//yeah this is very special but.... public static void ShowConfiguredTypeSelectionMenu(Type type, Action <Type> callback, bool showInterfaces = true) { GenericMenu.MenuFunction2 Selected = delegate(object t){ callback((Type)t); }; var menu = new UnityEditor.GenericMenu(); foreach (System.Type t in NCPrefs.GetCommonlyUsedTypes(typeof(object))) { if (type.IsAssignableFrom(t) || (t.IsInterface && showInterfaces)) { var category = "Classes/"; if (t.IsInterface) { category = "Interfaces/"; } if (t.IsEnum) { category = "Enumerations/"; } var nsString = string.IsNullOrEmpty(t.Namespace)? "No Namespace/" : (t.Namespace.Replace(".", "/") + "/"); menu.AddItem(new GUIContent(category + nsString + TypeName(t)), false, Selected, t); } } menu.AddDisabledItem(new GUIContent("Add more in Type Configurator")); menu.ShowAsContext(); Event.current.Use(); }
public void DeleteLinkMenuAndReLink <T>(List <T> nodes, UnityEditor.GenericMenu menu, string title, Action act) where T : LogicNodeBase { if (nodes.Count == 0) { return; } menu.AddSeparator(""); nodes.ForEach(x => menu.AddItem(new GUIContent(title + "/" + x.ShowName), false, () => { nodes.Remove(x); act(); })); }
private void ShowAddPointerMenu <TItem>(string name, Action addItem, Action <TItem> addPointer) where TItem : IDiagramNodeItem { var ctxMenu = new UnityEditor.GenericMenu(); ctxMenu.AddItem(new GUIContent("New " + name), false, () => { InvertApplication.Execute(() => { addItem(); }); }); ctxMenu.AddSeparator(""); var nodeConfigSection = NodeViewModel.DiagramViewModel.CurrentRepository.AllOf <TItem>(); foreach (var item in nodeConfigSection) { var item1 = item; ctxMenu.AddItem(new GUIContent(item.Name), false, () => { InvertApplication.Execute(() => { addPointer(item1); }); }); } ctxMenu.ShowAsContext(); }
private void OnGUI() { foreach (var sb in StatButtons) { sb.Draw(); sb.PollEvents(); } Repaint(); switch (Event.current.type) { case EventType.MouseDown: if (Event.current.button == 1) { var gm = new UnityEditor.GenericMenu(); gm.AddItem(new GUIContent("Create Stat"), false, CreateButton); gm.AddItem(new GUIContent("Print Info"), false, () => { Debug.Log("Info Printed"); }); gm.ShowAsContext(); } break; } }
/// <summary> /// Shows a context menu for the supplied transition. /// <param name="transition">The target transition.</param> /// </summary> void ShowContextMenu(StateTransition transition) { var menu = new UnityEditor.GenericMenu(); var currentEventID = transition.eventID; // Add none menu.AddItem(new GUIContent("None"), currentEventID == 0, delegate() { StateUtility.SetNewEvent(m_State, transition, 0); this.Refresh(); }); // Add blackboard events var blackboard = m_State.blackboard; if (blackboard != null) { foreach (var fsmEvent in blackboard.fsmEvents) { int eventId = fsmEvent.id; menu.AddItem(new GUIContent(fsmEvent.name), currentEventID == fsmEvent.id, delegate() { StateUtility.SetNewEvent(m_State, transition, eventId); this.Refresh(); }); } } // Add GlobalBlackboard events // This is not The GlobalBlackboard? if (InternalGlobalBlackboard.Instance != null && blackboard != InternalGlobalBlackboard.Instance) { foreach (var globalEvent in InternalGlobalBlackboard.Instance.fsmEvents) { int eventId = globalEvent.id; var eventName = globalEvent.isSystem ? "System/" + globalEvent.name : "Global/" + globalEvent.name; menu.AddItem(new GUIContent(eventName), currentEventID == globalEvent.id, delegate() { StateUtility.SetNewEvent(m_State, transition, eventId); this.Refresh(); }); } } menu.AddSeparator(""); // Separator menu.AddItem(new GUIContent("Delete"), false, delegate() { StateUtility.RemoveTransition(m_State, transition); this.Refresh(); }); // Shows the context menu menu.ShowAsContext(); }
/// <summary> /// Show the node menu. /// <param name="node">The target node.</param> /// </summary> void NodeContextMenu(ActionNode node) { // Validate Paramenters if (node == null) { return; } // Create the menu var menu = new UnityEditor.GenericMenu(); // Copy/Cut/Paste/Duplicate menu.AddItem(new GUIContent("Copy"), false, delegate() { BehaviourTreeUtility.nodeToPaste = node; }); menu.AddItem(new GUIContent("Cut"), false, delegate() { BehaviourTreeUtility.nodeToPaste = node; OnDestroyNode(node); }); ActionNode[] nodesToPaste = ActionStateUtility.GetActionsAndConditions(BehaviourTreeUtility.nodeToPaste != null ? new ActionNode[] { BehaviourTreeUtility.nodeToPaste } : new ActionNode[0]); if (nodesToPaste.Length > 0) { menu.AddItem(new GUIContent("Paste"), false, delegate() { ActionStateUtility.PasteNodes(m_ActionState, nodesToPaste); }); } else { menu.AddDisabledItem(new GUIContent("Paste")); } menu.AddItem(new GUIContent("Duplicate"), false, delegate() { ActionStateUtility.PasteNodes(m_ActionState, new ActionNode[] { node }); }); // Separator menu.AddSeparator(""); // Delete menu.AddItem(new GUIContent("Delete"), false, delegate() { this.OnDestroyNode(node); }); // Show the context menu menu.ShowAsContext(); }
//public void DeletItem() //{ // items.Remove(item); //} private void OnGUI() { foreach (var item in items) { item.Draw(); item.PollEvents(); } Repaint(); switch (Event.current.type) { case EventType.MouseDown: if (Event.current.button == 1) { var gm = new UnityEditor.GenericMenu(); gm.AddItem(new GUIContent("Create Item Menu"), false, CreateItem); gm.ShowAsContext(); } break; } }
internal static void DoToolContextMenu() { var toolHistoryMenu = new GenericMenu() { allowDuplicateNames = true }; var foundTool = false; // Recent history if (EditorToolContext.GetLastCustomTool() != null) { foundTool = true; toolHistoryMenu.AddDisabledItem(Styles.recentTools); EditorToolContext.GetToolHistory(s_ToolList, true); for (var i = 0; i < Math.Min(k_MaxToolHistory, s_ToolList.Count); i++) { var tool = s_ToolList[i]; if (EditorToolUtility.IsCustomEditorTool(tool.GetType())) { continue; } var name = EditorToolUtility.GetToolName(tool.GetType()); if (tool.IsAvailable()) { toolHistoryMenu.AddItem(new GUIContent(name), false, () => { EditorToolContext.activeTool = tool; }); } else { toolHistoryMenu.AddDisabledItem(new GUIContent(name)); } } toolHistoryMenu.AddSeparator(""); } EditorToolContext.GetCustomEditorTools(s_ToolList, false); // Current selection if (s_ToolList.Any()) { foundTool = true; toolHistoryMenu.AddDisabledItem(Styles.selectionTools); for (var i = 0; i < s_ToolList.Count; i++) { var tool = s_ToolList[i]; if (!EditorToolUtility.IsCustomEditorTool(tool.GetType())) { continue; } var path = new GUIContent(EditorToolUtility.GetToolMenuPath(tool)); if (tool.IsAvailable()) { toolHistoryMenu.AddItem(path, false, () => { EditorToolContext.activeTool = tool; }); } else { toolHistoryMenu.AddDisabledItem(path); } } toolHistoryMenu.AddSeparator(""); } var global = EditorToolUtility.GetCustomEditorToolsForType(null); if (global.Any()) { foundTool = true; toolHistoryMenu.AddDisabledItem(Styles.availableTools); foreach (var toolType in global) { toolHistoryMenu.AddItem( new GUIContent(EditorToolUtility.GetToolMenuPath(toolType)), false, () => { EditorTools.EditorTools.SetActiveTool(toolType); }); } } if (!foundTool) { toolHistoryMenu.AddDisabledItem(Styles.noToolsAvailable); } toolHistoryMenu.ShowAsContext(); }
// Add items to the context menu for the AudioMixerWindow (the tree horizontal lines, upper right corner) public virtual void AddItemsToMenu(GenericMenu menu) { menu.AddItem(EditorGUIUtility.TrTextContent("Sort groups alphabetically"), m_SortGroupsAlphabetically, delegate { m_SortGroupsAlphabetically = !m_SortGroupsAlphabetically; }); menu.AddItem(EditorGUIUtility.TrTextContent("Show referenced groups"), m_ShowReferencedBuses, delegate { m_ShowReferencedBuses = !m_ShowReferencedBuses; }); menu.AddItem(EditorGUIUtility.TrTextContent("Show group connections"), m_ShowBusConnections, delegate { m_ShowBusConnections = !m_ShowBusConnections; }); if (m_ShowBusConnections) { menu.AddItem(EditorGUIUtility.TrTextContent("Only highlight selected group connections"), m_ShowBusConnectionsOfSelection, delegate { m_ShowBusConnectionsOfSelection = !m_ShowBusConnectionsOfSelection; }); } menu.AddSeparator(""); menu.AddItem(EditorGUIUtility.TrTextContent("Vertical layout"), layoutMode == LayoutMode.Vertical, delegate { layoutMode = LayoutMode.Vertical; }); menu.AddItem(EditorGUIUtility.TrTextContent("Horizontal layout"), layoutMode == LayoutMode.Horizontal, delegate { layoutMode = LayoutMode.Horizontal; }); menu.AddSeparator(""); menu.AddItem(EditorGUIUtility.TrTextContent("Use RMS metering for display"), EditorPrefs.GetBool(kAudioMixerUseRMSMetering, true), delegate { EditorPrefs.SetBool(kAudioMixerUseRMSMetering, true); }); menu.AddItem(EditorGUIUtility.TrTextContent("Use peak metering for display"), !EditorPrefs.GetBool(kAudioMixerUseRMSMetering, true), delegate { EditorPrefs.SetBool(kAudioMixerUseRMSMetering, false); }); if (Unsupported.IsDeveloperMode()) { menu.AddSeparator(""); menu.AddItem(EditorGUIUtility.TrTextContent("DEVELOPER/Groups Rendered Above"), m_GroupsRenderedAboveSections, delegate { m_GroupsRenderedAboveSections = !m_GroupsRenderedAboveSections; }); menu.AddItem(EditorGUIUtility.TrTextContent("DEVELOPER/Build 10 groups"), false, delegate { m_Controller.BuildTestSetup(0, 7, 10); }); menu.AddItem(EditorGUIUtility.TrTextContent("DEVELOPER/Build 20 groups"), false, delegate { m_Controller.BuildTestSetup(0, 7, 20); }); menu.AddItem(EditorGUIUtility.TrTextContent("DEVELOPER/Build 40 groups"), false, delegate { m_Controller.BuildTestSetup(0, 7, 40); }); menu.AddItem(EditorGUIUtility.TrTextContent("DEVELOPER/Build 80 groups"), false, delegate { m_Controller.BuildTestSetup(0, 7, 80); }); menu.AddItem(EditorGUIUtility.TrTextContent("DEVELOPER/Build 160 groups"), false, delegate { m_Controller.BuildTestSetup(0, 7, 160); }); menu.AddItem(EditorGUIUtility.TrTextContent("DEVELOPER/Build chain of 10 groups"), false, delegate { m_Controller.BuildTestSetup(1, 1, 10); }); menu.AddItem(EditorGUIUtility.TrTextContent("DEVELOPER/Build chain of 20 groups "), false, delegate { m_Controller.BuildTestSetup(1, 1, 20); }); menu.AddItem(EditorGUIUtility.TrTextContent("DEVELOPER/Build chain of 40 groups"), false, delegate { m_Controller.BuildTestSetup(1, 1, 40); }); menu.AddItem(EditorGUIUtility.TrTextContent("DEVELOPER/Build chain of 80 groups"), false, delegate { m_Controller.BuildTestSetup(1, 1, 80); }); menu.AddItem(EditorGUIUtility.TrTextContent("DEVELOPER/Show overlays"), m_ShowDeveloperOverlays, delegate { m_ShowDeveloperOverlays = !m_ShowDeveloperOverlays; }); } }
internal void OnGUI() { Event e = Event.current; LoadIcons(); if (!m_HasUpdatedGuiStyles) { m_LineHeight = Mathf.RoundToInt(Constants.ErrorStyle.lineHeight); m_BorderHeight = Constants.ErrorStyle.border.top + Constants.ErrorStyle.border.bottom; UpdateListView(); } GUILayout.BeginHorizontal(Constants.Toolbar); // Clear button and clearing options bool clearClicked = false; if (EditorGUILayout.DropDownToggle(ref clearClicked, Constants.Clear, EditorStyles.toolbarDropDownToggle)) { var clearOnPlay = HasFlag(ConsoleFlags.ClearOnPlay); var clearOnBuild = HasFlag(ConsoleFlags.ClearOnBuild); var clearOnRecompile = HasFlag(ConsoleFlags.ClearOnRecompile); GenericMenu menu = new GenericMenu(); menu.AddItem(Constants.ClearOnPlay, clearOnPlay, () => { SetFlag(ConsoleFlags.ClearOnPlay, !clearOnPlay); }); menu.AddItem(Constants.ClearOnBuild, clearOnBuild, () => { SetFlag(ConsoleFlags.ClearOnBuild, !clearOnBuild); }); menu.AddItem(Constants.ClearOnRecompile, clearOnRecompile, () => { SetFlag(ConsoleFlags.ClearOnRecompile, !clearOnRecompile); }); var rect = GUILayoutUtility.GetLastRect(); rect.y += EditorGUIUtility.singleLineHeight; menu.DropDown(rect); } if (clearClicked) { LogEntries.Clear(); GUIUtility.keyboardControl = 0; } int currCount = LogEntries.GetCount(); bool showSearchNoResultMessage = currCount == 0 && !String.IsNullOrEmpty(m_SearchText); if (m_ListView.totalRows != currCount) { // scroll bar was at the bottom? if (m_ListView.scrollPos.y >= m_ListView.rowHeight * m_ListView.totalRows - ms_LVHeight) { m_ListView.scrollPos.y = currCount * RowHeight - ms_LVHeight; } } bool wasCollapsed = HasFlag(ConsoleFlags.Collapse); SetFlag(ConsoleFlags.Collapse, GUILayout.Toggle(wasCollapsed, Constants.Collapse, Constants.MiniButton)); bool collapsedChanged = (wasCollapsed != HasFlag(ConsoleFlags.Collapse)); if (collapsedChanged) { // unselect if collapsed flag changed m_ListView.row = -1; // scroll to bottom m_ListView.scrollPos.y = LogEntries.GetCount() * RowHeight; } if (HasSpaceForExtraButtons()) { SetFlag(ConsoleFlags.ErrorPause, GUILayout.Toggle(HasFlag(ConsoleFlags.ErrorPause), Constants.ErrorPause, Constants.MiniButton)); PlayerConnectionGUILayout.ConnectionTargetSelectionDropdown(m_ConsoleAttachToPlayerState, EditorStyles.toolbarDropDown, (int)(position.width - k_HasSpaceForExtraButtonsCutoff) + 80); } GUILayout.FlexibleSpace(); // Search bar if (HasSpaceForExtraButtons()) { SearchField(e); } // Flags int errorCount = 0, warningCount = 0, logCount = 0; LogEntries.GetCountsByType(ref errorCount, ref warningCount, ref logCount); EditorGUI.BeginChangeCheck(); bool setLogFlag = GUILayout.Toggle(HasFlag(ConsoleFlags.LogLevelLog), new GUIContent((logCount <= 999 ? logCount.ToString() : "999+"), logCount > 0 ? iconInfoSmall : iconInfoMono), Constants.MiniButton); bool setWarningFlag = GUILayout.Toggle(HasFlag(ConsoleFlags.LogLevelWarning), new GUIContent((warningCount <= 999 ? warningCount.ToString() : "999+"), warningCount > 0 ? iconWarnSmall : iconWarnMono), Constants.MiniButton); bool setErrorFlag = GUILayout.Toggle(HasFlag(ConsoleFlags.LogLevelError), new GUIContent((errorCount <= 999 ? errorCount.ToString() : "999+"), errorCount > 0 ? iconErrorSmall : iconErrorMono), Constants.MiniButtonRight); // Active entry index may no longer be valid if (EditorGUI.EndChangeCheck()) { SetActiveEntry(null); m_LastActiveEntryIndex = -1; } SetFlag(ConsoleFlags.LogLevelLog, setLogFlag); SetFlag(ConsoleFlags.LogLevelWarning, setWarningFlag); SetFlag(ConsoleFlags.LogLevelError, setErrorFlag); GUILayout.EndHorizontal(); if (showSearchNoResultMessage) { Rect r = new Rect(0, EditorGUI.kSingleLineHeight, ms_ConsoleWindow.position.width, ms_ConsoleWindow.position.height - EditorGUI.kSingleLineHeight); GUI.Box(r, m_ConsoleSearchNoResultMsg, Constants.ConsoleSearchNoResult); } else { // Console entries SplitterGUILayout.BeginVerticalSplit(spl); GUIContent tempContent = new GUIContent(); int id = GUIUtility.GetControlID(0); int rowDoubleClicked = -1; /////@TODO: Make Frame selected work with ListViewState using (new GettingLogEntriesScope(m_ListView)) { int selectedRow = -1; bool openSelectedItem = false; bool collapsed = HasFlag(ConsoleFlags.Collapse); float scrollPosY = m_ListView.scrollPos.y; foreach (ListViewElement el in ListViewGUI.ListView(m_ListView, ListViewOptions.wantsRowMultiSelection, Constants.Box)) { // Destroy latest restore entry if needed if (e.type == EventType.ScrollWheel || e.type == EventType.Used) { DestroyLatestRestoreEntry(); } // Make sure that scrollPos.y is always up to date after restoring last entry if (m_RestoreLatestSelection) { m_ListView.scrollPos.y = scrollPosY; } if (e.type == EventType.MouseDown && e.button == 0 && el.position.Contains(e.mousePosition)) { selectedRow = m_ListView.row; DestroyLatestRestoreEntry(); LogEntry entry = new LogEntry(); LogEntries.GetEntryInternal(m_ListView.row, entry); m_LastActiveEntryIndex = entry.globalLineIndex; if (e.clickCount == 2) { openSelectedItem = true; } } else if (e.type == EventType.Repaint) { int mode = 0; string text = null; LogEntries.GetLinesAndModeFromEntryInternal(el.row, Constants.LogStyleLineCount, ref mode, ref text); bool entryIsSelected = m_ListView.selectedItems != null && el.row < m_ListView.selectedItems.Length && m_ListView.selectedItems[el.row]; // offset value in x for icon and text var offset = Constants.LogStyleLineCount == 1 ? 4 : 8; // Draw the background GUIStyle s = el.row % 2 == 0 ? Constants.OddBackground : Constants.EvenBackground; s.Draw(el.position, false, false, entryIsSelected, false); // Draw the icon GUIStyle iconStyle = GetStyleForErrorMode(mode, true, Constants.LogStyleLineCount == 1); Rect iconRect = el.position; iconRect.x += offset; iconRect.y += 2; iconStyle.Draw(iconRect, false, false, entryIsSelected, false); // Draw the text tempContent.text = text; GUIStyle errorModeStyle = GetStyleForErrorMode(mode, false, Constants.LogStyleLineCount == 1); var textRect = el.position; textRect.x += offset; if (string.IsNullOrEmpty(m_SearchText)) { errorModeStyle.Draw(textRect, tempContent, id, m_ListView.row == el.row); } else if (text != null) { //the whole text contains the searchtext, we have to know where it is int startIndex = text.IndexOf(m_SearchText, StringComparison.OrdinalIgnoreCase); if (startIndex == -1 ) // the searchtext is not in the visible text, we don't show the selection { errorModeStyle.Draw(textRect, tempContent, id, m_ListView.row == el.row); } else // the searchtext is visible, we show the selection { int endIndex = startIndex + m_SearchText.Length; const bool isActive = false; const bool hasKeyboardFocus = true; // This ensure we draw the selection text over the label. const bool drawAsComposition = false; Color selectionColor = GUI.skin.settings.selectionColor; errorModeStyle.DrawWithTextSelection(textRect, tempContent, isActive, hasKeyboardFocus, startIndex, endIndex, drawAsComposition, selectionColor); } } if (collapsed) { Rect badgeRect = el.position; tempContent.text = LogEntries.GetEntryCount(el.row) .ToString(CultureInfo.InvariantCulture); Vector2 badgeSize = Constants.CountBadge.CalcSize(tempContent); if (Constants.CountBadge.fixedHeight > 0) { badgeSize.y = Constants.CountBadge.fixedHeight; } badgeRect.xMin = badgeRect.xMax - badgeSize.x; badgeRect.yMin += ((badgeRect.yMax - badgeRect.yMin) - badgeSize.y) * 0.5f; badgeRect.x -= 5f; GUI.Label(badgeRect, tempContent, Constants.CountBadge); } } } if (selectedRow != -1) { if (m_ListView.scrollPos.y >= m_ListView.rowHeight * m_ListView.totalRows - ms_LVHeight) { m_ListView.scrollPos.y = m_ListView.rowHeight * m_ListView.totalRows - ms_LVHeight - 1; } } // Make sure the selected entry is up to date if (m_ListView.totalRows == 0 || m_ListView.row >= m_ListView.totalRows || m_ListView.row < 0) { if (m_ActiveText.Length != 0) { SetActiveEntry(null); DestroyLatestRestoreEntry(); } } else { LogEntry entry = new LogEntry(); LogEntries.GetEntryInternal(m_ListView.row, entry); SetActiveEntry(entry); m_LastActiveEntryIndex = entry.globalLineIndex; // see if selected entry changed. if so - clear additional info LogEntries.GetEntryInternal(m_ListView.row, entry); if (m_ListView.selectionChanged || !m_ActiveText.Equals(entry.message)) { SetActiveEntry(entry); m_LastActiveEntryIndex = entry.globalLineIndex; } // If copy, get the messages from selected rows if (e.type == EventType.ExecuteCommand && e.commandName == EventCommandNames.Copy && m_ListView.selectedItems != null) { m_CopyString.Clear(); for (int rowIndex = 0; rowIndex < m_ListView.selectedItems.Length; rowIndex++) { if (m_ListView.selectedItems[rowIndex]) { LogEntries.GetEntryInternal(rowIndex, entry); m_CopyString.AppendLine(entry.message); } } } } // Open entry using return key if ((GUIUtility.keyboardControl == m_ListView.ID) && (e.type == EventType.KeyDown) && (e.keyCode == KeyCode.Return) && (m_ListView.row != 0)) { selectedRow = m_ListView.row; openSelectedItem = true; } if (e.type != EventType.Layout && ListViewGUI.ilvState.rectHeight != 1) { ms_LVHeight = ListViewGUI.ilvState.rectHeight; } if (openSelectedItem) { rowDoubleClicked = selectedRow; e.Use(); } } // Prevent dead locking in EditorMonoConsole by delaying callbacks (which can log to the console) until after LogEntries.EndGettingEntries() has been // called (this releases the mutex in EditorMonoConsole so logging again is allowed). Fix for case 1081060. if (rowDoubleClicked != -1) { LogEntries.RowGotDoubleClicked(rowDoubleClicked); } // Display active text (We want word wrapped text with a vertical scrollbar) m_TextScroll = GUILayout.BeginScrollView(m_TextScroll, Constants.Box); string stackWithHyperlinks = StacktraceWithHyperlinks(m_ActiveText, m_CallstackTextStart); float height = Constants.MessageStyle.CalcHeight(GUIContent.Temp(stackWithHyperlinks), position.width); EditorGUILayout.SelectableLabel(stackWithHyperlinks, Constants.MessageStyle, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true), GUILayout.MinHeight(height + 10)); GUILayout.EndScrollView(); SplitterGUILayout.EndVerticalSplit(); } // Copy & Paste selected item if ((e.type == EventType.ValidateCommand || e.type == EventType.ExecuteCommand) && e.commandName == EventCommandNames.Copy && m_CopyString != null) { if (e.type == EventType.ExecuteCommand) { EditorGUIUtility.systemCopyBuffer = m_CopyString.ToString(); } e.Use(); } if (!ms_ConsoleWindow) { ms_ConsoleWindow = this; } }
internal static void ShaderErrorListUI(UnityEngine.Object shader, ShaderError[] errors, ref Vector2 scrollPosition) { int num = errors.Length; GUILayout.Space(5f); GUILayout.Label(string.Format("Errors ({0}):", num), EditorStyles.boldLabel, new GUILayoutOption[0]); int controlID = GUIUtility.GetControlID(CustomShaderInspector.kErrorViewHash, FocusType.Passive); float minHeight = Mathf.Min(( float )num * 20f + 40f, 150f); scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUISkinEx.GetCurrentSkin().box, new GUILayoutOption[] { GUILayout.MinHeight(minHeight) }); EditorGUIUtility.SetIconSize(new Vector2(16f, 16f)); float height = CustomShaderInspector.Styles.messageStyle.CalcHeight(EditorGUIUtilityEx.TempContent(CustomShaderInspector.Styles.errorIcon), 100f); Event current = Event.current; for (int i = 0; i < num; i++) { Rect controlRect = EditorGUILayout.GetControlRect(false, height, new GUILayoutOption[0]); string message = errors[i].message; string platform = errors[i].platform; bool flag = errors[i].warning != 0; string lastPathNameComponent = FileUtilEx.GetLastPathNameComponent(errors[i].file); int line = errors[i].line; if (current.type == EventType.MouseDown && current.button == 0 && controlRect.Contains(current.mousePosition)) { GUIUtility.keyboardControl = controlID; if (current.clickCount == 2) { string file = errors[i].file; UnityEngine.Object @object = (!string.IsNullOrEmpty(file)) ? AssetDatabase.LoadMainAssetAtPath(file) : null; AssetDatabase.OpenAsset(@object ?? shader, line); GUIUtility.ExitGUI(); } current.Use(); } if (current.type == EventType.ContextClick && controlRect.Contains(current.mousePosition)) { current.Use(); GenericMenu genericMenu = new GenericMenu(); int errorIndex = i; genericMenu.AddItem(new GUIContent("Copy error text"), false, delegate { string text = errors[errorIndex].message; if (!string.IsNullOrEmpty(errors[errorIndex].messageDetails)) { text += '\n'; text += errors[errorIndex].messageDetails; } EditorGUIUtility.systemCopyBuffer = text; }); genericMenu.ShowAsContext(); } if (current.type == EventType.Repaint && (i & 1) == 0) { GUIStyle evenBackground = CustomShaderInspector.Styles.evenBackground; evenBackground.Draw(controlRect, false, false, false, false); } Rect rect = controlRect; rect.xMin = rect.xMax; if (line > 0) { GUIContent content; if (string.IsNullOrEmpty(lastPathNameComponent)) { content = EditorGUIUtilityEx.TempContent(line.ToString(System.Globalization.CultureInfo.InvariantCulture)); } else { content = EditorGUIUtilityEx.TempContent(lastPathNameComponent + ":" + line.ToString(System.Globalization.CultureInfo.InvariantCulture)); } Vector2 vector = EditorStyles.miniLabel.CalcSize(content); rect.xMin -= vector.x; GUI.Label(rect, content, EditorStyles.miniLabel); rect.xMin -= 2f; if (rect.width < 30f) { rect.xMin = rect.xMax - 30f; } } Rect position = rect; position.width = 0f; if (platform.Length > 0) { GUIContent content2 = EditorGUIUtilityEx.TempContent(platform); Vector2 vector2 = EditorStyles.miniLabel.CalcSize(content2); position.xMin -= vector2.x; Color contentColor = GUI.contentColor; GUI.contentColor = new Color(1f, 1f, 1f, 0.5f); GUI.Label(position, content2, EditorStyles.miniLabel); GUI.contentColor = contentColor; position.xMin -= 2f; } Rect position2 = controlRect; position2.xMax = position.xMin; GUI.Label(position2, EditorGUIUtilityEx.TempContent(message, (!flag) ? CustomShaderInspector.Styles.errorIcon : CustomShaderInspector.Styles.warningIcon), CustomShaderInspector.Styles.messageStyle); } EditorGUIUtility.SetIconSize(Vector2.zero); GUILayout.EndScrollView(); }
protected override void ContextClickedItem(int id) { UnityEditor.GenericMenu menu = new UnityEditor.GenericMenu(); var item = Find(id); if (CheckWaapi()) { if (CanPlay(item)) { menu.AddItem(UnityEditor.EditorGUIUtility.TrTextContent("Play \u2215 Stop _SPACE"), false, () => AkWaapiUtilities.TogglePlayEvent(item.objectType, item.objectGuid)); } else { menu.AddDisabledItem(UnityEditor.EditorGUIUtility.TrTextContent("Play \u2215 Stop _Space")); } menu.AddItem(UnityEditor.EditorGUIUtility.TrTextContent("Stop All"), false, () => AkWaapiUtilities.StopAllTransports()); menu.AddSeparator(""); if (CanRenameWithLog(item, false)) { menu.AddItem(UnityEditor.EditorGUIUtility.TrTextContent("Rename _F2"), false, () => BeginRename(item)); } else { menu.AddDisabledItem(UnityEditor.EditorGUIUtility.TrTextContent("Rename")); } if (CanDelete(item, false)) { menu.AddItem(UnityEditor.EditorGUIUtility.TrTextContent("Delete _Delete"), false, () => AkWaapiUtilities.Delete(item.objectGuid)); } else { menu.AddDisabledItem(UnityEditor.EditorGUIUtility.TrTextContent("Delete")); } menu.AddSeparator(""); if (item.objectType == WwiseObjectType.Soundbank) { menu.AddItem(UnityEditor.EditorGUIUtility.TrTextContent("Open Folder/WorkUnit #O"), false, () => AkWaapiUtilities.OpenWorkUnitInExplorer(item.objectGuid)); menu.AddItem(UnityEditor.EditorGUIUtility.TrTextContent("Open Folder/SoundBank "), false, () => AkWaapiUtilities.OpenSoundBankInExplorer(item.objectGuid)); } else { menu.AddItem(UnityEditor.EditorGUIUtility.TrTextContent("Open Containing Folder #O"), false, () => AkWaapiUtilities.OpenWorkUnitInExplorer(item.objectGuid)); } menu.AddItem(UnityEditor.EditorGUIUtility.TrTextContent("Find in Project Explorer #F"), false, () => m_dataSource.SelectObjectInAuthoring(item.objectGuid)); } else { if (AkWwiseProjectInfo.GetData().currentDataSource == AkWwiseProjectInfo.DataSourceType.WwiseAuthoring) { menu.AddItem(UnityEditor.EditorGUIUtility.TrTextContent("Wwise Connection Settings"), false, OpenSettings); menu.AddSeparator(""); } menu.AddDisabledItem(UnityEditor.EditorGUIUtility.TrTextContent("Play \u2215 Stop")); menu.AddDisabledItem(UnityEditor.EditorGUIUtility.TrTextContent("Stop all")); menu.AddSeparator(""); menu.AddDisabledItem(UnityEditor.EditorGUIUtility.TrTextContent("Rename")); menu.AddDisabledItem(UnityEditor.EditorGUIUtility.TrTextContent("Delete")); menu.AddSeparator(""); menu.AddDisabledItem(UnityEditor.EditorGUIUtility.TrTextContent("Open Containing Folder")); menu.AddDisabledItem(UnityEditor.EditorGUIUtility.TrTextContent("Find in Project Explorer")); } menu.AddItem(UnityEditor.EditorGUIUtility.TrTextContent("Find References in Scene #R"), false, () => FindReferencesInScene(item)); menu.ShowAsContext(); }
/// <summary> /// Shows the context menu. /// </summary> protected virtual void OnContextMenu() { // Create the menu var menu = new UnityEditor.GenericMenu(); if (m_State != null) { // Set as start state if (m_State.fsm != null && !(m_State is InternalAnyState)) { menu.AddItem(new GUIContent("Set as Start"), false, delegate() { StateUtility.SetAsStart(m_State); this.Refresh(); }); } else { menu.AddDisabledItem(new GUIContent("Set as Start")); } // Set as concurrent state if (m_State.fsm != null && !(m_State is InternalAnyState)) { if (m_IsConcurrent) { menu.AddItem(new GUIContent("Set as Not Concurrent"), false, delegate() { StateUtility.RemoveConcurrentState(m_State.fsm); this.Refresh(); }); } else { menu.AddItem(new GUIContent("Set as Concurrent"), false, delegate() { StateUtility.SetAsConcurrent(m_State); this.Refresh(); }); } } else { menu.AddDisabledItem(new GUIContent("Set as Concurrent")); } // Set as enabled if (m_State.fsm != null /*&& m_State.fsm.enabled*/ && Application.isPlaying && !(m_State is InternalAnyState)) { menu.AddItem(new GUIContent("Set as Enabled"), false, delegate() { m_State.enabled = true; }); } else { menu.AddDisabledItem(new GUIContent("Set as Enabled")); } // Add Transitions // Add none menu.AddItem(new GUIContent("Add Transition/None"), false, delegate() { StateUtility.AddTransition(m_State, 0); CreateTransitionGUIs(); }); // Add blackboard events var blackboard = m_State.blackboard; if (blackboard != null) { foreach (var fsmEvent in blackboard.fsmEvents) { int eventId = fsmEvent.id; menu.AddItem(new GUIContent("Add Transition/" + fsmEvent.name), false, delegate() { StateUtility.AddTransition(m_State, eventId); CreateTransitionGUIs(); }); } } // Add GlobalBlackboard events // This is not The GlobalBlackboard? if (InternalGlobalBlackboard.Instance != null && blackboard != InternalGlobalBlackboard.Instance) { foreach (var globalEvent in InternalGlobalBlackboard.Instance.fsmEvents) { int eventId = globalEvent.id; var eventName = globalEvent.isSystem ? "Add Transition/System/" + globalEvent.name : "Add Transition/Global/" + globalEvent.name; menu.AddItem(new GUIContent(eventName), false, delegate() { StateUtility.AddTransition(m_State, eventId); CreateTransitionGUIs(); }); } } // Separator menu.AddSeparator(""); // Copy menu.AddItem(new GUIContent("Copy State"), false, delegate() { StateUtility.CopySelectedStates(); }); // Paste if (StateUtility.statesToPaste != null && StateUtility.statesToPaste.Length > 0 && m_State.fsm != null) { menu.AddItem(new GUIContent("Paste State"), false, delegate() { StateUtility.PasteStates(m_State.fsm); }); } else { menu.AddDisabledItem(new GUIContent("Paste State")); } // Duplicate if (m_State.fsm != null) { menu.AddItem(new GUIContent("Duplicate State"), false, delegate() { var statesToPaste = new List <InternalStateBehaviour>(BehaviourWindow.activeStates); if (!statesToPaste.Contains(m_State)) { statesToPaste.Add(m_State); } StateUtility.CloneStates(m_State.gameObject, statesToPaste.ToArray(), m_State.fsm); } ); } else { menu.AddDisabledItem(new GUIContent("Duplicate State")); } // Separator menu.AddSeparator(""); // Delete menu.AddItem(new GUIContent("Delete"), false, delegate() { StateUtility.Destroy(m_State); this.Refresh(); }); } else { menu.AddDisabledItem(new GUIContent("Set as Start")); menu.AddDisabledItem(new GUIContent("Set as Enabled")); menu.AddDisabledItem(new GUIContent("Add Transition")); menu.AddSeparator(""); menu.AddDisabledItem(new GUIContent("Copy State")); menu.AddDisabledItem(new GUIContent("Paste State")); menu.AddSeparator(""); menu.AddDisabledItem(new GUIContent("Delete")); } // Show the context menu menu.ShowAsContext(); }
///---------------------------------------------------------------------------------------------- ///Graph events AFTER nodes static void HandlePostNodesGraphEvents(Graph graph, Vector2 canvasMousePos) { //Shortcuts if (GUIUtility.keyboardControl == 0) { //Copy/Cut/Paste if (e.type == EventType.ValidateCommand || e.type == EventType.Used) { if (e.commandName == "Copy" || e.commandName == "Cut") { List <Node> selection = null; if (GraphEditorUtility.activeNode != null) { selection = new List <Node> { GraphEditorUtility.activeNode }; } if (GraphEditorUtility.activeElements != null && GraphEditorUtility.activeElements.Count > 0) { selection = GraphEditorUtility.activeElements.Cast <Node>().ToList(); } if (selection != null) { CopyBuffer.Set <Node[]>(Graph.CloneNodes(selection).ToArray()); if (e.commandName == "Cut") { foreach (Node node in selection) { graph.RemoveNode(node); } } } e.Use(); } if (e.commandName == "Paste") { if (CopyBuffer.Has <Node[]>()) { TryPasteNodesInGraph(graph, CopyBuffer.Get <Node[]>(), canvasMousePos + new Vector2(500, 500) / graph.zoomFactor); } e.Use(); } } if (e.type == EventType.KeyUp) { //Delete if (e.keyCode == KeyCode.Delete || e.keyCode == KeyCode.Backspace) { if (GraphEditorUtility.activeElements != null && GraphEditorUtility.activeElements.Count > 0) { foreach (var obj in GraphEditorUtility.activeElements.ToArray()) { if (obj is Node) { graph.RemoveNode(obj as Node); } if (obj is Connection) { graph.RemoveConnection(obj as Connection); } } GraphEditorUtility.activeElements = null; } if (GraphEditorUtility.activeNode != null) { graph.RemoveNode(GraphEditorUtility.activeNode); GraphEditorUtility.activeElement = null; } if (GraphEditorUtility.activeConnection != null) { graph.RemoveConnection(GraphEditorUtility.activeConnection); GraphEditorUtility.activeElement = null; } e.Use(); } //Duplicate if (e.keyCode == KeyCode.D && e.control && !e.alt) { if (GraphEditorUtility.activeElements != null && GraphEditorUtility.activeElements.Count > 0) { TryPasteNodesInGraph(graph, GraphEditorUtility.activeElements.OfType <Node>().ToArray(), default(Vector2)); } if (GraphEditorUtility.activeNode != null) { GraphEditorUtility.activeElement = GraphEditorUtility.activeNode.Duplicate(graph); } //Connections can't be duplicated by themselves. They do so as part of multiple node duplication. e.Use(); } } } //No panel is obscuring if (GraphEditorUtility.allowClick) { #region 自定义快捷键 if ((currentGraph.GetType() == typeof(FlowGraph) || currentGraph.GetType().IsSubclassOf(typeof(FlowGraph))) && GUIUtility.keyboardControl == 0) { if (e.keyCode == KeyCode.F && e.control && !e.alt) { //Debug.Log("ctrl +f "); FindNode toolNode = currentGraph.GetAllNodesOfType <FindNode>().FirstOrDefault(); if (toolNode != null) { NodeCanvas.Editor.GraphEditorUtility.activeElement = toolNode; } else { FindNode newNode = currentGraph.AddNode <FindNode>(ViewToCanvas(e.mousePosition)); NodeCanvas.Editor.GraphEditorUtility.activeElement = newNode; //Debug.Log("There is no Find Node,Create a new node!"); } //e.Use(); } if (e.keyCode == KeyCode.A && e.control && !e.alt && !e.shift) { NodeCanvas.Editor.GraphEditorUtility.activeElements = null; NodeCanvas.Editor.GraphEditorUtility.activeElement = null; if (currentGraph.allNodes == null) { return; } if (currentGraph.allNodes.Count > 1) { NodeCanvas.Editor.GraphEditorUtility.activeElements = currentGraph.allNodes.Cast <object>().ToList(); //e.Use(); return; } else { NodeCanvas.Editor.GraphEditorUtility.activeElement = currentGraph.allNodes[0]; //e.Use(); } } if (e.keyCode == KeyCode.C && e.type == EventType.KeyUp && !e.control && !e.alt && !e.shift && GUIUtility.keyboardControl == 0) { if (GraphEditorUtility.activeElement != null || GraphEditorUtility.activeElements != null && GraphEditorUtility.activeElements.Count > 0) { List <Node> node = new List <Node>(); if (GraphEditorUtility.activeElement != null) { node.Add((Node)GraphEditorUtility.activeElement); } else { node = GraphEditorUtility.activeElements.Cast <Node>().ToList(); } Undo.RegisterCompleteObjectUndo(currentGraph, "Create Group"); if (currentGraph.canvasGroups == null) { currentGraph.canvasGroups = new List <Framework.CanvasGroup>(); } Framework.CanvasGroup group = new Framework.CanvasGroup(GetNodeBounds(node).ExpandBy(100f), "New Canvas Group"); currentGraph.canvasGroups.Add(group); group.isRenaming = true; } } if (e.keyCode == KeyCode.G && !e.control && !e.alt && e.shift && GUIUtility.keyboardControl == 0) { if (NodeCanvas.Editor.GraphEditorUtility.activeElements == null || NodeCanvas.Editor.GraphEditorUtility.activeElements.Count < 2 && NodeCanvas.Editor.GraphEditorUtility.activeElement != null && NodeCanvas.Editor.GraphEditorUtility.activeElement.GetType() == typeof(MacroNodeWrapper)) { //Debug.Log("current select is group node"); MacroNodeWrapper n = (MacroNodeWrapper)NodeCanvas.Editor.GraphEditorUtility.activeElement; if (n.macro.allNodes.Count <= 2) { return; } List <Node> childNode = new List <Node>(); foreach (var c in n.macro.allNodes) { if (c.GetType() != typeof(MacroInputNode) && c.GetType() != typeof(MacroOutputNode)) { childNode.Add(c); } } var newNodes = Graph.CopyNodesToGraph(childNode, currentGraph); currentGraph.RemoveNode(n); NodeCanvas.Editor.GraphEditorUtility.activeElement = null; if (NodeCanvas.Editor.GraphEditorUtility.activeElements != null) { NodeCanvas.Editor.GraphEditorUtility.activeElements = newNodes.Cast <object>().ToList(); } } } if (e.keyCode == KeyCode.G && e.control && !e.alt && !e.shift && GUIUtility.keyboardControl == 0) { //Debug.Log("ctrl +g "); if (NodeCanvas.Editor.GraphEditorUtility.activeElements == null || NodeCanvas.Editor.GraphEditorUtility.activeElements.Count < 1) { //e.Use(); return; } List <Node> ns = NodeCanvas.Editor.GraphEditorUtility.activeElements.Cast <Node>().ToList(); Rect groupNodeRect = GetNodeBounds(ns, viewRect, false); var wrapper = currentGraph.AddNode <MacroNodeWrapper>(groupNodeRect.center); wrapper.macro = NestedUtility.CreateBoundNested <GroupMacro>(wrapper, currentGraph); wrapper.macro.name = "NewGroup"; wrapper.macro.CategoryPath = (currentGraph.agent != null ? currentGraph.agent.name : currentGraph.name) + "/"; wrapper.macro.agent = currentGraph.agent; wrapper.macro.entry.position = new Vector2(groupNodeRect.x - 200f, groupNodeRect.y + 0.5f * groupNodeRect.height); wrapper.macro.exit.position = new Vector2(groupNodeRect.x + groupNodeRect.width + 100f, groupNodeRect.y + 0.5f * groupNodeRect.height); wrapper.macro.translation = -groupNodeRect.center + new Vector2(500f, 500f); Graph.CopyNodesToGraph(NodeCanvas.Editor.GraphEditorUtility.activeElements.OfType <Node>().ToList(), wrapper.macro); foreach (var c in ns) { currentGraph.RemoveNode(c); } NodeCanvas.Editor.GraphEditorUtility.activeElements.Clear(); NodeCanvas.Editor.GraphEditorUtility.activeElement = wrapper; } if (e.type == EventType.KeyDown && e.keyCode == KeyCode.I && GUIUtility.keyboardControl == 0) { List <Node> allNodes = currentGraph.GetAllNodesOfType <Node>(); if (allNodes != null && allNodes.Count < 2) { return; } if (NodeCanvas.Editor.GraphEditorUtility.activeElement != null) { if (allNodes.Contains((Node)NodeCanvas.Editor.GraphEditorUtility.activeElement)) { allNodes.Remove((Node)NodeCanvas.Editor.GraphEditorUtility.activeElement); NodeCanvas.Editor.GraphEditorUtility.activeElement = null; NodeCanvas.Editor.GraphEditorUtility.activeElements.Clear(); NodeCanvas.Editor.GraphEditorUtility.activeElements = allNodes.Cast <object>().ToList(); } return; } if (NodeCanvas.Editor.GraphEditorUtility.activeElements != null && NodeCanvas.Editor.GraphEditorUtility.activeElements.Count > 1) { List <object> invertNodeList = NodeCanvas.Editor.GraphEditorUtility.activeElements; invertNodeList.ForEach(x => { if (allNodes.Contains((Node)x)) { allNodes.Remove((Node)x); } }); NodeCanvas.Editor.GraphEditorUtility.activeElements.Clear(); if (allNodes.Count == 0) { NodeCanvas.Editor.GraphEditorUtility.activeElement = null; } else if (allNodes.Count == 1) { NodeCanvas.Editor.GraphEditorUtility.activeElement = allNodes[0]; } else { NodeCanvas.Editor.GraphEditorUtility.activeElements = allNodes.Cast <object>().ToList(); } return; } e.Use(); } if (e.type == EventType.KeyUp && e.alt && e.control) { //Type genericType; UnityEditor.GenericMenu.MenuFunction2 S = (obj) => { NodeCanvas.Editor.GraphEditorUtility.activeElement = GraphEditor.currentGraph.AddNode(obj.GetType(), ViewToCanvas(e.mousePosition)); }; UnityEditor.GenericMenu.MenuFunction2 D = (obj) => { var genericT = typeof(SimplexNodeWrapper <>).MakeGenericType(obj.GetType()); NodeCanvas.Editor.GraphEditorUtility.activeElement = GraphEditor.currentGraph.AddNode(genericT, ViewToCanvas(e.mousePosition)); }; if (e.keyCode == KeyCode.S) { var menu = new UnityEditor.GenericMenu(); menu.AddItem(new GUIContent("Split"), false, S, new Split()); menu.AddItem(new GUIContent("Sequence"), false, S, new Sequence()); menu.AddSeparator(""); menu.AddItem(new GUIContent("SetActive"), false, D, new S_Active()); menu.AddSeparator(""); menu.AddItem(new GUIContent("SendEvent"), false, D, new SendEvent()); menu.AddItem(new GUIContent("SendEvent<T>"), false, D, new SendEvent <object>()); menu.AddSeparator(""); menu.AddItem(new GUIContent("Self"), false, S, new OwnerVariable()); menu.AddSeparator(""); menu.AddItem(new GUIContent("SwitchByIndex"), false, S, new Switch <object>()); menu.AddItem(new GUIContent("Switch Value"), false, D, new SwitchValue <object>()); menu.AddSeparator(""); menu.AddItem(new GUIContent("SwitchFlow/Switch Bool"), false, S, new SwitchBool()); menu.AddItem(new GUIContent("SwitchFlow/Switch String"), false, S, new SwitchString()); menu.AddItem(new GUIContent("SwitchFlow/Switch Int"), false, S, new SwitchInt()); menu.AddItem(new GUIContent("SwitchFlow/Switch Enum"), false, S, new SwitchEnum()); menu.AddItem(new GUIContent("SwitchFlow/Switch Tag"), false, S, new SwitchTag()); menu.AddItem(new GUIContent("SwitchFlow/Switch Comparison"), false, S, new SwitchComparison()); menu.ShowAsContext(); //e.Use(); return; } if (e.keyCode == KeyCode.A) { var menu = new UnityEditor.GenericMenu(); menu.AddItem(new GUIContent("Awake"), false, S, new ConstructionEvent()); menu.AddItem(new GUIContent("OnEnable"), false, S, new EnableEvent()); menu.AddItem(new GUIContent("Start"), false, S, new StartEvent()); menu.AddSeparator(""); menu.AddItem(new GUIContent("Update"), false, S, new UpdateEvent()); menu.AddItem(new GUIContent("FixedUpdate"), false, S, new FixedUpdateEvent()); menu.AddItem(new GUIContent("LateUpdate"), false, S, new LateUpdateEvent()); menu.AddSeparator(""); menu.AddItem(new GUIContent("OnDisable"), false, S, new DisableEvent()); menu.ShowAsContext(); return; } if (e.keyCode == KeyCode.C) { var menu = new UnityEditor.GenericMenu(); menu.AddItem(new GUIContent("Cache"), false, D, new Cache <object>()); menu.AddSeparator(""); menu.AddItem(new GUIContent("Coroutine"), false, S, new CoroutineState()); menu.AddItem(new GUIContent("Cooldown"), false, S, new Cooldown()); menu.AddItem(new GUIContent("Chance"), false, S, new Chance()); menu.AddSeparator(""); menu.AddItem(new GUIContent("CustomEvent"), false, S, new CustomEvent()); menu.AddItem(new GUIContent("CustomEvent<T>"), false, S, new CustomEvent <object>()); menu.ShowAsContext(); return; } if (e.keyCode == KeyCode.E) { var menu = new UnityEditor.GenericMenu(); menu.AddItem(new GUIContent("KeyBoard"), false, S, new KeyboardEvents()); menu.AddItem(new GUIContent("UnityEventAutoCallbackEvent"), false, S, new UnityEventAutoCallbackEvent()); menu.AddItem(new GUIContent("CSharpAutoCallbackEvent"), false, S, new CSharpAutoCallbackEvent()); menu.AddItem(new GUIContent("DelegateCallbackEvent"), false, S, new DelegateCallbackEvent()); menu.AddSeparator(""); menu.AddItem(new GUIContent("UnityEventCallbackEvent"), false, S, new UnityEventCallbackEvent()); menu.AddItem(new GUIContent("CSharpEventCallback"), false, S, new CSharpEventCallback()); menu.ShowAsContext(); return; } if (e.keyCode == KeyCode.D) { var menu = new UnityEditor.GenericMenu(); menu.AddItem(new GUIContent("Debug log OnScreen"), false, S, new G_LogOnScreen()); menu.AddItem(new GUIContent("Debug log"), false, D, new LogText()); menu.AddItem(new GUIContent("Debug Event"), false, D, new DebugEvent()); menu.AddSeparator(""); menu.AddItem(new GUIContent("DummyFlow"), false, S, new Dummy()); menu.AddItem(new GUIContent("DummyValue"), false, D, new Identity <object>()); menu.AddItem(new GUIContent("DoOnce"), false, S, new DoOnce()); menu.ShowAsContext(); e.Use(); } if (e.keyCode == KeyCode.R) { var menu = new UnityEditor.GenericMenu(); menu.AddItem(new GUIContent("RelayFlowInput"), false, S, new RelayFlowInput()); menu.AddItem(new GUIContent("RelayFlowOutput"), false, S, new RelayFlowOutput()); menu.AddSeparator(""); menu.AddItem(new GUIContent("RelayValueInput"), false, S, new RelayValueInput <object>()); menu.AddItem(new GUIContent("RelayValueOutput"), false, S, new RelayValueOutput <object>()); menu.ShowAsContext(); e.Use(); } if (e.keyCode == KeyCode.W) { var menu = new UnityEditor.GenericMenu(); menu.AddItem(new GUIContent("Wait"), false, D, new Wait()); menu.AddItem(new GUIContent("While"), false, S, new While()); menu.AddSeparator(""); menu.AddItem(new GUIContent("WaitForOneFrame"), false, D, new WaitForOneFrame()); menu.AddItem(new GUIContent("WaitForEndOfFrame"), false, D, new FlowCanvas.Nodes.WaitForEndOfFrame()); menu.AddItem(new GUIContent("WaitForFixedUpdate"), false, D, new WaitForFixedUpdate()); menu.AddItem(new GUIContent("WaitForPhysicsFrame"), false, D, new WaitForPhysicsFrame()); menu.ShowAsContext(); e.Use(); } if (e.keyCode == KeyCode.F) { Selection.activeGameObject = null; //防止快捷键冲突 var menu = new UnityEditor.GenericMenu(); menu.AddItem(new GUIContent("Find"), false, D, new G_FindGameObject()); menu.AddItem(new GUIContent("FindChild"), false, D, new G_FindChild()); menu.AddItem(new GUIContent("FindGameObjectWithTag"), false, D, new G_FindGameObjectWithTag()); menu.AddItem(new GUIContent("FindGameObjectsWithTag"), false, D, new G_FindGameObjectsWithTag()); menu.AddItem(new GUIContent("FindObjectOfType"), false, D, new FindObjectOfType()); menu.AddItem(new GUIContent("FindObjectsOfType"), false, D, new FindObjectsOfType()); menu.AddSeparator(""); menu.AddItem(new GUIContent("Finish"), false, S, new Finish()); menu.AddItem(new GUIContent("CustomFunction"), false, S, new CustomFunctionEvent()); menu.AddItem(new GUIContent("CallCustomFunction"), false, S, new CustomFunctionCall()); menu.AddItem(new GUIContent("CallCustomFunction(CustomPort)"), false, S, new FunctionCall()); menu.AddItem(new GUIContent("FunctionCustomReturn"), false, S, new Return()); menu.AddSeparator(""); menu.AddItem(new GUIContent("ForLoop"), false, S, new ForLoop()); menu.AddItem(new GUIContent("ForEach"), false, S, new ForEach <float>()); menu.AddItem(new GUIContent("FlipFlop"), false, S, new FlipFlop()); menu.ShowAsContext(); e.Use(); } if (e.keyCode == KeyCode.G) { var menu = new UnityEditor.GenericMenu(); menu.AddItem(new GUIContent("GetName"), false, D, new G_Name()); menu.AddItem(new GUIContent("GetAcive"), false, D, new G_Active()); menu.AddItem(new GUIContent("GetPosition"), false, D, new G_Position()); menu.AddSeparator(""); menu.AddItem(new GUIContent("GetChildByIndex"), false, D, new G_Child()); menu.AddItem(new GUIContent("GetChildCount"), false, D, new G_ChildCount()); menu.AddSeparator(""); menu.AddItem(new GUIContent("GetComponentByType"), false, D, new G_Component()); menu.AddItem(new GUIContent("GetComponentsByType"), false, D, new G_Components()); menu.AddItem(new GUIContent("GetComponentByName"), false, D, new G_ComponentByTypeName()); menu.AddItem(new GUIContent("GetComponentsInChildren"), false, D, new G_ComponentsInChildren()); menu.AddItem(new GUIContent("GetComponentInChildren"), false, D, new G_ComponentInChildren()); menu.AddItem(new GUIContent("GetComponentInParent"), false, D, new G_ComponentInParent()); menu.ShowAsContext(); e.Use(); } } if (e.type == EventType.KeyUp && e.alt) { Type genericType; switch (e.keyCode) { case KeyCode.Alpha1: genericType = typeof(GetVariable <>).MakeGenericType(typeof(float)); break; case KeyCode.Alpha2: genericType = typeof(GetVariable <>).MakeGenericType(typeof(Vector2)); break; case KeyCode.Alpha3: genericType = typeof(GetVariable <>).MakeGenericType(typeof(Vector3)); break; case KeyCode.Alpha4: genericType = typeof(GetVariable <>).MakeGenericType(typeof(Quaternion)); break; case KeyCode.Alpha5: genericType = typeof(GetVariable <>).MakeGenericType(typeof(Color)); break; default: //genericType = typeof(GetVariable<>).MakeGenericType(typeof(float)); return; //break; } var varN = (FlowNode)GraphEditor.currentGraph.AddNode(genericType); varN.position = ViewToCanvas(e.mousePosition - varN.rect.center * 0.5f); NodeCanvas.Editor.GraphEditorUtility.activeElement = varN; e.Use(); } } if (e.type == EventType.KeyDown && e.keyCode == KeyCode.F && GUIUtility.keyboardControl == 0) { FocusSelection(); } #endregion //'Tilt' or 'Space' keys, opens up the complete context menu browser if (e.type == EventType.KeyDown && !e.shift && (e.keyCode == KeyCode.BackQuote || e.keyCode == KeyCode.Space)) { GenericMenuBrowser.Show(GetAddNodeMenu(graph, canvasMousePos), e.mousePosition, string.Format("Add {0} Node", graph.GetType().FriendlyName()), graph.baseNodeType); e.Use(); } //Right click canvas context menu. Basicaly for adding new nodes. if (e.type == EventType.ContextClick) { var menu = GetAddNodeMenu(graph, canvasMousePos); if (CopyBuffer.Has <Node[]>() && CopyBuffer.Peek <Node[]>()[0].GetType().IsSubclassOf(graph.baseNodeType)) { menu.AddSeparator("/"); var copiedNodes = CopyBuffer.Get <Node[]>(); if (copiedNodes.Length == 1) { menu.AddItem(new GUIContent(string.Format("Paste Node ({0})", copiedNodes[0].GetType().FriendlyName())), false, () => { TryPasteNodesInGraph(graph, copiedNodes, canvasMousePos); }); } else if (copiedNodes.Length > 1) { menu.AddItem(new GUIContent(string.Format("Paste Nodes ({0})", copiedNodes.Length.ToString())), false, () => { TryPasteNodesInGraph(graph, copiedNodes, canvasMousePos); }); } } if (NCPrefs.useBrowser) { menu.ShowAsBrowser(e.mousePosition, string.Format("Add {0} Node", graph.GetType().FriendlyName()), graph.baseNodeType); } else { menu.ShowAsContext(); } e.Use(); } } }
public static void OnGui(MapEditor wind) { m_deletegroup.Clear(); LevelMapData data = wind.Level_Data; m_scroll = GUILayout.BeginScrollView(m_scroll); GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); GUILayout.Label(data.Name, GUILayout.Width(200)); GUILayout.Label("关卡数:" + data.Configs.Count, GUILayout.Width(300)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); bool isadd = false; if (isaddmode) { string temp = "0"; isadd = GUILayout.Button("确认"); GUILayout.Label("关卡ID", GUILayout.Width(50)); temp = GUILayout.TextField(id.ToString()); id = uint.Parse(temp); if (GUILayout.Button("取消")) { isaddmode = false; } } else { isaddmode = GUILayout.Button("添加关卡", GUILayout.Width(75)); GUILayout.Label("筛选关卡:", GUILayout.Width(50)); if (GUILayout.Button("清空", GUILayout.Width(40))) { wind.selectedLevel = string.Empty; } wind.selectedLevel = GUILayout.TextField(wind.selectedLevel, GUILayout.Width(50)); GUILayout.Space(10); if (GUILayout.Button("关卡类型", MapEditor.toolbarDropdown, GUILayout.Width(75))) { GenericMenu menu = new UnityEditor.GenericMenu(); //menu.AddSeparator(""); menu.AddItem(new GUIContent("全部"), false, () => { wind.selectedLevel_Type = 0; }); menu.AddItem(new GUIContent("冒险关卡"), false, () => { wind.selectedLevel_Type = 1; }); menu.AddItem(new GUIContent("签到关卡"), false, () => { wind.selectedLevel_Type = 2; }); //menu.DropDown(new Rect(0, 0, 20, 30)); menu.ShowAsContext(); } } if (isadd) { AddConfig(wind, id); isaddmode = false; } if (GUILayout.Button("编辑工具格子", GUILayout.Width(150))) { wind.Pagetype = MapEditor.PageType.EditorSub; } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("地图ID", GUILayout.Width(200)); GUILayout.Label("对应的关卡ID", GUILayout.Width(250)); GUILayout.Label("规格:", GUILayout.Width(200)); GUILayout.EndHorizontal(); foreach (var k in data.Configs) { ConfigItem.OnGui(k, wind); } GUILayout.EndVertical(); GUILayout.EndScrollView(); if (m_deletegroup.Count > 0) { wind.Level_Data.DeleteConfig(m_deletegroup); } }
public override void Draw() { float width = UnityEditor.EditorGUIUtility.labelWidth; using (new GUILayout.HorizontalScope()) { GUILayout.Label("Search Name", GUILayout.Width(width)); search = GUILayout.TextField(search); } using (new GUILayout.HorizontalScope()) { GUILayout.Label("Filter", GUILayout.Width(width)); if (GUILayout.Button(filter == null ? "No Filter" : filter.Name, UnityEditor.EditorStyles.toolbarDropDown)) { var menu = new UnityEditor.GenericMenu(); var items = new List <Type>(AllGroups.Keys); items.Remove(typeof(GameSystem)); items.Sort((x, y) => y.Name.CompareTo(x.Name)); items.Add(typeof(GameSystem)); for (int i = items.Count - 1; i >= 0; --i) { var item = items[i]; menu.AddItem(new GUIContent(item.Name), filter == item, () => filter = item); } menu.ShowAsContext(); } } if (AllGroups.TryGetValue(filter, out var group)) { using (new GUILayout.VerticalScope(UnityEditor.EditorStyles.helpBox)) { using (new GUILayout.HorizontalScope()) { GUILayout.Label("Priority", UnityEditor.EditorStyles.boldLabel, GUILayout.Width(64f)); GUILayout.Label("Game System", UnityEditor.EditorStyles.boldLabel); } foreach (var item in group.List) { if (item.GetType().Name.IndexOf(search, StringComparison.OrdinalIgnoreCase) >= 0) { using (new GUILayout.HorizontalScope()) { GUILayout.Label(((int)item.GetType().GetCustomAttribute <Priority>()).ToString(), GUILayout.Width(64f)); using (new GUILayout.VerticalScope()) { if (GUILayout.Button(item.GetType().Name, UnityEditor.EditorStyles.label)) { if (item is IOnInspect inspectable) { if (inspected.Contains(inspectable)) { inspected.Remove(inspectable); } else { inspected.Add(inspectable); } } } if (inspected.Contains(item as IOnInspect)) { using (new GUILayout.VerticalScope(UnityEditor.EditorStyles.helpBox)) { (item as IOnInspect).OnInspect(); } } } } } } } } }
private void DrawToolbarGUI() { EditorGUILayout.BeginHorizontal("Toolbar"); GUI.backgroundColor = new Color(1f, 1f, 1f, 0.5f); if (GUILayout.Button("File", EditorStyles.toolbarDropDown, GUILayout.Width(50))) { GenericMenu menu = new GenericMenu(); // Canvas creation foreach (System.Collections.Generic.KeyValuePair <Type, NodeCanvasTypeData> data in NodeCanvasManager.CanvasTypes) { menu.AddItem(new GUIContent("New Canvas/" + data.Value.DisplayString), false, CreateCanvasCallback, data.Key); } // menu.AddItem(new GUIContent("New Standard Canvas"), false, CreateCanvasCallback, null); menu.AddSeparator(""); // Scene Saving menu.AddItem(new GUIContent("Load Canvas", "Loads an asset canvas"), false, LoadCanvas); menu.AddItem(new GUIContent("Reload Canvas", "Restores the current canvas to when it has been last saved."), false, ReloadCanvas); menu.AddSeparator(""); menu.AddItem(new GUIContent("Save Canvas"), false, SaveCanvas); menu.AddItem(new GUIContent("Save Canvas As"), false, SaveCanvasAs); menu.AddSeparator(""); // Scene Saving foreach (string sceneSave in NodeEditorSaveManager.GetSceneSaves()) { if (sceneSave.ToLower() != "lastsession") { menu.AddItem(new GUIContent("Load Canvas from Scene/" + sceneSave), false, LoadSceneCanvasCallback, sceneSave); } } menu.AddItem(new GUIContent("Save Canvas to Scene"), false, () => showModalPanel = true); menu.DropDown(new Rect(5, toolbarHeight, 0, 0)); } if (GUILayout.Button("Debug", EditorStyles.toolbarDropDown, GUILayout.Width(50))) { GenericMenu menu = new GenericMenu(); // Toggles side panel menu.AddItem(new GUIContent("Sidebar"), showSideWindow, () => showSideWindow = !showSideWindow); menu.DropDown(new Rect(55, toolbarHeight, 0, 0)); } GUILayout.Space(10); GUILayout.FlexibleSpace(); GUILayout.Label(new GUIContent("" + canvasCache.nodeCanvas.saveName + " (" + (canvasCache.nodeCanvas.livesInScene? "Scene Save" : "Asset Save") + ")", "Opened Canvas path: " + canvasCache.nodeCanvas.savePath), "ToolbarButton"); GUILayout.Label("Type: " + canvasCache.typeData.DisplayString /*+ "/" + canvasCache.nodeCanvas.GetType ().Name*/, "ToolbarButton"); GUI.backgroundColor = new Color(1, 0.3f, 0.3f, 1); if (GUILayout.Button("Force Re-init", EditorStyles.toolbarButton, GUILayout.Width(80))) { NodeEditor.ReInit(true); } GUI.backgroundColor = Color.white; EditorGUILayout.EndHorizontal(); }
/// <summary> /// Provides input handling for the panel /// </summary> public override void ProcessInput() { Event lCurrentEvent = Event.current; EventType lCurrentEventType = lCurrentEvent.type; Node lClickedNode = null; NodeLink lClickedLink = null; switch (lCurrentEventType) { // Handles keypresses case EventType.KeyUp: switch (lCurrentEvent.keyCode) { case KeyCode.Delete: if (GUIUtility.keyboardControl == 0) { if (mSelectedNode != null) { RemoveNode(mSelectedNode); } if (mSelectedLink != null) { RemoveLink(mSelectedLink); } Editor.Repaint(); } break; } break; // Handles the mouse down event case EventType.MouseDown: for (int i = 0; i < Nodes.Count; i++) { if (Nodes[i].ContainsPoint(lCurrentEvent.mousePosition)) { lClickedLink = null; lClickedNode = Nodes[i]; } if (lClickedNode == null) { for (int j = 0; j < Nodes[i].Links.Count; j++) { if (Nodes[i].Links[j].ContainsPoint(lCurrentEvent.mousePosition)) { lClickedLink = Nodes[i].Links[j]; break; } } } if (lClickedNode != null || lClickedLink != null) { break; } } mIsPanning = false; // With left mouse button, select if (lCurrentEvent.button == 0) { if (mIsLinking && mActiveLink != null) { if (lClickedNode != null && lClickedNode != mActiveLink.StartNode) { mActiveLink.EndNode = lClickedNode; AddLink(mActiveLink); } mActiveLink = null; mActiveNode = null; mSelectedNode = null; } else { if (lClickedNode != null) { GUIUtility.keyboardControl = 0; } if (lClickedNode != mSelectedNode && NodeSelectedEvent != null) { NodeSelectedEvent(lClickedNode); } if (lClickedLink != null) { GUIUtility.keyboardControl = 0; } if (lClickedLink != mSelectedLink && LinkSelectedEvent != null) { LinkSelectedEvent(lClickedLink); } mActiveNode = lClickedNode; mSelectedNode = lClickedNode; mActiveLink = lClickedLink; mSelectedLink = lClickedLink; if (lClickedNode != null) { mDragStart = lCurrentEvent.mousePosition; mDragOffset = Vector2.zero; } } mIsLinking = false; Editor.Repaint(); } // With right mouse button, show the menu else if (lCurrentEvent.button == 1) { mActiveNode = lClickedNode; mActiveLink = lClickedLink; if (mActiveNode != null) { GenericMenu lMenu = new UnityEditor.GenericMenu(); lMenu.AddItem(new GUIContent("Add Link"), false, OnStartAddLink, mActiveNode); lMenu.AddSeparator(""); lMenu.AddItem(new GUIContent("Delete Node"), false, OnRemoveNode, mActiveNode); lMenu.ShowAsContext(); lCurrentEvent.Use(); } else if (mActiveLink != null) { GenericMenu lMenu = new UnityEditor.GenericMenu(); lMenu.AddItem(new GUIContent("Delete Link"), false, OnRemoveLink, mActiveLink); lMenu.ShowAsContext(); lCurrentEvent.Use(); } else { GenericMenu lMenu = new UnityEditor.GenericMenu(); lMenu.AddItem(new GUIContent("Add Node"), false, OnAddNode, typeof(Node)); lMenu.ShowAsContext(); lCurrentEvent.Use(); } } // With right mouse buttion, drag the canvas else if (lCurrentEvent.button == 2) { mIsPanning = true; mDragStart = lCurrentEvent.mousePosition; mDragOffset = Vector2.zero; } break; // Handles the mouse drag event case EventType.MouseDrag: // Pan the canvas as needed if (mIsPanning) { Vector2 lDragOffset = mDragOffset; mDragOffset = lCurrentEvent.mousePosition - mDragStart; Vector2 lOffset = (mDragOffset - lDragOffset) * mZoom; mPanOffset = mPanOffset + lOffset; Editor.Repaint(); } // Move the active node as needed else if (mActiveNode != null) { Vector2 lDragOffset = mDragOffset; mDragOffset = lCurrentEvent.mousePosition - mDragStart; Vector2 lOffset = (mDragOffset - lDragOffset) * mZoom; mActiveNode.Position.x = mActiveNode.Position.x + lOffset.x; mActiveNode.Position.y = mActiveNode.Position.y + lOffset.y; Editor.Repaint(); } break; // Handles the mouse up event case EventType.MouseUp: if (mActiveNode != null) { if (mDragOffset.sqrMagnitude > 0f) { mDragOffset = Vector2.zero; // Reorder the links left to right for (int i = 0; i < Nodes.Count; i++) { bool lReorder = false; for (int j = 0; j < Nodes[i].Links.Count; j++) { if (Nodes[i].Links[j].EndNode == mActiveNode) { lReorder = true; break; } } if (lReorder) { Nodes[i].Links = Nodes[i].Links.OrderBy(x => x.EndNode.Position.x).ToList <NodeLink>(); } } // Flag the canvas as dirty EditorUtility.SetDirty(mActiveNode); SetDirty(); } } // Ensure we don't pan or move a node mIsPanning = false; mActiveNode = null; break; } }
void DoTrackContextMenu(Event e, Rect clipsPosRect, float cursorTime, System.Action action, System.Action <Track> onDragUpdated, System.Action <Track, float> onDragPerform) { if (e.type == EventType.ContextClick && clipsPosRect.Contains(e.mousePosition)) { var attachableTypeInfos = new List <EditorTools.TypeMetaInfo>(); foreach (var info in EditorTools.GetTypeMetaDerivedFrom(typeof(Clip), Prefs.isOld)) { if (info.attachableTypes != null && !info.attachableTypes.Contains(this.GetType())) { continue; } if (info.type != typeof(Clip)) { attachableTypeInfos.Add(info); } } var menu = new UnityEditor.GenericMenu(); if (attachableTypeInfos.Count > 0) { foreach (var _info in attachableTypeInfos) { var info = _info; var tName = info.name; menu.AddItem(new GUIContent(tName), false, () => { var clip = ReflectionTools.CreateInstance(_info.type) as Clip; clip.startTime = cursorTime; AddNode(clip); CutsceneUtility.selectedObject = clip; if (action != null) { action(); } }); } e.Use(); } if (CutsceneUtility.CanPastClip(attachableTypeInfos)) { menu.AddItem(new GUIContent("粘贴"), false, () => { CutsceneUtility.PasteClip(this, cursorTime); }); } if (menu.GetItemCount() > 0) { menu.ShowAsContext(); } else { menu = null; } } if (clipsPosRect.Contains(e.mousePosition) && e.type == EventType.DragUpdated) { if (onDragUpdated != null) { onDragUpdated(this); } } if (clipsPosRect.Contains(e.mousePosition) && e.type == EventType.DragPerform) { if (onDragPerform != null) { onDragPerform(this, cursorTime); } //for (int i = 0; i < DragAndDrop.objectReferences.Length; i++) //{ // var o = DragAndDrop.objectReferences[i]; // if (o is AnimationClip && this is SkillAnimationTrack) // { // var aniClip = new SKillAnimationEvent(); // AddNode(aniClip); // aniClip.startTime = cursorTime; // aniClip.length = (o as AnimationClip).length; // aniClip.animationClip = o as AnimationClip; // if (action != null) action(); // CutsceneUtility.selectedObject = aniClip; // } //} SortClips(); } }
void OnGUI() { EditorGUILayout.HelpBox("Here you can specify frequently used types for your game for easier access wherever you need to select a type\nFor example when setting the type of an Object variable as well as when setting the agent type in any 'Script Control' Task", MessageType.Info); if (GUILayout.Button("Add New Type")) { GenericMenu.MenuFunction2 Selected = delegate(object t){ if (!typeList.Contains((System.Type)t)) { typeList.Add((System.Type)t); Save(); } else { ShowNotification(new GUIContent("Type already in list")); } }; var menu = new UnityEditor.GenericMenu(); foreach (var t in EditorUtils.GetAssemblyTypes(typeof(object))) { var friendlyName = (string.IsNullOrEmpty(t.Namespace)? "No Namespace/" : t.Namespace.Replace(".", "/") + "/") + t.FriendlyName(); var category = "Classes/"; if (t.IsInterface) { category = "Interfaces/"; } if (t.IsEnum) { category = "Enumerations/"; } menu.AddItem(new GUIContent(category + friendlyName), false, Selected, t); } menu.ShowAsContext(); Event.current.Use(); } if (GUILayout.Button("RESET DEFAULTS")) { UserTypePrefs.ResetTypeConfiguration(); typeList = UserTypePrefs.GetPreferedTypesList(typeof(object)); Save(); } scrollPos = GUILayout.BeginScrollView(scrollPos); EditorUtils.ReorderableList(typeList, delegate(int i){ GUILayout.BeginHorizontal("box"); EditorGUILayout.LabelField(typeList[i].Name, typeList[i].Namespace); if (GUILayout.Button("X", GUILayout.Width(18))) { typeList.RemoveAt(i); Save(); } GUILayout.EndHorizontal(); }); GUILayout.EndScrollView(); Repaint(); }
public virtual void AddItemsToMenu(GenericMenu menu) { menu.AddItem(EditorGUIUtility.TrTextContent("Reload"), false, Reload); }
void OnGUI() { EditorGUILayout.HelpBox("Here you can specify frequently used types for your game for easier access wherever you need to select a type, like for example when you create a new blackboard variable or using any refelection based actions. Furthermore, it is essential when working with AOT platforms like iOS or WebGL, that you generate an AOT Classes and link.xml files with the relevant button bellow.\nTo add types in the list quicker, you can also Drag&Drop an object, or a Script file in this editor window, or seach it bellow.", MessageType.Info); GUILayout.BeginHorizontal(); search = EditorGUILayout.TextField(search, (GUIStyle)"ToolbarSeachTextField"); if (GUILayout.Button("", (GUIStyle)"ToolbarSeachCancelButton")) { search = null; GUIUtility.keyboardControl = 0; } GUILayout.EndHorizontal(); if (search != null && search.Length > 2) { GUILayout.Label(string.Format("<b>{0}</b>", "Showing Search Results. Click the plus button to add the type.")); GUILayout.Space(5); scrollPos = GUILayout.BeginScrollView(scrollPos); foreach (var type in EditorUtils.GetAssemblyTypes(typeof(object))) { if (type.Name.ToUpper().Contains(search.ToUpper())) { GUILayout.BeginHorizontal("box"); if (GUILayout.Button("+", GUILayout.Width(20))) { AddType(type); } EditorGUILayout.LabelField(type.Name, type.Namespace); GUILayout.EndHorizontal(); } } GUILayout.EndScrollView(); return; } if (GUILayout.Button("Add New Type")) { GenericMenu.MenuFunction2 Selected = delegate(object o){ if (o is System.Type) { AddType((System.Type)o); } if (o is string) //namespace { foreach (var type in EditorUtils.GetAssemblyTypes(typeof(object))) { if (type.Namespace == (string)o) { AddType(type); } } } }; var menu = new UnityEditor.GenericMenu(); menu.AddItem(new GUIContent("Classes/System/Object"), false, Selected, typeof(object)); foreach (var t in EditorUtils.GetAssemblyTypes(typeof(object))) { var friendlyName = (string.IsNullOrEmpty(t.Namespace)? "No Namespace/" : t.Namespace.Replace(".", "/") + "/") + t.FriendlyName(); var category = "Classes/"; if (t.IsInterface) { category = "Interfaces/"; } if (t.IsEnum) { category = "Enumerations/"; } menu.AddItem(new GUIContent(category + friendlyName), false, Selected, t); if (t.Namespace != null) { var ns = t.Namespace.Replace(".", "/"); menu.AddItem(new GUIContent("Namespaces/" + ns), false, Selected, t.Namespace); } } menu.ShowAsContext(); Event.current.Use(); } #if !UNITY_WEBPLAYER if (GUILayout.Button("Generate AOTClasses.cs and link.xml Files")) { if (EditorUtility.DisplayDialog("Generate AOT Classes", "A script relevant to AOT compatibility for certain platforms will now be generated.", "OK")) { var path = EditorUtility.SaveFilePanelInProject("AOT Classes File", "AOTClasses", "cs", ""); if (!string.IsNullOrEmpty(path)) { AOTClassesGenerator.GenerateAOTClasses(path); } } if (EditorUtility.DisplayDialog("Generate link.xml File", "A file relevant to 'code stripping' for platforms that have code stripping enabled will now be generated.", "OK")) { var path = EditorUtility.SaveFilePanelInProject("AOT link.xml", "link", "xml", ""); if (!string.IsNullOrEmpty(path)) { AOTClassesGenerator.GenerateLinkXML(path); } } AssetDatabase.Refresh(); } GUILayout.BeginHorizontal(); if (GUILayout.Button("RESET DEFAULTS")) { if (EditorUtility.DisplayDialog("Reset Preferred Types", "Are you sure?", "Yes", "NO!")) { UserTypePrefs.ResetTypeConfiguration(); typeList = UserTypePrefs.GetPreferedTypesList(typeof(object)); Save(); } } if (GUILayout.Button("Save Preset")) { var path = EditorUtility.SaveFilePanelInProject("Save Types Preset", "", "typePrefs", ""); if (!string.IsNullOrEmpty(path)) { System.IO.File.WriteAllText(path, JSONSerializer.Serialize(typeof(List <System.Type>), typeList, true)); AssetDatabase.Refresh(); } } if (GUILayout.Button("Load Preset")) { var path = EditorUtility.OpenFilePanel("Load Types Preset", "Assets", "typePrefs"); if (!string.IsNullOrEmpty(path)) { var json = System.IO.File.ReadAllText(path); typeList = JSONSerializer.Deserialize <List <System.Type> >(json); Save(); } } GUILayout.EndHorizontal(); #endif GUILayout.Space(5); scrollPos = GUILayout.BeginScrollView(scrollPos); for (int i = 0; i < typeList.Count; i++) { GUILayout.BeginHorizontal("box"); EditorGUILayout.LabelField(typeList[i].Name, typeList[i].Namespace); if (GUILayout.Button("X", GUILayout.Width(18))) { RemoveType(typeList[i]); } GUILayout.EndHorizontal(); } GUILayout.EndScrollView(); AcceptDrops(); Repaint(); }
protected void DrawToolbarGUI() { EditorGUILayout.BeginHorizontal("Toolbar"); GUI.backgroundColor = new Color(1f, 1f, 1f, 0.5f); if (GUILayout.Button("File", EditorStyles.toolbarDropDown, GUILayout.Width(50))) { var menu = new GenericMenu(); foreach (System.Collections.Generic.KeyValuePair <Type, NodeCanvasTypeData> data in NodeCanvasManager.CanvasTypes) { menu.AddItem(new GUIContent("New Canvas/" + data.Value.DisplayString), false, newCanvasTypeCallback, data.Value); } menu.AddSeparator(""); menu.AddItem(new GUIContent("Load Canvas", "Loads an Specified Empty CanvasType"), false, LoadCanvas); menu.AddSeparator(""); menu.AddItem(new GUIContent("Save Canvas"), false, SaveCanvas); menu.AddItem(new GUIContent("Save Canvas As"), false, SaveCanvasAs); menu.AddSeparator(""); // Load from canvas foreach (string sceneSave in NodeEditorSaveManager.GetSceneSaves()) { menu.AddItem(new GUIContent("Load Canvas from Scene/" + sceneSave), false, LoadSceneCanvasCallback, sceneSave); } // Save Canvas to Scene menu.AddItem(new GUIContent("Save Canvas to Scene"), false, () => { showModalPanel = true; Debug.Log(showModalPanel); }); menu.ShowAsContext(); } if (GUILayout.Button("Debug", EditorStyles.toolbarDropDown, GUILayout.Width(50))) { var menu = new GenericMenu(); // Toggles side panel menu.AddItem(new GUIContent("Sidebar"), showSideWindow, () => { showSideWindow = !showSideWindow; }); menu.ShowAsContext(); } GUILayout.Space(10); GUILayout.FlexibleSpace(); GUILayout.Label(new GUIContent("" + canvasCache.nodeCanvas.saveName + " (" + (canvasCache.nodeCanvas.livesInScene? "Scene Save" : "Asset Save") + ")", "Opened Canvas path: " + canvasCache.nodeCanvas.savePath), "ToolbarButton"); GUILayout.Label("Type: " + canvasCache.typeData.DisplayString + "/" + canvasCache.nodeCanvas.GetType().Name + "", "ToolbarButton"); GUI.backgroundColor = new Color(1, 0.3f, 0.3f, 1); if (GUILayout.Button("Force Re-init", EditorStyles.toolbarButton, GUILayout.Width(80))) { NodeEditor.ReInit(true); } EditorGUILayout.EndHorizontal(); GUI.backgroundColor = Color.white; }
internal static void DisplayObjectContextMenu(Rect position, Object[] context, int contextUserData) { // Don't show context menu if we're inside the side-by-side diff comparison. if (EditorGUIUtility.comparisonViewMode != EditorGUIUtility.ComparisonViewMode.None) { return; } Vector2 temp = GUIUtility.GUIToScreenPoint(new Vector2(position.x, position.y)); position.x = temp.x; position.y = temp.y; GenericMenu pm = new GenericMenu(); if (context != null && context.Length == 1 && context[0] is Component) { Object targetObject = context[0]; Component targetComponent = (Component)targetObject; // Do nothing if component is not on a prefab instance. if (PrefabUtility.GetCorrespondingConnectedObjectFromSource(targetComponent.gameObject) == null) { } // Handle added component. else if (PrefabUtility.GetCorrespondingObjectFromSource(targetObject) == null && targetComponent != null) { GameObject instanceGo = targetComponent.gameObject; PrefabUtility.HandleApplyRevertMenuItems( "Added Component", instanceGo, (menuItemContent, sourceGo) => { TargetChoiceHandler.ObjectInstanceAndSourcePathInfo info = new TargetChoiceHandler.ObjectInstanceAndSourcePathInfo(); info.instanceObject = targetComponent; info.assetPath = AssetDatabase.GetAssetPath(sourceGo); GameObject rootObject = PrefabUtility.GetRootGameObject(sourceGo); if (!PrefabUtility.IsPartOfPrefabThatCanBeAppliedTo(rootObject) || EditorUtility.IsPersistent(instanceGo)) { pm.AddDisabledItem(menuItemContent); } else { pm.AddItem(menuItemContent, false, TargetChoiceHandler.ApplyPrefabAddedComponent, info); } }, (menuItemContent) => { pm.AddItem(menuItemContent, false, TargetChoiceHandler.RevertPrefabAddedComponent, targetComponent); } ); } else { SerializedObject so = new SerializedObject(targetObject); SerializedProperty property = so.GetIterator(); bool hasPrefabOverride = false; while (property.Next(property.hasChildren)) { if (property.isInstantiatedPrefab && property.prefabOverride && !property.isDefaultOverride) { hasPrefabOverride = true; break; } } // Handle modified component. if (hasPrefabOverride) { bool defaultOverrides = PrefabUtility.IsObjectOverrideAllDefaultOverridesComparedToAnySource(targetObject); PrefabUtility.HandleApplyRevertMenuItems( "Modified Component", targetObject, (menuItemContent, sourceObject) => { TargetChoiceHandler.ObjectInstanceAndSourcePathInfo info = new TargetChoiceHandler.ObjectInstanceAndSourcePathInfo(); info.instanceObject = targetObject; info.assetPath = AssetDatabase.GetAssetPath(sourceObject); GameObject rootObject = PrefabUtility.GetRootGameObject(sourceObject); if (!PrefabUtility.IsPartOfPrefabThatCanBeAppliedTo(rootObject) || EditorUtility.IsPersistent(targetObject)) { pm.AddDisabledItem(menuItemContent); } else { pm.AddItem(menuItemContent, false, TargetChoiceHandler.ApplyPrefabObjectOverride, info); } }, (menuItemContent) => { pm.AddItem(menuItemContent, false, TargetChoiceHandler.RevertPrefabObjectOverride, targetObject); }, defaultOverrides ); } } } pm.ObjectContextDropDown(position, context, contextUserData); ResetMouseDown(); }
/// <summary> /// Draw the property pop-up. /// </summary> public override void OnGUI (SerializedNodeProperty property, ActionNode node, GUIContent guiContent) { // String if (property.propertyType == NodePropertyType.String) { var rect = GUILayoutUtility.GetRect(GUIContent.none, EditorStyles.popup); var id = GUIUtility.GetControlID(FocusType.Passive); var popupRect = EditorGUI.PrefixLabel(rect, id, guiContent); var popupName = property.value as string ?? string.Empty; var propertyOrField = node as PropertyOrField; var oldGUIColor = GUI.color; if (propertyOrField.propertyType == null) GUI.color = Color.red; if (GUI.Button(popupRect, string.IsNullOrEmpty(popupName) ? "None" : popupName, EditorStyles.popup)) { var isSetProperty = propertyOrField is SetProperty; var members = FieldUtility.GetPublicMembers(propertyOrField.targetObject.ObjectType, null, false, isSetProperty, !isSetProperty); var menu = new GenericMenu(); // Add none menu.AddItem(new GUIContent("None"), string.IsNullOrEmpty(popupName), delegate () {property.value = string.Empty;}); // Add members for (int i = 0; i < members.Length; i++) { var memberName = members[i].Name; menu.AddItem(new GUIContent(memberName), popupName == memberName, delegate () {property.value = memberName;}); } menu.ShowAsContext(); } GUI.color = oldGUIColor; } // Not String else EditorGUILayout.LabelField(guiContent, new GUIContent("Use UnityObjectProperty with string.")); }
private void AddDropdown(Rect buttonRect, ReorderableList l) { var menu = new GenericMenu(); foreach (string levelName in _listLevelName) menu.AddItem(new GUIContent(levelName), false, AddDropdownItem, levelName); menu.ShowAsContext(); }