private void RemoveTag(EditorTag tagName)
 {
     for (int i = 0; i < selectedTags.arraySize; i++)
     {
         if (tagName.Id.Trim() == selectedTags.GetArrayElementAtIndex(i).FindPropertyRelative("Id").stringValue.Trim())
         {
             selectedTags.DeleteArrayElementAtIndex(i);
             return;
         }
     }
 }
 private void RemoveTag(EditorTag tagName)
 {
     for (int i = 0; i < selectedTags.arraySize; i++)
     {
         if (tagName.Id.Trim() == selectedTags.GetArrayElementAtIndex(i).FindPropertyRelative("Id").stringValue.Trim())
         {
             selectedTags.DeleteArrayElementAtIndex(i);
             return;
         }
     }
 }
        private void AddTag(EditorTag tagName)
        {
            if (!ContainsTag(tagName))
            {
                selectedTags.arraySize += 1;
                SerializedProperty id  = selectedTags.GetArrayElementAtIndex(selectedTags.arraySize - 1).FindPropertyRelative("Id");
                SerializedProperty tag = selectedTags.GetArrayElementAtIndex(selectedTags.arraySize - 1).FindPropertyRelative("Tag");

                id.stringValue  = tagName.Id;
                tag.stringValue = tagName.Tag;
            }
        }
        private bool ContainsTag(EditorTag tagName)
        {
            for (int i = 0; i < selectedTags.arraySize; i++)
            {
                if (tagName.Id.Trim() == selectedTags.GetArrayElementAtIndex(i).FindPropertyRelative("Id").stringValue.Trim())
                {
                    return(true);
                }
            }

            return(false);
        }
        private bool ContainsTag(EditorTag tagName)
        {
            for (int i = 0; i < selectedTags.arraySize; i++)
            {
                if (tagName.Id.Trim() == selectedTags.GetArrayElementAtIndex(i).FindPropertyRelative("Id").stringValue.Trim())
                {
                    return true;
                }
            }

            return false;
        }
        private void AddTag(EditorTag tagName)
        {
            if (!ContainsTag(tagName))
            {
                selectedTags.arraySize +=1;
                SerializedProperty id = selectedTags.GetArrayElementAtIndex(selectedTags.arraySize - 1).FindPropertyRelative("Id");
                SerializedProperty tag = selectedTags.GetArrayElementAtIndex(selectedTags.arraySize - 1).FindPropertyRelative("Tag");

                id.stringValue = tagName.Id;
                tag.stringValue = tagName.Tag;
            }
        }
        private static void LoadXmlDoc()
        {
            var       doc     = Resources.Load(tagLoadXmlFileName) as TextAsset;
            XDocument xdoc    = XDocument.Parse(doc.text);
            var       xmltags = xdoc.Element("tags").Elements();

            foreach (XElement tag in xmltags)
            {
                EditorTag et = new EditorTag();
                et.Id  = tag.Attribute("id").Value;
                et.Tag = tag.Value;
                editorTags.Add(et);
            }
        }
示例#8
0
        void OnGUI()
        {
            scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition);

            for (int i = 0; i < newTags.Count(); i++)
            {
                EditorTag tag = newTags[i];
                EditorGUILayout.BeginHorizontal();

                newTags[i].Tag = MultiTagManager.CleanName(EditorGUILayout.TextField(new GUIContent("Tag"), tag.Tag));

                //Don't allow users to add tags that already exist.  Clear if needed
                if (newTags.Where(t => t.Tag.ToLower().Trim() == newTags[i].Tag.ToLower().Trim()).Count() > 1)
                {
                    newTags[i].Tag = "";
                }


                if (GUILayout.Button(new GUIContent("x", "Delete Tag")))
                {
                    newTags.Remove(tag);
                    AddTagCheck();
                }

                EditorGUILayout.EndHorizontal();
            }

            AddTagCheck();

            EditorGUILayout.EndScrollView();


            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button(new GUIContent("Save")))
            {
                MultiTagManager.Update(newTags);
                AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
                this.Close();
            }

            if (GUILayout.Button(new GUIContent("Cancel")))
            {
                this.Close();
            }
            EditorGUILayout.EndHorizontal();
        }
