Created
May 10, 2016 15:49
-
-
Save kanonji/dccdc546ee6637ef68e434d16a99dfb4 to your computer and use it in GitHub Desktop.
Get an event when tags edited on Tag Manager.
This file contains hidden or 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
using UnityEditor; | |
using UnityEditorInternal; | |
namespace Kanonji.TagManagerEvent | |
{ | |
public delegate void OnTagsChangedHandler(string[] tags); | |
public class Publisher | |
{ | |
public static event OnTagsChangedHandler OnTagsChanged; | |
[InitializeOnLoadMethod] | |
public static void InitEditorUpdateCallback() | |
{ | |
int interval = 6; | |
int nextTiming = (int) EditorApplication.timeSinceStartup; | |
string tokenBefore = MakeToken(InternalEditorUtility.tags); | |
EditorApplication.CallbackFunction function = () => | |
{ | |
if (EditorApplication.timeSinceStartup < nextTiming) return; | |
nextTiming += interval; | |
string token = MakeToken(InternalEditorUtility.tags); | |
if (false == tokenBefore.Equals(token)) | |
{ | |
tokenBefore = token; | |
OnTagsChanged(InternalEditorUtility.tags); | |
// Debug.Log("InternalEditorUtility.tags changed"); | |
} | |
}; | |
EditorApplication.update += function; | |
} | |
protected static string MakeToken(string[] tags) | |
{ | |
return string.Join(",", tags); | |
} | |
} | |
} |
This file contains hidden or 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
using UnityEngine; | |
using UnityEditor; | |
namespace Kanonji.TagManagerEvent | |
{ | |
public class Subscriber | |
{ | |
[InitializeOnLoadMethod] | |
public static void Subscribe() | |
{ | |
Publisher.OnTagsChanged += Foo; | |
} | |
protected static void Foo(string[] tags) | |
{ | |
Debug.Log(string.Join(",", tags)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment