private void InitLayoutData() { string pad = IsPad ? "_Pad" : ""; string data = CommonTool.GetDataFromResources("Layout/Vertical/Right" + pad); LayoutDataWrapper wrapper = JsonUtility.FromJson <LayoutDataWrapper>(data); Dictionary <string, MyRectTransform> vertical_Right = ConvertToDict(wrapper); data = CommonTool.GetDataFromResources("Layout/Vertical/Left" + pad); wrapper = JsonUtility.FromJson <LayoutDataWrapper>(data); Dictionary <string, MyRectTransform> vertical_Left = ConvertToDict(wrapper); data = CommonTool.GetDataFromResources("Layout/Horizontal/Right" + pad); wrapper = JsonUtility.FromJson <LayoutDataWrapper>(data); Dictionary <string, MyRectTransform> horizontal_Right = ConvertToDict(wrapper); data = CommonTool.GetDataFromResources("Layout/Horizontal/Left" + pad); wrapper = JsonUtility.FromJson <LayoutDataWrapper>(data); Dictionary <string, MyRectTransform> horizontal_Left = ConvertToDict(wrapper); layoutAssetDict.Add(LayoutID.Vertical, new List <Dictionary <string, MyRectTransform> > { vertical_Right, vertical_Left }); layoutAssetDict.Add(LayoutID.Horizontal, new List <Dictionary <string, MyRectTransform> > { horizontal_Right, horizontal_Left }); }
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); }
private static LayoutDataWrapper ConvertToDataWrapper(Dictionary <string, MyRectTransform> rectTransformDict) { LayoutDataWrapper wrapper = new LayoutDataWrapper(); wrapper.names.AddRange(rectTransformDict.Keys); wrapper.transforms.AddRange(rectTransformDict.Values); return(wrapper); }
private Dictionary <string, MyRectTransform> ConvertToDict(LayoutDataWrapper wrapper) { Dictionary <string, MyRectTransform> dict = new Dictionary <string, MyRectTransform>(); for (int i = 0; i < Mathf.Min(wrapper.names.Count, wrapper.transforms.Count); i++) { dict[wrapper.names[i]] = wrapper.transforms[i]; } return(dict); }