Example #1
0
        /// <summary>
        /// Parse the raw data to a DragonBonesData instance and cache it to the factory.
        /// </summary>
        /// <param name="dragonBonesJSONPath">The path of dragonBones data in Resources. (other forms of loading can be extended by themselves)</param>
        /// <param name="name">Specify a cache name for the instance so that the instance can be obtained through this name. (If not set, use the instance name instead)</param>
        /// <param name="scale">Specify a scaling value for all armatures. (Default does not scale)</param>
        /// <returns>DragonBonesData instance</returns>
        /// <version>DragonBones 4.5</version>
        /// <language>en_US</language>

        /// <summary>
        /// 将原始数据解析为 DragonBonesData 实例,并缓存到工厂中。
        /// </summary>
        /// <param name="dragonBonesJSONPath">龙骨数据在 Resources 中的路径。(其他形式的加载可自行扩展)</param>
        /// <param name="name">为该实例指定一个缓存名称,以便可以通过此名称获取该实例。 (如果未设置,则使用该实例中的名称)</param>
        /// <param name="scale">为所有的骨架指定一个缩放值。 (默认不缩放)</param>
        /// <returns>龙骨数据</returns>
        /// <version>DragonBones 4.5</version>
        /// <language>zh_CN</language>
        public DragonBonesData LoadDragonBonesData(string dragonBonesJSONPath, string name = "", float scale = 0.01f)
        {
            dragonBonesJSONPath = UnityFactoryHelper.CheckResourecdPath(dragonBonesJSONPath);

            TextAsset dragonBonesJSON = Resources.Load <TextAsset>(dragonBonesJSONPath);

            DragonBonesData dragonBonesData = LoadDragonBonesData(dragonBonesJSON, name);

            return(dragonBonesData);
        }
        /**
         * @language zh_CN
         * 加载、解析并添加贴图集数据。
         * @param path 贴图集数据在 Resources 中的路径。(其他形式的加载可自行扩展,使用 factory.ParseTextureAtlasData(JSONObject, Material))
         * @param name 为数据指定一个名称,以便可以通过这个名称获取数据,如果未设置,则使用数据中的名称。
         * @param scale 为贴图集设置一个缩放值。
         * @returns 贴图集数据
         * @see #ParseTextureAtlasData()
         * @see #GetTextureAtlasData()
         * @see #AddTextureAtlasData()
         * @see #RemoveTextureAtlasData()
         * @see DragonBones.UnityTextureAtlasData
         */
        public UnityTextureAtlasData LoadTextureAtlasData(string textureAtlasJSONPath, string name = null, float scale = 1.0f, bool isUGUI = false)
        {
            textureAtlasJSONPath = UnityFactoryHelper.CheckResourecdPath(textureAtlasJSONPath);

            UnityTextureAtlasData textureAtlasData = null;

            if (_pathTextureAtlasDataMap.ContainsKey(textureAtlasJSONPath))
            {
                textureAtlasData = _pathTextureAtlasDataMap[textureAtlasJSONPath] as UnityTextureAtlasData;
                _RefreshTextureAtlas(textureAtlasData, isUGUI);
            }
            else
            {
                //if (string.IsNullOrEmpty(name))
                //{
                //    name = UnityFactoryHelper.GetTextureAtlasNameByPath(textureAtlasJSONPath);
                //}

                TextAsset textureAtlasJSON = Resources.Load <TextAsset>(textureAtlasJSONPath);
                if (textureAtlasJSON != null)
                {
                    Dictionary <string, object> textureJSONData = (Dictionary <string, object>)MiniJSON.Json.Deserialize(textureAtlasJSON.text);
                    textureAtlasData = ParseTextureAtlasData(textureJSONData, null, name, scale) as UnityTextureAtlasData;

                    if (textureAtlasData != null)
                    {
                        //if (!string.IsNullOrEmpty(name))
                        //{
                        //    textureAtlasData.name = name;
                        //}

                        textureAtlasData.imagePath = UnityFactoryHelper.GetTextureAtlasImagePath(textureAtlasJSONPath, textureAtlasData.imagePath);

                        _RefreshTextureAtlas(textureAtlasData, isUGUI);

                        _pathTextureAtlasDataMap[textureAtlasJSONPath] = textureAtlasData;
                    }
                }
            }

            return(textureAtlasData);
        }
        /**
         * @language zh_CN
         * 加载、解析并添加龙骨数据。
         * @param path 龙骨数据在 Resources 中的路径。(其他形式的加载可自行扩展)
         * @param name 为数据提供一个名称,以便可以通过这个名称获取数据,如果未设置,则使用数据中的名称。
         * @param scale 为所有骨架设置一个缩放值。
         * @returns 龙骨数据
         * @see #ParseDragonBonesData()
         * @see #GetDragonBonesData()
         * @see #AddDragonBonesData()
         * @see #RemoveDragonBonesData()
         * @see DragonBones.DragonBonesData
         */
        public DragonBonesData LoadDragonBonesData(string dragonBonesJSONPath, string name = null, float scale = 0.01f)
        {
            dragonBonesJSONPath = UnityFactoryHelper.CheckResourecdPath(dragonBonesJSONPath);

            if (_pathDragonBonesDataMap.ContainsKey(dragonBonesJSONPath))
            {
                return(_pathDragonBonesDataMap[dragonBonesJSONPath]);
            }

            TextAsset dragonBonesJSON = Resources.Load <TextAsset>(dragonBonesJSONPath);

            DragonBonesData dragonBonesData = LoadDragonBonesData(dragonBonesJSON, name);

            if (dragonBonesData != null)
            {
                _pathDragonBonesDataMap[dragonBonesJSONPath] = dragonBonesData;
            }

            return(dragonBonesData);
        }
