void CreatePlayers(float[,] mapArea) { int i = 0; StaticValues.players = new GameObject[StaticValues.numPlayers]; while (i < StaticValues.numPlayers) { Debug.Log("Spawn player " + i); Vector3 spawnPositions = randomPositionScript.GetRandomPosition( mapArea[0, 0], mapArea[0, 1], mapArea[1, 0], mapArea[1, 1], mapArea[2, 0], mapArea[2, 1] ); GameObject playersGameObject = GameObject.FindWithTag("Players"); GameObject player = Instantiate(playerPrefab, spawnPositions, Quaternion.identity) as GameObject; player.transform.parent = playersGameObject.transform; PlayerController playerController = player.GetComponent <PlayerController>(); playerController.InitPlayerController(i); StaticValues.players[i] = player; player.GetComponent <PlayerHealth>()?.setHealthbar(healthSliders[i]); i++; } }
private IEnumerator CreateFood() { yield return(new WaitForSeconds(Random.Range(minSpawnTime, maxSpawnTime))); Vector3 position = randomPositionScript.GetRandomPosition( mapArea[0, 0], mapArea[0, 1], mapArea[1, 0], mapArea[1, 1], mapArea[2, 0], mapArea[2, 1] ); InstantiateFood(position); }
private void Update() { if (!loadRole.isCreatingData) { //dataSaver.CloseStream(); return; } if (index < rotateTimes) { //保存数据 StartCoroutine(dataSaver.SavePicture(roleCamera, path, loadRole.currentRole[0].name, index)); dataSaver.SavePositionData(path, roleID, loadRole.currentRole[0].transform.position, Camera.main.transform.position); //旋转模型 loadRole.currentRole[0].transform.Rotate(Vector3.up, -rotateAngle); // loadRole.currentRole[1].transform.Rotate(Vector3.up, -rotateAngle); //随机位置 if (randomPosition) { position = randomPosition.GetRandomPosition(loadRole.currentRole[0].transform.localPosition); loadRole.currentRole[0].transform.localPosition = position; // loadRole.currentRole[1].transform.localPosition = position; } index++; } else { //销毁模型 Destroy(loadRole.currentRole[0]); // Destroy(loadRole.currentRole[1]); //clean apace loadRole.currentRole = null; Resources.UnloadUnusedAssets(); //加载下一个模型,然后初始化 loadRole.GeneratePeople(sameName, ++roleID); if (loadRole.isCreatingData) { //dataSaver.CloseStream(); dataSaver.CreateDirectory(path, loadRole.currentRole[0].name); } index = 0; } }
public static void MakeStep(Config config, Player player, World world) { if (player.IsNeutrall) { return; } var enemyUnits = world.OverlapUnits(player.AvgPosition, (player.Units.FirstOrDefault()?.CurrentStats.ViewRadius ?? 1f) + 0.5f) .Where((u) => u.Owner != null && u.Owner != player && u.CurrentStats.UnitVisible); var enemyCount = enemyUnits.GroupBy((u) => u.Owner.UserId).Select((o) => o.First().Owner) .Select((o) => o.IsAI ? (o.IsNeutrall ? 6 : o.Units.Count) : 1).DefaultIfEmpty(0).Sum(); Vector2 inputDir = RandomPosition.GetRandomPosition(byte.MaxValue + player.NetworkId * 17, 1f); float t = Math.Clamp((world.ZoneRadius * world.ZoneRadius * 0.8f) - player.AvgPosition.SqrLength(), 0f, 10f) / 10f; inputDir = inputDir * t + (player.AvgPosition * -1f) * (1f - t); bool rise = false; if (player.GetCooldown() < 0.3f) { var neutralUnits = world.OverlapUnits(player.AvgPosition, config.RiseRadius).Where((u) => u.Owner == null); rise = neutralUnits.Count() > 0; if (!rise) { var nearUnits = world.OverlapUnits(player.AvgPosition, config.MaxViewRange); var nearUnit = nearUnits.Where((u) => u.Owner == null).FirstOrDefault(); if (nearUnit != null) { inputDir = nearUnit.Position - player.AvgPosition; } } } else if (enemyCount > 0 && (player.Units.Count * 2 >= enemyCount || world.ZoneRadius < 3f || player.Units.Count == config.MaxUnitCount)) { inputDir = Vector2.Empty; } player.SetInput(new Packets.ClientInput() { MoveX = inputDir.X, MoveY = inputDir.Y, Rise = rise }); }
IEnumerator startHurricane() { yield return(new WaitForSeconds(initialWait)); while (true) { Vector3 position = randomPositionScript.GetRandomPosition( mapArea[0, 0], mapArea[0, 1], mapArea[1, 0], mapArea[1, 1], mapArea[2, 0], mapArea[2, 1] ); GameObject hurricane = InstantiateHurricane(position); yield return(new WaitForSeconds(hurricaneDuration)); Destroy(hurricane); yield return(new WaitForSeconds(timeBetweenHuricanes)); } }
private IEnumerator SpawnMeteorInsideRectangle() { GameObject meteors = GameObject.FindWithTag("MeteorHail"); while (hail) { yield return(new WaitForSeconds(intervalBetweenMeteors)); for (int j = 0; j < numMeteorsPerHail; j++) { Vector3 position = randomPositionScript.GetRandomPosition( mapArea[0, 0], mapArea[0, 1], mapArea[1, 0], mapArea[1, 1], mapArea[2, 0], mapArea[2, 1] ); CreateHail(meteors, position); } } }
IEnumerator TemporarilyDisablePlatform(BoxCollider[] meshColliders) { float respawnIn = respawnTimeRandom ? Random.Range(respawnTime - respawnTimeDeviation, respawnTime + respawnTimeDeviation) : respawnTime; yield return(new WaitForSeconds(respawnIn)); gameObject.GetComponent <MeshRenderer>().enabled = true; float [,] mapDimension = mapPosition.GetMapPosition(); Vector3 position = randomPosition.GetRandomPosition( mapDimension[0, 0], mapDimension[0, 1], mapDimension[1, 0], mapDimension[1, 1], mapDimension[2, 0], mapDimension[2, 1] ); gameObject.transform.position = position; foreach (BoxCollider meshCollider in meshColliders) { meshCollider.enabled = true; } }
private static Vector2 GetPos(int i, float zone, float time) { return(RandomPosition.GetRandomPosition(i, time) * zone * RandomPosition.GetRandomFloat(i + 5, time)); }