Пример #1
0
        private void _getTextureAtlasConfigs(List <string> textureAtlasFiles, string filePath, string rawName = null, string suffix = "texture")
        {
            var folder                 = Directory.GetParent(filePath).ToString();
            var name                   = rawName != null ? rawName : filePath.Substring(0, filePath.LastIndexOf(".")).Substring(filePath.LastIndexOf("/") + 1);
            int index                  = 0;
            var textureAtlasName       = "";
            var textureAtlasConfigFile = "";

            textureAtlasName       = DragonBones.IsAvailableString(name) ? name + (DragonBones.IsAvailableString(suffix) ? "_" + suffix : suffix) : suffix;
            textureAtlasConfigFile = folder + "/" + textureAtlasName + ".json";

            if (File.Exists(textureAtlasConfigFile))
            {
                textureAtlasFiles.Add(textureAtlasConfigFile);
                return;
            }

            if (textureAtlasFiles.Count > 0 || rawName != null)
            {
                return;
            }

            while (true)
            {
                textureAtlasName       = (DragonBones.IsAvailableString(name) ? name + (DragonBones.IsAvailableString(suffix) ? "_" + suffix : suffix) : suffix) + "_" + (index++);
                textureAtlasConfigFile = folder + "/" + textureAtlasName + ".json";
                if (File.Exists(textureAtlasConfigFile))
                {
                    textureAtlasFiles.Add(textureAtlasConfigFile);
                }
                else if (index > 1)
                {
                    break;
                }
            }

            _getTextureAtlasConfigs(textureAtlasFiles, filePath, "", suffix);
            if (textureAtlasFiles.Count > 0)
            {
                return;
            }

            index = name.LastIndexOf("_");
            if (index >= 0)
            {
                name = name.Substring(0, index);

                _getTextureAtlasConfigs(textureAtlasFiles, filePath, name, suffix);
                if (textureAtlasFiles.Count > 0)
                {
                    return;
                }

                _getTextureAtlasConfigs(textureAtlasFiles, filePath, name, "");
                if (textureAtlasFiles.Count > 0)
                {
                    return;
                }
            }
        }
Пример #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);
            }
        }
        /**
         * @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.displayIndex.ToString()))
                {
                    slot[value.displayIndex.ToString()] = value;
                }
                else
                {
                    DragonBones.Warn("");
                }
            }
            else
            {
                DragonBones.Warn("");
            }
        }
Пример #4
0
        void Awake()
        {
            _armatureComponent = this.target as UnityArmatureComponent;
            _dragonBoneJSON    = _armatureComponent.draggonBonesJSON;

            if (
                !EditorApplication.isPlayingOrWillChangePlaymode &&
                _armatureComponent.draggonBonesJSON != null &&
                _armatureComponent.armature == null
                )
            {
                _armatureComponent.ClearChildren();

                if (DragonBones.IsAvailableString(_armatureComponent.armatureName))
                {
                    var dragonBonesData = _armatureComponent.LoadData();
                    _changeArmature(_armatureComponent.armatureName, dragonBonesData.name);

                    if (DragonBones.IsAvailableString(_armatureComponent.animationName))
                    {
                        _armatureComponent.animation.Play(_armatureComponent.animationName);
                        _armatureComponent.animation.Stop();
                    }
                }
            }

            _update();
        }
Пример #5
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 = DragonBones.IsAvailableString(name) ? name : data.name;
         if (DragonBones.IsAvailableString(name))
         {
             if (!_dragonBonesDataMap.ContainsKey(name))
             {
                 _dragonBonesDataMap[name] = data;
             }
             else
             {
                 DragonBones.Warn("Same name data. " + name);
             }
         }
         else
         {
             DragonBones.Warn("Unnamed data.");
         }
     }
     else
     {
         DragonBones.Warn("");
     }
 }
        /**
         * @language zh_CN
         * 播放动画。
         * @param animationName 动画数据的名称,如果未设置,则播放默认动画,或将暂停状态切换为播放状态,或重新播放上一个正在播放的动画。
         * @param playTimes 动画需要播放的次数。 [-1: 使用动画数据默认值, 0: 无限循环播放, [1~N]: 循环播放 N 次]
         * @returns 返回控制这个动画数据的动画状态。
         * @see dragonBones.AnimationState
         * @version DragonBones 3.0
         */
        public AnimationState Play(string animationName = null, int playTimes = -1)
        {
            var animationState = (AnimationState)null;

            if (DragonBones.IsAvailableString(animationName))
            {
                animationState = FadeIn(animationName, 0.0f, playTimes, 0, null, AnimationFadeOutMode.All);
            }
            else if (_lastAnimationState == null)
            {
                var defaultAnimation = _armature.armatureData.defaultAnimation;
                if (defaultAnimation != null)
                {
                    animationState = FadeIn(defaultAnimation.name, 0.0f, playTimes, 0, null, AnimationFadeOutMode.All);
                }
            }
            else if (!_isPlaying || (!_lastAnimationState.isPlaying && !_lastAnimationState.isCompleted))
            {
                _isPlaying = true;
                _lastAnimationState.Play();
            }
            else
            {
                animationState = FadeIn(_lastAnimationState.name, 0.0f, playTimes, 0, null, AnimationFadeOutMode.All);
            }

            return(animationState);
        }
        public void CopyFrom(AnimationConfig value)
        {
            pauseFadeOut    = value.pauseFadeOut;
            fadeOutMode     = value.fadeOutMode;
            autoFadeOutTime = value.autoFadeOutTime;
            fadeOutEasing   = value.fadeOutEasing;

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

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

                    _maxCountMap[pair.Key] = maxCount;

                    var pool = _poolsMap[pair.Key];
                    if (pool.Count > maxCount)
                    {
                        DragonBones.ResizeList(pool, (int)maxCount, null);
                    }
                }
            }
        }
