예제 #1
0
    static int ReplaceDisplay(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 3)
            {
                DragonBones.UnityFactory obj  = (DragonBones.UnityFactory)ToLua.CheckObject <DragonBones.UnityFactory>(L, 1);
                DragonBones.Slot         arg0 = (DragonBones.Slot)ToLua.CheckObject <DragonBones.Slot>(L, 2);
                DragonBones.DisplayData  arg1 = (DragonBones.DisplayData)ToLua.CheckObject <DragonBones.DisplayData>(L, 3);
                obj.ReplaceDisplay(arg0, arg1);
                return(0);
            }
            else if (count == 4)
            {
                DragonBones.UnityFactory obj  = (DragonBones.UnityFactory)ToLua.CheckObject <DragonBones.UnityFactory>(L, 1);
                DragonBones.Slot         arg0 = (DragonBones.Slot)ToLua.CheckObject <DragonBones.Slot>(L, 2);
                DragonBones.DisplayData  arg1 = (DragonBones.DisplayData)ToLua.CheckObject <DragonBones.DisplayData>(L, 3);
                int arg2 = (int)LuaDLL.luaL_checknumber(L, 4);
                obj.ReplaceDisplay(arg0, arg1, arg2);
                return(0);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: DragonBones.UnityFactory.ReplaceDisplay"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
예제 #2
0
        /// <private/>
        internal void ReplaceDisplayData(DisplayData value, int displayIndex = -1)
        {
            if (displayIndex < 0)
            {
                if (this._displayIndex < 0)
                {
                    displayIndex = 0;
                }
                else
                {
                    displayIndex = this._displayIndex;
                }
            }

            if (this._displayDatas.Count <= displayIndex)
            {
                this._displayDatas.ResizeList(displayIndex + 1);

                for (int i = 0, l = this._displayDatas.Count; i < l; ++i)
                {
                    // Clean undefined.
                    this._displayDatas[i] = null;
                }
            }

            this._displayDatas[displayIndex] = value;
        }
        protected override void _onClear()
        {
            base._onClear();

            skin    = null;
            slot    = null;
            display = null;
        }
예제 #4
0
        /**
         * @private
         */
        protected void _updatePivot(DisplayData rawDisplayData, DisplayData currentDisplayData, TextureData currentTextureData)
        {
            var isReplaceDisplay = rawDisplayData != null && rawDisplayData != currentDisplayData;

            if (_meshData != null && _display == _meshDisplay)
            {
                if (_meshData != rawDisplayData.mesh && isReplaceDisplay)
                {
                    _pivotX = rawDisplayData.transform.x - currentDisplayData.transform.x;
                    _pivotY = rawDisplayData.transform.y - currentDisplayData.transform.y;
                }
                else
                {
                    _pivotX = 0.0f;
                    _pivotY = 0.0f;
                }
            }
            else
            {
                var scale = this._armature.armatureData.scale;
                _pivotX = currentDisplayData.pivot.x;
                _pivotY = currentDisplayData.pivot.y;

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

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

                    _pivotX *= width;
                    _pivotY *= height;
                }

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

                if (isReplaceDisplay)
                {
                    _pivotX += rawDisplayData.transform.x - currentDisplayData.transform.x;
                    _pivotY += rawDisplayData.transform.y - currentDisplayData.transform.y;
                }
            }
        }
예제 #5
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;
            }
        }
예제 #6
0
        /**
         * @private
         */
        protected void _ReplaceSlotDisplay(BuildArmaturePackage dataPackage, DisplayData displayData, Slot slot, int displayIndex)
        {
            if (displayIndex < 0)
            {
                displayIndex = slot.displayIndex;
            }

            if (displayIndex < 0)
            {
                displayIndex = 0;
            }

            slot.ReplaceDisplayData(displayData, displayIndex);

            var displayList = slot.displayList; // Copy.

            if (displayList.Count <= displayIndex)
            {
                displayList.ResizeList(displayIndex + 1);

                for (int i = 0, l = displayList.Count; i < l; ++i)
                {
                    // Clean undefined.
                    displayList[i] = null;
                }
            }

            if (displayData != null)
            {
                var         rawDisplayDatas = slot.rawDisplayDatas;
                DisplayData rawDisplayData  = null;

                if (rawDisplayDatas != null)
                {
                    if (displayIndex < rawDisplayDatas.Count)
                    {
                        rawDisplayData = rawDisplayDatas[displayIndex];
                    }
                }

                displayList[displayIndex] = this._GetSlotDisplay(dataPackage, displayData, rawDisplayData, slot);
            }
            else
            {
                displayList[displayIndex] = null;
            }

            slot.displayList = displayList;
        }
        /// <private/>
        public virtual void ReplaceDisplay(Slot slot, DisplayData displayData, int displayIndex = -1)
        {
            if (displayIndex < 0)
            {
                displayIndex = slot.displayIndex;
            }

            if (displayIndex < 0)
            {
                displayIndex = 0;
            }

            slot.ReplaceDisplayData(displayData, displayIndex);

            var displayList = slot.displayList; // Copy.

            if (displayList.Count <= displayIndex)
            {
                displayList.ResizeList(displayIndex + 1);

                for (int i = 0, l = displayList.Count; i < l; ++i)
                {
                    // Clean undefined.
                    displayList[i] = null;
                }
            }

            if (displayData != null)
            {
                var         rawDisplayDatas = slot.rawDisplayDatas;
                DisplayData rawDisplayData  = null;

                if (rawDisplayDatas != null)
                {
                    if (displayIndex < rawDisplayDatas.Count)
                    {
                        rawDisplayData = rawDisplayDatas[displayIndex];
                    }
                }

                displayList[displayIndex] = this._GetSlotDisplay(null, displayData, rawDisplayData, slot);
            }
            else
            {
                displayList[displayIndex] = null;
            }

            slot.displayList = displayList;
        }
        /**
         * @private
         */
        public void AddDisplay(string slotName, DisplayData value)
        {
            if (!string.IsNullOrEmpty(slotName) && value != null && !string.IsNullOrEmpty(value.name))
            {
                if (!this.displays.ContainsKey(slotName))
                {
                    this.displays[slotName] = new List <DisplayData>();
                }

                if (value != null)
                {
                    value.parent = this;
                }

                var slotDisplays = this.displays[slotName]; // TODO clear prev
                slotDisplays.Add(value);
            }
        }
예제 #9
0
        /// <private/>
        public override void ReplaceDisplay(Slot slot, DisplayData displayData, int displayIndex = -1)
        {
            //UGUI Display Object and Normal Display Object cannot be replaced with each other
            if (displayData.type == DisplayType.Image || displayData.type == DisplayType.Mesh)
            {
                var dataName    = displayData.parent.parent.parent.name;
                var textureData = this._GetTextureData(dataName, displayData.path);
                if (textureData != null)
                {
                    var textureAtlasData = textureData.parent as UnityTextureAtlasData;

                    var oldIsUGUI = (slot._armature.proxy as UnityArmatureComponent).isUGUI;

                    if ((oldIsUGUI && textureAtlasData.uiTexture == null) || (!oldIsUGUI && textureAtlasData.texture == null))
                    {
                        LogHelper.LogWarning("ugui display object and normal display object cannot be replaced with each other");
                        return;
                    }
                }
            }

            base.ReplaceDisplay(slot, displayData, displayIndex);
        }
예제 #10
0
        protected override Armature _BuildChildArmature(BuildArmaturePackage dataPackage, Slot slot, DisplayData displayData)
        {
            var      childDisplayName = slot.slotData.name + " (" + displayData.path + ")"; //
            var      proxy            = slot.armature.proxy as UnityArmatureComponent;
            var      childTransform   = proxy.transform.Find(childDisplayName);
            Armature childArmature    = null;

            if (childTransform == null)
            {
                childArmature = BuildArmature(displayData.path, dataPackage.dataName);
            }
            else
            {
                if (dataPackage != null)
                {
                    childArmature = BuildArmatureComponent(displayData.path, dataPackage != null ? dataPackage.dataName : "", null, dataPackage.textureAtlasName, childTransform.gameObject).armature;
                }
                else
                {
                    childArmature = BuildArmatureComponent(displayData.path, null, null, null, childTransform.gameObject).armature;
                }
            }

            //
            var childArmatureDisplay = childArmature.display as GameObject;

            childArmatureDisplay.GetComponent <UnityArmatureComponent>().isUGUI = proxy.GetComponent <UnityArmatureComponent>().isUGUI;
            childArmatureDisplay.name = childDisplayName;
            childArmatureDisplay.transform.SetParent(proxy.transform, false);
            childArmatureDisplay.gameObject.hideFlags = HideFlags.HideInHierarchy;
            childArmatureDisplay.SetActive(false);
            return(childArmature);
        }
예제 #11
0
        /// <private/>
        protected void _UpdateDisplayData()
        {
            var prevDisplayData = this._displayData;
            var prevTextureData = this._textureData;
            var prevMeshData    = this._meshData;
            var rawDisplayData  = this._displayIndex >= 0 && this._rawDisplayDatas != null && this._displayIndex < this._rawDisplayDatas.Count ? this._rawDisplayDatas[this._displayIndex] : null;

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

            // Update texture and mesh data.
            if (this._displayData != null)
            {
                if (this._displayData.type == DisplayType.Image || this._displayData.type == DisplayType.Mesh)
                {
                    this._textureData = (this._displayData as ImageDisplayData).texture;
                    if (this._displayData.type == DisplayType.Mesh)
                    {
                        this._meshData = this._displayData as MeshDisplayData;
                    }
                    else if (rawDisplayData != null && rawDisplayData.type == DisplayType.Mesh)
                    {
                        this._meshData = rawDisplayData as MeshDisplayData;
                    }
                    else
                    {
                        this._meshData = null;
                    }
                }
                else
                {
                    this._textureData = null;
                    this._meshData    = null;
                }
            }
            else
            {
                this._textureData = null;
                this._meshData    = null;
            }

            // Update bounding box data.
            if (this._displayData != null && this._displayData.type == DisplayType.BoundingBox)
            {
                this._boundingBoxData = (this._displayData as BoundingBoxDisplayData).boundingBox;
            }
            else if (rawDisplayData != null && rawDisplayData.type == DisplayType.BoundingBox)
            {
                this._boundingBoxData = (rawDisplayData as BoundingBoxDisplayData).boundingBox;
            }
            else
            {
                this._boundingBoxData = null;
            }

            if (this._displayData != prevDisplayData || this._textureData != prevTextureData || this._meshData != prevMeshData)
            {
                // Update pivot offset.
                if (this._meshData != null)
                {
                    this._pivotX = 0.0f;
                    this._pivotY = 0.0f;
                }
                else if (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;
                    }
                }
                else
                {
                    this._pivotX = 0.0f;
                    this._pivotY = 0.0f;
                }

                // Update mesh bones and ffd vertices.
                if (this._meshData != prevMeshData)
                {
                    if (this._meshData != null)// && this._meshData === this._displayData
                    {
                        if (this._meshData.weight != null)
                        {
                            this._ffdVertices.ResizeList(this._meshData.weight.count * 2);
                            this._meshBones.ResizeList(this._meshData.weight.bones.Count);

                            for (int i = 0, l = this._meshBones.Count; i < l; ++i)
                            {
                                this._meshBones[i] = this._armature.GetBone(this._meshData.weight.bones[i].name);
                            }
                        }
                        else
                        {
                            var vertexCount = this._meshData.parent.parent.parent.intArray[this._meshData.offset + (int)BinaryOffset.MeshVertexCount];
                            this._ffdVertices.ResizeList(vertexCount * 2);
                            this._meshBones.Clear();
                        }

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

                        this._meshDirty = true;
                    }
                    else
                    {
                        this._ffdVertices.Clear();
                        this._meshBones.Clear();
                    }
                }
                else if (this._meshData != null && this._textureData != prevTextureData)
                {
                    // Update mesh after update frame.
                    this._meshDirty = true;
                }

                if (this._displayData != null && rawDisplayData != null && this._displayData != rawDisplayData && this._meshData == null)
                {
                    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;
                }

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

                this._displayDirty             = true;
                this._transformDirty           = true;
                this._skinedMeshTransformDirty = true;
            }
        }
