- Getting Start
- Project Settings
- Rich Text
- Cocos Creator
- Cry Engine
SDK - Unity
- Insert 3D
- Curved UI
FairyGUI uses the upper left corner of the screen as the origin, and Unity’s screen coordinates use the lower left corner as the origin. Generally, this conversion does not require developer intervention. If you really need to convert these two, you can use:
The x / y / position values in GObject are allLocal coordinates, Which is the offset from the parent component. GObject does not provide direct properties to obtain the global coordinates of the object, but provides methods to convert.
Please note: For an object, the origin of the local coordinates is (0,0), not (x, y), (x, y) is the coordinates of the parent component, not its own local coordinates.
If you want to get the coordinates of any UI element on the screen, you can use:
(Note that the screen mentioned here refers to the screen in FairyGUI semantics, with the upper left corner of the screen as the origin, not the screen in Unity semantics)
Conversely, if you want to get the local coordinates of the screen coordinates on the UI element, you can use:
If there is global scaling caused by UI adaptation, then the logical screen size is not the same as the physical screen size, and the coordinates of the logical screen are the coordinates in GRoot. If you want to convert local coordinates to logical screen coordinates, you can use:
Note that what we define in the editor and what is handled in the code generally refers to this logical screen coordinate.
If you want to transform the coordinates between any two UI objects, for example, you need to know the position of coordinate (10,10) in A in B, you can use:
If you want to convert the coordinates of the world space to the coordinates in the UI, you need to convert the coordinates of the world space to the screen coordinates first, and then continue to convert, for example:
If you want to convert the coordinates in the UI to the coordinates in the world space, you need to convert the coordinates in the UI to the screen coordinates before continuing the conversion, for example: