internal void AddToMap(Map map, Vector3 start, Vector3 end, bool fixEnd) { StartAnchor.transform.position = start; EndAnchor.transform.position = end; StartAnchor.transform.rotation = Quaternion.FromToRotation(Vector3.down, end - start); EndAnchor.transform.rotation = Quaternion.FromToRotation(Vector3.up, start - end); EndAnchor.gameObject.SetActive(fixEnd); int segCount = Mathf.CeilToInt((end - start).magnitude / segmentSize); Vector3 segOffset = (end - start).normalized * segmentSize; Rigidbody prevBody = StartAnchor; for (int i = 0; i < segCount; i++) { Placeable seg = Game.Instance.PrefabsStore.RopeSegment.Create(transform); seg.transform.position = start + i * segOffset; seg.transform.rotation = StartAnchor.transform.rotation; var joint = seg.GetComponent <HingeJoint>(); joint.connectedBody = prevBody; joint.connectedAnchor = new Vector3(0, i == 0 ? 0 : -segmentSize, 0); prevBody = seg.GetComponent <Rigidbody>(); seg.PlaceToMap(map); } if (fixEnd) { EndAnchor.connectedBody = prevBody; EndAnchor.connectedAnchor = new Vector3(0, -segmentSize, 0); } }
private void Update() { var cameraRay = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hitInfo; if (placeableInstance != null) { if (Input.GetKeyDown(KeyCode.R)) { placeableInstance.transform.Rotate(new Vector3(0, 90, 0), Space.World); } if (Input.GetKeyDown(KeyCode.Escape)) { ClearPlaceable(); return; } if (CanPlace()) { placeableInstance.GetComponent <Selectable>().ChangeColor(Color.green); } else { placeableInstance.GetComponent <Selectable>().ChangeColor(Color.red); } var selectionManager = SelectionManager.GetInstance(); if (Physics.Raycast(cameraRay, out hitInfo, float.MaxValue, LayerMask.GetMask("Ground"))) { placeableInstance.transform.position = hitInfo.point; if (CanPlace() && Input.GetMouseButtonUp(0) && !EventSystem.current.IsPointerOverGameObject()) { if (ResourceManager.GetInstance().OffsetAll(-placeableInstance.GetWoodCost(), -placeableInstance.GetStoneCost(), -placeableInstance.GetMetalCost(), 0)) { var buildSite = BuildSite.Instantiate(placeableInstance).GetComponent <Assignable>(); foreach (var worker in selectionManager.GetSelected().Where(s => s.GetComponent <Worker>() != null).Select(s => s.GetComponent <Worker>()).OrderBy(s => s.IsAssigned())) { if (!buildSite.AddWorker(worker)) { break; } } placeableInstance.GetComponent <Selectable>().ChangeColor(Color.clear); placeableInstance = null; selectionManager.DeselectAll(); selectionManager.Enable(); } } else if (Input.GetMouseButtonUp(1)) { ClearPlaceable(); return; } } } }
/// <summary> /// Removes block From Batch /// </summary> /// <param name="block"></param> public void RemoveBlockFromBatch(Placeable block) { block.batch.combineInstances.Remove(block.MeshInCombined); block.GetComponent <MeshRenderer>().enabled = true; RefreshBatch(block); }
public object OnSave() { var data = new Dictionary <string, object>(); data["percentComplete"] = percentComplete; data["pendingInstance"] = pendingInstance == null ? -1 : pendingInstance.GetComponent <Saveable>().GetSavedIndex(); return(data); }
private void HandleRemove(Placeable target) { var chest = target.GetComponent <Chest>(); if (chest) { HideAmount += chest.Bupees; HiddenAmount -= chest.Bupees; } var pot = target.GetComponent <Pot>(); if (pot) { HideAmount += pot.Bupees; HiddenAmount -= pot.Bupees; } SpendAmount += target.Price; Destroy(target.gameObject); }
public static BuildSite Instantiate(Placeable pendingInstance) { var otherGrid = pendingInstance.GetComponent <SnapToCircleGrid>(); var prefab = otherGrid != null?ResourceLoader.GetInstance().BuildSite : ResourceLoader.GetInstance().CircularBuildSite; var instance = Instantiate(prefab, pendingInstance.transform.position, new Quaternion());; if (otherGrid != null) { instance.GetComponent <SnapToCircleGrid>().SetCenter(otherGrid.GetMinNumber(), otherGrid.GetCenter()); } pendingInstance.transform.position += new Vector3(0, -DELTA_Y, 0); instance.pendingInstance = pendingInstance; return(instance); }
public void RefreshBatch(Placeable block) { if (block != null && block.batch != null) { if (block.batch.batchObject == null) { CreateNewBatch(block.batch); } if (block.batch.batchObject != null) { block.batch.batchObject.GetComponent <MeshRenderer>().material = block.GetComponent <MeshRenderer>().material; block.batch.batchObject.GetComponent <MeshFilter>().mesh = new Mesh(); block.batch.batchObject.GetComponent <MeshFilter>().mesh.CombineMeshes( block.batch.combineInstances.ToArray(), true, true); } } }
public void SetPlaceable(Placeable prefab) { if (placeableInstance != null) { placeableInstance.Remove(); } placeableInstance = Instantiate(prefab, Vector3.zero, prefab.transform.rotation); var center = SelectionManager.GetInstance().GetFirstSelected().GetComponent <CentralNode>(); var grid = placeableInstance.GetComponent <SnapToCircleGrid>(); if (grid != null && center != null) { grid.SetCenter(center.MinNumber, center.transform.position); } SelectionManager.GetInstance().Disable(); Update(); }
private void UpdateTooltip() { if (PlaceMode) { if ((PlaceAction != PlaceAction.Hide && PlaceAction != PlaceAction.Sell) || (!TargetPlaceable && !Target)) { Tooltip.gameObject.SetActive(false); return; } if (PlaceAction == PlaceAction.Hide) { if (TargetPlaceable) { Tooltip.gameObject.SetActive(true); var chest = TargetPlaceable.GetComponent <Chest>(); if (chest) { Tooltip.ActionGroup.alpha = 0; Tooltip.StorageGroup.alpha = 1; Tooltip.StorageKeyText.text = "-SPACE-"; Tooltip.StorageTargetText.text = TargetPlaceable.Name; Tooltip.StorageAmountText.text = chest.Bupees.ToString(); Tooltip.StorageMaxText.text = chest.Capacity.ToString(); goto useDone; } var pot = TargetPlaceable.GetComponent <Pot>(); if (pot) { Tooltip.ActionGroup.alpha = 0; Tooltip.StorageGroup.alpha = 1; Tooltip.StorageKeyText.gameObject.SetActive(true); Tooltip.StorageKeyText.text = "-SPACE-"; Tooltip.StorageTargetText.text = TargetPlaceable.Name; Tooltip.StorageAmountText.text = pot.Bupees.ToString(); Tooltip.StorageMaxText.text = pot.Capacity.ToString(); goto useDone; } Tooltip.gameObject.SetActive(false); useDone: Tooltip.transform.position = TargetPlaceable.transform.position; } } else // PlaceAction == PlaceAction.Sell { if (TargetPlaceable) { Tooltip.gameObject.SetActive(true); Tooltip.ActionGroup.alpha = 1; Tooltip.StorageGroup.alpha = 0; Tooltip.ActionTargetText.text = TargetPlaceable.Name; Tooltip.ActionNameText.text = "SELL"; sellDone: Tooltip.transform.position = TargetPlaceable.transform.position; } } } else { if (TalkTimer > 0) { Tooltip.gameObject.SetActive(false); return; } if (TargetPlaceable) { Tooltip.gameObject.SetActive(true); var chest = TargetPlaceable.GetComponent <Chest>(); if (chest) { Tooltip.ActionGroup.alpha = 0; Tooltip.StorageGroup.alpha = 1; Tooltip.StorageKeyText.text = "-----"; Tooltip.StorageTargetText.text = TargetPlaceable.Name; Tooltip.StorageAmountText.text = chest.Bupees.ToString(); Tooltip.StorageMaxText.text = chest.Capacity.ToString(); goto inspectDone; } var pot = TargetPlaceable.GetComponent <Pot>(); if (pot) { Tooltip.ActionGroup.alpha = 0; Tooltip.StorageGroup.alpha = 1; Tooltip.StorageKeyText.text = "-----"; Tooltip.StorageTargetText.text = TargetPlaceable.Name; Tooltip.StorageAmountText.text = pot.Bupees.ToString(); Tooltip.StorageMaxText.text = pot.Capacity.ToString(); goto inspectDone; } Tooltip.gameObject.SetActive(false); inspectDone: Tooltip.transform.position = TargetPlaceable.transform.position; } else if (TargetEnemy) { Tooltip.gameObject.SetActive(true); Tooltip.ActionGroup.alpha = 1; Tooltip.StorageGroup.alpha = 0; Tooltip.ActionTargetText.text = "Lonk the Orlf"; if (Energy >= EnergyShovePrice) { Tooltip.ActionNameText.text = "SHOVE"; } else if (Energy >= EnergyTalkPrice) { Tooltip.ActionNameText.text = "TALK"; } else { Tooltip.ActionNameText.text = "NO ENERGY!"; } Tooltip.transform.position = TargetEnemy.transform.position; } else { Tooltip.gameObject.SetActive(false); } } }