unity编辑器Scene界面输出位置及路径

工程Asset下新建Editor文件夹;

Editor文件夹下新建脚本LogPosition

cs 复制代码
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
public class LogPosition : EditorWindow
{
    //最终输出的数据.
    static string logtext;
    //增加菜单栏选项
    [MenuItem("LOGPOSITION/LOG")]
    public static void OpenLoadLevel()
    {
        //重置数据
        logtext = "";
        //获取编辑器中当前选中的物体
        GameObject[] obj = Selection.gameObjects ;
        //如果没有选择任何物体,弹出提示并退出
        if (obj == null)
        {
            EditorUtility.DisplayDialog("ERROR", "No select obj!!", "ENTRY");
            return;
        }
        //遍历所有子物体,并记录数据
        // ForeachObjAndSave(obj[0]);
        logtext = "new Vector3(" + obj[0].transform.localPosition.x + "f" + "," + obj[0].transform.localPosition.y + "f" + "," + obj[0].transform.localPosition.z + "f" + ")" + "\n" +
             "new Vector3(" + obj[0].transform.localEulerAngles.x + "f" + "," + obj[0].transform.localEulerAngles.y + "f" + "," + obj[0].transform.localEulerAngles.z + "f" + ")" + "\n" +
             "path:" +OutputObjPath(obj[0].transform, obj[0].transform.name);          
        //}
        Debug.Log(logtext);
        复制到剪贴板  
        //TextEditor editor = new TextEditor();
        //editor.text  = new GUIContent(logtext);
        //editor.SelectAll();
        //editor.Copy();
    }
   static  string objPathEditor = "";
   static string OutputObjPath(Transform tar, string path)
    {
        if (tar.parent != null)
        {
            objPathEditor = tar.parent.name + "/" + path;
            OutputObjPath(tar.parent, objPathEditor);
        }
        return objPathEditor;
    }
    //遍历所有子物体
    static void ForeachObjAndSave(GameObject obj)
    {
        //foreach (Transform child in obj.transform)
        //{
        //    logtext += (child.localPosition.x + "," + child.localPosition.y + "," + child.localPosition.z + "\n");
        //}
    }
}

场景选择物体后,点击界面上方LOGPOSITION

引用原文链接:

unity编辑器中打印选中物体所有子物体的坐标并复制到剪贴板_unity打印物体x轴-CSDN博客

相关推荐
harrain3 小时前
拟合模型与虚幻引擎
游戏引擎·数字孪生·虚幻
相思难忘成疾8 小时前
RHEL9 文件管理与 vi/vim 编辑操作实验
linux·编辑器·vim
努力长头发的程序猿8 小时前
在Unity2d中,根据Y轴决定渲染顺序(URP项目适用)
unity
im_AMBER9 小时前
万字长文:编辑器集成Vercel AI SDK
前端·人工智能·react.js·前端框架·编辑器
DaLiangChen18 小时前
Unity 精准 Mesh 点击检测:穿透遮挡 + 单击双击识别
unity·游戏引擎
迪普阳光开朗很健康21 小时前
Unity中new() 和实例化有什么区别?
unity·游戏引擎
mxwin1 天前
Unity Shader 极坐标特效 从数学原理到实战案例
unity·游戏引擎·shader·uv
狂龙骄子1 天前
键盘布局编辑器Keyboard Layout Editor
编辑器·keyboard·layout editor·keyboard layout·键盘布局编辑器·键盘布局设计
zhensherlock1 天前
Protocol Launcher 系列:Trae AI 编辑器的深度集成
javascript·人工智能·vscode·ai·typescript·编辑器·ai编程
Never_Satisfied1 天前
将web服务绑定在 1024 以下的端口上
前端·编辑器·vim