ScriptOrderManager.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /****************************************************************************
  2. * Copyright 2019 Nreal Techonology Limited. All rights reserved.
  3. *
  4. * This file is part of NRSDK.
  5. *
  6. * https://www.nreal.ai/
  7. *
  8. *****************************************************************************/
  9. namespace NRKernal
  10. {
  11. using System;
  12. using UnityEditor;
  13. /// <summary> Manager for script orders. </summary>
  14. [InitializeOnLoad]
  15. public class ScriptOrderManager
  16. {
  17. /// <summary> Static constructor. </summary>
  18. static ScriptOrderManager()
  19. {
  20. foreach (MonoScript monoScript in MonoImporter.GetAllRuntimeMonoScripts())
  21. {
  22. if (monoScript.GetClass() != null)
  23. {
  24. foreach (var a in Attribute.GetCustomAttributes(monoScript.GetClass(), typeof(ScriptOrder)))
  25. {
  26. var currentOrder = MonoImporter.GetExecutionOrder(monoScript);
  27. var newOrder = ((ScriptOrder)a).order;
  28. if (currentOrder != newOrder)
  29. MonoImporter.SetExecutionOrder(monoScript, newOrder);
  30. }
  31. }
  32. }
  33. }
  34. }
  35. }