Jump to content

ScreenSafeUI???


Recommended Posts

Looking at code written for unity 4, trying to update it and of course knowing what it *was* would help that.

ScreenSafeUI.referenceCam specifically.

Edited by tg626
Link to comment
Share on other sites

That's most likely the viewpoint that all those UI elements were drawn for. I doubt you'll find an equivalent in the new UI since it doesn't use cameras to create unique UI layers, or atleast not externally

Edited by Crzyrndm
Link to comment
Share on other sites

6 hours ago, sarbian said:

Hum, the new UI does uses camera. Each Canvas has one.

But it hard to answer the question when you have so little info on what you want to do...


 
public void GetNavBallRect()
        {
            var navball = GameObject.FindObjectOfType<NavBall>();
 
            if (navball == null)
            {
                Deb.Err("GetNavBallArea: no navball object found");
            }
 
            Deb.Log("Navball game object: {0}", navball);
            Deb.Log("Navball transform: {0}", navball.transform.localToWorldMatrix);
            Deb.Log("Navball transform.position: {0}", navball.transform.position);
 
            // position is (1.0,0.1,0.0) when visible
            // position is (1.0,-0.1,0.0) when not visible
            var camera = ScreenSafeUI.referenceCam;
 
            // this looks to be the center of the ball with Y counting up from bottom of screen
            // so 800,85 for 1600x1200 screen.
            Vector3 center = camera.WorldToScreenPoint(navball.transform.position);
            Deb.Log("Navball center in screen point: {0}", center);
 
            // cannot figure out how to get actual size. Just assume that since we have the center
            // and the Y is offset from 0 the size is about twice that.
            // the 200 and 223 come from measuring this in a 1600x1200 frame
            float height = (float)center.y * (200.0f / 85.6f);
            float width = (float)center.y * (223.0f / 85.6f);
 
            // this does not work; maybe only valid inside GUI draw calls
            // Vector2 guiCenter = GUIUtility.ScreenToGUIPoint(new Vector2(center.x, center.y));
 
            // Just assume as is the case currently with unity that the Y reverses direction
            navBallRect =
                new Rect(center.x - width / 2, Screen.height - height, width, height);
 
            Deb.Log("Navball Rect calculated to be: {0}", navBallRect);
        }
Link to comment
Share on other sites

Ok, so the camera you need should be UIMasterController.Instance.appCanvas.worldCamera and I you ll need to call RectTransformUtility.WorldToScreenPoint()

But if the whole mod was made for the old UI I have a strong feeling that getting the new pos will be the least of your problem.

Link to comment
Share on other sites

Actually popping a return at the start if the function puts it in the upper left corner.  As a stop gap I added gui.dragable (or whatever it's called, I'm on my phone...) I was able to simply click and drag it where I wanted. 

I'll have a look at what you suggested tho thanks a ton!!!

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...