Пример #1
0
 private void CacheAnimator(Animator animator)
 {
     if (_animator == null)
     {
         _animator = animator.GetComponent <Spine3DAnimator>();
     }
 }
                        private static void OnSelectionChanged()
                        {
                            if (Selection.activeGameObject != null)
                            {
                                Spine3DAnimator animator = Selection.activeGameObject.GetComponent <Spine3DAnimator>();

                                if (animator != null)
                                {
                                    _animator = animator;
                                }
                            }
                        }
Пример #3
0
                public void SetTrackAsset(TrackAsset trackAsset, PlayableDirector playableDirector)
                {
                    _trackAsset   = trackAsset as Spine3DAnimatorTrack;
                    _director     = playableDirector;
                    _trackBinding = _director.GetGenericBinding(trackAsset) as Spine3DAnimator;

                    if (_trackBinding != null)
                    {
                        _animationStates = new AnimationState[_trackBinding._renderer._animationSets.Length];

                        for (int i = 0; i < _animationStates.Length; i++)
                        {
                            SpineAnimator spineAnimator = _trackBinding._renderer._animationSets[i]._animatior;
                            _animationStates[i] = new AnimationState(spineAnimator.GetSkeletonAnimation().SkeletonDataAsset.GetAnimationStateData());
                        }
                    }
                }
                    public override void OnInspectorGUI()
                    {
                        serializedObject.Update();

                        SerializedProperty animationIdProperty       = serializedObject.FindProperty("_animationId");
                        SerializedProperty animationDurationProperty = serializedObject.FindProperty("_animationDuration");
                        SerializedProperty animationSpeedProperty    = serializedObject.FindProperty("_animationSpeed");

                        Spine3DAnimationClipAsset clip     = (Spine3DAnimationClipAsset)target;
                        Spine3DAnimator           animator = GetClipBoundAnimator(clip);

                        if (animator != null)
                        {
                            string[] animationNames = animator.GetAnimationNames();

                            int currentIndex = -1;

                            for (int i = 0; i < animationNames.Length; i++)
                            {
                                if (animationNames[i] == animationIdProperty.stringValue)
                                {
                                    currentIndex = i;
                                    break;
                                }
                            }

                            int index = EditorGUILayout.Popup("Animation", currentIndex == -1 ? 0 : currentIndex, animationNames);

                            if (currentIndex != index)
                            {
                                clip.name = animationNames[index];
                                animationIdProperty.stringValue       = animationNames[index];
                                animationDurationProperty.doubleValue = animator.GetAnimationLength(animationNames[index]);
                            }
                        }
                        else
                        {
                            GUI.enabled = false;
                            EditorGUILayout.PropertyField(animationIdProperty);
                            GUI.enabled = true;
                        }

                        EditorGUILayout.PropertyField(animationSpeedProperty);

                        serializedObject.ApplyModifiedProperties();
                    }
                    public override void OnInspectorGUI()
                    {
                        SerializedProperty animationIdProperty = serializedObject.FindProperty("_animationName");
                        Spine3DAnimator    animator            = EditorHelper.GetLastInspectedSpineAnimator();

                        if (animator != null)
                        {
                            string[] animationNames = animator.GetAnimationNames();
                            int      currentIndex   = -1;

                            for (int i = 0; i < animationNames.Length; i++)
                            {
                                if (animationNames[i] == animationIdProperty.stringValue)
                                {
                                    currentIndex = i;
                                    break;
                                }
                            }

                            int index = EditorGUILayout.Popup("Animation", currentIndex == -1 ? 0 : currentIndex, animationNames);

                            if (currentIndex != index)
                            {
                                animationIdProperty.stringValue = animationNames[index];
                                serializedObject.ApplyModifiedProperties();

                                if (Application.isPlaying)
                                {
                                    ((SpineAnimatorStateBehaviour)target).ForceUpdate();
                                }
                            }
                        }
                        else
                        {
                            GUI.enabled = false;
                            EditorGUILayout.PropertyField(animationIdProperty);
                            GUI.enabled = true;
                        }
                    }