Exemple #1
0
        /**
         * @private
         */
        public void CacheFrames(float frameRate)
        {
            if (cacheFrameRate > 0.0f)
            {
                return;
            }

            cacheFrameRate = Math.Max((float)Math.Ceiling(frameRate * scale), 1.0f);
            var cacheFrameCount = (int)Math.Ceiling(cacheFrameRate * duration) + 1;

            DragonBones.ResizeList(cachedFrames, 0, false);
            DragonBones.ResizeList(cachedFrames, cacheFrameCount, false);

            foreach (var k in boneTimelines.Keys)
            {
                var indices = new List <int>(cacheFrameCount);
                for (int i = 0, l = indices.Capacity; i < l; ++i)
                {
                    indices.Add(-1);
                }

                boneCachedFrameIndices[k] = indices;
            }

            foreach (var k in slotTimelines.Keys)
            {
                var indices = new List <int>(cacheFrameCount);
                for (int i = 0, l = indices.Capacity; i < l; ++i)
                {
                    indices.Add(-1);
                }

                slotCachedFrameIndices[k] = indices;
            }
        }
        public void CopyFrom(AnimationConfig value)
        {
            pauseFadeOut    = value.pauseFadeOut;
            fadeOutMode     = value.fadeOutMode;
            autoFadeOutTime = value.autoFadeOutTime;
            fadeOutEasing   = value.fadeOutEasing;

            additiveBlending = value.additiveBlending;
            displayControl   = value.displayControl;
            pauseFadeIn      = value.pauseFadeIn;
            actionEnabled    = value.actionEnabled;
            playTimes        = value.playTimes;
            layer            = value.layer;
            position         = value.position;
            duration         = value.duration;
            timeScale        = value.timeScale;
            fadeInTime       = value.fadeInTime;
            fadeOutTime      = value.fadeOutTime;
            fadeInEasing     = value.fadeInEasing;
            weight           = value.weight;
            name             = value.name;
            animationName    = value.animationName;
            group            = value.group;

            DragonBones.ResizeList(boneMask, value.boneMask.Count, null);
            for (int i = 0, l = boneMask.Count; i < l; ++i)
            {
                boneMask[i] = value.boneMask[i];
            }
        }
        /**
         * @language zh_CN
         * 设置每种对象池的最大缓存数量。
         * @param classType 对象类型。
         * @param maxCount 最大缓存数量。 (设置为 0 则不缓存)
         * @version DragonBones 4.5
         */
        public static void SetMaxCount(System.Type classType, uint maxCount)
        {
            if (classType != null)
            {
                _maxCountMap[classType] = maxCount;
                if (_poolsMap.ContainsKey(classType))
                {
                    var pool = _poolsMap[classType];
                    if (pool.Count > maxCount)
                    {
                        DragonBones.ResizeList(pool, (int)maxCount, null);
                    }
                }
            }
            else
            {
                _defaultMaxCount = maxCount;
                foreach (var pair in _poolsMap)
                {
                    if (!_maxCountMap.ContainsKey(pair.Key))
                    {
                        continue;
                    }

                    _maxCountMap[pair.Key] = maxCount;

                    var pool = _poolsMap[pair.Key];
                    if (pool.Count > maxCount)
                    {
                        DragonBones.ResizeList(pool, (int)maxCount, null);
                    }
                }
            }
        }
Exemple #4
0
        /**
         * @private
         */
        protected void _replaceSlotDisplay(BuildArmaturePackage dataPackage, DisplayData displayData, Slot slot, int displayIndex)
        {
            if (displayIndex < 0)
            {
                displayIndex = slot.displayIndex;
            }

            if (displayIndex >= 0)
            {
                var displayList = slot.displayList; // Copy.
                if (displayList.Count <= displayIndex)
                {
                    DragonBones.ResizeList(displayList, displayIndex + 1, null);
                }

                if (slot._replacedDisplayDatas.Count <= displayIndex)
                {
                    DragonBones.ResizeList(slot._replacedDisplayDatas, displayIndex + 1, null);
                }

                slot._replacedDisplayDatas[displayIndex] = displayData;

                if (displayData.type == DisplayType.Armature)
                {
                    var childArmature = BuildArmature(displayData.path, dataPackage.dataName);
                    displayList[displayIndex] = childArmature;
                }
                else
                {
                    if (displayData.texture == null)
                    {
                        displayData.texture = _getTextureData(dataPackage.dataName, displayData.path);
                    }

                    var displayDatas = slot.skinSlotData.displays;
                    if (
                        displayData.mesh != null ||
                        (displayIndex < displayDatas.Count && displayDatas[displayIndex].mesh != null)
                        )
                    {
                        displayList[displayIndex] = slot.meshDisplay;
                    }
                    else
                    {
                        displayList[displayIndex] = slot.rawDisplay;
                    }
                }

                slot.displayList = displayList;
            }
        }
        protected TweenType _updateExtensionKeyFrame(ExtensionFrameData current, ExtensionFrameData next, ExtensionFrameData result)
        {
            var tweenType = TweenType.None;

            if (current.type == next.type)
            {
                for (int i = 0, l = current.tweens.Count; i < l; ++i)
                {
                    var tweenDuration = next.tweens[i] - current.tweens[i];
                    result.tweens[i] = tweenDuration;

                    if (tweenDuration > 0.0f)
                    {
                        tweenType = TweenType.Always;
                    }
                }
            }

            if (tweenType == TweenType.None)
            {
                if (result.type != current.type)
                {
                    tweenType   = TweenType.Once;
                    result.type = current.type;
                }

                if (result.tweens.Count != current.tweens.Count)
                {
                    tweenType = TweenType.Once;
                    DragonBones.ResizeList(result.tweens, current.tweens.Count, 0.0f);
                }

                if (result.keys.Count != current.keys.Count)
                {
                    tweenType = TweenType.Once;
                    DragonBones.ResizeList(result.keys, current.keys.Count, 0);
                }

                for (int i = 0, l = current.keys.Count; i < l; ++i)
                {
                    var key = current.keys[i];
                    if (result.keys[i] != key)
                    {
                        tweenType      = TweenType.Once;
                        result.keys[i] = key;
                    }
                }
            }

            return(tweenType);
        }
Exemple #6
0
        override public void _init(Armature armature, AnimationState animationState, FFDTimelineData timelineData)
        {
            base._init(armature, animationState, timelineData);

            _slotFFDVertices = slot._ffdVertices;
            DragonBones.ResizeList(_ffdVertices, _timelineData.frames[0].tweens.Count, 0.0f);
            DragonBones.ResizeList(_durationFFDVertices, _ffdVertices.Count, 0.0f);

            for (int i = 0, l = _ffdVertices.Count; i < l; ++i)
            {
                _ffdVertices[i] = 0.0f;
            }

            for (int i = 0, l = _durationFFDVertices.Count; i < l; ++i)
            {
                _durationFFDVertices[i] = 0.0f;
            }
        }
Exemple #7
0
        override public void FadeIn(Armature armature, AnimationState animationState, FFDTimelineData timelineData, float time)
        {
            base.FadeIn(armature, animationState, timelineData, time);

            _slotFFDVertices  = slot._ffdVertices;
            _durationFFDFrame = BaseObject.BorrowObject <ExtensionFrameData>();
            DragonBones.ResizeList(_durationFFDFrame.tweens, _slotFFDVertices.Count, 0.0f);
            DragonBones.ResizeList(_ffdVertices, _slotFFDVertices.Count, 0.0f);

            for (int i = 0, l = _durationFFDFrame.tweens.Count; i < l; ++i)
            {
                _durationFFDFrame.tweens[i] = 0.0f;
            }

            for (int i = 0, l = _ffdVertices.Count; i < l; ++i)
            {
                _ffdVertices[i] = 0.0f;
            }
        }
Exemple #8
0
        /**
         * @private
         */
        public int SetCacheFrame(Matrix globalTransformMatrix, Transform transform)
        {
            var dataArray   = parent.cachedFrames;
            var arrayOffset = dataArray.Count;

            DragonBones.ResizeList(dataArray, arrayOffset + 10, 0.0f);

            dataArray[arrayOffset]     = globalTransformMatrix.a;
            dataArray[arrayOffset + 1] = globalTransformMatrix.b;
            dataArray[arrayOffset + 2] = globalTransformMatrix.c;
            dataArray[arrayOffset + 3] = globalTransformMatrix.d;
            dataArray[arrayOffset + 4] = globalTransformMatrix.tx;
            dataArray[arrayOffset + 5] = globalTransformMatrix.ty;
            dataArray[arrayOffset + 6] = transform.skewX;
            dataArray[arrayOffset + 7] = transform.skewY;
            dataArray[arrayOffset + 8] = transform.scaleX;
            dataArray[arrayOffset + 9] = transform.scaleY;

            return(arrayOffset);
        }
