GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - IntoTheDev/MultiTag-System-for-Unity: This package allows you to Tag Game Objects with ScriptableObjects

BranchesTags
Open more actions menu

Latest commit

 

History

173 Commits
173 Commits

Folders and files

NameName
Last commit message
Last commit date
Runtime
Runtime
 
 
Changelog.md
Changelog.md
 
 
Changelog.md.meta
Changelog.md.meta
 
 
LICENSE
LICENSE
 
 
LICENSE.meta
LICENSE.meta
 
 
README.md
README.md
 
 
README.md.meta
README.md.meta
 
 
Runtime.meta
Runtime.meta
 
 
package.json
package.json
 
 
package.json.meta
package.json.meta
 
 

Repository files navigation

MultiTag System for Unity

This package allows you to Tag Game Objects with ScriptableObjects.

TODO

  • Editor support with custom inspector
  • Add tag code generator to quickly access tags without referencing them in the inspector
  • Add API to get entity's runtime added tags

Features

  • Allows you to put as many Tags on your GameObject as you want
  • Add and remove tags via code and inspector
  • Work with ScriptableObjects instead of strings
  • Faster than Unity's tag system. Keep in mind that such methods as AddTag, AddTags, RemoveTag and RemoveTags are way slower in Editor than in Build because of the Taggable component's updates and Custom Inspector
  • Editor support

How to Install

Git Installation (Best way to get latest version)

If you have Git on your computer, you can open Package Manager indside Unity, select "Add package from Git url...", and paste link https://github.com/IntoTheDev/MultiTag-System-for-Unity.git

or

Open the manifest.json file of your Unity project. Add "com.intothedev.multitags": "https://github.com/IntoTheDev/MultiTag-System-for-Unity.git"

Manual Installation (Version can be outdated)

Download latest package from the Release section. Import MultiTags.unitypackage to your Unity Project

Usage

How to create a new Tag/CompositeTag

Assets/Create/ToolBox/Tags

Change Tags in Editor

If you want to change tags only in Runtime via code then Taggable component is unnecessary.

Runtime Operations (HasTag, HasTags, AddTag, RemoveTag, GetInstances, etc)

Code

using ToolBox.Tags;
	
public class Test : MonoBehaviour
{
	[SerializeField] private GameObject _enemy = null;
	[SerializeField] private Tag _zombieTag = null;
	[SerializeField] private CompositeTag _allEnemiesTags = null;
 
	private void Awake()
	{
		// Check for Tag
		if (_enemy.HasTag(_zombieTag))
		{
		
		}
		
		// Check for Multiple Tags
		// You can also pass in simple array of tags
		if (_enemy.HasTags(_allEnemiesTags, allRequired: false))
		{
		
		}
		
		// Add Tag
		// Be careful, if you create a copy of an existing object with added/removed tags via API (AddTag, RemoveTag, etc). 
		// These tags will not be copied to the new object. 
		// But I'll implement a way to copy tags in the future.
		_enemy.AddTag(_zombieTag);
		
		// Remove Tag
		_enemy.RemoveTag(_zombieTag);
		
		
		// Get all objects with tag
		var zombies = _zombieTag.GetInstances();
		
		foreach (var zombie in zombies)
		{
			// Do something
		}
	
		// Instead of gameObject you can use any class that inherits from Component (transform, collider, etc)
		// Example:
		_enemy.transform.AddTag(_zombieTag);
	}
}

CompositeTag Usage

CompositeTag allows you to combine tags into single asset and use API with that asset (AddTags, RemoveTags, HasTags)

Example:

Performance Test

Code

using Sirenix.OdinInspector;
using System.Diagnostics;
using ToolBox.Tags;
using UnityEngine;

namespace ToolBox.Test
{
	[DefaultExecutionOrder(-100)]
	public class Tester : MonoBehaviour
	{
		[SerializeField] private Tag _myTag = null;
		[SerializeField] private string _unityTag = null;
		[SerializeField] private GameObject _object = null;

		private const int ITERATIONS = 100000;

		[Button]
		private void MyTagTest()
		{
			Stopwatch stopwatch = new Stopwatch();
			stopwatch.Start();

			for (int j = 0; j < ITERATIONS; j++)
			{
				_object.HasTag(_myTag);
			}

			stopwatch.Stop();
			UnityEngine.Debug.Log($"Scriptable Object Tag Comparer: {stopwatch.ElapsedMilliseconds} milliseconds");
		}

		[Button]
		private void UnityTagTest()
		{
			Stopwatch stopwatch = new Stopwatch();
			stopwatch.Start();

			for (int j = 0; j < ITERATIONS; j++)
			{
				_object.CompareTag(_unityTag);
			}

			stopwatch.Stop();
			UnityEngine.Debug.Log($"Unity Tag Comparer: {stopwatch.ElapsedMilliseconds} milliseconds");
		}
	}
}

Test Result

Result

About

This package allows you to Tag Game Objects with ScriptableObjects

Topics

inspectorscriptableobjectsunityunity-scriptsunity2dunity3d

Resources

Readme
Activity

Stars

156 stars

Watchers

5 watching

Forks

13 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.