Unity 编辑器扩展,复制物体的Position和Roation

示例:
Unity 编辑器扩展,复制物体的Position和Roation_第1张图片
使用方法:将脚本放入Editor文件夹下,然后选中需要复制Position的物体,选择编辑器顶部的[复制坐标],需要粘贴的地方Ctrl+V即可

using UnityEditor;
using UnityEngine;

/// 
/// 放在Editor目录下
/// 选中物体之后,在扩展窗口选择复制的选项,就可以将选中的物体的transform信息位置复制下来,然后在要复制的地方Ctrl+V就可以复制出来
/// 
public class CopyObjTransformData : Editor
{
     
    /// 
    /// 复制Position
    /// 
    [UnityEditor.MenuItem("复制节点Transform信息/复制坐标")]
    static void CopyXYZ()
    {
     
        GameObject obj = UnityEditor.Selection.activeGameObject;
        if (obj != null)
        {
     
            string ret = obj.transform.localPosition.x + "f,"
                                                       + obj.transform.localPosition.y + "f,"
                                                       + obj.transform.localPosition.z + "f";
            GUIUtility.systemCopyBuffer = ret;
        }
    }

    /// 
    /// 复制Rotation
    /// 
    [UnityEditor.MenuItem("复制节点Transform信息/复制旋转")]
    static void CopyObjRotation()
    {
     
        GameObject obj = UnityEditor.Selection.activeGameObject;
        if (obj != null)
        {
     
            string ret = obj.transform.localEulerAngles.x + "f," + obj.transform.localEulerAngles.y + "f," +
                         obj.transform.localEulerAngles.z + "f";
            GUIUtility.systemCopyBuffer = ret;
        }
    }
}

你可能感兴趣的:(unity)