/**
         * @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);
        }
示例#2
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("");
     }
 }
示例#3
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;
                }
            }
        }
示例#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();
        }
 /**
  * @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("");
     }
 }
示例#6
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);
        }
 /**
  * @language zh_CN
  * 暂停播放动画。
  * @param animationName 动画状态的名称,如果未设置,则暂停所有动画状态。
  * @see dragonBones.AnimationState
  * @version DragonBones 3.0
  */
 public void Stop(string animationName = null)
 {
     if (DragonBones.IsAvailableString(animationName))
     {
         var animationState = GetState(animationName);
         if (animationState != null)
         {
             animationState.Stop();
         }
     }
     else
     {
         _isPlaying = false;
     }
 }
示例#8
0
        /**
         * @private
         */
        internal bool _isDisabled(Slot slot)
        {
            if (
                displayControl &&
                (
                    !DragonBones.IsAvailableString(slot.displayController) ||
                    slot.displayController == _name ||
                    slot.displayController == _group
                )
                )
            {
                return(false);
            }

            return(true);
        }
        /**
         * @private
         */
        void Awake()
        {
            LoadData(dragonBonesJSON, textureAtlasJSON);

            if (DragonBones.IsAvailableString(armatureName))
            {
                UnityFactory.factory.BuildArmatureComponent(armatureName, null, null, this.gameObject);
                sortingLayerName = sortingLayerName;
                sortingOrder     = sortingOrder;
            }

            if (_armature != null && DragonBones.IsAvailableString(animationName))
            {
                _armature.animation.Play(animationName);
            }
        }
示例#10
0
        void OnEnable()
        {
            _armatureComponent = this.target as UnityArmatureComponent;
            _dragonBoneJSON    = _armatureComponent == null ? null : _armatureComponent.dragonBonesJSON;

            //
            _nowTime           = System.DateTime.Now.Ticks;
            _sortingLayerNames = _getSortingLayerNames();
            _sortingLayerIndex = _getSortingLayerIndex(_armatureComponent.sortingLayerName);

            // Create armature.
            if (
                !EditorApplication.isPlayingOrWillChangePlaymode &&
                _armatureComponent.armature == null &&
                _armatureComponent.dragonBonesJSON != null &&
                DragonBones.IsAvailableString(_armatureComponent.armatureName)
                )
            {
                var dragonBonesData = _armatureComponent.LoadData(_armatureComponent.dragonBonesJSON, _armatureComponent.textureAtlasJSON);
                UnityFactory.factory.RefreshAllTextureAtlas();

                _changeArmature(_armatureComponent.armatureName, dragonBonesData.name);
                _armatureComponent.armature.InvalidUpdate(null, true);
                if (DragonBones.IsAvailableString(_armatureComponent.animationName))
                {
                    _armatureComponent.animation.Play(_armatureComponent.animationName);
                }
            }

            // Update hideFlags.
            if (!EditorApplication.isPlayingOrWillChangePlaymode &&
                _armatureComponent.armature != null &&
                _armatureComponent.armature.parent != null
                )
            {
                _armatureComponent.gameObject.hideFlags = HideFlags.NotEditable;
            }
            else
            {
                _armatureComponent.gameObject.hideFlags = HideFlags.None;
            }

            //
            _update();
        }
        public DragonBonesData LoadDragonBonesData(TextAsset dragonBonesJSON, string name = null)
        {
            if (dragonBonesJSON == null)
            {
                return(null);
            }

            if (DragonBones.IsAvailableString(name))
            {
                var existedData = this.GetDragonBonesData(name);
                if (existedData != null)
                {
                    return(existedData);
                }
            }

            return(this.ParseDragonBonesData((Dictionary <string, object>)MiniJSON.Json.Deserialize(dragonBonesJSON.text), name, 0.01f)); // Unity default Scale Factor.
        }
示例#12
0
        /**
         * @private
         */
        void Awake()
        {
            if (EditorApplication.isPlayingOrWillChangePlaymode)
            {
                ClearChildren();
            }

            LoadData();

            if (DragonBones.IsAvailableString(armatureName))
            {
                UnityFactory.factory.BuildArmatureComponent(armatureName, null, null, this.gameObject);
            }

            if (_armature != null && DragonBones.IsAvailableString(animationName))
            {
                _armature.animation.Play(animationName);
            }
        }
示例#13
0
        void Awake()
        {
            _nowTime           = System.DateTime.Now.Ticks;
            _armatureComponent = this.target as UnityArmatureComponent;
            _dragonBoneJSON    = _armatureComponent.draggonBonesJSON;

            if (
                !EditorApplication.isPlayingOrWillChangePlaymode &&
                _armatureComponent.draggonBonesJSON != null &&
                _armatureComponent.armature == null
                )
            {
                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();
            _sortingLayerNames = _getSortingLayerNames();
            _selectedOption    = _getSortingLayerIndex(_armatureComponent.sortingLayerName);

            //
            if (!EditorApplication.isPlayingOrWillChangePlaymode &&
                _armatureComponent.armature != null &&
                _armatureComponent.armature.parent != null
                )
            {
                _armatureComponent.gameObject.hideFlags = HideFlags.NotEditable;
            }
            else
            {
                _armatureComponent.gameObject.hideFlags = HideFlags.None;
            }
        }
        /**
         * @private
         */
        void Awake()
        {
            if (Application.isPlaying)
            {
                ClearChildren();
            }

            LoadData();

            if (DragonBones.IsAvailableString(armatureName))
            {
                UnityFactory.factory.BuildArmatureComponent(armatureName, null, null, this.gameObject);
                sortingLayerName = sortingLayerName;
                sortingOrder     = sortingOrder;
            }

            if (_armature != null && DragonBones.IsAvailableString(animationName))
            {
                _armature.animation.Play(animationName);
            }
        }
示例#15
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 = DragonBones.IsAvailableString(name) ? name : data.name;
         if (DragonBones.IsAvailableString(name))
         {
             var textureAtlasList = _textureAtlasDataMap.ContainsKey(name) ? _textureAtlasDataMap[name] : (_textureAtlasDataMap[name] = new List <TextureAtlasData>());
             if (!textureAtlasList.Contains(data))
             {
                 textureAtlasList.Add(data);
             }
         }
         else
         {
             DragonBones.Warn("Unnamed data.");
         }
     }
     else
     {
         DragonBones.Warn("");
     }
 }
        /**
         * @language zh_CN
         * 更新骨骼和插槽的变换。 (当骨骼没有动画状态或动画状态播放完成时,骨骼将不在更新)
         * @param boneName 指定的骨骼名称,如果未设置,将更新所有骨骼。
         * @param updateSlotDisplay 是否更新插槽的显示对象。
         * @see dragonBones.Bone
         * @see dragonBones.Slot
         * @version DragonBones 3.0
         */
        public void InvalidUpdate(string boneName = null, bool updateSlotDisplay = false)
        {
            if (DragonBones.IsAvailableString(boneName))
            {
                var bone = GetBone(boneName);
                if (bone != null)
                {
                    bone.InvalidUpdate();

                    if (updateSlotDisplay)
                    {
                        foreach (var slot in _slots)
                        {
                            if (slot.parent == bone)
                            {
                                slot.InvalidUpdate();
                            }
                        }
                    }
                }
            }
            else
            {
                foreach (var bone in _bones)
                {
                    bone.InvalidUpdate();
                }

                if (updateSlotDisplay)
                {
                    foreach (var slot in _slots)
                    {
                        slot.InvalidUpdate();
                    }
                }
            }
        }
 /**
  * @language zh_CN
  * 获取指定名称的动画数据。
  * @param name 动画数据名称。
  * @see dragonBones.AnimationData
  * @version DragonBones 3.0
  */
 public AnimationData GetAnimation(string name)
 {
     return(DragonBones.IsAvailableString(name) ? (animations.ContainsKey(name) ? animations[name] : null) : _defaultAnimation);
 }
 /**
  * @language zh_CN
  * 获取指定名称的皮肤数据。
  * @param name 皮肤数据名称。
  * @see dragonBones.SkinData
  * @version DragonBones 3.0
  */
 public SkinData GetSkin(string name)
 {
     return(DragonBones.IsAvailableString(name) ? (skins.ContainsKey(name) ? skins[name] : null) : _defaultSkin);
 }