/// <summary> /// 重置 /// </summary> /// <param name="transform"></param> public static void Reset(Transform transform, TransformMode transformMode = TransformMode.localPosition | TransformMode.localRotation | TransformMode.localScale) { if (transformMode.Contains(TransformMode.localPosition)) { transform.localPosition = Vector3.zero; } if (transformMode.Contains(TransformMode.localRotation)) { transform.localRotation = Quaternion.identity; } if (transformMode.Contains(TransformMode.localScale)) { transform.localScale = Vector3.one; } if (transformMode.Contains(TransformMode.position)) { transform.position = Vector3.zero; } if (transformMode.Contains(TransformMode.rotation)) { transform.rotation = Quaternion.identity; } }
public static void CopyTo(this Transform self, Transform traget_transform, TransformMode transformMode = TransformMode.localPosition | TransformMode.localRotation | TransformMode.localScale) { if (transformMode.Contains(TransformMode.position)) { traget_transform.position = self.position; } if (transformMode.Contains(TransformMode.localPosition)) { traget_transform.localPosition = self.localPosition; } if (transformMode.Contains(TransformMode.rotation)) { traget_transform.rotation = self.rotation; } if (transformMode.Contains(TransformMode.localRotation)) { traget_transform.localRotation = self.localRotation; } if (transformMode.Contains(TransformMode.scale)) { traget_transform.SetLossyScale(self.lossyScale); } if (transformMode.Contains(TransformMode.localScale)) { traget_transform.localScale = self.localScale; } //有rect的,rect也一起copy if (self.GetComponent <RectTransform>() != null && traget_transform.GetComponent <RectTransform>() != null) { traget_transform.GetComponent <RectTransform>().CopyFrom(self.GetComponent <RectTransform>()); } }