HKI Core
Asserts.cs
Go to the documentation of this file.
1 using UnityEngine;
2 
3 namespace HKI.Core.Assertions
4 {
8  public static class Asserts
9  {
17  public static void IsNotNull<T>(UnityEngine.Object obj, string variableName, string parentObjectName = null)
18  {
19  if (obj == null)
20  {
21  if (string.IsNullOrEmpty(parentObjectName))
22  Debug.LogError("The variable with the name \"" + variableName + "\" of the type \"" + typeof(T).Name + "\" is null");
23  else
24  Debug.LogError("(" + parentObjectName + ") The variable with the name \"" + variableName + "\" of the type \"" + typeof(T).Name + "\" is null");
25  }
26  }
27 
35  public static void IsNull<T>(UnityEngine.Object obj, string variableName, string parentObjectName = null)
36  {
37  if(obj != null)
38  {
39  if (string.IsNullOrEmpty(parentObjectName))
40  Debug.LogError("The variable with the name \"" + variableName + "\" of the type \"" + typeof(T).Name + "\" is not null");
41  else
42  Debug.LogError("(" + parentObjectName + ") The variable with the name \"" + variableName + "\" of the type \"" + typeof(T).Name + "\" is not null");
43  }
44  }
45 
52  public static void IsTrue(bool value, string variableName, string parentObjectName = null)
53  {
54  if(!value)
55  {
56  if (string.IsNullOrEmpty(parentObjectName))
57  Debug.LogError("The variable with the name \"" + variableName + "\" of the type \"bool\" is not true");
58  else
59  Debug.LogError("(" + parentObjectName + ") The variable with the name \"" + variableName + "\" of the type \"bool\" is not true");
60  }
61  }
62 
69  public static void IsFalse(bool value, string variableName, string parentObjectName = null)
70  {
71  if(value)
72  {
73  if (string.IsNullOrEmpty(parentObjectName))
74  Debug.LogError("The variable with the name \"" + variableName + "\" of the type \"bool\" is not false");
75  else
76  Debug.LogError("(" + parentObjectName + ") The variable with the name \"" + variableName + "\" of the type \"bool\" is not false");
77  }
78  }
79  }
80 }
static void IsTrue(bool value, string variableName, string parentObjectName=null)
Check if a bool is true
Definition: Asserts.cs:52
static void IsFalse(bool value, string variableName, string parentObjectName=null)
Check if a bool is false
Definition: Asserts.cs:69
Static class for unifying error msg (of standard checks) of HKI Core in Unity
Definition: Asserts.cs:8