├── .gitignore ├── Assets ├── Editor.meta └── Editor │ ├── ListView.meta │ ├── ListView │ ├── DragAndDropDelay.cs │ ├── DragAndDropDelay.cs.meta │ ├── ListViewElement.cs │ ├── ListViewElement.cs.meta │ ├── ListViewGUI.cs │ ├── ListViewGUI.cs.meta │ ├── ListViewOptions.cs │ ├── ListViewOptions.cs.meta │ ├── ListViewShared.cs │ ├── ListViewShared.cs.meta │ ├── ListViewState.cs │ ├── ListViewState.cs.meta │ ├── helper.meta │ └── helper │ │ ├── GUIClipHelper.cs │ │ └── GUIClipHelper.cs.meta │ ├── TestListView.cs │ ├── TestListView.cs.meta │ ├── TestListViewButton.cs │ ├── TestListViewButton.cs.meta │ ├── TestListViewExternalFiles.cs │ ├── TestListViewExternalFiles.cs.meta │ ├── TestListViewReordering.cs │ ├── TestListViewReordering.cs.meta │ ├── TestListViewWithCol.cs │ └── TestListViewWithCol.cs.meta ├── ProjectSettings ├── AudioManager.asset ├── ClusterInputManager.asset ├── DynamicsManager.asset ├── EditorBuildSettings.asset ├── EditorSettings.asset ├── GraphicsSettings.asset ├── InputManager.asset ├── NavMeshAreas.asset ├── NetworkManager.asset ├── Physics2DSettings.asset ├── ProjectSettings.asset ├── ProjectVersion.txt ├── QualitySettings.asset ├── TagManager.asset ├── TimeManager.asset ├── UnityAdsSettings.asset └── UnityConnectSettings.asset ├── README.md └── Screenshots ├── Button.png ├── Col.png ├── ExternalFiles.png ├── Reordering.png ├── default.png └── enter.png /.gitignore: -------------------------------------------------------------------------------- 1 | /[Ll]ibrary/ 2 | /[Tt]emp/ 3 | /[Oo]bj/ 4 | /[Bb]uild/ 5 | /[Bb]uilds/ 6 | /Assets/AssetStoreTools* 7 | 8 | # Autogenerated VS/MD solution and project files 9 | ExportedObj/ 10 | *.csproj 11 | *.unityproj 12 | *.sln 13 | *.suo 14 | *.tmp 15 | *.user 16 | *.userprefs 17 | *.pidb 18 | *.booproj 19 | *.svd 20 | 21 | 22 | # Unity3D generated meta files 23 | *.pidb.meta 24 | 25 | # Unity3D Generated File On Crash Reports 26 | sysinfo.txt 27 | -------------------------------------------------------------------------------- /Assets/Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5b09aebd7fdc00e4a8dddb8e952737cf 3 | folderAsset: yes 4 | timeCreated: 1460785677 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Editor/ListView.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 584c354077631cf4184d28a9579582c9 3 | folderAsset: yes 4 | timeCreated: 1460785688 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Editor/ListView/DragAndDropDelay.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | namespace WH.Editor 4 | { 5 | internal class DragAndDropDelay 6 | { 7 | public Vector2 mouseDownPosition; 8 | public bool CanStartDrag() 9 | { 10 | return Vector2.Distance(this.mouseDownPosition, Event.current.mousePosition) > 6f; 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Assets/Editor/ListView/DragAndDropDelay.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 594c583919e09d547ade6f58d3a8a9fc 3 | timeCreated: 1460785803 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Editor/ListView/ListViewElement.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | namespace WH.Editor 4 | { 5 | public struct ListViewElement 6 | { 7 | public int row; 8 | public int column; 9 | public Rect position; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Assets/Editor/ListView/ListViewElement.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 04fd68eb264187f4db983372f5e18b89 3 | timeCreated: 1460785718 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Editor/ListView/ListViewGUI.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEditor; 3 | using UnityEngine; 4 | namespace WH.Editor 5 | { 6 | internal class ListViewGUI 7 | { 8 | private static int[] dummyWidths = new int[1]; 9 | internal static ListViewShared.InternalListViewState ilvState = new ListViewShared.InternalListViewState(); 10 | private static int listViewHash = "ListView".GetHashCode(); 11 | public static ListViewShared.ListViewElementsEnumerator ListView(Rect pos, ListViewState state) 12 | { 13 | return ListViewGUI.DoListView(pos, state, null, string.Empty); 14 | } 15 | public static ListViewShared.ListViewElementsEnumerator ListView(ListViewState state, GUIStyle style, params GUILayoutOption[] options) 16 | { 17 | return ListViewGUI.ListView(state, (ListViewOptions)0, null, string.Empty, style, options); 18 | } 19 | public static ListViewShared.ListViewElementsEnumerator ListView(ListViewState state, int[] colWidths, GUIStyle style, params GUILayoutOption[] options) 20 | { 21 | return ListViewGUI.ListView(state, (ListViewOptions)0, colWidths, string.Empty, style, options); 22 | } 23 | public static ListViewShared.ListViewElementsEnumerator ListView(ListViewState state, ListViewOptions lvOptions, GUIStyle style, params GUILayoutOption[] options) 24 | { 25 | return ListViewGUI.ListView(state, lvOptions, null, string.Empty, style, options); 26 | } 27 | public static ListViewShared.ListViewElementsEnumerator ListView(ListViewState state, ListViewOptions lvOptions, string dragTitle, GUIStyle style, params GUILayoutOption[] options) 28 | { 29 | return ListViewGUI.ListView(state, lvOptions, null, dragTitle, style, options); 30 | } 31 | public static ListViewShared.ListViewElementsEnumerator ListView(ListViewState state, ListViewOptions lvOptions, int[] colWidths, string dragTitle, GUIStyle style, params GUILayoutOption[] options) 32 | { 33 | GUILayout.BeginHorizontal(style, new GUILayoutOption[0]); 34 | state.scrollPos = EditorGUILayout.BeginScrollView(state.scrollPos, options); 35 | ListViewGUI.ilvState.beganHorizontal = true; 36 | state.draggedFrom = -1; 37 | state.draggedTo = -1; 38 | state.fileNames = null; 39 | if ((lvOptions & ListViewOptions.wantsReordering) != (ListViewOptions)0) 40 | { 41 | ListViewGUI.ilvState.wantsReordering = true; 42 | } 43 | if ((lvOptions & ListViewOptions.wantsExternalFiles) != (ListViewOptions)0) 44 | { 45 | ListViewGUI.ilvState.wantsExternalFiles = true; 46 | } 47 | if ((lvOptions & ListViewOptions.wantsToStartCustomDrag) != (ListViewOptions)0) 48 | { 49 | ListViewGUI.ilvState.wantsToStartCustomDrag = true; 50 | } 51 | if ((lvOptions & ListViewOptions.wantsToAcceptCustomDrag) != (ListViewOptions)0) 52 | { 53 | ListViewGUI.ilvState.wantsToAcceptCustomDrag = true; 54 | } 55 | return ListViewGUI.DoListView(GUILayoutUtility.GetRect(1f, (float)(state.totalRows * state.rowHeight + 3)), state, colWidths, string.Empty); 56 | } 57 | public static ListViewShared.ListViewElementsEnumerator DoListView(Rect pos, ListViewState state, int[] colWidths, string dragTitle) 58 | { 59 | int controlID = GUIUtility.GetControlID(ListViewGUI.listViewHash, FocusType.Passive); 60 | state.ID = controlID; 61 | state.selectionChanged = false; 62 | Rect rect; 63 | if (GUIClipHelper.visibleRect.x < 0f || GUIClipHelper.visibleRect.y < 0f) 64 | { 65 | rect = pos; 66 | } 67 | else 68 | { 69 | rect = ((pos.y >= 0f) ? new Rect(0f, state.scrollPos.y, GUIClipHelper.visibleRect.width, GUIClipHelper.visibleRect.height) : new Rect(0f, 0f, GUIClipHelper.visibleRect.width, GUIClipHelper.visibleRect.height)); 70 | } 71 | if (rect.width <= 0f) 72 | { 73 | rect.width = 1f; 74 | } 75 | if (rect.height <= 0f) 76 | { 77 | rect.height = 1f; 78 | } 79 | ListViewGUI.ilvState.rect = rect; 80 | int num = (int)((-pos.y + rect.yMin) / (float)state.rowHeight); 81 | int num2 = num + (int)Math.Ceiling((double)(((rect.yMin - pos.y) % (float)state.rowHeight + rect.height) / (float)state.rowHeight)) - 1; 82 | if (colWidths == null) 83 | { 84 | ListViewGUI.dummyWidths[0] = (int)rect.width; 85 | colWidths = ListViewGUI.dummyWidths; 86 | } 87 | ListViewGUI.ilvState.invisibleRows = num; 88 | ListViewGUI.ilvState.endRow = num2; 89 | ListViewGUI.ilvState.rectHeight = (int)rect.height; 90 | ListViewGUI.ilvState.state = state; 91 | if (num < 0) 92 | { 93 | num = 0; 94 | } 95 | if (num2 >= state.totalRows) 96 | { 97 | num2 = state.totalRows - 1; 98 | } 99 | return new ListViewShared.ListViewElementsEnumerator(ListViewGUI.ilvState, colWidths, num, num2, dragTitle, new Rect(0f, (float)(num * state.rowHeight), pos.width, (float)state.rowHeight)); 100 | } 101 | public static bool MultiSelection(int prevSelected, int currSelected, ref int initialSelected, ref bool[] selectedItems) 102 | { 103 | return ListViewShared.MultiSelection(ListViewGUI.ilvState, prevSelected, currSelected, ref initialSelected, ref selectedItems); 104 | } 105 | public static bool HasMouseUp(Rect r) 106 | { 107 | return ListViewShared.HasMouseUp(ListViewGUI.ilvState, r, 0); 108 | } 109 | public static bool HasMouseDown(Rect r) 110 | { 111 | return ListViewShared.HasMouseDown(ListViewGUI.ilvState, r, 0); 112 | } 113 | public static bool HasMouseDown(Rect r, int button) 114 | { 115 | return ListViewShared.HasMouseDown(ListViewGUI.ilvState, r, button); 116 | } 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /Assets/Editor/ListView/ListViewGUI.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1776f5b1fb38c62409ae497959d8f9d1 3 | timeCreated: 1460785718 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Editor/ListView/ListViewOptions.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akof1314/UnityEditorListView/c6e2be475eb8962c7b47e871dfb83b08da95918c/Assets/Editor/ListView/ListViewOptions.cs -------------------------------------------------------------------------------- /Assets/Editor/ListView/ListViewOptions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8d383514ffd82a64da8a214f4472e528 3 | timeCreated: 1460785718 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Editor/ListView/ListViewShared.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using UnityEditor; 5 | using UnityEngine; 6 | namespace WH.Editor 7 | { 8 | internal class ListViewShared 9 | { 10 | internal class InternalListViewState 11 | { 12 | public int id = -1; 13 | public int invisibleRows; 14 | public int endRow; 15 | public int rectHeight; 16 | public ListViewState state; 17 | public bool beganHorizontal; 18 | public Rect rect; 19 | public bool wantsReordering; 20 | public bool wantsExternalFiles; 21 | public bool wantsToStartCustomDrag; 22 | public bool wantsToAcceptCustomDrag; 23 | public int dragItem; 24 | } 25 | internal class Constants 26 | { 27 | public static string insertion = "PR Insertion"; 28 | } 29 | internal class ListViewElementsEnumerator : IDisposable, IEnumerator, IEnumerator 30 | { 31 | private int[] colWidths; 32 | private int xTo; 33 | private int yFrom; 34 | private int yTo; 35 | private Rect firstRect; 36 | private Rect rect; 37 | private int xPos = -1; 38 | private int yPos = -1; 39 | private ListViewElement element; 40 | private ListViewShared.InternalListViewState ilvState; 41 | private bool quiting; 42 | private bool isLayouted; 43 | private string dragTitle; 44 | ListViewElement IEnumerator.Current 45 | { 46 | get 47 | { 48 | return this.element; 49 | } 50 | } 51 | object IEnumerator.Current 52 | { 53 | get 54 | { 55 | return this.element; 56 | } 57 | } 58 | internal ListViewElementsEnumerator(ListViewShared.InternalListViewState ilvState, int[] colWidths, int yFrom, int yTo, string dragTitle, Rect firstRect) 59 | { 60 | this.colWidths = colWidths; 61 | this.xTo = colWidths.Length - 1; 62 | this.yFrom = yFrom; 63 | this.yTo = yTo; 64 | this.firstRect = firstRect; 65 | this.rect = firstRect; 66 | this.quiting = (ilvState.state.totalRows == 0); 67 | this.ilvState = ilvState; 68 | this.dragTitle = dragTitle; 69 | ilvState.state.customDraggedFromID = 0; 70 | this.Reset(); 71 | } 72 | public bool MoveNext() 73 | { 74 | if (this.xPos > -1) 75 | { 76 | if (ListViewShared.HasMouseDown(this.ilvState, this.rect)) 77 | { 78 | this.ilvState.state.selectionChanged = true; 79 | this.ilvState.state.row = this.yPos; 80 | this.ilvState.state.column = this.xPos; 81 | this.ilvState.state.scrollPos = ListViewShared.ListViewScrollToRow(this.ilvState, this.yPos); 82 | if ((this.ilvState.wantsReordering || this.ilvState.wantsToStartCustomDrag) && GUIUtility.hotControl == this.ilvState.state.ID) 83 | { 84 | DragAndDropDelay dragAndDropDelay = (DragAndDropDelay)GUIUtility.GetStateObject(typeof(DragAndDropDelay), this.ilvState.state.ID); 85 | dragAndDropDelay.mouseDownPosition = Event.current.mousePosition; 86 | this.ilvState.dragItem = this.yPos; 87 | ListViewShared.dragControlID = this.ilvState.state.ID; 88 | } 89 | } 90 | if ((this.ilvState.wantsReordering || this.ilvState.wantsToStartCustomDrag) && GUIUtility.hotControl == this.ilvState.state.ID && Event.current.type == EventType.MouseDrag && GUIClipHelper.visibleRect.Contains(Event.current.mousePosition)) 91 | { 92 | DragAndDropDelay dragAndDropDelay2 = (DragAndDropDelay)GUIUtility.GetStateObject(typeof(DragAndDropDelay), this.ilvState.state.ID); 93 | if (dragAndDropDelay2.CanStartDrag()) 94 | { 95 | DragAndDrop.PrepareStartDrag(); 96 | DragAndDrop.objectReferences = new UnityEngine.Object[0]; 97 | DragAndDrop.paths = null; 98 | if (this.ilvState.wantsReordering) 99 | { 100 | this.ilvState.state.dropHereRect = new Rect(this.ilvState.rect.x, 0f, this.ilvState.rect.width, (float)(this.ilvState.state.rowHeight * 2)); 101 | DragAndDrop.StartDrag(this.dragTitle); 102 | } 103 | else 104 | { 105 | if (this.ilvState.wantsToStartCustomDrag) 106 | { 107 | DragAndDrop.SetGenericData("CustomDragID", this.ilvState.state.ID); 108 | DragAndDrop.StartDrag(this.dragTitle); 109 | } 110 | } 111 | } 112 | Event.current.Use(); 113 | } 114 | } 115 | this.xPos++; 116 | if (this.xPos > this.xTo) 117 | { 118 | this.xPos = 0; 119 | this.yPos++; 120 | this.rect.x = this.firstRect.x; 121 | this.rect.width = (float)this.colWidths[0]; 122 | if (this.yPos > this.yTo) 123 | { 124 | this.quiting = true; 125 | } 126 | else 127 | { 128 | this.rect.y = this.rect.y + this.rect.height; 129 | } 130 | } 131 | else 132 | { 133 | if (this.xPos >= 1) 134 | { 135 | this.rect.x = this.rect.x + (float)this.colWidths[this.xPos - 1]; 136 | } 137 | this.rect.width = (float)this.colWidths[this.xPos]; 138 | } 139 | this.element.row = this.yPos; 140 | this.element.column = this.xPos; 141 | this.element.position = this.rect; 142 | if (this.element.row >= this.ilvState.state.totalRows) 143 | { 144 | this.quiting = true; 145 | } 146 | if (this.isLayouted && Event.current.type == EventType.Layout && this.yFrom + 1 == this.yPos) 147 | { 148 | this.quiting = true; 149 | } 150 | if (this.isLayouted && this.yPos != this.yFrom) 151 | { 152 | GUILayout.EndHorizontal(); 153 | } 154 | if (this.quiting) 155 | { 156 | if (this.ilvState.state.drawDropHere && Event.current.GetTypeForControl(this.ilvState.state.ID) == EventType.Repaint) 157 | { 158 | GUIStyle gUIStyle = ListViewShared.Constants.insertion; 159 | gUIStyle.Draw(gUIStyle.margin.Remove(this.ilvState.state.dropHereRect), false, false, false, false); 160 | } 161 | if (ListViewShared.ListViewKeyboard(this.ilvState, this.colWidths.Length)) 162 | { 163 | this.ilvState.state.selectionChanged = true; 164 | } 165 | if (Event.current.GetTypeForControl(this.ilvState.state.ID) == EventType.MouseUp) 166 | { 167 | GUIUtility.hotControl = 0; 168 | } 169 | if (this.ilvState.wantsReordering && GUIUtility.hotControl == this.ilvState.state.ID) 170 | { 171 | ListViewState state = this.ilvState.state; 172 | EventType type = Event.current.type; 173 | if (type != EventType.DragUpdated) 174 | { 175 | if (type != EventType.DragPerform) 176 | { 177 | if (type == EventType.DragExited) 178 | { 179 | this.ilvState.wantsReordering = false; 180 | this.ilvState.state.drawDropHere = false; 181 | GUIUtility.hotControl = 0; 182 | } 183 | } 184 | else 185 | { 186 | if (GUIClipHelper.visibleRect.Contains(Event.current.mousePosition)) 187 | { 188 | this.ilvState.state.draggedFrom = this.ilvState.dragItem; 189 | this.ilvState.state.draggedTo = Mathf.RoundToInt(Event.current.mousePosition.y / (float)state.rowHeight); 190 | if (this.ilvState.state.draggedTo > this.ilvState.state.totalRows) 191 | { 192 | this.ilvState.state.draggedTo = this.ilvState.state.totalRows; 193 | } 194 | if (this.ilvState.state.draggedTo > this.ilvState.state.draggedFrom) 195 | { 196 | this.ilvState.state.row = this.ilvState.state.draggedTo - 1; 197 | } 198 | else 199 | { 200 | this.ilvState.state.row = this.ilvState.state.draggedTo; 201 | } 202 | this.ilvState.state.selectionChanged = true; 203 | DragAndDrop.AcceptDrag(); 204 | Event.current.Use(); 205 | this.ilvState.wantsReordering = false; 206 | this.ilvState.state.drawDropHere = false; 207 | } 208 | GUIUtility.hotControl = 0; 209 | } 210 | } 211 | else 212 | { 213 | DragAndDrop.visualMode = ((!this.ilvState.rect.Contains(Event.current.mousePosition)) ? DragAndDropVisualMode.None : DragAndDropVisualMode.Move); 214 | Event.current.Use(); 215 | if (DragAndDrop.visualMode != DragAndDropVisualMode.None) 216 | { 217 | state.dropHereRect.y = (float)((Mathf.RoundToInt(Event.current.mousePosition.y / (float)state.rowHeight) - 1) * state.rowHeight); 218 | if (state.dropHereRect.y >= (float)(state.rowHeight * state.totalRows)) 219 | { 220 | state.dropHereRect.y = (float)(state.rowHeight * (state.totalRows - 1)); 221 | } 222 | state.drawDropHere = true; 223 | } 224 | } 225 | } 226 | else 227 | { 228 | if (this.ilvState.wantsExternalFiles) 229 | { 230 | EventType type = Event.current.type; 231 | if (type != EventType.DragUpdated) 232 | { 233 | if (type != EventType.DragPerform) 234 | { 235 | if (type == EventType.DragExited) 236 | { 237 | this.ilvState.wantsExternalFiles = false; 238 | this.ilvState.state.drawDropHere = false; 239 | GUIUtility.hotControl = 0; 240 | } 241 | } 242 | else 243 | { 244 | if (GUIClipHelper.visibleRect.Contains(Event.current.mousePosition)) 245 | { 246 | this.ilvState.state.fileNames = DragAndDrop.paths; 247 | DragAndDrop.AcceptDrag(); 248 | Event.current.Use(); 249 | this.ilvState.wantsExternalFiles = false; 250 | this.ilvState.state.drawDropHere = false; 251 | this.ilvState.state.draggedTo = Mathf.RoundToInt(Event.current.mousePosition.y / (float)this.ilvState.state.rowHeight); 252 | if (this.ilvState.state.draggedTo > this.ilvState.state.totalRows) 253 | { 254 | this.ilvState.state.draggedTo = this.ilvState.state.totalRows; 255 | } 256 | this.ilvState.state.row = this.ilvState.state.draggedTo; 257 | } 258 | GUIUtility.hotControl = 0; 259 | } 260 | } 261 | else 262 | { 263 | if (GUIClipHelper.visibleRect.Contains(Event.current.mousePosition) && DragAndDrop.paths != null && DragAndDrop.paths.Length != 0) 264 | { 265 | DragAndDrop.visualMode = ((!this.ilvState.rect.Contains(Event.current.mousePosition)) ? DragAndDropVisualMode.None : DragAndDropVisualMode.Copy); 266 | Event.current.Use(); 267 | if (DragAndDrop.visualMode != DragAndDropVisualMode.None) 268 | { 269 | this.ilvState.state.dropHereRect = new Rect(this.ilvState.rect.x, (float)((Mathf.RoundToInt(Event.current.mousePosition.y / (float)this.ilvState.state.rowHeight) - 1) * this.ilvState.state.rowHeight), this.ilvState.rect.width, (float)this.ilvState.state.rowHeight); 270 | if (this.ilvState.state.dropHereRect.y >= (float)(this.ilvState.state.rowHeight * this.ilvState.state.totalRows)) 271 | { 272 | this.ilvState.state.dropHereRect.y = (float)(this.ilvState.state.rowHeight * (this.ilvState.state.totalRows - 1)); 273 | } 274 | this.ilvState.state.drawDropHere = true; 275 | } 276 | } 277 | } 278 | } 279 | else 280 | { 281 | if (this.ilvState.wantsToAcceptCustomDrag && ListViewShared.dragControlID != this.ilvState.state.ID) 282 | { 283 | EventType type = Event.current.type; 284 | if (type != EventType.DragUpdated) 285 | { 286 | if (type != EventType.DragPerform) 287 | { 288 | if (type == EventType.DragExited) 289 | { 290 | GUIUtility.hotControl = 0; 291 | } 292 | } 293 | else 294 | { 295 | object genericData = DragAndDrop.GetGenericData("CustomDragID"); 296 | if (GUIClipHelper.visibleRect.Contains(Event.current.mousePosition) && genericData != null) 297 | { 298 | this.ilvState.state.customDraggedFromID = (int)genericData; 299 | DragAndDrop.AcceptDrag(); 300 | Event.current.Use(); 301 | } 302 | GUIUtility.hotControl = 0; 303 | } 304 | } 305 | else 306 | { 307 | object genericData2 = DragAndDrop.GetGenericData("CustomDragID"); 308 | if (GUIClipHelper.visibleRect.Contains(Event.current.mousePosition) && genericData2 != null) 309 | { 310 | DragAndDrop.visualMode = ((!this.ilvState.rect.Contains(Event.current.mousePosition)) ? DragAndDropVisualMode.None : DragAndDropVisualMode.Move); 311 | Event.current.Use(); 312 | } 313 | } 314 | } 315 | } 316 | } 317 | if (this.ilvState.beganHorizontal) 318 | { 319 | EditorGUILayout.EndScrollView(); 320 | GUILayout.EndHorizontal(); 321 | this.ilvState.beganHorizontal = false; 322 | } 323 | if (this.isLayouted) 324 | { 325 | } 326 | this.ilvState.wantsReordering = false; 327 | this.ilvState.wantsExternalFiles = false; 328 | } 329 | else 330 | { 331 | if (this.isLayouted) 332 | { 333 | } 334 | } 335 | if (this.isLayouted) 336 | { 337 | if (!this.quiting) 338 | { 339 | GUILayout.BeginHorizontal(GUIStyle.none, new GUILayoutOption[0]); 340 | } 341 | else 342 | { 343 | GUILayout.EndHorizontal(); 344 | } 345 | } 346 | return !this.quiting; 347 | } 348 | public void Reset() 349 | { 350 | this.xPos = -1; 351 | this.yPos = this.yFrom; 352 | } 353 | public IEnumerator GetEnumerator() 354 | { 355 | return this; 356 | } 357 | public void Dispose() 358 | { 359 | } 360 | } 361 | public static bool OSX = Application.platform == RuntimePlatform.OSXEditor; 362 | internal static int dragControlID = -1; 363 | private static bool DoLVPageUpDown(ListViewShared.InternalListViewState ilvState, ref int selectedRow, ref Vector2 scrollPos, bool up) 364 | { 365 | int num = ilvState.endRow - ilvState.invisibleRows; 366 | if (up) 367 | { 368 | if (!ListViewShared.OSX) 369 | { 370 | selectedRow -= num; 371 | if (selectedRow < 0) 372 | { 373 | selectedRow = 0; 374 | } 375 | return true; 376 | } 377 | scrollPos.y -= (float)(ilvState.state.rowHeight * num); 378 | if (scrollPos.y < 0f) 379 | { 380 | scrollPos.y = 0f; 381 | } 382 | } 383 | else 384 | { 385 | if (!ListViewShared.OSX) 386 | { 387 | selectedRow += num; 388 | if (selectedRow >= ilvState.state.totalRows) 389 | { 390 | selectedRow = ilvState.state.totalRows - 1; 391 | } 392 | return true; 393 | } 394 | scrollPos.y += (float)(ilvState.state.rowHeight * num); 395 | } 396 | return false; 397 | } 398 | internal static bool ListViewKeyboard(ListViewShared.InternalListViewState ilvState, int totalCols) 399 | { 400 | int totalRows = ilvState.state.totalRows; 401 | return Event.current.type == EventType.KeyDown && totalRows != 0 && GUIUtility.keyboardControl == ilvState.state.ID && Event.current.GetTypeForControl(ilvState.state.ID) == EventType.KeyDown && ListViewShared.SendKey(ilvState, Event.current.keyCode, totalCols); 402 | } 403 | internal static bool SendKey(ListViewShared.InternalListViewState ilvState, KeyCode keyCode, int totalCols) 404 | { 405 | ListViewState state = ilvState.state; 406 | switch (keyCode) 407 | { 408 | case KeyCode.UpArrow: 409 | if (state.row > 0) 410 | { 411 | state.row--; 412 | } 413 | goto IL_136; 414 | case KeyCode.DownArrow: 415 | if (state.row < state.totalRows - 1) 416 | { 417 | state.row++; 418 | } 419 | goto IL_136; 420 | case KeyCode.RightArrow: 421 | if (state.column < totalCols - 1) 422 | { 423 | state.column++; 424 | } 425 | goto IL_136; 426 | case KeyCode.LeftArrow: 427 | if (state.column > 0) 428 | { 429 | state.column--; 430 | } 431 | goto IL_136; 432 | case KeyCode.Home: 433 | state.row = 0; 434 | goto IL_136; 435 | case KeyCode.End: 436 | state.row = state.totalRows - 1; 437 | goto IL_136; 438 | case KeyCode.PageUp: 439 | if (!ListViewShared.DoLVPageUpDown(ilvState, ref state.row, ref state.scrollPos, true)) 440 | { 441 | Event.current.Use(); 442 | return false; 443 | } 444 | goto IL_136; 445 | case KeyCode.PageDown: 446 | if (!ListViewShared.DoLVPageUpDown(ilvState, ref state.row, ref state.scrollPos, false)) 447 | { 448 | Event.current.Use(); 449 | return false; 450 | } 451 | goto IL_136; 452 | } 453 | return false; 454 | IL_136: 455 | state.scrollPos = ListViewShared.ListViewScrollToRow(ilvState, state.scrollPos, state.row); 456 | Event.current.Use(); 457 | return true; 458 | } 459 | internal static bool HasMouseDown(ListViewShared.InternalListViewState ilvState, Rect r) 460 | { 461 | return ListViewShared.HasMouseDown(ilvState, r, 0); 462 | } 463 | internal static bool HasMouseDown(ListViewShared.InternalListViewState ilvState, Rect r, int button) 464 | { 465 | if (Event.current.type == EventType.MouseDown && Event.current.button == button && r.Contains(Event.current.mousePosition)) 466 | { 467 | GUIUtility.hotControl = ilvState.state.ID; 468 | GUIUtility.keyboardControl = ilvState.state.ID; 469 | Event.current.Use(); 470 | return true; 471 | } 472 | return false; 473 | } 474 | internal static bool HasMouseUp(ListViewShared.InternalListViewState ilvState, Rect r) 475 | { 476 | return ListViewShared.HasMouseUp(ilvState, r, 0); 477 | } 478 | internal static bool HasMouseUp(ListViewShared.InternalListViewState ilvState, Rect r, int button) 479 | { 480 | if (Event.current.type == EventType.MouseUp && Event.current.button == button && r.Contains(Event.current.mousePosition)) 481 | { 482 | GUIUtility.hotControl = 0; 483 | Event.current.Use(); 484 | return true; 485 | } 486 | return false; 487 | } 488 | internal static bool MultiSelection(ListViewShared.InternalListViewState ilvState, int prevSelected, int currSelected, ref int initialSelected, ref bool[] selectedItems) 489 | { 490 | bool shift = Event.current.shift; 491 | bool actionKey = EditorGUI.actionKey; 492 | bool result = false; 493 | if ((shift || actionKey) && initialSelected == -1) 494 | { 495 | initialSelected = prevSelected; 496 | } 497 | if (shift) 498 | { 499 | int num = Math.Min(initialSelected, currSelected); 500 | int num2 = Math.Max(initialSelected, currSelected); 501 | if (!actionKey) 502 | { 503 | for (int i = 0; i < num; i++) 504 | { 505 | if (selectedItems[i]) 506 | { 507 | result = true; 508 | } 509 | selectedItems[i] = false; 510 | } 511 | for (int j = num2 + 1; j < selectedItems.Length; j++) 512 | { 513 | if (selectedItems[j]) 514 | { 515 | result = true; 516 | } 517 | selectedItems[j] = false; 518 | } 519 | } 520 | if (num < 0) 521 | { 522 | num = num2; 523 | } 524 | for (int k = num; k <= num2; k++) 525 | { 526 | if (!selectedItems[k]) 527 | { 528 | result = true; 529 | } 530 | selectedItems[k] = true; 531 | } 532 | } 533 | else 534 | { 535 | if (actionKey) 536 | { 537 | selectedItems[currSelected] = !selectedItems[currSelected]; 538 | initialSelected = currSelected; 539 | result = true; 540 | } 541 | else 542 | { 543 | if (!selectedItems[currSelected]) 544 | { 545 | result = true; 546 | } 547 | for (int l = 0; l < selectedItems.Length; l++) 548 | { 549 | if (selectedItems[l] && currSelected != l) 550 | { 551 | result = true; 552 | } 553 | selectedItems[l] = false; 554 | } 555 | initialSelected = -1; 556 | selectedItems[currSelected] = true; 557 | } 558 | } 559 | if (ilvState != null) 560 | { 561 | ilvState.state.scrollPos = ListViewShared.ListViewScrollToRow(ilvState, currSelected); 562 | } 563 | return result; 564 | } 565 | internal static Vector2 ListViewScrollToRow(ListViewShared.InternalListViewState ilvState, int row) 566 | { 567 | return ListViewShared.ListViewScrollToRow(ilvState, ilvState.state.scrollPos, row); 568 | } 569 | internal static int ListViewScrollToRow(ListViewShared.InternalListViewState ilvState, int currPosY, int row) 570 | { 571 | return (int)ListViewShared.ListViewScrollToRow(ilvState, new Vector2(0f, (float)currPosY), row).y; 572 | } 573 | internal static Vector2 ListViewScrollToRow(ListViewShared.InternalListViewState ilvState, Vector2 currPos, int row) 574 | { 575 | if (ilvState.invisibleRows < row && ilvState.endRow > row) 576 | { 577 | return currPos; 578 | } 579 | if (row <= ilvState.invisibleRows) 580 | { 581 | currPos.y = (float)(ilvState.state.rowHeight * row); 582 | } 583 | else 584 | { 585 | currPos.y = (float)(ilvState.state.rowHeight * (row + 1) - ilvState.rectHeight); 586 | } 587 | if (currPos.y < 0f) 588 | { 589 | currPos.y = 0f; 590 | } 591 | else 592 | { 593 | if (currPos.y > (float)(ilvState.state.totalRows * ilvState.state.rowHeight - ilvState.rectHeight)) 594 | { 595 | currPos.y = (float)(ilvState.state.totalRows * ilvState.state.rowHeight - ilvState.rectHeight); 596 | } 597 | } 598 | return currPos; 599 | } 600 | } 601 | } 602 | -------------------------------------------------------------------------------- /Assets/Editor/ListView/ListViewShared.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7870d2228ef934b4588ef3d9126344a6 3 | timeCreated: 1460785718 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Editor/ListView/ListViewState.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | namespace WH.Editor 4 | { 5 | [Serializable] 6 | public class ListViewState 7 | { 8 | private const int c_rowHeight = 16; 9 | public int row; 10 | public int column; 11 | public Vector2 scrollPos; 12 | public int totalRows; 13 | public int rowHeight; 14 | public int ID; 15 | public bool selectionChanged; 16 | public int draggedFrom; 17 | public int draggedTo; 18 | public bool drawDropHere; 19 | public Rect dropHereRect = new Rect(0f, 0f, 0f, 0f); 20 | public string[] fileNames; 21 | public int customDraggedFromID; 22 | public ListViewState() 23 | { 24 | this.Init(0, c_rowHeight); 25 | } 26 | public ListViewState(int totalRows) 27 | { 28 | this.Init(totalRows, c_rowHeight); 29 | } 30 | public ListViewState(int totalRows, int rowHeight) 31 | { 32 | this.Init(totalRows, rowHeight); 33 | } 34 | private void Init(int totalRows, int rowHeight) 35 | { 36 | this.row = -1; 37 | this.column = 0; 38 | this.scrollPos = Vector2.zero; 39 | this.totalRows = totalRows; 40 | this.rowHeight = rowHeight; 41 | this.selectionChanged = false; 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Assets/Editor/ListView/ListViewState.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 91b978051a71e3844a811fd6f28f05dc 3 | timeCreated: 1460785719 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Editor/ListView/helper.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 924fca9ed2a441443898e8ec4b15cdd1 3 | folderAsset: yes 4 | timeCreated: 1460785766 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Editor/ListView/helper/GUIClipHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Reflection; 4 | using UnityEditor; 5 | using UnityEngine; 6 | 7 | public static class GUIClipHelper 8 | { 9 | private static Func VisibleRect; 10 | 11 | public static void InitType() 12 | { 13 | if (VisibleRect != null) 14 | { 15 | return; 16 | } 17 | var tyGUIClip = Type.GetType("UnityEngine.GUIClip,UnityEngine"); 18 | if (tyGUIClip != null) 19 | { 20 | var piVisibleRect = tyGUIClip.GetProperty("visibleRect", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); 21 | if (piVisibleRect != null) 22 | { 23 | var getMethod = piVisibleRect.GetGetMethod(true) ?? piVisibleRect.GetGetMethod(false); 24 | VisibleRect = (Func)Delegate.CreateDelegate(typeof(Func), getMethod); 25 | } 26 | } 27 | } 28 | 29 | public static Rect visibleRect 30 | { 31 | get 32 | { 33 | InitType(); 34 | return VisibleRect(); 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /Assets/Editor/ListView/helper/GUIClipHelper.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 950b8d1986ce07643b0a713b9b7f785d 3 | timeCreated: 1460194449 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Editor/TestListView.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections.Generic; 3 | using UnityEditor; 4 | using WH.Editor; 5 | 6 | public class TestListView : EditorWindow 7 | { 8 | protected List m_MsgList; 9 | 10 | protected ListViewState m_ListView; 11 | protected bool m_Focus; 12 | 13 | protected class Styles 14 | { 15 | public readonly GUIStyle listItem = new GUIStyle("PR Label"); 16 | public readonly GUIStyle listItemBackground = new GUIStyle("CN EntryBackOdd"); 17 | public readonly GUIStyle listItemBackground2 = new GUIStyle("CN EntryBackEven"); 18 | public readonly GUIStyle listBackgroundStyle = new GUIStyle("CN Box"); 19 | public Styles() 20 | { 21 | Texture2D background = this.listItem.hover.background; 22 | // 开启即失去焦点时,也显示蓝色 23 | //this.listItem.onNormal.background = background; 24 | this.listItem.onActive.background = background; 25 | this.listItem.onFocused.background = background; 26 | } 27 | } 28 | protected static Styles s_Styles; 29 | 30 | [MenuItem("Test/ListView default")] 31 | static void Init() 32 | { 33 | GetWindow(typeof(TestListView)); 34 | } 35 | 36 | public TestListView() 37 | { 38 | m_ListView = new ListViewState(); 39 | m_MsgList = new List(); 40 | m_MsgList.Add("第一行"); 41 | m_MsgList.Add("第二行数据"); 42 | m_MsgList.Add("第三行内容"); 43 | } 44 | 45 | private void OnGUI() 46 | { 47 | if (s_Styles == null) 48 | { 49 | s_Styles = new Styles(); 50 | } 51 | m_ListView.totalRows = m_MsgList.Count; 52 | 53 | Event current = Event.current; 54 | EditorGUILayout.BeginVertical(); 55 | GUIContent textContent = new GUIContent(); 56 | foreach (ListViewElement el in ListViewGUI.ListView(m_ListView, s_Styles.listBackgroundStyle)) 57 | { 58 | if (current.type == EventType.MouseDown && current.button == 0 && el.position.Contains(current.mousePosition) && current.clickCount == 2) 59 | { 60 | Debug.Log(el.row); 61 | } 62 | if (current.type == EventType.Repaint) 63 | { 64 | textContent.text = GetRowText(el); 65 | 66 | // 交替显示不同背景色 67 | GUIStyle style = (el.row%2 != 0) ? s_Styles.listItemBackground2 : s_Styles.listItemBackground; 68 | style.Draw(el.position, false, false, m_ListView.row == el.row, false); 69 | s_Styles.listItem.Draw(el.position, textContent, false, false, m_ListView.row == el.row, m_Focus); 70 | } 71 | } 72 | EditorGUILayout.EndVertical(); 73 | } 74 | 75 | protected string GetRowText(ListViewElement el) 76 | { 77 | return m_MsgList[el.row]; 78 | } 79 | 80 | private void OnFocus() 81 | { 82 | m_Focus = true; 83 | } 84 | 85 | private void OnLostFocus() 86 | { 87 | m_Focus = false; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /Assets/Editor/TestListView.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a72665cf2f97cbb4aa6c76fab7239481 3 | timeCreated: 1460785837 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Editor/TestListViewButton.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using UnityEditor; 3 | using UnityEngine; 4 | using WH.Editor; 5 | 6 | public class TestListViewButton : TestListView 7 | { 8 | 9 | [MenuItem("Test/ListView Button")] 10 | static void Init() 11 | { 12 | GetWindow(typeof(TestListViewButton)); 13 | } 14 | 15 | private void OnGUI() 16 | { 17 | if (s_Styles == null) 18 | { 19 | s_Styles = new Styles(); 20 | } 21 | s_Styles.listItem.fixedHeight = 22f; 22 | m_ListView.totalRows = m_MsgList.Count; 23 | m_ListView.rowHeight = 22; 24 | 25 | Event current = Event.current; 26 | EditorGUILayout.BeginVertical(); 27 | GUIContent textContent = new GUIContent(); 28 | Rect btnRect = new Rect(); 29 | foreach (ListViewElement el in ListViewGUI.ListView(m_ListView, s_Styles.listBackgroundStyle)) 30 | { 31 | btnRect = el.position; 32 | btnRect.x += btnRect.width - 32f; 33 | btnRect.y += 2f; 34 | btnRect.width = 30f; 35 | btnRect.height = 18f; 36 | 37 | if (current.type == EventType.MouseDown && current.button == 0 && el.position.Contains(current.mousePosition)) 38 | { 39 | if (btnRect.Contains(current.mousePosition)) 40 | { 41 | Debug.Log("点击第" + el.row + "的按钮"); 42 | } 43 | else if (current.clickCount == 2) 44 | { 45 | Debug.Log(el.row); 46 | } 47 | } 48 | if (current.type == EventType.Repaint) 49 | { 50 | textContent.text = GetRowText(el); 51 | 52 | // 交替显示不同背景色 53 | GUIStyle style = (el.row % 2 != 0) ? s_Styles.listItemBackground2 : s_Styles.listItemBackground; 54 | style.Draw(el.position, false, false, m_ListView.row == el.row, false); 55 | s_Styles.listItem.Draw(el.position, textContent, false, false, m_ListView.row == el.row, m_Focus); 56 | 57 | 58 | textContent.text = ">>"; 59 | GUI.skin.button.Draw(btnRect, textContent, false, false, false, false); 60 | } 61 | } 62 | EditorGUILayout.EndVertical(); 63 | s_Styles.listItem.fixedHeight = 16f; 64 | } 65 | } -------------------------------------------------------------------------------- /Assets/Editor/TestListViewButton.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d7f4398fb372ed145968203285015d14 3 | timeCreated: 1461895314 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Editor/TestListViewExternalFiles.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using UnityEditor; 3 | using UnityEngine; 4 | using WH.Editor; 5 | 6 | public class TestListViewExternalFiles : TestListView 7 | { 8 | [MenuItem("Test/ListView ExternalFiles")] 9 | static void Init() 10 | { 11 | GetWindow(typeof(TestListViewExternalFiles)); 12 | } 13 | 14 | private void OnGUI() 15 | { 16 | if (s_Styles == null) 17 | { 18 | s_Styles = new Styles(); 19 | } 20 | m_ListView.totalRows = m_MsgList.Count; 21 | 22 | Event current = Event.current; 23 | EditorGUILayout.BeginVertical(); 24 | GUIContent textContent = new GUIContent(); 25 | foreach (ListViewElement el in ListViewGUI.ListView(m_ListView, ListViewOptions.wantsExternalFiles, s_Styles.listBackgroundStyle)) 26 | { 27 | if (current.type == EventType.MouseDown && current.button == 0 && el.position.Contains(current.mousePosition) && current.clickCount == 2) 28 | { 29 | Debug.Log(el.row); 30 | } 31 | if (current.type == EventType.Repaint) 32 | { 33 | textContent.text = GetRowText(el); 34 | 35 | // 交替显示不同背景色 36 | GUIStyle style = (el.row % 2 != 0) ? s_Styles.listItemBackground2 : s_Styles.listItemBackground; 37 | style.Draw(el.position, false, false, m_ListView.row == el.row, false); 38 | s_Styles.listItem.Draw(el.position, textContent, false, false, m_ListView.row == el.row, m_Focus); 39 | } 40 | } 41 | EditorGUILayout.EndVertical(); 42 | 43 | { 44 | // 拖动文件 45 | if (m_ListView.fileNames != null) 46 | { 47 | m_MsgList.InsertRange(m_ListView.row, m_ListView.fileNames); 48 | } 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /Assets/Editor/TestListViewExternalFiles.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ce8fa334a814bb841af9fe546c4b86d9 3 | timeCreated: 1461836474 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Editor/TestListViewReordering.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using UnityEditor; 3 | using UnityEngine; 4 | using WH.Editor; 5 | 6 | public class TestListViewReordering : TestListView 7 | { 8 | 9 | [MenuItem("Test/ListView Reordering")] 10 | static void Init() 11 | { 12 | GetWindow(typeof(TestListViewReordering)); 13 | } 14 | 15 | private void OnGUI() 16 | { 17 | if (s_Styles == null) 18 | { 19 | s_Styles = new Styles(); 20 | } 21 | m_ListView.totalRows = m_MsgList.Count; 22 | 23 | Event current = Event.current; 24 | EditorGUILayout.BeginVertical(); 25 | GUIContent textContent = new GUIContent(); 26 | foreach (ListViewElement el in ListViewGUI.ListView(m_ListView, ListViewOptions.wantsReordering, s_Styles.listBackgroundStyle)) 27 | { 28 | if (current.type == EventType.MouseDown && current.button == 0 && el.position.Contains(current.mousePosition) && current.clickCount == 2) 29 | { 30 | Debug.Log(el.row); 31 | } 32 | if (current.type == EventType.Repaint) 33 | { 34 | textContent.text = GetRowText(el); 35 | 36 | // 交替显示不同背景色 37 | GUIStyle style = (el.row % 2 != 0) ? s_Styles.listItemBackground2 : s_Styles.listItemBackground; 38 | style.Draw(el.position, false, false, m_ListView.row == el.row, false); 39 | s_Styles.listItem.Draw(el.position, textContent, false, false, m_ListView.row == el.row, m_Focus); 40 | } 41 | } 42 | EditorGUILayout.EndVertical(); 43 | 44 | if (m_ListView.totalRows > 0 && m_ListView.selectionChanged) 45 | { 46 | // 拖动更新 47 | if (m_ListView.draggedFrom != -1 && m_ListView.draggedTo != -1) 48 | { 49 | var tmp = m_MsgList[m_ListView.draggedFrom]; 50 | m_MsgList[m_ListView.draggedFrom] = m_MsgList[m_ListView.row]; 51 | m_MsgList[m_ListView.row] = tmp; 52 | } 53 | } 54 | } 55 | } -------------------------------------------------------------------------------- /Assets/Editor/TestListViewReordering.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c243b623688cbec4383572f8a6cbda5f 3 | timeCreated: 1461833683 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Editor/TestListViewWithCol.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using UnityEditor; 3 | using UnityEngine; 4 | using WH.Editor; 5 | 6 | public class TestListViewWithCol : TestListView 7 | { 8 | private List m_MsgList2; 9 | 10 | private int[] m_ColWidths = new []{100, 100}; 11 | 12 | [MenuItem("Test/ListView Col")] 13 | static void Init() 14 | { 15 | GetWindow(typeof(TestListViewWithCol)); 16 | } 17 | 18 | public TestListViewWithCol() 19 | { 20 | m_MsgList2 = new List(); 21 | m_MsgList2.Add("第二列"); 22 | m_MsgList2.Add("abc"); 23 | m_MsgList2.Add("efg"); 24 | } 25 | 26 | private void OnGUI() 27 | { 28 | if (s_Styles == null) 29 | { 30 | s_Styles = new Styles(); 31 | } 32 | m_ListView.totalRows = m_MsgList.Count; 33 | 34 | Event current = Event.current; 35 | EditorGUILayout.BeginVertical(); 36 | GUIContent textContent = new GUIContent(); 37 | foreach (ListViewElement el in ListViewGUI.ListView(m_ListView, m_ColWidths, s_Styles.listBackgroundStyle)) 38 | { 39 | if (current.type == EventType.MouseDown && current.button == 0 && el.position.Contains(current.mousePosition) && current.clickCount == 2) 40 | { 41 | Debug.Log("点中了" + "行" + el.row + "列" + el.column); 42 | } 43 | if (current.type == EventType.Repaint) 44 | { 45 | textContent.text = GetRowText(el); 46 | 47 | // 交替显示不同背景色 48 | GUIStyle style = (el.row % 2 != 0) ? s_Styles.listItemBackground2 : s_Styles.listItemBackground; 49 | style.Draw(el.position, false, false, m_ListView.row == el.row, false); 50 | s_Styles.listItem.Draw(el.position, textContent, false, false, m_ListView.row == el.row, m_Focus); 51 | } 52 | } 53 | EditorGUILayout.EndVertical(); 54 | } 55 | 56 | private string GetRowText(ListViewElement el) 57 | { 58 | if (el.column == 0) 59 | { 60 | return m_MsgList[el.row]; 61 | } 62 | return m_MsgList2[el.row]; 63 | } 64 | } -------------------------------------------------------------------------------- /Assets/Editor/TestListViewWithCol.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8f255810cd25a9f40af1f4169639a420 3 | timeCreated: 1461833046 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akof1314/UnityEditorListView/c6e2be475eb8962c7b47e871dfb83b08da95918c/ProjectSettings/AudioManager.asset -------------------------------------------------------------------------------- /ProjectSettings/ClusterInputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akof1314/UnityEditorListView/c6e2be475eb8962c7b47e871dfb83b08da95918c/ProjectSettings/ClusterInputManager.asset -------------------------------------------------------------------------------- /ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akof1314/UnityEditorListView/c6e2be475eb8962c7b47e871dfb83b08da95918c/ProjectSettings/DynamicsManager.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akof1314/UnityEditorListView/c6e2be475eb8962c7b47e871dfb83b08da95918c/ProjectSettings/EditorBuildSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akof1314/UnityEditorListView/c6e2be475eb8962c7b47e871dfb83b08da95918c/ProjectSettings/EditorSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/GraphicsSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akof1314/UnityEditorListView/c6e2be475eb8962c7b47e871dfb83b08da95918c/ProjectSettings/GraphicsSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/InputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akof1314/UnityEditorListView/c6e2be475eb8962c7b47e871dfb83b08da95918c/ProjectSettings/InputManager.asset -------------------------------------------------------------------------------- /ProjectSettings/NavMeshAreas.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akof1314/UnityEditorListView/c6e2be475eb8962c7b47e871dfb83b08da95918c/ProjectSettings/NavMeshAreas.asset -------------------------------------------------------------------------------- /ProjectSettings/NetworkManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akof1314/UnityEditorListView/c6e2be475eb8962c7b47e871dfb83b08da95918c/ProjectSettings/NetworkManager.asset -------------------------------------------------------------------------------- /ProjectSettings/Physics2DSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akof1314/UnityEditorListView/c6e2be475eb8962c7b47e871dfb83b08da95918c/ProjectSettings/Physics2DSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/ProjectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akof1314/UnityEditorListView/c6e2be475eb8962c7b47e871dfb83b08da95918c/ProjectSettings/ProjectSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/ProjectVersion.txt: -------------------------------------------------------------------------------- 1 | m_EditorVersion: 5.3.4f1 2 | m_StandardAssetsVersion: 0 3 | -------------------------------------------------------------------------------- /ProjectSettings/QualitySettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akof1314/UnityEditorListView/c6e2be475eb8962c7b47e871dfb83b08da95918c/ProjectSettings/QualitySettings.asset -------------------------------------------------------------------------------- /ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akof1314/UnityEditorListView/c6e2be475eb8962c7b47e871dfb83b08da95918c/ProjectSettings/TagManager.asset -------------------------------------------------------------------------------- /ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akof1314/UnityEditorListView/c6e2be475eb8962c7b47e871dfb83b08da95918c/ProjectSettings/TimeManager.asset -------------------------------------------------------------------------------- /ProjectSettings/UnityAdsSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akof1314/UnityEditorListView/c6e2be475eb8962c7b47e871dfb83b08da95918c/ProjectSettings/UnityAdsSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/UnityConnectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akof1314/UnityEditorListView/c6e2be475eb8962c7b47e871dfb83b08da95918c/ProjectSettings/UnityConnectSettings.asset -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # UnityEditorListView 2 | Unity 编辑器列表控件 3 | 4 | # 功能 5 | * 点击选中 6 | * 键盘移动 7 | * 多行多列 8 | * 拖曳排序 9 | * 接受外部文件拖放 10 | * 支持自定义数据拖曳 11 | 12 | # 截图 13 | ![](https://github.com/akof1314/UnityEditorListView/raw/master/Screenshots/default.png) 14 | 15 | # 说明 16 | 代码提取自 Unity 编辑器反编译出来的代码 -------------------------------------------------------------------------------- /Screenshots/Button.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akof1314/UnityEditorListView/c6e2be475eb8962c7b47e871dfb83b08da95918c/Screenshots/Button.png -------------------------------------------------------------------------------- /Screenshots/Col.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akof1314/UnityEditorListView/c6e2be475eb8962c7b47e871dfb83b08da95918c/Screenshots/Col.png -------------------------------------------------------------------------------- /Screenshots/ExternalFiles.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akof1314/UnityEditorListView/c6e2be475eb8962c7b47e871dfb83b08da95918c/Screenshots/ExternalFiles.png -------------------------------------------------------------------------------- /Screenshots/Reordering.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akof1314/UnityEditorListView/c6e2be475eb8962c7b47e871dfb83b08da95918c/Screenshots/Reordering.png -------------------------------------------------------------------------------- /Screenshots/default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akof1314/UnityEditorListView/c6e2be475eb8962c7b47e871dfb83b08da95918c/Screenshots/default.png -------------------------------------------------------------------------------- /Screenshots/enter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akof1314/UnityEditorListView/c6e2be475eb8962c7b47e871dfb83b08da95918c/Screenshots/enter.png --------------------------------------------------------------------------------