IsVisibleFrom() public static method

Is the renderer bounds visible from given Camera.
public static IsVisibleFrom ( this renderer, Camera camera ) : bool
renderer this
camera Camera
return bool
Exemplo n.º 1
0
    IEnumerator LoopNodeFindingDelay()
    {
        while (true)
        {
            if (currentNodeRen == null)
            {
                yield return(new WaitForSecondsRealtime(1f));

                continue;
            }

            if (!RendererExtensions.IsVisibleFrom(currentNodeRen, cam))
            {
                Debug.Log("current node is not on cam");
                calculateNodeSide();
            }
            else             //if node is on screen turn off the UI
            {
                turnLeftUI.transform.DOScale(0, 0.25f);
                turnRightUI.transform.DOScale(0, 0.25f);
                distanceLeft  = 0;
                distanceRight = 0;
            }
            yield return(new WaitForSecondsRealtime(1f));
        }
    }
Exemplo n.º 2
0
 private void Update()
 {
     if (!RendererExtensions.IsVisibleFrom(gameObject.GetComponentInChildren <Renderer>(), main) && transform.position.x < spawnEndLocation.position.x)
     {
         transform.position = new Vector3(spawnLocation.position.x, Random.Range((float)spawnLocation.position.y - 1.0f, (float)spawnLocation.position.y + 1.0f), spawnLocation.position.z);
     }
 }
Exemplo n.º 3
0
    // After all actions the object takes, we face the billboard
    void LateUpdate()
    {
        if (renderer && !RendererExtensions.IsVisibleFrom(renderer, referenceCamera))
        {
            return;
        }
        if (Flip)
        {
            targetPos = transform.position + referenceCamera.transform.rotation * Vector3.back;
        }
        else
        {
            targetPos = transform.position + referenceCamera.transform.rotation * Vector3.forward;
        }

        // Ignore camera Y position to stay upright
        if (LockY)
        {
            targetPos.y = transform.position.y;
        }

        transform.LookAt(targetPos);                    // Inefficient, slowdowns with massive billboards
        if (Rotate90)
        {
            transform.Rotate(Vector3.left, 90F);
        }
    }
Exemplo n.º 4
0
    void Update()
    {
        bool isInsideCamera = RendererExtensions.IsVisibleFrom(this.GetComponent <SpriteRenderer>(), mainCamera);

        if (!isInsideCamera)
        {
            Destroy(this.gameObject);
        }
    }
Exemplo n.º 5
0
    void Update()
    {
        bool isInsideCamera = RendererExtensions.IsVisibleFrom(this.GetComponent <SpriteRenderer>(), Camera.main);

        if (isInsideCamera && isInvincible)
        {
            isInvincible = false;
        }
    }
Exemplo n.º 6
0
 // Update is called once per frame.
 void Update()
 {
     // Check if this object (corpse) is being renderer by Camera.
     if (RendererExtensions.IsVisibleFrom(_renderer, Camera.main))
     {
         if (!_hasSpawn)
         {
             _spawnController.SpawnRat(SpawnPoints);
             _hasSpawn = true;
         }
     }
 }
Exemplo n.º 7
0
 public void checkVisibility()
 {
     isVisible = RendererExtensions.IsVisibleFrom(sprite, cam);
     if (isVisible && !lastVisible)
     {
         GameManager.Instance.currentFight.onPlayerInsideCamera(player);
     }
     if (!isVisible && lastVisible)
     {
         GameManager.Instance.currentFight.onPlayerOutOfCamera(player);
     }
     lastVisible = isVisible;
 }
Exemplo n.º 8
0
    /**
     * Checks every fixed update if the spawner is visible from the main camera.
     * If it is then an invoke repeating is executed only once on the Spawn enemy
     * function.
     *
     * If it is not then the invoke is cancelled.
     *
     * Prevents the world from being stuffed with enemies that aren't in the game's view.
     *
     */
    private void FixedUpdate()
    {
        if (RendererExtensions.IsVisibleFrom(gameObject.GetComponent <SpriteRenderer>(), Camera.main))
        {
            if (IsInvoking("SpawnEnemy"))
            {
                return;
            }

            InvokeRepeating("SpawnEnemy", 0.5f, 0.25f);
        }
        else
        {
            CancelInvoke("SpawnEnemy");
        }
    }
Exemplo n.º 9
0
    void Update()
    {
        if (transform.position.x < spawnEndLocation.position.x || transform.position.x > spawnEndLocation.position.x + 50)
        {
            if (!RendererExtensions.IsVisibleFrom(gameObject.GetComponentInChildren <Renderer>(), main))
            {
                transform.position = new Vector3(spawnLocation.position.x, Random.Range((float)spawnLocation.position.y - 1.0f, (float)spawnLocation.position.y + 1.0f), spawnLocation.position.z);
                rb.velocity        = Vector3.zero;
            }
        }


        //if (RendererExtensions.IsVisibleFrom(GetComponentInChildren<Renderer>() , Camera.main))
        // {
#if UNITY_EDITOR
        //SimulateMouseSwipe();
#endif

#if UNITY_ANDROID || UNITY_IOS
        if (Input.touchCount == 1)
        {
            //_rb.gravityScale = 0;
            Touch touch = Input.GetTouch(0);
            if (touch.phase == TouchPhase.Began)
            {
                Ray ray = Camera.main.ScreenPointToRay(new Vector3(touch.position.x, touch.position.y, 0));
                //Debug.Log(ray);
                Vector2 pos = Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position);
                //Debug.Log("touch pos " + pos);
                //Collider2D[] overlap = Physics2D.OverlapPointAll(pos);

                RaycastHit2D raycastHit = Physics2D.Raycast(pos, Input.GetTouch(0).position, 100f);

                if (raycastHit)
                {
                    //Debug.Log("Something Hit");
                    //Debug.Log(raycastHit.collider.name);
                    if (raycastHit.collider.CompareTag("EnemyCollider") || raycastHit.collider.CompareTag("Enemy"))
                    {
                        //Debug.Log("Enemy hit");
                        hit = true;
                        rb  = raycastHit.transform.gameObject.GetComponentInParent <Rigidbody2D>();
                        //Debug.Log("name" + rb.name);
                    }
                }

                _startTimer  = true;
                _elapsedTime = 0f;
            }

            if (touch.phase == TouchPhase.Ended && _elapsedTime < MAX_SWIPE_TIME && hit)
            {
                //Debug.Log("swipe");
                //Debug.Log("name" + rb.name);
                Swipe(touch.deltaPosition, rb);
                SoundManager.instance.PlaySingleSound(enemySnd, SoundManager.instance.sfxVolume);
            }
            //}
#endif

        if (_startTimer)
        {
            if (_elapsedTime < MAX_SWIPE_TIME)
            {
                _elapsedTime += Time.deltaTime;
            }

            if (_elapsedTime >= MAX_SWIPE_TIME)
            {
                _startTimer = false;
            }
        }
    }
Exemplo n.º 10
0
    void Update()
    {
        if (Time.timeScale == 1)
        {
            if (rb2d.velocity.y < 0)
            {
                // a heavier gravity when landing the jump to create a more crisp jump
                rb2d.velocity += Vector2.up * Physics2D.gravity.y * rb2d.gravityScale * (gravityMult - 1) * Time.deltaTime;
            }

            if (!RendererExtensions.IsVisibleFrom(gameObject.GetComponent <Renderer>(), main))
            {
                GameOver();
            }

            scoreText.text = score.ToString();


            if (score > GameManager.instance.highscore)
            {
                GameManager.instance.highscore = score;
                highscoreText.text             = score.ToString();
            }


            isGrounded = Physics2D.IsTouchingLayers(col2d, ground);


#if UNITY_IOS || UNITY_ANDROID
            if (isGrounded)
            {
                rb2d.velocity = new Vector2(0, rb2d.velocity.y);
                if (Input.touchCount == 1)
                {
                    Touch touch = Input.GetTouch(0);

                    if (touch.phase == TouchPhase.Began)
                    {
                        Ray ray = Camera.main.ScreenPointToRay(new Vector3(touch.position.x, touch.position.y, 0));

                        Vector2 pos = Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position);

                        RaycastHit2D raycastHit = Physics2D.Raycast(pos, Input.GetTouch(0).position, 100f);

                        // as long as player is not hitting enemy, jump
                        // jump is much smoother this way, otherwise waiting till TouchPhase.end has a slight lag in jumping
                        if (!(raycastHit && raycastHit.collider.CompareTag("EnemyCollider")))
                        {
                            if (Input.GetTouch(0).tapCount == 1)
                            {
                                rb2d.gravityScale = gravityScale;

                                rb2d.velocity = new Vector2(2f, jumpSpeed);


                                PlaySoundEffect(jumpSnd, SoundManager.instance.sfxVolume);
                                anim.SetTrigger("Jump");
                            }
                        }
                        _startTimer  = true;
                        _elapsedTime = 0f;
                    }
                }


                if (_startTimer)
                {
                    if (_elapsedTime < MAX_TAP_TIME)
                    {
                        _elapsedTime += Time.deltaTime;
                    }

                    if (_elapsedTime >= MAX_TAP_TIME)
                    {
                        _startTimer = false;
                    }
                }
            }
#endif
        }
    }
