Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

detecting if a Element in a panel is visible or outside of the view

Discussion in 'Scripting' started by grka, Jan 3, 2016.

  1. grka

    grka

    Joined:
    Jan 14, 2015
    Posts:
    80
    I have one canvas Element (Screen Space - Overlay) which contains several panels. Each Panel contains a ListView element.

    Because gameObject.Find can't find inactive Objects I made a workaround and instead of deactivate my panel I just move it outside of the camera view when I "close" it. When I activate it then I move it to the middle of the screen at 0,0,0

    So far everything works fine but now I need to detect if my Panel is viewable right now or not. The easy way is:
    Code (CSharp):
    1. if (transform.parent.transform.localPosition.x == 0 && transform.parent.transform.localPosition.y == 0 && transform.parent.transform.localPosition.z == 0)
    2. {
    3.   // is visible
    4. }
    5. else
    6. {
    7.   // is not visible
    8. }
    But now my problem: I want to allow drag and drop of the ui dialog and then I need to know if my panel is within the viewable area or if it was moved aways because it was "closed"

    How Can I calculate the viewable edges from the camera when the center of the screen is 0,0,0?
     
  2. troyfury

    troyfury

    Joined:
    May 15, 2015
    Posts:
    19
    I think you might be looking to calculate the camera's frustum planes. This is the documentation http://docs.unity3d.com/ScriptReference/GeometryUtility.CalculateFrustumPlanes.html
     
  3. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    might be simpler to just not use Find and enable/disable as needed... why do you think you need to use find to access the panel?
     
  4. grka

    grka

    Joined:
    Jan 14, 2015
    Posts:
    80
    I need the find because some dynamical game objects are created during runtime and need access to the panel