VoxelObject.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using UnityEngine;
  2. using UnityEngine.Assertions;
  3. using UnityEngine.Serialization;
  4. using System;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. namespace VoxelImporter
  8. {
  9. [AddComponentMenu("Voxel Importer/Voxel Object")]
  10. [RequireComponent(typeof(MeshFilter)), RequireComponent(typeof(MeshRenderer))]
  11. public class VoxelObject : VoxelBase
  12. {
  13. #if !UNITY_EDITOR
  14. protected virtual void Awake()
  15. {
  16. Destroy(this);
  17. }
  18. #else
  19. public override bool EditorInitialize()
  20. {
  21. var result = base.EditorInitialize();
  22. //ver1.021 -> ver1.0.3
  23. if (material != null)
  24. {
  25. materials = new List<Material>();
  26. materials.Add(material);
  27. materialData = new List<MaterialData>();
  28. materialData.Add(new MaterialData());
  29. materialIndexes = new List<int>();
  30. materialIndexes.Add(0);
  31. material = null;
  32. result = true;
  33. }
  34. return result;
  35. }
  36. public Mesh mesh;
  37. [SerializeField]
  38. protected Material material; //ver1.021 old
  39. public List<Material> materials; //ver1.0.3 new
  40. public Texture2D atlasTexture;
  41. #region Asset
  42. public override bool IsUseAssetObject(UnityEngine.Object obj)
  43. {
  44. if (mesh == obj) return true;
  45. if (materials != null)
  46. {
  47. for (int i = 0; i < materials.Count; i++)
  48. {
  49. if (materials[i] == obj) return true;
  50. }
  51. }
  52. if (atlasTexture == obj) return true;
  53. return false;
  54. }
  55. #endregion
  56. #endif
  57. }
  58. }