/// <summary> /// Get tags of editing object(s). /// If editing multiple objects and they have different tags, /// get only tags in common. /// </summary> private void GetObjectsTags() { // If editing multiple objects and they do not have the same tag, // get tags in common between them if (serializedObject.isEditingMultipleObjects) { string[][] _objectTags = targetGO.Select(t => t.GetTagNames()).ToArray(); string[] _tagsInCommon = _objectTags.Aggregate((previousList, nextList) => previousList.Intersect(nextList).ToArray()); editingTags = MultiTags.GetTags(_tagsInCommon); lastTags = targetGO.Select(g => g.tag).ToArray(); haveTargetsDifferentTags = _objectTags.Any(t => !Enumerable.SequenceEqual(t, _tagsInCommon)); } // Else, just get tags of the first editing object else { // Get editing object tags lastTags = new string[1] { targetGO[0].tag }; editingTags = targetGO[0].GetTags(); haveTargetsDifferentTags = false; } }
public override TaskResult Run(ITaskNode node) { var ctx = node.Context; var targets = ctx.GetGameObjects(this.Target); var tagsToSet = MultiTags.Parse(this.Set); var tagsToUnset = MultiTags.Parse(this.Unset); foreach (var t in targets) { var multitags = t.GetComponent <MultiTags>(); if (multitags == null) { throw new InvalidOperationException(string.Format("Target gameobject {0} does not have a MultiTags component", t)); } foreach (var tag in tagsToSet) { multitags.AddTag(tag); } foreach (var tag in tagsToUnset) { multitags.RemoveTag(tag); } } return(TaskResult.Success); }
/// <summary> /// Adds multiple new tags to the object. /// </summary> /// <param name="_tags">Name of the tags to add.</param> public void AddTags(string[] _tags) { // If this object already contains a tag with the same name, do not add it. string[] _tagNames = TagNames; _tags = _tags.Where(t => !_tagNames.Contains(t)).ToArray(); if (_tags.Length == 0) { return; } Tag[] _newTags = new Tag[ObjectTags.Length + _tags.Length]; Tag[] _existingTags = MultiTags.GetTags(_tags); for (int _i = 0; _i < ObjectTags.Length; _i++) { _newTags[_i] = ObjectTags[_i]; } for (int _i = 0; _i < _existingTags.Length; _i++) { _newTags[ObjectTags.Length + _i] = _existingTags[_i]; } for (int _i = _existingTags.Length; _i < _tags.Length; _i++) { _newTags[ObjectTags.Length + _i] = new Tag(_tags[_i]); } ObjectTags = _newTags; Sort(); }
/// <summary> /// Have these tags in GameObject /// </summary> public static bool HaveTags(this GameObject value, params string[] tags) { MultiTags CurrentGameComponent = value.GetComponent <MultiTags>(); if (CurrentGameComponent == null || tags == null || tags.Length == 0) { return(false); } bool aux = false; foreach (string tag in tags) { aux = false; foreach (var item in CurrentGameComponent.localTagList) { if (string.Equals(item.Name.ToLower(), tag.ToLower(), StringComparison.CurrentCultureIgnoreCase)) { aux = true; break; } } if (!aux) { return(false); } } return(true); }
void OnCollisionEnter(Collision other) { if (MultiTags.GameObjectHasTag(other.gameObject, Tag.Puck)) { other.gameObject.GetComponent <Rigidbody> ().AddForce((other.gameObject.transform.position - this.gameObject.transform.position) * collisionForce); } }
/// <summary> /// Registers a GameObject into the field <see cref="objectsTags"/>. /// </summary> /// <param name="_object">GameObject to register.</param> private void RegisterObject(GameObject _object) { int _id = _object.GetInstanceID(); if (!TDS_LevelManager.Instance.ObjectsTags.ContainsKey(_id)) { TDS_LevelManager.Instance.ObjectsTags.Add(_id, new Tags(MultiTags.GetTags(_object.tag.Split(MultiTags.TAG_SEPARATOR)))); } }
private static MultiTags GetMultiTagsComponent(GameObject gameObject) { MultiTags multiTags = gameObject.GetComponent <MultiTags>(); if (multiTags == null) { multiTags = gameObject.AddComponent <MultiTags>(); } return(multiTags); }
public static void UntagGameObject(GameObject gameObject, Tag target) { MultiTags multiTags = GetMultiTagsComponent(gameObject); List <Tag> newTags = new List <Tag> (multiTags.tags); while (GameObjectHasTag(gameObject, target)) { newTags.Remove(target); multiTags.tags = newTags.ToArray(); } }
//HAS TAG Private private static bool HasTagPrivate(MultiTags go, string tagToCheck) { foreach (var item in go.localTagList) { if (string.Equals(item.Name, tagToCheck, StringComparison.CurrentCultureIgnoreCase)) { return(true); } } return(false); }
//Private GetTagItem private static MT GetTagItem(MultiTags CGC, string tagToCheck) { foreach (var item in CGC.localTagList) { if (string.Equals(item.Name, tagToCheck, StringComparison.CurrentCultureIgnoreCase)) { return(item); } } return(null); }
/// <summary> /// Get a Tag objects from all this game object tags. /// </summary> /// <param name="_go">Game object to get tags from.</param> /// <returns>Returns a Tags object from all this game object tags.</returns> public static Tag[] GetTags(this GameObject _go) { #if UNITY_EDITOR if (!Application.isPlaying) { return(MultiTags.GetTags(_go.GetTagNames())); } #endif return(MultiTags.TagsAsset.GetObjectTags(_go)); }
public override TaskResult Run(ITaskNode node) { var ctx = node.Context; var require = MultiTags.Parse(this.Require); var include = MultiTags.Parse(this.Include); var exclude = MultiTags.Parse(this.Exclude); var filtered = MultiTags.FindGameObjectsWithTags(require, include, exclude); ctx.SetItem(this.Assign, filtered); return(TaskResult.Success); }
public static void TagGameObject(GameObject gameObject, Tag newTag) { MultiTags multiTags = GetMultiTagsComponent(gameObject); Tag[] newTags = new Tag[multiTags.tags.Length + 1]; for (int i = 0; i < multiTags.tags.Length; i++) { newTags[i] = multiTags.tags[i]; } newTags [multiTags.tags.Length] = newTag; multiTags.tags = newTags; }
public static bool GameObjectHasTag(GameObject gameObject, Tag searchTag) { bool hasTag = false; MultiTags multiTags = GetMultiTagsComponent(gameObject); foreach (Tag objectTag in multiTags.tags) { if (objectTag == searchTag) { hasTag = true; break; } } return(hasTag); }
void Start() { if (GameManager.instance == null) { return; } checkTagsHashed = MultiTags.GetHashedTagsArray(checkTags.ToArray()); if (includeHero) { TriggerIfTouching.Add(GameManager.instance.Player.gameObject); } if (gameObject.isStatic) { return; } if (useMeshEffects && meshFx == null) { meshFx = this.GetComponent <MeshFilter>(); } if (meshFx != null) { tris = meshFx.mesh.triangles; verts = GameMath.CopyVertorArray(meshFx.mesh.vertices); uvs = meshFx.mesh.uv; if (useMeshEffects) { vertsScaled = GameMath.CopyVertorArray(meshFx.mesh.vertices); for (int i = 0; i < vertsScaled.Length; i++) { vertsScaled[i].x *= scaleFactor.x; vertsScaled[i].y *= scaleFactor.y; vertsScaled[i].z *= scaleFactor.z; //offset: vertsScaled[i].x += offsetFactor.x; vertsScaled[i].y += offsetFactor.y; vertsScaled[i].z += offsetFactor.z; } } } if (exitOnStart) { SuccessOnExit(); } }
//ADD TAG GameObject Extention public static void AddTag(this GameObject go, string newTag) { MultiTags CurrentGameComponent = go.GetComponent <MultiTags> (); if (CurrentGameComponent == null) { go.AddComponent <MultiTags>(); CurrentGameComponent = go.GetComponent <MultiTags> (); } if (!HasTagPrivate(CurrentGameComponent, newTag)) { MT newItem = new MT(); newItem.Name = newTag; CurrentGameComponent.localTagList.Add(newItem); } }
/// <summary> /// Remove these tags in GameObject /// </summary> public static void RemoveTags(this GameObject value, params string[] tags) { MultiTags CurrentGameComponent = value.GetComponent <MultiTags>(); if (CurrentGameComponent == null) { return; } foreach (string tag in tags) { MT tempItem = GetTagItem(CurrentGameComponent, tag); if (tempItem != null) { CurrentGameComponent.localTagList.Remove(tempItem); } } }
/// <summary> /// Return these tags in GameObject /// </summary> public static string[] ReturnTags(this GameObject value) { MultiTags multiTags = value.GetComponent <MultiTags>(); if (multiTags && multiTags.localTagList.Count > 0) { List <MT> mts = multiTags.localTagList; string[] tags = new string[mts.Count]; for (int i = 0; i < tags.Length; i++) { tags[i] = mts[i].Name; } return(tags); } else { return(null); } }
//REMOVE TAG GameObject Extention public static void RemoveTag(this GameObject go, string tag) { MultiTags CurrentGameComponent = go.GetComponent <MultiTags> (); if (CurrentGameComponent == null) { return; } MT tempItem = GetTagItem(CurrentGameComponent, tag); if (tempItem == null) { return; } CurrentGameComponent.localTagList.Remove(tempItem); }
//HAS TAG GameObject Extention public static bool HasTag(this GameObject go, string tagToCheck) { MultiTags CurrentGameComponent = go.GetComponent <MultiTags> (); if (CurrentGameComponent == null) { return(false); } foreach (var item in CurrentGameComponent.localTagList) { //item.Name.ToLower() == tagToCheck.ToLower() if (string.Equals(item.Name, tagToCheck, StringComparison.CurrentCultureIgnoreCase)) { return(true); } } return(false); }
/// <summary> /// Add these tags in GameObject /// </summary> public static void AddTags(this GameObject value, params string[] tags) { MultiTags CurrentGameComponent = value.GetComponent <MultiTags>(); if (CurrentGameComponent == null) { value.AddComponent <MultiTags>(); CurrentGameComponent = value.GetComponent <MultiTags>(); } foreach (string tag in tags) { if (!HasTagPrivate(CurrentGameComponent, tag)) { MT newItem = new MT(); newItem.Name = tag; CurrentGameComponent.localTagList.Add(newItem); } } }
bool CheckTag(GameObject col) { MultiTags mt = col.GetComponent <MultiTags>(); if (mt != null) { /* * Simple tag checks can be done with strings, but it's faster to check ints, so I'll use the hashed list instead: * * String check example: * for (int i = 0; i < mt.Tags.Length; i++) * { * string s = mt.Tags[i]; * for (int y = 0; y < checkTags.Count; y++) * { * string t = checkTags[y]; * if (s == t) * { * return true; * } * } * } */ for (int i = 0; i < mt.TagsHashed.Length; i++) { int t1 = mt.TagsHashed[i]; for (int y = 0; y < checkTagsHashed.Length; y++) { int t2 = checkTagsHashed[y]; if (t1 == t2) { return(true); } } } } return(false); }
public override void OnInspectorGUI() { MultiTags myScript = (MultiTags)target; EditorGUILayout.LabelField("--------------------------------------------------------------------------------------------------------------------"); GUI.color = Color.green; EditorGUILayout.LabelField("LOCAL ASSIGNED TAGS: "); GUI.color = Color.white; GUILayout.Space(10); foreach (var item in myScript.localTagList.ToArray()) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Tag: ", GUILayout.Width(40)); //EditorGUILayout.TextField(item.Name); EditorGUILayout.SelectableLabel(item.Name, EditorStyles.textField, GUILayout.Height(EditorGUIUtility.singleLineHeight)); GUI.color = Color.red + Color.yellow; if (GUILayout.Button("Remove", GUILayout.Width(55))) { myScript.localTagList.Remove(item); } GUI.color = Color.white; EditorGUILayout.EndHorizontal(); if (!HasTagGlobal(item.Name)) { EditorGUILayout.BeginHorizontal(); GUI.color = Color.yellow; EditorGUILayout.LabelField("warning: (" + item.Name + ") is not a global tag.", GUILayout.Height(25)); GUI.color = Color.white; EditorGUILayout.EndHorizontal(); } } EditorGUILayout.LabelField("--------------------------------------------------------------------------------------------------------------------"); EditorGUILayout.LabelField("--------------------------------------------------------------------------------------------------------------------"); GUI.color = Color.cyan; expandGlobals = EditorGUILayout.Foldout(expandGlobals, "GLOBAL PROJECT TAGS: "); GUI.color = Color.white; if (expandGlobals) { foreach (var itemG in GlobalTagHolder.TagHolder.GlobalTagList.ToArray()) { EditorGUILayout.BeginHorizontal(); if (myScript.gameObject.HasTag(itemG.Name)) { GUI.color = Color.green; EditorGUILayout.LabelField("Assigned ", GUILayout.Width(55)); GUI.color = Color.white; } else { GUI.color = Color.green; //EditorGUILayout.LabelField ("Tag: " + item); if (GUILayout.Button("Assign", GUILayout.Width(55))) { myScript.localTagList.Add(itemG); } GUI.color = Color.white; } EditorGUILayout.LabelField("Tag: ", GUILayout.Width(40)); // EditorGUILayout.LabelField ("Tag: " + itemG.Name); EditorGUILayout.SelectableLabel(itemG.Name, EditorStyles.textField, GUILayout.Height(EditorGUIUtility.singleLineHeight)); GUI.color = Color.red + Color.red; if (GUILayout.Button("Destroy", GUILayout.Width(55))) { GlobalTagHolder.TagHolder.GlobalTagList.Remove(itemG); GlobalTagHolder.TagHolder.Save(); } GUI.color = Color.white; // EditorGUILayout.LabelField ("Description: " + itemAll.Description.ToString (), GUILayout.MaxWidth (160)); //item.Description = EditorGUILayout.TextField ("Description: ", item.Description, GUILayout.MaxWidth(120)); //EditorGUILayout.Separator(); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); // itemAll.ID = (byte)EditorGUILayout.IntField ("ReID: ", itemAll.ID, GUILayout.MaxWidth (180)); // itemAll.Name = EditorGUILayout.TextField ("Rename: ", itemAll.Name); EditorGUILayout.EndHorizontal(); // EditorGUILayout.LabelField ("-----------"); } EditorGUILayout.LabelField("--------------------------------------------------------------------------------------------------------------------"); } GUILayout.Space(20); EditorGUILayout.BeginHorizontal(); //tagDescription = GUILayout.TextField(tagDescription,20); tagDescription = EditorGUILayout.TextField("Tag Name: ", tagDescription); GUI.color = Color.cyan; if (GUILayout.Button("Add New Tag", GUILayout.Width(100))) { tagDescription = tagDescription.Trim(); if (string.IsNullOrEmpty(tagDescription)) { return; } MT itemLocal = new MT(); MT itemGlobal = new MT(); itemLocal.Name = tagDescription; // item.ID = 44; // itemLocal.tagGUID = Guid.NewGuid().ToString();; itemGlobal.Name = itemLocal.Name; // itemGlobal.tagGUID = itemLocal.tagGUID; if (!HasTagGlobal(tagDescription)) { GlobalTagHolder.TagHolder.GlobalTagList.Add(itemGlobal); GlobalTagHolder.TagHolder.Save(); } if (!myScript.gameObject.HasTag(tagDescription)) { myScript.localTagList.Add(itemLocal); } tagDescription = string.Empty; } GUI.color = Color.white; EditorGUILayout.EndHorizontal(); GUILayout.Space(20); expandCodeExample = EditorGUILayout.Foldout(expandCodeExample, "CODE EXAMPLE: "); if (expandCodeExample) { GUILayout.TextArea(stringToEdit, 200); } GUILayout.Space(20); // DrawDefaultInspector (); if (GUI.changed) { // Debug.Log ("I Changed"); // foreach (var item in myScript.multiTag) { // if (String.IsNullOrEmpty(item.TestGUID())) { // // item.SetGUID(Guid.NewGuid().ToString()); // // } // } } }
/// <summary> /// Get a Tag objects from all this game object tags. /// </summary> /// <param name="_go">Game object to get tags from.</param> /// <returns>Returns a Tags object from all this game object tags.</returns> public static Tag[] GetTags(this GameObject _go) { return(MultiTags.GetTags(_go.GetTagNames())); }
/// <summary> /// Adds a new tag to the object. /// </summary> /// <param name="_tag">Name of the tag to add.</param> public void AddTag(string _tag) { Tag _toAdd = MultiTags.GetTag(_tag) ?? new Tag(_tag); AddTag(_toAdd); }
public static GameObject[] FindGameObjectsWithTags(bool only = false, params string[] tags) { return(MultiTags.FindGameObjectsWithMultiTags(only, tags)); }
//Private GetTagItem private static MT GetTagItem (MultiTags CGC, string tagToCheck) { foreach (var item in CGC.localTagList) { if (string.Equals(item.Name,tagToCheck,StringComparison.CurrentCultureIgnoreCase)) { return item; } } return null; }
//HAS TAG Private private static bool HasTagPrivate (MultiTags go, string tagToCheck) { foreach (var item in go.localTagList) { //item.Name.ToLower() == tagToCheck.ToLower() if (string.Equals(item.Name,tagToCheck,StringComparison.CurrentCultureIgnoreCase)) { return true; } } return false; }
public override void OnInspectorGUI() { MultiTags myScript = (MultiTags)target; //////// GUI.color = Color.green; EditorGUILayout.LabelField("LOCAL ASSIGNED TAGS: "); GUI.color = Color.white; GUILayout.Space(10); foreach (var item in myScript.localTagList.ToArray()) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Tag: ", GUILayout.Width(40)); EditorGUILayout.SelectableLabel(item.Name, EditorStyles.textField, GUILayout.Height(EditorGUIUtility.singleLineHeight)); GUI.color = Color.red + Color.yellow; if (GUILayout.Button("Remove", GUILayout.Width(55))) { myScript.localTagList.Remove(item); } GUI.color = Color.white; EditorGUILayout.EndHorizontal(); if (!HasTagGlobal(item.Name)) { EditorGUILayout.BeginHorizontal(); GUI.color = Color.yellow; EditorGUILayout.LabelField("warning: (" + item.Name + ") is not a global tag.", GUILayout.Height(25)); GUI.color = Color.white; EditorGUILayout.EndHorizontal(); } } //////// GUI.color = Color.cyan; expandGlobals = EditorGUILayout.Foldout(expandGlobals, "GLOBAL PROJECT TAGS: "); GUI.color = Color.white; if (expandGlobals) { foreach (var itemG in GlobalTagHolder.TagHolder.GlobalTagList.ToArray()) { EditorGUILayout.BeginHorizontal(); if (myScript.gameObject.HaveTags(itemG.Name)) { GUI.color = Color.green; EditorGUILayout.LabelField("Assigned ", GUILayout.Width(55)); GUI.color = Color.white; } else { GUI.color = Color.green; if (GUILayout.Button("Assign", GUILayout.Width(55))) { myScript.localTagList.Add(itemG); } GUI.color = Color.white; } EditorGUILayout.LabelField("Tag: ", GUILayout.Width(40)); EditorGUILayout.SelectableLabel(itemG.Name, EditorStyles.textField, GUILayout.Height(EditorGUIUtility.singleLineHeight)); GUI.color = Color.red + Color.red; if (GUILayout.Button("Destroy", GUILayout.Width(55))) { GlobalTagHolder.TagHolder.GlobalTagList.Remove(itemG); GlobalTagHolder.TagHolder.Save(); } GUI.color = Color.white; EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.EndHorizontal(); } //////// } EditorGUILayout.BeginHorizontal(); tagDescription = EditorGUILayout.TextField("Tag Name: ", tagDescription); GUI.color = Color.cyan; if (GUILayout.Button("Add New Tag", GUILayout.Width(100))) { tagDescription = tagDescription.Trim(); if (string.IsNullOrEmpty(tagDescription)) { return; } MT itemLocal = new MT(); MT itemGlobal = new MT(); itemLocal.Name = tagDescription; itemGlobal.Name = itemLocal.Name; if (!HasTagGlobal(tagDescription)) { GlobalTagHolder.TagHolder.GlobalTagList.Add(itemGlobal); GlobalTagHolder.TagHolder.Save(); } if (!myScript.gameObject.HaveTags(tagDescription)) { myScript.localTagList.Add(itemLocal); } tagDescription = string.Empty; } GUI.color = Color.white; EditorGUILayout.EndHorizontal(); }