Beispiel #1
0
        //we always adjust position in order to keep the camera in scene.The sceneBorder should always be non-null.
        void AdjustPos()
        {
            var border    = CamUtility.BoundToRect(sceneBorder.bounds);
            var camBorder = CamUtility.GetCamViewRect(cam);

            var y_diff = 0f;
            var x_diff = 0f;

            if (camBorder.yMax < border.yMin)
            {
                y_diff = border.yMin - camBorder.yMax;
            }
            else if (camBorder.yMin > border.yMax)
            {
                y_diff = border.yMax - camBorder.yMin;
            }

            if (camBorder.xMin < border.xMin)
            {
                x_diff = border.xMin - camBorder.xMin;
            }
            else if (camBorder.xMax > border.xMax)
            {
                x_diff = border.xMax - camBorder.xMax;
            }


            var mov_vec = new Vector3(x_diff, y_diff, 0);

            this.cam.transform.Translate(mov_vec);
        }
Beispiel #2
0
 //三元逻辑
 public bool?BirdWithinScene()
 {
     if (birdUnderWatch != null)
     {
         var sceneBound = sceneBorder.bounds;
         var scenceRect = CamUtility.BoundToRect(sceneBound);
         var birdPos    = new Vector2(
             birdUnderWatch.transform.position.x,
             birdUnderWatch.transform.position.y
             );
         //if the bird goes out of scene or it just reached some low speed, stop watch
         return(scenceRect.Contains(birdPos) && birdUnderWatch.GetComponent <Rigidbody2D>().velocity.magnitude >= deadSpeed);
     }
     else
     {
         return(new bool?());
     }
 }