43 | 44 | ```csharp 45 | using ToolBox.Tags; 46 | 47 | public class Test : MonoBehaviour 48 | { 49 | [SerializeField] private GameObject _enemy = null; 50 | [SerializeField] private Tag _zombieTag = null; 51 | [SerializeField] private CompositeTag _allEnemiesTags = null; 52 | 53 | private void Awake() 54 | { 55 | // Check for Tag 56 | if (_enemy.HasTag(_zombieTag)) 57 | { 58 | 59 | } 60 | 61 | // Check for Multiple Tags 62 | // You can also pass in simple array of tags 63 | if (_enemy.HasTags(_allEnemiesTags, allRequired: false)) 64 | { 65 | 66 | } 67 | 68 | // Add Tag 69 | // Be careful, if you create a copy of an existing object with added/removed tags via API (AddTag, RemoveTag, etc). 70 | // These tags will not be copied to the new object. 71 | // But I'll implement a way to copy tags in the future. 72 | _enemy.AddTag(_zombieTag); 73 | 74 | // Remove Tag 75 | _enemy.RemoveTag(_zombieTag); 76 | 77 | 78 | // Get all objects with tag 79 | var zombies = _zombieTag.GetInstances(); 80 | 81 | foreach (var zombie in zombies) 82 | { 83 | // Do something 84 | } 85 | 86 | // Instead of gameObject you can use any class that inherits from Component (transform, collider, etc) 87 | // Example: 88 | _enemy.transform.AddTag(_zombieTag); 89 | } 90 | } 91 | ``` 92 | 93 |
94 |107 | 108 | ```csharp 109 | using Sirenix.OdinInspector; 110 | using System.Diagnostics; 111 | using ToolBox.Tags; 112 | using UnityEngine; 113 | 114 | namespace ToolBox.Test 115 | { 116 | [DefaultExecutionOrder(-100)] 117 | public class Tester : MonoBehaviour 118 | { 119 | [SerializeField] private Tag _myTag = null; 120 | [SerializeField] private string _unityTag = null; 121 | [SerializeField] private GameObject _object = null; 122 | 123 | private const int ITERATIONS = 100000; 124 | 125 | [Button] 126 | private void MyTagTest() 127 | { 128 | Stopwatch stopwatch = new Stopwatch(); 129 | stopwatch.Start(); 130 | 131 | for (int j = 0; j < ITERATIONS; j++) 132 | { 133 | _object.HasTag(_myTag); 134 | } 135 | 136 | stopwatch.Stop(); 137 | UnityEngine.Debug.Log($"Scriptable Object Tag Comparer: {stopwatch.ElapsedMilliseconds} milliseconds"); 138 | } 139 | 140 | [Button] 141 | private void UnityTagTest() 142 | { 143 | Stopwatch stopwatch = new Stopwatch(); 144 | stopwatch.Start(); 145 | 146 | for (int j = 0; j < ITERATIONS; j++) 147 | { 148 | _object.CompareTag(_unityTag); 149 | } 150 | 151 | stopwatch.Stop(); 152 | UnityEngine.Debug.Log($"Unity Tag Comparer: {stopwatch.ElapsedMilliseconds} milliseconds"); 153 | } 154 | } 155 | } 156 | 157 | ``` 158 |
159 |163 | 164 |  165 | 166 |
167 |