To follow along. Kenny https://kenney.nl/assets/platformer-pack-remastered.
To create. In the Hierarchy. A new thing is there.
Right click on the Hierarchy => 2D Object => HDAnimation => HDAnimator
Go ahead and give it GameObject a name. I'm going to call mine Player.
If you look at the component it created.
There a few things it does. It creates SpriteRenderer and a HD Animator component. And Sprite Renderer already assigned. But you look. There things.
Container
play on Awake
and a button called
'Open Animator Window'
If you click on Open Animator Window if no Container is assigned. It will ask you if you want to create one.
The container contains several things. It's really the data stored for each animation. But we won't be editing any of that.
This is just one way to create a container. As that will make it and assign it to container.
You can also create it manually.
On project Window.
Right click => HDAnimator => Container
You do have to remind yourself to assign it to container.
The choice is really yours.
(HD Animator) is needed. It allows you to know which gameObject your editing. If you forgot to add a container to HD Animator. The create container will be enable and allow you to make one. Otherwise it will remain disable.
We now created a empty Window. Now it's time for some drag and drop.
Awesome. These will now be part of Player(HD Animation). If you come back. It will be there.
It supports right now
Texture2D and Sprites.
Note : If there a frame already exist in there. It won't add it as it's already there. It uses Unity Default slice tool.
Now Lets add something else. A new Animation.
Click on the Plus way on the button.
Hitting the plus adds a new animation. Double clicking on it will allow you to edit the name of it. You can name it whatever you want. Note to prevent issues in the future. Give them unique names. Every animation should have a different name. The minus of course removes the animation all together.
Now we're getting to the good part. Frames. Timelines.
There several ways to do it. As shown.
Click or drag
Dragging gives you more control as so. As you can place them anywhere on the timeline, or swap them.
The frames on top in order.
Frames per second. This is local. As walk and Idle can have different FPS
Play button. It really play and stop at the same time. you can also use the space bar.
Remove. Select a frame and you can remove it. but delete button on the keyboard
Duplicate. It copies a frame. (Wnd) ctrl + D or (Mac) cmd + D
Insert a blank left.
Insert a blank right.
loop. Loop only effects runtime and not editor.
play on awake. Do you want this animation to play on awake? Only one can be assign at a time.
That all and fine? But what about code.
You'll need
Using HDAnimation;
Then HDAnimator animator;
These are all the expose Methods inside HDAnimator
getSpriteRender // Can't assign it to a spriteRenderer. You got to do it in the inspector. But that a strength.
Play(string); // You can call it a lot. It only changes if detects a different animation name
Stop(); // Stops at the current frame.
Resume(); // Resumes at the current frame
ResetCurrentAnimation(); // Reset current Animation
AssignAnimator(AnimatorContainerSO : AnimatorController); // Those who want a tad bit more control