Exemple #9
0
        /**
         * @private
         */
        internal bool _setDisplayList(List <object> value)
        {
            if (value != null && value.Count > 0)
            {
                if (_displayList.Count != value.Count)
                {
                    DragonBones.ResizeList(_displayList, value.Count, null);
                }

                for (int i = 0, l = value.Count; i < l; ++i) // Retain input render displays.
                {
                    var eachDisplay = value[i];
                    if (
                        eachDisplay != null && eachDisplay != _rawDisplay && eachDisplay != _meshDisplay &&
                        !(eachDisplay is Armature) && !_displayList.Contains(eachDisplay)
                        )
                    {
                        _initDisplay(eachDisplay);
                    }

                    _displayList[i] = eachDisplay;
                }
            }
            else if (_displayList.Count > 0)
            {
                _displayList.Clear();
            }

            if (_displayIndex >= 0 && _displayIndex < _displayList.Count)
            {
                _displayDirty = _display != _displayList[_displayIndex];
            }
            else
            {
                _displayDirty = _display != null;
            }

            _updateDisplayData();

            return(_displayDirty);
        }
        /**
         * @private
         */
        internal void _init(SkinSlotData skinSlotData, object rawDisplay, object meshDisplay)
        {
            if (_skinSlotData != null)
            {
                return;
            }

            _skinSlotData = skinSlotData;

            var slotData = _skinSlotData.slot;

            name = slotData.name;

            _zOrder    = slotData.zOrder;
            _blendMode = slotData.blendMode;
            _colorTransform.CopyFrom(slotData.color);
            _rawDisplay  = rawDisplay;
            _meshDisplay = meshDisplay;
            DragonBones.ResizeList(_textureDatas, _skinSlotData.displays.Count, null);

            _blendModeDirty = true;
            _colorDirty     = true;
        }
Exemple #11
0
        /**
         * @private
         */
        internal void _advanceTime(float passedTime)
        {
            if (!_isPlaying)
            {
                return;
            }

            if (passedTime < 0.0f)
            {
                passedTime = -passedTime;
            }

            if (_armature.inheritAnimation && _armature._parent != null) // Inherit parent animation timeScale.
            {
                passedTime *= _armature._parent._armature.animation.timeScale;
            }

            if (timeScale != 1.0f)
            {
                passedTime *= timeScale;
            }

            var animationStateCount = _animationStates.Count;

            if (animationStateCount == 1)
            {
                var animationState = _animationStates[0];
                if (animationState._fadeState > 0 && animationState._subFadeState > 0)
                {
                    animationState.ReturnToPool();
                    _animationStates.Clear();
                    _animationStateDirty = true;
                    _lastAnimationState  = null;
                }
                else
                {
                    var animationData  = animationState.animationData;
                    var cacheFrameRate = animationData.cacheFrameRate;

                    if (_animationStateDirty && cacheFrameRate > 0.0f) // Update cachedFrameIndices.
                    {
                        _animationStateDirty = false;

                        var bones = _armature.GetBones();
                        for (int i = 0, l = bones.Count; i < l; ++i)
                        {
                            var bone = bones[i];
                            bone._cachedFrameIndices = animationData.GetBoneCachedFrameIndices(bone.name);
                        }

                        var slots = _armature.GetSlots();
                        for (int i = 0, l = slots.Count; i < l; ++i)
                        {
                            var slot = slots[i];
                            slot._cachedFrameIndices = animationData.GetSlotCachedFrameIndices(slot.name);
                        }
                    }

                    if (_timelineStateDirty)
                    {
                        animationState._updateTimelineStates();
                    }

                    animationState._advanceTime(passedTime, cacheFrameRate);
                }
            }
            else if (animationStateCount > 1)
            {
                for (int i = 0, r = 0; i < animationStateCount; ++i)
                {
                    var animationState = _animationStates[i];
                    if (animationState._fadeState > 0 && animationState._fadeProgress <= 0.0f)
                    {
                        r++;
                        animationState.ReturnToPool();
                        _animationStateDirty = true;

                        if (_lastAnimationState == animationState) // Update last animation state.
                        {
                            _lastAnimationState = null;
                        }
                    }
                    else
                    {
                        if (r > 0)
                        {
                            _animationStates[i - r] = animationState;
                        }

                        if (_timelineStateDirty)
                        {
                            animationState._updateTimelineStates();
                        }

                        animationState._advanceTime(passedTime, 0.0f);
                    }

                    if (i == animationStateCount - 1 && r > 0) // Modify animation states size.
                    {
                        DragonBones.ResizeList(_animationStates, animationStateCount - r, null);

                        if (_lastAnimationState == null && _animationStates.Count > 0)
                        {
                            _lastAnimationState = _animationStates[_animationStates.Count - 1];
                        }
                    }
                }

                _cacheFrameIndex = -1;
            }
            else
            {
                _cacheFrameIndex = -1;
            }

            _timelineStateDirty = false;
        }
Exemple #12
0
        /**
         * @private
         */
        protected void _updateDisplayData()
        {
            var prevDisplayData        = _displayData;
            var prevReplaceDisplayData = _replacedDisplayData;
            var prevTextureData        = _textureData;
            var prevMeshData           = _meshData;
            var currentDisplay         = _displayIndex >= 0 && _displayIndex < _displayList.Count ? _displayList[_displayIndex] : null;

            if (_displayIndex >= 0 && _displayIndex < _skinSlotData.displays.Count)
            {
                _displayData = _skinSlotData.displays[_displayIndex];
            }
            else
            {
                _displayData = null;
            }

            if (_displayIndex >= 0 && _displayIndex < _replacedDisplayDatas.Count)
            {
                _replacedDisplayData = _replacedDisplayDatas[_displayIndex];
            }
            else
            {
                _replacedDisplayData = null;
            }

            if (_displayData != prevDisplayData || _replacedDisplayData != prevReplaceDisplayData || this._display != currentDisplay)
            {
                var currentDisplayData = _replacedDisplayData != null ? _replacedDisplayData : _displayData;
                if (currentDisplayData != null && (currentDisplay == _rawDisplay || currentDisplay == _meshDisplay))
                {
                    _textureData = _replacedDisplayData != null ? _replacedDisplayData.texture : _displayData.texture;
                    if (currentDisplay == _meshDisplay)
                    {
                        if (_replacedDisplayData != null && _replacedDisplayData.mesh != null)
                        {
                            _meshData = _replacedDisplayData.mesh;
                        }
                        else
                        {
                            _meshData = _displayData.mesh;
                        }
                    }
                    else
                    {
                        _meshData = null;
                    }

                    // Update pivot offset.
                    if (_meshData != null)
                    {
                        _pivotX = 0.0f;
                        _pivotY = 0.0f;
                    }
                    else if (_textureData != null)
                    {
                        var scale = _armature.armatureData.scale;
                        _pivotX = currentDisplayData.pivot.x;
                        _pivotY = currentDisplayData.pivot.y;

                        if (currentDisplayData.isRelativePivot)
                        {
                            var rect   = _textureData.frame != null ? _textureData.frame : _textureData.region;
                            var width  = rect.width * scale;
                            var height = rect.height * scale;

                            if (_textureData.rotated)
                            {
                                width  = rect.height;
                                height = rect.width;
                            }

                            _pivotX *= width;
                            _pivotY *= height;
                        }

                        if (_textureData.frame != null)
                        {
                            _pivotX += _textureData.frame.x * scale;
                            _pivotY += _textureData.frame.y * scale;
                        }
                    }
                    else
                    {
                        _pivotX = 0.0f;
                        _pivotY = 0.0f;
                    }

                    if (
                        _displayData != null && currentDisplayData != _displayData &&
                        (_meshData == null || _meshData != _displayData.mesh)
                        )
                    {
                        _displayData.transform.ToMatrix(_helpMatrix);
                        _helpMatrix.Invert();
                        _helpMatrix.TransformPoint(0.0f, 0.0f, _helpPoint);
                        _pivotX -= _helpPoint.x;
                        _pivotY -= _helpPoint.y;

                        currentDisplayData.transform.ToMatrix(_helpMatrix);
                        _helpMatrix.Invert();
                        _helpMatrix.TransformPoint(0.0f, 0.0f, _helpPoint);
                        _pivotX += _helpPoint.x;
                        _pivotY += _helpPoint.y;
                    }

                    if (_meshData != prevMeshData) // Update mesh bones and ffd vertices.
                    {
                        if (_meshData != null && _displayData != null && _meshData == _displayData.mesh)
                        {
                            if (_meshData.skinned)
                            {
                                DragonBones.ResizeList(_meshBones, _meshData.bones.Count, null);

                                for (int i = 0, l = _meshBones.Count; i < l; ++i)
                                {
                                    _meshBones[i] = _armature.GetBone(_meshData.bones[i].name);
                                }

                                int ffdVerticesCount = 0;
                                for (int i = 0, l = _meshData.boneIndices.Count; i < l; ++i)
                                {
                                    ffdVerticesCount += _meshData.boneIndices[i].Length;
                                }

                                DragonBones.ResizeList(_ffdVertices, ffdVerticesCount * 2, 0.0f);
                            }
                            else
                            {
                                _meshBones.Clear();
                                DragonBones.ResizeList(_ffdVertices, _meshData.vertices.Count, 0.0f);
                            }

                            for (int i = 0, l = _ffdVertices.Count; i < l; ++i)
                            {
                                _ffdVertices[i] = 0.0f;
                            }

                            _meshDirty = true;
                        }
                        else
                        {
                            _meshBones.Clear();
                            _ffdVertices.Clear();
                        }
                    }
                    else if (_textureData != prevTextureData)
                    {
                        _meshDirty = true;
                    }
                }
                else
                {
                    _textureData = null;
                    _meshData    = null;
                    _pivotX      = 0.0f;
                    _pivotY      = 0.0f;
                    _meshBones.Clear();
                    _ffdVertices.Clear();
                }

                _displayDirty  = true;
                _originalDirty = true;

                if (_displayData != null)
                {
                    origin = _displayData.transform;
                }
                else if (_replacedDisplayData != null)
                {
                    origin = _replacedDisplayData.transform;
                }
            }

            // Update bounding box data.
            if (_replacedDisplayData != null)
            {
                _boundingBoxData = _replacedDisplayData.boundingBox;
            }
            else if (_displayData != null)
            {
                _boundingBoxData = _displayData.boundingBox;
            }
            else
            {
                _boundingBoxData = null;
            }
        }
