154 lines
4.5 KiB
C#
154 lines
4.5 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
|
|
public class CopyTrans : EditorWindow
|
|
{
|
|
|
|
|
|
static List<GameObject> ObjList = new List<GameObject>();
|
|
static List<GameObject> pastObjList = new List<GameObject>();
|
|
|
|
static List<GameObject> twoSelectObj = new List<GameObject>();
|
|
|
|
|
|
static GameObject obj3 = null;
|
|
|
|
static GameObject obj4 = null;
|
|
|
|
[MenuItem("Window/CopyTrans Window")]
|
|
static void Init()
|
|
{
|
|
//CopyTrans copyTransWindow =(CopyTrans)EditorWindow.GetWindow(typeof(CopyTrans));
|
|
EditorWindow window = EditorWindow.GetWindow(typeof(CopyTrans),true,"CopyTrans");
|
|
window.Show();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnGUI()
|
|
{
|
|
//obj1 =(GameObject) EditorGUILayout.ObjectField("物体一", obj1,typeof(GameObject),true);
|
|
//obj2 =(GameObject)EditorGUILayout.ObjectField("物体二", obj2, typeof(GameObject), true);
|
|
|
|
obj3 = (GameObject)EditorGUILayout.ObjectField("物体一", obj3, typeof(GameObject), true);
|
|
obj4 = (GameObject)EditorGUILayout.ObjectField("物体二", obj4, typeof(GameObject), true);
|
|
|
|
if (GUILayout.Button("SingleCopy",GUILayout.Height(150
|
|
)))
|
|
{
|
|
if (Selection.gameObjects.Length == 2)
|
|
{
|
|
obj3 = Selection.gameObjects[0];
|
|
obj4 = Selection.gameObjects[1];
|
|
}
|
|
|
|
obj3 = (GameObject)EditorGUILayout.ObjectField("物体一", obj3, typeof(GameObject), true);
|
|
obj4 = (GameObject)EditorGUILayout.ObjectField("物体二", obj4, typeof(GameObject), true);
|
|
|
|
if (obj3 != null && obj4 != null)
|
|
{
|
|
obj4.transform.position = obj3.transform.position;
|
|
obj4.transform.rotation = obj3.transform.rotation;
|
|
}
|
|
}
|
|
|
|
//obj3= (GameObject)EditorGUILayout.ObjectField("物体一", obj3, typeof(GameObject), true);
|
|
//obj4= (GameObject)EditorGUILayout.ObjectField("物体二", obj4, typeof(GameObject), true);
|
|
|
|
//if (GUILayout.Button("确定两个物体"))
|
|
//{
|
|
// if (Selection.gameObjects.Length == 2)
|
|
// {
|
|
// obj3 = Selection.gameObjects[0];
|
|
// obj4 = Selection.gameObjects[1];
|
|
// }
|
|
//}
|
|
|
|
//if (GUILayout.Button("替换两个物体"))
|
|
//{
|
|
// GameObject temp = null;
|
|
// temp = obj3;
|
|
// obj3 = obj4;
|
|
// obj4 = temp;
|
|
//}
|
|
|
|
|
|
|
|
//if (GUILayout.Button("CopyGameobjects"))
|
|
//{
|
|
// if (ObjList != null)
|
|
// {
|
|
// if (Selection.gameObjects.Length > 0)
|
|
// {
|
|
// ObjList.Clear();
|
|
// for (int i = 0; i < Selection.gameObjects.Length; i++)
|
|
// {
|
|
// ObjList.Add(Selection.gameObjects[i]);
|
|
// Debug.Log(i);
|
|
// }
|
|
// }
|
|
// }
|
|
//}
|
|
|
|
//if (GUILayout.Button("PastGameObjects"))
|
|
//{
|
|
// if (pastObjList != null)
|
|
// {
|
|
// if (Selection.gameObjects.Length > 0)
|
|
// {
|
|
// pastObjList.Clear();
|
|
// for (int i = 0; i < Selection.gameObjects.Length; i++)
|
|
// {
|
|
// pastObjList.Add(Selection.gameObjects[i]);
|
|
// Debug.Log(i);
|
|
// }
|
|
// }
|
|
// }
|
|
//}
|
|
|
|
//if (GUILayout.Button("AllCopy"))
|
|
//{
|
|
// for (int i = 0; i < ObjList.Count; i++)
|
|
// {
|
|
// for (int j = 0; j < pastObjList.Count; j++)
|
|
// {
|
|
// if (string.Equals(ObjList[i].name + "_past", pastObjList[j].name))
|
|
// {
|
|
// pastObjList[j].transform.position = ObjList[i].transform.position;
|
|
// pastObjList[j].transform.rotation = ObjList[i].transform.rotation;
|
|
// continue;
|
|
// }
|
|
// }
|
|
// }
|
|
//}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//[MenuItem("CopyTrans/CopyTrans")]
|
|
//static void CopyTransform()
|
|
//{
|
|
// //obj1 = Selection.activeGameObject;
|
|
// //Debug.Log(obj1.name);
|
|
|
|
// // Selection.gameObjects.Length;
|
|
// for (int i = 0; i < Selection.gameObjects.Length; i++)
|
|
// {
|
|
// ObjList.Add(Selection.gameObjects[i]);
|
|
// Debug.Log(i);
|
|
// }
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|