Example #1
0
 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();
 }
Example #2
0
		public static void ExtractMenuItemWithPath(string menuString, GenericMenu menu, string replacementMenuString, UnityEngine.Object[] temporaryContext)
		{
			MenuUtils.MenuCallbackObject menuCallbackObject = new MenuUtils.MenuCallbackObject();
			menuCallbackObject.menuItemPath = menuString;
			menuCallbackObject.temporaryContext = temporaryContext;
			menu.AddItem(new GUIContent(replacementMenuString), false, new GenericMenu.MenuFunction2(MenuUtils.MenuCallback), menuCallbackObject);
		}
Example #3
0
 void IHasCustomMenu.AddItemsToMenu(GenericMenu menu)
 {
     menu.AddItem(new GUIContent("Lock"), locked, () =>
     {
         locked = !locked;
     });
 }
Example #4
0
 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));
 }
Example #5
0
 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();
     }
 }
Example #6
0
        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.."));
                }
            }
        }
Example #7
0
 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);
         }
     }
 }
Example #8
0
        // Add menu items to a given menu.
        public static void AddNodeItemsToMenu(GenericMenu menu, GenericMenu.MenuFunction2 callback)
        {
            if (_nodeTypes == null) EnumerateNodeTypes();

            foreach (var nodeType in _nodeTypes)
                menu.AddItem(nodeType.label, false, callback, nodeType.type);
        }
Example #9
0
	// ================================================================================================================

	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;
	}
Example #10
0
        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();
            }
        }
 public static void AddMenu( State state,GenericMenu menu )
 {
     foreach( BehaviourMenuItem menuItem in _BehaviourMenuItems )
     {
         menu.AddItem( new GUIContent( Localization.GetWord("Add Behaviour") +"/" + menuItem.menuName ),false,AddBehaviourContextMenu,new KeyValuePair<State,System.Type>(state,menuItem.classType) );
     }
 }
Example #12
0
			public MenuItem(GUIContent _content, bool _separator, bool _on, GenericMenu.MenuFunction _func)
			{
				this.content = _content;
				this.separator = _separator;
				this.on = _on;
				this.func = _func;
			}
			internal static void Show(int savedFilterInstanceID)
			{
				GUIContent content = new GUIContent("Delete");
				GenericMenu genericMenu = new GenericMenu();
				genericMenu.AddItem(content, false, new GenericMenu.MenuFunction(new ProjectBrowser.SavedFiltersContextMenu(savedFilterInstanceID).Delete));
				genericMenu.ShowAsContext();
			}
Example #14
0
        /// <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();
        }
 internal static void AddSetToValueOfTargetMenuItems(GenericMenu menu, SerializedProperty property, TargetChoiceMenuFunction func)
 {
     SerializedProperty property2 = property.serializedObject.FindProperty(property.propertyPath);
     UnityEngine.Object[] targetObjects = property.serializedObject.targetObjects;
     List<string> list = new List<string>();
     foreach (UnityEngine.Object obj2 in targetObjects)
     {
         string item = "Set to Value of " + obj2.name;
         if (list.Contains(item))
         {
             int num2 = 1;
             while (true)
             {
                 object[] objArray1 = new object[] { "Set to Value of ", obj2.name, " (", num2, ")" };
                 item = string.Concat(objArray1);
                 if (!list.Contains(item))
                 {
                     break;
                 }
                 num2++;
             }
         }
         list.Add(item);
         menu.AddItem(EditorGUIUtility.TextContent(item), false, new GenericMenu.MenuFunction2(TargetChoiceHandler.TargetChoiceForwardFunction), new PropertyAndTargetHandler(property2, obj2, func));
     }
 }
 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();
 }
        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.");
                }
            }
        }
Example #18
0
        //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();
        }
		internal static void AddSetToValueOfTargetMenuItems(GenericMenu menu, SerializedProperty property, TargetChoiceHandler.TargetChoiceMenuFunction func)
		{
			SerializedProperty property2 = property.serializedObject.FindProperty(property.propertyPath);
			UnityEngine.Object[] targetObjects = property.serializedObject.targetObjects;
			List<string> list = new List<string>();
			UnityEngine.Object[] array = targetObjects;
			for (int i = 0; i < array.Length; i++)
			{
				UnityEngine.Object @object = array[i];
				string text = "Set to Value of " + @object.name;
				if (list.Contains(text))
				{
					int num = 1;
					while (true)
					{
						text = string.Concat(new object[]
						{
							"Set to Value of ",
							@object.name,
							" (",
							num,
							")"
						});
						if (!list.Contains(text))
						{
							break;
						}
						num++;
					}
				}
				list.Add(text);
				menu.AddItem(EditorGUIUtility.TextContent(text), false, new GenericMenu.MenuFunction2(TargetChoiceHandler.TargetChoiceForwardFunction), new PropertyAndTargetHandler(property2, @object, func));
			}
		}