Exemple #13
0
        /**
         * @private
         */
        internal void _init(Armature armature, AnimationData animationData, AnimationConfig animationConfig)
        {
            _armature      = armature;
            _animationData = animationData;
            _name          = !string.IsNullOrEmpty(animationConfig.name) ? animationConfig.name : animationConfig.animationName;

            actionEnabled    = animationConfig.actionEnabled;
            additiveBlending = animationConfig.additiveBlending;
            displayControl   = animationConfig.displayControl;
            playTimes        = (uint)animationConfig.playTimes;
            timeScale        = animationConfig.timeScale;
            fadeTotalTime    = animationConfig.fadeInTime;
            autoFadeOutTime  = animationConfig.autoFadeOutTime;
            weight           = animationConfig.weight;

            if (animationConfig.pauseFadeIn)
            {
                _playheadState = 2; // 10
            }
            else
            {
                _playheadState = 3; // 11
            }

            _fadeState    = -1;
            _subFadeState = -1;
            _layer        = animationConfig.layer;
            _time         = animationConfig.position;
            _group        = animationConfig.group;

            if (animationConfig.duration < 0.0f)
            {
                _position = 0.0f;
                _duration = _animationData.duration;
            }
            else
            {
                _position = animationConfig.position;
                _duration = animationConfig.duration;
            }

            if (fadeTotalTime <= 0.0f)
            {
                _fadeProgress = 0.999999f;
            }

            if (animationConfig.boneMask.Count > 0)
            {
                DragonBones.ResizeList(_boneMask, animationConfig.boneMask.Count, null);
                for (int i = 0, l = _boneMask.Count; i < l; ++i)
                {
                    _boneMask[i] = animationConfig.boneMask[i];
                }
            }

            _timeline = BaseObject.BorrowObject <AnimationTimelineState>();
            _timeline._init(_armature, this, _animationData);

            if (_animationData.zOrderTimeline != null)
            {
                _zOrderTimeline = BaseObject.BorrowObject <ZOrderTimelineState>();
                _zOrderTimeline._init(_armature, this, _animationData.zOrderTimeline);
            }

            _updateTimelineStates();
        }
