/// <summary> /// Gets a random GameObject from the suit (which has a HapticLocation) that is within the set of potential areas. /// You can request 'AreaFlag.Right_All' to get any random right area. /// </summary> /// <param name="setOfPotentialAreas">Please </param> /// <returns>A game object within the random set. Can be null if you ask for AreaFlag.None or for spots that aren't on your configured body.</returns> public GameObject GetRandomLocationWithinSet(AreaFlag setOfPotentialAreas) { //TODO: Refactor this //Give me a random area flag within the set of area flag. //Apply filter to that set. //Then get the index of that area. var limitedAreas = DefinedAreas.Where(x => setOfPotentialAreas.HasFlag(x)); int index = Random.Range(0, limitedAreas.Count()); if (limitedAreas.Count() > 0) { int sceneReferenceIndex = DefinedAreas.IndexOf(limitedAreas.ElementAt(index)); //Debug.Log("Rand Loc: " + index + " of " + limitedAreas.Count() + " " + limitedAreas.ElementAt(index).ToString() + " " + DefinedAreas.IndexOf(limitedAreas.ElementAt(index)) + "\n" + SceneReferences[sceneReferenceIndex].name); //This is not possible. //if (index > regions.Count) //{ //} //else if (SceneReferences[sceneReferenceIndex] == null) { Debug.LogError("Attempted to get Random Location inside HardlightSuit's SuitDefinition.\n\tNo locations should be null. Check to make sure the fields in the Body Mimic prefab were assigned."); } else { return(SceneReferences[sceneReferenceIndex].Representation); } } return(null); }
private void TestAreaFlagExtensions() { //This section digs into some of the AreaFlagExtension methods. string Report = "[AreaFlag Tests]\n" + "\t[Number of Areas/Single Area Tests]\n\n"; AreaFlag flag = AreaFlag.Mid_Ab_Left; Report += "How many flags in Mid Ab Left [1]:" + flag.NumberOfAreas() + " - is single area? [T] " + flag.IsSingleArea() + "\n"; flag = AreaFlag.Back_Both; Report += "How many flags in Mid Ab Left [2]: " + flag.NumberOfAreas() + " - is single area? [F] " + flag.IsSingleArea() + "\n"; flag = (AreaFlag.All_Areas).RemoveArea(AreaFlag.Back_Both); Report += "How many flags in All but Back Both [14]: " + flag.NumberOfAreas() + " - is single area? [T] " + flag.IsSingleArea() + "\n"; flag = AreaFlag.Right_All; Report += "How many flags in Right All [8]: " + flag.NumberOfAreas() + " - is single area? [T] " + flag.IsSingleArea() + "\n\n"; flag = AreaFlag.All_Areas; Report += "AreaFlag HasFlag Tests:\nDoes All_Areas contain Lower Left Ab? (T): " + flag.HasFlag(AreaFlag.Lower_Ab_Left) + "\nDoes All_Areas contain Right_All? (T): " + flag.HasFlag(AreaFlag.Right_All) + "\nDoes Right_All contain Back_Both? (F): " + AreaFlag.Right_All.HasFlag(AreaFlag.Back_Both) + "\n"; Debug.Log(Report); }
/// <summary> /// Breaks a multiple AreaFlag into a list of Single AreaFlags /// Ex: Multi Area Flag = AreaFlag.Forearm_Left|AreaFlag.Forearm_Right /// Return: {AreaFlag.Forearm_Left, AreaFlag.Forearm_Right /// </summary> /// <param name="baseFlag">The flag to be evaluated.</param> /// <returns>Retusn an array of single AreaFlags. Will not include None, Boths or All AreaFlag values.</returns> public static AreaFlag[] ToArray(this AreaFlag baseFlag) { AreaFlag[] values = baseFlag.AllSingleAreasInEnum(); List <AreaFlag> has = new List <AreaFlag>(); for (int i = 0; i < values.Length; i++) { if (baseFlag.HasFlag(values[i])) { has.Add(values[i]); } } // //if (has.Count < 1) //{ // has.Add(AreaFlag.None); //} return(has.ToArray()); }