コード例 #1
0
 public ObjectGrabSettings()
 {
     for (int index = 0; index < _layerGrabSettings.Length; ++index)
     {
         _layerGrabSettings[index] = new ObjectLayerGrabSettings(index);
     }
 }
コード例 #2
0
        private void RotateTargetsAroundAnchor()
        {
            IInputDevice inputDevice = RTInputDevice.Get.Device;

            if (!inputDevice.WasMoved())
            {
                return;
            }

            float rotationAmount = inputDevice.GetFrameDelta().x *SharedSettings.RotationSensitivity;

            foreach (GrabTarget grabTarget in _grabTargets)
            {
                if (grabTarget == null)
                {
                    continue;
                }

                ObjectLayerGrabSettings layerGrabSettings = SharedSettings.GetLayerGrabSettings(grabTarget.GameObject.layer);
                if (layerGrabSettings.IsActive)
                {
                    if (layerGrabSettings.AlignAxis)
                    {
                        Quaternion rotation = Quaternion.AngleAxis(rotationAmount, _grabSurfaceInfo.AnchorNormal);
                        grabTarget.Transform.RotateAroundPivot(rotation, _grabSurfaceInfo.AnchorPoint);
                        grabTarget.AnchorVector = rotation * grabTarget.AnchorVector;
                    }
                    else
                    {
                        Quaternion rotation = Quaternion.AngleAxis(rotationAmount, Vector3.up);
                        grabTarget.Transform.RotateAroundPivot(rotation, _grabSurfaceInfo.AnchorPoint);
                        grabTarget.AnchorVector = rotation * grabTarget.AnchorVector;
                    }
                }
                else
                {
                    if (SharedSettings.AlignAxis)
                    {
                        Quaternion rotation = Quaternion.AngleAxis(rotationAmount, _grabSurfaceInfo.AnchorNormal);
                        grabTarget.Transform.RotateAroundPivot(rotation, _grabSurfaceInfo.AnchorPoint);
                        grabTarget.AnchorVector = rotation * grabTarget.AnchorVector;
                    }
                    else
                    {
                        Quaternion rotation = Quaternion.AngleAxis(rotationAmount, Vector3.up);
                        grabTarget.Transform.RotateAroundPivot(rotation, _grabSurfaceInfo.AnchorPoint);
                        grabTarget.AnchorVector = rotation * grabTarget.AnchorVector;
                    }
                }
            }

            SnapTargetsToSurface();
        }
コード例 #3
0
        private void OffsetTargetsFromSurface()
        {
            IInputDevice inputDevice = RTInputDevice.Get.Device;

            if (!inputDevice.WasMoved())
            {
                return;
            }

            float offsetAmount = inputDevice.GetFrameDelta().x *SharedSettings.OffsetFromSurfaceSensitivity;

            foreach (GrabTarget grabTarget in _grabTargets)
            {
                if (grabTarget == null)
                {
                    continue;
                }

                ObjectLayerGrabSettings layerGrabSettings = SharedSettings.GetLayerGrabSettings(grabTarget.GameObject.layer);
                if (layerGrabSettings.IsActive)
                {
                    if (layerGrabSettings.AlignAxis)
                    {
                        grabTarget.Transform.position += grabTarget.SittingPlane.normal * offsetAmount;
                        grabTarget.OffsetFromSurface  += offsetAmount;
                    }
                    else
                    {
                        grabTarget.Transform.position += Vector3.up * offsetAmount;
                        grabTarget.OffsetFromSurface  += offsetAmount;
                    }
                }
                else
                {
                    if (SharedSettings.AlignAxis)
                    {
                        grabTarget.Transform.position += grabTarget.SittingPlane.normal * offsetAmount;
                        grabTarget.OffsetFromSurface  += offsetAmount;
                    }
                    else
                    {
                        grabTarget.Transform.position += Vector3.up * offsetAmount;
                        grabTarget.OffsetFromSurface  += offsetAmount;
                    }
                }
            }

            CalculateGrabTargetsAnchorVectors();
        }
