private void DrawLeftView() { GUILayout.BeginVertical(GUILayout.Width(leftViewWidth)); GUILayout.BeginHorizontal(); groupName = GUILayout.TextField(groupName, GUILayout.Width(140)); if (GUILayout.Button("Add", EditorStyles.toolbarButton)) { if (!string.IsNullOrEmpty(groupName)) { var group = new TileBrushGroup(groupName); this.brushGroups.Add(group); this.activeGroup = group; this.groupName = ""; this.selectBrushIndex = 0; } } if (GUILayout.Button("Del", EditorStyles.toolbarButton)) { this.brushGroups.Remove(activeGroup); } GUILayout.EndHorizontal(); foreach (var g in brushGroups) { var flag = GUILayout.Toggle(g == activeGroup, g.name, layerStyle); if (flag) { if (this.activeGroup != g) { this.activeGroup = g; this.selectBrushIndex = 0; } } } GUILayout.EndVertical(); }
private void DrawRightView() { Rect rect = EditorGUILayout.BeginVertical(); rect.width = this.position.width - leftViewWidth; rect.height = this.position.height - 20 * 2; //绘制背景 EditorGUI.DrawRect(rect, new Color(0.2f, 0.2f, 0.2f)); //绘制笔刷组 scrollPos = GUILayout.BeginScrollView(scrollPos); // GUILayout.Box("",GUILayout.Width(100),GUILayout.Height(100)); // if (myTex) // { // Rect textRect = GUILayoutUtility.GetLastRect(); // Debug.Log(textRect); // EditorGUI.DrawPreviewTexture(textRect,myTex); // } this.DrawActiveBrushGroup(); GUILayout.EndScrollView(); var e = Event.current; if (e.type == EventType.ContextClick) { if (rect.Contains(e.mousePosition)) { var menu = new GenericMenu(); menu.AddItem(new GUIContent("Delete Selected Brush"), false, this.DeleteSelectedBrush); menu.AddItem(new GUIContent("Delete All Brushes"), false, this.DeleteAllBrushes); menu.ShowAsContext(); e.Use(); } } if (e.type == EventType.DragUpdated || e.type == EventType.DragPerform) { if (rect.Contains(Event.current.mousePosition)) { DragAndDrop.visualMode = DragAndDropVisualMode.Link; //如果拖入了拖拽区 if (e.type == EventType.DragPerform) { DragAndDrop.AcceptDrag(); for (int i = 0; i < DragAndDrop.objectReferences.Length; i++) { var obj = DragAndDrop.objectReferences[i]; TileBrush brush = new TileBrush(obj.name); brush.prefabPath = DragAndDrop.paths[i]; brush.texture = AssetPreview.GetAssetPreview(obj); if (activeGroup == null) { var defaultGroup = new TileBrushGroup("default"); this.brushGroups.Add(defaultGroup); this.activeGroup = defaultGroup; } this.activeGroup.brushes.Add(brush); } } } Event.current.Use(); } EditorGUILayout.EndVertical(); }