private void Start() { j_Interactable = GetComponent <JMRInteractable>(); if (j_Interactable) { j_Interactable.SwipeLeft += OnHorizontalSwipe; j_Interactable.SwipeRight += OnHorizontalSwipe; j_Interactable.SwipeUp += OnVerticalSwipe; j_Interactable.SwipeDown += OnVerticalSwipe; } else { throw new MissingComponentException("Interactable component missing from the object"); } if (JMRPointerManager.Instance != null) { j_RaycastCam = JMRPointerManager.Instance.UIRaycastCamera; } else { throw new MissingComponentException("Raycast Camera component missing from the Scene"); } j_SliderRect = GetComponent <RectTransform>(); j_SliderStartDistance = j_SliderRect.rect.xMin; j_SliderEndDistance = j_SliderRect.rect.xMax; InitializeSliderHandle(); OnValueUpdated?.Invoke(j_SliderValue); j_Cursor = FindObjectOfType(typeof(JMRCursor)) as JMRCursor; }
public void InvokeValue(float value) { _value = value; onValue?.Invoke(value); _onValue?.Invoke(value); }
public virtual void Progress(Single value, PlaybackDirection direction) { Initialize(); onProgress?.Invoke((direction == PlaybackDirection.FORWARD) ? value : 1f - value); _onProgress?.Invoke((direction == PlaybackDirection.FORWARD) ? value : 1f - value); AtProgress(value, direction); if (value >= 1f) { switch (repeat) { case RepeatType.ZERO_TO_ONE: if (direction == PlaybackDirection.FORWARD) { PlayForward(true); } else { PlayBackward(true); } break; case RepeatType.PING_PONG: Toggle(true); break; } } }
public void LaunchVictoryAnimation(CharId winnerCharId) { // stop music GameObject.FindGameObjectWithTag("Music")?.SetActive(false); // setup delayed tasks float cachedAnimationDuration = SpecialTitleAnimationDuration; // play ad (this).ExecuteAfterTime(cachedAnimationDuration + VICTORY_SCREEN_DURATION, () => { ShowAdThenShowScene(); }); // start timer this.ExecuteAfterTime(cachedAnimationDuration, () => { _timerRemainingTime.StartTimer(VICTORY_SCREEN_DURATION); }); // update canvas activation DeactivateGamePanel(); _victoryCanvas.SetActive(true); OnLaunchVictoryAnimation?.Invoke(VICTORY_SCREEN_DURATION); CameraEffectController.Instance.EnableBlur(true); // update content SetWinnerContent(winnerCharId); SetSpecialPlayersContent(winnerCharId); // we put it at the end of method, if it has errors }
/// <summary> /// <para>Mark the ContentSizeFitter as dirty.</para> /// </summary> protected void SetDirty() { if (IsActive()) { OnRectWidthChange?.Invoke(rectTransform.rect.size.x); OnRectHeightChange?.Invoke(rectTransform.rect.size.y); } }
private void CheckCollision(Collision2D col) { CollisionStrength = col.relativeVelocity.magnitude; if (ValidateLayer) { //01000100 (mask) //& //00100000 (test) //= //00000000 (test not "in" mask) var testMask = 1 << col.gameObject.layer; if ((Mask.value & testMask) != 0) { Callback?.Invoke(CollisionStrength); } } else { Callback?.Invoke(CollisionStrength); } }
private IEnumerator LoadSceneAsyncProcess(int sceneBuildIndex, LoadSceneMode loadSceneMode, UnityEventFloat onLoadingSceneAsync) { AsyncOperation sceneLoadingAsyncOperation = SceneManager.LoadSceneAsync(sceneBuildIndex, loadSceneMode); while (!sceneLoadingAsyncOperation.isDone) { this._onLoadingSceneAsync.Invoke(sceneLoadingAsyncOperation.progress); onLoadingSceneAsync?.Invoke(sceneLoadingAsyncOperation.progress); yield return(null); } }
public override void UpdateValue() { handDevice.TryGetFeatureValue(inputFeature, out value); if (value != prevValue) { StateChanged.Invoke(value); if (value.x != prevValue.x) { MovedX?.Invoke(value.x); } else if (value.y != prevValue.y) { MovedY?.Invoke(value.y); } prevValue = value; } handDevice.TryGetFeatureValue(touch, out bool _touched); handDevice.TryGetFeatureValue(click, out bool _clicked); if (_touched != touched) { if (_touched) { Touched.Invoke(); } else { UnTouched.Invoke(); } touched = _touched; } if (_clicked != clicked) { if (_clicked) { Clicked.Invoke(); } else { UnClicked.Invoke(); } clicked = _clicked; } }
public void Hit(int p = 1) { points -= p; isHit = true; onPlayerHit?.Invoke(); onPlayerBecomeInvincible?.Invoke(invincibleDuration); if (points <= 0) { onPlayerDeath?.Invoke(); } }
public void TakeDamage(int amount) { currentHealth -= amount; if (currentHealth <= 0) { currentHealth = 0; if (this.transform.root.tag == "Player") { SceneManager.LoadScene("Menu"); } else { Destroy(this.gameObject); } } // Notify UI about change of health percentage healthPercentageUpdate.Invoke((float)currentHealth / maxHealth); }
void WasHitEvent(float damage) { AdjustStatValue(-damage); if (GetStatValue() <= 0) // Health 0 { lives -= 1; // Decrease lives wasKilledEvent.Invoke(lives); if (lives <= 0) // No more lives { DestroyObject(playerM.tankObj); lostEvent.Invoke(0); } else // Respawn { playerM.tankObj.transform.position = spawnPoint; SetStatPercent(100); } } }
internal override void ChartPreview(Vector3 worldPosition) { RectTransform rectTransform = (RectTransform)transform; Vector3[] corners = new Vector3[4]; rectTransform.GetWorldCorners(corners); Vector3 middleLine = Vector3.Lerp(corners[0], corners[1], 0.5f); Vector3 position = ProjectPointOnLine(middleLine, base.transform.right, worldPosition); float lengthPosition = Vector3.Distance(middleLine, position); float widthLength = Vector3.Distance(corners[1], corners[2]); float ratio = lengthPosition / widthLength; if (_preview != null) { _preview.position = position; } onValuePreview.Invoke(ratio); _onValuePreview.Invoke(ratio); }
public override void OnEventRaised(float input) { base.OnEventRaised(input); response.Invoke(input); }
public void Set(float value) { var v = (((value - minIn) / (maxIn - minIn)) * (maxOut - minOut)) + minOut; onValue.Invoke(v); }
public void OnEventRaised(float parameter) { ResponseFloat.Invoke(parameter); }
// Update is called once per frame void Update() { if (health.hasDied()) { return; } Vector2 thisPos = transform.position; //////////////////////////////////////// Oxygen ////////////////////////////////////////////////// if (submergePhysic.getDiveState() == DiveState.fullyInWater) { oxygen -= Time.deltaTime * oxygenDepletionRate; } else { oxygen = maxOxygen; } if (oxygen < 0) { health.damage(health.getHealth()); } //////////////////////////////////////// Movement /////////////////////////////////////////////// // Is player touching ground? touchGround = Physics2D.CircleCast(thisPos, circleCollider.radius, Vector2.down, 0.05f, TerrainMask).collider != null; anim.SetBool("touchground", touchGround); Vector2 moveVec = Vector2.zero; // Land Movement Vector2 landMoveVec = Vector2.zero; if (touchGround) { if (Input.GetKey(left)) { landMoveVec += Vector2.left; } if (Input.GetKey(right)) { landMoveVec += Vector2.right; } if (Input.GetKeyDown(keyJump) && Time.time > timeLastJump + jumpCoolDown) { timeLastJump = Time.time; RB.AddForce(Vector2.up * jumpSpeed); } } // Aqua Control Vector2 aquaMoveVec = Vector2.zero; if (Input.GetKey(up)) { aquaMoveVec += Vector2.up; } if (Input.GetKey(down)) { aquaMoveVec += Vector2.down; } if (Input.GetKey(left)) { aquaMoveVec += Vector2.left; } if (Input.GetKey(right)) { aquaMoveVec += Vector2.right; } float submergeRatio = Mathf.Clamp(submergePhysic.getSubmergeRatio(), 0.0f, 1.0f); // Sum up move force moveVec = ((aquaMoveVec.normalized * submergeRatio).normalized * swimSpeed + landMoveVec.normalized * walkSpeed); // Move body RB.AddForce(moveVec * Time.deltaTime); // Limit land walk speed float currMovementSpeed = RB.velocity.magnitude; if (touchGround && currMovementSpeed > maxLandWalkSpeed) { RB.velocity *= maxLandWalkSpeed / currMovementSpeed; } //////////////////////////////////// Animation //////////////////////////////////////////////////////// Vector2 animMoveDir; if (submergePhysic.getDiveState() != DiveState.fullyInWater) { animMoveDir = moveVec; } else { animMoveDir = RB.velocity; } // Update moveDirection reference gameobject if (animMoveDir.sqrMagnitude != 0.0f) { float moveAngle = Mathf.Atan2(animMoveDir.y, animMoveDir.x) * 180.0f / 3.14f; playerDirectionTransform.rotation = Quaternion.Euler(0, 0, moveAngle); OnMoveTowardAngle.Invoke(moveAngle); } // Facing left or right? Vector3 flipScale = anim.transform.localScale; if (animMoveDir.x > 0.0f) { flipScale.x = Mathf.Abs(flipScale.x); anim.transform.localScale = flipScale; } else if (animMoveDir.x < 0.0f) { flipScale.x = Mathf.Abs(flipScale.x) * -1; anim.transform.localScale = flipScale; } // Rotate via swim direction under water if (submergePhysic.getDiveState() == DiveState.fullyInWater) { // Change rotation only when swimming if (animMoveDir != Vector2.zero) { float movementRightAngle = Mathf.Atan2(animMoveDir.y, Mathf.Abs(animMoveDir.x)) * 180.0f / 3.14f; float movementRightAngleClamped = Mathf.Clamp(movementRightAngle, pitchMinAngle, pitchMaxAngle); if (flipScale.x < 0.0f) { movementRightAngleClamped *= -1; } anim.transform.rotation = Quaternion.Euler(0, 0, movementRightAngleClamped); } } // Resume upright rotation else { anim.transform.rotation = Quaternion.identity; } anim.SetBool("fullyinwater", (submergePhysic.getDiveState() == DiveState.fullyInWater)); anim.SetFloat("speed", RB.velocity.magnitude / 5.0f); }
private void Update() { updateValue.Invoke(value); }
void FixedUpdate() { rb.velocity = Vector3.zero; rb.angularVelocity = 0; if (MoveInput != Vector2.zero) { // Input angle, clamped between 0 and 360 float inputAngle = (Mathf.Atan2(MoveInput.y, MoveInput.x) * Mathf.Rad2Deg); while (inputAngle < 0) { inputAngle += 360; } float currentAngle = transform.eulerAngles.z; // Angle diff, soft clamped between -180 and 180 float angleDiff = inputAngle - currentAngle; if (angleDiff < -180) { angleDiff += 360; } else if (angleDiff > 180) { angleDiff -= 360; } else if (angleDiff == 180) // Prefer clockwise full turns; { angleDiff = -180; } // Rotate if needed if (angleDiff != 0) { float rotateAmt = Time.deltaTime * TankTweaksProp.rotationSpeed; // Usual rotate amt if (angleDiff < 0) { rotateAmt *= -1; rotateAmt = Mathf.Max(rotateAmt, angleDiff); // Clamp with angleDiff } else // angleDiff > 0 { rotateAmt = Mathf.Min(rotateAmt, angleDiff); // Clamp with angleDiff } transform.eulerAngles = new Vector3(0, 0, currentAngle + rotateAmt); // Add to rotation } // Move // if (!IsAnchored) { // Not anchored float moveAmt = Time.deltaTime * TankTweaksProp.maxSpeed; // Usual move amt moveAmt *= ((180 - Mathf.Abs(angleDiff)) / 180); // Reduce if facing away Vector3 moveVec3 = transform.right * moveAmt; Vector2 moveVec2 = rb.position + (new Vector2(moveVec3.x, moveVec3.y)); rb.MovePosition(moveVec2); moveEvent.Invoke(moveAmt); // } // Reset vector for next time MoveInput = Vector2.zero; } }
public float Update(float duration) { OnUpdate.Invoke(Values.Evaluate(duration)); return(Values.Evaluate(duration)); }
public void NotifyValue(float horizontal, float vertical) { onHorizontalChange.Invoke(horizontal * outputMultiplier); onVerticalChange.Invoke(vertical * outputMultiplier); }
public void SubmitFieldValue() { m_onEndEdit.Invoke(fieldValue); }
protected override void SetValue(float normalisedPoint) { Callback.Invoke(Mathf.Lerp(FromValue, ToValue, normalisedPoint)); }
// -- Public Functions public void OnEventRaised(float value) { EventFloatResponse.Invoke(value); }
void OnSignal(float f) { callback.Invoke(f); }
private void MoveMouseX(float value) { moveMouseX.Invoke(value); }
public void OnEventRaised(float payload) { Response.Invoke(payload); }
public void Axis2DUpdate(Vector2 data) { Moved2D.Invoke(data); Moved2DX.Invoke(data.x); Moved2DY.Invoke(data.y); }
private void Awake() { onAwake.Invoke(variableSO.RuntimeValue); listener = new VariableListenerClass <VariableFloat, float, UnityEventFloat>(variableSO, onVariableChanged); }
void OnTriggerEnter(Collider other) { Debug.Log("OnTargetDirectionDetected :" + targeDirectionValue.ToString()); OnTargetDirectionDetected.Invoke(targeDirectionValue); }
private void Update() { t += Time.deltaTime / duration; t %= 1; onValue.Invoke(curve.Evaluate(t)); }