using UnityEditor;
using UnityEngine;
//[CustomEditor(typeof(Test))]
public class Tools:Editor
{
[MenuItem("CONTEXT/Transform/拷贝信息")]
static void Test1( )
{
GameObject obj = Selection.activeGameObject;//obj代表当前选择的物体
Transform trans = obj.transform;//用临时变量trans储存obj的transform信息;
string str = trans.localPosition.x + "," + trans.localPosition.y + "," + trans.localPosition.z + "," + trans.localEulerAngles.x + "," + trans.localEulerAngles.y + "," + trans.localEulerAngles.z + "," + trans.localScale.x + "," + trans.localScale.y + "," + trans.localScale.z;
TextEditor te = new TextEditor();
te.content = new GUIContent(str);
te.SelectAll();
te.Copy();
}
}
举一反三,也可拷贝其他组件的其他信息,
从剪切板写入transform值
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Test : MonoBehaviour
{
public int a=10;
public Vector3 pos, rot;
}
using UnityEditor;
using UnityEngine;
//[CustomEditor(typeof(Test))]
public class Tools:Editor
{
static Test test;
[MenuItem("CONTEXT/Test/粘贴信息")]
static void Paste()
{
test = Selection.activeGameObject.GetComponent<Test>();
string str = GUIUtility.systemCopyBuffer;
string[] a = str.Split(',');
test.pos = new Vector3(float.Parse(a[0]), float.Parse(a[1]), float.Parse(a[2]));
test.rot = new Vector3(float.Parse(a[3]), float.Parse(a[4]), float.Parse(a[5]));
}
[MenuItem("CONTEXT/Transform/拷贝信息")]
static void Copy( )
{
GameObject obj = Selection.activeGameObject;//obj代表当前选择的物体
Transform trans = obj.transform;//用临时变量trans储存obj的transform信息;
string str = trans.localPosition.x + "," + trans.localPosition.y + "," + trans.localPosition.z + "," + trans.localEulerAngles.x + "," + trans.localEulerAngles.y + "," + trans.localEulerAngles.z + "," + trans.localScale.x + "," + trans.localScale.y + "," + trans.localScale.z;
TextEditor te = new TextEditor();
te.content = new GUIContent(str);
te.SelectAll();
te.Copy();
}
}