CurvedUIScriptOrder.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using UnityEditor;
  2. namespace CurvedUI
  3. {
  4. /// <summary>
  5. /// This class changes the Execution Order of Scripts in CurvedUI package.
  6. /// Some of them must be executed before or after default time to work properly.
  7. /// </summary>
  8. [InitializeOnLoad]
  9. public class CurvedUIScriptOrder : Editor
  10. {
  11. static CurvedUIScriptOrder()
  12. {
  13. ChangeScriptOrder(typeof(CurvedUITMP).Name, 100, OrderMatch.GREATER_THAN);
  14. }
  15. static void ChangeScriptOrder(string scriptName, int order, OrderMatch match = OrderMatch.EXACT)
  16. {
  17. // Iterate through all scripts (Might be a better way to do this?)
  18. foreach (MonoScript monoScript in MonoImporter.GetAllRuntimeMonoScripts())
  19. {
  20. // If found our script
  21. if (monoScript.name == scriptName)
  22. {
  23. if(match == OrderMatch.EXACT)
  24. {
  25. // And it's not at the execution time we want already
  26. if (MonoImporter.GetExecutionOrder(monoScript) != order)
  27. {
  28. MonoImporter.SetExecutionOrder(monoScript, order);
  29. }
  30. break;
  31. }
  32. if (match == OrderMatch.LESSER_THAN)
  33. {
  34. // And it's not at the execution time we want already
  35. if (MonoImporter.GetExecutionOrder(monoScript) > order)
  36. {
  37. MonoImporter.SetExecutionOrder(monoScript, order);
  38. }
  39. break;
  40. }
  41. if (match == OrderMatch.GREATER_THAN)
  42. {
  43. // And it's not at the execution time we want already
  44. if (MonoImporter.GetExecutionOrder(monoScript) < order)
  45. {
  46. MonoImporter.SetExecutionOrder(monoScript, order);
  47. }
  48. break;
  49. }
  50. }
  51. }
  52. }
  53. enum OrderMatch
  54. {
  55. EXACT = 0,
  56. GREATER_THAN = 1,
  57. LESSER_THAN = 2,
  58. }
  59. }
  60. }