UILogic

Provides UI related functions.

# Properties

[{"index":"int32 ScreenHeight (ReadOnly)","0":"Indicates the current screen height."}]

[{"index":"int32 ScreenWidth (ReadOnly)","0":"Indicates the current screen width."}]

# Methods

[{"index":"int32 GetSiblingIndex(UITransformComponent target) (ClientOnly)","0":"Checks the order of the child TransformComponents with the same parent when played."}]

[{"index":"Vector2 LocalUIToWorldPosition(Vector2 localUIPosition, UITransformComponent uiTransformComponent) (ClientOnly)","0":"Converts the UITransformComponent's UI coordinates based on pivot to World coordinates. Cannot use a UITransformComponent with its UIMode set as World."}]

[{"index":"Vector2 ScreenToLocalUIPosition(Vector2 screenPosition, UITransformComponent uiTransformComponent) (ClientOnly)","0":"Converts the UITransformComponent's UI coordinates based on pivot to World coordinates. Cannot use a UITransformComponent with its UIMode set as World."}]

[{"index":"Vector2 ScreenToUIPosition(Vector2 screenPosition) (ClientOnly)","0":"Converts Screen coordinates to UI coordinates. The UI coordinate's origin point is the pivot (Middle Center) of the top most UI."}]

[{"index":"Vector2 ScreenToWorldPosition(Vector2 screenPosition) (ClientOnly)","0":"Converts Screen coordinates into World coordinates."}]

[{"index":"void SetSiblingIndex(UITransformComponent target, int32 index) (ClientOnly)","0":"Changes the order of the child UITransformComponents with the same parent when played."}]

[{"index":"Vector2 UIToWorldPosition(Vector2 uiPosition) (ClientOnly)","0":"Converts UI coordinates to World coordinates. The UI coordinate's origin point is the pivot (Middle Center) of the top most UI."}]

[{"index":"Vector2 WorldToScreenPosition(Vector2 worldPosition) (ClientOnly)","0":"Converts World coordinates to Screen coordinates."}]

##### inherited from Logic:

[{"index":"EventHandlerBase ConnectEvent(string key, IScriptFunction eventHandler)","0":"Links events. When a key-type event occurs in this service, a handler is notified. The handler receives event parameters."}]

[{"index":"EventHandlerBase ConnectEvent(Type eventType, IScriptFunction eventHandler)","0":"Links events. This service notifies a handler when an eventType event occurs. The handler receives event parameters."}]

[{"index":"boolean DisconnectEvent(string key, EventHandlerBase eventHandler)","0":"Disconnects the key-type event and its handler."}]

[{"index":"boolean DisconnectEvent(Type eventType, EventHandlerBase eventHandler)","0":"Disconnects the eventType event from its handler."}]

[{"index":"boolean IsClient()","0":"Returns whether the current execution environment is a client or not."}]

[{"index":"boolean IsServer()","0":"Returns whether the current execution environment is a server or not."}]

[{"index":"void SendEvent(EventType sendEvent)","0":"Generates an event."}]

# Examples

#### ScreenToWorldPosition

The following is an example of teleporting the character to the location touched on the screen.
    
    
    @Component
    script ScreenTouchTeleporter extends Component
        @EventSender("Service", "InputService")
        handler HandleScreenTouchEvent(ScreenTouchEvent event)
        -- Parameters
        local TouchPoint = event.TouchPoint
        --------------------------------------------------------
    
        local worldPosition = _UILogic:ScreenToWorldPosition(TouchPoint)
        local me = _UserService.LocalPlayer
        local currentMapName = me.CurrentMapName
        local destinationPosition = Vector3(worldPosition.x, worldPosition.y, 0)
    
        _TeleportService:TeleportToMapPosition(me, destinationPosition, currentMapName)
        end
    end
    

#### ScreenToLocalUIPosition

This is an example of moving a specific UI entity to the location touched on the screen. The UI entity's Anchor Preset is Middle Center, and the UI entity is the Safe Area's child.
    
    
    @Component
    script UITouchFollower extends Component
        property any followingUI = nil
    
        @ExecSpace("ClientOnly")
        method void OnBeginPlay()
        self.followingUI = _EntityService:GetEntityByPath("/ui/UIGroup/UIEmpty").UITransformComponent
        end
    
        @EventSender("Service", "InputService")
        handler HandleScreenTouchEvent(ScreenTouchEvent event)
        --------------- Native Event Sender Info ----------------
        -- Sender: InputService
        -- Space: Client
        ---------------------------------------------------------
    
        -- Parameters
        -- local TouchId = event.TouchId
        local TouchPoint = event.TouchPoint
        ---------------------------------------------------------
    
        self.followingUI.anchoredPosition = _UILogic:ScreenToUIPosition(TouchPoint)
        end
    end
    

# SeeAlso

  * ScreenTouchEvent
  * Vector3
  * TeleportService
  * UserService