Created
August 8, 2018 22:36
-
-
Save beardordie/139affe81a0492e2a0725928c004adae to your computer and use it in GitHub Desktop.
Nested Classes
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
// Use a class that does not inherit from MonoBehaviour and has attribute [System.Serializable] | |
// then reference that in a MonoBehaviour class. This results in a dropdown in the Inspector | |
// for the referenced class. | |
// The documentation says to have the NestedClass inherit from System.Object but I've seen no need for that. | |
// For more robust functionality, consider creating a ScriptableObject/template for the Nested Classes, | |
// then reference those. It won't drop down in the inspector the same way, but it affords other benefits. | |
using UnityEngine; | |
public class NestedClassHolder : MonoBehaviour | |
{ | |
public NestedClass1 nestedClass1; | |
} | |
[System.Serializable] | |
public class NestedClass1 | |
{ | |
public float myFloat = 5.5f; | |
public Color myColor = Color.blue; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Alternative setup:
I'm not sure when this method would be preferable.