예제 #12
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;
                    //Debug.Log(_pivotX + "," + _pivotY);

                    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;
                    //Debug.Log(_pivotX + "," + _pivotY);
                    if (frame != null)
                    {
                        this._pivotX += frame.x * scale;
                        this._pivotY += frame.y * scale;
                    }

                    //Debug.Log("-----------");

                    // 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;
            }
        }
예제 #13
0
        /// <inheritDoc/>
        protected override void _OnClear()
        {
            base._OnClear();

            var disposeDisplayList = new List <object>();

            for (int i = 0, l = _displayList.Count; i < l; ++i)
            {
                var eachDisplay = _displayList[i];
                if (eachDisplay != _rawDisplay && eachDisplay != _meshDisplay && !disposeDisplayList.Contains(eachDisplay))
                {
                    disposeDisplayList.Add(eachDisplay);
                }
            }

            for (int i = 0, l = disposeDisplayList.Count; i < l; ++i)
            {
                var eachDisplay = disposeDisplayList[i];
                if (eachDisplay is Armature)
                {
                    (eachDisplay as Armature).Dispose();
                }
                else
                {
                    this._DisposeDisplay(eachDisplay, true);
                }
            }

            if (this._deformVertices != null)
            {
                this._deformVertices.ReturnToPool();
            }

            if (this._meshDisplay != null && this._meshDisplay != this._rawDisplay)
            {
                // May be _meshDisplay and _rawDisplay is the same one.
                this._DisposeDisplay(this._meshDisplay, false);
            }

            if (this._rawDisplay != null)
            {
                this._DisposeDisplay(this._rawDisplay, false);
            }

            this.displayController = null;

            this._displayDirty          = false;
            this._zOrderDirty           = false;
            this._blendModeDirty        = false;
            this._colorDirty            = false;
            this._transformDirty        = false;
            this._visible               = true;
            this._blendMode             = BlendMode.Normal;
            this._displayIndex          = -1;
            this._animationDisplayIndex = -1;
            this._zOrder           = 0;
            this._cachedFrameIndex = -1;
            this._pivotX           = 0.0f;
            this._pivotY           = 0.0f;
            this._localMatrix.Identity();
            this._colorTransform.Identity();
            this._displayList.Clear();
            this._displayDatas.Clear();
            this._slotData           = null; //
            this._rawDisplayDatas    = null; //
            this._displayData        = null;
            this._boundingBoxData    = null;
            this._textureData        = null;
            this._deformVertices     = null;
            this._rawDisplay         = null;
            this._meshDisplay        = null;
            this._display            = null;
            this._childArmature      = null;
            this._parent             = null;
            this._cachedFrameIndices = null;
        }
예제 #14
0
        /**
         * @private
         */
        protected override void _onClear()
        {
            base._onClear();

            var disposeDisplayList = new List <object>();

            for (int i = 0, l = _displayList.Count; i < l; ++i)
            {
                var eachDisplay = _displayList[i];
                if (
                    eachDisplay != _rawDisplay && eachDisplay != _meshDisplay &&
                    !disposeDisplayList.Contains(eachDisplay)
                    )
                {
                    disposeDisplayList.Add(eachDisplay);
                }
            }

            for (int i = 0, l = disposeDisplayList.Count; i < l; ++i)
            {
                var eachDisplay = disposeDisplayList[i];
                if (eachDisplay is Armature)
                {
                    (eachDisplay as Armature).Dispose();
                }
                else
                {
                    _disposeDisplay(eachDisplay);
                }
            }

            if (_meshDisplay != null && _meshDisplay != _rawDisplay) // May be _meshDisplay and _rawDisplay is the same one.
            {
                _disposeDisplay(_meshDisplay);
            }

            if (_rawDisplay != null)
            {
                _disposeDisplay(_rawDisplay);
            }

            displayController = null;

            _displayDirty     = false;
            _zOrderDirty      = false;
            _blendModeDirty   = false;
            _colorDirty       = false;
            _originalDirty    = false;
            _transformDirty   = false;
            _meshDirty        = false;
            _updateState      = -1;
            _blendMode        = BlendMode.Normal;
            _displayIndex     = -1;
            _cachedFrameIndex = -1;
            _zOrder           = -1;
            _pivotX           = 0.0f;
            _pivotY           = 0.0f;
            _localMatrix.Identity();
            _colorTransform.Identity();
            _ffdVertices.Clear();
            _displayList.Clear();
            _replacedDisplayDatas.Clear();
            _meshBones.Clear();
            _skinSlotData        = null;
            _displayData         = null;
            _replacedDisplayData = null;
            _textureData         = null;
            _meshData            = null;
            _boundingBoxData     = null;
            _rawDisplay          = null;
            _meshDisplay         = null;
            _display             = null;
            _childArmature       = null;
            _cachedFrameIndices  = null;
        }
