/// <summary> /// Handles end of conflict events if user chooses to do so. /// </summary> private void handleEndConflicts(ConflictEndMode mode, TrackedObjectStates tos) { switch (mode) { case ConflictEndMode.OnIndividualConflictEnded: //find conflicts that have partially or completely ended and inform agents monitoring int numStates = tos.ParentIDLeavers.Length; for (int endParentID = 0; endParentID < numStates; endParentID++) { int parentID = tos.ParentIDLeavers[endParentID]; TrackedObjectData TOData; // = TrackedObjectDataRef[parentID]; if (TrackedObjectDataRef.TryGetValue(parentID, out TOData)) { int numConflicts = tos.LeavingIDs[endParentID].Length; // allocate arrays for conflict data GameObject[] leavers = new GameObject[numConflicts]; string[] conflictorAffiliations = new string[numConflicts]; // fill conflict data for (int i = 0; i < numConflicts; i++) { int m = TrackedObjectStates.LeavingIDs[endParentID][i]; leavers[i] = gameObjectReference[m]; conflictorAffiliations[i] = TrackedObjectAffiliations[m]; } //inform the agents monitoring this object foreach (WorldMonitors wm in TOData.ObjectOwners) { wm.RaiseConflictLeavers(TOData.Object, leavers, conflictorAffiliations); } } } break; case ConflictEndMode.OnAllConflictsEnded: //find conflicts that have completely ended and inform the agents monitoring foreach (int endParentID in TrackedObjectStates.PriorConflictingIDs) { TrackedObjectData TOData; if (TrackedObjectDataRef.TryGetValue(endParentID, out TOData)) // preserve the ability to have non-owned tracked objects { if (TOData.ObjectOwners.Count > 0) { foreach (WorldMonitors wm in TOData.ObjectOwners) { wm.EndConflicts(gameObjectReference[endParentID]); } } } } break; } }
// MonoBehaviour method private void OnTriggerExit(Collider other) { ConflictEndMode cem = WorldMonitor.Instance.ConflictEndMode; if (cem == ConflictEndMode.NoConflictEndEvents) { return; } if (other.gameObject) { GameObject[] goPass = new GameObject[1]; goPass[0] = other.gameObject; int childID; int parentID; if (WorldMonitor.Instance.GameObjectIDReference.TryGetValue(goPass[0], out childID)) // not all gameObjects may be in tracking system { if (!WorldMonitor.Instance.GameObjectIDReference.TryGetValue(gameObject, out parentID)) { Debug.LogError("TrackedObjectTriggers cannot be used on objects not located in a field of a WorldMonitors instance"); } insiders--; string[] sPass = new string[1]; sPass[0] = WorldMonitor.Instance.TrackedObjectAffiliations[childID]; if (string.Compare(WorldMonitor.Instance.TrackedObjectAffiliations[TrackedObjectID], sPass[0]) != 0) { if (cem == ConflictEndMode.OnAllConflictsEnded && insiders > 0) { return; } // else: both OnAll and OnIndividual modes will be handled the same from here out foreach (WorldMonitors wm in wms) { wm.RaiseConflictLeavers(gameObject, goPass, sPass); } } } } }