void OnInventoryUpdated(InventoryUpdateEvent update) { if (update.Type != InventoryUpdateEvent.UpdateType.Added) { return; } if (inventory == null) { return; } if (actor == null) { return; } if (AreAllRequiredItemsAvailable()) { GameObject newObj = Instantiate(blueprintPrefab) as GameObject; GridActor newActor = newObj.GetComponent <GridActor>(); if (actor) { newActor.Move(actor.Position); } GameObject.Destroy(gameObject); } }
public static BlockBuildingSite InstantiateNew(Vector3Int position, Block blockToBuild, Type itemRequired) { GameObject prefabObj = PrefabLoader.GetPrefab <GameObject>(prefabName); GameObject obj = Instantiate(prefabObj) as GameObject; if (!obj) { throw new System.Exception("Could not instantiate prefab " + prefabName); } GridActor actor = obj.GetComponent <GridActor>(); if (!actor) { throw new System.Exception("No GridActor on prefab " + prefabName); } actor.Move(position); BlockBuildingSite bbs = obj.GetComponent <BlockBuildingSite>(); if (!bbs) { throw new System.Exception("No BlockBuildingSite on prefab " + prefabName); } bbs.data.targetBlock = blockToBuild; bbs.data.itemRequired = itemRequired; return(bbs); }
void Update() { if (!dorfsSpawned) { dorfsSpawned = true; for (int i = 0; i < 1; i++) { Vector3Int middleOfMap = new Vector3Int(GridMap.Instance.GetSize().x / 2, 0, GridMap.Instance.GetSize().z / 2); spawnedDorfs.Add(DorfComponent.InstantiateDorf(middleOfMap).gameObject); } } if (GridMap.Instance.IsGenerationDone() && correctDorfPositions) { correctDorfPositions = false; foreach (GameObject g in spawnedDorfs) { GridActor actor = g.GetComponent <GridActor>(); Vector3Int pos = actor.Position; Vector3Int newPos = Vector3Int.zero; for (int y = 0; y < GridMap.Instance.GetSize().y; y++) { newPos = new Vector3Int(pos.x, y, pos.z); if (GridMap.Instance.GetBlock(newPos).SupportsWalkingThrough()) { break; } } actor.Move(newPos); } } }
public override State OnDuring() { Vector3Int currPos = user.Position; foreach (var delta in DeltaPositions.GetRandomDeltaPositions3D()) { Vector3Int newPos = currPos + delta; if (Astar.IsStepValid(newPos, currPos, delta)) { user.Move(newPos); break; } } return(new WaitState(this.logger)); }
void Start() { inventory = Helpers.GetComponent <InventoryComponent>(gameObject, logger); if (inventory) { inventoryObserver = new SimpleObserver <InventoryUpdateEvent>(inventory, OnInventoryUpdated); } actor = Helpers.GetComponent <GridActor>(gameObject, logger); if (actor) { actor.Move(data.blueprint.Location); transform.position = actor.Position; } if (data.blueprint != null) { blueprintPrefab = PrefabLoader.GetPrefab <GameObject>(data.blueprint.PrefabPath); SetupMesh(); SetupGridActor(); SetupRequests(); } }
public static DroppedItemComponent InstantiateNew(Vector3Int position) { GameObject prefabObj = PrefabLoader.GetPrefab <GameObject>(prefabName); GameObject obj = Instantiate(prefabObj) as GameObject; if (!obj) { throw new System.Exception("Could not instantiate prefab " + prefabName); } GridActor gridActor = obj.GetComponent <GridActor>(); if (!gridActor) { throw new System.Exception("No GridActor Component on " + prefabName); } gridActor.Move(position); DroppedItemComponent comp = obj.GetComponent <DroppedItemComponent>(); if (!comp) { throw new System.Exception("No ItemContainerComponent Component on " + prefabName); } return(comp); }