Hello, so I'm creating a custom editor to trigger spine animations and activate SkeletonAnimation's on a movement system. I have Node's and Trajectory's scripts in this system. On Trajectory script I have a list of AnimationTriggers to help trigger the specific animation and skeleton. But the list of animations of every AnimationTrigger of all AnimationTriggers are not finding the reference to SkeletonDataAsset. I use AnimationTrigger structure on Node script and it's working. Can someone help me?
[System.Serializable]
public struct AnimationTrigger
{
public SkeletonAnimation skeletonAnimation;
[SpineAnimation(dataField: "skeletonAnimation")]
public List<string> animations;
public AnimationTrigger (SkeletonAnimation skeletonAnimation)
{
this.skeletonAnimation = skeletonAnimation;
animations = new List<string>(1);
}
}
[System.Serializable]
public struct AnimationTriggers
{
public List<AnimationTrigger> animationTriggers;
public AnimationTriggers(int size)
{
animationTriggers = new List<AnimationTrigger>(size);
}
}
public class Node : MonoBehaviour
{
public SkeletonAnimation skeletonAnimation;
public List<AnimationTrigger> animationTriggers = new List<AnimationTrigger>(2);
}
// Node custom OnInspector
public override void OnInspectorGUI()
{
EditorGUILayout.LabelField("Characters Animation", EditorStyles.boldLabel);
EditorGUILayout.Space();
EditorGUI.indentLevel += 1;
EditorGUILayout.PropertyField(skeletonAnimation);
serializedObject.ApplyModifiedProperties();
serializedObject.Update();
if (!node.parentNetwork.skeletonsAttachedCharacter.Contains(node.skeletonAnimation))
{
node.skeletonAnimation = null;
}
EditorGUILayout.Space();
EditorGUILayout.PropertyField(animationTriggers);
serializedObject.ApplyModifiedProperties();
serializedObject.Update();
if (node.skeletonAnimation != null)
{
if (animationTriggers.isExpanded)
{
EditorGUI.indentLevel += 1;
EditorGUILayout.PropertyField(animationTriggers.FindPropertyRelative("Array.size"));
serializedObject.ApplyModifiedProperties();
serializedObject.Update();
EditorGUI.indentLevel -= 1;
EditorGUILayout.Space();
}
for (int i = 0; i < animationTriggers.arraySize; i++)
{
AnimationTrigger animationTrigger = node.animationTriggers[i];
if (animationTrigger.skeletonAnimation != node.skeletonAnimation)
{
animationTrigger.animations = new List<string>(1);
}
animationTrigger.skeletonAnimation = node.skeletonAnimation;
node.animationTriggers[i] = animationTrigger;
}
EditorGUI.indentLevel += 1;
if (animationTriggers.isExpanded)
{
for (int i = 0; i < animationTriggers.arraySize; i++)
{
if (i == 0)
{
EditorGUILayout.PropertyField(animationTriggers.GetArrayElementAtIndex(i), new GUIContent("Idles"), true);
}
else if (i == 1)
{
EditorGUILayout.PropertyField(animationTriggers.GetArrayElementAtIndex(i), new GUIContent("Turns"), true);
}
else
{
EditorGUILayout.PropertyField(animationTriggers.GetArrayElementAtIndex(i), new GUIContent("Other"), true);
}
}
}
EditorGUI.indentLevel -= 1;
}
else
{
node.animationTriggers.Clear();
node.animationTriggers.Add(new AnimationTrigger());
node.animationTriggers.Add(new AnimationTrigger());
}
}
//* Trajectory
public class Trajectory: MonoBehaviour
{
public List<SkeletonAnimation> skeletonAnimations = new List<SkeletonAnimation>();
public List<AnimationTriggers> animationTriggers = new List<AnimationTriggers>();
}
public override void OnInspectorGUI()
{
EditorGUILayout.LabelField("Characters Animation", EditorStyles.boldLabel);
EditorGUILayout.Space();
// Skeleton Animations
EditorGUILayout.PropertyField(skeletonAnimations);
serializedObject.ApplyModifiedProperties();
serializedObject.Update();
for (int i = 0; i < skeletonAnimations.arraySize; i++)
{
if (trajectory.skeletonAnimations[i] == null || !trajectory.parentNetwork.skeletonsAttachedCharacter.Contains(trajectory.skeletonAnimations[i]))
{
trajectory.skeletonAnimations.RemoveAt(i);
}
if (skeletonAnimations.isExpanded)
{
EditorGUI.indentLevel += 1;
if (i == 0)
{
if (skeletonAnimations.arraySize > 1)
{
EditorGUILayout.PropertyField(skeletonAnimations.GetArrayElementAtIndex(i), new GUIContent("Side Skeleton"), true);
}
else
{
EditorGUILayout.PropertyField(skeletonAnimations.GetArrayElementAtIndex(i), new GUIContent("Default Skeleton"), true);
}
}
else if (i == 1)
{
if (skeletonAnimations.arraySize > 1)
{
EditorGUILayout.PropertyField(skeletonAnimations.GetArrayElementAtIndex(i), new GUIContent("Up Skeleton"), true);
}
}
else
{
EditorGUILayout.PropertyField(skeletonAnimations.GetArrayElementAtIndex(i), new GUIContent("Other Skeleton"), true);
}
EditorGUI.indentLevel -= 1;
}
}
EditorGUILayout.Space();
serializedObject.ApplyModifiedProperties();
// Animation Triggers
EditorGUILayout.PropertyField(animationTriggers);
serializedObject.ApplyModifiedProperties();
serializedObject.Update();
EditorGUILayout.Space();
if (trajectory.skeletonAnimations.Any())
{
if (animationTriggers.arraySize < skeletonAnimations.arraySize && skeletonAnimations.arraySize > 0)
{
for (int b = 0; b < skeletonAnimations.arraySize; b++)
{
if (b >= trajectory.animationTriggers.Count())
{
AnimationTriggers newATs = new AnimationTriggers(0);
AnimationTrigger at = new AnimationTrigger(trajectory.skeletonAnimations[b]);
newATs.animationTriggers.Add(at);
newATs.animationTriggers.Add(at);
newATs.animationTriggers.Add(at);
newATs.animationTriggers.Add(at);
trajectory.animationTriggers.Add(newATs);
}
else if (trajectory.skeletonAnimations[b] != trajectory.animationTriggers[b].animationTriggers[b].skeletonAnimation)
{
Debug.Log("Entrei");
AnimationTriggers newATs = new AnimationTriggers(0);
AnimationTrigger at = new AnimationTrigger(trajectory.skeletonAnimations[trajectory.animationTriggers.Count() - 1]);
newATs.animationTriggers.Add(at);
newATs.animationTriggers.Add(at);
newATs.animationTriggers.Add(at);
newATs.animationTriggers.Add(at);
trajectory.animationTriggers[b] = newATs;
}
}
}
else if (animationTriggers.arraySize > skeletonAnimations.arraySize)
{
for (int b = 0; b < animationTriggers.arraySize; b++)
{
if (b >= skeletonAnimations.arraySize)
{
trajectory.animationTriggers.RemoveAt(animationTriggers.arraySize - 1);
}
else if (animationTriggers.GetArrayElementAtIndex(b).name != skeletonAnimations.GetArrayElementAtIndex(b).name)
{
trajectory.animationTriggers.RemoveAt(b);
}
}
}
if (animationTriggers.isExpanded)
{
EditorGUI.indentLevel += 1;
serializedObject.ApplyModifiedProperties();
serializedObject.Update();
for (int i = 0; i < animationTriggers.arraySize; i++)
{
SerializedProperty animationTri = animationTriggers.GetArrayElementAtIndex(i);
SerializedProperty animTriggerList = animationTri.FindPropertyRelative("animationTriggers");
if (animationTri != null && animTriggerList != null && trajectory.skeletonAnimations[i] != null)
{
EditorGUILayout.PropertyField(animTriggerList, new GUIContent(trajectory.skeletonAnimations[i].name));
}
else
{
continue;
}
if (animTriggerList.isExpanded)
{
EditorGUI.indentLevel += 1;
for (int l = 0; l < animTriggerList.arraySize; l++)
{
SerializedProperty animationTrigger = animTriggerList.GetArrayElementAtIndex(l);
if (l == 0)
{
EditorGUILayout.PropertyField(animationTrigger, new GUIContent("Walk"), true);
}
else if (l == 1)
{
EditorGUILayout.PropertyField(animationTrigger, new GUIContent("Turn"), true);
}
else if (l == 2)
{
EditorGUILayout.PropertyField(animationTrigger, new GUIContent("Run"), true);
}
else
{
EditorGUILayout.PropertyField(animationTrigger, new GUIContent("Other"), true);
}
}
serializedObject.ApplyModifiedProperties();
serializedObject.Update();
EditorGUI.indentLevel -= 1;
}
}
EditorGUI.indentLevel -= 1;
}
EditorGUILayout.Space();
}
else
{
trajectory.animationTriggers.Clear();
}
}
-> Inspector Images : https://drive.google.com/drive/folders/1moxF3a8DyaFJAYwPNp5Y2ePSTca99aSK?usp=sharing