public static List <GameObject> Find <C1, C2, C3, C4>() where C1 : Component where C2 : Component where C3 : Component where C4 : Component { TypeComposit <Type, int> key; retObjects.Clear(); key = new TypeComposit <Type, int>(typeof(C1), 0); CompareComponents(key); List <GameObject> temp1 = retObjects.Keys.ToList(); key = new TypeComposit <Type, int>(typeof(C2), 0); CompareComponents(key); List <GameObject> temp2 = retObjects.Keys.ToList(); List <GameObject> tempInbetween = temp1.Intersect(temp2).ToList(); key = new TypeComposit <Type, int>(typeof(C3), 0); CompareComponents(key); List <GameObject> temp3 = retObjects.Keys.ToList(); List <GameObject> tempInbetween1 = tempInbetween.Intersect(temp3).ToList(); key = new TypeComposit <Type, int>(typeof(C4), 0); CompareComponents(key); List <GameObject> temp4 = retObjects.Keys.ToList(); List <GameObject> finalList = tempInbetween1.Intersect(temp4).ToList(); return(finalList); //return retObjects.Keys.ToList(); }
public static List <GameObject> Find <C1>() where C1 : Component { TypeComposit <Type, int> key; retObjects.Clear(); key = new TypeComposit <Type, int>(typeof(C1), 0); CompareComponents(key); return(retObjects.Keys.ToList()); }
/// <summary> /// Register the specified service instance. Usually called in Awake(), like this: /// Set<ExampleService>(this); /// </summary> /// <param name="service">Service instance object.</param> /// <typeparam name="T">Type of the instance object.</typeparam> public static void Register(Type compType, GameObject go) { TypeComposit <Type, int> key = new TypeComposit <Type, int>(compType, 0); if (instance.allObjects.ContainsKey(key)) { // // increase the count and add the composit key // key = new TypeComposit <Type, int>(compType, instance.allObjects.Count); } instance.allObjects.Add(key, go); }
/// <summary> /// Remove a component and its game object from the collection /// </summary> /// <param name="component"></param> /// <param name="gameObject"></param> public static void Remove(Type compType, GameObject go) { TypeComposit <Type, int> key = new TypeComposit <Type, int>(compType, 0); // // if the partial key is found by type, then remove // if (instance.allObjects.ContainsKey(key)) { foreach (KeyValuePair <TypeComposit <Type, int>, GameObject> val in instance.allObjects) { if ((val.Key.CompType == key.CompType) & (val.Value == go)) { instance.allObjects.Remove(key); } } } }
public static List <GameObject> Find <C1, C2>() where C1 : Component where C2 : Component { TypeComposit <Type, int> key; retObjects.Clear(); //Dictionary<GameObject, int> retObjects = new Dictionary<GameObject, int>(); key = new TypeComposit <Type, int>(typeof(C1), 0); CompareComponents(key); List <GameObject> temp1 = retObjects.Keys.ToList(); key = new TypeComposit <Type, int>(typeof(C2), 0); CompareComponents(key); List <GameObject> temp2 = retObjects.Keys.ToList(); return(temp1.Intersect(temp2).ToList()); //return retObjects.Keys.ToList() ; }
private static void CompareComponents(TypeComposit <Type, int> key) { // // if the partial key is found by type, then get all GameObjects that // have the type, We will end up with a List that has once occurance // of each GameObject // //if (instance.allObjects.ContainsKey(key)) //{ foreach (KeyValuePair <TypeComposit <Type, int>, GameObject> val in instance.allObjects) { if (val.Key.CompType == key.CompType) { if (!retObjects.ContainsKey(val.Value)) //if GameObject is NOT present { retObjects.Add(val.Value, 0); // then add it } } } //} }