static int ReturnToPool(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         DragonBones.BaseObject obj = (DragonBones.BaseObject)ToLua.CheckObject <DragonBones.BaseObject>(L, 1);
         obj.ReturnToPool();
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
예제 #2
0
    static int set_hashCode(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            DragonBones.BaseObject obj = (DragonBones.BaseObject)o;
            uint arg0 = (uint)LuaDLL.luaL_checknumber(L, 2);
            obj.hashCode = arg0;
            return(0);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index hashCode on a nil value"));
        }
    }
    static int get_hashCode(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            DragonBones.BaseObject obj = (DragonBones.BaseObject)o;
            uint ret = obj.hashCode;
            LuaDLL.lua_pushnumber(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index hashCode on a nil value"));
        }
    }
예제 #4
0
        /**
         * @private
         */
        private void _advanceFadeTime(float passedTime)
        {
            if (passedTime < 0.0f)
            {
                passedTime = -passedTime;
            }

            _fadeTime += passedTime;

            var fadeProgress = 0.0f;

            if (_fadeTime >= fadeTotalTime) // Fade complete.
            {
                fadeProgress = _isFadeOut ? 0.0f : 1.0f;
            }
            else if (_fadeTime > 0.0f) // Fading.
            {
                fadeProgress = _isFadeOut ? (1 - _fadeTime / fadeTotalTime) : (_fadeTime / fadeTotalTime);
            }
            else // Before fade.
            {
                fadeProgress = _isFadeOut ? 1.0f : 0.0f;
            }

            if (_fadeProgress != fadeProgress)
            {
                _fadeProgress = fadeProgress;

                var eventDispatcher = _armature._eventDispatcher;

                if (_fadeTime <= passedTime)
                {
                    if (_isFadeOut)
                    {
                        if (eventDispatcher.HasEventListener(EventObject.FADE_OUT))
                        {
                            var evt = BaseObject.BorrowObject <EventObject>();
                            evt.animationState = this;
                            _armature._bufferEvent(evt, EventObject.FADE_OUT);
                        }
                    }
                    else
                    {
                        if (eventDispatcher.HasEventListener(EventObject.FADE_IN))
                        {
                            var evt = BaseObject.BorrowObject <EventObject>();
                            evt.animationState = this;
                            _armature._bufferEvent(evt, EventObject.FADE_IN);
                        }
                    }
                }

                if (_fadeTime >= fadeTotalTime)
                {
                    if (_isFadeOut)
                    {
                        _isFadeOutComplete = true;

                        if (eventDispatcher.HasEventListener(EventObject.FADE_OUT_COMPLETE))
                        {
                            var evt = BaseObject.BorrowObject <EventObject>();
                            evt.animationState = this;
                            _armature._bufferEvent(evt, EventObject.FADE_OUT_COMPLETE);
                        }
                    }
                    else
                    {
                        _isPausePlayhead = false;

                        if (eventDispatcher.HasEventListener(EventObject.FADE_IN_COMPLETE))
                        {
                            var evt = BaseObject.BorrowObject <EventObject>();
                            evt.animationState = this;
                            _armature._bufferEvent(evt, EventObject.FADE_IN_COMPLETE);
                        }
                    }
                }
            }
        }
예제 #5
0
        /**
         * @private
         */
        internal void _updateTimelineStates()
        {
            var time = _time;

            if (!_animationData.hasAsynchronyTimeline)
            {
                time = _timeline._currentTime;
            }

            var boneTimelineStates = new Dictionary <string, BoneTimelineState>();
            var slotTimelineStates = new Dictionary <string, SlotTimelineState>();

            foreach (var boneTimelineState in _boneTimelines) // Creat bone timelines map.
            {
                boneTimelineStates.Add(boneTimelineState.bone.name, boneTimelineState);
            }

            foreach (var bone in _armature.GetBones())
            {
                var boneTimelineName = bone.name;
                var boneTimelineData = _animationData.GetBoneTimeline(boneTimelineName);

                if (boneTimelineData != null && ContainsBoneMask(boneTimelineName))
                {
                    var boneTimelineState = boneTimelineStates.ContainsKey(boneTimelineName) ? boneTimelineStates[boneTimelineName] : null;
                    if (boneTimelineState != null) // Remove bone timeline from map.
                    {
                        boneTimelineStates.Remove(boneTimelineName);
                    }
                    else // Create new bone timeline.
                    {
                        boneTimelineState      = BaseObject.BorrowObject <BoneTimelineState>();
                        boneTimelineState.bone = bone;
                        boneTimelineState.FadeIn(_armature, this, boneTimelineData, time);
                        _boneTimelines.Add(boneTimelineState);
                    }
                }
            }

            foreach (var boneTimelineState in boneTimelineStates.Values) // Remove bone timelines.
            {
                boneTimelineState.bone.InvalidUpdate();                  //
                _boneTimelines.Remove(boneTimelineState);
                boneTimelineState.ReturnToPool();
            }

            foreach (var slotTimelineState in _slotTimelines) // Create slot timelines map.
            {
                slotTimelineStates[slotTimelineState.slot.name] = slotTimelineState;
            }

            foreach (var slot in _armature.GetSlots())
            {
                var slotTimelineName   = slot.name;
                var parentTimelineName = slot.parent.name;
                var slotTimelineData   = _animationData.GetSlotTimeline(slotTimelineName);

                if (slotTimelineData != null && ContainsBoneMask(parentTimelineName) && !_isFadeOut)
                {
                    var slotTimelineState = slotTimelineStates.ContainsKey(slotTimelineName) ? slotTimelineStates[slotTimelineName] : null;
                    if (slotTimelineState != null) // Remove slot timeline from map.
                    {
                        slotTimelineStates.Remove(slotTimelineName);
                    }
                    else // Create new slot timeline.
                    {
                        slotTimelineState      = BaseObject.BorrowObject <SlotTimelineState>();
                        slotTimelineState.slot = slot;
                        slotTimelineState.FadeIn(_armature, this, slotTimelineData, time);
                        _slotTimelines.Add(slotTimelineState);
                    }
                }
            }

            foreach (var slotTimelineState in slotTimelineStates.Values) // Remove slot timelines.
            {
                _slotTimelines.Remove(slotTimelineState);
                slotTimelineState.ReturnToPool();
            }

            _updateFFDTimelineStates();
        }