Exemplo n.º 11
0
    void Update()
    {
        // Movement
        Vector3 movement = new Vector3(
            speed.x * direction.x,
            speed.y * direction.y,
            0);

        movement *= Time.deltaTime;
        transform.Translate(movement);

        // Move the camera
        if (isLinkedToCamera)
        {
            Camera.main.transform.Translate(movement);
        }

        // Loop
        if (isLooping)
        {
            //---------------------------------------------------------------------------------
            // 2 - Check if the object is before, in or after the camera bounds
            //---------------------------------------------------------------------------------

            // Camera borders
            var   dist         = (transform.position - Camera.main.transform.position).z;
            float leftBorder   = Camera.main.ViewportToWorldPoint(new Vector3(0, 0, dist)).x;
            float rightBorder  = Camera.main.ViewportToWorldPoint(new Vector3(1, 0, dist)).x;
            float width        = Mathf.Abs(rightBorder - leftBorder);
            var   topBorder    = Camera.main.ViewportToWorldPoint(new Vector3(0, 0, dist)).y;
            var   bottomBorder = Camera.main.ViewportToWorldPoint(new Vector3(0, 1, dist)).y;
            float height       = Mathf.Abs(topBorder - bottomBorder);

            // Determine entry and exit border using direction
            Vector3 exitBorder  = Vector3.zero;
            Vector3 entryBorder = Vector3.zero;

            if (direction.x < 0)
            {
                exitBorder.x  = leftBorder;
                entryBorder.x = rightBorder;
            }
            else if (direction.x > 0)
            {
                exitBorder.x  = rightBorder;
                entryBorder.x = leftBorder;
            }

            if (direction.y < 0)
            {
                exitBorder.y  = bottomBorder;
                entryBorder.y = topBorder;
            }
            else if (direction.y > 0)
            {
                exitBorder.y  = topBorder;
                entryBorder.y = bottomBorder;
            }

            // Get the first object
            Transform firstChild = backgroundPart.FirstOrDefault();

            if (firstChild != null)
            {
                bool checkVisible = false;

                // Check if we are after the camera
                // The check is on the position first as IsVisibleFrom is a heavy method
                // Here again, we check the border depending on the direction
                if (direction.x != 0)
                {
                    if ((direction.x < 0 && (firstChild.position.x < exitBorder.x)) ||
                        (direction.x > 0 && (firstChild.position.x > exitBorder.x)))
                    {
                        checkVisible = true;
                    }
                }
                if (direction.y != 0)
                {
                    if ((direction.y < 0 && (firstChild.position.y < exitBorder.y)) ||
                        (direction.y > 0 && (firstChild.position.y > exitBorder.y)))
                    {
                        checkVisible = true;
                    }
                }

                // Check if the sprite is really visible on the camera or not
                if (checkVisible)
                {
                    //---------------------------------------------------------------------------------
                    // 3 - The object was in the camera bounds but isn't anymore.
                    // -- We need to recycle it
                    // -- That means he was the first, he's now the last
                    // -- And we physically moves him to the further position possible
                    //---------------------------------------------------------------------------------

                    //if (firstChild.renderer.isvi(Camera.main) == false)
                    if (RendererExtensions.IsVisibleFrom(firstChild.renderer, Camera.main) == false)
                    {
                        // Set position in the end
                        firstChild.position = new Vector3(
                            firstChild.position.x + ((repeatableSize.x + firstChild.renderer.bounds.size.x) * -1 * direction.x),
                            firstChild.position.y + ((repeatableSize.y + firstChild.renderer.bounds.size.y) * -1 * direction.y),
                            firstChild.position.z
                            );

                        // The first part become the last one
                        backgroundPart.Remove(firstChild);
                        backgroundPart.Add(firstChild);
                    }
                }
            }
        }
    }