VoxelChunksObjectChunkCore.cs 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using UnityEngine;
  2. using UnityEngine.Assertions;
  3. using UnityEditor;
  4. using System;
  5. using System.IO;
  6. using System.Collections;
  7. using System.Collections.Generic;
  8. namespace VoxelImporter
  9. {
  10. public class VoxelChunksObjectChunkCore
  11. {
  12. public VoxelChunksObjectChunkCore(VoxelChunksObjectChunk target)
  13. {
  14. voxelChunk = target;
  15. voxelObject = target.transform.parent.GetComponent<VoxelChunksObject>();
  16. objectCore = new VoxelChunksObjectCore(voxelObject);
  17. }
  18. public VoxelChunksObjectChunk voxelChunk { get; protected set; }
  19. public VoxelChunksObject voxelObject { get; protected set; }
  20. public VoxelChunksObjectCore objectCore { get; protected set; }
  21. public void Initialize()
  22. {
  23. voxelChunk.EditorInitialize();
  24. }
  25. #region CreateVoxel
  26. public string GetDefaultPath()
  27. {
  28. var path = objectCore.GetDefaultPath();
  29. if (voxelObject != null)
  30. {
  31. if (voxelObject.materialMode == VoxelChunksObject.MaterialMode.Combine)
  32. {
  33. if (voxelChunk.mesh != null && AssetDatabase.Contains(voxelChunk.mesh))
  34. {
  35. var assetPath = AssetDatabase.GetAssetPath(voxelChunk.mesh);
  36. if (!string.IsNullOrEmpty(assetPath))
  37. {
  38. path = Path.GetDirectoryName(assetPath);
  39. }
  40. }
  41. }
  42. else if (voxelObject.materialMode == VoxelChunksObject.MaterialMode.Individual)
  43. {
  44. if (voxelChunk.mesh != null && AssetDatabase.Contains(voxelChunk.mesh))
  45. {
  46. var assetPath = AssetDatabase.GetAssetPath(voxelChunk.mesh);
  47. if (!string.IsNullOrEmpty(assetPath))
  48. {
  49. path = Path.GetDirectoryName(assetPath);
  50. }
  51. }
  52. if (voxelChunk.materials != null)
  53. {
  54. for (int i = 0; i < voxelChunk.materials.Count; i++)
  55. {
  56. if (AssetDatabase.Contains(voxelChunk.materials[i]))
  57. {
  58. var assetPath = AssetDatabase.GetAssetPath(voxelChunk.materials[i]);
  59. if (!string.IsNullOrEmpty(assetPath))
  60. {
  61. path = Path.GetDirectoryName(assetPath);
  62. }
  63. }
  64. }
  65. }
  66. if (voxelChunk.atlasTexture != null && AssetDatabase.Contains(voxelChunk.atlasTexture))
  67. {
  68. var assetPath = AssetDatabase.GetAssetPath(voxelChunk.atlasTexture);
  69. if (!string.IsNullOrEmpty(assetPath))
  70. {
  71. path = Path.GetDirectoryName(assetPath);
  72. }
  73. }
  74. }
  75. else
  76. {
  77. Assert.IsTrue(false);
  78. }
  79. }
  80. return path;
  81. }
  82. #endregion
  83. }
  84. }