You can easily use ReorderableList. This will improve the design and efficiency of the editor extension!
The ReorderableList that exists in the UnityEditorInternal namespace is very useful as an array representation when writing Editor extension code. However, it is hard to use for those who use it for the first time. By using this, you can easily and quickly create ReorderableList.
private EasyReorderableList<int> easyList;
public override void OnInspectorGUI()
{
var Target = target as TestScriptable;
//Create new EasyReorderableList instance.
if(easyList == null) easyList = new EasyReorderableList<int>("i", Target.i, Draw);
//Draw
easyList.DoLayoutList();
//Save
EditorUtility.SetDirty(Target);
}
//DrawFunction
public int Draw(Rect rect, int data, bool isActive, bool isFocused)
{
return EditorGUI.IntField(rect, "int", data);
}
- Import EasyReorderableList.
- Write
using CPRUnitySystem;
- Create instance
easyList = new EasyReorderableList<Type>([ListTitle], [Array], [DrawFunction]);
- Draw EasyReorderableList
easyList.DoLayoutList();
// or reorderableList.DoList([Rect]);
- Run EditorUtility.SetDirty
EditorUtility.SetDirty([Target]);
- Download it => ReleasePage
- Import this into your unity project (If you download DLL file, you should create plugins folder.)
UnityEditorInternal namespace and UnityEditor namespace(Only when UNITY_EDITOR is defined)
- Fork it
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create new Pull Request