Hello Guest

Author Topic: public animation clip variable  (Read 3571 times)

lwaarbroek

  • Newbie
  • *
  • Posts: 2
    • View Profile
public animation clip variable
« on: January 08, 2013, 08:39:58 pm »
Hey all,

Thanks for creating this wonderful plugin.
I was coming across a minor problem though:
I want my animations to be set by using public inspector variables so that artists can set the proper animation for each character they create. For example: in my AnimManager script I've made 4 animations "slots"; run, attack, death and idle. And I want to be able to set each slot by using the animation library and then selecting a clip from that library.

Is something like this possible? Currently I solved it by just typing in the name of the clip but this is quite inconvenient as you have to check your clip names and have typo's etc.

Thanks,
Luuk

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: public animation clip variable
« Reply #1 on: January 09, 2013, 05:47:20 am »
It is kinda possible, but you will have to code it in.
If everything is from the same library then all you'll need to do is add something like this.

Make a new behaviour and attach it to your animated sprite, or have a link to an animated sprite.
In the inspector code for that behaviour, add something like this

Code: [Select]
string[] clipNames = new string[sprite.anim.clips.Length];
for (int i = 0; i < sprite.anim.clips.Length; ++i)
clipNames[i] = sprite.anim.clips[i].name;

myTarget.RunClip = EditorGUILayout.Popup("Run", myTarget.RunClip, clipNames);

This code is almost entirely lifted from tk2dSpriteAnimationEditor.cs
Refer to that file for a bit more info, but this is more or less sufficient to do what you were asking.

lwaarbroek

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: public animation clip variable
« Reply #2 on: January 09, 2013, 08:57:30 am »
Nice! I'll give it a try as soon as I get home.

Thanks for the quick reply.

Luuk