Example #20
0
 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));
 }
 public static void Show(Rect buttonRect, string[] classNames, int initialSelectedInstanceID)
 {
     GenericMenu menu = new GenericMenu();
     List<UnityEngine.Object> source = FindAssetsOfType(classNames);
     if (source.Any<UnityEngine.Object>())
     {
         if (<>f__am$cache0 == null)
         {
Example #22
0
			public MenuItem(GUIContent _content, bool _separator, bool _on, GenericMenu.MenuFunction2 _func, object _userData)
			{
				this.content = _content;
				this.separator = _separator;
				this.on = _on;
				this.func2 = _func;
				this.userData = _userData;
			}
        protected override void OnRightClick(Vector2 mousePosition)
        {
            base.OnRightClick(mousePosition);

            GenericMenu menu = new GenericMenu();
            menu.AddItem(new GUIContent("Add Sequence Action"), false, OnAddNode, mousePosition);
            menu.ShowAsContext();
        }
Example #24
0
        protected override void OnRightClick(Vector2 mousePosition)
        {
            base.OnRightClick(mousePosition);

            GenericMenu menu = new GenericMenu();
            menu.AddItem(new GUIContent("Delete State Transition"), false, Delete);
            menu.ShowAsContext();
        }
        /// <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();
        }
Example #26
0
			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();
			}
Example #27
0
 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(); }));
 }
 public void OnTreeViewContextClick(int index)
 {
   AudioMixerItem node = (AudioMixerItem) this.m_TreeView.FindNode(index);
   if (node == null)
     return;
   GenericMenu genericMenu = new GenericMenu();
   genericMenu.AddItem(new GUIContent("Delete AudioMixer"), false, new GenericMenu.MenuFunction2(this.DeleteAudioMixerCallback), (object) node.mixer);
   genericMenu.ShowAsContext();
 }
Example #29
0
		private void OnTransitionContextClick(int index){
			GenericMenu menu = new GenericMenu ();
			menu.AddItem (new GUIContent("Remove"),false,delegate() {
				FsmEditorUtility.DestroyImmediate(node.Transitions[index]);
				node.Transitions = ArrayUtility.Remove (node.Transitions, transitions [index]);
				this.ResetTransitionList();
			});
			menu.ShowAsContext ();
		}
Example #30
0
        public override void OpenContextual(ToolControl control)
        {
            activatorControl = control;
            var menu = new GenericMenu();

            menu.allowDuplicateNames = true;
            GameObjectContextMenu.Fill(targets, menu, activatorControl.activatorScreenPosition, null);
            menu.DropDown(activatorControl.activatorGuiPosition);
        }
Example #31
0
 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));
 }
        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();
            }
        }
Example #33
0
    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();
    }
Example #34
0
    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;
     }
 }
    //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;
        }
    }
Example #37
0
        /// <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();
        }
Example #38
0
        /// <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();
        }
        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();
        }
Example #40
0
        //public virtual void OnRemove(List<LogicValue> value)
        //{
        //    if (logicValue != null)
        //        value.Remove(logicValue);
        //}

        public virtual void OnGenericMenu(UnityEditor.GenericMenu menu)
        {
            DeleteLinkMenu(Link, menu, "移除链接");
        }