예제 #15
0
        /// <summary>
        /// 用特定的显示对象数据替换特定插槽当前的显示对象数据。
        /// </summary>
        /// <param name="dragonBonesName">The DragonBonesData instance cache name</param>
        /// <param name="armatureName">The armature data name</param>
        /// <param name="slotName">The slot data name</param>
        /// <param name="displayName">The display data name</param>
        /// <param name="slot">The slot</param>
        /// <param name="texture">The new texture</param>
        /// <param name="material">The new material</param>
        /// <param name="isUGUI">is ugui。</param>
        /// <param name="displayIndex">The index of the display data that is replaced. (If it is not set, replaces the current display data)</param>
        /// <version>DragonBones 4.5</version>
        /// <language>zh_CN</language>

        /// <summary>
        /// 用特定的显示对象数据替换特定插槽当前的显示对象数据。
        /// </summary>
        /// <param name="dragonBonesName">指定的龙骨数据名称。</param>
        /// <param name="armatureName">指定的骨架名称。</param>
        /// <param name="slotName">指定的插槽名称。</param>
        /// <param name="displayName">指定的显示对象名称。</param>
        /// <param name="slot">指定的插槽实例。</param>
        /// <param name="texture">新的贴图。</param>
        /// <param name="material">新的材质。</param>
        /// <param name="isUGUI">是否为ugui。</param>
        /// <param name="displayIndex">被替换的显示对象数据的索引。 (如果未设置,则替换当前的显示对象数据)。</param>
        /// <version>DragonBones 4.5</version>
        /// <language>zh_CN</language>
        public void ReplaceSlotDisplay(
            string dragonBonesName, string armatureName, string slotName, string displayName,
            Slot slot, Texture2D texture, Material material,
            bool isUGUI = false, int displayIndex = -1)
        {
            var armatureData = this.GetArmatureData(armatureName, dragonBonesName);

            if (armatureData == null || armatureData.defaultSkin == null)
            {
                return;
            }

            var displays = armatureData.defaultSkin.GetDisplays(slotName);

            if (displays == null)
            {
                return;
            }

            DisplayData prevDispalyData = null;

            foreach (var displayData in displays)
            {
                if (displayData.name == displayName)
                {
                    prevDispalyData = displayData;
                    break;
                }
            }

            if (prevDispalyData == null || !(prevDispalyData is ImageDisplayData))
            {
                return;
            }

            TextureData      prevTextureData = (prevDispalyData as ImageDisplayData).texture;
            UnityTextureData newTextureData  = new UnityTextureData();

            newTextureData.CopyFrom(prevTextureData);
            newTextureData.rotated       = false;
            newTextureData.region.x      = 0.0f;
            newTextureData.region.y      = 0.0f;
            newTextureData.region.width  = texture.width;
            newTextureData.region.height = texture.height;
            newTextureData.frame         = newTextureData.region;
            newTextureData.name          = prevTextureData.name;
            newTextureData.parent        = new UnityTextureAtlasData();
            newTextureData.parent.width  = (uint)texture.width;
            newTextureData.parent.height = (uint)texture.height;
            if (isUGUI)
            {
                (newTextureData.parent as UnityTextureAtlasData).uiTexture = material;
            }
            else
            {
                (newTextureData.parent as UnityTextureAtlasData).texture = material;
            }

            material.mainTexture = texture;

            ImageDisplayData newDisplayData = prevDispalyData is MeshDisplayData ? new MeshDisplayData() : new ImageDisplayData();

            newDisplayData.type = prevDispalyData.type;
            newDisplayData.name = prevDispalyData.name;
            newDisplayData.path = prevDispalyData.path;
            newDisplayData.transform.CopyFrom(prevDispalyData.transform);
            newDisplayData.parent = prevDispalyData.parent;
            newDisplayData.pivot.CopyFrom((prevDispalyData as ImageDisplayData).pivot);
            newDisplayData.texture = newTextureData;

            if (newDisplayData is MeshDisplayData)
            {
                (newDisplayData as MeshDisplayData).inheritAnimation = (prevDispalyData as MeshDisplayData).inheritAnimation;
                (newDisplayData as MeshDisplayData).offset           = (prevDispalyData as MeshDisplayData).offset;
                (newDisplayData as MeshDisplayData).weight           = (prevDispalyData as MeshDisplayData).weight;
            }

            ReplaceDisplay(slot, newDisplayData, displayIndex);
        }
