Skip to content

Commit

Permalink
Fix Clone / Paste when viewer scale changes
Browse files Browse the repository at this point in the history
  • Loading branch information
amirebrahimi committed Jun 2, 2017
1 parent 1c3324e commit f9be5c2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Actions/Clone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace UnityEditor.Experimental.EditorVR.Actions
{
[ActionMenuItem("Clone", ActionMenuItemAttribute.DefaultActionSectionName, 3)]
sealed class Clone : BaseAction, IUsesSpatialHash
sealed class Clone : BaseAction, IUsesSpatialHash, IUsesViewerScale
{
public override void ExecuteAction()
{
Expand All @@ -21,7 +21,7 @@ public override void ExecuteAction()
var cloneTransform = clone.transform;
var cameraTransform = CameraUtils.GetMainCamera().transform;
var viewDirection = cloneTransform.position - cameraTransform.position;
cloneTransform.position = cameraTransform.TransformPoint(Vector3.forward * viewDirection.magnitude)
cloneTransform.position = cameraTransform.TransformPoint(Vector3.forward * viewDirection.magnitude / this.GetViewerScale())
+ cloneTransform.position - bounds.center;
this.AddToSpatialHash(clone);
clones[index++] = clone;
Expand Down
5 changes: 3 additions & 2 deletions Actions/Paste.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace UnityEditor.Experimental.EditorVR.Actions
{
[ActionMenuItem("Paste", ActionMenuItemAttribute.DefaultActionSectionName, 6)]
sealed class Paste : BaseAction, IUsesSpatialHash
sealed class Paste : BaseAction, IUsesSpatialHash, IUsesViewerScale
{
public static Transform[] buffer
{
Expand All @@ -22,7 +22,8 @@ public static Transform[] buffer
{
var bounds = ObjectUtils.GetBounds(value);

s_BufferDistance = bounds.size == Vector3.zero ? (bounds.center - CameraUtils.GetMainCamera().transform.position).magnitude : 0f;
s_BufferDistance = bounds.size != Vector3.zero ? (bounds.center - CameraUtils.GetMainCamera().transform.position).magnitude : 0f;
s_BufferDistance /= IUsesViewerScaleMethods.getViewerScale(); // Normalize this value, so if viewer scale changes when pasted
}
}
}
Expand Down

0 comments on commit f9be5c2

Please sign in to comment.