private void UpdateInstallRopeNode() { if (Input.GetMouseButtonDown(0)) { TryPlaceNode(); } else { ray = viewCamera.ScreenPointToRay(Input.mousePosition); hits = Physics.RaycastAll(ray, hitDistence, (1 << Layers.ropePosLayer)); if (hits != null || hits.Length > 0) { bool hited = false; for (int i = 0; i < hits.Length; i++) { if (pickUpedRopeNode == null) { return; } if (hits[i].collider.name == pickUpedRopeNode.name) { hited = true; ropeTarget = hits[i].collider.GetComponentInParent <RopeObj>(); pickDownAble = CanPlaceNode(ropeTarget, ropeSelected, pickUpedRopeNode, out resonwhy); } } if (!hited) { pickDownAble = false; resonwhy = "零件放置位置不正确"; } } } }
private void TrySelectNode() { ray = viewCamera.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit, hitDistence, (1 << Layers.ropeNodeLayer))) { var obj = hit.collider.GetComponentInParent <RopeObj>(); if (obj != null && obj.Started && !obj.Complete)//正在进行操作 { obj.PickupCollider(hit.collider); ropeSelected = obj; pickUpedRopeNode = hit.collider; Debug.Log("Select: " + pickUpedRopeNode); elementDistence = Vector3.Distance(viewCamera.transform.position, pickUpedRopeNode.transform.position); } } }
private void TryPlaceNode() { ray = viewCamera.ScreenPointToRay(Input.mousePosition); if (pickDownAble) { PlaceNode(pickUpedRopeNode); } else { PlaceNodeWrong(ropeSelected, pickUpedRopeNode); userErr(resonwhy); } pickUpedRopeNode = null; ropeSelected = null; pickDownAble = false; }
private static bool CanPlaceNode(RopeObj ropeTarget, RopeItem ropeSelected, Collider collider, out string resonwhy) { resonwhy = null; if (ropeSelected.BindingTarget != ropeTarget) { resonwhy = "对象不匹配"; } else if (ropeTarget == null) { resonwhy = "目标点父级没有挂RopeObj脚本"; } else if (ropeTarget.Connected) { resonwhy = "目标点已经完成连接"; } else if (!ropeTarget.CanInstallCollider(collider)) { resonwhy = "坐标点已经占用"; } return(resonwhy == null); }
private void RopeNodeMoveWithMouse(float distence) { disRay = viewCamera.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(disRay, out disHit, distence, 1 << Layers.obstacleLayer)) { if (!ropeSelected.TryMoveToPos(pickUpedRopeNode, disHit.point)) { ropeSelected.PickDownCollider(pickUpedRopeNode); pickUpedRopeNode = null; ropeSelected = null; } } else { var pos = disRay.GetPoint(elementDistence); if (!ropeSelected.TryMoveToPos(pickUpedRopeNode, pos)) { ropeSelected.PickDownCollider(pickUpedRopeNode); pickUpedRopeNode = null; ropeSelected = null; } } }
private void PlaceNodeWrong(RopeObj ropeItem, Collider collider) { Debug.Log("PlaceNodeWrong"); ropeItem.PickDownCollider(collider); }