public void CompleteBuilding(Vector3 pos) { CraftData item = current_crafting; if (item != null && current_buildable != null && (!build_pay_cost || CanCraft(item, true))) { current_buildable.SetBuildPositionTemporary(pos); //Set to position to test the condition, before applying it if (current_buildable.CheckIfCanBuild()) { current_buildable.SetBuildPosition(pos); character.FaceTorward(pos); if (build_pay_cost) { PayCraftingCost(item); } Buildable buildable = current_buildable; buildable.FinishBuild(); character.Data.AddCraftCount(item.id); UnityAction <Buildable> bcallback = build_callback; current_buildable = null; current_build_data = null; build_callback = null; clicked_build = false; character.StopAutoMove(); PlayerUI.Get(character.player_id)?.CancelSelection(); TheAudio.Get().PlaySFX("craft", buildable.build_audio); if (onBuild != null) { onBuild.Invoke(buildable); } if (bcallback != null) { bcallback.Invoke(buildable); } character.TriggerAction(1f); } } }
private void Start() { canvas.worldCamera = TheCamera.GetCamera(); if (!TheGame.IsMobile() && ItemSelectedFX.Get() == null && AssetData.Get().item_select_fx != null) { Instantiate(AssetData.Get().item_select_fx, transform.position, Quaternion.identity); } PlayerUI gameplay_ui = GetComponentInChildren <PlayerUI>(); if (gameplay_ui == null) { Debug.LogError("Warning: Missing PlayerUI script on the Gameplay tab in the UI prefab"); } }
public void OnClickAction(SAction action) { if (IsVisible()) { PlayerCharacter character = GetPlayer(); if (action != null && slot != null && character != null) { ItemSlot aslot = slot; PlayerUI.Get(character.player_id)?.CancelSelection(); Hide(); if (action.CanDoAction(character, aslot)) { action.DoAction(character, aslot); } } } }
protected override void Awake() { base.Awake(); panel_list.Add(this); parent_ui = GetComponentInParent <PlayerUI>(); for (int i = 0; i < slots.Length; i++) { CategorySlot cslot = (CategorySlot)slots[i]; if (cslot.group) { default_categories.Add(cslot.group); } } if (animator != null) { animator.SetBool("Visible", IsVisible()); } }
public void BuildItem(InventoryData inventory, int slot) { InventoryItemData invdata = inventory?.GetItem(slot); ItemData idata = ItemData.Get(invdata?.item_id); if (invdata != null && idata != null) { ConstructionData construct = idata.construction_data; PlantData aplant = idata.plant_data; CharacterData acharacter = idata.character_data; if (construct != null) { inventory.RemoveItemAt(slot, 1); Construction construction = character.Crafting.CraftConstruction(construct, false); BuiltConstructionData constru = PlayerData.Get().GetConstructed(construction.GetUID()); if (idata.HasDurability()) { constru.durability = invdata.durability; //Save durability } TheAudio.Get().PlaySFX("craft", construction.GetBuildable().build_audio); } else if (aplant != null) { inventory.RemoveItemAt(slot, 1); Plant plant = character.Crafting.CraftPlant(aplant, 0, false); TheAudio.Get().PlaySFX("craft", plant.GetBuildable().build_audio); } else if (acharacter != null) { inventory.RemoveItemAt(slot, 1); Character charact = character.Crafting.CraftCharacter(acharacter, false); TheAudio.Get().PlaySFX("craft", charact.GetBuildable().build_audio); } PlayerUI.Get(character.player_id)?.CancelSelection(); } }
private void OnClickFloor(Vector3 pos) { if (!controls_enabled) { return; } if (is_action && can_cancel_action) { CancelAction(); } //Cancel previous build if (character_craft.ClickedBuild()) { character_craft.CancelCrafting(); } //Build mode if (character_craft.IsBuildMode()) { if (!TheGame.IsMobile()) //On mobile, will build on mouse release { character_craft.TryBuildAt(pos); } } //Move to clicked position else { MoveTo(pos); PlayerUI ui = PlayerUI.Get(player_id); auto_move_drop = ui != null?ui.GetSelectedSlotIndex() : -1; auto_move_drop_inventory = ui != null?ui.GetSelectedSlotInventory() : null; } }
void Awake() { parent_ui = GetComponentInParent <PlayerUI>(); bar = GetComponent <ProgressBar>(); }