protected override JSONObject ExportResource(ExportPreset preset)
        {
            JSONObject meta     = JSONObject.Create("{\"file\": {}}");
            JSONObject metadata = new JSONObject();

            meta.AddField("data", metadata);

            byte[] content = WriteMeshFile(ref metadata);

            meta.GetField("file").AddField(
                "src",
                AddFile(new WXEngineMeshFile(unityAssetPath, meshName, content))
                );

            // 在importsetting里关联fbx文件
            if (Path.GetExtension(unityAssetPath).ToLower() == ".fbx")
            {
                importSetting = new JSONObject();
                WXRawResource fbx             = new WXRawResource(unityAssetPath);
                string        fbxExportedPath = fbx.Export(preset);
                importSetting.AddField("associateFbx", fbxExportedPath);
                AddDependencies(fbxExportedPath);
            }

            return(meta);
        }
        protected override JSONObject ToJSON(WXHierarchyContext context)
        {
            JSONObject json = new JSONObject(JSONObject.Type.OBJECT);
            JSONObject data = new JSONObject(JSONObject.Type.OBJECT);

            json.AddField("type", getTypeName());
            json.AddField("data", data);

            JSONObject res_paths_json = new JSONObject(JSONObject.Type.ARRAY);

            data.AddField("resources", res_paths_json);


            foreach (Object file in collection_.ResourceFiles)
            {
                if (file != null)
                {
                    string        file_path         = AssetDatabase.GetAssetPath(file.GetInstanceID());
                    WXRawResource resourceConverter = new WXRawResource(file_path);
                    string        ret_path          = resourceConverter.Export(context.preset);
                    if (ret_path != "")
                    {
                        res_paths_json.Add(ret_path);
                        context.AddResource(ret_path);
                    }
                }
            }

            return(json);
        }
