ddionisio / MateAnimator

Adding more features to the open sourced Animator from Unity.
113 stars 29 forks source link

Where's the Code View? #19

Open tomaszzackiewicz opened 7 years ago

tomaszzackiewicz commented 7 years ago

I would like to drive some things in the MateAnimator via code, but I cannot find the Code View that is in the PDF documentation file and I don't know how to start. Do I need a Unity Animator or Animation component attached to the game object? In general, it would be great to get a video tutorial, especially for API and coding. I mean the whole process form adding an object and animate it to manipulate the animation in code like Play, Pause, Stop, resume, etc.

Thank you.

ddionisio commented 7 years ago

Code view and json exporter are disabled for now, much of the infrastructure has changed and those two features would need a major overhaul. I haven't had a chance to look into it.

For the most part, the documentation still explains the core part of how the animation system works. A new documentation and video/project sample are also something I've been meaning to get out. Now that the plugin seem pretty solid at this point.

Once you have the animator dialog open, it should be straightforward from there. Access it from Window->Cutscene Editor. From there, clicking on Create AnimatorData will either add the component on a currently selected GameObject, or create a new GameObject.

The AnimatorData is basically what holds all of the animation info. So this can be part of the root game object, or it can be a child. This is also the Component you'll pretty much interact with in script for playing, pausing, etc.

tomaszzackiewicz commented 7 years ago

Ok, I understand that. But how to control the anim from the code? I have an animated game object and it plays in the Timeline and in the Play mode. But how to control Play, Pause, Stop from the code? And more important for me - what is possible to do at runtime? Can I use the Timeline at runtime, changing for example anim (Keyframes, some properties, etc) during playing?

ddionisio commented 7 years ago

All of those are found in AnimatorData, simply grab that component, and you can check the public access in that script.

The animations are baked into DOTween's sequence, so a lot of the data from AMTakeData, AMTrack, etc. will not have much use at runtime. But you can still manipulate the tweens via the currentPlayingSequence.

With the AnimatorData, you can also add callbacks for when takes complete, or when triggers happen via a Trigger Track.

Example:

var anim = GetComponent<AnimatorData>();

//If you want to respond after a take has finished playing
anim.takeCompleteCallback += delegate(AnimatorData a, AMTakeData take) {
    if(take.name == "death") {
        //proceed to game over
    }
}

//If you want to respond to trigger track
//In this example, you'll want to reference a Transform/GameObject for positioning the spawned projectile
anim.takeTriggerCallback += delegate(AnimatorData a, AMTakeData take, AMKey key, AMTriggerData data) {
    if(data.valString == "fire") {
        //Spawn projectile
    }
}

anim.Play("takename");

//If you want to do stuff with the DOTween sequence, just don't destroy it
var curSequence = anim.currentPlayingSequence;
tomaszzackiewicz commented 7 years ago

Thank you. I needed that. Now, I know what to do.