Morph Animator

This a clip based animation system for the Morph component which allows you to add any number of anim clips which can be selected and played back using the C# methods for the class as shown below. You just need to click the Add Clip button and add as many slots as you need and then fill in the start and end times and loop mode. This component is aimed at scripters who want to have direct control over the animations of the morphing system. Note the clip start and end values are in seconds not frames.

Info

Make sure you uncheck the Animate box in the morph component else the Morph Animator clips will not play.

Mega Animator Param Description

Use Frames

You can choose to define your animation clips in either frames or by time. If you choose frames then the Source FPS value will be used to calculate the timing. So if your 3d package has exported your animation at 24fps then you should enter 24 in the Source FPS box, the default is 30.

Source FPS

The frames per second count that the animation was built at in your 3d package.

Multiple Morphs

If you have a character that is made up of multiple morphs and you would like to control all those morphs at the same time using the same clips then you can check this box, the system will then find and update any morph component in the children of this object.

Linked Update

If your main character has a load of animations already loaded into the main Unity animation system you can select this option to have the system try and match the morph animation to whatever main animation is running on your character, to make this happen you must name the clips below to match the names of the Unity animation clips, then the system will watch the main object for changes to the main Unity animation clip and will look to see if there is a morph anim clip with the same name, if it finds one it will start that playing.

Play On Start

If this is checked then the Playing Clip will be started when the game is run.

Playing Clip

Click this to select the clip you want to be playing. A box will open showing all the clips on this morph to select from.

Add Clip

Click this to append a new clip slot to the bottom of the list. You can then fill in the start and end times and loop mode.

Clip Line

Each clip has a slot here which shows the name of the clip the start and end time or frame number and the anim loop mode, all these values can be edited. The last button is a delete channel button.

You can also control the the play back of clips via the Unity Animation Event system, you just add an event to a Unity Animation clip at the time you need then select ‘PlayClip(int clip)’ from the function selection box and provide the index of the clip you want to start playing at that time. You can find more information on Unity Animation Events Here

The other option is to control the animation from script by calling one of the methods listed below.

C# Functions

This system exposes a set of methods so the morph system can be controlled by clips and code.

bool IsPlaying()

Returns true is an animation is currently being played.

void SetTime(float time)

Allows you to set the time manually if you want to override the animation system.

Parameters
time – Time to set.

float GetTime()

Returns the current time of the animation system.

void PlayClip(int clip)

Starts a new animation by index.

Parameters
clip – The new clip to start playing.

void PlayClip(string name)

Starts a new animation by name, will look through the clip array for a match, if none is found nothing happens.

Parameters
name – Animation clip to start playing.

void Stop()

Stops any animation playing/

int AddClip(string name, float start, float end, MegaRepeatMode loop)

Allows you to easily add a new script via code. Returns the index of the newly created clip.

Parameters
name – Name for the new clip.
start – Start time for the clip.
end – End time for the clip.
loop – Looping mode for the animation, either Loop, Clamp or PingPong.

string[] GetClipNames()

Returns a string array of all the animation clip names.

Animator Classes

public class MegaMorphAnimClip
{
    public string           name;
    public float            start;
    public float            end;
    public MegaRepeatMode   loop;
}

public class MegaMorphAnimator : MonoBehaviour
{
    public MegaMorph                morph;
    public MegaMorphBase[]          morphs;
    public List<MegaMorphAnimClip>  clips;
    public int                      current;
    public float                    t;
    public float                    at;
    public int                      sourceFPS;
    public bool                     useFrames;
}