Пример #10
0
        /**
         * @private
         */
        public void CacheFrames(float frameRate)
        {
            if (cacheFrameRate > 0.0f)
            {
                return;
            }

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

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

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

                boneCachedFrameIndices[k] = indices;
            }

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

                slotCachedFrameIndices[k] = indices;
            }
        }
Пример #11
0
        /**
         * @private
         */
        protected override void _OnClear()
        {
            if (this._clock != null)
            {
                // Remove clock first.
                this._clock.Remove(this);
            }

            foreach (var bone in this._bones)
            {
                bone.ReturnToPool();
            }

            foreach (var slot in this._slots)
            {
                slot.ReturnToPool();
            }

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

            if (this._proxy != null)
            {
                this._proxy.DBClear();
            }

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

            this.inheritAnimation = true;
            this.armatureData     = null; //
            this.userData         = null;

            this._lockUpdate      = false;
            this._bonesDirty      = false;
            this._slotsDirty      = false;
            this._zOrderDirty     = false;
            this._flipX           = false;
            this._flipY           = false;
            this._cacheFrameIndex = -1;
            this._bones.Clear();
            this._slots.Clear();
            this._actions.Clear();
            this._animation = null; //
            this._proxy     = null; //
            this._display   = null;
            this._replaceTextureAtlasData = null;
            this._replacedTexture         = null;
            this._dragonBones             = null; //
            this._clock  = null;
            this._parent = null;
        }
Пример #12
0
 private void InitDragonBonesInstance(IEventDispatcher <EventObject> eventManager)
 {
     if (_dragonBonesInstance != null)
     {
         return;
     }
     _dragonBonesInstance      = new DragonBonesInstance(eventManager);
     DragonBonesInstance.yDown = false; // ???
     _dragonBones = _dragonBonesInstance;
 }
 /**
  * @private
  */
 public void AddSlotTimeline(SlotTimelineData value)
 {
     if (value != null && value.slot != null && !slotTimelines.ContainsKey(value.slot.name))
     {
         slotTimelines[value.slot.name] = value;
     }
     else
     {
         DragonBones.Warn("");
     }
 }
Пример #14
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);
     }
 }
 /**
  * @private
  */
 public void AddBoneTimeline(BoneTimelineData value)
 {
     if (value != null && value.bone != null && !boneTimelines.ContainsKey(value.bone.name))
     {
         boneTimelines[value.bone.name] = value;
     }
     else
     {
         DragonBones.Warn("");
     }
 }
 /**
  * @private
  */
 public void AddSlot(SlotDisplayDataSet value)
 {
     if (value != null && value.slot != null && !slots.ContainsKey(value.slot.name))
     {
         slots[value.slot.name] = value;
     }
     else
     {
         DragonBones.Warn("");
     }
 }
Пример #17
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);
     }
 }
