Created
January 12, 2018 06:31
-
-
Save mikenekoworks/8434f3c68c7431a8c17183275d56b8d9 to your computer and use it in GitHub Desktop.
ReorderableListを使う時毎回、調べて持ってくるのが面倒だからまとめておく
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using UnityEditor; | |
using UnityEditorInternal; | |
[CustomEditor( typeof( Sample ) )] | |
public class SampleEditor : Editor { | |
private ReorderableList reorderableList; | |
private void OnEnable() { | |
Sample sample = ( Sample )target; | |
//ReorderableListを作成 | |
reorderableList = new ReorderableList( | |
elements: ****, //配列要素 | |
elementType: typeof( **** ), //要素の種類 | |
draggable: true, //ドラッグして要素を入れ替えられるか | |
displayHeader: true, //ヘッダーを表示するか | |
displayAddButton: true, //要素追加用の+ボタンを表示するか | |
displayRemoveButton: true //要素削除用の-ボタンを表示するか | |
); | |
reorderableList.drawElementBackgroundCallback = OnDrawElementBackground; | |
reorderableList.drawElementCallback = OnDrawElement; | |
reorderableList.drawFooterCallback = OnDrawFooter; | |
reorderableList.drawHeaderCallback = OnDrawHeader; | |
reorderableList.elementHeightCallback = OnElementHeight; | |
reorderableList.onAddCallback = OnAdd; | |
reorderableList.onAddDropdownCallback = OnAddDropdown; | |
reorderableList.onCanAddCallback = OnCanAdd; | |
reorderableList.onCanRemoveCallback = OnCanRemove; | |
reorderableList.onChangedCallback = OnChanged; | |
reorderableList.onMouseUpCallback = OnMouseUp; | |
reorderableList.onRemoveCallback = OnRemove; | |
reorderableList.onReorderCallback = OnReorder; | |
reorderableList.onSelectCallback = OnSelect; | |
} | |
public override void OnInspectorGUI() { | |
serializedObject.Update(); | |
reorderableList.DoLayoutList(); | |
serializedObject.ApplyModifiedProperties(); | |
} | |
public void OnDrawElementBackground( Rect rect, int index, bool isActive, bool isFocused ) { | |
} | |
public void OnDrawElement( Rect rect, int index, bool isActive, bool isFocused ) { | |
} | |
public void OnDrawFooter( Rect rect ) { | |
} | |
public void OnDrawHeader( Rect rect ) { | |
} | |
public float OnElementHeight( int index ) { | |
return EditorGUIUtility.singleLineHeight; | |
} | |
public void OnAdd( ReorderableList list ) { | |
} | |
public void OnAddDropdown( Rect buttonRect, ReorderableList list ) { | |
} | |
public bool OnCanAdd( ReorderableList list ) { | |
return false; | |
} | |
public bool OnCanRemove( ReorderableList list ) { | |
return false; | |
} | |
public void OnMouseUp( ReorderableList list ) { | |
} | |
public void OnChanged( ReorderableList list ) { | |
} | |
public void OnRemove( ReorderableList list ) { | |
} | |
public void OnReorder( ReorderableList list ) { | |
} | |
public void OnSelect( ReorderableList list ) { | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment