/// <summary> /// When the camea enters the proximity's collider zone /// </summary> /// <param name="e">The Gaze_ProximityEventArgs</param> private void onProximityEvent(Gaze_ProximityEventArgs e) { if (gazable != null && e.Sender.Equals(gazable.Root)) { isInProximity = e.IsInProximity; } }
private void OnProximityEvent(Gaze_ProximityEventArgs e) { if (e.Sender.Equals(gazeConditionsScript.RootIO)) { IsInProximity = e.IsInProximity; } IsValid = HandleProximity(e); }
/// <summary> /// Checks the proximities conditions validity. /// </summary> /// <returns><c>true</c>, if proximities was checked, <c>false</c> otherwise.</returns> /// <param name="e">E.</param> private bool HandleProximity(Gaze_ProximityEventArgs e) { // get colliding objects Gaze_InteractiveObject sender = ((Gaze_InteractiveObject)e.Sender).GetComponentInChildren <Gaze_Proximity>().IOScript; Gaze_InteractiveObject other = ((Gaze_InteractiveObject)e.Other).GetComponentInChildren <Gaze_Proximity>().IOScript; // make sure the collision concerns two objects in the list of proximities (-1 if NOT) int otherIndex = IsCollidingObjectsInList(other, sender); // Debug.Log ("otherIndex = " + otherIndex); if (otherIndex != -1) { // OnEnter and tested only if validation is not already true (to avoid multiple collision to toggle the proximitiesValidated flag if (e.IsInProximity && !IsValid) { // update number of collision in the list occuring collisionsOccuringCount++; // if the sender is normal entry, add colliding object to it if (otherIndex > -1) { gazeConditionsScript.proximityMap.AddCollidingObjectToEntry(gazeConditionsScript.proximityMap.proximityEntryList[otherIndex], sender.GetComponentInChildren <Gaze_Proximity>().IOScript); } // if the sender is an entryGroup (then otherIndex starts at -2 and goes down instead of going up), add colliding object to the entry of the group that triggered the event else { gazeConditionsScript.proximityMap.AddCollidingObjectToEntry(gazeConditionsScript.proximityMap.proximityEntryGroupList[-otherIndex - 2].proximityEntries[entryInGroupIndex], sender.GetComponentInChildren <Gaze_Proximity>().IOScript); } if (gazeConditionsScript.proximityMap.proximityStateIndex.Equals((int)ProximityEventsAndStates.OnEnter) || gazeConditionsScript.proximityMap.proximityStateIndex.Equals((int)ProximityEventsAndStates.OnStay)) { // get number of valid entries int validatedEntriesCount = gazeConditionsScript.proximityMap.GetValidatedEntriesCount(); // OnEnter + RequireAll if (gazeConditionsScript.requireAllProximities) { return(validatedEntriesCount == gazeConditionsScript.proximityMap.proximityEntryList.Count + gazeConditionsScript.proximityMap.proximityEntryGroupList.Count); } // OnEnter + NOT RequireAll if (!gazeConditionsScript.requireAllProximities) { return(validatedEntriesCount >= 2); } } } // OnExit else if (!e.IsInProximity) { // update number of collision in the list occuring collisionsOccuringCount--; // update everyoneIsColliding tag before removing an element gazeConditionsScript.proximityMap.UpdateEveryoneColliding(); if (otherIndex > -1) { // // if the sender is normal entry, remove colliding object to it gazeConditionsScript.proximityMap.RemoveCollidingObjectToEntry(gazeConditionsScript.proximityMap.proximityEntryList[otherIndex], sender.GetComponentInChildren <Gaze_Proximity>().IOScript); } else { // if the sender is an entryGroup (then otherIndex starts at -2 and goes down instead of going up), remove colliding object to the entry of the group that triggered the event gazeConditionsScript.proximityMap.RemoveCollidingObjectToEntry(gazeConditionsScript.proximityMap.proximityEntryGroupList[-otherIndex - 2].proximityEntries[entryInGroupIndex], sender.GetComponentInChildren <Gaze_Proximity>().IOScript); } // if proximity condition is EXIT if (gazeConditionsScript.proximityMap.proximityStateIndex.Equals((int)ProximityEventsAndStates.OnExit)) { if (gazeConditionsScript.requireAllProximities) { // every entry was colliding before the exit if (gazeConditionsScript.proximityMap.IsEveryoneColliding) { IsValid = true; } else { IsValid = false; } // OnExit + NOT RequireAll } else { gazeConditionsScript.proximityMap.ResetEveryoneColliding(); IsValid = true; } // if proximity condition is ENTER } else { // if proximities was validated if (IsValid) { // and if require all if (gazeConditionsScript.requireAllProximities) { return(false); } else { // check there's a valid collision left in the list... if (collisionsOccuringCount > 0) { IsValid = true; } else { IsValid = false; } } } } } } return(IsValid); }
/// <summary> /// Method called when a proximity events occur. /// </summary> /// <param name="e">event arguments</param> protected abstract void onProximityEvent(Gaze_ProximityEventArgs e);