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博客

相关推荐
Python私教1 小时前
Unity 游戏开发「工业化级」学习路线 2025 版
学习·unity·游戏引擎
于小汐在咯6 小时前
【Unity每日一记】Unity物理引擎:刚体与碰撞体详解
unity·游戏引擎
哲此一生9847 小时前
Vscode中选择Conda环境
ide·vscode·编辑器
朱嘉鼎10 小时前
VSCode + Copilot
ide·vscode·编辑器
鱼蛋-Felix10 小时前
Unity jar更新不生效怎么解决
unity·游戏引擎·jar
我是苹果,不是香蕉12 小时前
vscode使用verilog format插件教程
ide·vscode·编辑器
爱吃小胖橘1 天前
Unity资源加载模块全解析
开发语言·unity·c#·游戏引擎
井队Tell1 天前
打造高清3D虚拟世界|零基础学习Unity HDRP高清渲染管线(第九天)
学习·3d·unity
.NET修仙日记1 天前
Visual Studio 演进之路:从集成套件到AI驱动的开发平台
ide·编辑器·ai编程·visual studio·1024程序员节
white-persist1 天前
Linux中,vi(vim)编辑器大部分快捷键
linux·运维·服务器·网络·安全·编辑器·vim