private void CleanupGameObject([NotNull] EntityDeconstructionStartingEventArgs args) { if (args == null) { throw new ArgumentNullException(nameof(args)); } //This removes the world entity from it's special collection AND removes it from the relevant map GameObject rootEntityGameObject = GuidToGameObjectMappable.RetrieveEntity(args.EntityGuid); GameObjectToEntityMap.ObjectToEntityMap.Remove(rootEntityGameObject); GameObject.Destroy(rootEntityGameObject); }
/// <inheritdoc /> public GameObject Create(TCreationContext context) { if (Logger.IsDebugEnabled) { Logger.Debug($"Creating entity. Type: {context.EntityGuid.EntityType} Id: {context.EntityGuid.EntityId}"); } //load the entity's prefab from the factory GameObject prefab = PrefabFactory.Create(context.PrefabType); GameObject entityGameObject = GameObject.Instantiate(prefab, context.MovementData.InitialPosition, Quaternion.Euler(0, 0, 0)); if (context.EntityGuid.EntityType == EntityType.Player) { CharacterControllerMappable[context.EntityGuid] = entityGameObject.GetComponent <CharacterController>(); } GameObjectToEntityMap.ObjectToEntityMap.Add(entityGameObject, context.EntityGuid); //TODO: Better handle initial movement/position data GuidToMovementInfoMappable.Add(context.EntityGuid, context.MovementData); GuidToGameObjectMappable.Add(context.EntityGuid, entityGameObject); //TODO: Is it best to do this here? if (!MovementHandlerService.TryHandleMovement(context.EntityGuid, context.MovementData)) { throw new InvalidOperationException($"Cannot handle MovementType: {context.MovementData.GetType().Name} for Entity: {context.EntityGuid}"); } //TODO: We need a better way to handle the entity data collection, we're casting and downcasting in afew spots //Entity data needs to be change trackable var changeTrackableEntityDataCollection = new ChangeTrackingEntityFieldDataCollectionDecorator <EntityDataFieldType>((IEntityDataFieldContainer <EntityDataFieldType>)context.EntityData); //Now we should add the entity data to the mappable collection //This lets it be looked up in both ways FieldDataContainers.Add(context.EntityGuid, changeTrackableEntityDataCollection); ChangeTrackableEntityDataFieldContainers.Add(context.EntityGuid, changeTrackableEntityDataCollection); EntityAsyncLockMap.Add(new KeyValuePair <NetworkEntityGuid, AsyncReaderWriterLock>(context.EntityGuid, new AsyncReaderWriterLock())); return(entityGameObject); }
protected override void OnEventFired(object source, EntityWorldRepresentationCreatedEventArgs args) { //Basically, all this one does is it just initializes the containers. GameObjectToEntityMap.ObjectToEntityMap.Add(args.EntityWorldRepresentation, args.EntityGuid); GuidToGameObjectMappable.AddObject(args.EntityGuid, args.EntityWorldRepresentation); }