/// <summary> /// Handle the raycastHits to check if one object was clicked /// </summary> /// <param name="hits">The list of RaycastHits to check</param> /// <param name="hasClicked">the BoolVariable to set if something got clicked</param> /// <param name="objectClicked">The GameEvent to raise with the transform of the hit</param> private void HandleClick(List <RaycastHit> hits, BoolVariable hasClicked, GameEventTransform objectClicked) { foreach (var hit in hits) { if (hit.collider.gameObject.layer != pointerRayCast.ExclusionLayer) { var hitTransform = hit.collider.transform; hasClicked.SetValue(true); objectClicked.Raise(hitTransform); return; } } }
/// <summary> /// Handle the raycastHits to check if one object was clicked /// </summary> /// <param name="hits">The list of RaycastHits to check</param> /// <param name="hasClicked">the BoolVariable to set if something got clicked</param> /// <param name="objectClicked">The GameEvent to raise with the transform of the hit</param> private void HandleClick(RaycastHitVariable hit, BoolVariable hasClicked, GameEventTransform objectClickedEvent) { //If nothing is hit, we set the isOver value to false if (hit.isNull) { hasClicked.SetValue(false); } else { if (hit.Value.collider != null) { hasClicked.SetValue(true); objectClickedEvent.Raise(hit.Value.collider.transform); } } }
/// <summary> /// Handle the raycastHits to check if one of them touch something /// </summary> /// <param name="isOver">the BoolVariable to set if something got hit</param> /// <param name="hit">The Hit Point where the raycast collide</param> /// <param name="objectOver">The GameEvent to raise with the transform of the hit</param> private void HandleOver(BoolVariable isOver, RaycastHitVariable hit, GameEventTransform objectOver) { //If nothing is hit, we set the isOver value to false if (hit.isNull) { isOver.SetValue(false); } else { if (hit.Value.collider != null) { var hitTransform = hit.Value.collider.transform; objectOver.Raise(hitTransform); isOver.SetValue(true); } } }
/// <summary> /// Set the Event and response of the GameEventListeners passed in parameter, and register it int he gameEvent corresponding /// A GameEventListenerTransform is used as we check the transfrom of the object that was clicked /// </summary> /// <param name="gameEvent">The game Event to listen to</param> /// <param name="listener">The listener of the gameEvent that need to be set</param> /// <returns>The new version of the GameEventListenerTransform</returns> public GameEventListenerTransform SetGameEventClickListener(GameEventTransform gameEvent, GameEventListenerTransform listener) { listener.Event = gameEvent; listener.Response = new ScriptableFramework.Events.UnityEvents.EventTransform(); // Add the listener to the gameEvent if it wasn't there yet if (!gameEvent.GetListeners().Contains(listener)) { gameEvent.RegisterListener(listener); } if (listener.Event.name.ToLower().Contains("click")) { listener.Response.AddListener(delegate { _CheckObjectClick(listener.Value); }); } else { listener.Response.AddListener(delegate { _CheckObjectOver(listener.Value); }); } return(listener); }
/// <summary> /// Handle the raycastHits to check if one of them touch something /// </summary> /// <param name="hits">The list of RaycastHits to check</param> /// <param name="isOver">the BoolVariable to set if something got hit</param> /// <param name="hitPoint">The Hit Point where the raycast collide</param> /// <param name="objectOver">The GameEvent to raise with the transform of the hit</param> private void HandleOver(List <RaycastHit> hits, BoolVariable isOver, RaycastHitVariable hitPoint, GameEventTransform objectOver) { //If nothing is hit, we set the hasHit value to false if (hits.Count == 0) { isOver.SetValue(false); } else { foreach (var hit in hits) { // If something is hit and is not from the Exclusion layer, we set everything and return if (hit.collider.gameObject.layer != pointerRayCast.ExclusionLayer) { var hitTransform = hit.collider.transform; isOver.SetValue(true); hitPoint.SetValue(hit); objectOver.Raise(hitTransform); return; } //If the only hit was on the exclusion layer, we set the hasHit value to false else { isOver.SetValue(false); } } } }
/// <summary> /// Check if the listener passed as reference exist, disable and unregister it if it's the case. /// </summary> /// <param name="listener">The listener to check and disable</param> /// <param name="gameEvent">the GameEvent that Registered the listener at runtime</param> /// <returns>The Listener after being disabled</returns> public GameEventListenerTransform DeactivateListener(GameEventListenerTransform listener, GameEventTransform gameEvent) { if (listener) { gameEvent.UnregisterListener(listener); listener.OnDisable(); } return(listener); }