예제 #6
0
        /// <private/>
        protected void _UpdateDisplay()
        {
            var prevDisplay       = this._display != null ? this._display : this._rawDisplay;
            var prevChildArmature = this._childArmature;

            // Update display and child armature.
            if (this._displayIndex >= 0 && this._displayIndex < this._displayList.Count)
            {
                this._display = this._displayList[this._displayIndex];
                if (this._display != null && this._display is Armature)
                {
                    this._childArmature = this._display as Armature;
                    this._display       = this._childArmature.display;
                }
                else
                {
                    this._childArmature = null;
                }
            }
            else
            {
                this._display       = null;
                this._childArmature = null;
            }

            // Update display.
            var currentDisplay = this._display != null ? this._display : this._rawDisplay;

            if (currentDisplay != prevDisplay)
            {
                this._OnUpdateDisplay();
                this._ReplaceDisplay(prevDisplay);

                this._transformDirty = true;
                this._visibleDirty   = true;
                this._blendModeDirty = true;
                this._colorDirty     = true;
            }

            // Update frame.
            if (currentDisplay == this._rawDisplay || currentDisplay == this._meshDisplay)
            {
                this._UpdateFrame();
            }

            // Update child armature.
            if (this._childArmature != prevChildArmature)
            {
                if (prevChildArmature != null)
                {
                    // Update child armature parent.
                    prevChildArmature._parent = null;
                    prevChildArmature.clock   = null;
                    if (prevChildArmature.inheritAnimation)
                    {
                        prevChildArmature.animation.Reset();
                    }
                }

                if (this._childArmature != null)
                {
                    // Update child armature parent.
                    this._childArmature._parent = this;
                    this._childArmature.clock   = this._armature.clock;
                    if (this._childArmature.inheritAnimation)
                    {
                        // Set child armature cache frameRate.
                        if (this._childArmature.cacheFrameRate == 0)
                        {
                            var cacheFrameRate = this._armature.cacheFrameRate;
                            if (cacheFrameRate != 0)
                            {
                                this._childArmature.cacheFrameRate = cacheFrameRate;
                            }
                        }

                        // Child armature action.
                        List <ActionData> actions = null;
                        if (this._displayData != null && this._displayData.type == DisplayType.Armature)
                        {
                            actions = (this._displayData as ArmatureDisplayData).actions;
                        }
                        else if (this._displayIndex >= 0 && this._rawDisplayDatas != null)
                        {
                            var rawDisplayData = this._displayIndex < this._rawDisplayDatas.Count ? this._rawDisplayDatas[this._displayIndex] : null;

                            if (rawDisplayData == null)
                            {
                                rawDisplayData = this._GetDefaultRawDisplayData(this._displayIndex);
                            }

                            if (rawDisplayData != null && rawDisplayData.type == DisplayType.Armature)
                            {
                                actions = (rawDisplayData as ArmatureDisplayData).actions;
                            }
                        }

                        if (actions != null && actions.Count > 0)
                        {
                            foreach (var action in actions)
                            {
                                var eventObject = BaseObject.BorrowObject <EventObject>();
                                EventObject.ActionDataToInstance(action, eventObject, this._armature);
                                eventObject.slot = this;
                                this._armature._BufferAction(eventObject, false);
                            }
                        }
                        else
                        {
                            this._childArmature.animation.Play();
                        }
                    }
                }
            }
        }
예제 #7
0
        /// <summary>
        /// - Play animation with a specific animation config.
        /// The API is still in the experimental phase and may encounter bugs or stability or compatibility issues when used.
        /// </summary>
        /// <param name="animationConfig">- The animation config.</param>
        /// <returns>The playing animation state.</returns>
        /// <see cref="DragonBones.AnimationConfig"/>
        /// <beta/>
        /// <version>DragonBones 5.0</version>
        /// <language>en_US</language>

        /// <summary>
        /// - 通过指定的动画配置来播放动画。
        /// 该 API 仍在实验阶段,使用时可能遭遇 bug 或稳定性或兼容性问题。
        /// </summary>
        /// <param name="animationConfig">- 动画配置。</param>
        /// <returns>播放的动画状态。</returns>
        /// <see cref="DragonBones.AnimationConfig"/>
        /// <beta/>
        /// <version>DragonBones 5.0</version>
        /// <language>zh_CN</language>
        public AnimationState PlayConfig(AnimationConfig animationConfig)
        {
            var animationName = animationConfig.animation;

            if (!(this._animations.ContainsKey(animationName)))
            {
                Helper.Assert(false,
                              "Non-existent animation.\n" +
                              "DragonBones name: " + this._armature.armatureData.parent.name +
                              "Armature name: " + this._armature.name +
                              "Animation name: " + animationName
                              );

                return(null);
            }

            var animationData = this._animations[animationName];

            if (animationConfig.fadeOutMode == AnimationFadeOutMode.Single)
            {
                foreach (var aniState in this._animationStates)
                {
                    if (aniState._animationData == animationData)
                    {
                        return(aniState);
                    }
                }
            }

            if (this._animationStates.Count == 0)
            {
                animationConfig.fadeInTime = 0.0f;
            }
            else if (animationConfig.fadeInTime < 0.0f)
            {
                animationConfig.fadeInTime = animationData.fadeInTime;
            }

            if (animationConfig.fadeOutTime < 0.0f)
            {
                animationConfig.fadeOutTime = animationConfig.fadeInTime;
            }

            if (animationConfig.timeScale <= -100.0f)
            {
                animationConfig.timeScale = 1.0f / animationData.scale;
            }

            if (animationData.frameCount > 1)
            {
                if (animationConfig.position < 0.0f)
                {
                    animationConfig.position %= animationData.duration;
                    animationConfig.position  = animationData.duration - animationConfig.position;
                }
                else if (animationConfig.position == animationData.duration)
                {
                    animationConfig.position -= 0.000001f; // Play a little time before end.
                }
                else if (animationConfig.position > animationData.duration)
                {
                    animationConfig.position %= animationData.duration;
                }

                if (animationConfig.duration > 0.0f && animationConfig.position + animationConfig.duration > animationData.duration)
                {
                    animationConfig.duration = animationData.duration - animationConfig.position;
                }

                if (animationConfig.playTimes < 0)
                {
                    animationConfig.playTimes = (int)animationData.playTimes;
                }
            }
            else
            {
                animationConfig.playTimes = 1;
                animationConfig.position  = 0.0f;
                if (animationConfig.duration > 0.0)
                {
                    animationConfig.duration = 0.0f;
                }
            }

            if (animationConfig.duration == 0.0f)
            {
                animationConfig.duration = -1.0f;
            }

            this._FadeOut(animationConfig);

            var animationState = BaseObject.BorrowObject <AnimationState>();

            animationState.Init(this._armature, animationData, animationConfig);
            this._animationDirty            = true;
            this._armature._cacheFrameIndex = -1;

            if (this._animationStates.Count > 0)
            {
                var added = false;
                for (int i = 0, l = this._animationStates.Count; i < l; ++i)
                {
                    if (animationState.layer > this._animationStates[i].layer)
                    {
                        added = true;
                        this._animationStates.Insert(i, animationState);
                        break;
                    }
                    else if (i != l - 1 && animationState.layer > this._animationStates[i + 1].layer)
                    {
                        added = true;
                        this._animationStates.Insert(i + 1, animationState);
                        break;
                    }
                }

                if (!added)
                {
                    this._animationStates.Add(animationState);
                }
            }
            else
            {
                this._animationStates.Add(animationState);
            }

            // Child armature play same name animation.
            foreach (var slot in this._armature.GetSlots())
            {
                var childArmature = slot.childArmature;
                if (childArmature != null &&
                    childArmature.inheritAnimation &&
                    childArmature.animation.HasAnimation(animationName) &&
                    childArmature.animation.GetState(animationName) == null)
                {
                    childArmature.animation.FadeIn(animationName); //
                }
            }

            if (!this._lockUpdate)
            {
                if (animationConfig.fadeInTime <= 0.0f)
                {
                    // Blend animation state, update armature.
                    this._armature.AdvanceTime(0.0f);
                }
            }

            this._lastAnimationState = animationState;

            return(animationState);
        }
