123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- using UnityEngine;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- public static class ExtensionTransform
- {
- 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 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<string, Transform> Compile(this Transform tra)
- {
- Dictionary<string, Transform> dic = new Dictionary<string, Transform>();
- Transform[] transforms = tra.GetComponentsInChildren<Transform>(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<string, Transform> Compile(this Transform tra, Dictionary<string, Transform> dic)
- {
- Transform[] transforms = tra.GetComponentsInChildren<Transform>(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;
- }
- }
|