public void setPart(RobotPart part) { if (!part.isBroken && transform.GetChild((int)part.whatPart).childCount > 0) { part.transform.parent = transform.GetChild((int)part.whatPart); } }
/// <summary> /// Überprüft, ob der Roboter bereits ein Teil mit der selben Klasse(z.B. Welder oder Boat) hat. /// </summary> /// <param name="partToCheck"></param> /// <returns></returns> public RobotPart AlreadyHasPartOfClass(RobotPart partToCheck) { foreach (RobotPart part in parts) { if (partToCheck.GetType() == part.GetType()) { return(part); } } return(null); }
public bool AttachRobotPart <T>() where T : RobotPart { RobotPart newRobotPart = gameObject.AddComponent <T>(); this.AttacehdRobotParts.Add(newRobotPart); newRobotPart.MotherRobotBase = this; RobotPartCache.Add(typeof(T), newRobotPart); return(true); }
/// <summary> /// Entfernt das angebene Teil von der Teileliste des Roboters, sofern es in dessen Teileliste ist. /// </summary> /// <param name="part"></param> public void RemovePart(RobotPart part) { if (parts.Contains(part)) { parts.Remove(part); part.RemoveFrom(this); } else { Debug.LogError("Das Teil kann nicht vom Roboter entfernt werden, weil es nicht ein Teil von dessen Teileliste ist."); } }
/// <summary> /// Fügt das angegebene Teil zur Teileliste des Roboters hinzu. /// Teile der Typen 'Tool' und 'Mobility' ersetzen bereits hinzugefügte Teile des gleichen Typs. /// </summary> /// <param name="part"></param> public void AddPart(RobotPart part) { if (part.type != RobotPart.PartType.Sensor) { RemovePartsOfSameType(part.type); } if (AlreadyHasPartOfClass(part) == null) { parts.Add(part); part.AddTo(this); } }
public void IdentifyRobotPart(RobotPart robotPart) { switch (robotPart.RobotPartCategory) { case RobotPartCategory.Assembly: TransportMechanism = new AssemblyRoomTransportMechanism(); break; case RobotPartCategory.Weapon: TransportMechanism = new ArmouryTransportMechanism(); break; } }
public void CheckInputs(RobotPart part) { if (Input.GetKeyDown(dropDownKey)) { gameManager.selectedPart.attachedToEntity.RemoveRobotPart(gameManager.selectedPart); } else if (Input.GetKeyDown(getCloseParts)) { gameManager.selectedPart.attachedToEntity.CheckProximity(gameManager.selectedPart); } if (part.isAttached) { if (part.attachedInput.inputType == InputType.axis) { var x = Input.GetAxis("Horizontal"); var z = Input.GetAxis("Vertical"); if ((x != 0 || z != 0)) { part.AttachedAction(x, z); } } else { if (Input.GetKeyDown(part.attachedInput.key)) { part.AttachedAction(1, 0); } } } else { if (part.detachedInput.inputType == InputType.axis) { var x = Input.GetAxis("Horizontal"); var z = Input.GetAxis("Vertical"); if ((x != 0 || z != 0)) { part.DetachedAction(x, z); } } else { if (Input.GetKeyDown(part.detachedInput.key)) { part.DetachedAction(1, 0); } } } }
public void CheckProximity(RobotPart part) { var colliders = Physics.BoxCastAll(part.transform.position, Vector3.one * 4, Vector3.up); var entities = new List <Entity>(); foreach (var collider in colliders) { var entity = collider.collider.gameObject.GetComponent <Entity>(); if (entity != null && entity != this) { ReceiveOtherEntity(entity); } } }
public void RemoveRobotPart(RobotPart part) { Entity entity = part.attachedToEntity; if (part.attachedToEntity.parts.Count > 1) { RobotPart highestPart = part.attachedToEntity.parts[0]; for (int i = 0; i < entity.parts.Count; i++) { if (part.attachedToEntity.parts[i].partNumber > highestPart.partNumber) { highestPart = part.attachedToEntity.parts[i]; } } RaycastHit hit; if (!Physics.Raycast(highestPart.transform.position, entity.transform.forward, 1f)) { var from = highestPart.transform.position + gameObject.transform.forward; if (Physics.Raycast(from, from + Vector3.down * 10f, out hit, 10f)) { if (hit.collider.tag == "RobotPart") { return; } Debug.Log("Ho colpito: " + hit.transform.name); part.transform.parent = null; var go = new GameObject(); go.SetActive(false); var component = go.AddComponent <Entity>(); component.parts.Add(part); go.AddComponent <BoxCollider>(); go.AddComponent <Rigidbody>().freezeRotation = true; go.SetActive(true); part.attachedToEntity = component; part.transform.parent = go.transform; parts.Remove(part); CreateBoxCollider(); ReorderParts(); go.transform.position = hit.point + Vector3.up * 0.7f; go.tag = "RobotPart"; } else { Debug.Log("Can't puut it there"); } } } }
/// <summary> /// Wird aufgerufen, wenn der Spieler auf einen Button klickt, der zu einem Part gehört. /// Fügt das Teil dann zum derzeitig ausgewählten Roboter hinzu und passt die Buttons an. /// </summary> /// <param name="partName"></param> public void PartButtonClick(string partName) { Robot robot = RobotManager.Instance.selectedRobot.GetComponent <Robot>(); RobotPart partToAdd = CreatePartWithName(partName); if (robot.AlreadyHasPartOfClass(partToAdd) != null) { RobotManager.Instance.RemovePartFromRobot(robot.gameObject, robot.AlreadyHasPartOfClass(partToAdd)); AdjustTotalCostDisplay(); } else { AddPartToSelectedRobot(partToAdd); } AdjustButtonColors(); }
/* * Assigns the dictionary that matches the key to the value * if the child is equal to the value */ private void ChangeValue(string key, string value, RobotPart child) { if (value == child.obj_name) { if (!part_success[key]) { FindObjectOfType <RobotGameManager>().ChangeScore(5); part_success[key] = true; } } else { Debug.Log("Key " + key + ", Value: " + value); child.is_fading = true; } }
/// <summary> /// Detach Robot Part From Robot /// </summary> /// <returns><c>true</c>, if robot part was detached successfully, <c>false</c> otherwise.</returns> /// <typeparam name="T">Robot Part Type</typeparam> public bool DetachRobotPart <T>() where T : RobotPart { for (int i = 0; i < this.AttacehdRobotParts.Count; i++) { if (this.AttacehdRobotParts[i] is T) { RobotPart robotPart = this.AttacehdRobotParts[i]; this.AttacehdRobotParts.RemoveAt(i); Destroy(robotPart); // Destroy From Scene return(true); } } return(false); }
static async Task RunAsync() { using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://localhost:60985/"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); // HTTP GET HttpResponseMessage response = await client.GetAsync("api/robotparts/2"); if (response.IsSuccessStatusCode) { RobotPart robotPart = await response.Content.ReadAsAsync<RobotPart>(); Console.WriteLine("Part #2: ID: {0}, Serial Number: {1}, Name: {2}, Mnf: {3}, Weight: {4}", robotPart.Id, robotPart.SN, robotPart.Name, robotPart.Manufacturer, robotPart.Weight); Console.WriteLine("Press enter to add a new part"); Console.Read(); } // HTTP POST var gizmo = new RobotPart() { Id = 5, SN = "4553", Name = "TTT", Manufacturer = "ABB", Weight = 88, CompatibleWith = "OOO" }; response = await client.PostAsJsonAsync("api/robotparts", gizmo); if (response.IsSuccessStatusCode) { Uri gizmoUrl = response.Headers.Location; // HTTP PUT //gizmo.Weight = 80; // Update price // response = await client.PutAsJsonAsync(gizmoUrl, gizmo); // HTTP DELETE //response = await client.DeleteAsync(gizmoUrl); } } }
public List <RobotPartRuntimeObject> LoadRobot(RobotData CurrentRobot, GameObject robotBodyGameObject) { List <RobotPartRuntimeObject> RobotParts; RobotParts = new List <RobotPartRuntimeObject>(); RobotPart SelectedRobotPart = null; GameObject SelectedRobotPartGameObject = new GameObject(); GameObject RobotRootObject = new GameObject(); SetRigidBodyCount(0); if (CurrentRobot.robotDataEntries != null) { foreach (RobotDataEntry robotDataEntry in CurrentRobot.robotDataEntries) { SelectedRobotPart = partsManager.GetRobotPartFromRobotDataEntry(robotDataEntry); SelectedRobotPartGameObject = Instantiate(SelectedRobotPart.robotPartPrefab); SetLayerRecursively(SelectedRobotPartGameObject, LayerMask.NameToLayer("Default")); SelectedRobotPartGameObject.transform.parent = robotBodyGameObject.transform; SelectedRobotPartGameObject.transform.localPosition = robotDataEntry.robotPartLocalPosition; SelectedRobotPartGameObject.transform.localRotation = robotDataEntry.robotPartLocalRotation; if (SelectedRobotPart.robotPartType == RobotPartType.WheelPart) { SelectedRobotPartGameObject.GetComponent <FixedJoint>().connectedBody = GetRigidbodyByIndex(robotBodyGameObject, robotDataEntry.parentIndex); SelectedRobotPartGameObject.GetComponent <SimpleWheelController>().SetActivateMotor(robotDataEntry.robotPartSettings.boolSettings[0]); SelectedRobotPartGameObject.GetComponent <SimpleWheelController>().SetActivateSteering(robotDataEntry.robotPartSettings.boolSettings[1]); SelectedRobotPartGameObject.GetComponent <SimpleWheelController>().SetReverseSpinDirection(robotDataEntry.robotPartSettings.boolSettings[2]); } if (SelectedRobotPart.robotPartType == RobotPartType.HingePart) { SelectedRobotPartGameObject.GetComponent <FixedJoint>().connectedBody = GetRigidbodyByIndex(robotBodyGameObject, robotDataEntry.parentIndex); } AddRobotPartRuntimeObject(RobotParts, robotDataEntry.parentIndex, SelectedRobotPart, SelectedRobotPartGameObject); } } return(RobotParts); }
public void GoNext() { List <RobotPart> next = new List <RobotPart>(); for (int i = 0; i < allParts.Count; i++) { if (allParts[i].partNumber > selectedPart.partNumber) { next.Add(allParts[i]); } } next = next.OrderBy(x => x.partNumber).ToList(); if (next.Count == 0) { selectedPart = allParts.OrderBy(x => x.partNumber).ToList().First(); } else { selectedPart = next[0]; } }
public void GoPrevious() { List <RobotPart> next = new List <RobotPart>(); for (int i = 0; i < allParts.Count; i++) { if (allParts[i].partNumber < selectedPart.partNumber) { next.Add(allParts[i]); } } next = next.OrderByDescending(x => x.partNumber).ToList(); if (next.Count == 0) { selectedPart = allParts.OrderBy(x => x.partNumber).ToList().Last(); } else { selectedPart = next[0]; } }
/// <summary> /// Fügt das übergebene Teil zum derzeitig ausgewählten Roboter hinzu. /// </summary> /// <param name="part"></param> private void AddPartToSelectedRobot(RobotPart part) { RobotManager.Instance.AddPartToRobot(RobotManager.Instance.selectedRobot, part); AdjustTotalCostDisplay(); }
// Update is called once per frame public void DoUpdate() { _camera.transform.position += new Vector3(0, 0, Input.mouseScrollDelta.y); //_partsPlaneDistance = 10.0f - _camera.transform.position.z; CursorState stateAtStartOfFrame = _currentState; switch (_currentState) { case CursorState.Default: if (_previousState != CursorState.Default) { //Debug.Log("Default"); Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto); } if (Input.GetMouseButtonDown(0)) { startClick = Input.mousePosition; SelectionPanel.GetComponent <CanvasGroup>().alpha = 1; requestState(CursorState.Selecting); } break; case CursorState.Dummy: requestState(CursorState.Default); break; case CursorState.Menu: break; case CursorState.Hovering: if (_previousState != CursorState.Hovering) { //Debug.Log("Hovering"); Cursor.SetCursor(_hovering, new Vector2(_hovering.width / 2, _hovering.height / 2), CursorMode.Auto); } if (Input.GetKey(KeyCode.T) && Input.GetMouseButtonDown(0)) { Vector3 localCoords = CurrentObject.transform.InverseTransformPoint(getScreenToWorld()); Debug.Log("Local Coords: " + localCoords.ToString()); } if (Input.GetMouseButton(0)) { if (_selectedTransforms.Count > 0 && !Input.GetKey(KeyCode.LeftControl)) //if there are selections and more are not trying to be added { //if the cursor is actually above a selected item Vector3 worldVec = getScreenToWorld(); RaycastHit2D hit = Physics2D.Raycast(new Vector2(worldVec.x, worldVec.y), Vector2.zero); if (hit && !_selectedTransforms.Contains(hit.transform)) { UnselectAll(); _selectedTransforms.Add(hit.transform); } requestState(CursorState.Moving); } else { checkPosForSelection(Input.mousePosition); } } break; case CursorState.Moving: if (_previousState != CursorState.Moving) { //Debug.Log("Moving"); Cursor.SetCursor(_moving, new Vector2(_moving.width / 2, _moving.height / 2), CursorMode.Auto); } if (Input.GetMouseButton(0)) { Vector3 prevWorldPos = _camera.ScreenToWorldPoint(new Vector3(_prevMousePos.x, _prevMousePos.y, _partsPlaneDistance - _camera.transform.position.z)); Vector3 curWorld = getScreenToWorld(); Vector3 worldDelta = curWorld - prevWorldPos; worldDelta.z = 0; foreach (Transform t in _selectedTransforms) { t.position += worldDelta; } } else { requestState(CursorState.Default); } //TODO:move selected objects from mouse delta break; case CursorState.Selecting: if (_previousState != CursorState.Selecting) { //Debug.Log("Selecting"); } if (Input.GetMouseButton(0)) { //TODO: toggle selections bool isControlPressed = Input.GetKey(KeyCode.LeftControl); //don't clear if control is down if (!isControlPressed) { UnselectAll(); } Vector3 mousePos = Input.mousePosition; Vector3 startPoint = startClick; Vector3 difference = mousePos - startClick; if (difference.x < 0) { startPoint.x = mousePos.x; difference.x = -difference.x; } if (difference.y < 0) { startPoint.y = mousePos.y; difference.y = -difference.y; } selection = new Rect(startPoint.x, startPoint.y, difference.x, difference.y); SelectionPanel.GetComponent <RectTransform>().anchoredPosition = new Vector3(selection.x, selection.y); SelectionPanel.GetComponent <RectTransform>().sizeDelta = new Vector2(selection.width, selection.height); } else if (Input.GetMouseButtonUp(0)) { Transform[] ts = MechRoot.GetComponentsInChildren <Transform>(); if (ts.Length != 0) { List <Transform> tsList = new List <Transform>(ts); tsList.Remove(MechRoot.transform); foreach (Transform t in tsList) { RobotPart rp = t.GetComponent <RobotPart>(); if (!rp) { continue; } Vector3 pos = _camera.WorldToScreenPoint(t.position); if (selection.Contains(pos)) { if (!_selectedTransforms.Contains(t.transform)) { _selectedTransforms.Add(t); } } } //check four corners of selection box for intersection with robot parts //have to convert to world space for collider intersections. done in function checkPosForSelection(selection.position); checkPosForSelection(selection.position + new Vector2(selection.width, 0)); checkPosForSelection(selection.position + new Vector2(0, selection.height)); checkPosForSelection(selection.position + new Vector2(selection.width, selection.height)); } SelectionPanel.GetComponent <CanvasGroup>().alpha = 0; SelectionPanel.GetComponent <RectTransform>().sizeDelta = new Vector2(0, 0); requestState(CursorState.Default); } break; case CursorState.Placing: //Debug.Log("Placing"); if (CurrentObject != null) { CurrentObject.transform.position = getScreenToWorld(); } if (Input.GetMouseButtonDown(0) && CurrentObject) { CurrentObject.transform.parent = MechRoot.transform; CurrentObject = null; requestState(CursorState.Default); } break; } //loop for making sure topmost transform is selected List <Transform> toRemove = new List <Transform>(); foreach (Transform t in _selectedTransforms) { for (int i = 0; i < t.childCount; i++) { Transform child = t.GetChild(i); RobotPart rp = child.gameObject.GetComponent <RobotPart>(); if (rp) { toRemove.Add(child); } } } foreach (Transform t in toRemove) { _selectedTransforms.Remove(t); t.gameObject.GetComponent <RobotPart>().Selected = false; } foreach (Transform t in _selectedTransforms) { t.gameObject.GetComponent <RobotPart>().Selected = true; Renderer ren = t.gameObject.GetComponent <Renderer>(); if (!ren) { continue; } ren.material.color = Color.green; for (int i = 0; i < t.childCount; i++) { Transform child = t.GetChild(i); Renderer[] rs = child.gameObject.GetComponentsInChildren <Renderer>(); foreach (Renderer r in rs) { r.material.color = new Color(0, 1, 0, 0.5f); } } } _previousState = stateAtStartOfFrame; _prevMousePos = Input.mousePosition; }
/// <summary> /// Entfernt das übergebene Teil vom angegebenen Roboter. /// </summary> /// <param name="robotObject"></param> /// <param name="part"></param> public void RemovePartFromRobot(GameObject robotObject, RobotPart part) { Robot bot = robotObject.GetComponent <Robot>(); bot.RemovePart(part); }
/// <summary> /// Fügt das übergebene Teil zum angegebenen Roboter hinzu. /// </summary> /// <param name="robotObject"></param> /// <param name="part"></param> public void AddPartToRobot(GameObject robotObject, RobotPart part) { Robot bot = robotObject.GetComponent <Robot>(); bot.AddPart(part); }
private void AddRobotPartRuntimeObject(List <RobotPartRuntimeObject> robotParts, int parentIndex, RobotPart robotPart, GameObject robotPartGameObject) { if (robotParts == null) { robotParts = new List <RobotPartRuntimeObject>(); } robotParts.Add(new RobotPartRuntimeObject(parentIndex, robotPart, robotPartGameObject)); if (robotPart.robotPartType == RobotPartType.CorePart) { robotPartGameObject.GetComponent <CorePart>().OnIsPlaced(ref rigidBodyCount); } if (robotPart.robotPartType == RobotPartType.WheelPart) { robotPartGameObject.GetComponent <WheelPart>().OnIsPlaced(ref rigidBodyCount); } if (robotPart.robotPartType == RobotPartType.HingePart) { robotPartGameObject.GetComponent <HingePart>().OnIsPlaced(ref rigidBodyCount); } }
protected TransportMechanism(RobotPart robotPart) { _robotPart = robotPart; }
public bool DetachRobotPart(RobotPart robotPart) { return(this.AttacehdRobotParts.Remove(robotPart)); }
public RobotPartRuntimeObject(int parentIndex, RobotPart robotPart, GameObject robotPartGameObject) { this.parentIndex = parentIndex; this.robotPart = robotPart; this.robotPartGameObject = robotPartGameObject; }