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

相关推荐
wulaladamowang11 小时前
日常踩雷系列-vscode无法输入中文
ide·vscode·编辑器
心疼你的一切15 小时前
使用Unity引擎开发Rokid主机应用的模型交互操作
游戏·ui·unity·c#·游戏引擎·交互
淡海水16 小时前
【URP】Unity[内置Shader]光照着色器Lit
unity·游戏引擎·shader·urp·着色器·lit
爱吃小胖橘17 小时前
Lua语法(2)
开发语言·unity·lua
徐归阳20 小时前
DevEco Studio安装
编辑器·harmonyos
心疼你的一切21 小时前
使用Unity引擎开发Rokid主机应用的全面配置交互操作
学习·游戏·unity·c#·游戏引擎·交互
HBR666_21 小时前
AI编辑器(FIM补全,AI扩写)简介
前端·ai·编辑器·fim·tiptap
夫唯不争,故无尤也1 天前
安装好vscode后,缺少vscode打开文件或文件夹选项
ide·vscode·编辑器
‍。。。1 天前
vscode 一键导出导入所有插件
ide·vscode·编辑器
qq_428639612 天前
虚幻基础:角色受击
游戏引擎·虚幻