public static void GetLayout() { Dictionary <string, MyRectTransform> rectTransformDict = new Dictionary <string, MyRectTransform>(); RectTransform[] rectTransformArray = Selection.gameObjects[0].GetComponentsInChildren <RectTransform>(true); for (int i = 0; i < rectTransformArray.Length; i++) { if (rectTransformArray[i].name.Contains("FightFrame")) { continue; } MyRectTransform rect = new MyRectTransform(); rect.pivot = new MyVector2(rectTransformArray[i].pivot.x, rectTransformArray[i].pivot.y); rect.anchorMax = new MyVector2(rectTransformArray[i].anchorMax.x, rectTransformArray[i].anchorMax.y); rect.anchorMin = new MyVector2(rectTransformArray[i].anchorMin.x, rectTransformArray[i].anchorMin.y); rect.offsetMax = new MyVector2(rectTransformArray[i].offsetMax.x, rectTransformArray[i].offsetMax.y); rect.offsetMin = new MyVector2(rectTransformArray[i].offsetMin.x, rectTransformArray[i].offsetMin.y); rect.localEulerAngles = new MyVector3(rectTransformArray[i].localEulerAngles.x, rectTransformArray[i].localEulerAngles.y, rectTransformArray[i].localEulerAngles.z); rectTransformDict.Add(rectTransformArray[i].name, rect); } string path = Application.dataPath + "/Temp/Vertical/Left_Pad.txt"; LayoutDataWrapper wrapper = ConvertToDataWrapper(rectTransformDict); string toSave = JsonUtility.ToJson(wrapper); CommonTool.SetData(path, toSave); }
void Start() { canvas = GameObject.FindGameObjectWithTag("canvas").GetComponent <Canvas>(); rectTransform = GetComponent <RectTransform>(); btnRects = new List <RectTransform>(); initRects = new List <MyRectTransform>(); for (int i = 0; i < transform.childCount; i++) { if (transform.GetChild(i).GetComponent <Button>() != null) { RectTransform rectTrans = transform.GetChild(i).GetComponent <RectTransform>(); MyRectTransform rectTransInit = new MyRectTransform(); rectTransInit.localPosition = rectTrans.localPosition; rectTransInit.sizeDelta = rectTrans.sizeDelta; btnRects.Add(rectTrans); initRects.Add(rectTransInit); } } }