Version: 2019.2

Assert

class in UnityEngine.Assertions

マニュアルに切り替える

説明

Assert クラスには、コード上に不変条件を設定するためのアサーションメソッドに含まれています。

All method calls will be conditionally included only in a development build, unless specified explicitly. See BuildOptions.ForceEnableAssertions. The inclusion of an assertion is controlled by the UNITY_ASSERTIONS define.

Assert throws exceptions by default whenever an assertion fails. You can however set Assert.raiseExceptions to false and Unity then logs a message using LogType.Assert instead.

If a debugger is attached to the project (System.Diagnostics.Debugger.IsAttached is true), AssertionException will be thrown in order to pause the excecution and invoke the debugger.

using UnityEngine;
using UnityEngine.Assertions;

public class AssertionExampleClass : MonoBehaviour { public int health; public GameObject go;

void Update() { // You expect the health never to be equal to zero Assert.AreNotEqual(0, health);

// The referenced GameObject should be always (in every frame) be active Assert.IsTrue(go.activeInHierarchy); } }

Static 変数

raiseExceptionsSet to true to throw an exception when assertion methods fail and false if otherwise. This value defaults to true.

Static 関数

AreApproximatelyEqualAssert the values are approximately equal.
AreEqualAssert that the values are equal.
AreNotApproximatelyEqualAsserts that the values are approximately not equal.
AreNotEqualAssert that the values are not equal.
IsFalseReturn true when the condition is false. Otherwise return false.
IsNotNullAssert that the value is not null.
IsNullAssert the value is null.
IsTruetrue となる条件のアサート
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961