MeshObjGeneratorInspector.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /****************************************************************************
  2. * Copyright 2019 Nreal Techonology Limited. All rights reserved.
  3. *
  4. * This file is part of NRSDK.
  5. *
  6. * https://www.nreal.ai/
  7. *
  8. *****************************************************************************/
  9. using System.IO;
  10. using UnityEditor;
  11. using UnityEngine;
  12. namespace NRKernal.NRExamples
  13. {
  14. #if UNITY_EDITOR
  15. [CustomEditor(typeof(MeshObjGenerator))]
  16. public class MeshObjGeneratorInspector : Editor
  17. {
  18. public override void OnInspectorGUI()
  19. {
  20. base.OnInspectorGUI();
  21. if (GUILayout.Button("Load Obj Mesh File"))
  22. {
  23. string path = EditorUtility.OpenFolderPanel("Load Obj Mesh File", Application.dataPath, "");
  24. if (!string.IsNullOrEmpty(path))
  25. {
  26. DirectoryInfo directoryInfo = new DirectoryInfo(path);
  27. if (directoryInfo.Exists)
  28. {
  29. foreach (var file in directoryInfo.EnumerateFiles("*.obj"))
  30. {
  31. StreamReader sr = File.OpenText(file.FullName);
  32. string meshData = sr.ReadToEnd();
  33. sr.Close();
  34. Mesh mesh = MeshSaver.StringToMesh(meshData);
  35. ulong.TryParse(file.Name.Substring(0, file.Name.IndexOf(".")), out ulong identifier);
  36. (serializedObject.targetObject as IMeshInfoProcessor).UpdateMeshInfo(identifier, NRMeshingBlockState.NR_MESHING_BLOCK_STATE_NEW, mesh);
  37. }
  38. }
  39. }
  40. }
  41. }
  42. }
  43. #endif
  44. }