public static void SyncTagData(TagData tagData) { if (!tagData.SimilarTo(UnityEditorInternal.InternalEditorUtility.tags)) { var helper = new TagData.EditorHelper(tagData); using (var tags = com.spacepuppy.Collections.TempCollection.GetList <string>(UnityEditorInternal.InternalEditorUtility.tags)) { bool added = false; if (!tags.Contains(SPConstants.TAG_MULTITAG)) { tags.Add(SPConstants.TAG_MULTITAG); added = true; } if (!tags.Contains(SPConstants.TAG_ROOT)) { tags.Add(SPConstants.TAG_ROOT); added = true; } if (added) { try { SerializedObject tagManager = new SerializedObject(AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/TagManager.asset")[0]); SerializedProperty tagsProp = tagManager.FindProperty("tags"); var arr = (from st in tags where !string.IsNullOrEmpty(st) && !TagData.IsDefaultUnityTag(st) select st).ToArray(); tagsProp.arraySize = arr.Length; for (int i = 0; i < arr.Length; i++) { tagsProp.GetArrayElementAtIndex(i).stringValue = arr[i]; } tagManager.ApplyModifiedProperties(); } catch { Debug.LogWarning("Failed to save TagManager when syncing tags."); } } Undo.RecordObject(tagData, "Sync TagData"); helper.UpdateTags(tags); EditorUtility.SetDirty(tagData); AssetDatabase.SaveAssets(); } } }
public static void SyncTagData(TagData tagData) { if (!tagData.SimilarTo(UnityEditorInternal.InternalEditorUtility.tags)) { var helper = new TagData.EditorHelper(tagData); using (var tags = com.spacepuppy.Collections.TempCollection.GetList<string>(UnityEditorInternal.InternalEditorUtility.tags)) { bool added = false; if (!tags.Contains(SPConstants.TAG_MULTITAG)) { tags.Add(SPConstants.TAG_MULTITAG); added = true; } if (!tags.Contains(SPConstants.TAG_ROOT)) { tags.Add(SPConstants.TAG_ROOT); added = true; } if(added) { try { SerializedObject tagManager = new SerializedObject(AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/TagManager.asset")[0]); SerializedProperty tagsProp = tagManager.FindProperty("tags"); var arr = (from st in tags where !TagData.IsDefaultUnityTag(st) select st).ToArray(); tagsProp.arraySize = arr.Length; for(int i = 0; i < arr.Length; i++) { tagsProp.GetArrayElementAtIndex(i).stringValue = arr[i]; } tagManager.ApplyModifiedProperties(); } catch { Debug.LogWarning("Failed to save TagManager when syncing tags."); } } helper.UpdateTags(tags); EditorUtility.SetDirty(tagData); AssetDatabase.SaveAssets(); } } }
public static void SyncTagData() { var tagData = (TagData)AssetDatabase.LoadAssetAtPath(@"Assets/Resources/TagData.asset", typeof(TagData)); if (tagData == null) { if(!System.IO.Directory.Exists(Application.dataPath + "/Resources")) { System.IO.Directory.CreateDirectory(Application.dataPath + "/Resources"); } tagData = ScriptableObjectHelper.CreateAsset<TagData>(@"Assets/Resources/TagData.asset"); } if (!tagData.SimilarTo(UnityEditorInternal.InternalEditorUtility.tags)) { var helper = new TagData.EditorHelper(tagData); helper.UpdateTags(UnityEditorInternal.InternalEditorUtility.tags); EditorUtility.SetDirty(tagData); AssetDatabase.SaveAssets(); } }
protected override void OnEnable() { base.OnEnable(); _helper = new TagData.EditorHelper(this.target as TagData); }
void OnEnable() { _helper = new TagData.EditorHelper(this.target as TagData); }