/// <summary> /// Updates the list of filtered motion types based on the search string /// </summary> /// <param name="rFilteredTypes">List to fill with the filtered types</param> /// <param name="rMasterTypes">Master list of all types</param> /// <param name="rSearchString">Search parameters</param> /// <returns></returns> public static int GetFilteredMotionTypes(List <MotionSelectType> rFilteredTypes, List <MotionSelectType> rMasterTypes, string rSearchString) { rFilteredTypes.Clear(); string[] lSearchItems = rSearchString.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); // Parse out the search values List <string> lSearchText = new List <string>(); List <string> lSearchTags = new List <string>(); for (int i = 0; i < lSearchItems.Length; i++) { string lText = lSearchItems[i]; if (lText.Length > 4 && lText.IndexOf("tag:", StringComparison.OrdinalIgnoreCase) == 0) { lText = lText.Substring(4); if (lText.Length > 0 && !lSearchTags.Contains(lText, StringComparer.OrdinalIgnoreCase)) { lSearchTags.Add(lText); } } else { if (lText.Length > 0 && !lSearchText.Contains(lText, StringComparer.OrdinalIgnoreCase)) { lSearchText.Add(lText); } } } // Generate the list of motions to display for (int i = 0; i < rMasterTypes.Count; i++) { MotionSelectType lItem = rMasterTypes[i]; if (rFilteredTypes.Contains(lItem)) { continue; } bool lAddItem = true; // First, exclude all items that don't match the tag if (lAddItem && lSearchTags.Count > 0) { for (int j = 0; j < lSearchTags.Count; j++) { if (!lItem.TypeTagArray.Contains(lSearchTags[j], StringComparer.OrdinalIgnoreCase)) { lAddItem = false; } } } // Next, exclude all items that don't match the search if (lAddItem && lSearchText.Count > 0) { for (int j = 0; j < lSearchText.Count; j++) { if (!lItem.Name.Contains(lSearchText[j], StringComparison.OrdinalIgnoreCase)) { lAddItem = false; } } } if (lAddItem) { rFilteredTypes.Add(lItem); } } return(rFilteredTypes.Count); }
/// <summary> /// Gathers the master list of items and categories /// </summary> /// <param name="rItems">MotionSelectItems that represent the motion types</param> /// <param name="rTags">Tag strings</param> /// <returns></returns> public static int GetMasterMotionTypes(List <MotionSelectType> rTypes) { Type lBaseType = typeof(MotionControllerMotion); rTypes.Clear(); //rTypeTags.Clear(); // Generate the list of motions to display Assembly lAssembly = Assembly.GetAssembly(lBaseType); Type[] lMotionTypes = lAssembly.GetTypes().OrderBy(x => x.Name).ToArray <Type>(); for (int i = 0; i < lMotionTypes.Length; i++) { Type lType = lMotionTypes[i]; if (lType.IsAbstract) { continue; } if (!lBaseType.IsAssignableFrom(lType)) { continue; } string lName = MotionNameAttribute.GetName(lType); if (lName == null || lName.Length == 0) { lName = BaseNameAttribute.GetName(lType); } string lDescription = MotionDescriptionAttribute.GetDescription(lType); if (lDescription == null || lDescription.Length == 0) { lDescription = BaseDescriptionAttribute.GetDescription(lType); } string lTypeTags = MotionTypeTagsAttribute.GetTypeTags(lType); MotionSelectType lItem = new MotionSelectType(); lItem.Type = lType; lItem.Path = lType.Name + ".cs"; //string[] lFolders = System.IO.Directory.GetFiles(Application.dataPath, lItem.Path, System.IO.SearchOption.AllDirectories); //if (lFolders.Length > 0) { lItem.Path = lFolders[0]; } lItem.Name = lName; lItem.Description = lDescription; lItem.TypeTags = lTypeTags; lItem.TypeTagArray = lTypeTags.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); rTypes.Add(lItem); //// Create the type tags //if (lItem.TypeTagArray != null) //{ // for (int j = 0; j < lItem.TypeTagArray.Length; j++) // { // bool lIsFound = false; // for (int k = 0; k < rTypeTags.Count; k++) // { // if (string.Compare(rTypeTags[k].Tag, lItem.TypeTagArray[j], true) == 0) // { // lIsFound = true; // break; // } // } // if (!lIsFound) // { // MotionSelectTypeTag lTypeTag = new MotionSelectTypeTag(); // lTypeTag.Tag = lItem.TypeTagArray[j]; // rTypeTags.Add(lTypeTag); // } // } //} } return(rTypes.Count); }