Example #41
0
 public virtual void OnGenericMenu(UnityEditor.GenericMenu menu, Action act)
 {
     DeleteLinkMenuAndReLink(Link, menu, "移除链接并连接", act);
 }
        void OnGUI()
        {
            EditorGUILayout.BeginHorizontal();
            Rect dropdownbuttonRect = new Rect(0, 0, 70, 20);
            var  _contentRect       = contentRect;

            _contentRect.height = (zoo.animals.Count + 1) * 20;

            EditorGUI.DrawRect(zoneRect, new Color(0.2f, 0.2f, 0.2f));
            //GUILayout.BeginArea(zoneRect, GUI.skin.box);
            sp = GUI.BeginScrollView(zoneRect, sp, _contentRect);
            //GUI.Label(new Rect(100, 200, Screen.width, 50), "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
            GUILayout.BeginArea(_contentRect);
            EditorGUILayout.LabelField("animal count", zoo.animals.Count.ToString());
            for (int i = 0; i < zoo.animals.Count; i++)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField(i.ToString(), zoo.animals[i].Species);

                if (EditorGUILayout.DropdownButton(new GUIContent(m_Type[zoo.animals[i].type]), FocusType.Passive))
                {
                    GenericMenu menu = new GenericMenu();
                    for (int j = 0; j < m_Type.Length; j++)
                    {
                        var info = new ClickInfo
                        {
                            index = i,
                            type  = j
                        };
                        menu.AddItem(new GUIContent(m_Type[j]), false, ItemCallBack2, info);
                    }
                    //menu.DropDown(GUILayoutUtility.GetLastRect());
                    menu.ShowAsContext();
                }

                if (GUILayout.Button("remove", GUILayout.Width(70)))
                {
                    zoo.animals.RemoveAt(i);
                }
                EditorGUILayout.EndHorizontal();
            }
            GUILayout.EndArea();
            GUI.EndScrollView();
            EditorGUILayout.EndHorizontal();
            //GUILayout.EndArea();

            GUILayout.BeginArea(buttonRect, GUI.skin.box);
            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("add Cat"))
            {
                zoo.animals.Add(new Cat());
            }
            if (GUILayout.Button("add Dog"))
            {
                zoo.animals.Add(new Dog());
            }
            if (GUILayout.Button("add Giraffe"))
            {
                zoo.animals.Add(new Giraffe());
            }
            EditorGUILayout.EndHorizontal();
            GUILayout.EndArea();

            GUILayout.BeginArea(dropdownButtonRect, GUI.skin.box);
            EditorGUILayout.BeginHorizontal();
            if (EditorGUILayout.DropdownButton(new GUIContent(m_Type[selectedType]), FocusType.Passive))
            {
                GenericMenu menu = new GenericMenu();
                for (int i = 0; i < m_Type.Length; i++)
                {
                    menu.AddItem(new GUIContent(m_Type[i]), false, ItemCallBack, i);
                }
                menu.ShowAsContext();
            }
            //GUILayout.FlexibleSpace();
            this.selectedOption = EditorGUILayout.Popup("Popup", (int)this.selectedOption, new string[] { "s1", "s2", "s3" });
            if (GUILayout.Button("Select Animation"))
            {
                AnimationClip fbxObj = AssetDatabase.LoadAssetAtPath <AnimationClip>("Assets/Data/Emotes--RussianDance.anim.fbx");
                Selection.activeObject = fbxObj;
            }

            //Set certain model to the AvatarPreview window
            if (GUILayout.Button("Set Model"))
            {
                SetSelectModel("Assets/Data/Robot_A.fbx");
            }

            EditorGUILayout.EndHorizontal();
            GUILayout.EndArea();
        }
Example #43
0
    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();
    }
Example #44
0
        ///----------------------------------------------------------------------------------------------

        ///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 virtual void AddItemsToMenu(GenericMenu menu)
 {
     menu.AddItem(new GUIContent("Reset Bake Settings"), false, new GenericMenu.MenuFunction(this.ResetBakeSettings));
 }
Example #46
0
        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;
        }
