UnityEngine.Camera.ScreenToWorldPoint C# (CSharp) Method

ScreenToWorldPoint() public method

Transforms position from screen space into world space.

public ScreenToWorldPoint ( Vector3 position ) : Vector3
position Vector3
return Vector3
        public Vector3 ScreenToWorldPoint(Vector3 position)
        {
            Vector3 vector;
            INTERNAL_CALL_ScreenToWorldPoint(this, ref position, out vector);
            return vector;
        }

Usage Example

コード例 #1
0
 protected override JobHandle OnUpdate(JobHandle inputDependencies)
 {
     if (!camera)
     {
         camera = UnityEngine.Camera.main;
     }
     if (!camera)
     {
         return(inputDependencies);
     }
     if (!EntityManager.Exists(draggedEntity))
     {
         dragging = false;
     }
     if (UnityEngine.Input.GetMouseButton(0) && !dragging)
     {
         var results = new NativeArray <RaycastHit>(1, Allocator.TempJob);
         new MouseRaycastJob {
             CollisionWorld = buildPhysicsSystem.PhysicsWorld.CollisionWorld,
             RaycastInput   = new RaycastInput {
                 Ray    = new Ray(camera.ScreenToWorldPoint(UnityEngine.Input.mousePosition).withZ(-25), new float3(0, 0, 100)),
                 Filter = new CollisionFilter {
                     MaskBits = 1 << 0, CategoryBits = ~0u
                 },
             },
             Results = results,
         }.Schedule(JobHandle.CombineDependencies(buildPhysicsSystem.FinalJobHandle, inputDependencies)).Complete();
         if (results[0].Fraction > 0 && results[0].RigidBodyIndex >= 0 && results[0].RigidBodyIndex < buildPhysicsSystem.PhysicsWorld.CollisionWorld.Bodies.Length)
         {
             draggedEntity = buildPhysicsSystem.PhysicsWorld.CollisionWorld.Bodies[results[0].RigidBodyIndex].Entity;
             if (EntityManager.Exists(draggedEntity))
             {
                 EntityManager.AddComponentData(draggedEntity, new ForceToPosition {
                     SpeedModifier = 10
                 });
                 dragging = true;
                 OnDragStart(draggedEntity, this);
             }
         }
         results.Dispose();
     }
     else if (UnityEngine.Input.GetMouseButton(0))
     {
         var c = EntityManager.GetComponentData <ForceToPosition>(draggedEntity);
         c.Position = camera.ScreenToWorldPoint(UnityEngine.Input.mousePosition).withZ(0); // force to Z 0
         EntityManager.SetComponentData(draggedEntity, c);
     }
     else if (dragging)
     {
         EntityManager.RemoveComponent <ForceToPosition>(draggedEntity);
         dragging = false;
         OnDragEnd(draggedEntity, this);
     }
     return(inputDependencies);
 }
All Usage Examples Of UnityEngine.Camera::ScreenToWorldPoint
Camera