Advertisement
glados123123123123

Untitled

Dec 25th, 2023
1,160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.09 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEditor;
  3.  
  4. public class PositionRotationTransferTool : EditorWindow
  5. {
  6.     GameObject sourceObject;
  7.     Item targetItem;
  8.  
  9.     [MenuItem("Tools/PositionRotationTransferTool")]
  10.     public static void ShowWindow()
  11.     {
  12.         GetWindow<PositionRotationTransferTool>("Position Rotation Transfer Tool");
  13.     }
  14.  
  15.     private void OnGUI()
  16.     {
  17.         sourceObject = (GameObject)EditorGUILayout.ObjectField("Source Object", sourceObject, typeof(GameObject), true);
  18.         targetItem = (Item)EditorGUILayout.ObjectField("Target Item", targetItem, typeof(Item), false);
  19.  
  20.         if (GUILayout.Button("Transfer Position and Rotation"))
  21.         {
  22.             if (sourceObject != null && targetItem != null)
  23.             {
  24.                 Undo.RecordObject(targetItem, "Transfer Position and Rotation");
  25.                 targetItem.positionOffset = sourceObject.transform.localPosition;
  26.                 targetItem.rotationOffset = sourceObject.transform.localRotation.eulerAngles;
  27.                 EditorUtility.SetDirty(targetItem);
  28.             }
  29.         }
  30.     }
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement