ExtensionTransform.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. using UnityEngine;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. public static class ExtensionTransform
  6. {
  7. public static void SetLZ(this DragonBones.Slot slot, float z)
  8. {
  9. if (slot.childArmature!=null)
  10. {
  11. slot.childArmature.UnityTransform.SetLZ(z);
  12. //Debug.Log(slot.childArmature.UnityTransform.name);
  13. }
  14. else
  15. {
  16. slot.UnityTransform.SetLZ(z);
  17. //Debug.Log(slot.UnityTransform.name);
  18. }
  19. }
  20. public static void SetX(this Transform tra, float x)
  21. {
  22. tra.position = new Vector3(x, tra.position.y, tra.position.z);
  23. }
  24. public static void SetY(this Transform tra, float y)
  25. {
  26. tra.position = new Vector3(tra.position.x, y, tra.position.z);
  27. }
  28. public static void SetZ(this Transform tra, float z)
  29. {
  30. tra.position = new Vector3(tra.position.x, tra.position.y, z);
  31. }
  32. public static void SetLX(this Transform tra, float x)
  33. {
  34. tra.localPosition = new Vector3(x, tra.localPosition.y, tra.localPosition.z);
  35. }
  36. public static void SetLY(this Transform tra, float y)
  37. {
  38. tra.localPosition = new Vector3(tra.localPosition.x, y, tra.localPosition.z);
  39. }
  40. public static void SetLZ(this Transform tra, float z)
  41. {
  42. tra.localPosition = new Vector3(tra.localPosition.x, tra.localPosition.y, z);
  43. }
  44. public static void SetEX(this Transform tra, float x)
  45. {
  46. tra.eulerAngles = new Vector3(x, tra.eulerAngles.y, tra.eulerAngles.z);
  47. }
  48. public static void SetEY(this Transform tra, float y)
  49. {
  50. tra.eulerAngles = new Vector3(tra.eulerAngles.x, y, tra.eulerAngles.z);
  51. }
  52. public static void SetEZ(this Transform tra, float z)
  53. {
  54. tra.eulerAngles = new Vector3(tra.eulerAngles.x, tra.eulerAngles.y, z);
  55. }
  56. public static Vector3 GetScale(this Transform tra)
  57. {
  58. Vector3 scale = tra.localScale;
  59. while (tra.parent != null)
  60. {
  61. float x = scale.x * tra.parent.localScale.x;
  62. float y = scale.y * tra.parent.localScale.y;
  63. float z = scale.z * tra.parent.localScale.z;
  64. scale = new Vector3(x, y, z);
  65. tra = tra.parent;
  66. }
  67. return scale;
  68. }
  69. public static Component AddComponent(this Transform tra, Type type)
  70. {
  71. return tra.gameObject.AddComponent(type);
  72. }
  73. public static Dictionary<string, Transform> Compile(this Transform tra)
  74. {
  75. Dictionary<string, Transform> dic = new Dictionary<string, Transform>();
  76. Transform[] transforms = tra.GetComponentsInChildren<Transform>(true);
  77. for (int i = 0; i < transforms.Length; i++)
  78. {
  79. if (dic.ContainsKey(transforms[i].name))
  80. {
  81. throw new Exception(transforms[i].name);
  82. }
  83. else
  84. {
  85. dic.Add(transforms[i].name, transforms[i]);
  86. }
  87. }
  88. return dic;
  89. }
  90. public static Dictionary<string, Transform> Compile(this Transform tra, Dictionary<string, Transform> dic)
  91. {
  92. Transform[] transforms = tra.GetComponentsInChildren<Transform>(true);
  93. for (int i = 0; i < transforms.Length; i++)
  94. {
  95. if (dic.ContainsKey(transforms[i].name))
  96. {
  97. throw new Exception(transforms[i].name);
  98. }
  99. else
  100. {
  101. dic.Add(transforms[i].name, transforms[i]);
  102. }
  103. }
  104. return dic;
  105. }
  106. }