Exemple #14
0
        protected void _mergeFrameToAnimationTimeline(float framePostion,List <ActionData> actions,List <EventData> events)
        {
            var frameStart = (int)Math.Floor(framePostion * _armature.frameRate); // uint()
            var frames     = _animation.frames;

            if (frames.Count == 0)
            {
                var startFrame = BaseObject.BorrowObject <AnimationFrameData>(); // Add start frame.
                startFrame.position = 0.0f;

                if (_animation.frameCount > 1)
                {
                    DragonBones.ResizeList(frames,(int)_animation.frameCount + 1,null);                // One more count for zero duration frame.

                    var endFrame = BaseObject.BorrowObject <AnimationFrameData> ();                    // Add end frame to keep animation timeline has two different frames atleast.
                    endFrame.position = _animation.frameCount / _armature.frameRate;

                    frames[0] = startFrame;
                    frames[(int)_animation.frameCount] = endFrame;
                }
                else                 // TODO
                {
                    DragonBones.ResizeList(frames,1,null);
                    frames[0] = startFrame;
                }
            }

            AnimationFrameData insertedFrame = null;
            var replacedFrame = frames[frameStart];

            if (replacedFrame != null && (frameStart == 0 || frames[frameStart - 1] == replacedFrame.prev)) // Key frame.
            {
                insertedFrame = replacedFrame;
            }
            else
            {
                insertedFrame          = BaseObject.BorrowObject <AnimationFrameData>(); // Create frame.
                insertedFrame.position = frameStart / _armature.frameRate;
                frames[frameStart]     = insertedFrame;

                for (int i = frameStart + 1,l = frames.Count; i < l; ++i)  // Clear replaced frame.
                {
                    var frame = frames[i];
                    if (replacedFrame != null && frame == replacedFrame)
                    {
                        frames[i] = null;
                    }
                }
            }

            if (actions != null) // Merge actions.
            {
                foreach (var action in actions)
                {
                    insertedFrame.actions.Add(action);
                }
            }

            if (events != null) // Merge events.
            {
                foreach (var evt in events)
                {
                    insertedFrame.events.Add(evt);
                }
            }

            // Modify frame link and duration.
            AnimationFrameData prevFrame = null;
            AnimationFrameData nextFrame = null;

            for (int i = 0,l = frames.Count; i < l; ++i)
            {
                var currentFrame = frames[i];
                if (currentFrame != null && nextFrame != currentFrame)
                {
                    nextFrame = currentFrame;

                    if (prevFrame != null)
                    {
                        nextFrame.prev     = prevFrame;
                        prevFrame.next     = nextFrame;
                        prevFrame.duration = nextFrame.position - prevFrame.position;
                    }

                    prevFrame = nextFrame;
                }
                else
                {
                    frames[i] = prevFrame;
                }
            }

            nextFrame.duration = _animation.duration - nextFrame.position;

            nextFrame      = frames[0];
            prevFrame.next = nextFrame;
            nextFrame.prev = prevFrame;
        }
