public override void OnInspectorGUI() { serializedObject.Update(); var dclObject = target as DclObject; var go = dclObject.gameObject; EditorGUILayout.PropertyField(visible, new GUIContent("visible")); //to do : rebuild primitive mesh when mesh parameter changed if (dclObject.dclPrimitiveType != DclPrimitiveType.other) { EditorGUILayout.PropertyField(withCollision, new GUIContent("withCollision", "Only available for primitives")); } //XML Preview var style = EditorStyles.foldout; style.fontStyle = FontStyle.Bold; if (EditorUtil.GUILayout.AutoSavedFoldout("DclObjectXml", "XML Preview", true, style, false)) { EditorGUILayout.BeginVertical("box"); var xml = new StringBuilder(); SceneTraverser.RecursivelyTraverseTransform(go.transform, xml, null, 0, null, null, null); style = EditorStyles.label; style.wordWrap = true; EditorGUILayout.TextArea(xml.ToString(), style); EditorGUILayout.EndVertical(); } serializedObject.ApplyModifiedProperties(); }
void InfoGUI() { EditorGUILayout.BeginHorizontal(); GUILayout.Label("Statistics", EditorStyles.boldLabel, GUILayout.Width(100)); if (GUILayout.Button("Refresh")) { sceneStatistics = new SceneStatistics(); SceneTraverser.TraverseAllScene(null, null, sceneStatistics); } EditorGUILayout.EndHorizontal(); GUILayout.Label("Keep these numbers smaller than the right", EditorStyles.centeredGreyMiniLabel); var n = sceneMeta.parcels.Count; EditorGUILayout.LabelField("Triangles", string.Format("{0} / {1}", sceneStatistics.triangleCount, LimitationConfigs.GetMaxTriangles(n))); EditorGUILayout.LabelField("Entities", string.Format("{0} / {1}", sceneStatistics.entityCount, LimitationConfigs.GetMaxTriangles(n))); EditorGUILayout.LabelField("Bodies", string.Format("{0} / {1}", sceneStatistics.bodyCount, LimitationConfigs.GetMaxBodies(n))); EditorGUILayout.LabelField("Height", string.Format("{0} / {1}", sceneStatistics.maxHeight, LimitationConfigs.GetMaxHeight(n))); }
/// <summary> /// Export scene.tsx, scene.json, unity_assets/ /// </summary> void Export() { if (string.IsNullOrEmpty(exportPath)) { EditorUtility.DisplayDialog("NO Path!", "You must assign the export path!", null, "OK"); return; } if (!Directory.Exists(exportPath)) { Directory.CreateDirectory("exportPath"); } //delete all files in exportPath/unity_assets/ var unityAssetsFolderPath = Path.Combine(exportPath, "unity_assets/"); if (Directory.Exists(unityAssetsFolderPath)) { //ClearFolder(unityAssetsFolderPath); UnityEditor.FileUtil.DeleteFileOrDirectory(unityAssetsFolderPath); } Directory.CreateDirectory(unityAssetsFolderPath);//TODO:当DCLSDK运行时,文件操作会冲突。可能可以用异步等待删除完毕。 if (!Directory.Exists(Path.Combine(exportPath, "src"))) { Directory.CreateDirectory(Path.Combine(exportPath, "src")); } var statistics = new SceneStatistics(); StringBuilder exportStr = new StringBuilder(); var resourceRecorder = SceneTraverser.TraverseAllScene(exportStr, statistics, null); File.WriteAllText(Path.Combine(exportPath, "src/game.ts"), exportStr.ToString()); //glTF in unity_asset foreach (var go in resourceRecorder.meshesToExport) { string tempPath = Path.Combine(unityAssetsFolderPath, SceneTraverser.GetIdentityName(go) + ".gltf"); sceneMeta.sceneToGlTFWiz.ExportGameObjectAndChildren(go, tempPath, null, false, true, false, false); } //textures foreach (var texture in resourceRecorder.primitiveTexturesToExport) { var relPath = AssetDatabase.GetAssetPath(texture); if (string.IsNullOrEmpty(relPath) || relPath.StartsWith("Library/")) { //built-in asset var bytes = ((Texture2D)texture).EncodeToPNG(); string str = Path.Combine(unityAssetsFolderPath, texture.name + ".png"); File.WriteAllBytes(str.Replace(" ", string.Empty), bytes); } else { var path = Application.dataPath; //<path to project folder>/Assets path = path.Remove(path.Length - 6, 6) + relPath; var toPath = unityAssetsFolderPath + relPath; //replace space by zcy //toPath = toPath.Replace (" ", string.Empty); var directoryPath = Path.GetDirectoryName(toPath); if (!Directory.Exists(directoryPath)) { Directory.CreateDirectory(directoryPath); } File.Copy(path, toPath, true); } Debug.Log("Texture out " + relPath); } //audioClips foreach (var audioClip in resourceRecorder.audioClipsToExport) { var relPath = AssetDatabase.GetAssetPath(audioClip); if (string.IsNullOrEmpty(relPath) || relPath.StartsWith("Library/")) { Debug.LogError("AudioClip should not be built-in assets."); } else { var path = Application.dataPath; //<path to project folder>/Assets path = path.Remove(path.Length - 6, 6) + relPath; var toPath = unityAssetsFolderPath + relPath; var directoryPath = Path.GetDirectoryName(toPath); if (!Directory.Exists(directoryPath)) { Directory.CreateDirectory(directoryPath); } File.Copy(path, toPath, true); } Debug.Log("Audio out " + relPath); } //scene.json { var fileTxt = GetSceneJsonFileTemplate(); fileTxt = fileTxt.Replace("{ETH_ADDRESS}", sceneMeta.ethAddress); fileTxt = fileTxt.Replace("{CONTACT_NAME}", sceneMeta.contactName); fileTxt = fileTxt.Replace("{CONTACT_EMAIL}", sceneMeta.email); var parcelsString = GetParcelsString(); fileTxt = fileTxt.Replace("{PARCELS}", parcelsString); if (sceneMeta.parcels.Count > 0) { fileTxt = fileTxt.Replace("{BASE}", ParcelToString(sceneMeta.parcels[0])); } var filePath = Path.Combine(exportPath, "scene.json"); File.WriteAllText(filePath, fileTxt); } Debug.Log("===Export Complete==="); }
void Export() { var exportPath = sceneMeta.exportPath; if (string.IsNullOrEmpty(exportPath)) { EditorUtility.DisplayDialog("NO Path!", "You must assign the export path!", null, "OK"); return; } if (!Directory.Exists(exportPath)) { Directory.CreateDirectory("exportPath"); } //delete all files in exportPath/unity_assets/ var unityAssetsFolderPath = Path.Combine(exportPath, "unity_assets/"); if (Directory.Exists(unityAssetsFolderPath)) { Directory.GetFiles(unityAssetsFolderPath, "*", SearchOption.AllDirectories).ToList().ForEach(File.Delete); Directory.GetDirectories(unityAssetsFolderPath).ToList().ForEach(f => Directory.Delete(f, true)); } else { Directory.CreateDirectory(unityAssetsFolderPath); } var meshesToExport = new List <GameObject>(); var sceneXmlBuilder = new StringBuilder(); var statistics = new SceneStatistics(); SceneTraverser.TraverseAllScene(sceneXmlBuilder, meshesToExport, statistics); var sceneXml = sceneXmlBuilder.ToString(); //scene.tsx var fileTxt = GetSceneTsxFileTemplate(); fileTxt = fileTxt.Replace("{XML}", sceneXml); var filePath = Path.Combine(exportPath, "scene.tsx"); File.WriteAllText(filePath, fileTxt); //glTF in unity_asset foreach (var go in meshesToExport) { sceneMeta.sceneToGlTFWiz.ExportGameObject(go, Path.Combine(unityAssetsFolderPath, go.name + ".gltf"), null, false, true, false, false); } //scene.json fileTxt = GetSceneJsonFileTemplate(); fileTxt = fileTxt.Replace("{ETH_ADDRESS}", sceneMeta.ethAddress); fileTxt = fileTxt.Replace("{CONTACT_NAME}", sceneMeta.contactName); fileTxt = fileTxt.Replace("{CONTACT_EMAIL}", sceneMeta.email); var parcelsString = GetParcelsString(); fileTxt = fileTxt.Replace("{PARCELS}", parcelsString); if (sceneMeta.parcels.Count > 0) { fileTxt = fileTxt.Replace("{BASE}", ParcelToString(sceneMeta.parcels[0])); } filePath = Path.Combine(exportPath, "scene.json"); File.WriteAllText(filePath, fileTxt); Debug.Log("===Export Complete==="); }
public void RefreshStatistics() { sceneStatistics = new SceneStatistics(); sceneWarningRecorder = new SceneWarningRecorder(); SceneTraverser.TraverseAllScene(null, sceneStatistics, sceneWarningRecorder); }
/// <summary> /// Export scene.tsx, scene.json, unity_assets/ /// </summary> void Export() { if (string.IsNullOrEmpty(exportPath)) { EditorUtility.DisplayDialog("NO Path!", "You must assign the export path!", null, "OK"); return; } if (!Directory.Exists(exportPath)) { Directory.CreateDirectory("exportPath"); } //delete all files in exportPath/unity_assets/ var unityAssetsFolderPath = Path.Combine(exportPath, "unity_assets/"); if (Directory.Exists(unityAssetsFolderPath)) { //ClearFolder(unityAssetsFolderPath); UnityEditor.FileUtil.DeleteFileOrDirectory(unityAssetsFolderPath); } Directory.CreateDirectory(unityAssetsFolderPath); var meshesToExport = new List <GameObject>(); var sceneXmlBuilder = new StringBuilder(); var statistics = new SceneStatistics(); SceneTraverser.TraverseAllScene(sceneXmlBuilder, meshesToExport, statistics, null); var sceneXml = sceneXmlBuilder.ToString(); //scene.tsx var fileTxt = GetSceneTsxFileTemplate(); fileTxt = fileTxt.Replace("{XML}", sceneXml); var filePath = Path.Combine(exportPath, "scene.tsx"); File.WriteAllText(filePath, fileTxt); //glTF in unity_asset foreach (var go in meshesToExport) { string tempPath = Path.Combine(unityAssetsFolderPath, SceneTraverser.CalcName(go) + ".gltf"); if (!File.Exists(tempPath)) { sceneMeta.sceneToGlTFWiz.ExportGameObjectAndChildren(go, tempPath, null, false, true, false, false); } } //textures var primitiveTexturesToExport = SceneTraverser.primitiveTexturesToExport; foreach (var texture in primitiveTexturesToExport) { var relPath = AssetDatabase.GetAssetPath(texture); if (string.IsNullOrEmpty(relPath)) { //built-in asset var bytes = ((Texture2D)texture).EncodeToPNG(); File.WriteAllBytes(Path.Combine(unityAssetsFolderPath, texture.name + ".png"), bytes); } else { var path = Application.dataPath; //<path to project folder>/Assets path = path.Remove(path.Length - 6, 6) + relPath; var toPath = unityAssetsFolderPath + relPath; var directoryPath = Path.GetDirectoryName(toPath); if (!Directory.Exists(directoryPath)) { Directory.CreateDirectory(directoryPath); } File.Copy(path, toPath, true); } } //scene.json fileTxt = GetSceneJsonFileTemplate(); fileTxt = fileTxt.Replace("{ETH_ADDRESS}", sceneMeta.ethAddress); fileTxt = fileTxt.Replace("{CONTACT_NAME}", sceneMeta.contactName); fileTxt = fileTxt.Replace("{CONTACT_EMAIL}", sceneMeta.email); var parcelsString = GetParcelsString(); fileTxt = fileTxt.Replace("{PARCELS}", parcelsString); if (sceneMeta.parcels.Count > 0) { fileTxt = fileTxt.Replace("{BASE}", ParcelToString(sceneMeta.parcels[0])); } filePath = Path.Combine(exportPath, "scene.json"); File.WriteAllText(filePath, fileTxt); Debug.Log("===Export Complete==="); }