Esempio n. 1
0
 public static UnityUILogger Instance()
 {
     if (!Application.isPlaying)
     {
         return null;
     }
     if (UnityUILogger._instance == null)
     {
         GameObject consoleContainer = new GameObject();
         consoleContainer.name = "Console";
         DontDestroyOnLoad(consoleContainer);
         UnityUILogger._instance = consoleContainer.AddComponent<UnityUILogger>();
     }
     return UnityUILogger._instance;
 }
Esempio n. 2
0
    void Awake()
    {
        if (UnityUILogger._instance == null)
        {
            Application.RegisterLogCallback(HandleLog);

            UnityUILogger._instance = this;
            DontDestroyOnLoad(this.gameObject);
            _canvasBackgorund = new GameObject();
            _canvasBackgorund.AddComponent<Canvas>();
            _canvasBackgorund.GetComponent<Canvas>().renderMode = RenderMode.ScreenSpaceOverlay;
            _canvasBackgorund.transform.SetParent(this.gameObject.transform);
            _canvasBackgorund.name = "Console Canvas";
            _canvasBackgorund.AddComponent<GraphicRaycaster>();
            GameObject overlayPanel = new GameObject();
            overlayPanel.AddComponent<Image>();
            overlayPanel.transform.SetParent(_canvasBackgorund.transform);
            overlayPanel.GetComponent<RectTransform>().anchorMin = new Vector2(0,0);
            overlayPanel.GetComponent<RectTransform>().anchorMax = new Vector2(1,1);
            overlayPanel.GetComponent<RectTransform>().position = Vector3.zero;
            overlayPanel.GetComponent<RectTransform>().offsetMax = Vector2.zero;
            overlayPanel.GetComponent<RectTransform>().offsetMin = Vector2.zero;
            overlayPanel.GetComponent<Image>().color = new Color(0,0,0,0);
            overlayPanel.AddComponent<BoxCollider2D>().size = new Vector2(Screen.width, Screen.height);
            _logTypeColors = new Dictionary<LogType, Color>()
            {
                { LogType.Assert, AssertColor },
                { LogType.Error, ErrorColor },
                { LogType.Exception, ExeptionColor },
                { LogType.Log, LogColor },
                { LogType.Warning, WarningColor },
            };
            this.setGuiStyle();
        }
        else
        {
            Destroy(this.gameObject);
        }
    }