Beispiel #1
0
        public void UnlinkGameObjectFromEntity(GameObject gameObject, Entity entity, ViewCommandBuffer viewCommandBuffer)
        {
            if (entityManager.Exists(entity))
            {
                foreach (var component in gameObject.GetComponents <Component>())
                {
                    if (ReferenceEquals(component, null))
                    {
                        continue;
                    }

                    var componentType = component.GetType();
                    if (entityManager.HasComponent(entity, componentType))
                    {
                        viewCommandBuffer.RemoveComponent(entity, componentType);
                    }
                }

                if (entityManager.HasComponent <GameObjectReference>(entity))
                {
                    viewCommandBuffer.RemoveComponent(entity, typeof(GameObjectReference));
                }
            }

            var spatialOSComponent = gameObject.GetComponent <SpatialOSComponent>();

            if (spatialOSComponent != null)
            {
                UnityObjectDestroyer.Destroy(spatialOSComponent);
            }
        }
Beispiel #2
0
        public override void Tick()
        {
            if (Input.GetKeyDown(KeyCode.KeypadEnter) ||
                Input.GetKeyDown(KeyCode.Return) ||
                Input.GetKeyDown(KeyCode.Escape))
            {
                ScreenManager.ResultsScreenDoneButton.onClick.Invoke();
            }

            if (Blackboard.ClientConnector == null)
            {
                return;
            }

            if (trackPlayerSystem.PlayerResults.Count == 0)
            {
                return;
            }

            var results    = trackPlayerSystem.PlayerResults;
            var playerRank = results.FirstOrDefault(res => res.PlayerName == Blackboard.PlayerName).Rank;

            Debug.Log($"playerRank {playerRank}");
            Debug.Log($"player name {Blackboard.PlayerName}");

            ScreenManager.ResultsScreenDoneButton.onClick.AddListener(Restart);
            ScreenManager.InformOfResults(results, playerRank);
            Manager.ShowFrontEnd();
            ScreenManager.SwitchToResultsScreen();

            UnityObjectDestroyer.Destroy(Blackboard.ClientConnector);
            Blackboard.ClientConnector = null;
        }
Beispiel #3
0
 public void OnEntityRemoved(EntityId entityId, GameObject linkedGameObject)
 {
     if (linkedGameObject != null)
     {
         UnityObjectDestroyer.Destroy(linkedGameObject);
     }
 }
Beispiel #4
0
 protected override void OnDestroyManager()
 {
     if (UIComponent.Main != null)
     {
         UnityObjectDestroyer.Destroy(UIComponent.Main.gameObject);
     }
 }
Beispiel #5
0
        public void OnGUI()
        {
            layerCount = Mathf.Max(0,
                                   EditorGUILayout.IntField(new GUIContent(
                                                                "Number of Tile Layers",
                                                                "N layers corresponds to 4*(N^2) tiles."), layerCount));

            var numTiles = Mathf.RoundToInt(GetTotalTilesFromLayers(layerCount));

            GUI.color = numTiles < WarnTilesThreshold ? Color.white : Color.yellow;
            GUILayout.Label($"Number of tiles to generate: ~{numTiles}");
            GUI.color = Color.white;

            seed = EditorGUILayout.TextField(new GUIContent(
                                                 "Seed for Map Generator",
                                                 "Different seeds produce different maps."),
                                             seed);

            mapBuilderSettings = (MapBuilderSettings)EditorGUILayout.ObjectField(new GUIContent(
                                                                                     "Map Builder Settings",
                                                                                     "Different seeds produce different maps."),
                                                                                 mapBuilderSettings,
                                                                                 typeof(MapBuilderSettings),
                                                                                 false);

            EditorGUI.BeginDisabledGroup(mapBuilderSettings == null);
            if (GUILayout.Button("Generate Map"))
            {
                if (numTiles < WarnTilesThreshold ||
                    GetGenerationUserConfirmation(numTiles))
                {
                    if (mapBuilder == null || mapBuilder.InvalidMapBuilder)
                    {
                        SetupMapBuilder();
                    }

                    var volumesPrefab = mapBuilderSettings.WorldTileVolumes == null
                        ? null
                        : Instantiate(mapBuilderSettings.WorldTileVolumes);

                    UnwindCoroutine(mapBuilder.CleanAndBuild(layerCount, seed));

                    if (volumesPrefab != null)
                    {
                        UnityObjectDestroyer.Destroy(volumesPrefab);
                    }
                }
            }

            EditorGUI.EndDisabledGroup();

            EditorGUI.BeginDisabledGroup(mapBuilder == null);
            if (GUILayout.Button("Clear Map"))
            {
                mapBuilder.Clean();
            }

            EditorGUI.EndDisabledGroup();
        }
 public void TearDown()
 {
     ActivationManager?.Dispose();
     ActivationManager = null;
     UnityObjectDestroyer.Destroy(TestGameObject);
     world?.Dispose();
     world = null;
 }
Beispiel #7
0
        public void TearDown()
        {
            if (testGameObject != null)
            {
                UnityObjectDestroyer.Destroy(testGameObject);
            }

            world.Dispose();
        }
    private void DestroyMeshRenderers(Transform obj)
    {
        foreach (var meshRenderer in obj.GetComponentsInChildren <MeshRenderer>())
        {
            UnityObjectDestroyer.Destroy(meshRenderer);
        }

        foreach (var meshFilter in obj.GetComponentsInChildren <MeshFilter>())
        {
            UnityObjectDestroyer.Destroy(meshFilter);
        }
    }
Beispiel #9
0
 private void OnCreatePlayerResponse(PlayerCreator.CreatePlayer.ReceivedResponse response)
 {
     if (response.StatusCode == StatusCode.Success)
     {
         Owner.SetState(new PlayState(Manager, Owner));
     }
     else
     {
         ScreenManager.LobbyStatus.ShowSpawningFailedText(response.Message);
         UnityObjectDestroyer.Destroy(Blackboard.ClientConnector);
         Blackboard.ClientConnector = null;
         Owner.SetState(Owner.StartState);
     }
 }
        private IMobileConnectionController PrepareConnect()
        {
            errorMessage.text = string.Empty;
            worker            = Instantiate(clientWorkerPrefab);
            var workerConnector = worker.GetComponent <IMobileConnectionController>();

            if (workerConnector == null)
            {
                UnityObjectDestroyer.Destroy(worker);
                errorMessage.text = MissingWorkerConnectorMessage;
                throw new MissingComponentException(MissingWorkerConnectorMessage);
            }

            workerConnector.IpAddress = IpAddress;
            workerConnector.ConnectionScreenController = this;
            return(workerConnector);
        }
Beispiel #11
0
        // Get the world size from the config, and use it to generate the correct-sized level
        public static IEnumerator GenerateMap(
            MapBuilderSettings mapBuilderSettings,
            Transform workerTransform,
            Connection connection,
            string workerType,
            ILogDispatcher logDispatcher,
            WorkerConnectorBase worker)
        {
            var worldSize = GetWorldSizeFlag(connection);

            if (!TryGetWorldLayerCount(mapBuilderSettings, worldSize, out var worldLayerCount))
            {
                logDispatcher.HandleLog(LogType.Error,
                                        new LogEvent("Invalid world_size worker flag. Make sure that it is either small or large,")
                                        .WithField("world_size", worldSize));
                yield break;
            }

            var levelInstance = worker.LevelInstance = new GameObject();

            levelInstance.name = $"FPS-Level_{worldLayerCount}({workerType})";
            levelInstance.transform.position = workerTransform.position;
            levelInstance.transform.rotation = workerTransform.rotation;

            var mapBuilder = new MapBuilder(mapBuilderSettings, levelInstance);

            var volumesPrefab = mapBuilderSettings.WorldTileVolumes == null
                ? null
                : Object.Instantiate(mapBuilderSettings.WorldTileVolumes);

            yield return(mapBuilder.CleanAndBuild(worldLayerCount));

            if (volumesPrefab != null)
            {
                UnityObjectDestroyer.Destroy(volumesPrefab);
            }
        }
