You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.3 KiB

  1. #if UNITY_EDITOR
  2. using UnityEngine;
  3. using UnityEditor;
  4. using System.Linq;
  5. using System.Collections;
  6. /**
  7. * Despite the MonoBehaviour inheritance, this is an Editor-only script.
  8. */
  9. [ExecuteInEditMode]
  10. public class pg_SceneMeshRender : MonoBehaviour
  11. {
  12. // HideFlags.DontSaveInEditor isn't exposed for whatever reason, so do the bit math on ints
  13. // and just cast to HideFlags.
  14. // HideFlags.HideInHierarchy | HideFlags.DontSaveInEditor | HideFlags.NotEditable
  15. HideFlags SceneCameraHideFlags = (HideFlags) (1 | 4 | 8);
  16. public Mesh mesh;
  17. public Material material;
  18. void OnDestroy()
  19. {
  20. if(mesh) DestroyImmediate(mesh);
  21. if(material) DestroyImmediate(material);
  22. }
  23. void OnRenderObject()
  24. {
  25. // instead of relying on 'SceneCamera' string comparison, check if the hideflags match.
  26. // this could probably even just check for one bit match, since chances are that any
  27. // game view camera isn't going to have hideflags set.
  28. if( (Camera.current.gameObject.hideFlags & SceneCameraHideFlags) != SceneCameraHideFlags || Camera.current.name != "SceneCamera" )
  29. return;
  30. if(material == null || mesh == null)
  31. {
  32. GameObject.DestroyImmediate(this.gameObject);
  33. // Debug.Log("NULL MESH || MATERIAL");
  34. return;
  35. }
  36. material.SetPass(0);
  37. Graphics.DrawMeshNow(mesh, Vector3.zero, Quaternion.identity, 0);
  38. }
  39. }
  40. #endif