using UnityEngine; using System; using System.Collections; using System.Collections.Generic; public static class ExtensionTransform { public static void SetLZ(this DragonBones.Slot slot, float z) { if (slot.childArmature!=null) { slot.childArmature.UnityTransform.SetLZ(z); //Debug.Log(slot.childArmature.UnityTransform.name); } else { slot.UnityTransform.SetLZ(z); //Debug.Log(slot.UnityTransform.name); } } public static void SetX(this Transform tra, float x) { tra.position = new Vector3(x, tra.position.y, tra.position.z); } public static void SetY(this Transform tra, float y) { tra.position = new Vector3(tra.position.x, y, tra.position.z); } public static void SetZ(this Transform tra, float z) { tra.position = new Vector3(tra.position.x, tra.position.y, z); } public static void SetLX(this Transform tra, float x) { tra.localPosition = new Vector3(x, tra.localPosition.y, tra.localPosition.z); } public static void SetLY(this Transform tra, float y) { tra.localPosition = new Vector3(tra.localPosition.x, y, tra.localPosition.z); } public static void SetLZ(this Transform tra, float z) { tra.localPosition = new Vector3(tra.localPosition.x, tra.localPosition.y, z); } public static void SetEX(this Transform tra, float x) { tra.eulerAngles = new Vector3(x, tra.eulerAngles.y, tra.eulerAngles.z); } public static void SetEY(this Transform tra, float y) { tra.eulerAngles = new Vector3(tra.eulerAngles.x, y, tra.eulerAngles.z); } public static void SetEZ(this Transform tra, float z) { tra.eulerAngles = new Vector3(tra.eulerAngles.x, tra.eulerAngles.y, z); } public static void SetLocalScaleX(this Transform tra, float x) { tra.localScale = new Vector3(x, tra.localScale.y, tra.localScale.z); } public static Vector3 GetScale(this Transform tra) { Vector3 scale = tra.localScale; while (tra.parent != null) { float x = scale.x * tra.parent.localScale.x; float y = scale.y * tra.parent.localScale.y; float z = scale.z * tra.parent.localScale.z; scale = new Vector3(x, y, z); tra = tra.parent; } return scale; } public static Component AddComponent(this Transform tra, Type type) { return tra.gameObject.AddComponent(type); } public static Dictionary Compile(this Transform tra) { Dictionary dic = new Dictionary(); Transform[] transforms = tra.GetComponentsInChildren(true); for (int i = 0; i < transforms.Length; i++) { if (dic.ContainsKey(transforms[i].name)) { throw new Exception(transforms[i].name); } else { dic.Add(transforms[i].name, transforms[i]); } } return dic; } public static Dictionary Compile(this Transform tra, Dictionary dic) { Transform[] transforms = tra.GetComponentsInChildren(true); for (int i = 0; i < transforms.Length; i++) { if (dic.ContainsKey(transforms[i].name)) { throw new Exception(transforms[i].name); } else { dic.Add(transforms[i].name, transforms[i]); } } return dic; } }