예제 #16
0
        /**
         * @language zh_CN
         * 用外部贴图替换display贴图。
         * @param dragonBonesName 指定的龙骨数据名称。
         * @param armatureName 指定的骨架名称。
         * @param slotName 指定的插槽名称。
         * @param displayName 指定的显示对象名称。
         * @param slot 指定的插槽实例。
         * @param texture 新的贴图。
         * @param material 新的材质。
         * @param isUGUI 是否为ugui。
         * @param displayIndex 要替换的显示对象的索引,如果未设置,则替换当前正在显示的显示对象。
         * @version DragonBones 4.5
         */
        public void ReplaceSlotDisplay(string dragonBonesName, string armatureName, string slotName, string displayName, Slot slot, Texture2D texture, Material material, bool isUGUI = false, int displayIndex = -1)
        {
            var dataPackage = new BuildArmaturePackage();

            if (_fillBuildArmaturePackage(dataPackage, dragonBonesName, armatureName, null, null))
            {
                var slotDisplayDataSet = dataPackage.skin.GetSlot(slotName);
                if (slotDisplayDataSet != null)
                {
                    DisplayData prevDispalyData = null;
                    int         index           = 0;
                    foreach (var displayData in slotDisplayDataSet.displays)
                    {
                        if (displayData.name == displayName)
                        {
                            prevDispalyData = displayData;
                            break;
                        }
                        ++index;
                    }
                    if (prevDispalyData == null)
                    {
                        return;
                    }

                    TextureData      prevTextureData = prevDispalyData.texture;
                    UnityTextureData newTextureData  = new UnityTextureData();
                    newTextureData.CopyFrom(prevTextureData);
                    newTextureData.rotated       = false;
                    newTextureData.region.x      = 0f;
                    newTextureData.region.y      = 0f;
                    newTextureData.region.width  = texture.width;
                    newTextureData.region.height = texture.height;
                    newTextureData.frame         = newTextureData.region;
                    newTextureData.name          = prevTextureData.name;
                    newTextureData.parent        = new UnityTextureAtlasData();
                    newTextureData.parent.width  = texture.width;
                    newTextureData.parent.height = texture.height;
                    if (isUGUI)
                    {
                        (newTextureData.parent as UnityTextureAtlasData).uiTexture = material;
                    }
                    else
                    {
                        (newTextureData.parent as UnityTextureAtlasData).texture = material;
                    }
                    material.mainTexture = texture;

                    DisplayData newDisplayData = new DisplayData();
                    newDisplayData.armature         = prevDispalyData.armature;
                    newDisplayData.boundingBox      = prevDispalyData.boundingBox;
                    newDisplayData.inheritAnimation = prevDispalyData.inheritAnimation;
                    newDisplayData.isRelativePivot  = prevDispalyData.isRelativePivot;
                    newDisplayData.name             = prevDispalyData.name;
                    newDisplayData.pivot.CopyFrom(prevDispalyData.pivot);
                    newDisplayData.texture = newTextureData;
                    newDisplayData.type    = prevDispalyData.type;
                    newDisplayData.transform.CopyFrom(prevDispalyData.transform);
                    newDisplayData.mesh = prevDispalyData.mesh;
                    if (newDisplayData.mesh != null && newDisplayData.mesh.uvs != null)
                    {
                        List <float> uvs = new List <float>();
                        for (int i = 0; i < newDisplayData.mesh.uvs.Count; i += 2)
                        {
                            Vector2 uv    = new Vector2(newDisplayData.mesh.uvs[i], newDisplayData.mesh.uvs[i + 1]);
                            Vector2 uvPos = new Vector2(newTextureData.frame.x, -newTextureData.frame.y) +
                                            new Vector2(newTextureData.frame.width * uv.x, newTextureData.frame.height * uv.y);
                            uv.x = uvPos.x / newTextureData.frame.width;
                            uv.y = uvPos.y / newTextureData.frame.height;
                            uvs.Add(uv.x);
                            uvs.Add(uv.y);
                        }
                        newDisplayData.mesh.uvs.Clear();
                        newDisplayData.mesh.uvs.AddRange(uvs);
                    }
                    _replaceSlotDisplay(dataPackage, newDisplayData, slot, displayIndex);
                }
            }
        }
