public void SetUp() { GameSceneFactory gameSceneFactory = new GameSceneFactory(); Scene matchScene = gameSceneFactory.Create(); ArrangeTransformSystem[] arrangeCollidersSystems = { new WithHpArrangeTransformSystem(contexts) }; PhysicsRollbackManager physicsRollbackManager = new PhysicsRollbackManager(arrangeCollidersSystems); PhysicsVelocityManager physicsVelocityManager = new PhysicsVelocityManager(); PhysicsRotationManager physicsRotationManager = new PhysicsRotationManager(); SnapshotFactory snapshotFactory = new SnapshotFactory(contexts.serverGame); playerPredictor = new PlayerPredictor(physicsRollbackManager, matchScene, contexts.serverGame, physicsVelocityManager, physicsRotationManager, snapshotFactory); playerEntity = contexts.serverGame.CreateEntity(); ClientPrefabsStorage clientPrefabsStorage = new ClientPrefabsStorage(); GameObject warshipPrefab = clientPrefabsStorage.GetPrefab(ViewTypeEnum.StarSparrow1); GameObject go = Object.Instantiate(warshipPrefab, Vector3.zero, Quaternion.identity); SceneManager.MoveGameObjectToScene(go, matchScene); ushort playerEntityId = 100; playerEntity.AddId(playerEntityId); playerEntity.AddView(go); playerEntity.AddRigidbody(go.GetComponent <Rigidbody>()); LogAssert.ignoreFailingMessages = true; }
public void Spawn(ServerGameEntity entity) { ViewTypeEnum viewType = entity.viewType.value; Vector3 spawnPosition = entity.spawnTransform.position; Quaternion spawnRotation = entity.spawnTransform.rotation; GameObject prefab = prefabStorage.GetPrefab(viewType); GameObject go = physicsSpawner.SpawnProjectile(prefab, spawnPosition, spawnRotation); go.layer = projectileLayerNumber; entity.AddTransform(go.transform); Rigidbody rigidbody = go.GetComponent <Rigidbody>(); entity.AddRigidbody(rigidbody); go.Link(entity); entity.AddView(go); if (entity.hasParentWarship) { var projectileCollider = go.GetComponent <Collider>(); Collider[] warshipColliders = entity.parentWarship.entity.warshipColliders.colliders; Vector3 parentVelocity = entity.parentWarship.entity.rigidbody.value.velocity; rigidbody.velocity = parentVelocity; physicsSpawner.Ignore(new[] { projectileCollider }, warshipColliders); } }
public void Execute() { var entities = needHealthBar.GetEntities(); for (var index = 0; index < entities.Length; index++) { var entity = entities[index]; if (!entity.hasView) { log.Error("Если есть NeedHealthBar, то обязательно должен быть view"); continue; } //Создать полоску ServerGameEntity healthBarEntity = gameContext.CreateEntity(); GameObject prefab = healthBarStorage.GetPrefab(); GameObject go = Object.Instantiate(prefab); go.Link(entity); go.transform.position = new Vector3(0, healthBarHeightStorage.GetHeight(entity.viewType.value)); Slider slider = go.transform.Find("Slider").GetComponent <Slider>(); if (slider == null) { log.Error("Не найден слайдер на полоске хп"); continue; } TextMeshProUGUI username = go.transform.Find("Text_Username").GetComponent <TextMeshProUGUI>(); if (username == null) { log.Error("Не найден text username на полоске хп"); continue; } TextMeshProUGUI healthPoints = go.transform.Find("Slider/Text_HealthPoints") .GetComponent <TextMeshProUGUI>(); if (healthPoints == null) { log.Error("Не найден text healthPoints на полоске хп"); continue; } healthBarEntity.AddView(go); healthBarEntity.AddTransform(go.transform); healthBarEntity.AddHealthBar(slider, username, healthPoints, entity); if (entity.hasHealthBarParent) { log.Error("У этой сущности не должно быть этого компонета."); continue; } entity.AddHealthBarParent(healthBarEntity); } }
public void Spawn(ServerGameEntity entity) { ViewTypeEnum viewType = entity.viewType.value; Vector3 spawnPosition = entity.spawnTransform.position; Quaternion spawnRotation = entity.spawnTransform.rotation; GameObject prefab = prefabStorage.GetPrefab(viewType); GameObject go = physicsSpawner.Spawn(prefab, spawnPosition, spawnRotation); go.Link(entity); entity.AddTransform(go.transform); Rigidbody rigidbody = go.GetComponent <Rigidbody>(); entity.AddRigidbody(rigidbody); entity.AddView(go); //todo не забыть убрать компонент // entity.RemoveSpawnTransform(); }
public void Spawn(ServerGameEntity entity) { ViewTypeEnum viewType = entity.viewType.value; Vector3 spawnPosition = entity.spawnTransform.position; Quaternion spawnRotation = entity.spawnTransform.rotation; GameObject prefab = prefabStorage.GetPrefab(viewType); GameObject go = physicsSpawner.Spawn(prefab, spawnPosition, spawnRotation); go.layer = playersLayerNumber; go.Link(entity); entity.AddView(go); entity.AddTransform(go.transform); Rigidbody rigidbody = go.GetComponent <Rigidbody>(); entity.AddRigidbody(rigidbody); shootingPointsHelper.AddShootingPoints(go, entity); Collider[] colliders = go.GetComponents <Collider>(); entity.AddWarshipColliders(colliders); }