Extensions.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. using System;
  2. using System.Collections;
  3. using UnityEngine;
  4. namespace Siccity.GLTFUtility {
  5. public static class Extensions {
  6. public class CoroutineRunner : MonoBehaviour { }
  7. private static CoroutineRunner coroutineRunner;
  8. public static Coroutine RunCoroutine(this IEnumerator ienum) {
  9. if (coroutineRunner == null) {
  10. coroutineRunner = new GameObject("[CoroutineRunner]").AddComponent<CoroutineRunner>();
  11. coroutineRunner.hideFlags = HideFlags.DontSaveInEditor | HideFlags.HideInHierarchy | HideFlags.HideInInspector | HideFlags.NotEditable | HideFlags.DontSaveInBuild;
  12. coroutineRunner.gameObject.hideFlags = HideFlags.DontSaveInEditor | HideFlags.HideInHierarchy | HideFlags.HideInInspector | HideFlags.NotEditable | HideFlags.DontSaveInBuild;
  13. }
  14. return coroutineRunner.StartCoroutine(ienum);
  15. }
  16. public static T[] SubArray<T>(this T[] data, int index, int length) {
  17. T[] result = new T[length];
  18. Array.Copy(data, index, result, 0, length);
  19. return result;
  20. }
  21. public static void UnpackTRS(this Matrix4x4 trs, ref Vector3 position, ref Quaternion rotation, ref Vector3 scale) {
  22. position = trs.GetColumn(3);
  23. position.x = -position.x;
  24. rotation = trs.rotation;
  25. rotation = new Quaternion(rotation.x, -rotation.y, -rotation.z, rotation.w);
  26. scale = trs.lossyScale;
  27. }
  28. }
  29. }