Exemple #15
0
        /**
         * @private
         */
        internal void _updateMeshData(bool isTimelineUpdate)
        {
            var prevMeshData = _meshData;
            var rawMeshData  = (MeshData)null;

            if (_display != null && _display == _meshDisplay && _displayIndex >= 0)
            {
                rawMeshData = (_displayDataSet != null && _displayIndex < _displayDataSet.displays.Count) ? _displayDataSet.displays[_displayIndex].mesh : null;
                var replaceDisplayData = (_displayIndex < _replacedDisplayDataSet.Count) ? _replacedDisplayDataSet[_displayIndex] : null;
                var replaceMeshData    = replaceDisplayData != null ? replaceDisplayData.mesh : null;
                _meshData = replaceMeshData != null ? replaceMeshData : rawMeshData;
            }
            else
            {
                _meshData = null;
            }

            if (_meshData != prevMeshData)
            {
                if (_meshData != null && _meshData == rawMeshData)
                {
                    if (_meshData.skinned)
                    {
                        DragonBones.ResizeList(_meshBones, _meshData.bones.Count, null);

                        for (int i = 0, l = _meshBones.Count; i < l; ++i)
                        {
                            _meshBones[i] = this._armature.GetBone(_meshData.bones[i].name);
                        }

                        var ffdVerticesCount = 0;
                        for (int i = 0, l = _meshData.boneIndices.Count; i < l; ++i)
                        {
                            ffdVerticesCount += _meshData.boneIndices[i].Length;
                        }

                        DragonBones.ResizeList(_ffdVertices, ffdVerticesCount * 2, 0.0f);
                    }
                    else
                    {
                        _meshBones.Clear();

                        DragonBones.ResizeList(_ffdVertices, _meshData.vertices.Count, 0.0f);
                    }

                    for (int i = 0, l = _ffdVertices.Count; i < l; ++i)
                    {
                        _ffdVertices[i] = 0;
                    }

                    _ffdDirty = true;
                }
                else
                {
                    _meshBones.Clear();
                    _ffdVertices.Clear();
                }

                if (isTimelineUpdate)
                {
                    this._armature.animation._updateFFDTimelineStates();
                }
            }
        }
        /**
         * @private
         */
        internal void _advanceTime(float passedTime)
        {
            if (!_isPlaying)
            {
                return;
            }

            if (passedTime < 0.0f)
            {
                passedTime = -passedTime;
            }

            var animationStateCount = _animationStates.Count;

            if (animationStateCount == 1)
            {
                var animationState = _animationStates[0];
                if (animationState._fadeState > 0 && animationState._fadeProgress <= 0.0f)
                {
                    animationState.ReturnToPool();
                    _animationStates.Clear();
                    _animationStateDirty = true;
                    _lastAnimationState  = null;
                }
                else
                {
                    if (_timelineStateDirty)
                    {
                        animationState._updateTimelineStates();
                    }

                    animationState._advanceTime(passedTime, 1.0f, 0);
                }
            }
            else if (animationStateCount > 1)
            {
                var prevLayer        = _animationStates[0]._layer;
                var weightLeft       = 1.0f;
                var layerTotalWeight = 0.0f;
                int animationIndex   = 1; // If has multiply animation state, first index is 1.

                for (int i = 0, r = 0; i < animationStateCount; ++i)
                {
                    var animationState = _animationStates[i];
                    if (animationState._fadeState > 0 && animationState._fadeProgress <= 0.0f)
                    {
                        r++;
                        animationState.ReturnToPool();
                        _animationStateDirty = true;

                        if (_lastAnimationState == animationState) // Update last animation state.
                        {
                            if (i - r >= 0)
                            {
                                _lastAnimationState = _animationStates[i - r];
                            }
                            else
                            {
                                _lastAnimationState = null;
                            }
                        }
                    }
                    else
                    {
                        if (r > 0)
                        {
                            _animationStates[i - r] = animationState;
                        }

                        if (prevLayer != animationState._layer)
                        { // Update weight left.
                            prevLayer = animationState._layer;

                            if (layerTotalWeight >= weightLeft)
                            {
                                weightLeft = 0.0f;
                            }
                            else
                            {
                                weightLeft -= layerTotalWeight;
                            }

                            layerTotalWeight = 0.0f;
                        }

                        if (_timelineStateDirty)
                        {
                            animationState._updateTimelineStates();
                        }

                        animationState._advanceTime(passedTime, weightLeft, animationIndex);

                        if (animationState._weightResult > 0.0f)
                        { // Update layer total weight.
                            layerTotalWeight += animationState._weightResult;
                            animationIndex++;
                        }
                    }

                    if (i == animationStateCount - 1 && r > 0) // Modify animation states size.
                    {
                        DragonBones.ResizeList(_animationStates, animationStateCount - r, null);
                    }
                }
            }
            else
            {
                _armature._cacheFrameIndex = -1;
            }

            _timelineStateDirty = false;
        }
        /**
         * @language zh_CN
         * 为所有的 IAnimatable 实例更新时间。
         * @param passedTime 前进的时间。 (以秒为单位,当设置为 -1 时将自动计算当前帧与上一帧的时间差)
         * @version DragonBones 3.0
         */
        public void AdvanceTime(float passedTime)
        {
            if (float.IsNaN(passedTime))
            {
                passedTime = 0.0f;
            }

            if (passedTime < 0.0f)
            {
                passedTime = DateTime.Now.Ticks / 100.0f / DragonBones.SECOND_TO_MILLISECOND - time;
            }

            if (timeScale != 1.0f)
            {
                passedTime *= timeScale;
            }

            if (passedTime < 0.0f)
            {
                time -= passedTime;
            }
            else
            {
                time += passedTime;
            }

            if (passedTime > 0.0f)
            {
                int i = 0, r = 0, l = _animatebles.Count;
                for (; i < l; ++i)
                {
                    var animateble = _animatebles[i];
                    if (animateble != null)
                    {
                        if (r > 0)
                        {
                            _animatebles[i - r] = animateble;
                            _animatebles[i]     = null;
                        }

                        animateble.AdvanceTime(passedTime);
                    }
                    else
                    {
                        r++;
                    }
                }

                if (r > 0)
                {
                    l = _animatebles.Count;
                    for (; i < l; ++i)
                    {
                        var animateble = _animatebles[i];
                        if (animateble != null)
                        {
                            _animatebles[i - r] = animateble;
                        }
                        else
                        {
                            r++;
                        }
                    }

                    DragonBones.ResizeList(_animatebles, l - r, null);
                }
            }
        }
