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

相关推荐
mxwin28 分钟前
Unity Shader URP:法线如何进行光照计算
unity·游戏引擎·shader
郝学胜-神的一滴1 小时前
中级OpenGL教程 009:用环境光告别模型死黑
前端·c++·unity·godot·图形渲染·opengl·unreal
c238561 小时前
Vim 高阶实操技巧篇
linux·编辑器·vim
c238561 小时前
Vim 零基础核心基础篇
linux·编辑器·vim
zyplayer-doc2 小时前
新增AI智能助手菜单,支持PostgreSQL数据库,开放文档增加搜索选项,zyplayer-doc 2.6.4 发布啦!
人工智能·编辑器·创业创新
芋头莎莎3 小时前
window 右键菜单添加 vscode
ide·vscode·编辑器
王cb3 小时前
visual studio 编辑器 卡钝解决方法
ide·编辑器·visual studio
一锅炖出任易仙3 小时前
创梦汤锅学习日记day30
学习·ai·ue5·游戏引擎
yeflx4 小时前
vscode-server下载异常导致远程连接失败解决方法
ide·vscode·编辑器
mxwin12 小时前
Unity URP 中的法线生成完全指南
unity·游戏引擎