Is it possible to customize the Scriptableobject inspector for Simple level data, without the use of PropertyDrawers?

I've invented an innovative, new game mechanic for Bricker Breaker Quest and want to create a quick prototype to recruit a game development team. After wasting a week researching the best way to easily represent the simple level data, I reluctantly started using Scriptableobjects. Each level is defined as a List<Block>, where :

public class Block : MonoBehaviour, IComparer<Block>
{
public int x;
public int y;

public int lives = 0;
private int pastLife = 0;

private SpriteRenderer spriteRenderer;
private TextMeshPro text;

private void OnCollisionEnter2D(Collision2D collision)
{
lives--;

if (lives > 0)
UpdateVisualState();
else
{
gameObject.SetActive(false);
}
}

private void Awake()...

}


How do I properly serialize the Block object so that I can enter the X, Y, and Lives integers directly in the Inspector? As a quick hack, I created a List<Vector3Int> instead of the Block List and use the Z input field to enter the lives. Seems like overkill to create a PropertyDrawer just to relabel one field.

• why don't you define a list of Vector3Int (docs.unity3d.com/ScriptReference/Vector3Int.html)? Then, if you really need the IComparer<T> interface, why not making a Block to Vector3Int implicit conversion (docs.microsoft.com/en-us/dotnet/csharp/programming-guide/…) so you can make comparisons? Apr 27 '19 at 21:33
• Sorry if it wasn't clear, but I'm currently using a list of Vector3Int. Wasn't familiar with the conversion operator though. Very useful. Thank you. Apr 28 '19 at 7:20

Do you need the Block class to be a MonoBehaviour? if not, then why not making it a class with the Serializable attribute? That way it will show on the inspector, because otherwise by making a list of MonoBehaviours you will only make object fields of that class on the inspector.

[System.Serializable]
public class Block : IComparer<Block>
{
public int x;
public int y;
public int z;

public int Compare<Block a, Block b>
{
/// Do whatever evaluation you want to make.
return 0;
}
}


And if you need it to be on either a MonoBehaviour or ScriptableObject, then just make a member of Block type:

public class Mono : MonoBehaviour
{
public Block block;
}

// Or...

public class ScriptableClass : ScriptableObject
{
public Block block;
}

• I'd recommend a struct for this data — similar effect, but a little lighter weight on allocations / garbage management. Apr 27 '19 at 22:37
• Totally agree on that. I just copied and modified the asker's code for the sake of giving a quick example. Apr 28 '19 at 0:42
• I'm afraid I underrepresented the Block class properties and methods for simplicity. If the block class is controlling it's Active state and contains both a SpriteRenderer and a TextMeshPro object, it needs to be a MonoBehaviour, right? Can the 2nd recommendation work with the updated class data? Apr 28 '19 at 7:17
• Yes, it would work, but then instead of referencing a Block object, you could instead reference the MonoBehaviour that holds a Block object, so you could get both the active state and the TextMeshPro reference from that same MonoBehaviour. And yes, for the sake of more clarity it would be better to show the main members of a class so anyone here can find out a solution taking those key members into account. Apr 28 '19 at 18:29