Exemplo n.º 1
0
 private static void _CreateUnityDataMenuItem()
 {
     foreach (var dragonBonesSkePath in _GetDragonBonesSkePaths(true))
     {
         var dragonBonesSke    = AssetDatabase.LoadMainAssetAtPath(dragonBonesSkePath) as TextAsset;
         var textureAtlasJSONs = new List <string>();
         GetTextureAtlasConfigs(textureAtlasJSONs, AssetDatabase.GetAssetPath(dragonBonesSke.GetInstanceID()));
         UnityDragonBonesData.TextureAtlas[] textureAtlas = new UnityDragonBonesData.TextureAtlas[textureAtlasJSONs.Count];
         for (int i = 0; i < textureAtlasJSONs.Count; ++i)
         {
             string path = textureAtlasJSONs[i];
             //load textureAtlas data
             UnityDragonBonesData.TextureAtlas ta = new UnityDragonBonesData.TextureAtlas();
             ta.textureAtlasJSON = AssetDatabase.LoadAssetAtPath <TextAsset>(path);
             //load texture
             path       = path.Substring(0, path.LastIndexOf(".json"));
             ta.texture = AssetDatabase.LoadAssetAtPath <Texture2D>(path + ".png");
             //load material
             ta.material     = AssetDatabase.LoadAssetAtPath <Material>(path + "_Mat.mat");
             ta.uiMaterial   = AssetDatabase.LoadAssetAtPath <Material>(path + "_UI_Mat.mat");
             textureAtlas[i] = ta;
         }
         CreateUnityDragonBonesData(dragonBonesSke, textureAtlas);
     }
 }
Exemplo n.º 2
0
        public static UnityDragonBonesData.TextureAtlas[] GetTextureAtlasByJSONs(List <string> textureAtlasJSONs)
        {
            UnityDragonBonesData.TextureAtlas[] textureAtlas = new UnityDragonBonesData.TextureAtlas[textureAtlasJSONs.Count];

            for (int i = 0; i < textureAtlasJSONs.Count; ++i)
            {
                string path = textureAtlasJSONs[i];
                //load textureAtlas data
                UnityDragonBonesData.TextureAtlas ta = new UnityDragonBonesData.TextureAtlas();
                ta.textureAtlasJSON = AssetDatabase.LoadAssetAtPath <TextAsset>(path);
                //load texture
                path       = path.Substring(0, path.LastIndexOf(".json"));
                ta.texture = AssetDatabase.LoadAssetAtPath <Texture2D>(path + ".png");
                //load material
                ta.material     = AssetDatabase.LoadAssetAtPath <Material>(path + "_Mat.mat");
                ta.uiMaterial   = AssetDatabase.LoadAssetAtPath <Material>(path + "_UI_Mat.mat");
                textureAtlas[i] = ta;
            }

            return(textureAtlas);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Parse the TextureAtlas 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>
        /// 将TextureAtlas解析为UnityTextureAtlasData,并缓存到工厂中。
        /// </summary>
        /// <param name="textureAtlas"></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(UnityDragonBonesData.TextureAtlas textureAtlas, string name, float scale = 1.0f, bool isUGUI = false)
        {
            Dictionary <string, object> textureJSONData  = (Dictionary <string, object>)MiniJSON.Json.Deserialize(textureAtlas.textureAtlasJSON.text);
            UnityTextureAtlasData       textureAtlasData = ParseTextureAtlasData(textureJSONData, null, name, scale) as UnityTextureAtlasData;

            if (textureJSONData.ContainsKey("width"))
            {
                textureAtlasData.width = uint.Parse(textureJSONData["width"].ToString());
            }

            if (textureJSONData.ContainsKey("height"))
            {
                textureAtlasData.height = uint.Parse(textureJSONData["height"].ToString());
            }

            if (textureAtlasData != null)
            {
                textureAtlasData.uiTexture = textureAtlas.uiMaterial;
                textureAtlasData.texture   = textureAtlas.material;
#if UNITY_EDITOR
                if (!Application.isPlaying)
                {
                    textureAtlasData.imagePath = AssetDatabase.GetAssetPath(textureAtlas.texture);
                    textureAtlasData.imagePath = textureAtlasData.imagePath.Substring(0, textureAtlasData.imagePath.Length - 4);
                    _RefreshTextureAtlas(textureAtlasData, isUGUI, true);
                    if (isUGUI)
                    {
                        textureAtlas.uiMaterial = textureAtlasData.uiTexture;
                    }
                    else
                    {
                        textureAtlas.material = textureAtlasData.texture;
                    }
                }
#endif
            }

            return(textureAtlasData);
        }
Exemplo n.º 4
0
    static int LoadTextureAtlasData(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 2)
            {
                DragonBones.UnityFactory obj = (DragonBones.UnityFactory)ToLua.CheckObject <DragonBones.UnityFactory>(L, 1);
                string arg0 = ToLua.CheckString(L, 2);
                DragonBones.UnityTextureAtlasData o = obj.LoadTextureAtlasData(arg0);
                ToLua.PushObject(L, o);
                return(1);
            }
            else if (count == 3 && TypeChecker.CheckTypes <string, string>(L, 2))
            {
                DragonBones.UnityFactory obj = (DragonBones.UnityFactory)ToLua.CheckObject <DragonBones.UnityFactory>(L, 1);
                string arg0 = ToLua.ToString(L, 2);
                string arg1 = ToLua.ToString(L, 3);
                DragonBones.UnityTextureAtlasData o = obj.LoadTextureAtlasData(arg0, arg1);
                ToLua.PushObject(L, o);
                return(1);
            }
            else if (count == 3 && TypeChecker.CheckTypes <DragonBones.UnityDragonBonesData.TextureAtlas, string>(L, 2))
            {
                DragonBones.UnityFactory obj = (DragonBones.UnityFactory)ToLua.CheckObject <DragonBones.UnityFactory>(L, 1);
                DragonBones.UnityDragonBonesData.TextureAtlas arg0 = (DragonBones.UnityDragonBonesData.TextureAtlas)ToLua.ToObject(L, 2);
                string arg1 = ToLua.ToString(L, 3);
                DragonBones.UnityTextureAtlasData o = obj.LoadTextureAtlasData(arg0, arg1);
                ToLua.PushObject(L, o);
                return(1);
            }
            else if (count == 4 && TypeChecker.CheckTypes <string, string, float>(L, 2))
            {
                DragonBones.UnityFactory obj = (DragonBones.UnityFactory)ToLua.CheckObject <DragonBones.UnityFactory>(L, 1);
                string arg0 = ToLua.ToString(L, 2);
                string arg1 = ToLua.ToString(L, 3);
                float  arg2 = (float)LuaDLL.lua_tonumber(L, 4);
                DragonBones.UnityTextureAtlasData o = obj.LoadTextureAtlasData(arg0, arg1, arg2);
                ToLua.PushObject(L, o);
                return(1);
            }
            else if (count == 4 && TypeChecker.CheckTypes <DragonBones.UnityDragonBonesData.TextureAtlas, string, float>(L, 2))
            {
                DragonBones.UnityFactory obj = (DragonBones.UnityFactory)ToLua.CheckObject <DragonBones.UnityFactory>(L, 1);
                DragonBones.UnityDragonBonesData.TextureAtlas arg0 = (DragonBones.UnityDragonBonesData.TextureAtlas)ToLua.ToObject(L, 2);
                string arg1 = ToLua.ToString(L, 3);
                float  arg2 = (float)LuaDLL.lua_tonumber(L, 4);
                DragonBones.UnityTextureAtlasData o = obj.LoadTextureAtlasData(arg0, arg1, arg2);
                ToLua.PushObject(L, o);
                return(1);
            }
            else if (count == 5 && TypeChecker.CheckTypes <string, string, float, bool>(L, 2))
            {
                DragonBones.UnityFactory obj = (DragonBones.UnityFactory)ToLua.CheckObject <DragonBones.UnityFactory>(L, 1);
                string arg0 = ToLua.ToString(L, 2);
                string arg1 = ToLua.ToString(L, 3);
                float  arg2 = (float)LuaDLL.lua_tonumber(L, 4);
                bool   arg3 = LuaDLL.lua_toboolean(L, 5);
                DragonBones.UnityTextureAtlasData o = obj.LoadTextureAtlasData(arg0, arg1, arg2, arg3);
                ToLua.PushObject(L, o);
                return(1);
            }
            else if (count == 5 && TypeChecker.CheckTypes <DragonBones.UnityDragonBonesData.TextureAtlas, string, float, bool>(L, 2))
            {
                DragonBones.UnityFactory obj = (DragonBones.UnityFactory)ToLua.CheckObject <DragonBones.UnityFactory>(L, 1);
                DragonBones.UnityDragonBonesData.TextureAtlas arg0 = (DragonBones.UnityDragonBonesData.TextureAtlas)ToLua.ToObject(L, 2);
                string arg1 = ToLua.ToString(L, 3);
                float  arg2 = (float)LuaDLL.lua_tonumber(L, 4);
                bool   arg3 = LuaDLL.lua_toboolean(L, 5);
                DragonBones.UnityTextureAtlasData o = obj.LoadTextureAtlasData(arg0, arg1, arg2, arg3);
                ToLua.PushObject(L, o);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: DragonBones.UnityFactory.LoadTextureAtlasData"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Exemplo n.º 5
0
        public static bool ChangeDragonBonesData(UnityArmatureComponent _armatureComponent, TextAsset dragonBoneJSON)
        {
            if (dragonBoneJSON != null)
            {
                var textureAtlasJSONs = new List <string>();
                UnityEditor.GetTextureAtlasConfigs(textureAtlasJSONs, AssetDatabase.GetAssetPath(dragonBoneJSON.GetInstanceID()));
                UnityDragonBonesData.TextureAtlas[] textureAtlas = new UnityDragonBonesData.TextureAtlas[textureAtlasJSONs.Count];
                for (int i = 0; i < textureAtlasJSONs.Count; ++i)
                {
                    string path = textureAtlasJSONs[i];
                    //load textureAtlas data
                    UnityDragonBonesData.TextureAtlas ta = new UnityDragonBonesData.TextureAtlas();
                    ta.textureAtlasJSON = AssetDatabase.LoadAssetAtPath <TextAsset>(path);
                    //load texture
                    path       = path.Substring(0, path.LastIndexOf(".json"));
                    ta.texture = AssetDatabase.LoadAssetAtPath <Texture2D>(path + ".png");
                    //load material
                    ta.material     = AssetDatabase.LoadAssetAtPath <Material>(path + "_Mat.mat");
                    ta.uiMaterial   = AssetDatabase.LoadAssetAtPath <Material>(path + "_UI_Mat.mat");
                    textureAtlas[i] = ta;
                }
                UnityDragonBonesData data = UnityEditor.CreateUnityDragonBonesData(dragonBoneJSON, textureAtlas);
                _armatureComponent.unityData = data;

                var dragonBonesData = UnityFactory.factory.LoadData(data, _armatureComponent.isUGUI);
                if (dragonBonesData != null)
                {
                    Undo.RecordObject(_armatureComponent, "Set DragonBones");

                    _armatureComponent.unityData = data;

                    var armatureName = dragonBonesData.armatureNames[0];
                    ChangeArmatureData(_armatureComponent, armatureName, dragonBonesData.name);

                    _armatureComponent.gameObject.name = armatureName;

                    EditorUtility.SetDirty(_armatureComponent);

                    return(true);
                }
                else
                {
                    EditorUtility.DisplayDialog("Error", "Could not load dragonBones data.", "OK", null);

                    return(false);
                }
            }
            else if (_armatureComponent.unityData != null)
            {
                Undo.RecordObject(_armatureComponent, "Set DragonBones");

                _armatureComponent.unityData = null;

                if (_armatureComponent.armature != null)
                {
                    _armatureComponent.Dispose(false);
                }

                EditorUtility.SetDirty(_armatureComponent);

                return(true);
            }

            return(false);
        }