예제 #8
0
        /**
         * @private
         */
        override protected void _updateFrame()
        {
            var isMeshDisplay      = _meshData != null && _display == _meshDisplay;
            var currentTextureData = _textureData as UnityTextureData;

            if (_proxy.isUGUI)
            {
                _uiDisplay = _renderDisplay.GetComponent <UnityUGUIDisplay>();
                if (_uiDisplay == null)
                {
                    _uiDisplay = _renderDisplay.AddComponent <UnityUGUIDisplay>();
                    _uiDisplay.raycastTarget = false;
                }
            }
            else
            {
                _renderer = _renderDisplay.GetComponent <MeshRenderer>();
                if (_renderer == null)
                {
                    _renderer = _renderDisplay.AddComponent <MeshRenderer>();
                }
                _meshFilter = _renderDisplay.GetComponent <MeshFilter>();
                if (_meshFilter == null)
                {
                    _meshFilter = _renderDisplay.AddComponent <MeshFilter>();
                }
            }

            if (_display != null && _displayIndex >= 0 && currentTextureData != null)
            {
                var currentTextureAtlasData = currentTextureData.parent as UnityTextureAtlasData;

                // Update replaced texture atlas.
                if (_armature.replacedTexture != null && _displayData != null && currentTextureAtlasData == _displayData.texture.parent)
                {
                    currentTextureAtlasData = _armature._replaceTextureAtlasData as UnityTextureAtlasData;
                    if (currentTextureAtlasData == null)
                    {
                        currentTextureAtlasData = BaseObject.BorrowObject <UnityTextureAtlasData>();
                        currentTextureAtlasData.CopyFrom(_textureData.parent);
                        if (_proxy.isUGUI)
                        {
                            currentTextureAtlasData.uiTexture = _armature.replacedTexture as Material;
                        }
                        else
                        {
                            currentTextureAtlasData.texture = _armature.replacedTexture as Material;
                        }
                        _armature._replaceTextureAtlasData = currentTextureAtlasData;
                    }

                    currentTextureData = currentTextureAtlasData.GetTexture(currentTextureData.name) as UnityTextureData;
                }

                var currentTextureAtlas = _proxy.isUGUI?currentTextureAtlasData.uiTexture :currentTextureAtlasData.texture;
                if (currentTextureAtlas != null)
                {
                    var textureAtlasWidth  = currentTextureAtlasData.width > 0.0f ? currentTextureAtlasData.width : currentTextureAtlas.mainTexture.width;
                    var textureAtlasHeight = currentTextureAtlasData.height > 0.0f ? currentTextureAtlasData.height : currentTextureAtlas.mainTexture.height;

                    if (_mesh == null)
                    {
                        _mesh = new Mesh();
                        _mesh.MarkDynamic();
                    }
                    else
                    {
                        _mesh.Clear();
                        _mesh.uv        = null;
                        _mesh.vertices  = null;
                        _mesh.normals   = null;
                        _mesh.triangles = null;
                        _mesh.colors32  = null;
                    }

                    if (isMeshDisplay) // Mesh.
                    {
                        if (_uvs == null || _uvs.Length != _meshData.uvs.Count / 2)
                        {
                            _uvs = new Vector2[_meshData.uvs.Count / 2];
                        }
                        if (_vertices == null || _vertices.Length != _meshData.vertices.Count / 2)
                        {
                            _vertices  = new Vector3[_meshData.vertices.Count / 2];
                            _vertices2 = new Vector3[_vertices.Length];
                        }

                        for (int i = 0, l = _meshData.uvs.Count; i < l; i += 2)
                        {
                            var iN = i / 2;
                            var u  = _meshData.uvs[i];
                            var v  = _meshData.uvs[i + 1];
                            _uvs[iN] = new Vector2(
                                (currentTextureData.region.x + u * currentTextureData.region.width) / textureAtlasWidth,
                                1.0f - (currentTextureData.region.y + v * currentTextureData.region.height) / textureAtlasHeight
                                );
                            _vertices[iN]  = new Vector3(_meshData.vertices[i], -_meshData.vertices[i + 1], 0.0f);
                            _vertices2[iN] = _vertices[iN];
                        }

                        _mesh.vertices  = _vertices; // Must set vertices before uvs.
                        _mesh.uv        = _uvs;
                        _mesh.triangles = _meshData.vertexIndices.ToArray();
                    }
                    else // Normal texture.
                    {
                        var pivotY = _pivotY - currentTextureData.region.height * _armature.armatureData.scale;

                        if (_vertices == null || _vertices.Length != 4)
                        {
                            _vertices  = new Vector3[4];
                            _vertices2 = new Vector3[4];
                        }

                        for (int i = 0, l = 4; i < l; ++i)
                        {
                            var u = 0.0f;
                            var v = 0.0f;

                            switch (i)
                            {
                            case 0:
                                break;

                            case 1:
                                u = 1.0f;
                                break;

                            case 2:
                                u = 1.0f;
                                v = 1.0f;
                                break;

                            case 3:
                                v = 1.0f;
                                break;

                            default:
                                break;
                            }

                            _helpVector2s[i].x = (currentTextureData.region.x + u * currentTextureData.region.width) / textureAtlasWidth;
                            _helpVector2s[i].y = 1.0f - (currentTextureData.region.y + v * currentTextureData.region.height) / textureAtlasHeight;
                            _vertices[i].x     = (u * currentTextureData.region.width) * 0.01f - _pivotX;
                            _vertices[i].y     = (1.0f - v) * currentTextureData.region.height * 0.01f + pivotY;
                            _vertices[i].z     = 0.0f * 0.01f;
                            _vertices2[i]      = _vertices[i];
                        }

                        _mesh.vertices  = _vertices; // Must set vertices before uvs.
                        _mesh.uv        = _helpVector2s;
                        _mesh.triangles = TRIANGLES;
                    }

                    if (_proxy.isUGUI)
                    {
                        _uiDisplay.material = currentTextureAtlas;
                        _uiDisplay.texture  = currentTextureAtlas.mainTexture;
                        _mesh.RecalculateBounds();
                        _uiDisplay.sharedMesh = _mesh;
                    }
                    else
                    {
                        if (_renderer.enabled)
                        {
                            _mesh.RecalculateBounds();
                        }
                        _meshFilter.sharedMesh   = _mesh;
                        _renderer.sharedMaterial = currentTextureAtlas;
                    }

                    _updateVisible();

                    return;
                }
            }

            _renderDisplay.SetActive(false);
            if (_proxy.isUGUI)
            {
                _uiDisplay.material   = null;
                _uiDisplay.texture    = null;
                _uiDisplay.sharedMesh = null;
            }
            else
            {
                _meshFilter.sharedMesh   = null;
                _renderer.sharedMaterial = null;
            }
            _helpVector3.x = 0.0f;
            _helpVector3.y = 0.0f;
            _helpVector3.z = _renderDisplay.transform.localPosition.z;

            _renderDisplay.transform.localPosition = _helpVector3;
        }
예제 #9
0
        /// <private/>
        protected void _UpdateDisplayData()
        {
            var prevDisplayData  = this._displayData;
            var prevVerticesData = this._deformVertices != null ? this._deformVertices.verticesData : null;
            var prevTextureData  = this._textureData;

            DisplayData  rawDisplayData      = null;
            VerticesData currentVerticesData = null;

            this._displayData     = null;
            this._boundingBoxData = null;
            this._textureData     = null;

            if (this._displayIndex >= 0)
            {
                if (this._rawDisplayDatas != null)
                {
                    rawDisplayData = this._displayIndex < this._rawDisplayDatas.Count ? this._rawDisplayDatas[this._displayIndex] : null;
                }

                if (rawDisplayData == null)
                {
                    rawDisplayData = this._GetDefaultRawDisplayData(this._displayIndex);
                }

                if (this._displayIndex < this._displayDatas.Count)
                {
                    this._displayData = this._displayDatas[this._displayIndex];
                }
            }

            // Update texture and mesh data.
            if (this._displayData != null)
            {
                if (this._displayData.type == DisplayType.Mesh)
                {
                    currentVerticesData = (this._displayData as MeshDisplayData).vertices;
                }
                else if (this._displayData.type == DisplayType.Path)
                {
                    currentVerticesData = (this._displayData as PathDisplayData).vertices;
                }
                else if (rawDisplayData != null)
                {
                    if (rawDisplayData.type == DisplayType.Mesh)
                    {
                        currentVerticesData = (rawDisplayData as MeshDisplayData).vertices;
                    }
                    else if (rawDisplayData.type == DisplayType.Path)
                    {
                        currentVerticesData = (rawDisplayData as PathDisplayData).vertices;
                    }
                }

                if (this._displayData.type == DisplayType.BoundingBox)
                {
                    this._boundingBoxData = (this._displayData as BoundingBoxDisplayData).boundingBox;
                }
                else if (rawDisplayData != null)
                {
                    if (rawDisplayData.type == DisplayType.BoundingBox)
                    {
                        this._boundingBoxData = (rawDisplayData as BoundingBoxDisplayData).boundingBox;
                    }
                }

                if (this._displayData.type == DisplayType.Image)
                {
                    this._textureData = (this._displayData as ImageDisplayData).texture;
                }
                else if (this._displayData.type == DisplayType.Mesh)
                {
                    this._textureData = (this._displayData as MeshDisplayData).texture;
                }
            }

            if (this._displayData != prevDisplayData || currentVerticesData != prevVerticesData || this._textureData != prevTextureData)
            {
                // Update pivot offset.
                if (currentVerticesData == null && this._textureData != null)
                {
                    var imageDisplayData = this._displayData as ImageDisplayData;
                    var scale            = this._textureData.parent.scale * this._armature._armatureData.scale;
                    var frame            = this._textureData.frame;

                    this._pivotX = imageDisplayData.pivot.x;
                    this._pivotY = imageDisplayData.pivot.y;

                    var rect   = frame != null ? frame : this._textureData.region;
                    var width  = rect.width;
                    var height = rect.height;

                    if (this._textureData.rotated && frame == null)
                    {
                        width  = rect.height;
                        height = rect.width;
                    }

                    this._pivotX *= width * scale;
                    this._pivotY *= height * scale;

                    if (frame != null)
                    {
                        this._pivotX += frame.x * scale;
                        this._pivotY += frame.y * scale;
                    }

                    // Update replace pivot. TODO
                    if (this._displayData != null && rawDisplayData != null && this._displayData != rawDisplayData)
                    {
                        rawDisplayData.transform.ToMatrix(Slot._helpMatrix);
                        Slot._helpMatrix.Invert();
                        Slot._helpMatrix.TransformPoint(0.0f, 0.0f, Slot._helpPoint);
                        this._pivotX -= Slot._helpPoint.x;
                        this._pivotY -= Slot._helpPoint.y;

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

                    if (!DragonBones.yDown)
                    {
                        this._pivotY = (this._textureData.rotated ? this._textureData.region.width : this._textureData.region.height) * scale - this._pivotY;
                    }
                }
                else
                {
                    this._pivotX = 0.0f;
                    this._pivotY = 0.0f;
                }

                // Update original transform.
                if (rawDisplayData != null)
                {
                    // Compatible.
                    this.origin = rawDisplayData.transform;
                }
                else if (this._displayData != null)
                {
                    // Compatible.
                    this.origin = this._displayData.transform;
                }
                else
                {
                    this.origin = null;
                }

                // Update vertices.
                if (currentVerticesData != prevVerticesData)
                {
                    if (this._deformVertices == null)
                    {
                        this._deformVertices = BaseObject.BorrowObject <DeformVertices>();
                    }

                    this._deformVertices.init(currentVerticesData, this._armature);
                }
                else if (this._deformVertices != null && this._textureData != prevTextureData)
                {
                    // Update mesh after update frame.
                    this._deformVertices.verticesDirty = true;
                }

                this._displayDirty   = true;
                this._transformDirty = true;
            }
        }
예제 #10
0
        protected override AnimationData _ParseAnimation(Dictionary <string, object> rawData)
        {
            var animation = BaseObject.BorrowObject <AnimationData>();

            animation.frameCount = (uint)System.Math.Max(ObjectDataParser._GetNumber(rawData, DataParser.DURATION, 1), 1);
            animation.playTimes  = (uint)ObjectDataParser._GetNumber(rawData, DataParser.PLAY_TIMES, 1);
            animation.duration   = (float)animation.frameCount / (float)this._armature.frameRate;//Must float
            animation.fadeInTime = ObjectDataParser._GetNumber(rawData, DataParser.FADE_IN_TIME, 0.0f);
            animation.scale      = ObjectDataParser._GetNumber(rawData, DataParser.SCALE, 1.0f);
            animation.name       = ObjectDataParser._GetString(rawData, DataParser.NAME, DataParser.DEFAULT_NAME);
            if (animation.name.Length == 0)
            {
                animation.name = DataParser.DEFAULT_NAME;
            }

            // Offsets.
            var offsets = rawData[DataParser.OFFSET] as List <object>;

            animation.frameIntOffset   = uint.Parse(offsets[0].ToString());
            animation.frameFloatOffset = uint.Parse(offsets[1].ToString());
            animation.frameOffset      = uint.Parse(offsets[2].ToString());

            this._animation = animation;

            if (rawData.ContainsKey(DataParser.ACTION))
            {
                animation.actionTimeline = this._ParseBinaryTimeline(TimelineType.Action, uint.Parse(rawData[DataParser.ACTION].ToString()));
            }

            if (rawData.ContainsKey(DataParser.Z_ORDER))
            {
                animation.zOrderTimeline = this._ParseBinaryTimeline(TimelineType.ZOrder, uint.Parse(rawData[DataParser.Z_ORDER].ToString()));
            }

            if (rawData.ContainsKey(DataParser.BONE))
            {
                var rawTimeliness = rawData[DataParser.BONE] as Dictionary <string, object>;
                foreach (var k in rawTimeliness.Keys)
                {
                    var rawTimelines = rawTimeliness[k] as List <object>;

                    var bone = this._armature.GetBone(k);
                    if (bone == null)
                    {
                        continue;
                    }

                    for (int i = 0, l = rawTimelines.Count; i < l; i += 2)
                    {
                        var timelineType   = int.Parse(rawTimelines[i].ToString());
                        var timelineOffset = int.Parse(rawTimelines[i + 1].ToString());
                        var timeline       = this._ParseBinaryTimeline((TimelineType)timelineType, (uint)timelineOffset);
                        this._animation.AddBoneTimeline(bone, timeline);
                    }
                }
            }

            if (rawData.ContainsKey(DataParser.SLOT))
            {
                var rawTimeliness = rawData[DataParser.SLOT] as Dictionary <string,object>;
                foreach (var k in rawTimeliness.Keys)
                {
                    var rawTimelines = rawTimeliness[k] as List <object>;

                    var slot = this._armature.GetSlot(k);
                    if (slot == null)
                    {
                        continue;
                    }

                    for (int i = 0,l = rawTimelines.Count; i < l; i += 2)
                    {
                        var timelineType   = int.Parse(rawTimelines[i].ToString());
                        var timelineOffset = int.Parse(rawTimelines[i + 1].ToString());
                        var timeline       = this._ParseBinaryTimeline((TimelineType)timelineType,(uint)timelineOffset);
                        this._animation.AddSlotTimeline(slot,timeline);
                    }
                }
            }

            if (rawData.ContainsKey(DataParser.CONSTRAINT))
            {
                var rawTimeliness = rawData[DataParser.CONSTRAINT] as Dictionary <string,object>;
                foreach (var k in rawTimeliness.Keys)
                {
                    var rawTimelines = rawTimeliness[k] as List <object>;

                    var constraint = this._armature.GetConstraint(k);
                    if (constraint == null)
                    {
                        continue;
                    }

                    for (int i = 0,l = rawTimelines.Count; i < l; i += 2)
                    {
                        var timelineType   = int.Parse(rawTimelines[i].ToString());
                        var timelineOffset = int.Parse(rawTimelines[i + 1].ToString());
                        var timeline       = this._ParseBinaryTimeline((TimelineType)timelineType,(uint)timelineOffset);
                        this._animation.AddConstraintTimeline(constraint,timeline);
                    }
                }
            }

            this._animation = null;

            return(animation);
        }
예제 #11
0
 /**
  * @private
  */
 public override TextureData CreateTexture()
 {
     return(BaseObject.BorrowObject <UnityTextureData>());
 }
예제 #12
0
        /**
         * @private
         */
        protected override void _UpdateFrame()
        {
            var meshData           = this._display == this._meshDisplay ? this._meshData : null;
            var currentTextureData = this._textureData as UnityTextureData;

            if (_proxy.isUGUI)
            {
                _uiDisplay = _renderDisplay.GetComponent <UnityUGUIDisplay>();
                if (_uiDisplay == null)
                {
                    _uiDisplay = _renderDisplay.AddComponent <UnityUGUIDisplay>();
                    _uiDisplay.raycastTarget = false;
                }
            }
            else
            {
                _renderer = _renderDisplay.GetComponent <MeshRenderer>();
                if (_renderer == null)
                {
                    _renderer = _renderDisplay.AddComponent <MeshRenderer>();
                }

                _meshFilter = _renderDisplay.GetComponent <MeshFilter>();
                if (_meshFilter == null)
                {
                    _meshFilter = _renderDisplay.AddComponent <MeshFilter>();
                }
            }

            if (this._displayIndex >= 0 && this._display != null && currentTextureData != null)
            {
                if (this._armature.replacedTexture != null && this._rawDisplayDatas.Contains(this._displayData))
                {
                    var currentTextureAtlasData = currentTextureData.parent as UnityTextureAtlasData;
                    if (this._armature._replaceTextureAtlasData == null)
                    {
                        currentTextureAtlasData = BaseObject.BorrowObject <UnityTextureAtlasData>();
                        currentTextureAtlasData.CopyFrom(currentTextureData.parent);

                        if (_proxy.isUGUI)
                        {
                            currentTextureAtlasData.uiTexture = _armature.replacedTexture as Material;
                        }
                        else
                        {
                            currentTextureAtlasData.texture = _armature.replacedTexture as Material;
                        }

                        this._armature._replaceTextureAtlasData = currentTextureAtlasData;
                    }
                    else
                    {
                        currentTextureAtlasData = this._armature._replaceTextureAtlasData as UnityTextureAtlasData;
                    }

                    currentTextureData = currentTextureAtlasData.GetTexture(currentTextureData.name) as UnityTextureData;
                }

                var currentTextureAtlas = _proxy.isUGUI ? currentTextureAtlasData.uiTexture : currentTextureAtlasData.texture;
                if (currentTextureAtlas != null)
                {
                    var textureAtlasWidth  = currentTextureAtlasData.width > 0.0f ? (int)currentTextureAtlasData.width : currentTextureAtlas.mainTexture.width;
                    var textureAtlasHeight = currentTextureAtlasData.height > 0.0f ? (int)currentTextureAtlasData.height : currentTextureAtlas.mainTexture.height;

                    if (_mesh == null)
                    {
                        _mesh           = new Mesh();
                        _mesh.hideFlags = HideFlags.DontSaveInEditor | HideFlags.DontSaveInBuild;
                        _mesh.MarkDynamic();
                    }

                    var meshDisplay = this._mesh;
                    meshDisplay.Clear();
                    meshDisplay.uv        = null;
                    meshDisplay.vertices  = null;
                    meshDisplay.normals   = null;
                    meshDisplay.triangles = null;
                    meshDisplay.colors32  = null;

                    var textureScale = _armature.armatureData.scale * currentTextureData.parent.scale;
                    var sourceX      = currentTextureData.region.x;
                    var sourceY      = currentTextureData.region.y;
                    var sourceWidth  = currentTextureData.region.width;
                    var sourceHeight = currentTextureData.region.height;

                    if (meshData != null)
                    {
                        var data          = meshData.parent.parent.parent;
                        var intArray      = data.intArray;
                        var floatArray    = data.floatArray;
                        var vertexCount   = intArray[meshData.offset + (int)BinaryOffset.MeshVertexCount];
                        var triangleCount = intArray[meshData.offset + (int)BinaryOffset.MeshTriangleCount];
                        int vertexOffset  = intArray[meshData.offset + (int)BinaryOffset.MeshFloatOffset];
                        if (vertexOffset < 0)
                        {
                            vertexOffset += 65536; // Fixed out of bouds bug.
                        }

                        var uvOffset = vertexOffset + vertexCount * 2;

                        if (this._uvs == null || this._uvs.Length != vertexCount)
                        {
                            this._uvs = new Vector2[vertexCount];
                        }

                        if (this._vertices == null || this._vertices.Length != vertexCount)
                        {
                            this._vertices  = new Vector3[vertexCount];
                            this._vertices2 = new Vector3[vertexCount];
                        }

                        int[] triangles = new int[triangleCount * 3];

                        for (int i = 0, iV = vertexOffset, iU = uvOffset, l = vertexCount; i < l; ++i)
                        {
                            this._vertices[i].x = floatArray[iV++] * textureScale;
                            this._vertices[i].y = floatArray[iV++] * textureScale;

                            this._uvs[i].x = (sourceX + floatArray[iU++] * sourceWidth) / textureAtlasWidth;
                            this._uvs[i].y = 1.0f - (sourceY + floatArray[iU++] * sourceHeight) / textureAtlasHeight;

                            this._vertices2[i] = this._vertices[i];
                        }

                        for (int i = 0; i < triangleCount * 3; ++i)
                        {
                            triangles[i] = intArray[meshData.offset + (int)BinaryOffset.MeshVertexIndices + i];
                        }

                        //
                        meshDisplay.vertices  = this._vertices;
                        meshDisplay.uv        = this._uvs;// Must set vertices before uvs.
                        meshDisplay.triangles = triangles;
                    }
                    else
                    {
                        if (_vertices == null || _vertices.Length != 4)
                        {
                            _vertices  = new Vector3[4];
                            _vertices2 = new Vector3[4];
                        }

                        // Normal texture.
                        for (int i = 0, l = 4; i < l; ++i)
                        {
                            var u = 0.0f;
                            var v = 0.0f;

                            switch (i)
                            {
                            case 0:
                                break;

                            case 1:
                                u = 1.0f;
                                break;

                            case 2:
                                u = 1.0f;
                                v = 1.0f;
                                break;

                            case 3:
                                v = 1.0f;
                                break;

                            default:
                                break;
                            }

                            var scaleWidth  = sourceWidth * textureScale;
                            var scaleHeight = sourceHeight * textureScale;
                            var pivotX      = _pivotX;
                            var pivotY      = scaleHeight - _pivotY;

                            if (currentTextureData.rotated)
                            {
                                var temp = scaleWidth;
                                scaleWidth  = scaleHeight;
                                scaleHeight = temp;

                                pivotX = scaleWidth - _pivotX;
                                pivotY = scaleHeight - _pivotY;

                                //uv
                                _helpVector2s[i].x = (sourceX + (1.0f - v) * sourceWidth) / textureAtlasWidth;
                                _helpVector2s[i].y = 1.0f - (sourceY + u * sourceHeight) / textureAtlasHeight;
                            }
                            else
                            {
                                //uv
                                _helpVector2s[i].x = (sourceX + u * sourceWidth) / textureAtlasWidth;
                                _helpVector2s[i].y = 1.0f - (sourceY + v * sourceHeight) / textureAtlasHeight;
                            }

                            //vertices
                            _vertices[i].x = (u * scaleWidth) - pivotX;
                            _vertices[i].y = (1.0f - v) * scaleHeight - pivotY;

                            _vertices[i].z = 0.0f;
                            _vertices2[i]  = _vertices[i];
                        }

                        _mesh.vertices  = _vertices; // Must set vertices before uvs.
                        _mesh.uv        = _helpVector2s;
                        _mesh.triangles = TRIANGLES;
                    }

                    if (_proxy.isUGUI)
                    {
                        _uiDisplay.material = currentTextureAtlas;
                        _uiDisplay.texture  = currentTextureAtlas.mainTexture;
                        _mesh.RecalculateBounds();
                        _uiDisplay.sharedMesh = _mesh;
                    }
                    else
                    {
                        if (_renderer.enabled)
                        {
                            _mesh.RecalculateBounds();
                        }

                        _meshFilter.sharedMesh   = _mesh;
                        _renderer.sharedMaterial = currentTextureAtlas;
                    }

                    this._blendModeDirty = true;
                    this._colorDirty     = true;// Relpace texture will override blendMode and color.
                    this._visibleDirty   = true;
                    return;
                }
            }

            _renderDisplay.SetActive(false);
            if (_proxy.isUGUI)
            {
                _uiDisplay.material   = null;
                _uiDisplay.texture    = null;
                _uiDisplay.sharedMesh = null;
            }
            else
            {
                _meshFilter.sharedMesh   = null;
                _renderer.sharedMaterial = null;
            }

            _helpVector3.x = 0.0f;
            _helpVector3.y = 0.0f;
            _helpVector3.z = _renderDisplay.transform.localPosition.z;

            _renderDisplay.transform.localPosition = _helpVector3;
        }
예제 #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;
                if (animationConfig.position != 0.0f)
                {
                    if (timeScale >= 0.0f)
                    {
                        _time = animationConfig.position;
                    }
                    else
                    {
                        _time = animationConfig.position - _duration;
                    }
                }
                else
                {
                    _time = 0.0f;
                }
            }
            else
            {
                _position = animationConfig.position;
                _duration = animationConfig.duration;
                _time     = 0.0f;
            }

            if (timeScale < 0.0f && _time == 0.0f)
            {
                _time = -0.000001f; // Can not cross last frame event.
            }

            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();
        }
예제 #14
0
 /**
  * @private
  */
 override public TextureData GenerateTextureData()
 {
     return(BaseObject.BorrowObject <UnityTextureData>());
 }
예제 #15
0
        /**
         * @private
         */
        override protected Slot _generateSlot(BuildArmaturePackage dataPackage, SlotDisplayDataSet slotDisplayDataSet, Armature armature)
        {
            var slot            = BaseObject.BorrowObject <UnitySlot>();
            var slotData        = slotDisplayDataSet.slot;
            var displayList     = new List <object>();
            var armatureDisplay = armature.display as GameObject;
            var transform       = armatureDisplay.transform.Find(slotData.name);
            var gameObject      = transform == null ? null : transform.gameObject;

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

            slot.name         = slotData.name;
            slot._rawDisplay  = gameObject;
            slot._meshDisplay = slot._rawDisplay;

            foreach (var displayData in slotDisplayDataSet.displays)
            {
                switch (displayData.type)
                {
                case DisplayType.Image:
                    if (displayData.texture == null)
                    {
                        displayData.texture = this._getTextureData(dataPackage.dataName, displayData.name);
                    }

                    displayList.Add(slot._rawDisplay);
                    break;

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

                    displayList.Add(slot._meshDisplay);
                    break;

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

                    if (childArmature != null)
                    {
                        if (childArmature._clock != null)
                        {
                            childArmature._clock.Remove(childArmature);
                        }

                        if (!slot.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.Add(childArmature);
                    break;

                default:
                    displayList.Add(null);
                    break;
                }
            }

            slot._setDisplayList(displayList);

            return(slot);
        }
        /**
         * @private
         */
        override protected Slot _generateSlot(BuildArmaturePackage dataPackage, SlotDisplayDataSet slotDisplayDataSet, Armature armature)
        {
            var slot        = BaseObject.BorrowObject <UnitySlot>();
            var slotData    = slotDisplayDataSet.slot;
            var displayList = new List <object>();

            slot.name         = slotData.name;
            slot._rawDisplay  = new GameObject();
            slot._meshDisplay = slot._rawDisplay;

            (slot._rawDisplay as GameObject).AddComponent <SpriteRenderer>();
            (slot._rawDisplay as GameObject).name = slot.name;

            foreach (var displayData in slotDisplayDataSet.displays)
            {
                switch (displayData.type)
                {
                case DisplayType.Image:
                    if (displayData.texture == null)
                    {
                        displayData.texture = this._getTextureData(dataPackage.dataName, displayData.name);
                    }

                    displayList.Add(slot._rawDisplay);
                    break;

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

                    displayList.Add(slot._meshDisplay);
                    break;

                case DisplayType.Armature:
                    var childArmature = this.BuildArmature(displayData.name, dataPackage.dataName);
                    if (childArmature != null)
                    {
                        if (!slot.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();
                            }
                        }

                        // hide
                        var childArmatureDisplay = childArmature.display as GameObject;
                        var armatureComponent    = childArmatureDisplay.GetComponent <UnityArmatureComponent>();
                        if (armatureComponent != null && EditorApplication.isPlayingOrWillChangePlaymode)
                        {
                            childArmatureDisplay.transform.parent = _hiddenObject.transform;
                        }
                        else
                        {
                            childArmatureDisplay.transform.parent = (armature.display as GameObject).transform;
                            childArmatureDisplay.SetActive(false);
                        }

                        //
                        (childArmature.display as GameObject).name = slot.name;

                        displayData.armature = childArmature.armatureData;     //
                    }

                    displayList.Add(childArmature);
                    break;

                default:
                    displayList.Add(null);
                    break;
                }
            }

            slot._setDisplayList(displayList);

            return(slot);
        }
예제 #17
0
        /**
         * @private
         */
        internal void _updateFFDTimelineStates()
        {
            var time = _time;

            if (!_animationData.hasAsynchronyTimeline)
            {
                time = _timeline._currentTime;
            }

            var ffdTimelineStates = new Dictionary <string, FFDTimelineState>();

            foreach (var ffdTimelineState in _ffdTimelines) // Create ffd timelines map.
            {
                ffdTimelineStates[ffdTimelineState.slot.name] = ffdTimelineState;
            }

            foreach (var slot in _armature.GetSlots())
            {
                var slotTimelineName   = slot.name;
                var parentTimelineName = slot.parent.name;

                if (slot._meshData != null)
                {
                    var displayIndex = slot.displayIndex;
                    var rawMeshData  = displayIndex < slot._displayDataSet.displays.Count ? slot._displayDataSet.displays[displayIndex].mesh : null;

                    if (slot._meshData == rawMeshData)
                    {
                        var ffdTimelineData = _animationData.GetFFDTimeline(_armature._skinData.name, slotTimelineName, displayIndex);
                        if (ffdTimelineData != null && ContainsBoneMask(parentTimelineName)) // && !_isFadeOut
                        {
                            var ffdTimelineState = ffdTimelineStates.ContainsKey(slotTimelineName) ? ffdTimelineStates[slotTimelineName] : null;
                            if (ffdTimelineState != null && ffdTimelineState._timeline == ffdTimelineData) // Remove ffd timeline from map.
                            {
                                ffdTimelineStates.Remove(slotTimelineName);
                            }
                            else // Create new ffd timeline.
                            {
                                ffdTimelineState      = BaseObject.BorrowObject <FFDTimelineState>();
                                ffdTimelineState.slot = slot;
                                ffdTimelineState.FadeIn(_armature, this, ffdTimelineData, time);
                                _ffdTimelines.Add(ffdTimelineState);
                            }
                        }
                        else
                        {
                            for (int i = 0, l = slot._ffdVertices.Count; i < l; ++i) // Clear slot ffd.
                            {
                                slot._ffdVertices[i] = 0.0f;
                            }

                            slot._ffdDirty = true;
                        }
                    }
                }
            }

            foreach (var ffdTimelineState in ffdTimelineStates.Values)// Remove ffd timelines.
            {
                //ffdTimelineState.slot._ffdDirty = true;
                _ffdTimelines.Remove(ffdTimelineState);
                ffdTimelineState.ReturnToPool();
            }
        }
예제 #18
0
        override public void Update(float passedTime)
        {
            var prevState     = _playState;
            var prevTime      = _currentTime;
            var prevPlayTimes = _currentPlayTimes;

            if (_playState <= 0 && _setCurrentTime(passedTime))
            {
                var eventDispatcher = _armature.eventDispatcher;

                if (prevState < 0 && _playState != prevState)
                {
                    if (_animationState.displayControl)
                    {
                        _armature._sortZOrder(null);
                    }

                    if (eventDispatcher.HasEventListener(EventObject.START))
                    {
                        var eventObject = BaseObject.BorrowObject <EventObject>();
                        eventObject.animationState = _animationState;
                        _armature._bufferEvent(eventObject, EventObject.START);
                    }
                }

                if (prevTime < 0.0f)
                {
                    return;
                }

                if (_keyFrameCount > 1)
                {
                    var currentFrameIndex = (int)(_currentTime * _frameRate); // uint
                    var currentFrame      = _timelineData.frames[currentFrameIndex];
                    if (_currentFrame != currentFrame)
                    {
                        var isReverse    = _currentPlayTimes == prevPlayTimes && prevTime > _currentTime;
                        var crossedFrame = _currentFrame;
                        _currentFrame = currentFrame;

                        if (crossedFrame == null)
                        {
                            var prevFrameIndex = (int)(prevTime * _frameRate);
                            crossedFrame = _timelineData.frames[prevFrameIndex];

                            if (isReverse)
                            {
                            }
                            else
                            {
                                if (
                                    prevTime <= crossedFrame.position
                                    // || prevPlayTimes != _currentPlayTimes ?
                                    )
                                {
                                    crossedFrame = crossedFrame.prev;
                                }
                            }
                        }

                        if (isReverse)
                        {
                            while (crossedFrame != currentFrame)
                            {
                                _onCrossFrame(crossedFrame);
                                crossedFrame = crossedFrame.prev;
                            }
                        }
                        else
                        {
                            while (crossedFrame != currentFrame)
                            {
                                crossedFrame = crossedFrame.next;
                                _onCrossFrame(crossedFrame);
                            }
                        }
                    }
                    else if (_keyFrameCount > 0 && _currentFrame == null)
                    {
                        _currentFrame = _timelineData.frames[0];
                        _onCrossFrame(_currentFrame);
                    }
                }

                if (_currentPlayTimes != prevPlayTimes)
                {
                    if (eventDispatcher.HasEventListener(EventObject.LOOP_COMPLETE))
                    {
                        var eventObject = BaseObject.BorrowObject <EventObject>();
                        eventObject.animationState = _animationState;
                        _armature._bufferEvent(eventObject, EventObject.LOOP_COMPLETE);
                    }

                    if (_playState > 0 && eventDispatcher.HasEventListener(EventObject.COMPLETE))
                    {
                        var eventObject = BaseObject.BorrowObject <EventObject>();
                        eventObject.animationState = _animationState;
                        _armature._bufferEvent(eventObject, EventObject.COMPLETE);
                    }
                }
            }
        }
예제 #19
0
        /**
         * @private
         */
        internal void _updateTimelineStates()
        {
            var boneTimelineStates = new Dictionary <string, BoneTimelineState>();
            var slotTimelineStates = new Dictionary <string, SlotTimelineState>();
            var ffdTimelineStates  = new Dictionary <string, FFDTimelineState>();

            for (int i = 0, l = _boneTimelines.Count; i < l; ++i) // Creat bone timelines map.
            {
                var boneTimelineState = _boneTimelines[i];
                boneTimelineStates[boneTimelineState.bone.name] = boneTimelineState;
            }

            var bones = _armature.GetBones();

            for (int i = 0, l = bones.Count; i < l; ++i)
            {
                var bone             = bones[i];
                var boneTimelineName = bone.name;
                if (ContainsBoneMask(boneTimelineName))
                {
                    var boneTimelineData = _animationData.GetBoneTimeline(boneTimelineName);
                    if (boneTimelineData != null)
                    {
                        if (boneTimelineStates.ContainsKey(boneTimelineName)) // Remove bone timeline from map.
                        {
                            boneTimelineStates.Remove(boneTimelineName);
                        }
                        else // Create new bone timeline.
                        {
                            var boneTimelineState = BaseObject.BorrowObject <BoneTimelineState>();
                            boneTimelineState.bone = bone;
                            boneTimelineState._init(_armature, this, boneTimelineData);
                            _boneTimelines.Add(boneTimelineState);
                        }
                    }
                }
            }

            foreach (var boneTimelineState in boneTimelineStates.Values) // Remove bone timelines.
            {
                boneTimelineState.bone.InvalidUpdate();                  //
                _boneTimelines.Remove(boneTimelineState);
                boneTimelineState.ReturnToPool();
            }

            for (int i = 0, l = _slotTimelines.Count; i < l; ++i) // Creat slot timelines map.
            {
                var slotTimelineState = _slotTimelines[i];
                slotTimelineStates[slotTimelineState.slot.name] = slotTimelineState;
            }

            for (int i = 0, l = _ffdTimelines.Count; i < l; ++i) // Creat ffd timelines map.
            {
                var ffdTimelineState = _ffdTimelines[i];
                var display          = ffdTimelineState._timelineData.display;
                var meshName         = display.inheritAnimation ? display.mesh.name : display.name;
                ffdTimelineStates[meshName] = ffdTimelineState;
            }

            var slots = _armature.GetSlots();

            for (int i = 0, l = slots.Count; i < l; ++i)
            {
                var slot               = slots[i];
                var slotTimelineName   = slot.name;
                var parentTimelineName = slot.parent.name;
                var resetFFDVertices   = false;

                if (ContainsBoneMask(parentTimelineName))
                {
                    var slotTimelineData = _animationData.GetSlotTimeline(slotTimelineName);
                    if (slotTimelineData != null)
                    {
                        if (slotTimelineStates.ContainsKey(slotTimelineName)) // Remove slot timeline from map.
                        {
                            slotTimelineStates.Remove(slotTimelineName);
                        }
                        else // Create new slot timeline.
                        {
                            var slotTimelineState = BaseObject.BorrowObject <SlotTimelineState>();
                            slotTimelineState.slot = slot;
                            slotTimelineState._init(_armature, this, slotTimelineData);
                            _slotTimelines.Add(slotTimelineState);
                        }
                    }

                    var ffdTimelineDatas = _animationData.GetFFDTimeline(_armature._skinData.name, slotTimelineName);
                    if (ffdTimelineDatas != null)
                    {
                        foreach (var pair in ffdTimelineDatas)
                        {
                            if (ffdTimelineStates.ContainsKey(pair.Key)) // Remove ffd timeline from map.
                            {
                                ffdTimelineStates.Remove(pair.Key);
                            }
                            else // Create new ffd timeline.
                            {
                                var ffdTimelineState = BaseObject.BorrowObject <FFDTimelineState>();
                                ffdTimelineState.slot = slot;
                                ffdTimelineState._init(_armature, this, pair.Value);
                                _ffdTimelines.Add(ffdTimelineState);
                            }
                        }
                    }
                    else
                    {
                        resetFFDVertices = true;
                    }
                }
                else
                {
                    resetFFDVertices = true;
                }

                if (resetFFDVertices)
                {
                    for (int iA = 0, lA = slot._ffdVertices.Count; iA < lA; ++iA)
                    {
                        slot._ffdVertices[iA] = 0.0f;
                    }

                    slot._meshDirty = true;
                }
            }

            foreach (var slotTimelineState in slotTimelineStates.Values) // Remove slot timelines.
            {
                _slotTimelines.Remove(slotTimelineState);
                slotTimelineState.ReturnToPool();
            }

            foreach (var ffdTimelineState in ffdTimelineStates.Values)// Remove ffd timelines.
            {
                _ffdTimelines.Remove(ffdTimelineState);
                ffdTimelineState.ReturnToPool();
            }
        }
예제 #20
0
        /// <private/>
        protected object _GetSlotDisplay(BuildArmaturePackage dataPackage, DisplayData displayData, DisplayData rawDisplayData, Slot slot)
        {
            var    dataName = dataPackage != null ? dataPackage.dataName : displayData.parent.parent.parent.name;
            object display  = null;

            switch (displayData.type)
            {
            case DisplayType.Image:
            {
                var imageDisplayData = displayData as ImageDisplayData;
                if (imageDisplayData.texture == null)
                {
                    imageDisplayData.texture = this._GetTextureData(dataName, displayData.path);
                }
                else if (dataPackage != null && !string.IsNullOrEmpty(dataPackage.textureAtlasName))
                {
                    imageDisplayData.texture = this._GetTextureData(dataPackage.textureAtlasName, displayData.path);
                }

                if (rawDisplayData != null && rawDisplayData.type == DisplayType.Mesh && this._IsSupportMesh())
                {
                    display = slot.meshDisplay;
                }
                else
                {
                    display = slot.rawDisplay;
                }
            }
            break;

            case DisplayType.Mesh:
            {
                var meshDisplayData = displayData as MeshDisplayData;
                if (meshDisplayData.texture == null)
                {
                    meshDisplayData.texture = this._GetTextureData(dataName, meshDisplayData.path);
                }
                else if (dataPackage != null && !string.IsNullOrEmpty(dataPackage.textureAtlasName))
                {
                    meshDisplayData.texture = this._GetTextureData(dataPackage.textureAtlasName, meshDisplayData.path);
                }

                if (this._IsSupportMesh())
                {
                    display = slot.meshDisplay;
                }
                else
                {
                    display = slot.rawDisplay;
                }
            }
            break;

            case DisplayType.Armature:
            {
                var armatureDisplayData = displayData as ArmatureDisplayData;
                var childArmature       = this._BuildChildArmature(dataPackage, slot, displayData);
                if (childArmature != null)
                {
                    childArmature.inheritAnimation = armatureDisplayData.inheritAnimation;
                    if (!childArmature.inheritAnimation)
                    {
                        var actions = armatureDisplayData.actions.Count > 0 ? armatureDisplayData.actions : childArmature.armatureData.defaultActions;
                        if (actions.Count > 0)
                        {
                            foreach (var action in actions)
                            {
                                var eventObject = BaseObject.BorrowObject <EventObject>();
                                EventObject.ActionDataToInstance(action, eventObject, slot.armature);
                                eventObject.slot = slot;
                                slot.armature._BufferAction(eventObject, false);
                            }
                        }
                        else
                        {
                            childArmature.animation.Play();
                        }
                    }

                    armatureDisplayData.armature = childArmature.armatureData;         //
                }

                display = childArmature;
            }
            break;

            case DisplayType.BoundingBox:
                break;
            }

            return(display);
        }
예제 #21
0
        /**
         * @language zh_CN
         * @beta
         * 通过动画配置来播放动画。
         * @param animationConfig 动画配置。
         * @returns 对应的动画状态。
         * @see DragonBones.AnimationConfig
         * @see DragonBones.AnimationState
         * @version DragonBones 5.0
         */
        public AnimationState PlayConfig(AnimationConfig animationConfig)
        {
            if (animationConfig == null)
            {
                DragonBones.Assert(false, DragonBones.ARGUMENT_ERROR);
                return(null);
            }

            var animationName = !string.IsNullOrEmpty(animationConfig.animationName) ? animationConfig.animationName : animationConfig.name;
            var animationData = _animations.ContainsKey(animationName) ? _animations[animationName] : null;

            if (animationData == null)
            {
                DragonBones.Assert(false,
                                   "Non-existent animation.\n" +
                                   "DragonBones name: " + _armature.armatureData.parent.name +
                                   " Armature name: " + _armature.name +
                                   " Animation name: " + animationName
                                   );

                return(null);
            }

            _isPlaying = true;

            if (animationConfig.playTimes < 0)
            {
                animationConfig.playTimes = (int)animationData.playTimes;
            }

            if (animationConfig.fadeInTime < 0.0f || float.IsNaN(animationConfig.fadeInTime))
            {
                if (_lastAnimationState != null)
                {
                    animationConfig.fadeInTime = animationData.fadeInTime;
                }
                else
                {
                    animationConfig.fadeInTime = 0.0f;
                }
            }

            if (animationConfig.fadeOutTime < 0.0f || float.IsNaN(animationConfig.fadeOutTime))
            {
                animationConfig.fadeOutTime = animationConfig.fadeInTime;
            }

            if (animationConfig.timeScale <= -100.0f || float.IsNaN(animationConfig.timeScale)) //
            {
                animationConfig.timeScale = 1.0f / animationData.scale;
            }

            if (animationData.duration > 0.0f)
            {
                if (float.IsNaN(animationConfig.position))
                {
                    animationConfig.position = 0.0f;
                }
                else if (animationConfig.position < 0.0f)
                {
                    animationConfig.position %= animationData.duration;
                    animationConfig.position  = animationData.duration - animationConfig.position;
                }
                else if (animationConfig.position == animationData.duration)
                {
                    animationConfig.position -= 0.001f;
                }
                else if (animationConfig.position > animationData.duration)
                {
                    animationConfig.position %= animationData.duration;
                }

                if (animationConfig.position + animationConfig.duration > animationData.duration)
                {
                    animationConfig.duration = animationData.duration - animationConfig.position;
                }
            }
            else
            {
                animationConfig.position = 0.0f;
                animationConfig.duration = -1.0f;
            }

            var isStop = animationConfig.duration == 0.0f;

            if (isStop)
            {
                animationConfig.playTimes  = 1;
                animationConfig.duration   = -1.0f;
                animationConfig.fadeInTime = 0.0f;
            }

            _fadeOut(animationConfig);

            _lastAnimationState = BaseObject.BorrowObject <AnimationState>();
            _lastAnimationState._init(_armature, animationData, animationConfig);
            _animationStates.Add(_lastAnimationState);
            _animationStateDirty = true;
            _cacheFrameIndex     = -1;

            if (_animationStates.Count > 1)
            {
                _animationStates.Sort(_sortAnimationState);
            }

            // Child armature play same name animation.
            var slots = _armature.GetSlots();

            for (int i = 0, l = slots.Count; i < l; ++i)
            {
                var childArmature = slots[i].childArmature;
                if (
                    childArmature != null && childArmature.inheritAnimation &&
                    childArmature.animation.HasAnimation(animationName) &&
                    childArmature.animation.GetState(animationName) == null
                    )
                {
                    childArmature.animation.FadeIn(animationName); //
                }
            }

            if (animationConfig.fadeInTime <= 0.0f) // Blend animation state, update armature.
            {
                _armature.AdvanceTime(0.0f);
            }

            if (isStop)
            {
                _lastAnimationState.Stop();
            }

            return(_lastAnimationState);
        }
예제 #22
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 slotsRoot       = armatureDisplay.GetComponent <UnityArmatureComponent>().slotsRoot.transform;
            var transform       = slotsRoot.Find(skinSlotData.slot.name);
            var gameObject      = transform == null ? null : transform.gameObject;

            if (gameObject == null)
            {
                gameObject = new GameObject(slotData.name);
            }

            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   = slotsRoot.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.GetComponent <UnityArmatureComponent>().isUGUI = armatureDisplay.GetComponent <UnityArmatureComponent>().isUGUI;
                        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);
        }