Example #47
0
        // shared by compute shader inspector too
        internal static void ShaderErrorListUI(Object shader, ShaderMessage[] messages, ref Vector2 scrollPosition)
        {
            int n = messages.Length;

            GUILayout.Space(kSpace);
            GUILayout.Label(string.Format("Errors ({0}):", n), EditorStyles.boldLabel);
            int   errorListID = GUIUtility.GetControlID(kErrorViewHash, FocusType.Passive);
            float height      = Mathf.Min(n * 20f + 40f, 150f);

            scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUISkin.current.box, GUILayout.MinHeight(height));

            EditorGUIUtility.SetIconSize(new Vector2(16.0f, 16.0f));
            float lineHeight = Styles.messageStyle.CalcHeight(EditorGUIUtility.TempContent(Styles.errorIcon), 100);

            Event e = Event.current;

            for (int i = 0; i < n; ++i)
            {
                Rect r = EditorGUILayout.GetControlRect(false, lineHeight);

                string err      = messages[i].message;
                string plat     = messages[i].platform.ToString();
                bool   warn     = messages[i].severity != ShaderCompilerMessageSeverity.Error;
                string fileName = FileUtil.GetLastPathNameComponent(messages[i].file);
                int    line     = messages[i].line;

                // Double click opens shader file at error line
                if (e.type == EventType.MouseDown && e.button == 0 && r.Contains(e.mousePosition))
                {
                    GUIUtility.keyboardControl = errorListID;
                    if (e.clickCount == 2)
                    {
                        string filePath = messages[i].file;
                        Object asset    = string.IsNullOrEmpty(filePath) ? null : AssetDatabase.LoadMainAssetAtPath(filePath);

                        // if we don't have an asset and the filePath is an absolute path, it's an error in a system
                        // cginc - open that instead
                        if (asset == null && System.IO.Path.IsPathRooted(filePath))
                        {
                            ShaderUtil.OpenSystemShaderIncludeError(filePath, line);
                        }
                        else
                        {
                            AssetDatabase.OpenAsset(asset ?? shader, line);
                        }
                        GUIUtility.ExitGUI();
                    }
                    e.Use();
                }

                // Context menu, "Copy"
                if (e.type == EventType.ContextClick && r.Contains(e.mousePosition))
                {
                    e.Use();
                    var menu = new GenericMenu();
                    // need to copy current value to be used in delegate
                    // (C# closures close over variables, not their values)
                    var errorIndex = i;
                    menu.AddItem(EditorGUIUtility.TrTextContent("Copy error text"), false, delegate {
                        string errMsg = messages[errorIndex].message;
                        if (!string.IsNullOrEmpty(messages[errorIndex].messageDetails))
                        {
                            errMsg += '\n';
                            errMsg += messages[errorIndex].messageDetails;
                        }
                        EditorGUIUtility.systemCopyBuffer = errMsg;
                    });
                    menu.ShowAsContext();
                }

                // background
                if (e.type == EventType.Repaint)
                {
                    if ((i & 1) == 0)
                    {
                        GUIStyle st = Styles.evenBackground;
                        st.Draw(r, false, false, false, false);
                    }
                }

                // error location on the right side
                Rect locRect = r;
                locRect.xMin = locRect.xMax;
                if (line > 0)
                {
                    GUIContent gc;
                    if (string.IsNullOrEmpty(fileName))
                    {
                        gc = EditorGUIUtility.TempContent(line.ToString(CultureInfo.InvariantCulture));
                    }
                    else
                    {
                        gc = EditorGUIUtility.TempContent(fileName + ":" + line.ToString(CultureInfo.InvariantCulture));
                    }

                    // calculate size so we can right-align it
                    Vector2 size = EditorStyles.miniLabel.CalcSize(gc);
                    locRect.xMin -= size.x;
                    GUI.Label(locRect, gc, EditorStyles.miniLabel);
                    locRect.xMin -= 2;
                    // ensure some minimum width so that platform field next will line up
                    if (locRect.width < 30)
                    {
                        locRect.xMin = locRect.xMax - 30;
                    }
                }

                // platform to the left of it
                Rect platRect = locRect;
                platRect.width = 0;
                if (plat.Length > 0)
                {
                    GUIContent gc = EditorGUIUtility.TempContent(plat);
                    // calculate size so we can right-align it
                    Vector2 size = EditorStyles.miniLabel.CalcSize(gc);
                    platRect.xMin -= size.x;

                    // draw platform in dimmer color; it's often not very important information
                    Color oldColor = GUI.contentColor;
                    GUI.contentColor = new Color(1, 1, 1, 0.5f);
                    GUI.Label(platRect, gc, EditorStyles.miniLabel);
                    GUI.contentColor = oldColor;
                    platRect.xMin   -= 2;
                }

                // error message
                Rect msgRect = r;
                msgRect.xMax = platRect.xMin;
                GUI.Label(msgRect, EditorGUIUtility.TempContent(err, warn ? Styles.warningIcon : Styles.errorIcon), Styles.messageStyle);
            }
            EditorGUIUtility.SetIconSize(Vector2.zero);
            GUILayout.EndScrollView();
        }
        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();
        }
Example #49
0
    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);
        }
    }
        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();
        }
Example #51
0
 public virtual void AddItemsToMenu(GenericMenu menu)
 {
     menu.AddItem(EditorGUIUtility.TrTextContent("Reload"), false, Reload);
 }
Example #52
0
 public void AddMenuItems(SerializedProperty property, GenericMenu menu)
 {
Example #53
0
        /// <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();
        }
 public virtual void AddItemsToMenu(GenericMenu menu)
 {
     m_SceneHierarchy.AddItemsToWindowMenu(menu);
 }
Example #55
0
        /// <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;
            }
        }
 public virtual void OnShowConfig(GenericMenu genericMenu)
 {
 }
Example #57
0
        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();
            }
        }
 public override void Go()
 {
     base.Go();
     var genericMenu = new GenericMenu();
     CreateMenuItems(genericMenu);
     genericMenu.ShowAsContext();
 }
        /// <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."));
        }
Example #60
-16
		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();
		}