public override void OnLoad() { PrefabFactory prefabFactory = new PrefabFactory(world.EntityManager); player = prefabFactory.Create(PrefabIds.PLAYER); player.GetComponent <Transform>().Position = new Vector2(250, 50); }
private void addElement(DataNet net) { PrefabFactory.Parameter[] parameters = { new PrefabFactory.Parameter(net, typeof(DataNet)) }; NetSelectionElementInstaller createdElement = _prefabFactory.Create(_elementPrefab, parameters); createdElement.transform.SetParent(_hook, false); _elements.Add(net.ID, createdElement); }
protected TInputDetector createInputDetector <TInputDetector>(TInputDetector prefab, PrefabFactory.Parameter[] parameters) where TInputDetector : InputDetector { TInputDetector inputDetector = _prefabFactory.Create(prefab, parameters); inputDetector.transform.SetParent(_hook.transform, false); return(inputDetector); }
private void InstantiateStage(Stage stage) { for (var i = 0; i < Stage.Width; i++) { for (var j = 0; j < Stage.Height; j++) { var cell = stage.GetCell(i, j); var pos = new Vector3(i, 0, j); switch (cell.CellType) { case CellType.Hard: PrefabFactory.Create <HardRockView>(StagePrefabPathDef.HardRock, _stageRootTransform, pos); break; case CellType.Medium: PrefabFactory.Create <MediumRockView>(StagePrefabPathDef.MediumRock, _stageRootTransform, pos); break; case CellType.Normal: PrefabFactory.Create <NormalRockView>(StagePrefabPathDef.NormalRock, _stageRootTransform, pos); break; case CellType.Treasure: PrefabFactory.Create <TreasureCellView>(StagePrefabPathDef.TreasureCell, _stageRootTransform, pos); break; case CellType.Trap: break; case CellType.ArrowUp: PrefabFactory.Create <TmpArrowCellView>(StagePrefabPathDef.TmpArrowCell, _stageRootTransform, pos); break; case CellType.ArrowDown: PrefabFactory.Create <TmpArrowCellView>(StagePrefabPathDef.TmpArrowCell, _stageRootTransform, pos); break; case CellType.ArrowRight: PrefabFactory.Create <TmpArrowCellView>(StagePrefabPathDef.TmpArrowCell, _stageRootTransform, pos); break; case CellType.ArrowLeft: PrefabFactory.Create <TmpArrowCellView>(StagePrefabPathDef.TmpArrowCell, _stageRootTransform, pos); break; default: throw new ArgumentOutOfRangeException(); } } } }
private static ICanvas CreateCanvas(ICamera renderCamera, Transform rootTransform, string canvasPrefabPath, string touchBlockPrefabPath) { var canvas = PrefabFactory.Create <CanvasBase>(canvasPrefabPath, rootTransform); canvas.SetCamera(renderCamera); var touchBlockPresenter = CreateTouchBlockPresenter(canvas, touchBlockPrefabPath); canvas.SetTouchBlockPresenter(touchBlockPresenter); return(canvas); }
protected override void OnEventFired(object source, EntityCreationStartingEventArgs args) { EntityPrefab prefabType = ComputePrefabType(args.EntityGuid); IMovementData movementData = MovementDataMappable.RetrieveEntity(args.EntityGuid); //load the entity's prefab from the factory GameObject prefab = PrefabFactory.Create(prefabType); GameObject entityGameObject = GameObject.Instantiate(prefab, movementData.InitialPosition, Quaternion.Euler(0, movementData.Rotation, 0)); OnEntityWorldRepresentationCreated?.Invoke(this, new EntityWorldRepresentationCreatedEventArgs(args.EntityGuid, entityGameObject)); }
protected override void HandleEvent(CharacterFriendAddedEventArgs args) { UnityAsyncHelper.UnityMainThreadContext.PostAsync(async() => { string characterName = await NameQueryable.RetrieveAsync(args.FriendGuid); GameObject slotObject = GameObject.Instantiate(PrefabFactory.Create(EntityPrefab.CharacterFriendSlot)); IUICharacterFriendSlot characterFriendSlot = slotObject.GetComponent <IUICharacterFriendSlot>(); //We're on the main thread here, we can create the tab. FriendWindowRoot.Parent(slotObject); //TODO: Query for name. characterFriendSlot.Text = characterName; characterFriendSlot.LocationText.Text = "Unknown"; }); }
/// <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); }
public void ReceiveChatMessage(int tabId, [NotNull] string text) { if (text == null) { throw new ArgumentNullException(nameof(text)); } if (tabId <= 0) { throw new ArgumentOutOfRangeException(nameof(tabId)); } GameObject textObject = GameObject.Instantiate(PrefabFactory.Create(EntityPrefab.MessageBoxText)); IUIText uiText = RetrieveUITextComponent(textObject); uiText.Text = text; //Parent to the message box. ChatWindow.Parent(textObject); }
public static ICamera BuildCamera <T>(string cameraPrefabPath, Transform parentTransform) where T : CameraBase { var camera = PrefabFactory.Create <T>(cameraPrefabPath, parentTransform); return(camera); }
public void Create_WorksForSimplePrefab() { GameObject result = _prefabFactory.Create(_simpleTestObjectPrefab); Assert.IsNotNull(result); }
protected PresenterBase(PrefabGenParams prefabGenParams) { TargetView = PrefabFactory.Create <T>(prefabGenParams.PrefabPath, prefabGenParams.GetCanvasTransform()); _canvas = prefabGenParams.targetCanvas; SetActiveView(false); }