Beispiel #12
0
        protected override void OnUpdate()
        {
            for (var i = 0; i < addedEntitiesData.Length; i++)
            {
                var prefabMapping   = PrefabConfig.PrefabMappings[addedEntitiesData.PrefabNames[i].Prefab];
                var transform       = addedEntitiesData.Transforms[i];
                var entity          = addedEntitiesData.Entities[i];
                var spatialEntityId = addedEntitiesData.SpatialEntityIds[i].EntityId;

                if (!SystemConfig.UnityClient.Equals(worker.WorkerType) &&
                    !SystemConfig.UnityGameLogic.Equals(worker.WorkerType))
                {
                    worker.LogDispatcher.HandleLog(LogType.Error, new LogEvent(
                                                       "Worker type isn't supported by the GameObjectInitializationSystem.")
                                                   .WithField("WorldName", World.Name)
                                                   .WithField("WorkerType", worker));
                    continue;
                }

                var prefabName = SystemConfig.UnityGameLogic.Equals(worker.WorkerType)
                    ? prefabMapping.UnityGameLogic
                    : prefabMapping.UnityClient;

                var position = new Vector3(transform.Location.X, transform.Location.Y, transform.Location.Z) +
                               worker.Origin;
                var rotation = new UnityEngine.Quaternion(transform.Rotation.X, transform.Rotation.Y,
                                                          transform.Rotation.Z, transform.Rotation.W);

                var gameObject =
                    entityGameObjectCreator.CreateEntityGameObject(entity, prefabName, position, rotation,
                                                                   spatialEntityId);
                var gameObjectReference = new GameObjectReference {
                    GameObject = gameObject
                };

                entityGameObjectCache[entity.Index] = gameObject;
                var gameObjectReferenceHandleComponent = new GameObjectReferenceHandle();

                PostUpdateCommands.AddComponent(addedEntitiesData.Entities[i], gameObjectReferenceHandleComponent);

                viewCommandBuffer.AddComponent(entity, gameObjectReference);
                entityGameObjectLinker.LinkGameObjectToEntity(gameObject, entity, spatialEntityId,
                                                              viewCommandBuffer);
            }

            for (var i = 0; i < removedEntitiesData.Length; i++)
            {
                var entity      = removedEntitiesData.Entities[i];
                var entityIndex = entity.Index;

                if (!entityGameObjectCache.TryGetValue(entityIndex, out var gameObject))
                {
                    worker.LogDispatcher.HandleLog(LogType.Error, new LogEvent(
                                                       "GameObject corresponding to removed entity not found.")
                                                   .WithField("EntityIndex", entityIndex));
                    continue;
                }

                entityGameObjectCache.Remove(entityIndex);
                UnityObjectDestroyer.Destroy(gameObject);
                PostUpdateCommands.RemoveComponent <GameObjectReferenceHandle>(entity);
            }

            viewCommandBuffer.FlushBuffer();
        }
Beispiel #13
0
 private void CancelSession()
 {
     UnityObjectDestroyer.Destroy(Blackboard.ClientConnector);
     Blackboard.ClientConnector = null;
     Owner.SetState(Owner.StartState);
 }
 public void OnConnectionFailed(string connectionError)
 {
     UnityObjectDestroyer.Destroy(worker);
     errorMessage.text =
         $"Connection failed. Please check the IP address entered.\nSpatialOS error message:\n{connectionError}";
 }
Beispiel #15
0
        private void MakeEdge(float offset, int angle)
        {
            var rotation = Quaternion.Euler(0, angle, 0);

            var floor = Object.Instantiate(groundEdge,
                                           rotation * new Vector3(
                                               offset,
                                               0,
                                               HalfNumGroundLayers * UnitsPerGroundLayer + UnitsPerBlock * 0.25f),
                                           rotation * Quaternion.Euler(90, 0, 0),
                                           groundParentTransform);

            floor.transform.localScale = new Vector3(
                UnitsPerGroundLayer,
                UnitsPerBlock * .5f,
                1);

            var wall = Object.Instantiate(wallStraight,
                                          rotation * new Vector3(
                                              offset,
                                              UnitsPerBlock * .5f,
                                              HalfNumGroundLayers * UnitsPerGroundLayer + UnitsPerBlock * .5f),
                                          rotation,
                                          surroundParentTransform);

            wall.transform.localScale = new Vector3(
                UnitsPerGroundLayer,
                UnitsPerBlock,
                1);

            var wallFloor = Object.Instantiate(groundEdge,
                                               rotation * new Vector3(
                                                   offset,
                                                   UnitsPerBlock,
                                                   HalfNumGroundLayers * UnitsPerGroundLayer + UnitsPerBlock),
                                               rotation * Quaternion.Euler(90, 0, 0),
                                               surroundParentTransform);

            wallFloor.transform.localScale = new Vector3(
                UnitsPerGroundLayer,
                UnitsPerBlock,
                1);

            // Collision
            var collision = Object.Instantiate(wallStraight,
                                               rotation * new Vector3(
                                                   offset,
                                                   UnitsPerBlock + BoundaryCollisionHeight * .5f,
                                                   HalfNumGroundLayers * UnitsPerGroundLayer +
                                                   UnitsPerBlock * .5f),
                                               rotation,
                                               surroundParentTransform);

            collision.transform.localScale =
                new Vector3(
                    UnitsPerGroundLayer +
                    UnitsPerBlock, // Collisions overlap to fill corners
                    BoundaryCollisionHeight,
                    1);

            collision.name = "Collision";

            UnityObjectDestroyer.Destroy(collision.GetComponent <MeshRenderer>());
            UnityObjectDestroyer.Destroy(collision.GetComponent <MeshFilter>());
        }
 public void OnDisconnected(string disconnectReason)
 {
     UnityObjectDestroyer.Destroy(worker);
     ipAddressInput.text = PlayerPrefs.GetString(HostIpPlayerPrefsKey);
     connectionPanel.SetActive(true);
 }