Beispiel #1
0
        public void Hide()
        {
            Destroy(gameObject);

            var blocker = OpenTibiaUnity.GameManager.ActiveBlocker;

            blocker.gameObject.SetActive(false);

            var buttonComponent = blocker.GetComponent <UnityUI.Button>();

            if (buttonComponent)
            {
                OpenTibiaUnity.GameManager.InvokeOnMainThread(() => Destroy(buttonComponent));
            }

            CurrentContextMenu = null;
        }
Beispiel #2
0
        public void Display(Vector3 position)
        {
            if (CurrentContextMenu != null)
            {
                CurrentContextMenu.Hide();
                CurrentContextMenu = null;
            }

            // add options
            try
            {
                InitialiseOptions();
            }
            catch (System.Exception)
            {
                return;
            }

            var blocker = OpenTibiaUnity.GameManager.ActiveBlocker;

            blocker.transform.SetAsLastSibling();
            blocker.gameObject.SetActive(true);

            var buttonComponent = blocker.GetComponent <UnityUI.Button>();

            if (buttonComponent)
            {
                Destroy(buttonComponent);
            }

            buttonComponent = blocker.gameObject.AddComponent <UnityUI.Button>();
            buttonComponent.onClick.AddListener(OnMouseHide);

            // todo replace this with expected values when adding options
            // instead of rebuilding twice
            UnityUI.LayoutRebuilder.ForceRebuildLayoutImmediate(rectTransform);
            position.x = Mathf.Min(position.x, Screen.width - rectTransform.rect.width);
            position.y = Mathf.Min(position.y, Screen.height - rectTransform.rect.height);
            rectTransform.anchorMin        = new Vector2(0, 1);
            rectTransform.anchorMax        = new Vector2(0, 1);
            rectTransform.pivot            = new Vector2(0, 1);
            rectTransform.anchoredPosition = new Vector3(position.x, -position.y, 0);

            CurrentContextMenu = this;
        }