Exemple #1
0
        /// Update the list of animatables.
        private void UpdateAnimatables()
        {
            // If the user removes a controller from the scene in the middle of a draw call, the index in the for loop stays the same but _animatables.Count diminishes.
            // Since this is pretty much inevitable, and will correct itself next frame, what we do is swallow the exception and wait for the next draw call.
            try
            {
                if (_animators.Count != 0 &&
                    _currentAnimatablesIndex < _animators.Count &&
                    _animators[_currentAnimatablesIndex] != null)
                {
                    RevertToPreviousAnimator(_animators[_currentAnimatablesIndex]);
                }

                _animators.Clear();
                _animations.Clear();
                _animators       = AnimatorHandler.GetObjectsWithAnimator();
                _animations      = AnimationHandler.GetObjectsWithAnimation();
                _animatableNames = null;
                _animatableNames = AnimationClipHandler.GetNames(_animators, _animations);
                _clipNamesBackup.Clear();
                _clipNamesBackup = AnimationClipHandler.BuildClipNamesBackup(_animators, _animations);

                _controllersBackup.Clear();
                _controllersBackup = AnimatorHandler.BuildControllersBackup(_animators);
            }
            catch (System.Exception) {}
        }
Exemple #2
0
        private void OnEnable()
        {
        #if UNITY_5_3_OR_NEWER || UNITY_5_1 || UNITY_5_2
            titleContent = new GUIContent("AnimationTester");
        #else
            title = "AnimationTester";
        #endif

            Instance = this;

            // Load current preferences (like colours, etc.).
            // We do this here so that most preferences are updated as soon as they're changed.
            Preferences.GetAllPrefValues();

            LoadSkin();
            LoadStyles();

            // Populate list of gameobjects with animator/animation, but only once.
            if (_collectedAnimatables == false)
            {
                _animators            = AnimatorHandler.GetObjectsWithAnimator();
                _animations           = AnimationHandler.GetObjectsWithAnimation();
                _collectedAnimatables = true;
                _animatableNames      = AnimationClipHandler.GetNames(_animators, _animations);

                // Build the backups.
                _clipNamesBackup = AnimationClipHandler.BuildClipNamesBackup(_animators, _animations);

            #if !UNITY_5_4_OR_NEWER
                _controllersBackup = AnimatorHandler.BuildControllersBackup(_animators);
            #endif
            }
        }
Exemple #3
0
        /// Draw the "Play" button.
        private void DrawPlay()
        {
            Rect       playRect;
            GUIContent playContent;


            SetupButton_Play(out playRect, out playContent);
            if (Controls.Button(playRect, playContent))
            {
                if (!Application.isPlaying)
                {
                    var sceneWindow = (SceneView)GetWindow(typeof(SceneView));
                    sceneWindow.ShowNotification(new GUIContent("To play an animation you must be in Play mode."));
                }
                else
                {
                    if (_currentAnimatablesIndex < _animators.Count)
                    {
                        AnimatorHandler.PlayAnimation(_animators[_currentAnimatablesIndex], _animatableClips[_currentClipIndex]);
                    }
                    else
                    {
                        AnimationHandler.PlayAnimation(_animations[_currentAnimatablesIndex - _animators.Count], _animatableClips[_currentClipIndex]);
                    }
                }
            }
        }