/// <summary> /// Renders a pulsing ripple effect over a target. /// </summary> /// <param name="target">Location to put ripple effect.</param> /// <param name="mouseDown">If a mouse has been pressed, but not yet released.</param> public void TriggerPulseOnTarget(Vector3 target, bool isMouseDown) { if (!AutomatedQARuntimeSettings.ActivatePlaybackVisualFx || !AutomatedQARuntimeSettings.ActivateClickFeedbackFx) { return; } // Drag events also use mouseup logic, so if we were dragging and just released the click, don't also create a click pulse. if (lastFxEventType == FxEventType.Drag && !isMouseDown && ActivePulseManagers.Any()) { ActivePulseManagers.Last().KillEarly(true); // Remove the IsMouseDown pulse that is currently holding (waiting for mouse release). return; // We don't want a pulse/ripple effect either at the mousedown location or mouseup location of a drag event. } lastFxEventType = FxEventType.Click; if (ActivePulseManagers.Any() && ActivePulseManagers.Last().IsMouseDown) { ActivePulseManagers.Last().Init(target, false); } else { // The number of pulses to immediately remove is the difference between the total active pulses and the requested count, plus the one pulse we are about to create. Or plus zero if we are not creating a new pulse, but triggering the last one to animate. int killImmediateCount = ActivePulseManagers.Count + 1 - maxPulsesOnScreenAtOnce; int index = 0; // Stop pulsing of any existing PulseManagers. while (index < ActivePulseManagers.Count) { PulseManager pm = ActivePulseManagers[index]; if (pm == null || !pm) { ActivePulseManagers.RemoveAt(index); continue; } bool killImmediately = killImmediateCount > 0 && index + 1 <= killImmediateCount; if (killImmediately) { pm.GetComponent <PulseManager>().KillEarly(true); killImmediateCount--; } else { pm.GetComponent <PulseManager>().KillEarly(false); index++; } } GameObject pulseManagerGo = VisualFxCanvases[0]; pulseManagerGo.SetActive(true); pulseManagerGo.transform.SetParent(visualFxGo.transform, false); PulseManager pulseManager = pulseManagerGo.GetComponent <PulseManager>(); pulseManager.enabled = true; pulseManager.Init(target, isMouseDown); ActivePulseManagers.Add(pulseManager); VisualFxCanvases.RemoveAt(0); } }
/// <summary> /// Return ring GameObject to the pool for later use. /// </summary> /// <param name="ring"></param> public static void ReturnVisualFxCanvas(GameObject canvasObj) { PulseManager pm = canvasObj.GetComponent <PulseManager>(); pm.enabled = false; canvasObj.transform.SetParent(canvasPoolGo.transform); canvasObj.SetActive(false); if (ActivePulseManagers.FindAll(x => x == pm).Any()) { ActivePulseManagers.Remove(ActivePulseManagers.Find(x => x == pm)); } VisualFxCanvases.Add(canvasObj); }