Skip to content

Instantly share code, notes, and snippets.

@maikelcoke
Last active May 8, 2018 11:53
Show Gist options
  • Save maikelcoke/21d28ab1d46efee5f125fe5357e4597a to your computer and use it in GitHub Desktop.
Save maikelcoke/21d28ab1d46efee5f125fe5357e4597a to your computer and use it in GitHub Desktop.
UIWindowHelper: Focus Window on title click
Create new UIWindowHelper.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UIWindowHelper : MonoBehaviour {
public static void bringToFront(Transform window)
{
RectTransform theRectTransform = window.transform as RectTransform; // Cast it to RectTransform
theRectTransform.SetAsLastSibling(); // Make the panel show on top.
}
}
Open UIWindow.cs
a) Add "IPointerClickHandler" Interface to the class definition
b) Add "UIWindowHelper.bringToFront(transform.parent.transform.parent);" in OnBeginDrag() method before HandleDrag method
c) Add new method:
public void OnPointerClick(PointerEventData d)
{
UIWindowHelper.bringToFront(transform.parent.transform.parent);
}
Now, if you click a window title, it will come to front. Easy and fast.
Tipp: Add this method if ummorpg opens a window to bring it to the front (see UIShortcuts.cs).
@maikelcoke
Copy link
Author

For some UI (like NPCTRading) you have to rearrange the UI in the Inspector. It will be used a parent container like in Inventory. This is "Inventory -> InventoryPanel", but in some UI it is only "NpcTrading", so that the code "transform.parent.transform.parent" does not work. But i think you get the idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment