Created
January 14, 2022 20:05
-
-
Save farukcan/21c516e1c947c52f42155b2ecb048ced to your computer and use it in GitHub Desktop.
Advanced Multiple Tagging instead of Unity's
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Author : github.com/farukcan | |
// Usage : AdvancedTag.GetTagList("Player") | |
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class AdvancedTag : MonoBehaviour | |
{ | |
private static Dictionary<string, List<GameObject>> dictionary = new Dictionary<string, List<GameObject>>(); | |
public string[] tags; | |
public static List<GameObject> GetTagList(string tag) | |
{ | |
if (dictionary.ContainsKey(tag)) | |
{ | |
return dictionary[tag]; | |
} | |
else | |
{ | |
return dictionary[tag] = new List<GameObject>(); | |
} | |
} | |
private void OnEnable() | |
{ | |
foreach(var tag in tags) | |
{ | |
var list = GetTagList(tag); | |
list.Add(gameObject); | |
} | |
} | |
private void OnDisable() | |
{ | |
foreach (var tag in tags) | |
{ | |
var list = GetTagList(tag); | |
list.Remove(gameObject); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment