private void Start() { playManager = GameObject.Find("PlayManager").GetComponent <PlayManager>(); Vector3 face = new Vector3(RD.NextFloat() - 0.5f, RD.NextFloat(), RD.NextFloat() - 0.5f).normalized; this.transform.rotation = Quaternion.FromToRotation(Vector3.zero, face); _passDelay = 0; }
// Start is called before the first frame update void Start() { player = null; size = RD.NextFloat() * 0.25f + 0.8f; health = GetComponent <Health>(); playManager = GameObject.Find("PlayManager").GetComponent <PlayManager>(); /// 受到攻击时冷却减少。(极致削弱) playManager.AddEventListener(PlayEventType.HEALTH_BEATTACKED, () => { currentCD /= 3f; // DEPRECATED Shining Effect }); }
/// Return a lazy sequence of samples. You typically want to call this in a foreach loop, like so: /// foreach (Vector2 sample in sampler.Samples()) { ... } public IEnumerable <Vector2> Samples() { // First sample is choosen randomly yield return(AddSample(new Vector2(RD.NextFloat() * rect.width, RD.NextFloat() * rect.height))); while (activeSamples.Count > 0) { // Pick a random active sample int i = (int)RD.NextFloat() * activeSamples.Count; Vector2 sample = activeSamples[i]; // Try `k` random candidates between [radius, 2 * radius] from that sample. bool found = false; for (int j = 0; j < k; ++j) { float angle = 2 * Mathf.PI * RD.NextFloat(); float r = Mathf.Sqrt(RD.NextFloat() * 3 * radius2 + radius2); // See: http://stackoverflow.com/questions/9048095/create-random-number-within-an-annulus/9048443#9048443 Vector2 candidate = sample + r * new Vector2(Mathf.Cos(angle), Mathf.Sin(angle)); // Accept candidates if it's inside the rect and farther than 2 * radius to any existing sample. if (rect.Contains(candidate) && IsFarEnough(candidate)) { found = true; yield return(AddSample(candidate)); break; } } // If we couldn't find a valid candidate after k attempts, remove this sample from the active samples queue if (!found) { activeSamples[i] = activeSamples[activeSamples.Count - 1]; activeSamples.RemoveAt(activeSamples.Count - 1); } } }
private void FixedUpdate() { // 更新进度 float percent = curTime; if (progressStart && pieceCount > 0 && progressState == ProgressState.DAYTIME) { if (curTime < dayTime) { curTime += Time.fixedDeltaTime; } percent /= dayTime; hudManager.UpdateTimeBoard(percent); if (percent > 1) { /// do spawn monster // 数量由天数决定 // 考虑非线性 // Lazer int enemyCount = (int)((RD.NextDouble() * 0.5 + 0.5) * Mathf.Pow(dayCount, 0.7f) + 1); Debug.Log("Spawn Lazer: " + enemyCount); // enemies = new GameObject[enemyCount]; while (enemyCount-- > 0) { // random position float thita = (RD.NextFloat() * 2 * Mathf.PI); // 1-1.5倍距离生成 float actualSpawnDistance = enemySpawnDistance * (1 + RD.NextFloat() * 0.5f); Vector3 spawnpoint = new Vector3(enemySpawnDistance * Mathf.Sin(thita), 3, enemySpawnDistance * Mathf.Cos(thita)); enemies.Add(Instantiate(enemyPrefab, worldManager.playerInstance.transform.position + spawnpoint, Quaternion.identity)); } // Giant enemyCount = (int)((RD.NextDouble() * 0.5 + 0.5) * Mathf.Max(0, Mathf.Pow(dayCount - towerDestroyed[0], 0.6f))); Debug.Log("Spawn Giant: " + enemyCount); while (enemyCount-- > 0) { bool enemyposN = RD.NextInt(2) == 1; // enemies.Add(enemyposN?) enemies.Add(Instantiate(enemyGiantPrefab, GameUtils.PositionToTranform( enemyposN ? worldManager.GetUnit(worldManager.towerpos1).position : worldManager.GetUnit(worldManager.towerpos2).position ) + Vector3.up * 3, Quaternion.identity) ); } // state change SendEvent(PlayEventType.GAME_ENTER_SWITCH); SendEvent(PlayEventType.GAME_ENTER_NIGHT); progressState = ProgressState.NIGHT; curTime = 0; hudManager.UpdateTimeBoard(0); } } if (progressState == ProgressState.NIGHT) { // update UI if (curTime < nightTime) { curTime += Time.fixedDeltaTime; } percent /= nightTime; enemies.RemoveAll(g => g == null); if (/*all monster killed*/ enemies.Count == 0 || percent > 1) { SendEvent(PlayEventType.GAME_ENTER_SWITCH); SendEvent(PlayEventType.GAME_ENTER_DAY); progressState = ProgressState.DAYTIME; curTime = 0; dayCount++; } } //UI update // 补充包 if (nextPieces.Count < piecePrefabs.Length) { FillNextPiece(); } // 恒时补充资源 if (goldRefillTime > curGoldRefillTime) { curGoldRefillTime += Time.fixedDeltaTime; } else { curGoldRefillTime -= goldRefillTime; GainResource(ResourceType.GOLD); } }