using UnityEngine; using UnityEngine.UI; using NaughtyAttributes; using UnityEditor; public class AppLayer : MonoBehaviour { public int layer = 0; public bool active; public bool fullscreen; GameObject detectPanel; GameObject panel = null; public Sprite circleSprite; public Texture2D horizontalCursor; public Texture2D verticalCursor; public Texture2D diagonalCursor; private bool cursorsSet = false; public Vector2 lastOffsetMin = Vector2.zero; public Vector2 lastOffsetMax = Vector2.zero; public Vector2 appMinSize = new Vector2(200, 150); public Vector2 anchoredPosition = Vector2.zero; public Vector2 sizeDelta = Vector2.zero; public Color color = Color.black; public Sprite background; public Font font; public enum AppType { None, Calculator, Messenger, Notepad } [Header("Set Script")] public bool manualSet = false; [ShowIf(nameof(manualSet))] public AppType appType; [ShowIf(nameof(appType), AppType.Calculator)] public GameObject buttonPrefab; [ShowIf(nameof(appType), AppType.Messenger)] public GameObject buttonPrefab2; private void Awake() { if (!manualSet) appType = AppType.None; RectTransform rect = transform.GetComponent(); sizeDelta = rect.sizeDelta; anchoredPosition = rect.anchoredPosition; } void Start() { if (appType == AppType.Calculator) { if (GetComponentInChildren () == null) { GameObject panel = new GameObject( "Panel", typeof(RectTransform), typeof(CanvasRenderer), typeof(Image), typeof(SimpleCalculator) ); panel.transform.SetParent(transform, false); var Rect = panel.GetComponent(); Rect.anchorMin = Vector2.zero; Rect.anchorMax = Vector2.one; Rect.offsetMin = new Vector2(0, 0); Rect.offsetMax = new Vector2(0, -20); var calculator = panel.GetComponent(); calculator.appLayer = GetComponent(); calculator.buttonPrefab = buttonPrefab; calculator.font = font; var image = panel.GetComponent(); image.sprite = background; image.color = color; } } else if (appType == AppType.Messenger) { if (GetComponentInChildren() == null) { GameObject panel = new GameObject( "Panel", typeof(RectTransform), typeof(CanvasRenderer), typeof(Image), typeof(Messenger) ); panel.transform.SetParent(transform, false); var Rect = panel.GetComponent(); Rect.anchorMin = Vector2.zero; Rect.anchorMax = Vector2.one; Rect.offsetMin = new Vector2(0, 0); Rect.offsetMax = new Vector2(0, -20); var messenger = panel.GetComponent(); messenger.appLayer = GetComponent(); //messenger.buttonPrefab = buttonPrefab2; //messenger.font = font; var image = panel.GetComponent(); image.sprite = background; image.color = color; } } else if (appType == AppType.Notepad) { if (GetComponentInChildren() == null) { GameObject panel = new GameObject( "Panel", typeof(RectTransform), typeof(CanvasRenderer), typeof(Image), typeof(Notepad) ); panel.transform.SetParent(transform, false); var Rect = panel.GetComponent(); Rect.anchorMin = Vector2.zero; Rect.anchorMax = Vector2.one; Rect.offsetMin = new Vector2(0, 0); Rect.offsetMax = new Vector2(0, -20); var messenger = panel.GetComponent(); messenger.appLayer = GetComponent(); //messenger.buttonPrefab = buttonPrefab2; //messenger.font = font; var image = panel.GetComponent(); image.sprite = background; image.color = color; } } detectPanel = new GameObject("OverlayPanel", typeof(RectTransform), typeof(CanvasRenderer), typeof(Image), typeof(Button)); detectPanel.transform.SetParent(transform, false); RectTransform rect = detectPanel.GetComponent(); rect.anchorMin = new Vector2(0, 0); rect.anchorMax = new Vector2(1, 1); rect.offsetMin = Vector2.zero; rect.offsetMax = Vector2.zero; Image img = detectPanel.GetComponent(); img.color = new Color(0,0,0,0.001f); Button childButton = detectPanel.GetComponent