예제 #17
0
        /// <summary>
        /// 用特定的显示对象数据替换特定插槽当前的显示对象数据。
        /// </summary>
        /// <param name="dragonBonesName">The DragonBonesData instance cache name</param>
        /// <param name="armatureName">The armature data name</param>
        /// <param name="slotName">The slot data name</param>
        /// <param name="displayName">The display data name</param>
        /// <param name="slot">The slot</param>
        /// <param name="texture">The new texture</param>
        /// <param name="material">The new material</param>
        /// <param name="isUGUI">is ugui。</param>
        /// <param name="displayIndex">The index of the display data that is replaced. (If it is not set, replaces the current display data)</param>
        /// <version>DragonBones 4.5</version>
        /// <language>zh_CN</language>

        /// <summary>
        /// 用特定的显示对象数据替换特定插槽当前的显示对象数据。
        /// </summary>
        /// <param name="dragonBonesName">指定的龙骨数据名称。</param>
        /// <param name="armatureName">指定的骨架名称。</param>
        /// <param name="slotName">指定的插槽名称。</param>
        /// <param name="displayName">指定的显示对象名称。</param>
        /// <param name="slot">指定的插槽实例。</param>
        /// <param name="texture">新的贴图。</param>
        /// <param name="material">新的材质。</param>
        /// <param name="isUGUI">是否为ugui。</param>
        /// <param name="displayIndex">被替换的显示对象数据的索引。 (如果未设置,则替换当前的显示对象数据)。</param>
        /// <version>DragonBones 4.5</version>
        /// <language>zh_CN</language>
        public void ReplaceSlotDisplay(
            string dragonBonesName, string armatureName, string slotName, string displayName,
            Slot slot, Texture2D texture, Material material = null,
            bool isUGUI = false, int displayIndex = -1)
        {
            var armatureData = this.GetArmatureData(armatureName, dragonBonesName);

            if (armatureData == null || armatureData.defaultSkin == null)
            {
                return;
            }

            var displays = armatureData.defaultSkin.GetDisplays(slotName);

            if (displays == null)
            {
                return;
            }

            DisplayData prevDispalyData = null;

            foreach (var displayData in displays)
            {
                if (displayData.name == displayName)
                {
                    prevDispalyData = displayData;
                    break;
                }
            }

            if (prevDispalyData == null || !((prevDispalyData is ImageDisplayData) || (prevDispalyData is MeshDisplayData)))
            {
                return;
            }

            TextureData prevTextureData = null;

            if (prevDispalyData is ImageDisplayData)
            {
                prevTextureData = (prevDispalyData as ImageDisplayData).texture;
            }
            else
            {
                prevTextureData = (prevDispalyData as MeshDisplayData).texture;
            }

            UnityTextureData newTextureData = new UnityTextureData();

            newTextureData.CopyFrom(prevTextureData);
            newTextureData.rotated       = false;
            newTextureData.region.x      = 0.0f;
            newTextureData.region.y      = 0.0f;
            newTextureData.region.width  = texture.width;
            newTextureData.region.height = texture.height;
            newTextureData.frame         = newTextureData.region;
            newTextureData.name          = prevTextureData.name;
            newTextureData.parent        = new UnityTextureAtlasData();
            newTextureData.parent.width  = (uint)texture.width;
            newTextureData.parent.height = (uint)texture.height;
            newTextureData.parent.scale  = prevTextureData.parent.scale;

            //
            if (material == null)
            {
                if (isUGUI)
                {
                    material = UnityFactoryHelper.GenerateMaterial(defaultUIShaderName, texture.name + "_UI_Mat", texture);
                }
                else
                {
                    material = UnityFactoryHelper.GenerateMaterial(defaultShaderName, texture.name + "_Mat", texture);
                }
            }

            if (isUGUI)
            {
                (newTextureData.parent as UnityTextureAtlasData).uiTexture = material;
            }
            else
            {
                (newTextureData.parent as UnityTextureAtlasData).texture = material;
            }

            material.mainTexture = texture;

            DisplayData newDisplayData = null;

            if (prevDispalyData is ImageDisplayData)
            {
                newDisplayData      = new ImageDisplayData();
                newDisplayData.type = prevDispalyData.type;
                newDisplayData.name = prevDispalyData.name;
                newDisplayData.path = prevDispalyData.path;
                newDisplayData.transform.CopyFrom(prevDispalyData.transform);
                newDisplayData.parent = prevDispalyData.parent;
                (newDisplayData as ImageDisplayData).pivot.CopyFrom((prevDispalyData as ImageDisplayData).pivot);
                (newDisplayData as ImageDisplayData).texture = newTextureData;
            }
            else if (prevDispalyData is MeshDisplayData)
            {
                newDisplayData      = new MeshDisplayData();
                newDisplayData.type = prevDispalyData.type;
                newDisplayData.name = prevDispalyData.name;
                newDisplayData.path = prevDispalyData.path;
                newDisplayData.transform.CopyFrom(prevDispalyData.transform);
                newDisplayData.parent = prevDispalyData.parent;
                (newDisplayData as MeshDisplayData).texture = newTextureData;

                (newDisplayData as MeshDisplayData).vertices.inheritDeform = (prevDispalyData as MeshDisplayData).vertices.inheritDeform;
                (newDisplayData as MeshDisplayData).vertices.offset        = (prevDispalyData as MeshDisplayData).vertices.offset;
                (newDisplayData as MeshDisplayData).vertices.data          = (prevDispalyData as MeshDisplayData).vertices.data;
                (newDisplayData as MeshDisplayData).vertices.weight        = (prevDispalyData as MeshDisplayData).vertices.weight;
            }

            ReplaceDisplay(slot, newDisplayData, displayIndex);
        }
예제 #18
0
 /// <private/>
 protected virtual Armature _BuildChildArmature(BuildArmaturePackage dataPackage, Slot slot, DisplayData displayData)
 {
     return(this.BuildArmature(displayData.path, dataPackage != null ? dataPackage.dataName : "", "", dataPackage != null ? dataPackage.textureAtlasName : ""));
 }
예제 #19
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)
                            {
                                childArmature._BufferAction(action, true);
                            }
                        }
                        else
                        {
                            childArmature.animation.Play();
                        }
                    }

                    armatureDisplayData.armature = childArmature.armatureData;         //
                }

                display = childArmature;
            }
            break;

            case DisplayType.BoundingBox:
                break;
            }

            return(display);
        }
예제 #20
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;
            }
        }
예제 #21
0
 protected virtual Armature _BuildChildArmatrue(BuildArmaturePackage dataPackage, Slot slot, DisplayData displayData)
 {
     return(BuildArmature(displayData.path, dataPackage.dataName));
     //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;
 }