- Home /
[Editor] Adding Tags to Tag manager On Import
Hello there, I have 2 questions here,
1) how to add a tag to the tag manager's Tags array from editor on Importing something into unity say a package or a the like.
2) I know how to find when an asset is imported into unity using asset importer or assetpostprocessor but how to i find when a package is imported.
Basically I want to set some tags for my project when I import my framwork is it possible!!?.
Cheers.
Answer by sooncat · Aug 19, 2013 at 11:34 AM
I have try this in unity4.0. Add this script in your framework and it will works when you import your frameworkpackage.
using UnityEditor;
using UnityEngine;
using System.Collections;
public class MyClass : AssetPostprocessor
{
static void OnPostprocessAllAssets (
string[] importedAssets, string[] deletedAssets,
string[] movedAssets, string[] movedFromAssetPaths)
{
if (IsMyFrameWorkTagFile(importedAssets))
{
SerializedObject tagManager = new SerializedObject(AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/TagManager.asset")[0]);
SerializedProperty it = tagManager.GetIterator();
bool showChildren = true;
while (it.NextVisible(showChildren))
{
//set your tags here
if (it.name == "User Layer 31")
{
it.stringValue = "MyTag31";
}
}
tagManager.ApplyModifiedProperties();
}
}
static bool IsMyFrameWorkTagFile(string[] asstNames)
{
foreach(string s in asstNames)
{
//replaced by your path
if (s.Equals("Assets/Editor/MyClass.cs"))
return true;
}
return false;
}
}
that is a good one thanks... though I havnt tried yet, it looks convincing for me, and should work.
Thanks again
Your answer
![](https://koobas.hobune.stream/wayback/20220613093424im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
On Awake, Set System Tag array to 100? 1 Answer
Find Objects with particular tag 2 Answers
Tag Settings window 1 Answer