UOUtility.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using UnityEngine;
  2. using UnityEditor;
  3. using System.Linq;
  4. using System;
  5. namespace SplineMesh {
  6. public static class UOUtility {
  7. public static GameObject Create(string name, GameObject parent, params Type[] components) {
  8. var res = new GameObject(name, components);
  9. res.transform.parent = parent.transform;
  10. res.transform.localPosition = Vector3.zero;
  11. res.transform.localScale = Vector3.one;
  12. res.transform.localRotation = Quaternion.identity;
  13. return res;
  14. }
  15. public static GameObject Instantiate(GameObject prefab, Transform parent) {
  16. var res = UnityEngine.Object.Instantiate(prefab, parent);
  17. res.transform.localPosition = Vector3.zero;
  18. res.transform.localRotation = Quaternion.identity;
  19. res.transform.localScale = Vector3.one;
  20. return res;
  21. }
  22. public static void Destroy(GameObject go) {
  23. if (Application.isPlaying) {
  24. UnityEngine.Object.Destroy(go);
  25. } else {
  26. UnityEngine.Object.DestroyImmediate(go);
  27. }
  28. }
  29. public static void Destroy(Component comp) {
  30. if (Application.isPlaying) {
  31. UnityEngine.Object.Destroy(comp);
  32. } else {
  33. UnityEngine.Object.DestroyImmediate(comp);
  34. }
  35. }
  36. public static void DestroyChildren(GameObject go) {
  37. var childList = go.transform.Cast<Transform>().ToList();
  38. foreach (Transform childTransform in childList) {
  39. Destroy(childTransform.gameObject);
  40. }
  41. }
  42. }
  43. }