Misc.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. namespace UnityEngine.UI
  2. {
  3. /// <summary>
  4. /// Helper class containing generic functions used throughout the UI library.
  5. /// </summary>
  6. internal static class Misc
  7. {
  8. /// <summary>
  9. /// Destroy the specified object, immediately if in edit mode.
  10. /// </summary>
  11. static public void Destroy(UnityEngine.Object obj)
  12. {
  13. if (obj != null)
  14. {
  15. if (Application.isPlaying)
  16. {
  17. if (obj is GameObject)
  18. {
  19. GameObject go = obj as GameObject;
  20. go.transform.parent = null;
  21. }
  22. Object.Destroy(obj);
  23. }
  24. else Object.DestroyImmediate(obj);
  25. }
  26. }
  27. /// <summary>
  28. /// Destroy the specified object immediately, unless not in the editor, in which case the regular Destroy is used instead.
  29. /// </summary>
  30. static public void DestroyImmediate(Object obj)
  31. {
  32. if (obj != null)
  33. {
  34. if (Application.isEditor) Object.DestroyImmediate(obj);
  35. else Object.Destroy(obj);
  36. }
  37. }
  38. }
  39. }