Exemplo n.º 3
0
        protected override JSONObject ExportResource(ExportPreset preset)
        {
            if (avatar.isHuman)
            {
                isHuman = GetHumanDescription(avatar, ref desc);
                if (isHuman)
                {
                    foreach (var pair in desc.human)
                    {
                        humanMap.Add(pair.humanName, pair.boneName);
                    }
                }
            }
            JSONObject avatarJSON = new JSONObject(JSONObject.Type.OBJECT);

            /*
             * {
             *  avatar:{
             *      path,
             *      linkSprites
             *  }
             * }
             */
            int id = -2;
            // GetAvatarNodeData(gameObject, rootNode, gameObject, ref id);
            bool       succ = false;
            JSONObject avatarRootNodeJSON = GetAvatarRootNodeJSON(gameObject, gameObject, ref id, ref succ);

            if (avatarRootNodeJSON == null)
            {
                return(null);
            }
            JSONObject    paths     = new JSONObject(JSONObject.Type.ARRAY);
            AssetImporter importer  = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(avatar.GetInstanceID()));
            ModelImporter mImporter = importer as ModelImporter;

            if (mImporter != null)
            {
                for (int k = 0; k < mImporter.extraExposedTransformPaths.Length; k++)
                {
                    paths.Add(mImporter.extraExposedTransformPaths[k]);
                }
            }
            avatarJSON.AddField("version", "1");
            avatarJSON.AddField("rootNode", avatarRootNodeJSON);
            avatarJSON.AddField("optimized", mImporter.optimizeGameObjects);
            string avatarPath = Path.GetFullPath(Directory.GetParent(Application.dataPath) + "/" + AssetDatabase.GetAssetPath(avatar.GetInstanceID()));
            float  scale      = (Path.GetExtension(avatarPath).ToLower() == ".fbx" && mImporter.useFileUnits) ? 0.01f : 1.0f;

            avatarJSON.AddField("scaleFactor", succ ? scale : 1.0f);
            avatarJSON.AddField("paths", paths);

            avatarJSON.AddField("version", 2);

            // 在importsetting里关联fbx文件
            if (Path.GetExtension(avatarPath).ToLower() == ".fbx")
            {
                importSetting = new JSONObject();
                WXRawResource fbx             = new WXRawResource(AssetDatabase.GetAssetPath(avatar.GetInstanceID()));
                string        fbxExportedPath = fbx.Export(preset);
                importSetting.AddField("associateFbx", fbxExportedPath);
                AddDependencies(fbxExportedPath);
            }
            return(avatarJSON);
        }
        protected override void DoExport()
        {
            EditorUtility.ClearProgressBar();
            BridgeExport.isProcessing = false;

            List <string> allRecursiveAssets = new List <string>();

            // string choosedPath = GetExportPath();
            // string savePath = Path.Combine(choosedPath, "Assets/");
            var savePath = Path.Combine(ExportStore.storagePath, "Assets/");

            updateRecourcesDir();

            int totalCount = 0;

            string [] arr_dir = dirs.ToArray();

            JSONObject jsonConfig = new JSONObject(JSONObject.Type.ARRAY);

            if (arr_dir.Length > 0)
            {
                for (int index = 0; index < supportedTypes.Length; index++)
                {
                    string   filter = "t:" + supportedTypes[index];
                    string[] guids  = AssetDatabase.FindAssets(filter, arr_dir);
                    // Debug.Log(guids.Length);
                    if (guids.Length == 0)
                    {
                        continue;
                    }

                    JSONObject category = new JSONObject(JSONObject.Type.OBJECT);
                    JSONObject data     = new JSONObject(JSONObject.Type.ARRAY);
                    category.AddField("type", supportedTypes[index]);
                    category.AddField("files", data);

                    var t = 0;
                    HashSet <string> setFiles = new HashSet <string>();
                    for (int i = 0; i < guids.Length; i++)
                    {
                        string path = AssetDatabase.GUIDToAssetPath(guids[i]);
                        if (path.StartsWith("Assets"))
                        {
                            path = path.Substring(6);
                        }
                        string absolutePath = Path.Combine(Application.dataPath, path);
                        // #if UNITY_EDITOR_WIN
                        // string absolutePath = Application.dataPath + "\\" + path;
                        // #else
                        // string absolutePath = Application.dataPath + "/" + path;
                        // #endif

                        // string filename = System.IO.Path.GetFileName(absolutePath);

                        string copyToPath = Path.Combine(savePath, path);
                        // #if UNITY_EDITOR_WIN
                        // string copyToPath = savePath + "\\" + path;
                        // #else
                        // string copyToPath = savePath + "/" + path;
                        // #endif

                        string extension = System.IO.Path.GetExtension(path);
                        if (setExclude.Contains(extension))
                        {
                            continue;
                        }

                        if (supportedTypes[index] != "GameObject")
                        {
                            #if USE_RAW_MODE
                            string        projpath    = "Assets" + path;
                            WXRawResource rawResource = new WXRawResource(projpath);
                            string        ret_path    = rawResource.Export(this);
                            allRecursiveAssets.Add(ret_path);
                            #else
                            wxFileUtil.CopyFile(absolutePath, copyToPath);
                            #endif
                        }

                        JSONObject fileInfo = new JSONObject(JSONObject.Type.OBJECT);
                        // fileInfo.AddField("key", Path.GetFileNameWithoutExtension(filename));
                        string key = getResourcePath(path);
                        if (setFiles.Contains(key))
                        {
                            continue;
                        }
                        else
                        {
                            setFiles.Add(key);
                        }
                        fileInfo.AddField("key", key);
                        fileInfo.AddField("name", "Assets" + path);
                        data.Add(fileInfo);
                        totalCount++;
                        EditorUtility.DisplayProgressBar("原始资源导出", "", t++ / guids.Length);
                    }
                    jsonConfig.Add(category);
                }
            }
            #if USE_RAW_MODE
            string tempConfigFile = Path.Combine(Application.dataPath, "Resources.json");
            wxFileUtil.SaveJsonFile(jsonConfig, tempConfigFile);
            string        configpath   = "Assets/Resources.json";
            WXRawResource rawConfig    = new WXRawResource(configpath);
            string        ret_cfg_path = rawConfig.Export(this);
            allRecursiveAssets.Add(ret_cfg_path);
            File.Delete(tempConfigFile);
            #endif
            // string content = jsonConfig.ToString();
            // ExportStore.AddTextFile(configpath, content, WXUtility.GetMD5FromString(content));
            // List<string> useConfig = new List<string>();
            // useConfig.Add(configpath);
            // ExportStore.AddResource(configpath, "raw", null, useConfig);
            // allRecursiveAssets.Add(configpath);


            ExportStore.GenerateResourcePackage(
                "WXResources",
                allRecursiveAssets
                );

            EditorUtility.ClearProgressBar();
            Debug.Log("导出成功,总共导出文件个数:" + totalCount);
        }