Featured Blog | This community-written post highlights the best of what the game industry has to offer. Read more like it on the Game Developer Blogs or learn how to Submit Your Own Blog Post
Property Drawers for Active frames of an animation in Unity
We'll learn to make a PropertyDrawer to check active frames of an animation.
Explanation
So you implemented the FrameChecker from the last post but your editor is looking pretty bad. If you managed to make the FrameChecker appear in the inspector, you are seeing 3 integer boxes. Besides not looking great, it's probably making it hard for you to quickly modify things and have an idea of what you are actually doing.
Let's refresh what that class does. We created the FrameChecker to give it an animation clip and a range of frames in which we want to do something. For example, an attack. The animation for a punch may have 12 frames, but we only want to do damage in frames 4 to 8.
Problems
With the standard inspector you can input any frame number. You could even input negative frame numbers, or one greater than the total number of frames. Also you could make the start of the range bigger than the end, like hitting in frames 9 to 2. All of those are invalid states for our class, they break the implicit contract we were thinking of when we made it.
What do we want?
We want to enforce the contract, so you (or whoever uses this class) can only use valid inputs and therefore get valid outputs. Also we want a clear input interface and a way to provide visual feedback for valid and invalid values.
The Contract
The minimum possible frame number is 1.
The maximum possible frame number is the total frame number that the animation has.
hitFrameEnd