![Image](https://i.goopics.net/X1YRp.jpg)
Grâce à Application.logMessageReceived, il est possible d'afficher directement les sorties console dans la fenêtre Game en mode Play.
Exemple simple d'utilisation:
Code : Tout sélectionner
using UnityEngine;
public class TestLog : MonoBehaviour
{
private string tips = null;
private void Awake()
{
Application.logMessageReceived += ShowTips;
}
private void Update()
{
if(Input.GetKeyDown(KeyCode.Space))
{
Debug.Log("Exemple de message");
}
}
private void OnApplicationQuit()
{
Application.logMessageReceived -= ShowTips;
}
private void ShowTips(string msg, string stackTrace, LogType type)
{
switch (type)
{
case LogType.Error:
tips += "<color=red>" + msg + "</color>" + "\r\n";
break;
case LogType.Assert:
tips += msg + "\r\n";
break;
case LogType.Warning:
tips += "<color=yellow>" + msg + "</color>" + "\r\n";
break;
case LogType.Log:
tips += msg + "\r\n";
break;
case LogType.Exception:
tips += "<color=red>" + msg + "</color>" + "\r\n";
break;
default:
break;
}
}
void OnGUI()
{
GUI.Label(new Rect(16, 16, Screen.width / 2, Screen.height), tips);
}
}
![Image](https://i.goopics.net/800/Q1EA9.jpg)