Ejemplo n.º 1
0
        public override void OnPreviewSettings()
        {
            EditorGUI.BeginChangeCheck();
            _selectedAnimationForPreview = EditorGUILayout.Popup(_selectedAnimationForPreview, _animationNames);
            if (EditorGUI.EndChangeCheck())
            {
                _currentAnimation = _spriteAnimator.animations.Where(a => a.name == _animationNames[_selectedAnimationForPreview]).First();
            }


            if (GUILayout.Button(_isPlaying ? _pauseButton : _playButton, EditorStyles.miniButton))
            {
                _startTime = Time.realtimeSinceStartup;
                _isPlaying = !_isPlaying;

                if (_isPlaying)
                {
                    _didWireEditorUpdate      = true;
                    EditorApplication.update += editorUpdate;
                }
                else if (_didWireEditorUpdate)
                {
                    _didWireEditorUpdate      = false;
                    EditorApplication.update -= editorUpdate;
                }
            }
        }
Ejemplo n.º 2
0
        void validateData()
        {
            if (_spriteAnimator == null)
            {
                _spriteAnimator = target as SpriteAnimator;
                _spriteRenderer = _spriteAnimator.GetComponent <SpriteRenderer>();
                _animationNames = _spriteAnimator.animations.Select(a => a.name).ToArray();

                // prep the Play Animation on Start list which needs a "none"
                var tempNames = new List <string>(_animationNames);
                tempNames.Insert(0, "None");
                _animationNamesForInspector = tempNames.ToArray();

                if (_spriteAnimator.playAnimationOnStart != string.Empty)
                {
                    for (var i = 0; i < _spriteAnimator.animations.Length; i++)
                    {
                        if (_spriteAnimator.animations[i].name == _spriteAnimator.playAnimationOnStart)
                        {
                            _selectedAnimation = i;
                            break;
                        }
                    }
                }

                // set the animation for the preview
                _currentAnimation = _spriteAnimator.animations.Where(a => a.name == _animationNames[_selectedAnimation]).First();
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// handles selection in the reorderable list and pressing the edit button. Responsible for setting up the reorderable list
        /// for frame and trigger management.
        /// </summary>
        /// <param name="selectedIndex">Selected index.</param>
        void selectAnimationAtIndex(int selectedIndex)
        {
            _selectedIndex = selectedIndex;
            _reorderableAnimationList.index = selectedIndex;

            // update the preview GUI
            _currentAnimation            = _spriteAnimator.animations[selectedIndex];
            _selectedAnimationForPreview = selectedIndex;

            // prep the reorderable list
            var selectedAnimation = _reorderableAnimationList.serializedProperty.GetArrayElementAtIndex(selectedIndex);

            _reorderableFrameList = new ReorderableList(serializedObject, selectedAnimation.FindPropertyRelative("frames"));
            _reorderableFrameList.elementHeight      = 55;
            _reorderableFrameList.drawHeaderCallback = ( Rect rect ) =>
            {
                EditorGUI.LabelField(rect, "Animation Frames");
            };
            _reorderableFrameList.onAddCallback = ( ReorderableList list ) =>
            {
                list.serializedProperty.InsertArrayElementAtIndex(list.count);

                var prop = list.serializedProperty.GetArrayElementAtIndex(list.count - 1);
                prop.objectReferenceValue = null;
            };
            _reorderableFrameList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) =>
            {
                rect.y += 1;
                var kSpriteSize = 50;

                var prop = _reorderableFrameList.serializedProperty.GetArrayElementAtIndex(index);
                EditorGUI.PropertyField
                (
                    new Rect(rect.x, rect.y, rect.width - kSpriteSize - kOddPaddingInReorderableList, EditorGUIUtility.singleLineHeight),
                    prop, GUIContent.none
                );

                var sprite     = prop.objectReferenceValue as Sprite;
                var spriteRect = new Rect(rect.width - kSpriteSize + kOddPaddingInReorderableList, rect.y, kSpriteSize, kSpriteSize);
                drawSpriteInRect(sprite, spriteRect, new Color(0.8f, 0.8f, 0.8f, 0.5f));
            };
        }