-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ability to collect resources #38
Merged
Merged
Conversation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The Job Story
Player: When I press E, I want to mine a resource, so that I can collect the resource once done mining.
Notion
Deliberate Practice
Development Checklist
Files changed
and revise anything that needs to be cleaned up.Quality Assurance Checklist
Screen Recording
animations.mov
Changelog
StateMachine
frameworkStateMachine
frameworkThirdPartyAssets
framework for referencing third party assetsPlugins/
foldersHow it works
Updating the Mecanim state machine
If you ignore the numerous detours and tangents 😅, this pull request primarily implements the ability to collect resources.
You can press E to collect any of the resources in the world.
Currently, there are 8 collectable resources:
Which can be categorized into 3 animations:
Implementing the 3 animations required updating the Mecanim state machine for the player.
To keep the implementation maintainable, I used the “hub and spoke” pattern as described by William Armstrong in his Unite presentation.
The idea is to have a single “PlayerState” animation parameter, and to use that integer as an enum for switching between the various animation states:
This makes it nice to add more animation states in the future. You just add a new state, add a transition from the empty state to the new state, and add a transition back to the empty state.
The transition conditions are simply “PlayerState equals
<enum integer>
”, or “PlayerState does not equal<enum integer>
”.Using the state machine pattern
Because the player had all these different animation states, it made sense to extend these visual states to the underlying logical states as well.
Thus, I implemented a simple state machine framework, where a
StateMachineBehaviour
MonoBehaviour would selectively enable/disableStateBehaviours
on the same GameObject to maintain a single active state.(So there'd only ever be one
StateBehaviour
active at any time.)Also note that you can inspect the
Current State
. It’s the custom label at the top of the “Player State Machine” inspector:The
PlayerAnimator
would then use the currently active state to set thePlayerState
animation parameter:I map between Resources, StateBehaviours, and PlayerState enums with lists of serializable
Mapping
classes, which I use for lookup:Breadforge/Assets/Scripts/Behaviours/PlayerStateMachine/PlayerStateMachine.cs
Lines 30 to 50 in 4c69f0c
Lookup is not as efficient as a
Dictionary
, but it gets the job done! Besides, the list is only a few elements long.Pipelines
While doing all this, I realized that the player may have even more animations in the future. Perhaps for building structures, or performing any of a variety of crafting animations.
So I added a few more checklists to the
.github/PULL_REQUEST_TEMPLATE/
directory. Reducing the creative process to a few worksheets makes the work far more approachable.You don’t need to think; you just follow instructions!
(And yes, the irony of making a factory building game while optimizing my own game building process is not lost on me.)
I’m excited to juice up this mechanic in following pull requests. Sound is first on my list of priorities.
Final Checklist