示例#9
0
        /// <summary>
        /// Add a tag to this gameobject if it does not already exist.  Also add the tagger component to the gameobject if it doesn't exist
        /// </summary>
        /// <param name="go">The game object</param>
        /// <returns>A list of tags</returns>
        public static void AddTag(this GameObject go, Tags tag)
        {
            var tagger = go.GetComponent <TagFrenzyList>();

            if (tagger == null)
            {
                tagger = go.AddComponent <TagFrenzyList>();
            }

            //Make sure no deleted tags are hanging around before we add new ones
            tagger.CleanupDeletedTags();

            if (!tagger.SelectedEditorTags.Where(t => t.Tag == tag.ToString()).Any())
            {
                EditorTag et = MultiTagManager.EditorTags.Where(t => t.Tag == tag.ToString()).FirstOrDefault();
                tagger.SelectedEditorTags.Add(et);
            }
        }
        public static void SetupForTagger()
        {
            //Setup the current tags
            List<EditorTag> tagsToAdd = new List<EditorTag>();
            for (int i = 0; i < MultiTagManager.EditorTags.Count(); i++)
            {
                tagsToAdd.Add(MultiTagManager.EditorTags[i]);
            }

            //Loop trough all game objects in the scene
            object[] obj = GameObject.FindObjectsOfType(typeof(GameObject));
            foreach (object o in obj)
            {
                //Make sure they have a tagger component attached
                GameObject g = (GameObject)o;
                TagFrenzyList comp = (TagFrenzyList)g.GetComponent(typeof(TagFrenzyList));
                if (comp == null)
                {
                    comp = g.AddComponent<TagFrenzyList>();
                }

                //Find any tags on each current object
                string tag = g.tag;

                if (tag != null && tag.ToLower() != "untagged")
                {
                    //Does the tag exist in our global list of tags? If not, add it.
                    if (!MultiTagManager.TagNameMatch(tag))
                    {
                        EditorTag et = new EditorTag();
                        et.Id = "0";
                        et.Tag = tag;
                        tagsToAdd.Add(et);
                        MultiTagManager.Update(tagsToAdd);
                    }

                    //Add it to the local tagger script
                    g.AddTag(g.tag);
                }

            }

            AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
        }
示例#11
0
        public static void SetupForTagger()
        {
            //Setup the current tags
            List <EditorTag> tagsToAdd = new List <EditorTag>();

            for (int i = 0; i < MultiTagManager.EditorTags.Count(); i++)
            {
                tagsToAdd.Add(MultiTagManager.EditorTags[i]);
            }

            //Loop trough all game objects in the scene
            object[] obj = GameObject.FindObjectsOfType(typeof(GameObject));
            foreach (object o in obj)
            {
                //Make sure they have a tagger component attached
                GameObject    g    = (GameObject)o;
                TagFrenzyList comp = (TagFrenzyList)g.GetComponent(typeof(TagFrenzyList));
                if (comp == null)
                {
                    comp = g.AddComponent <TagFrenzyList>();
                }

                //Find any tags on each current object
                string tag = g.tag;

                if (tag != null && tag.ToLower() != "untagged")
                {
                    //Does the tag exist in our global list of tags? If not, add it.
                    if (!MultiTagManager.TagNameMatch(tag))
                    {
                        EditorTag et = new EditorTag();
                        et.Id  = "0";
                        et.Tag = tag;
                        tagsToAdd.Add(et);
                        MultiTagManager.Update(tagsToAdd);
                    }

                    //Add it to the local tagger script
                    g.AddTag(g.tag);
                }
            }

            AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
        }
        public override void OnInspectorGUI()
        {
            tagger.Update();


            for (int i = 0; i < MultiTagManager.EditorTags.Count; i++)
            {
                EditorTag tagName = MultiTagManager.EditorTags[i];
                bool      toggle  = ContainsTag(tagName);
                toggle = EditorGUILayout.BeginToggleGroup(new GUIContent(tagName.Tag), toggle);
                if (toggle)
                {
                    AddTag(tagName);
                }
                else
                {
                    RemoveTag(tagName);
                }
                EditorGUILayout.EndToggleGroup();
            }

            tagger.ApplyModifiedProperties();
        }
 /// <summary>
 /// Is the tag name found in the existing list of tags
 /// </summary>
 /// <param name="editorTag"></param>
 /// <returns></returns>
 public static bool TagNameMatch(EditorTag editorTag)
 {
     return TagNameMatch(editorTag.Tag);
 }
 private static void LoadXmlDoc()
 {
     var doc = Resources.Load(tagLoadXmlFileName) as TextAsset;
     XDocument xdoc = XDocument.Parse(doc.text);
     var xmltags = xdoc.Element("tags").Elements();
     foreach (XElement tag in xmltags)
     {
         EditorTag et = new EditorTag();
         et.Id = tag.Attribute("id").Value;
         et.Tag = tag.Value;
         editorTags.Add(et);
     }
 }
 public static bool TagIdMatch(EditorTag editorTag)
 {
     return TagIdMatch(editorTag.Id);
 }
示例#16
0
 public static bool TagIdMatch(EditorTag editorTag)
 {
     return(TagIdMatch(editorTag.Id));
 }
示例#17
0
 /// <summary>
 /// Is the tag name found in the existing list of tags
 /// </summary>
 /// <param name="editorTag"></param>
 /// <returns></returns>
 public static bool TagNameMatch(EditorTag editorTag)
 {
     return(TagNameMatch(editorTag.Tag));
 }