Example #4
0
        /// <summary>
        /// Parse the textureAtlas json data to a UnityTextureAtlasData instance and cache it to the factory.
        /// </summary>
        /// <param name="textureAtlasJSONPath">The path of dragonBones data in Resources. (other forms of loading can be extended by themselves. use factory.ParseTextureAtlasData(JSONObject, Material))</param>
        /// <param name="name">Specify a cache name for the instance so that the instance can be obtained through this name. (If not set, use the instance name instead)</param>
        /// <param name="scale">Specify a scaling value for textureAtlas. (Default does not scale)</param>
        /// <param name="isUGUI"></param>
        /// <returns></returns>
        /// <version>DragonBones 4.5</version>
        /// <language>en_US</language>

        /// <summary>
        /// 将贴图集json数据解析为UnityTextureAtlasData,并缓存到工厂中。
        /// </summary>
        /// <param name="textureAtlasJSONPath">贴图集数据在 Resources 中的路径。(其他形式的加载可自行扩展,使用 factory.ParseTextureAtlasData(JSONObject, Material))</param>
        /// <param name="name">为数据指定一个名称,以便可以通过这个名称获取数据,如果未设置,则使用数据中的名称。</param>
        /// <param name="scale">为贴图集设置一个缩放值。</param>
        /// <param name="isUGUI"></param>
        /// <returns>贴图集数据</returns>
        /// <version>DragonBones 4.5</version>
        /// <language>zh_CN</language>
        public UnityTextureAtlasData LoadTextureAtlasData(string textureAtlasJSONPath, string name = "", float scale = 1.0f, bool isUGUI = false)
        {
            textureAtlasJSONPath = UnityFactoryHelper.CheckResourecdPath(textureAtlasJSONPath);

            TextAsset textureAtlasJSON = Resources.Load <TextAsset>(textureAtlasJSONPath);

            //
            if (textureAtlasJSON != null)
            {
                Dictionary <string, object> textureJSONData  = (Dictionary <string, object>)MiniJSON.Json.Deserialize(textureAtlasJSON.text);
                UnityTextureAtlasData       textureAtlasData = ParseTextureAtlasData(textureJSONData, null, name, scale) as UnityTextureAtlasData;

                if (textureAtlasData != null)
                {
                    textureAtlasData.imagePath = UnityFactoryHelper.GetTextureAtlasImagePath(textureAtlasJSONPath, textureAtlasData.imagePath);

                    _RefreshTextureAtlas(textureAtlasData, isUGUI);
                }

                return(textureAtlasData);
            }

            return(null);
        }