Пример #18
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);
     }
 }
Пример #20
0
 /**
  * @language zh_CN
  * 将一个指定的骨骼从骨架中移除。
  * @param value 需要移除的骨骼。
  * @see dragonBones.Bone
  * @version DragonBones 3.0
  */
 public void RemoveBone(Bone value)
 {
     if (value != null && value.armature == this)
     {
         value._setParent(null);
         value._setArmature(null);
     }
     else
     {
         DragonBones.Warn("");
     }
 }
 /**
  * @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.Warn("");
     }
 }
Пример #22
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);
     }
 }
Пример #23
0
 /**
  * @language zh_CN
  * 将一个指定的骨骼添加到骨架中。
  * @param value 需要添加的骨骼。
  * @param parentName 需要添加到父骨骼的名称,如果未设置,则添加到骨架根部。
  * @see dragonBones.Bone
  * @version DragonBones 3.0
  */
 public void AddBone(Bone value, string parentName = null)
 {
     if (value != null)
     {
         value._setArmature(this);
         value._setParent(!string.IsNullOrEmpty(parentName) ? GetBone(parentName) : null);
     }
     else
     {
         DragonBones.Warn("");
     }
 }
 /**
  * @language zh_CN
  * 将一个指定的骨骼添加到骨架中。
  * @param value 需要添加的骨骼。
  * @param parentName 需要添加到父骨骼的名称,如果未设置,则添加到骨架根部。
  * @see dragonBones.Bone
  * @version DragonBones 3.0
  */
 public void AddBone(Bone value, string parentName = null)
 {
     if (value != null)
     {
         value._setArmature(this);
         value._setParent(DragonBones.IsAvailableString(parentName) ? GetBone(parentName) : null);
     }
     else
     {
         DragonBones.Warn("");
     }
 }
Пример #25
0
        /**
         * @private
         */
        protected bool _fillBuildArmaturePackage(string dragonBonesName, string armatureName, string skinName, BuildArmaturePackage dataPackage)
        {
            var isAvailableName = DragonBones.IsAvailableString(dragonBonesName);

            if (isAvailableName)
            {
                if (_dragonBonesDataMap.ContainsKey(dragonBonesName))
                {
                    var dragonBonesData = _dragonBonesDataMap[dragonBonesName];
                    var armatureData    = dragonBonesData.GetArmature(armatureName);
                    if (armatureData != null)
                    {
                        dataPackage.dataName = dragonBonesName;
                        dataPackage.data     = dragonBonesData;
                        dataPackage.armature = armatureData;
                        dataPackage.skin     = armatureData.GetSkin(skinName);
                        if (dataPackage.skin == null)
                        {
                            dataPackage.skin = armatureData.defaultSkin;
                        }

                        return(true);
                    }
                }
            }

            if (!isAvailableName || this.autoSearch) // Will be search all data, if do not give a data name or the autoSearch is true.
            {
                foreach (var pair in _dragonBonesDataMap)
                {
                    if (!isAvailableName || pair.Value.autoSearch)
                    {
                        var armatureData = pair.Value.GetArmature(armatureName);
                        if (armatureData != null)
                        {
                            dataPackage.dataName = pair.Key;
                            dataPackage.data     = pair.Value;
                            dataPackage.armature = armatureData;
                            dataPackage.skin     = armatureData.GetSkin(skinName);
                            if (dataPackage.skin == null)
                            {
                                dataPackage.skin = armatureData.defaultSkin;
                            }

                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
 /**
  * @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);
     }
 }
 /**
  * @private
  */
 public void AddSlot(SlotData value)
 {
     if (value != null && value.name != null && !slots.ContainsKey(value.name))
     {
         slots[value.name] = value;
         _sortedSlots.Add(value);
         _slotDirty = true;
     }
     else
     {
         DragonBones.Warn("");
     }
 }
Пример #28
0
 /**
  * @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.Warn("");
     }
 }
Пример #29
0
        /**
         * @private
         */
        protected void _replaceSlotDisplay(BuildArmaturePackage dataPackage, DisplayData displayData, Slot slot, int displayIndex)
        {
            if (displayIndex < 0)
            {
                displayIndex = slot.displayIndex;
            }

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

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

                slot._replacedDisplayDatas[displayIndex] = displayData;

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

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

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

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

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

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

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

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

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

            return(tweenType);
        }