public Pedestal Instantiate(PedestalType type, Vector3 position, float angle) { SafeCheckIfPoolIsCreated(type); Pedestal pedestal = null; List <Pedestal> pool = _pools[type]; if (pool.Count > 0) { pedestal = pool[pool.Count - 1]; pool.RemoveAt(pool.Count - 1); } else { pedestal = CreatePedestal(type, false); } pedestal.ResetMaterial(); pedestal.transform.SetParent(_root); pedestal.transform.position = position; pedestal.transform.rotation = Quaternion.Euler(0f, angle, 0f); pedestal.gameObject.SetActive(true); pedestal.Active = true; return(pedestal); }
void OnCharacterStuckInPedestal(Pedestal pedestal) { Debug.Log($"Detect character stuck in pedestal: lastAngle {_platform.LastAngle} - angle {_platform.Angle}"); float diffAngle = _platform.Angle - _platform.LastAngle; if (pedestal.type == PedestalType.Wall_01) { if (diffAngle > 0) { float diff = pedestal.transform.eulerAngles.y + 14; _platform.SetAngle(_platform.Angle - diff, true); } else { float diff = pedestal.transform.eulerAngles.y - 14; _platform.SetAngle(_platform.Angle - diff, true); } } else if (pedestal.type == PedestalType.DeadZone_01) { if (diffAngle > 0) { float diff = pedestal.transform.eulerAngles.y + 60; _platform.SetAngle(_platform.Angle - diff, true); } else { float diff = pedestal.transform.eulerAngles.y - 14; _platform.SetAngle(_platform.Angle - diff, true); } } }
public void OnLandingLayer(bool hasCombo, int comboCount, Pedestal pedestal) { if (_preventUpdateScore) { _preventUpdateScore = false; _hasPassLayer = false; _continousPowerupFloorCount = 0; return; } if (!_hasPassLayer) { return; } if (hasCombo) { long increaseScore = _scoreSetting.basicScore * _scoreSetting.comboMultiply * comboCount; UnityEngine.Debug.LogError("Passing layer combo : " + increaseScore); UnityEngine.Debug.LogError("Passing layer count : " + comboCount); Score += increaseScore; //OnScoreIncrease?.Invoke(increaseScore); //OnScoreUpdate?.Invoke(Score); OnScoreUpdate?.Invoke(Score, increaseScore); } else { long increaseScore = 0; switch (_previousPedestalType) { case PedestalType.Pedestal_01: increaseScore = _scoreSetting.basicScore * _scoreSetting.floorTypeNoFishMultiply + _scoreSetting.floorTypeNoFishIncrease; break; case PedestalType.Pedestal_01_1_Fish: increaseScore = _scoreSetting.basicScore * _scoreSetting.floorTypeOneFishMultiply + _scoreSetting.floorTypeOneFishIncrease; break; case PedestalType.Pedestal_01_3_Fish: increaseScore = _scoreSetting.basicScore * _scoreSetting.floorTypeThreeFishMultiply + _scoreSetting.floorTypeThreeFishIncrease; break; } UnityEngine.Debug.LogError("Normal score : " + increaseScore); Score += increaseScore; //OnScoreIncrease?.Invoke(increaseScore); //OnScoreUpdate?.Invoke(Score); OnScoreUpdate?.Invoke(Score, increaseScore); } _hasPassLayer = false; _continousPowerupFloorCount = 0; }
private int GetPedestalHitPriority(Pedestal pedestal) { if (_pedestalHitPriority.ContainsKey(pedestal.type)) { return(_pedestalHitPriority[pedestal.type]); } return(0); }
Pedestal CreatePedestal(PedestalType type, bool addToPool) { Pedestal prefab = _cachePedestalPrefabs[type]; Pedestal instance = GameObject.Instantiate(prefab, _root); if (addToPool) { instance.gameObject.SetActive(false); _pools[type].Add(instance); } return(instance); }
private void UsePowerUp(Pedestal collidePedestal) { _remainPowerupBreakFloor -= 1; _platform.ForceDestroyNextLayer(true); if (_remainPowerupBreakFloor == 0) { if (collidePedestal != null) { _character.Jump(); _scoreCaculator.OnLandingLayer(HasCombo(), _floorCombo, collidePedestal); _scoreCaculator.PreventUpdateScoreOnNextLanding(); } _character.SetBoostEffect(false); } }
private void OnCharacterCollideWithPedestal(Pedestal pedestal) { if (pedestal.type == PedestalType.Squid_01) { _roundTime += _gameSetting.squidBonusDuration; pedestal.Destroy(); EventHub.Emit(new EventGameTimeUpdate() { time = _roundTime }); EventHub.Emit(new EventGetBonusTime() { bonusTime = _gameSetting.squidBonusDuration, squid = pedestal }); return; } else if (HasPowerUp()) { if (pedestal.type == PedestalType.Pedestal_04_Powerup) { _character.ActivePowerup(); _character.SetBoostEffect(true); _remainPowerupBreakFloor = _gameSetting.powerUpBreakFloors; } UsePowerUp(pedestal); _floorCombo = 0; return; } else if (HasCombo()) { Debug.LogError("Has combo"); // Special case, should give player powerup. if (pedestal.type == PedestalType.Pedestal_04_Powerup) { _character.ActivePowerup(); _character.SetBoostEffect(true); _remainPowerupBreakFloor = _gameSetting.powerUpBreakFloors; } else { _character.Jump(); _platform.ForceDestroyNextLayer(); } _floorCombo += 1; _scoreCaculator.OnLandingLayer(HasCombo(), _floorCombo, pedestal); _scoreCaculator.PreventUpdateScoreOnNextLanding(); _floorCombo = 0; return; } else { if (pedestal.type == PedestalType.Pedestal_01 || pedestal.type == PedestalType.Pedestal_01_1_Fish || pedestal.type == PedestalType.Pedestal_01_3_Fish) { _character.Jump(); } else if (pedestal.type == PedestalType.Pedestal_04_Powerup) { _character.ActivePowerup(); _character.SetBoostEffect(true); _remainPowerupBreakFloor = _gameSetting.powerUpBreakFloors; } else if (pedestal.type == PedestalType.DeadZone_01) { Debug.Log("Dead by touching deadzone"); ProcessEndGame(true); } else if (pedestal.type == PedestalType.Wall_01) { Debug.Log("Dead by touching wall"); ProcessEndGame(true); } } _scoreCaculator.OnLandingLayer(HasCombo(), _floorCombo, pedestal); _floorCombo = 0; }
public void CustomUpdate() { if (State == CharacterState.Dead) { return; } _velocity -= _gameSetting.characterGravity * Time.deltaTime; _velocity = Mathf.Max(_velocity, _gameSetting.characterMaxDroppingVelocity); float moveDistance = _velocity * Time.deltaTime; int totalHit = Physics.BoxCastNonAlloc(transform.position + _collider.center, _collider.size / 2, Vector3.down, _rayCastHits, Quaternion.identity, moveDistance < 0 ? Mathf.Abs(moveDistance) : 0, _defaultLayerMask); Pedestal stuckInPedestal = null; Vector3 position = transform.position; position.y += moveDistance; int totalHitPedestal = 0; for (int i = 0; i < totalHit; i++) { Pedestal pedestal = _rayCastHits[i].collider.GetComponent <Pedestal>(); if (pedestal == null) { pedestal = _rayCastHits[i].collider.GetComponentInParent <Pedestal>(); } if (pedestal == null || !pedestal.Active) { continue; } _collidePedestalHits[totalHitPedestal++] = pedestal; } Array.Sort(_collidePedestalHits, 0, totalHitPedestal, Comparer <Pedestal> .Create((p1, p2) => { return(GetPedestalHitPriority(p1) > GetPedestalHitPriority(p2) ? 1 : -1); })); for (int i = 0; i < totalHitPedestal; i++) { Pedestal pedestal = _collidePedestalHits[i]; if (i == 0) { OnCollideWithPedestal?.Invoke(pedestal); if (!pedestal.CanGoThrough && _rayCastHits[i].distance <= 0) { stuckInPedestal = pedestal; } } if (!pedestal.CanGoThrough && _rayCastHits[i].distance > 0 && position.y < _rayCastHits[i].point.y) { position.y = _rayCastHits[i].point.y; } } transform.position = position; if (stuckInPedestal != null) { OnStuckInPedestal?.Invoke(stuckInPedestal); } }
public void Return(Pedestal pedestal) { SafeCheckIfPoolIsCreated(pedestal.type); _pools[pedestal.type].Add(pedestal); pedestal.gameObject.SetActive(false); }