コード例 #4
0
        private void RotateTargets()
        {
            IInputDevice inputDevice = RTInputDevice.Get.Device;

            if (!inputDevice.WasMoved())
            {
                return;
            }

            float rotationAmount = inputDevice.GetFrameDelta().x *SharedSettings.RotationSensitivity;

            foreach (GrabTarget grabTarget in _grabTargets)
            {
                if (grabTarget == null)
                {
                    continue;
                }

                ObjectLayerGrabSettings layerGrabSettings = SharedSettings.GetLayerGrabSettings(grabTarget.GameObject.layer);
                if (layerGrabSettings.IsActive)
                {
                    if (layerGrabSettings.AlignAxis)
                    {
                        grabTarget.Transform.Rotate(grabTarget.SittingPlane.normal, rotationAmount, Space.World);
                    }
                    else
                    {
                        grabTarget.Transform.Rotate(Vector3.up, rotationAmount, Space.World);
                    }
                }
                else
                {
                    if (SharedSettings.AlignAxis)
                    {
                        grabTarget.Transform.Rotate(grabTarget.SittingPlane.normal, rotationAmount, Space.World);
                    }
                    else
                    {
                        grabTarget.Transform.Rotate(Vector3.up, rotationAmount, Space.World);
                    }
                }
            }

            CalculateGrabTargetsAnchorVectors();
        }
コード例 #5
0
        private void SnapTargetsToSurface()
        {
            if (_grabSurfaceInfo.SurfaceType == GrabSurfaceType.Invalid)
            {
                return;
            }

            ObjectSurfaceSnap.SnapConfig snapConfig = new ObjectSurfaceSnap.SnapConfig();
            snapConfig.SurfaceHitPoint  = _grabSurfaceInfo.AnchorPoint;
            snapConfig.SurfaceHitNormal = _grabSurfaceInfo.AnchorNormal;
            snapConfig.SurfaceHitPlane  = _grabSurfaceInfo.AnchorPlane;
            snapConfig.SurfaceObject    = _grabSurfaceInfo.SceneRaycastHit.WasAnObjectHit ? _grabSurfaceInfo.SceneRaycastHit.ObjectHit.HitObject : null;

            snapConfig.SurfaceType = ObjectSurfaceSnap.Type.UnityTerrain;
            if (_grabSurfaceInfo.SurfaceType == GrabSurfaceType.Mesh)
            {
                snapConfig.SurfaceType = ObjectSurfaceSnap.Type.Mesh;
            }
            else if (_grabSurfaceInfo.SurfaceType == GrabSurfaceType.Grid)
            {
                snapConfig.SurfaceType = ObjectSurfaceSnap.Type.SceneGrid;
            }
            else if (_grabSurfaceInfo.SurfaceType == GrabSurfaceType.SphericalMesh)
            {
                snapConfig.SurfaceType = ObjectSurfaceSnap.Type.SphericalMesh;
            }
            else if (_grabSurfaceInfo.SurfaceType == GrabSurfaceType.TerrainMesh)
            {
                snapConfig.SurfaceType = ObjectSurfaceSnap.Type.TerrainMesh;
            }

            foreach (GrabTarget grabTarget in _grabTargets)
            {
                if (grabTarget.GameObject == null)
                {
                    continue;
                }
                grabTarget.Transform.position = _grabSurfaceInfo.AnchorPoint + grabTarget.AnchorVector;

                ObjectLayerGrabSettings layerGrabSettings = SharedSettings.GetLayerGrabSettings(grabTarget.GameObject.layer);
                if (layerGrabSettings.IsActive)
                {
                    snapConfig.AlignAxis         = layerGrabSettings.AlignAxis;
                    snapConfig.AlignmentAxis     = layerGrabSettings.AlignmentAxis;
                    snapConfig.OffsetFromSurface = layerGrabSettings.DefaultOffsetFromSurface + grabTarget.OffsetFromSurface;
                }
                else
                {
                    snapConfig.AlignAxis         = SharedSettings.AlignAxis;
                    snapConfig.AlignmentAxis     = SharedSettings.AlignmentAxis;
                    snapConfig.OffsetFromSurface = SharedSettings.DefaultOffsetFromSurface + grabTarget.OffsetFromSurface;
                }

                ObjectSurfaceSnap.SnapResult snapResult = ObjectSurfaceSnap.SnapHierarchy(grabTarget.GameObject, snapConfig);
                if (snapResult.Success)
                {
                    grabTarget.SittingPlane = snapResult.SittingPlane;
                    grabTarget.SittingPoint = snapResult.SittingPoint;
                }
            }
        }