示例#1
0
 /**
  * @language zh_CN
  * 添加龙骨数据。
  * @param data 龙骨数据。
  * @param name 为数据指定一个名称,以便可以通过这个名称获取数据,如果未设置,则使用数据中的名称。
  * @see #ParseDragonBonesData()
  * @see #GetDragonBonesData()
  * @see #RemoveDragonBonesData()
  * @see DragonBones.DragonBonesData
  * @version DragonBones 3.0
  */
 public void AddDragonBonesData(DragonBonesData data, string name = null)
 {
     if (data != null)
     {
         name = !string.IsNullOrEmpty(name) ? name : data.name;
         if (!string.IsNullOrEmpty(name))
         {
             if (!_dragonBonesDataMap.ContainsKey(name))
             {
                 _dragonBonesDataMap[name] = data;
             }
             else
             {
                 DragonBones.Assert(false, "Same name data. " + name);
             }
         }
         else
         {
             DragonBones.Assert(false, "Unnamed data.");
         }
     }
     else
     {
         DragonBones.Assert(false, DragonBones.ARGUMENT_ERROR);
     }
 }
示例#2
0
        /**
         * @private
         */
        public void AddFFDTimeline(FFDTimelineData value)
        {
            if (value != null && value.skin != null && value.slot != null)
            {
                var skin = ffdTimelines.ContainsKey(value.skin.name) ?
                           ffdTimelines[value.skin.name] :
                           (ffdTimelines[value.skin.name] = new Dictionary <string, Dictionary <string, FFDTimelineData> >());

                var slot = skin.ContainsKey(value.slot.slot.name) ?
                           skin[value.slot.slot.name] :
                           (skin[value.slot.slot.name] = new Dictionary <string, FFDTimelineData>());

                if (!slot.ContainsKey(value.display.name))
                {
                    slot[value.display.name] = value;
                }
                else
                {
                    DragonBones.Assert(false, DragonBones.ARGUMENT_ERROR);
                }
            }
            else
            {
                DragonBones.Assert(false, DragonBones.ARGUMENT_ERROR);
            }
        }
示例#3
0
 /**
  * @private
  */
 public void AddBoneTimeline(BoneTimelineData value)
 {
     if (value != null && value.bone != null && !boneTimelines.ContainsKey(value.bone.name))
     {
         boneTimelines[value.bone.name] = value;
     }
     else
     {
         DragonBones.Assert(false, DragonBones.ARGUMENT_ERROR);
     }
 }
示例#4
0
 /**
  * @private
  */
 public void AddSlotTimeline(SlotTimelineData value)
 {
     if (value != null && value.slot != null && !slotTimelines.ContainsKey(value.slot.name))
     {
         slotTimelines[value.slot.name] = value;
     }
     else
     {
         DragonBones.Assert(false, DragonBones.ARGUMENT_ERROR);
     }
 }
示例#5
0
 public void AddMesh(MeshData value)
 {
     if (value != null && !string.IsNullOrEmpty(value.name) && !meshs.ContainsKey(value.name))
     {
         meshs[value.name] = value;
     }
     else
     {
         DragonBones.Assert(false, DragonBones.ARGUMENT_ERROR);
     }
 }
 /**
  * @private
  */
 public void AddTexture(TextureData value)
 {
     if (value != null && value.name != null && !textures.ContainsKey(value.name))
     {
         textures[value.name] = value;
         value.parent         = this;
     }
     else
     {
         DragonBones.Assert(false, DragonBones.ARGUMENT_ERROR);
     }
 }
示例#7
0
 /**
  * @deprecated
  */
 public void AddBone(Bone value, string parentName = null)
 {
     if (value != null)
     {
         value._setArmature(this);
         value._setParent(!string.IsNullOrEmpty(parentName) ? GetBone(parentName) : null);
     }
     else
     {
         DragonBones.Assert(false, DragonBones.ARGUMENT_ERROR);
     }
 }
 /**
  * @private
  */
 public void AddArmature(ArmatureData value)
 {
     if (value != null && value.name != null && !armatures.ContainsKey(value.name))
     {
         armatures[value.name] = value;
         _armatureNames.Add(value.name);
         value.parent = this;
     }
     else
     {
         DragonBones.Assert(false, DragonBones.ARGUMENT_ERROR);
     }
 }
示例#9
0
        /**
         * @deprecated
         */
        public void AddSlot(Slot value, string parentName)
        {
            var bone = GetBone(parentName);

            if (bone != null)
            {
                value._setArmature(this);
                value._setParent(bone);
            }
            else
            {
                DragonBones.Assert(false, DragonBones.ARGUMENT_ERROR);
            }
        }
