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

相关推荐
maply4 小时前
VSCode 中的 Git Graph扩展使用详解
ide·git·vscode·编辑器·扩展
花花鱼4 小时前
vscode script 中间的function import等关键字 先高亮,然后又灰了,并且按ctrl+/ 注释以html的形式,导致报错处理
ide·vscode·编辑器
Dr.勿忘6 小时前
C#面试常考随笔8:using关键字有哪些用法?
开发语言·unity·面试·c#·游戏引擎
存储服务专家StorageExpert7 小时前
答疑解惑:如何监控EMC unity存储系统磁盘重构rebuild进度
运维·unity·存储维护·emc存储
Petrichorzncu9 小时前
Games104——游戏引擎Gameplay玩法系统:基础AI
游戏引擎
浅陌sss10 小时前
PhotoShop中JSX编辑器安装
编辑器
夏尔Gaesar10 小时前
Vim安装与配置教程(解决软件包Vim没有安装可候选)
linux·编辑器·vim
追逐梦想永不停13 小时前
Unity实现按键设置功能代码
unity
ue星空16 小时前
UE编辑器工具
编辑器
千航@abc1 天前
vim多文件操作如何同屏开多个文件
linux·编辑器·vim