您的位置:首页 > 移动开发 > Unity3D

unity编辑器中打印选中物体所有子物体的坐标并复制到剪贴板

2018-01-31 16:41 731 查看
从前公司有个同事提了个标题中描述的需求,顺手做了下,分享出来也许其他人也能用上。

代码很简单,看注释即可

public class LogPosition : EditorWindow {

//最终输出的数据
static string logtext;

//增加菜单栏选项
[MenuItem("LOGPOSITION/LOG")]
public static void OpenLoadLevel(){
//重置数据
logtext = "";
//获取编辑器中当前选中的物体
GameObject obj = Selection.activeGameObject;

//如果没有选择任何物体,弹出提示并退出
if(obj == null){
EditorUtility.DisplayDialog("ERROR", "No select obj!!", "ENTRY");
return;
}

//遍历所有子物体,并记录数据
ForeachObjAndSave(obj);
Debug.Log(logtext);

//复制到剪贴板
TextEditor editor = new TextEditor();
editor.content = new GUIContent(logtext);
editor.SelectAll();
editor.Copy();
}

//遍历所有子物体
static void ForeachObjAndSave(GameObject obj){
foreach (Transform child in obj.transform)
{
logtext+= (child.localPosition.x + "," + child.localPosition.y + "," + child.localPosition.z + "\n");
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  unity 编辑器