コード例 #1
0
        private IEntityObject InstantiateEntityObject(EntityId entityId, string prefabName)
        {
            // Always ensure that entities are spawned into the same scene that this script was started in.
            // This avoids the following case:
            //  1) Users dynamically loads scene, activates it, spawns their own entities into it.
            //  2) A new entity is spawned by SpatialOS into the new scene.
            //  3) The user destroys the scene, also destroying the SpatialOS-created GameObject.
            //  4) Errors ensue when the user tries to access the destroyed GameObject via the SpatialOS GameObject tracking layer (e.g. Universe.)
            using (new SaveAndRestoreScene(entitySpawningScene))
            {
                var loadedPrefab         = templateProvider.GetEntityTemplate(prefabName);
                var underlyingGameObject = prefabFactory.MakeComponent(loadedPrefab, prefabName);

                var entityObject = new EntityObject(entityId, underlyingGameObject, prefabName,
                                                    interestedComponentUpdaterProvider);

                var entityObjectStorage =
                    underlyingGameObject.GetComponent <EntityObjectStorage>() ??
                    underlyingGameObject.AddComponent <EntityObjectStorage>();

                entityObjectStorage.Initialize(entityObject, spatialCommunicator);

                return(entityObject);
            }
        }
コード例 #2
0
        /// <inheritdoc />
        public GameObject MakeComponent(GameObject prefabGameObject, string prefabName)
        {
            var name = GetPrefabsGauge(prefabName);

            metrics.IncrementGauge(name);

            return(prefabFactory.MakeComponent(prefabGameObject, prefabName));
        }