VoxelObjectExplosion.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. namespace VoxelImporter
  5. {
  6. [AddComponentMenu("Voxel Importer/Extra/Explosion/Voxel Object Explosion")]
  7. [ExecuteInEditMode, RequireComponent(typeof(VoxelObject))]
  8. public class VoxelObjectExplosion : VoxelBaseExplosion
  9. {
  10. protected VoxelObject voxelObject { get; private set; }
  11. public List<MeshData> meshes;
  12. public List<Material> materials;
  13. protected override void Awake()
  14. {
  15. base.Awake();
  16. voxelObject = GetComponent<VoxelObject>();
  17. }
  18. public override void DrawMesh()
  19. {
  20. if (materials != null && meshes != null)
  21. {
  22. var world = transformCache.localToWorldMatrix;
  23. for (int i = 0; i < meshes.Count; i++)
  24. {
  25. if (meshes[i] == null || meshes[i].mesh == null) continue;
  26. for (int j = 0; j < meshes[i].materialIndexes.Count; j++)
  27. {
  28. if (j < meshes[i].mesh.subMeshCount)
  29. Graphics.DrawMesh(meshes[i].mesh, world, materials[meshes[i].materialIndexes[j]], 0, null, j, materialPropertyBlock);
  30. }
  31. }
  32. }
  33. }
  34. #if UNITY_EDITOR
  35. #region Asset
  36. public override bool IsUseAssetObject(UnityEngine.Object obj)
  37. {
  38. if (meshes != null)
  39. {
  40. for (int i = 0; i < meshes.Count; i++)
  41. {
  42. if (meshes[i].mesh == obj) return true;
  43. }
  44. }
  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. return false;
  53. }
  54. #endregion
  55. #endif
  56. }
  57. }