CopyTransform

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
(C# - CopyTransform.cs)
Line 20: Line 20:
 
         private static Vector3 position;
 
         private static Vector3 position;
 
         private static Quaternion rotation;
 
         private static Quaternion rotation;
         private static Vector3 scale;
+
         private static Vector3 scale;
 +
        private static string myName;
 
      
 
      
     [MenuItem ("Custom/Transform Copier/Copy Selected Transform")]
+
     [MenuItem ("Custom/Transform Copier/Copy Transform")]
 
     static void DoRecord()
 
     static void DoRecord()
 
     {
 
     {
     
 
 
       position = Selection.activeTransform.localPosition;
 
       position = Selection.activeTransform.localPosition;
 
       rotation = Selection.activeTransform.localRotation;
 
       rotation = Selection.activeTransform.localRotation;
       scale = Selection.activeTransform.localScale;       
+
       scale = Selection.activeTransform.localScale;
 +
      myName = Selection.activeTransform.name;       
 
          
 
          
         EditorUtility.DisplayDialog("Transform Copier Copy", "Local position, rotation, and scale copied relative to parent.", "OK", "");
+
         EditorUtility.DisplayDialog("Transform Copy", "Local position, rotation, & scale of "+myName +" copied relative to parent.", "OK", "");
 
     }
 
     }
 
   
 
   
Line 36: Line 37:
 
     static void DoApply()
 
     static void DoApply()
 
     {
 
     {
        Selection.activeTransform.localPosition = position;
+
        Selection.activeTransform.localPosition = position;
 
         Selection.activeTransform.localRotation = rotation;
 
         Selection.activeTransform.localRotation = rotation;
         Selection.activeTransform.localScale = scale;      
+
         Selection.activeTransform.localScale = scale;    
 
+
 
          
 
          
         EditorUtility.DisplayDialog("Transform Copier Paste", "Local position, rototation, and scale pasted relative to parent.", "OK", "");
+
         EditorUtility.DisplayDialog("Transform Paste", "Local position, rotation, and scale of "+myName +"  pasted relative to parent of "+Selection.activeTransform.name+".", "OK", "");
 
     }
 
     }
 
}
 
}

Revision as of 04:39, 20 October 2006

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.

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