示例#10
0
        /**
         * @private
         */
        public void AddSlot(SlotData value)
        {
            if (value != null && !string.IsNullOrEmpty(value.name) && !slots.ContainsKey(value.name))
            {
                slots[value.name] = value;
                _sortedSlots.Add(value);

                _slotDirty = true;
            }
            else
            {
                DragonBones.Assert(false, DragonBones.ARGUMENT_ERROR);
            }
        }
示例#11
0
        /**
         * @private
         */
        public void AddSkin(SkinData value)
        {
            if (value != null && !string.IsNullOrEmpty(value.name) && !skins.ContainsKey(value.name))
            {
                skins[value.name] = value;

                if (_defaultSkin == null)
                {
                    _defaultSkin = value;
                }
            }
            else
            {
                DragonBones.Assert(false, DragonBones.ARGUMENT_ERROR);
            }
        }
示例#12
0
        /**
         * @private
         */
        public void AddAnimation(AnimationData value)
        {
            if (value != null && !string.IsNullOrEmpty(value.name) && !animations.ContainsKey(value.name))
            {
                animations[value.name] = value;
                _animationNames.Add(value.name);

                if (_defaultAnimation == null)
                {
                    _defaultAnimation = value;
                }
            }
            else
            {
                DragonBones.Assert(false, DragonBones.ARGUMENT_ERROR);
            }
        }
示例#13
0
        private static void _returnObject(BaseObject obj)
        {
            var classType = obj.GetType();
            var maxCount  = _maxCountMap.ContainsKey(classType) ? _maxCountMap[classType] : _defaultMaxCount;
            var pool      = _poolsMap.ContainsKey(classType) ? _poolsMap[classType] : _poolsMap[classType] = new List <BaseObject>();

            if (pool.Count < maxCount)
            {
                if (!pool.Contains(obj))
                {
                    pool.Add(obj);
                }
                else
                {
                    DragonBones.Assert(false, DragonBones.ARGUMENT_ERROR);
                }
            }
        }
示例#14
0
        /**
         * @language zh_CN
         * 创建一个指定名称的骨架。
         * @param armatureName 骨架数据名称。
         * @param dragonBonesName 龙骨数据名称,如果未设置,将检索所有的龙骨数据,当多个龙骨数据中包含同名的骨架数据时,可能无法创建出准确的骨架。
         * @param skinName 皮肤名称,如果未设置,则使用默认皮肤。
         * @returns 骨架
         * @see DragonBones.Armature
         * @version DragonBones 3.0
         */
        public Armature BuildArmature(string armatureName, string dragonBonesName = null, string skinName = null, string textureAtlasName = null)
        {
            var dataPackage = new BuildArmaturePackage();

            if (_fillBuildArmaturePackage(dataPackage, dragonBonesName, armatureName, skinName, textureAtlasName))
            {
                var armature = _generateArmature(dataPackage);
                _buildBones(dataPackage, armature);
                _buildSlots(dataPackage, armature);

                armature.InvalidUpdate(null, true);
                armature.AdvanceTime(0.0f); // Update armature pose.

                return(armature);
            }

            DragonBones.Assert(false, "No armature data. " + armatureName + " " + dragonBonesName != null ? dragonBonesName : "");

            return(null);
        }
示例#15
0
        /**
         * @private
         */
        public void AddBone(BoneData value, string parentName)
        {
            if (value != null && !string.IsNullOrEmpty(value.name) && !bones.ContainsKey(value.name))
            {
                if (parentName != null)
                {
                    var parent = GetBone(parentName);
                    if (parent != null)
                    {
                        value.parent = parent;
                    }
                    else
                    {
                        (_bonesChildren.ContainsKey(parentName) ?
                         _bonesChildren[parentName] :
                         (_bonesChildren[parentName] = new List <BoneData>())).Add(value);
                    }
                }

                if (_bonesChildren.ContainsKey(value.name))
                {
                    foreach (var child in _bonesChildren[value.name])
                    {
                        child.parent = value;
                    }

                    _bonesChildren.Remove(value.name);
                }

                bones[value.name] = value;
                _sortedBones.Add(value);

                _boneDirty = true;
            }
            else
            {
                DragonBones.Assert(false, DragonBones.ARGUMENT_ERROR);
            }
        }
