概要
- Debug.Assert と Debug.LogAssertion は Development Build の時のみ動作する
- Development Build ではない時にも動作させたい場合は
BuildOptions.ForceEnableAssertions
を使用する
using System.Linq;
using UnityEditor;
public class Example
{
[MenuItem( "Tools/Hoge" )]
private static void Hoge()
{
var options = new BuildPlayerOptions
{
scenes = EditorBuildSettings.scenes.Select( x => x.path ).ToArray(),
locationPathName = "app.apk",
targetGroup = BuildTargetGroup.Android,
target = BuildTarget.Android,
options = BuildOptions.ForceEnableAssertions,
};
BuildPipeline.BuildPlayer( options );
}
}
検証用スクリプト
using System.Text;
using UnityEngine;
using UnityEngine.UI;
public class Example : MonoBehaviour
{
public Text m_text;
private readonly StringBuilder m_builder = new StringBuilder();
private void Start()
{
void OnReceived
(
string condition,
string trace,
LogType type
)
{
m_builder.AppendLine( condition );
m_builder.AppendLine( trace );
m_builder.AppendLine( type.ToString() );
m_builder.AppendLine();
}
Application.logMessageReceivedThreaded += OnReceived;
Debug.LogAssertion( "LogAssertion" );
Debug.Assert( false, "Debug.Assert" );
}
private void Update()
{
m_text.text = m_builder.ToString();
}
}
参考サイト様