/// <summary> /// Interrupts the charge and calls related event. /// </summary> public void StopCharge() { data.enemyMovementBehaviour.ResetMoveDirection(); data.enemyMovementBehaviour.ResetMoveSpeed(); data.enemyMovementBehaviour.StopAllCoroutines(); OnChargeEnd.Invoke(0.1f); }
protected IEnumerator LoadAdditiveSceneAsync(SceneModel desired, float progressModifier = 1f) { AsyncOperation loadOp = SceneManager.LoadSceneAsync(desired.SceneName, LoadSceneMode.Additive); if (loadOp == null) { Debug.LogError("Failed to load scene: " + desired.SceneName); yield break; } float previousProgress = 0f; while (!loadOp.isDone) { float progress = loadOp.progress * progressModifier; if (progress != previousProgress) { onLoadProgressChanged.Invoke(progress); } previousProgress = progress; yield return(null); } Debug.Log("Loaded new scene: " + desired.SceneName); }
public override void Start() { if (ThrowEventOnStart) { OnValueChangedEvent.Invoke(CurrentValue); OnValueChanged?.Invoke(CurrentValue); } }
public void Heal(float hpGained) { // check for overhealing if ((hpGained + playerCurrentHealth) <= playerMaxHealth) { // add shield mechanic here } // add hp playerCurrentHealth += hpGained; // give it a clamp playerCurrentHealth = Mathf.Clamp(playerCurrentHealth, 0, playerMaxHealth); OnHealthChange.Invoke(playerCurrentHealth); }
protected virtual void Start() { statsContainer = GetComponent <StatsContainer>(); currentHealth = MaxHealth; onHealthChange?.Invoke(currentHealth); onMaxHealthChange?.Invoke(MaxHealth); onHealthPercentageChange?.Invoke(CalculateHealthPercentage()); onSpawn?.Invoke(this); }
IEnumerator Tweening() { float count = 0; while (count < duration) { onValueChanged.Invoke(count / duration); count += Time.deltaTime; yield return(null); } onValueChanged.Invoke(1); onTweenCompleted.Invoke(); coroutine = null; }
private IEnumerator TextUpdateIE() { yield return(new WaitForEndOfFrame()); textHeight = Mathf.Max(tmp.renderedHeight, 0f); newTextHeightEvent.Invoke(textHeight); }
public void CallEvents() { switch (m_type.ToLower()) { case "int": case "integer": m_intEvent.Invoke(GetIntValue()); break; case "float": case "real": m_floatEvent.Invoke(GetFloatValue()); break; case "string": case "text": m_stringEvent.Invoke(GetStringValue()); break; case "bool": case "boolean": m_boolEvent.Invoke(GetBoolValue()); break; default: break; } m_optionEvent.Invoke(this); }
protected void Move(Vector3 direction, float moveSpeed) { if (direction.magnitude < 0.01f) { return; } Vector3 destination = GetAjustedDestination(direction); Vector3 trueDirection = (destination - playerRef.transform.position); if (!HasWallCollision(trueDirection)) { //Vector3 destination = GetAjustedDestination(direction); //playerRef.transform.position += direction * moveSpeed * Time.deltaTime; playerRef.transform.position += trueDirection * moveSpeed * Time.deltaTime; //playerRef.transform.position += trueDirection * moveSpeed * Time.fixedDeltaTime; } else { float angle = 55; bool tryRightAngle = TryDirection(angle, moveSpeed); if (!tryRightAngle) { TryDirection(-angle, moveSpeed); } } OnWalkEvent.Invoke(direction.magnitude); }
/// <summary> /// Modifies the health by the amount given. /// </summary> /// <param name="amount">amount to modify health by</param> internal void ModifyHealth(int amount) { if (amount == 0 || CurrentHealth <= 0) { return; } if (CanExceedMaximumHealth) { CurrentHealth += amount; } else { CurrentHealth = Mathf.Clamp(CurrentHealth + amount, 0, MaximumHealth); } OnHealthPercentChanged?.Invoke(NormalizedCurrentHealth); if (CurrentHealth <= 0) { CurrentHealth = 0; OnHealthEmpty.Invoke(); return; } if (amount > 0) { OnHealthGained?.Invoke(CurrentHealth); } else { OnHealthLost?.Invoke(CurrentHealth); } }
// Use this for initialization void Start() { if (isLocalPlayer) { var cinemachine = GameObject.FindGameObjectWithTag("Cinemachine"); cinemachine.GetComponent <Cinemachine.CinemachineVirtualCamera>().Follow = transform; var canvas = GameObject.FindGameObjectWithTag("UI"); uiController = canvas.GetComponent <UIController>(); HPChanged.AddListener(uiController.HPUpdate); HPChanged.Invoke(Health, MaxHealth); ResourcesChanged.AddListener(uiController.ResourceUpdate); ResourcesChanged.Invoke(ResourceTanks, TankCapacity); } }
public void BallBounce() { score += ballBounceScore; if (OnBallBounce != null) { OnBallBounce.Invoke(ballBounceScore); } }
public void BrickHit() { score += brickHitScore; if (OnBrickHit != null) { OnBrickHit.Invoke(brickHitScore); } }
public void BallLost() { score += lostBallScore; if (OnBallLost != null) { OnBallLost.Invoke(lostBallScore); } }
public void OnEventRaised(float value) { FloatEvent floatEvent = gameEvent as FloatEvent; if (floatEvent) { floatResponse.Invoke(value); } }
public void Damage(float value) { currentLife -= value; OnLifeChanged.Invoke(currentLife); OnLifeChangedPercent.Invoke(currentLife / maxLife); if (currentLife <= 0) { OnLifeDepeleated.Invoke(); } }
public void Raycast(Ray ray) { RaycastHit hit; //If we get hit if (MyCollider.Raycast(ray, out hit, float.MaxValue)) { //calculate a new look value HitThisFrame = true; float LookValueBefore = LookValue; LookValue += Time.deltaTime / TimeToTrigger; LookValue = Mathf.Clamp01(LookValue); //if it changed if (LookValue != LookValueBefore) { //check if we're finished, trigger if so if (LookValue == 1f) { if (OnTrigger != null) { OnTrigger.Invoke(); } } //check if we should be hovering if (!Hovering) { if (OnHoverDown != null) { OnHoverDown.Invoke(); } Hovering = true; } //finally, output the new look value if (OnLookValueChanged != null) { OnLookValueChanged.Invoke(LookValue); } } } }
protected virtual void Update() { _currentTime += Time.deltaTime; OnTimer.Invoke(timer - _currentTime); OnNormalizedTimer.Invoke(_currentTime / timer); if (_currentTime >= timer) { OnTimerEnd.Invoke(); enabled = false; } }
private void BroadcastMouseX() { if (MouseXEvent == null) { return; } float x = Input.GetAxis("Mouse X"); MouseXEvent.Invoke(x); }
private void BroadcastMouseY() { if (MouseYEvent == null) { return; } float y = Input.GetAxis("Mouse Y"); MouseYEvent.Invoke(-y); }
private void BroadcastRight() { if (RightPressed == null) { return; } float right = Input.GetAxis("Horizontal"); RightPressed.Invoke(right); }
private void BroadcastForward() { if (ForwardPressed == null) { return; } float fwd = Input.GetAxis("Vertical"); ForwardPressed.Invoke(fwd); }
/// <summary> /// Preloads the main Scene. You can call <see cref="Activate"/> after this method has returned to activate the Scene. /// </summary> /// <returns></returns> public IEnumerator PreloadAsync() { if (_loading == null) { _loading = SceneManager.LoadSceneAsync(mainSceneToLoad.ScenePath); _loading.allowSceneActivation = false; } while (_loading.progress < ReadyToActivateProgress) { float reportedProgress = Mathf.Clamp01(_loading.progress / ReadyToActivateProgress); try { onProgress.Invoke(reportedProgress); } catch (Exception e) { Debug.LogException(e); } yield return(null); } try { onProgress.Invoke(1); } catch (Exception e) { Debug.LogException(e); } try { onReadyToActivate.Invoke(); } catch (Exception e) { Debug.LogException(e); } }
public void Increment() { ++_count; if (_count >= maxCount && !completed) { completed = true; onCountComplete.Invoke(); } var ratio = Mathf.Clamp01((float)_count / (float)maxCount); onPercentCahnged.Invoke(ratio); }
// Update is called once per frame void Update() { if (CurrentTime >= timer) { enabled = _restartOnEnd; OnTimerEnd.Invoke(); ResetTimer(); return; } CurrentTime += Time.deltaTime; OnTimerUpdate.Invoke(timer - CurrentTime); }
/// <summary> /// Adds amount to health and then to the shield if there is still an amount remaining. Will not go over the maximum health or shield value. /// </summary> /// <param name="amount">The amount of health or shield to add.</param> /// <returns>True if the object was healed.</returns> public virtual bool Heal(float amount) { #if ULTIMATE_CHARACTER_CONTROLLER_MULTIPLAYER if (m_NetworkInfo != null && m_NetworkInfo.IsLocalPlayer()) { m_NetworkHealthMonitor.Heal(amount); } #endif var healAmount = 0f; // Contribute the amount of the health first. if (m_HealthAttribute != null && m_HealthAttribute.Value < m_HealthAttribute.MaxValue) { var healthAmount = Mathf.Min(amount, m_HealthAttribute.MaxValue - m_HealthAttribute.Value); amount -= healthAmount; m_HealthAttribute.Value += healthAmount; healAmount += healthAmount; } // Add any remaining amount to the shield. if (m_ShieldAttribute != null && amount > 0 && m_ShieldAttribute.Value < m_ShieldAttribute.MaxValue) { var shieldAmount = Mathf.Min(amount, m_ShieldAttribute.MaxValue - m_ShieldAttribute.Value); m_ShieldAttribute.Value += shieldAmount; healAmount += shieldAmount; } // Don't play any effects if the object wasn't healed. if (healAmount == 0) { return(false); } // Play any heal audio. m_HealAudioClipSet.PlayAudioClip(m_GameObject); EventHandler.ExecuteEvent <float>(m_GameObject, "OnHealthHeal", healAmount); if (m_OnHealEvent != null) { m_OnHealEvent.Invoke(healAmount); } if (m_DamagePopupManager != null) { m_DamagePopupManager.OpenHealPopup(m_Transform.position, amount); } return(true); }
IEnumerator PlaceTimeRoutine() { float timer = 0; counting = true; OnPlaceTimeStart.Invoke(waveData.placeTime); while (counting == true && timer < waveData.placeTime) { timer += Time.deltaTime; yield return(null); } OnPlaceTimeEnd.Invoke(); }
public void SetYPosition(float height) { float yp = y_reference; if (rect_reference != null) { yp += rect_reference.localPosition.y; } if (!inverse) { transform.localPosition = new Vector3(transform.localPosition.x, yp + height + spacerDistance); } else { transform.localPosition = new Vector3(transform.localPosition.x, yp - height + spacerDistance); } yTransformEvent.Invoke(transform.localPosition.y); }
public void SendContent() { switch (contentType) { case ParseTarget.Int: IntEvent.Invoke(int.Parse(buttonText.text)); break; case ParseTarget.Float: FloatEvent.Invoke(float.Parse(buttonText.text)); break; case ParseTarget.String: StringEvent.Invoke(buttonText.text); break; default: break; } }
void HandleSelection() { GameObject handler; try { handler = ExecuteEvents.GetEventHandler <IPointerClickHandler>(pointerEventData.pointerEnter); var selectable = handler.GetComponent <Selectable>(); if (selectable && selectable.interactable == false) { throw new NullReferenceException(); } } catch (NullReferenceException) { currentTarget = null; StopHovering(); return; } if (currentTarget != handler) { var gazeTime = settings.GazeTime; currentTarget = handler; currentTargetClickTime = Time.realtimeSinceStartup + gazeTime; if (hovering) { StopHovering(); } hovering = true; onStartHover?.Invoke(gazeTime); } if (Time.realtimeSinceStartup > currentTargetClickTime || Input.GetButtonDown(settings.ClickInput)) { ExecuteEvents.ExecuteHierarchy(currentTarget, pointerEventData, ExecuteEvents.pointerClickHandler); currentTargetClickTime = float.MaxValue; onClick?.Invoke(); StopHovering(); } }