Exemple #18
0
        /**
         * @private
         */
        override protected Slot _generateSlot(BuildArmaturePackage dataPackage, SkinSlotData skinSlotData, Armature armature)
        {
            var slotData    = skinSlotData.slot;
            var slot        = BaseObject.BorrowObject <UnitySlot>();
            var displayList = new List <object>();

            DragonBones.ResizeList(displayList, skinSlotData.displays.Count, null);

            var armatureDisplay = armature.display as GameObject;
            var transform       = armatureDisplay.transform.Find(skinSlotData.slot.name);
            var gameObject      = transform == null ? null : transform.gameObject;

            if (gameObject == null)
            {
                gameObject = new GameObject(slotData.name);
                gameObject.AddComponent <MeshRenderer>();
                gameObject.AddComponent <MeshFilter>();
            }

            slot._init(
                skinSlotData,
                gameObject,
                gameObject
                );

            for (int i = 0, l = skinSlotData.displays.Count; i < l; ++i)
            {
                var displayData = skinSlotData.displays[i];
                switch (displayData.type)
                {
                case DisplayType.Image:
                    if (displayData.texture == null)
                    {
                        displayData.texture = _getTextureData(dataPackage.dataName, displayData.path);
                    }

                    if (!string.IsNullOrEmpty(dataPackage.textureAtlasName))
                    {
                        slot._textureDatas[i] = _getTextureData(dataPackage.textureAtlasName, displayData.path);
                    }

                    displayList[i] = slot.rawDisplay;
                    break;

                case DisplayType.Mesh:
                    if (displayData.texture == null)
                    {
                        displayData.texture = _getTextureData(dataPackage.dataName, displayData.path);
                    }

                    if (!string.IsNullOrEmpty(dataPackage.textureAtlasName))
                    {
                        slot._textureDatas[i] = _getTextureData(dataPackage.textureAtlasName, displayData.path);
                    }

                    displayList[i] = slot.meshDisplay;
                    break;

                case DisplayType.Armature:
                    var childDisplayName = slotData.name + " (" + displayData.path + ")";     //
                    var childTransform   = armatureDisplay.transform.Find(childDisplayName);
                    var childArmature    = childTransform == null?
                                           BuildArmature(displayData.path, dataPackage.dataName) :
                                               BuildArmatureComponent(displayData.path, dataPackage.dataName, null, dataPackage.textureAtlasName, childTransform.gameObject).armature;

                    if (childArmature != null)
                    {
                        childArmature.inheritAnimation = displayData.inheritAnimation;
                        if (!childArmature.inheritAnimation)
                        {
                            var actions = slotData.actions.Count > 0 ? slotData.actions : childArmature.armatureData.actions;
                            if (actions.Count > 0)
                            {
                                foreach (var actionData in actions)
                                {
                                    childArmature._bufferAction(actionData);
                                }
                            }
                            else
                            {
                                childArmature.animation.Play();
                            }
                        }

                        displayData.armature = childArmature.armatureData;     //

                        // Hide
                        var childArmatureDisplay = childArmature.display as GameObject;
                        childArmatureDisplay.name = childDisplayName;
                        childArmatureDisplay.gameObject.hideFlags = HideFlags.HideInHierarchy;
                        childArmatureDisplay.SetActive(false);
                    }

                    displayList[i] = childArmature;
                    break;

                default:
                    displayList[i] = null;
                    break;
                }
            }

            slot._setDisplayList(displayList);

            return(slot);
        }