- Đã chỉnh sửa
Anim name and file separator
Hi there,
With the awesome new animation folders features came a problem with enum: the "/" required to identify the animation "AttackFolder/Attack1" doesn't work in an enum. So I'm forced to use string instead which doesn't suit well my needs for inspector data editing.
Couple of questions:
Could I use "_" instead of "/" as a separator for "AttackFolder_Attack1"? If so where can I change the code in spine runtime? Couldn't find where the "/" is introduced.
Would you have better workflow suggestions as to how to handle animation ids? Maybe having animation ids getting generated automatically based on the SkeletonData exported, instead of manually creating enum or list of const? Maybe use SkeletonData info directly instead of creating my own name list ? Not sure about all this.
SoulGame đã viếtWith the awesome new animation folders features came a problem with enum: the "/" required to identify the animation "AttackFolder/Attack1" doesn't work in an enum. So I'm forced to use string instead which doesn't suit well my needs for inspector data editing.
How are you currently using the enum values? At some place you are mapping them from enum value to an animation reference (or animation name string), could you please post the code you are using for this mapping?
Well I would like to do a straightforward cast, like
AnimationState.SetAnimation(0, EnumAnimIds.Attack1.ToString());
But then again it can't work with "EnumAnimIds.AttackFolder/Attack1", so I cannot use enum, unless I find a way to use "_" to seperate folder name and animation name. Alternatively, I could have data duplicate between a list of simplified ids in my enum, point to a list of string with full folder/name... But Meh.
Actually, the only reason I want to use enum is to have a safe way to input animation names in the inspector, so what I need is exactly what you use in the SkeletonData inspector window for Mix Settings. You provide a safe drop down menu with animation names. Do you know how I could replicate that on my end?
You could use the dedicated property drawers for that:
[SpineAnimation(dataField:"skeletonDataAsset")] // skeletonDataAsset is the name of the `SkeletonDataAsset` property within the same class
public string startingAnimation;
Would this be an option here?
If not, how are you currently generating your enum names? Are you generating code based on the skeleton .json
file or based on the SkeletonDataAsset
?
Thanks this is exactly what I wanted!
I wasn't generating code, I was copying names manually ^^'
The only downside is that it's not very convenient to have to carry a reference to the SkeletonDataAsset each time I need the animation name, that is, on each of my array element.
I suspect there is no easy way to have only one "Knight_SkeletonData" reference in the main class, that would be used as reference by each of the element of the array ?
Sorry, adding the remark of dataField:"skeletonDataAsset"
caused more harm than it helped. In your case it's better to leave it out (leave it at the default ""
), then it will find the SkeletonRenderer
Component at the same GameObject automatically.
So e.g. the following code should list the same animations as a dropdown as when it contained a SkeletonDataAsset
itself:
public class AnimationPropertyComponent : MonoBehaviour {
[System.Serializable]
public class Entry {
[SpineAnimation]
public string animation;
}
public Entry[] array = new Entry[1];
}
As a different alternative, you could also generate and use Animation Reference Assets
as described here:
spine-unity Runtime Documentation: Preview
This is also shown in this example scene: Spine Examples/Gettings Started/3 Controlling Animation Continued
(Sorry for the late answer)
Thanks for the additional info, I start to understand. But the issue is that we are on a ScriptableObject, there is no SkeletonRenderer here, just data. So instead I added an Odin button with a function to provide a reference of the SkeletonDataAsset to each element of the array, and it worked fine...
But then I realized it was already working! Don't know what I changed, most likely the variable name, but each element from the array now somehow recognize the "skeletonDataAsset" variable from the main ScriptableObject, so I don't need to provide a reference for each of them, which is exactly what I wanted:
So either it's black magic or it seems that the parameters dataField:"skeletonDataAsset" is more powerful that we expected! Looks like it reaches out to all variable on the current gameobject or something like that.
SoulGame đã viếtSo either it's black magic or it seems that the parameters dataField:"skeletonDataAsset" is more powerful that we expected! Looks like it reaches out to all variable on the current gameobject or something like that.
:magic:
In case you want to become a wizard yourself, the code behind the magic can be found here:
spine-runtimes/SpineInspectorUtility.cs at 3.8