示例#16
0
 /**
  * @language zh_CN
  * 添加贴图集数据。
  * @param data 贴图集数据。
  * @param name 为数据指定一个名称,以便可以通过这个名称获取数据,如果未设置,则使用数据中的名称。
  * @see #ParseTextureAtlasData()
  * @see #GetTextureAtlasData()
  * @see #RemoveTextureAtlasData()
  * @see DragonBones.textures.TextureAtlasData
  * @version DragonBones 3.0
  */
 public void AddTextureAtlasData(TextureAtlasData data, string name = null)
 {
     if (data != null)
     {
         name = !string.IsNullOrEmpty(name) ? name : data.name;
         if (!string.IsNullOrEmpty(name))
         {
             var textureAtlasList = _textureAtlasDataMap.ContainsKey(name) ? _textureAtlasDataMap[name] : (_textureAtlasDataMap[name] = new List <TextureAtlasData>());
             if (!textureAtlasList.Contains(data))
             {
                 textureAtlasList.Add(data);
             }
         }
         else
         {
             DragonBones.Assert(false, "Unnamed data.");
         }
     }
     else
     {
         DragonBones.Assert(false, DragonBones.ARGUMENT_ERROR);
     }
 }
示例#17
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.000001f;
                }
                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.duration == 0.0f)
                {
                    animationConfig.playTimes = 1;
                }
                else if (animationConfig.playTimes < 0)
                {
                    animationConfig.playTimes = (int)animationData.playTimes;
                }
            }
            else
            {
                animationConfig.playTimes = 1;
                animationConfig.position  = 0.0f;
                animationConfig.duration  = 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);
            }

            return(_lastAnimationState);
        }
示例#18
0
        /**
         * @language zh_CN
         * 更新骨架和动画。
         * @param passedTime 两帧之间的时间间隔。 (以秒为单位)
         * @see DragonBones.IAnimateble
         * @see DragonBones.WorldClock
         * @version DragonBones 3.0
         */
        public void AdvanceTime(float passedTime)
        {
            if (_armatureData == null)
            {
                DragonBones.Assert(false, "The armature has been disposed.");
                return;
            }
            else if (_armatureData.parent == null)
            {
                DragonBones.Assert(false, "The armature data has been disposed.");
                return;
            }

            // Bones and slots.
            if (_bonesDirty)
            {
                _bonesDirty = false;
                _sortBones();
            }

            if (_slotsDirty)
            {
                _slotsDirty = false;
                _sortSlots();
            }

            var prevCacheFrameIndex = _animation._cacheFrameIndex;

            // Update animations.
            _animation._advanceTime(passedTime);

            var currentCacheFrameIndex = _animation._cacheFrameIndex;

            int i = 0, l = 0;

            if (currentCacheFrameIndex < 0 || currentCacheFrameIndex != prevCacheFrameIndex)
            {
                // Update bones.
                for (i = 0, l = _bones.Count; i < l; ++i)
                {
                    var bone = _bones[i];
                    bone._update(currentCacheFrameIndex);
                }

                // Update slots.
                for (i = 0, l = _slots.Count; i < l; ++i)
                {
                    _slots[i]._update(currentCacheFrameIndex);
                }
            }

            //
            if (!_lockDispose)
            {
                _lockDispose = true;

                // Events. (Dispatch event before action.)
                l = _events.Count;
                if (l > 0)
                {
                    for (i = 0; i < l; ++i)
                    {
                        var eventObject = _events[i];
                        _proxy.DispatchEvent(eventObject.type, eventObject);

                        if (eventObject.type == EventObject.SOUND_EVENT)
                        {
                            _eventManager.DispatchEvent(eventObject.type, eventObject);
                        }

                        eventObject.ReturnToPool();
                    }

                    _events.Clear();
                }

                // Actions.
                l = _actions.Count;
                if (l > 0)
                {
                    for (i = 0; i < l; ++i)
                    {
                        var action = _actions[i];
                        if (action.slot != null)
                        {
                            var slot = GetSlot(action.slot.name);
                            if (slot != null)
                            {
                                var childArmature = slot.childArmature;
                                if (childArmature != null)
                                {
                                    childArmature._doAction(action);
                                }
                            }
                        }
                        else if (action.bone != null)
                        {
                            for (int iA = 0, lA = _slots.Count; iA < lA; ++iA)
                            {
                                var childArmature = _slots[iA].childArmature;
                                if (childArmature != null)
                                {
                                    childArmature._doAction(action);
                                }
                            }
                        }
                        else
                        {
                            _doAction(action);
                        }
                    }

                    _actions.Clear();
                }

                _lockDispose = false;
            }

            if (_delayDispose)
            {
                ReturnToPool();
            }
        }