[Editor] 2D array, 2차 행렬을 inspector에서 보기 + 빌드 문제
Unity Editor에서는 public으로 선언한 변수에 대해서 inspector에서 값을 변경할 수 있게 해준다.
이러한 사유로 SciptableObject를 상속받는 데이터를 만들어서 사용하려고 한다.
그러나 1D array까지 지원해주지만, 기본적으로 2D array에 대해서는 지원해주지 않는다.
이에 관해 Custom inspector를 만들어 해결할 수 있다.
(Warning)
I didn't test those things. i just type this for remember what i did.
(주의) 아래의 내용들을 테스트 안해봤다. 기억하려고 적어놓은 거.
크게 Editor를 상속받는 방법과 PropertyDrawer를 사용하는 방법이 있는 것 같다.
(결과를 먼저 알고 싶다면, 내용을 생략하고 바로 밑으로 건너 뛰자.
If you guys wanna know how to i solved this issue. just skip main content. and go to the bottom of this post.)
(1) PropertyDrawer는 어떻게 사용하는지 잘모르니 아래의 주소를 참고하자.
:: https://catlikecoding.com/unity/tutorials/editor/custom-data/
(2) Inherit Editor
대충 알기 때문에 개요만 작성하도록 하겠다.
스크립트 생성하고 해당 클래스에 아래와 같은 형태로 작성하자.
[CustomEditor(typeof(ScriptableObjectData))]
public class className : Editor
{}
또한 위와 같은 스크립트가 존재한다면 ScriptableObjectData라는 스크립트도 존재해야 되지 않겠는가.
[CreateAssetMenu(fileName = "NewScriptableObjectData", menuName = "Data/ScriptabelObjectData", order = 1)]
public class ScriptableObjectData : ScriptableObject
{
// we don't care about data type. you can change 'bool type' to 'int type'.
public bool a;
[Range(0,5)]
public int arraySize;
public bool[,] arr = new int[arraySize, arraySize];
}
이제 ScriptableObjectData는 custom inspector의 형태를 띄기 때문에, inspector에서 변수가 표시되지 않을지도 모른다.
예전처럼 inspector에서 변수를 보기 위해서는 일련의 과정을 거쳐야 한다.
[CustomEditor(typeof(ScriptableObjectData))]
public class className : Editor
{
private SerializedProperty a;
void OnEnable()
{
a = serializedObject.FindProperty("a");
}
public override void OnInspectorGUI()
{
EditorGUILayout.PropertyField(a);
}
}
2D array Inspector를 개발해주신 형님의 github link.
:: https://github.com/Eldoir/2DArrayEditor
value = (value / rangeAttribute.step) * rangeAttribute.step + 1; // inside of if statement
error CS0246: The type or namespace name `Editor' could not be found. Are you missing an assembly reference?
<Result Ref>
What is PropertyDrawer
:: https://catlikecoding.com/unity/tutorials/editor/custom-data/
2D array Inspector를 개발해주신 형님의 github link.
:: https://github.com/Eldoir/2DArrayEditor
PropertyDrawer change slider increase step, 1 to 2
Android build issue