ExtensionTransform.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 void SetLocalScaleX(this Transform tra, float x)
  57. {
  58. tra.localScale = new Vector3(x, tra.localScale.y, tra.localScale.z);
  59. }
  60. public static Vector3 GetScale(this Transform tra)
  61. {
  62. Vector3 scale = tra.localScale;
  63. while (tra.parent != null)
  64. {
  65. float x = scale.x * tra.parent.localScale.x;
  66. float y = scale.y * tra.parent.localScale.y;
  67. float z = scale.z * tra.parent.localScale.z;
  68. scale = new Vector3(x, y, z);
  69. tra = tra.parent;
  70. }
  71. return scale;
  72. }
  73. public static Component AddComponent(this Transform tra, Type type)
  74. {
  75. return tra.gameObject.AddComponent(type);
  76. }
  77. public static Dictionary<string, Transform> Compile(this Transform tra)
  78. {
  79. Dictionary<string, Transform> dic = new Dictionary<string, Transform>();
  80. Transform[] transforms = tra.GetComponentsInChildren<Transform>(true);
  81. for (int i = 0; i < transforms.Length; i++)
  82. {
  83. if (dic.ContainsKey(transforms[i].name))
  84. {
  85. throw new Exception(transforms[i].name);
  86. }
  87. else
  88. {
  89. dic.Add(transforms[i].name, transforms[i]);
  90. }
  91. }
  92. return dic;
  93. }
  94. public static Dictionary<string, Transform> Compile(this Transform tra, Dictionary<string, Transform> dic)
  95. {
  96. Transform[] transforms = tra.GetComponentsInChildren<Transform>(true);
  97. for (int i = 0; i < transforms.Length; i++)
  98. {
  99. if (dic.ContainsKey(transforms[i].name))
  100. {
  101. throw new Exception(transforms[i].name);
  102. }
  103. else
  104. {
  105. dic.Add(transforms[i].name, transforms[i]);
  106. }
  107. }
  108. return dic;
  109. }
  110. }