/// <summary> /// Generates a crowd with the given arguments. /// </summary> /// <param name="criteria">The crowd's criteria</param> /// <param name="isStatic">Are the crowd's members static?</param> /// <param name="collection">The crowd's event scheduler.</param> public SmartCrowd GenerateCrowd(ISmartCrowdCriteria criteria, bool isStatic, EventCollection collection) { SmartCrowd instance = new GameObject(NamePrefix + currentCrowdIndex).AddComponent<SmartCrowd>(); instance.tag = "Smart Object"; if (Parent != null) { instance.transform.parent = Parent.transform; } instance.Initialize(criteria, isStatic, collection); instance.Portrait = GetPortrait(currentCrowdIndex); currentCrowdIndex++; return instance; }
/// <summary> /// Gets all the SmartObjects satisfying the given criteria, using the known satisfiers given in existingSatisfiers as base. Modifies this set /// and then returns it. /// </summary> public static HashSet<SmartObject> AllSatisfyingCriteria(ISmartCrowdCriteria criteria, HashSet<SmartObject> existingSatisfiers) { foreach (SmartObject obj in ObjectManager.Instance.GetObjects()) { if (!(obj is SmartCrowd) && criteria.SatisfiesCriteria(obj)) { existingSatisfiers.Add(obj); } } toRemove.Clear(); foreach (SmartObject obj in existingSatisfiers) { if (!criteria.SatisfiesCriteria(obj)) { toRemove.Add(obj); } } foreach (SmartObject obj in toRemove) { existingSatisfiers.Remove(obj); } return existingSatisfiers; }
/// <summary> /// Opens the window to create a new EventScheduler for the selected crowd. /// </summary> private void CreateEventScheduler(ISmartCrowdCriteria criteria) { EventSchedulerWindow schedulerSetup = new EventSchedulerWindow(); mainArea = schedulerSetup; notificationBar = new NotificationBar("You have selected a crowd. See the game view for the contained objects. You can now create an EventScheduler for the crowd or cancel."); MouseHandler.GetInstance().DeregisterDragEvents(crowdRectangleSelectAction); MouseHandler.GetInstance().DeregisterDragEvents(drawRectangleAction); ActionBar.AddButton("Set And Save Scheduler", () => { Debug.Log("Exectuting Set and save"); CrowdGenerator.Instance.GenerateCrowd(criteria, crowdStatic, schedulerSetup.ToEventCollection(true)); Reset(); }); ActionBar.AddButton("Set Scheduler", () => { CrowdGenerator.Instance.GenerateCrowd(criteria, crowdStatic, schedulerSetup.ToEventCollection(false)); Reset(); }); }
/// <summary> /// Gets all SmartObjects satisfying the given criteria. /// </summary> public static HashSet<SmartObject> AllSatisfyingCriteria(ISmartCrowdCriteria criteria) { return AllSatisfyingCriteria(criteria, new HashSet<SmartObject>()); }