Last active
February 22, 2018 09:26
-
-
Save simonwittber/ce2461ed412d65803248a9cc2ebbd15f to your computer and use it in GitHub Desktop.
A unique ID for your Serialized classes in Unity.
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
[Serializable] | |
public class MyClass { | |
public int id; | |
} | |
[CustomPropertyDrawer(typeof(MyClass))] | |
public class MyClassDrawer : PropertyDrawer | |
{ | |
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) | |
{ | |
var idProperty = property.FindPropertyRelative("id"); | |
idProperty.intValue = property.propertyPath.GetHashCode(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note, the GetHashCode() method will probably return a unique ID. There is a very remote chance you will get a clashing ID.