public static bool DoesComponentFitInSlot(ComponentSlot _slot, ComponentObject _comp, out float _efficiency) { _efficiency = 0; if ((_slot.SlotType != _comp.Type && _comp.StaticInfo.EfficiencyInOtherSlots.Find(x => x.Type == _slot.SlotType) == null)) { return(false); // stop if the held component doesn't match the slot and can't be jury-rigged into the slot } // determine how good a match the component is if (_slot.SlotTypeID == _comp.TypeID) { _efficiency = 1; } else { int _effIndex = _comp.StaticInfo.EfficiencyInOtherSlots.FindIndex(x => x.Type == _slot.SlotType); if (_effIndex > -1) { _efficiency = _comp.StaticInfo.EfficiencyInOtherSlots[_effIndex].Efficiency; } } if (_efficiency == 0) { return(false); // stop if the held component is as good as a non-match } return(true); }
public bool canConnectToSlot(ComponentSlot slot) { if (slot == null) { return(false); } if (_connectedSlot != null) { return(false); } if (!_willConnectComponentSlots.Contains(slot)) { return(false); } if (slot._currentComponent == this._currentComponent) { return(false); } if (!slot._type.Equals(this._type)) { return(false); } return(true); }
public void DropItem() { if (itemslot != null) { isCreate = false; itemslot.containitem = false; itemslot = null; } }
public bool disconnectToSlot(ComponentSlot slot) { if (_connectedSlot != slot) { return(false); } _connectedSlot = null; return(true); }
private void OnTriggerExit(Collider other) { if (other.CompareTag("ComponentSlot")) { ComponentSlot componentSlot = other.GetComponent <ComponentSlot>(); _willConnectComponentSlots.Remove(componentSlot); if (_willConnectComponentSlots.Count == 0) { this.setEnableSlotVisual(false); } } }
public void EqipItem(ComponentSlot slot) { isCreate = true; this.transform.SetParent(slot.transform); slot.containitem = true; transform.localScale = Vector3.one; transform.localPosition = Vector3.zero; slot.ship.ComponentController.CreateFromItem(this); GetComponent <Image>().enabled = false; itemslot = slot; }
public bool connectToSlot(ComponentSlot slot) { if (!this.canConnectToSlot(slot)) { return(false); } _willConnectComponentSlots.Remove(slot); _connectedSlot = slot; this.setEnableSlotVisual(false); return(true); }
// Use this for initialization void Start() { slot = transform.GetComponentInParent <ComponentSlot>(); if (SlotType != SlotTypeEnum.Weapon) { slot.component = transform.gameObject.GetComponent <ShipComponent>(); } else { slot.weapon = transform.gameObject.GetComponent <Weapon>(); slot.weapon.LookPoint = slot.LookPoint; } }
private void OnTriggerEnter(Collider other) { if (other.CompareTag("ComponentSlot")) { ComponentSlot componentSlot = other.GetComponent <ComponentSlot>(); _willConnectComponentSlots.Add(componentSlot); if (!this.canConnectToSlot(componentSlot)) { _willConnectComponentSlots.Remove(componentSlot); return; } this.setEnableSlotVisual(true); } }
public void CreateRecipeUI(Recipe recipe) { RecipeSlot recipeSlot = Instantiate(RecipeUiSlotModel); Button craftButton = PlayerShooting.getChildGameObject(recipeSlot.gameObject, "CraftingButton").GetComponent <Button>(); craftButton.onClick.AddListener(delegate { PlayerInfo.PlayerInventory.TryRecipe(recipe); }); Debug.LogError("Created for recipe " + recipe); foreach (Item component in recipe.Components) { ComponentSlot componentSlot = Instantiate(ComponentUiSlotModel); componentSlot.transform.SetParent(recipeSlot.ComponentsContainer, false); Image icon = PlayerShooting.getChildGameObject(componentSlot.gameObject, "Icon").GetComponent <Image>(); icon.sprite = component.icon; Text text = componentSlot.GetComponentInChildren <Text>(); int componentIndex = recipe.Components.IndexOf(component); int possessed = PlayerInfo.PlayerInventory.GetItemPossessedAmount(component); int needed = recipe.ComponentsAmounts[componentIndex]; text.text = possessed + "/" + needed; if (possessed >= needed) { text.color = Color.green; } else { text.color = Color.red; } } if (recipe.targetItem != null) { Debug.LogError("Recipe target item: " + recipe.targetItem.name); Image resultIcon = recipeSlot.Result.GetComponentInChildren <Image>(); resultIcon.sprite = recipe.targetItem.icon; } recipeSlot.transform.SetParent(recipesContainer, false); }
public bool addSubComponent(Component subComponent) { ComponentSlot fromSlot = subComponent.getReadyConnectSlots().FirstOrDefault(); ComponentSlot toSlot = this.getReadyConnectSlots().FirstOrDefault(); if (fromSlot == null || toSlot == null) { return(false); } if (!fromSlot.connectToSlot(toSlot)) { return(false); } if (!toSlot.connectToSlot(fromSlot)) { fromSlot.disconnectToSlot(toSlot); return(false); } subComponent.setEnableGrab(false); subComponent.transform.parent = this.transform; subComponent.transform.forward = toSlot.transform.forward; subComponent.transform.rotation = toSlot.transform.rotation; subComponent.transform.position += (toSlot.transform.position - fromSlot.transform.position); this._subComponents.Add(subComponent); subComponent._parentComponent = this; // this._subJoints.Add(fixedJoint); foreach (ComponentSlot componentSlot in this.getAllSlots()) { componentSlot._currentComponent = this; } return(true); }
public void RemoveComponent(ComponentSlot slot) { componentTable.Remove(slot); slot.installedComponent = null; }
public void AddComponent(ComponentSlot slot, ShipComponent component) { componentTable.Add(slot, component); }
public void AddComponent(ShipComponent component, ComponentSlot slot) { componentTable.Add(slot, component); slot.installedComponent = component; }