开始是直接赋值 运行后发现坐标和描点全部错误
unity 提示:
Parent of RectTransform is being set with parent property. Consider using the SetParent method instead, with the worldPositionStays argument set to false. This will retain local orientation and scale rather than world orientation and scale, which can prevent common UI scaling issues.
正确应该使用 transform.Setparent(transform , bool) 第二个参数是是否继承世界坐标 加载UI的 perfab时设为false 就不会错乱
GameObject perfab = (GameObject)Resources.Load("Prefabs/"+pname);
perfab = Instantiate(perfab);
perfab.transform.SetParent(parent.transform,false);
//perfab.transform.parent = parent.transform;
//RectTransform rtf = perfab.GetComponent<RectTransform>();
//rtf.offsetMin = Vector2.zero;
//rtf.offsetMax = Vector2.zero;
return perfab;