Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Reflection;
- using UnityEngine;
- public class InputBlocker : MonoBehaviour
- {
- private RectTransform rect;
- private BoxCollider blockCollider;
- private static GameObject devConsoleBlockerResource = null;
- private int framesEnabled = 0;
- // Start is called before the first frame update
- void Awake()
- {
- this.rect = this.GetComponent<RectTransform>();
- if (devConsoleBlockerResource == null)
- {
- devConsoleBlockerResource = Resources.Load<GameObject>("Prefabs/Gui/DevConsoleInputBlocker");
- }
- }
- private void OnEnable()
- {
- framesEnabled = 0;
- if (this.blockCollider == null)
- {
- GameObject blockObject = GameObject.Instantiate<GameObject>(devConsoleBlockerResource);
- blockObject.name = "ModInputBlocker";
- blockObject.layer = 9;
- try
- {
- blockObject.transform.SetParent(ServiceProvider.Instance.UserInterface.UIRootObject.transform);
- }
- catch
- {
- this.enabled = false;
- Debug.LogWarning("Mod could not parent input blocker. Clicks may go through the Mod UI.");
- }
- blockObject.transform.localPosition = Vector3.zero;
- blockObject.transform.localScale = Vector3.one;
- blockObject.transform.SetAsFirstSibling();
- blockObject.SetActive(true);
- this.blockCollider = blockObject.GetComponent<BoxCollider>();
- }
- this.blockCollider.gameObject.SetActive(true);
- }
- private void OnDisable()
- {
- if (this.blockCollider != null)
- {
- this.blockCollider.gameObject.SetActive(false);
- }
- }
- private void OnDestroy()
- {
- if (this.blockCollider != null)
- {
- GameObject.Destroy(this.blockCollider.gameObject);
- }
- }
- private static float? GameScale = null;
- private static PropertyInfo UiScale;
- private static object GameSettings;
- // Update is called once per frame
- void Update()
- {
- if (framesEnabled == 2)
- {
- Vector3[] array = new Vector3[4];
- this.rect.GetWorldCorners(array);
- Vector3 size = array[2] - array[0];
- Vector3 center = (array[0] + array[2]) / 2f;
- center -= new Vector3((float)Screen.width, (float)Screen.height) / 2f;
- size.z = 0f;
- if (GameSettings == null)
- {
- Type gameType = Type.GetType("Assets.Game.Game, Assembly-CSharp");
- object gameInstance = gameType.GetProperty("Instance").GetValue(null, null);
- GameSettings = gameType.GetProperty("Settings").GetValue(gameInstance);
- UiScale = GameSettings.GetType().GetProperty("UiScale");
- }
- GameScale = (float)UiScale.GetValue(GameSettings);
- if (GameScale.Value < 1)
- {
- size /= GameScale.Value;
- center /= GameScale.Value;
- }
- this.blockCollider.size = size;
- this.blockCollider.center = center;
- framesEnabled++;
- }
- else if (framesEnabled < 2)
- {
- framesEnabled++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment