CopyTransform

From Unify Community Wiki
Revision as of 05:07, 20 October 2006 by DocSWAB (Talk | contribs)

Jump to: navigation, search

Author: Steve Allison-Bunnell (with thanks to aarku)

Description

Allows you to copy the local position, rotation, and scale of the currently selected object in the scene. Then you can paste this transform information into another object. Useful for positioning new prefabs in the location of a different prefab if you want to swap them.

Usage

You must place the script in a folder named Editor in your project's Assets folder for it to work properly.

Select an object in the scene heirarchy, then choose Transform Copier -> Copy Transform. This copies the local position, rotation, and scale of the selected object. Then select another object and choose Transform Copier -> Paste Transform. This will apply the copied transform to the new object. Both objects must either be at the root of the scene heirarchy or within the same parent for the transform to be applied properly.

Zipped file: TransformCopier.cs.zip

C# - CopyTransform.cs

<csharp> using UnityEngine; using UnityEditor; using System.Collections;

public class TransformCopier : ScriptableObject {

       private static Vector3 position;
       private static Quaternion rotation;
       private static Vector3 scale;
       private static string myName; 
   
   [MenuItem ("Custom/Transform Copier/Copy Transform")]
   static void DoRecord()
   {
      position = Selection.activeTransform.localPosition;
      rotation = Selection.activeTransform.localRotation;
      scale = Selection.activeTransform.localScale;
      myName = Selection.activeTransform.name;       
       
       EditorUtility.DisplayDialog("Transform Copy", "Local position, rotation, & scale of "+myName +" copied relative to parent.", "OK", "");
   }

   [MenuItem ("Custom/Transform Copier/Paste Transform")]
   static void DoApply()
   {
       Selection.activeTransform.localPosition = position;
       Selection.activeTransform.localRotation = rotation;
       Selection.activeTransform.localScale = scale;      
       
       EditorUtility.DisplayDialog("Transform Paste", "Local position, rotation, and scale of "+myName +"  pasted relative to parent of "+Selection.activeTransform.name+".", "OK", "");
   }

} </csharp>

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox