public static void AddResource( string descriptionFilePath, string resourceType, // 依赖的资源 List <string> dependencies, // 这个资源使用到的文件 List <string> useFile ) { if (descriptionFilePath == null || descriptionFilePath == "") { throw new System.Exception("empty resourcePath"); } JSONObject storageResourceJSON = storage.GetField("assets"); JSONObject fileItem = new JSONObject(JSONObject.Type.OBJECT); fileItem.AddField("descriptionPath", descriptionFilePath); fileItem.AddField("type", resourceType); fileItem.AddField("dependencies", WXUtility.ConvertListToJSONArray(dependencies)); fileItem.AddField("useFile", WXUtility.ConvertListToJSONArray(useFile)); storageResourceJSON.AddField(descriptionFilePath, fileItem); saveStorage(); }
public JSONObject GetAvatarRootNodeJSON(GameObject gameObject, GameObject animatorGameObject, ref int id, ref bool succ, string path = "") { string avatarPath = Path.GetFullPath(Directory.GetParent(Application.dataPath) + "/" + AssetDatabase.GetAssetPath(avatar.GetInstanceID())); if (Path.GetExtension(avatarPath).ToLower() == ".fbx") { string toolDir = WXConfig.GetModelToolPath();; if (toolDir != null) { string result = WXUtility.ExecProcess( toolDir, "\"" + avatarPath + "\"", out succ ); if (succ) { return(JSONObject.Create(result)); } } } else { EditorUtility.DisplayDialog("Error", "导出的模型格式不支持", "确定"); } succ = false; JSONObject rootNode = GetAvatarNodeData(gameObject, animatorGameObject, ref id, path); return(rootNode); }
protected override void DoExport() { GameObject[] prefabRoots = Selection.gameObjects; Scene gameScene = SceneManager.GetActiveScene(); if (!gameScene.isDirty || gameScene.isDirty && EditorUtility.DisplayDialog("提示", "检测到当前场景未保存,导出会自动进行保存场景,是否要继续导出", "导出", "暂不导出")) { EditorSceneManager.SaveScene(gameScene, gameScene.path); // foreach (GameObject prefabRoot in prefabRoots) { // WXUtility.TraverseSceneTreeToSave(prefabRoot, gameScene); // } foreach (GameObject prefabRoot in prefabRoots) { WXPrefab converter = new WXPrefab( prefabRoot, AssetDatabase.GetAssetPath(WXUtility.GetPrefabSource(prefabRoot)) ); PresetUtil.writeGroup(converter, this /*, (string)(configs.ContainsKey("exportPath") ? configs["exportPath"] : "")*/); } } }
public JSONObject GetComponentListJSON() { JSONObject componentListJSON = new JSONObject(JSONObject.Type.ARRAY); int index = 0; foreach (WXComponent component in componentList) { var result = component.GetJSON(); if (component.filePath != null && component.filePath != "" && component.filePath != ".prefab") // 只有prefab中的component可以获取其filePath { result.AddField("__prefab", component.filePath); } result.AddField("__fileId", WXUtility.GenerateLongByString(component.objectId.ToString() + component.getTypeName()).ToString()); result.AddField("_index", index++); if (result == null) { EditorUtility.DisplayDialog("Error", "导出compoennt为空 " + component.getTypeName(), "确定"); } else { componentListJSON.Add(result); } } return(componentListJSON); }
protected override void DoExport() { // GameObject prefabRoot = (GameObject) Selection.activeObject; GameObject[] prefabRoots = Selection.gameObjects; Scene gameScene = SceneManager.GetActiveScene(); if (!gameScene.isDirty || gameScene.isDirty && EditorUtility.DisplayDialog("提示", "检测到当前场景未保存,导出会自动进行保存场景,是否要继续导出", "导出", "暂不导出")) { string path = gameScene.path; EditorSceneManager.SaveScene(gameScene, path); foreach (GameObject prefabRoot in prefabRoots) { WXNGUITree converter = new WXNGUITree( prefabRoot, AssetDatabase.GetAssetPath(WXUtility.GetPrefabSource(prefabRoot)), (this.exportConfigs as NGUIExportConfig).exportAsScene ); PresetUtil.writeGroup(converter, this /*, (string)(configs.ContainsKey("exportPath") ? configs["exportPath"] : "")*/); } } }
// 导出一个资源 private void DequeueAndExport(int maxCount) { if (maxCount == 0) { return; } string guid = exportQueue.Dequeue(); string assetPath = AssetDatabase.GUIDToAssetPath(guid); EditorUtility.DisplayProgressBar( "资源导出", assetPath, (float)(maxCount - exportQueue.Count - 1) / maxCount ); GameObject prefab = (GameObject)AssetDatabase.LoadAssetAtPath( assetPath, AssetDatabase.GetMainAssetTypeAtPath(assetPath) ); // prefab // 忘了为什么要加这句判断了,资源管理器里的prefab理论上这里返回都是null if (WXUtility.GetPrefabSource(prefab)) { DequeueAndExport(maxCount); return; } // 资源管理器里的prefab,GetPrefabSource是null,这里就要实例化之后再取。 prefab = (GameObject)PrefabUtility.InstantiatePrefab(prefab); Selection.activeObject = prefab; prefab.transform.position = Vector3.zero; prefab.SetActive(true); //RichText.StaticTextCreator[] staicTextCreators = prefabRoot.GetComponentsInChildren<RichText.StaticTextCreator>(); //if (staicTextCreators != null && staicTextCreators.Length > 0) //{ // for (int k = 0; k < staicTextCreators.Length; k++) // { // RichText.StaticTextCreator stc = staicTextCreators[k]; // stc.ParseStaticText(true); // } //} WXPrefab wxPrefab = new WXPrefab(prefab, assetPath); PresetUtil.writeGroup(wxPrefab, this /*, (string)(configs.ContainsKey("exportPath") ? configs["exportPath"] : "")*/); UnityEngine.Object.DestroyImmediate(prefab); if (exportQueue.Count == 0) { EditorUtility.ClearProgressBar(); } else { DequeueAndExport(maxCount); } }
public override string GetHash() { if (exportAsScene) { return(WXUtility.GetMD5FromString(prefabPath)); } return(WXUtility.GetMD5FromAssetPath(prefabPath)); }
public WXNGUITree(GameObject prefabRoot, string prefabPath, bool exportAsScene, bool rootExport = false) : base(prefabPath) { this.prefabRoot = prefabRoot; this.prefabPath = prefabPath; this.exportAsScene = exportAsScene; this.exportSceneRoot = rootExport; exportName = WXUtility.GetFileNameFromPath(prefabPath); }
protected override void DoExport() { GameObject prefabRoot = (GameObject)Selection.activeObject; WXUGUITree converter = new WXUGUITree( prefabRoot, AssetDatabase.GetAssetPath(WXUtility.GetPrefabSource(prefabRoot)), (this.exportConfigs as UGUIExportConfig).exportAsScene ); PresetUtil.writeGroup(converter, this /*, (string)(configs.ContainsKey("exportPath") ? configs["exportPath"] : "")*/); }
public override bool WillPresetShow() { if (Selection.activeObject == null) { return(false); } try { return(WXUtility.GetPrefabSource(Selection.activeObject)); } catch (Exception e) { return(false); } }
public WXPrefab(GameObject prefabRoot, string prefabPath) { if (!prefabPath.EndsWith(".prefab")) { this.prefabPath = prefabPath + ".prefab"; } else { this.prefabPath = prefabPath; } this.prefabRoot = prefabRoot; exportName = WXUtility.GetFileNameFromPath(prefabPath); }
public GameObject SelectParentbyType(GameObject gameObject, WXUtility.ComponentType type) { if ((UnityEngine.Object)gameObject.transform.parent == (UnityEngine.Object)null) { return(null); } GameObject gameObject2 = gameObject.transform.parent.gameObject; if (WXUtility.componentsOnGameObject(gameObject2).IndexOf(type) != -1) { return(gameObject2); } return(SelectParentbyType(gameObject2, type)); }
public WXEntity(GameObject _go, int _arrayId, string _resourcePath) { gameObject = _go; children = new List <WXEntity>(); components = new List <int>(); //arrayId = -1; arrayId = _arrayId; getFileIdAndPrefabInfo(gameObject, _resourcePath); if (fileIdInOriginalSource == -1 || fileIdInOriginalSource == 0) { Debug.LogError("entity localId is 0, can't get entity localId " + gameObject.name); WXUtility.SaveSingleGameObject(gameObject, SceneManager.GetActiveScene()); getFileIdAndPrefabInfo(gameObject, _resourcePath); } }
protected override void DoExport() { GameObject prefabRoot = (GameObject)Selection.activeObject; Scene gameScene = SceneManager.GetActiveScene(); string path = gameScene.path; EditorSceneManager.SaveScene(gameScene, path); WXNGUITree converter = new WXNGUITree( prefabRoot, AssetDatabase.GetAssetPath(WXUtility.GetPrefabSource(prefabRoot)), (this.exportConfigs as NGUIExportConfig).exportAsScene ); PresetUtil.writeGroup(converter, this /*, (string)(configs.ContainsKey("exportPath") ? configs["exportPath"] : "")*/); }
public static bool FindNotLegalChild(GameObject gameObject) { if (WXUtility.componentsOnGameObject(gameObject).Count <= 1) { return(true); } for (int i = 0; i < gameObject.transform.childCount; i++) { GameObject childObject = gameObject.transform.GetChild(i).gameObject; if (FindNotLegalChild(childObject)) { return(true); } } return(false); }
private void PackFiles(string pkgName, string dirPath) { if (!Directory.Exists(dirPath)) { return; } EditorUtility.DisplayProgressBar("插件代码打包", "", 0.0f); var files = Directory.EnumerateFiles(dirPath, "*.js", SearchOption.AllDirectories).ToList(); List <string> allRecursiveAssets = new List <string>(); // all converted scripts var t = 0; foreach (var file in files) { // bridge plugin blacklist var name = Path.GetFileName(file); // Debug.Log(name); // 插件代码不打包这几个文件 if (name.Equals("minigame-adaptor-lib.js") || name.Equals("minigame-adaptor-lib.meta.js") || name.Equals("minigame-adaptor-lib-patch.js")) { continue; } JSONObject metadata = new JSONObject(JSONObject.Type.OBJECT); var cutIndex = Path.GetFullPath(file).IndexOf(dirPath) + dirPath.Length + 1; // +1 : '/' string path = Path.GetFullPath(file).Substring(cutIndex).Replace('\\', '/'); string content = File.ReadAllText(file); ExportStore.AddTextFile(path, content, WXUtility.GetMD5FromString(content)); List <string> useFile = new List <string>(); useFile.Add(path); ExportStore.AddResource(path, "script", null, useFile); allRecursiveAssets.Add(path); EditorUtility.DisplayProgressBar("插件代码打包", "", t++ / files.Count); } ExportStore.GenerateResourcePackage( pkgName, allRecursiveAssets ); }
protected override void DoExport() { GameObject[] prefabRoots = Selection.gameObjects; foreach (GameObject prefabRoot in prefabRoots) { string path = AssetDatabase.GetAssetPath(WXUtility.GetPrefabSource(prefabRoot)); string[] assetIDs = AssetDatabase.FindAssets("t:Prefab", new string[] { path }); foreach (string guid in assetIDs) { exportQueue.Enqueue(guid); } } DequeueAndExport(exportQueue.Count); }
public WXPrefab(GameObject prefabRoot, string prefabPath) : base(prefabPath) { if (!prefabPath.EndsWith(".prefab")) { this.prefabPath = prefabPath + ".prefab"; } else { this.prefabPath = prefabPath; } this.prefabRoot = prefabRoot; exportName = WXUtility.GetFileNameFromPath(prefabPath); if (unityAssetPath == null || unityAssetPath == "") { ErrorUtil.ExportErrorReporter.create() .setResource(this) .setGameObject(prefabRoot) .error(0, "Mesh文件的unity路径为空"); } }
protected override void DoExport() { GameObject[] prefabRoots = Selection.gameObjects; Scene gameScene = SceneManager.GetActiveScene(); EditorSceneManager.SaveScene(gameScene, gameScene.path); // foreach (GameObject prefabRoot in prefabRoots) { // WXUtility.TraverseSceneTreeToSave(prefabRoot, gameScene); // } foreach (GameObject prefabRoot in prefabRoots) { WXPrefab converter = new WXPrefab( prefabRoot, AssetDatabase.GetAssetPath(WXUtility.GetPrefabSource(prefabRoot)) ); PresetUtil.writeGroup(converter, this /*, (string)(configs.ContainsKey("exportPath") ? configs["exportPath"] : "")*/); } }
/** * 递归获取一段资源列表的所有依赖资源 */ private void GetAllDependenciesList( ref List <string> allDependenciesList, // 最终结果 List <string> resources // 要记入的资源 ) { //Debug.Log("GetAllDependenciesList" + allDependenciesList.ToArray().Length); foreach (string resourcePath in resources) { JSONObject resourceStorage = storage.GetField(resourcePath); if (resourceStorage == null) { Debug.LogError("创建资源包时写入'" + resourcePath + "'失败,没有找到该资源的转换记录"); continue; } List <string> dependencies = WXUtility.ConvertJSONArrayToList( resourceStorage.GetField("dependencies") ); if (dependencies != null && dependencies.ToArray().Length > 0) { GetAllDependenciesList(ref allDependenciesList, dependencies); // 排重后add入 foreach (string dependency in dependencies) { if (!allDependenciesList.Contains(dependency)) { allDependenciesList.Add(dependency); } } } // 加入它本身 if (!allDependenciesList.Contains(resourcePath)) { allDependenciesList.Add(resourcePath); } } }
public static void writeGroup(WXResource resource, ExportPreset preset) { try { EditorUtility.DisplayProgressBar( "导出资源", "资源读取中...", 0.33f ); string resourcePath = resource.Export(preset); EditorUtility.DisplayProgressBar( "导出资源", "文件写入中...", 0.66f ); string packageName = WXUtility.GetFileNameFromPath(resourcePath); if (packageName == "") { packageName = "Untitled"; } ExportStore.GenerateResourcePackage( packageName, resourcePath ); } catch (Exception e) { Debug.LogError(e.Message); Debug.LogError(e.StackTrace); } finally { EditorUtility.ClearProgressBar(); } }
public JSONObject GetSkinPaths(string name, ref bool succ) { Transform trans = renderer.transform; Animator animator = trans.GetComponent(typeof(Animator)) as Animator; while (!animator && trans) { trans = trans.parent; if (trans) { animator = trans.GetComponent(typeof(Animator)) as Animator; } } JSONObject bonesObject = new JSONObject(JSONObject.Type.ARRAY); if (animator) { string filePath = Path.GetFullPath(Directory.GetParent(Application.dataPath) + "/" + AssetDatabase.GetAssetPath(renderer.sharedMesh.GetInstanceID())); if (Path.GetExtension(filePath).ToLower() == ".fbx") { string toolDir = WXConfig.GetModelToolPath(); if (toolDir != null) { string result = WXUtility.ExecProcess( toolDir, "\"" + filePath + "\" --skin=\"" + name + "\"", out succ ); if (succ) { return(JSONObject.Create(result)); } else { EditorUtility.DisplayDialog("Error", "导出骨骼模型失败:" + result, "确定"); } } else { EditorUtility.DisplayDialog("Error", "模型导出工具缺失", "确定"); } } else { EditorUtility.DisplayDialog("Error", "导出的模型格式不支持", "确定"); } succ = false; for (int i = 0; i < renderer.bones.Length; i++) { Transform node = renderer.bones[i]; List <string> pathArray = new List <string>(); while (node != null && node != trans) { pathArray.Add(node.name); node = node.parent; } if (node != null) { pathArray.Reverse(); bonesObject.Add("/" + String.Join("/", pathArray.ToArray())); } } } return(bonesObject); }
private void writeResourceRecursive(string resourceDescriptionFilePath) { // 如果已经转换过了 if (packageGroupManifest_resourceDefinitions.HasField(resourceDescriptionFilePath)) { return; } // 先找到之前已经写入缓存表的资源。 JSONObject resourceStorage = storage.GetField("assets").GetField(resourceDescriptionFilePath); if (resourceStorage == null) { Debug.LogError("创建资源包时写入'" + resourceDescriptionFilePath + "'失败,没有找到该资源的转换记录"); return; } // 创建每一个资源definition的json对象 JSONObject definitionObject = new JSONObject(JSONObject.Type.OBJECT); packageGroupManifest_resourceDefinitions.AddField(resourceDescriptionFilePath, definitionObject); // 写入字段 definitionObject.AddField("dependencies", resourceStorage.GetField("dependencies")); definitionObject.AddField("type", resourceStorage.GetField("type")); definitionObject.AddField("descriptionFileID", resourceDescriptionFilePath); // 把记在缓存里的useFile拿出来,遍历,写入group.manifest.json的fileDescription字段 // 并且排除掉resourceDescriptionFilePath之后放入resourceDefinition JSONObject outputUseFileArray = new JSONObject(JSONObject.Type.ARRAY); definitionObject.AddField("useFile", outputUseFileArray); // 放入文件 foreach (string usingFile in WXUtility.ConvertJSONArrayToList(resourceStorage.GetField("useFile"))) { if (usingFile != resourceDescriptionFilePath) { outputUseFileArray.Add(usingFile); } if (packageGroupManifest_fileDescription.HasField(usingFile)) { continue; } JSONObject fileStorage = storage.GetField("files").GetField(usingFile); // add fileDescriptions JSONObject fileDescription = new JSONObject(JSONObject.Type.OBJECT); packageGroupManifest_fileDescription.AddField(usingFile, fileDescription); fileDescription.AddField("path", usingFile); // add files 555 JSONObject fileItem = new JSONObject(JSONObject.Type.OBJECT); fileItem.AddField("path", usingFile); fileItem.AddField("filetype", fileStorage.GetField("filetype")); packageGroupManifest_files.Add(fileItem); wxFileUtil.CopyFile( Path.Combine(storagePath, Path.Combine(CONTENT_FOLDER, fileStorage.GetField("MD5").GetRawString())), Path.Combine(destPath, usingFile) ); } // 递归转依赖 foreach (string dependencyResource in WXUtility.ConvertJSONArrayToList(resourceStorage.GetField("dependencies"))) { writeResourceRecursive(dependencyResource); } }
public override string GetHash() { return(WXUtility.GetMD5FromAssetPath(unityAssetPath)); }
public override string GetHash() { string assetVersion = WXUtility.GetMD5FromAssetPath(gameScene.path); return(assetVersion); }
protected override void DoExport() { var build = DirectoryBuilder.GetDirectory("build"); // check cache var projectDir = new DirectoryInfo(build["Project"].FullPath); // Debug.Log(projectDir.GetFiles().Length); if (!projectDir.Exists || projectDir.GetFiles() == null || projectDir.GetFiles().Length <= 1) { BridgeExport.ExportCodeMenu(); } // convert // BridgeExport.ExportCode(); // EditorUtility.ClearProgressBar(); // BridgeExport.isProcessing = false; EditorUtility.DisplayProgressBar("代码导出", "", 0.0f); var dirPath = BridgeExport.PROJECT_CODE_PATH; var files = Directory.EnumerateFiles(dirPath, "*.js", SearchOption.AllDirectories).ToList(); List <string> allRecursiveAssets = new List <string>(); // all converted scripts var t = 0; foreach (var file in files) { // bridge plugin blacklist var name = Path.GetFileName(file); // Debug.Log(name); // 使用引擎插件不打包这几个文件,以节省代码包体积 if (WXBridge.isWXBridgePlugin && ( name.Equals("minigame-adaptor-lib.js") || name.Equals("minigame-adaptor-lib.meta.js") || name.Equals("minigame-adaptor-lib-patch.js"))) { continue; } JSONObject metadata = new JSONObject(JSONObject.Type.OBJECT); metadata.AddField("version", 1); // string path = Path.GetFullPath(file).Replace(Path.Combine(Application.dataPath.Replace("Assets", ""), "__tmp_dist_script~"), "Assets"); var cutIndex = Path.GetFullPath(file).IndexOf(dirPath) + dirPath.Length + 1; // +1 : '/' string path = Path.GetFullPath(file).Substring(cutIndex).Replace('\\', '/'); // Debug.Log(path); // Debug.Log(file + "===" + path); // Debug.Log(path); string content = File.ReadAllText(file); ExportStore.AddTextFile(path, content, WXUtility.GetMD5FromString(content)); List <string> useFile = new List <string>(); useFile.Add(path); ExportStore.AddResource(path, "script", null, useFile); allRecursiveAssets.Add(path); EditorUtility.DisplayProgressBar("代码导出", "", t++ / files.Count); } // var libs = Directory.EnumerateFiles(Path.Combine(bridgeRootPath, "lib"), "*.lib"); var libs = Directory.EnumerateFiles(DirectoryBuilder.GetDirectory("references")["Adaptor"].FullPath, "*.lib"); // Debug.Log(libs); foreach (var lib in libs) { var name = Path.GetFileName(lib); // Debug.Log(name); // bridge plugin blacklist // 使用引擎插件的情况 if (WXBridge.isWXBridgePlugin) { // 如果使用了插件但是要用自己的adaptor.js,这个文件也要打包 if (!WXBridge.isWXBridgePluginAdaptor) { if (!name.Equals("minigame-adaptor-util.js.lib") && !name.Equals("minigame-adaptor-config.js.lib") && !name.Equals("minigame-adaptor.js.lib")) { continue; } } else { if (!name.Equals("minigame-adaptor-util.js.lib") && !name.Equals("minigame-adaptor-config.js.lib")) { continue; } } } JSONObject metadata = new JSONObject(JSONObject.Type.OBJECT); metadata.AddField("version", 1); string path = name.Substring(0, name.Length - 4); // 配置文件内容根据插件的配置来生成 if (name.Equals("minigame-adaptor-config.js.lib")) { // var content = String.Format("module.exports = {{\r\n userMiniGameAdaptorPlugin:{0},\r\n userMiniGameAdaptorJs:{1},\r\n pluginAlias:'WXBridge'\r\n}}", WXBridge.isWXBridgePlugin ? 1 : 0, WXBridge.isWXBridgePluginAdaptor ? 1 : 0); var content = ScriptExportHelper.ExportGameConfig(); ExportStore.AddTextFile(path, content, WXUtility.GetMD5FromString(content)); } else { string content = File.ReadAllText(lib); ExportStore.AddTextFile(path, content, WXUtility.GetMD5FromString(content)); } List <string> useFile = new List <string>(); useFile.Add(path); ExportStore.AddResource(path, "script", null, useFile); allRecursiveAssets.Add(path); } // game config js // { // JSONObject metadata = new JSONObject(JSONObject.Type.OBJECT); // metadata.AddField("version", 1); // string path = "Assets/bridge_game_config.js"; // JSONObject content = ScriptExportHelper.ExportSceneJson(); // WXExportStore.AddJSONFile(path, content, WXUtility.GetMD5FromString(content.ToString())); // List<string> useFile = new List<string>(); // useFile.Add(path); // WXExportStore.AddResource(path, "script", null, useFile); // allRecursiveAssets.Add(path); // } //string savePath = Path.Combine(SAVE_BASE_PATH, "Scripts.mgepackage/"); //JSONObject manifestRoot = new JSONObject(JSONObject.Type.OBJECT); //manifestRoot.AddField("resourceMeta", exportContext.writeResourcesTo(savePath, allRecursiveAssets)); //wxFileUtil.SaveJsonFile(manifestRoot, savePath + "group.manifest.json"); ExportStore.GenerateResourcePackage( "WXScripts", allRecursiveAssets ); EditorUtility.ClearProgressBar(); Debug.Log("导出工程代码: 1"); }
private void getFileIdAndPrefabInfo(GameObject gameObject, string _resourcePath) { if (gameObject != null) { fileIdInOriginalSource = WXUtility.GetFileIdInInspector(gameObject); } #if UNITY_2018_4_OR_NEWER string guid; long fileId; if (gameObject != null) { isPrefabNode = PrefabUtility.IsPartOfPrefabInstance(gameObject) || PrefabUtility.IsPartOfPrefabAsset(gameObject); bool isDisconnectedPrefabInstance = PrefabUtility.IsDisconnectedFromPrefabAsset(gameObject); // Debug.LogError("gameObject.name: " + gameObject.name + " isDisconnectedPrefabInstance: " + isDisconnectedPrefabInstance + " IsPartOfAnyPrefab: " + isPrefabNode + " isAssetPrefabNode: " + PrefabUtility.IsPartOfPrefabAsset(gameObject) + " isPrefabInstanceNode: " + PrefabUtility.IsPartOfPrefabInstance(gameObject) + " IsPartOfModelPrefab: " + PrefabUtility.IsPartOfModelPrefab(gameObject) + " IsPartOfNonAssetPrefabInstance: " + PrefabUtility.IsPartOfNonAssetPrefabInstance(gameObject) + " IsPartOfPrefabThatCanBeAppliedTo: " + PrefabUtility.IsPartOfPrefabThatCanBeAppliedTo(gameObject) + " IsPartOfRegularPrefab: " + PrefabUtility.IsPartOfRegularPrefab(gameObject) + " IsPartOfVariantPrefab: " + PrefabUtility.IsPartOfVariantPrefab(gameObject) + " IsPrefabAssetMissing: " + PrefabUtility.IsPrefabAssetMissing(gameObject)); if (isPrefabNode && !isDisconnectedPrefabInstance) { GameObject sourceObj = PrefabUtility.GetCorrespondingObjectFromOriginalSource(gameObject); if (sourceObj != null && AssetDatabase.TryGetGUIDAndLocalFileIdentifier(sourceObj, out guid, out fileId)) { string path = AssetDatabase.GUIDToAssetPath(guid); unityAssetPath = path; if (!path.EndsWith(".prefab")) { path = path + ".prefab"; } prefabPath = path; fileIdInOriginalSource = fileId; if (_resourcePath != prefabPath) { isPrefabNodeInParentInstance = PrefabUtility.IsPartOfPrefabInstance(gameObject); GameObject sourceGameObject = gameObject; try { // 处理S1->P1->P2的场景下,导出P1,P2应该是P1的outermostPrefabRoot if (!_resourcePath.EndsWith(".scene")) { GameObject source = PrefabUtility.GetCorrespondingObjectFromSourceAtPath(sourceGameObject, _resourcePath); if (source) { sourceGameObject = source; } } } catch { } isOutermostPrefabRoot = PrefabUtility.IsOutermostPrefabInstanceRoot(sourceGameObject); prefabRootInstanceFileId = WXUtility.GetFileIdInInspector(sourceGameObject.transform); bool isAnyPrefabInstanceRoot = PrefabUtility.IsAnyPrefabInstanceRoot(gameObject); // Debug.Log("prefabObj: " + gameObject.name + " isAnyPrefabInstanceRoot: " + isAnyPrefabInstanceRoot + " isOutermostPrefabRoot: " + isOutermostPrefabRoot); if (isAnyPrefabInstanceRoot && !isOutermostPrefabRoot) // 如果不是最外层的prefabRoot // 处理S1->P1->P2的场景下,计算P2的prefabInstanceLocalId时,先找到P2的父节点,再通过父节点找到所在的P1文件,再拿到P2在P1中的Instance,再通过其transform的fileId作为prefabInstanceLocalId { string prefabAssetPath = PrefabUtility.GetPrefabAssetPathOfNearestInstanceRoot(gameObject.transform.parent.gameObject); // GameObject instanceRoot = PrefabUtility.GetCorrespondingObjectFromSource(gameObject); GameObject instanceRoot = PrefabUtility.GetCorrespondingObjectFromSourceAtPath(gameObject, prefabAssetPath); isNestedPrefabRoot = true; if (instanceRoot != null) { prefabRootInstanceFileId = WXUtility.GetFileIdInInspector(instanceRoot.transform); } } // string prefabAssetPath = PrefabUtility.GetPrefabAssetPathOfNearestInstanceRoot(gameObject); // bool isModelPrefabInstance = prefabAssetPath.EndsWith(".FBX"); // // 对于model的根节点,统一设置其prefabRootInstanceFileId // if (isModelPrefabInstance && isAnyPrefabInstanceRoot) { // GameObject instanceRoot = PrefabUtility.GetCorrespondingObjectFromOriginalSource(gameObject); // prefabRootInstanceFileId = WXUtility.GetFileIdInInspector(instanceRoot.transform); // } } // Debug.Log("sourceObj: " + sourceObj.name + " guid: " + guid + " fileID: " + fileIdInOriginalSource + " path: " + prefabPath); } else { Debug.LogError("2 can't get component localId " + gameObject.name); } } } #else if (gameObject != null && PrefabUtility.GetPrefabParent(gameObject) != null) { try { PrefabType type = PrefabUtility.GetPrefabType(gameObject); if (type == PrefabType.DisconnectedPrefabInstance || type == PrefabType.DisconnectedModelPrefabInstance || type == PrefabType.MissingPrefabInstance) { return; } UnityEngine.Object prefabGameObject = PrefabUtility.GetPrefabParent(gameObject); string path = AssetDatabase.GetAssetPath(prefabGameObject); unityAssetPath = path; if (!path.EndsWith(".prefab")) { path = path + ".prefab"; } prefabPath = path; if (prefabPath == _resourcePath) { isPrefabNodeInParentInstance = false; } else { GameObject prefabRoot = PrefabUtility.FindRootGameObjectWithSameParentPrefab(gameObject); if (prefabRoot == gameObject) { isOutermostPrefabRoot = true; prefabRootInstanceFileId = WXUtility.GetFileIdInInspector(gameObject.transform); } isPrefabNodeInParentInstance = true; } fileIdInOriginalSource = WXUtility.GetFileIdInInspector(prefabGameObject); } catch { // 应该不会走道这里单独导出prefab时,nativeComponent已经是一个实例了,会被GetCorrespondingObjectFromOriginalSource方法抛错 Debug.LogError("2 can't get component localId " + gameObject.name); } } #endif }
public override string GetHash() { return("" + WXUtility.GetMD5FromString(GetExportPath()) + File.GetLastWriteTime(unityAssetPath).Ticks); }
public JSONObject GetAvatarNodeData(GameObject gameObject, GameObject animatorGameObject, ref int id, string path = "") { bool currentNodeHasNotLegalChild = FindNotLegalChild(gameObject); if ( ( (UnityEngine.Object)SelectParentbyType( gameObject, WXUtility.ComponentType.Animator ) != (UnityEngine.Object)animatorGameObject || WXUtility .componentsOnGameObject(gameObject) .IndexOf(WXUtility.ComponentType.Animator) != -1 ) && (UnityEngine.Object)gameObject != (UnityEngine.Object)animatorGameObject ) { return(null); } if (currentNodeHasNotLegalChild) { JSONObject nodeJSON = new JSONObject(JSONObject.Type.OBJECT); JSONObject nodeProps = new JSONObject(JSONObject.Type.OBJECT); JSONObject translate = new JSONObject(JSONObject.Type.ARRAY); JSONObject rotation = new JSONObject(JSONObject.Type.ARRAY); JSONObject scale = new JSONObject(JSONObject.Type.ARRAY); Vector3 localPosition = gameObject.transform.localPosition; Quaternion localRotation = gameObject.transform.localRotation; Vector3 localScale = gameObject.transform.localScale; nodeProps.AddField("name", gameObject.name); nodeJSON.AddField("props", nodeProps); translate = new JSONObject(JSONObject.Type.ARRAY); nodeProps.AddField("translate", translate); translate.Add(localPosition.x * -1f); translate.Add(localPosition.y); translate.Add(localPosition.z); rotation = new JSONObject(JSONObject.Type.ARRAY); nodeProps.AddField("rotation", rotation); rotation.Add(localRotation.x * -1f); rotation.Add(localRotation.y); rotation.Add(localRotation.z); rotation.Add(localRotation.w * -1f); scale = new JSONObject(JSONObject.Type.ARRAY); nodeProps.AddField("scale", scale); scale.Add(localScale.x); scale.Add(localScale.y); scale.Add(localScale.z); id = id + 1; if (id > -1) { if (path.Length > 0) { path = path + "/" + gameObject.name; } else { path = gameObject.name; } } JSONObject nodeChildrenArray = new JSONObject(JSONObject.Type.ARRAY); if (gameObject.transform.childCount > 0) { for (int i = 0; i < gameObject.transform.childCount; i++) { JSONObject child = GetAvatarNodeData(gameObject.transform.GetChild(i).gameObject, animatorGameObject, ref id, path); if (child != null) { nodeChildrenArray.Add(child); } } } nodeJSON.AddField("child", nodeChildrenArray); return(nodeJSON); } return(null); }
public override string GetHash() { return(WXUtility.GetMD5FromHierarchyResourceAssetPath(prefabPath)); }