コード例 #1
0
    private void PlaceAction()
    {
        if (ic != null && icModel != null)
        {
            switch (ic.IcType)
            {
            case ICType.breadboard:
            case ICType.powerrail:
                if (raycastManager.GetNodeId(out RaycastHit hit1, out string _, "Ground"))
                {
                    int x = Mathf.RoundToInt(hit1.point.x);
                    int z = Mathf.RoundToInt(hit1.point.z);
                    icModel.transform.position = new Vector3(x, 0, z);

                    string type = (ic.IcType == ICType.breadboard ? "0" : "1");

                    if (fabricator.canPlaceBreadBoard(type, x, z, placeRotated))
                    {
                        fabricator.addBoard(type, x, z, placeRotated);
                    }
                    else
                    {
                        Debug.Log("Cannot place item here");
                    }
                }
                else
                {
                    icModel.transform.position = GameObjectPool;
                }
                break;

            default:
                if (raycastManager.GetNodeId(out RaycastHit hit2, out string nodeId, "Pin"))
                {
                    int index = CircuitHelper.GetIndexFromNode(nodeId, hit2.point);

                    int x = Mathf.RoundToInt(hit2.point.x);
                    int z = Mathf.RoundToInt(hit2.point.z);
                    icModel.transform.position = new Vector3(x, 0, z);

                    if (circuitPool.CanPlace(ic.IcType, ic.Pins, nodeId, index))
                    {
                        PlaceComponent(nodeId, index, new Vector3(x, 0, z));
                    }
                    else
                    {
                        Debug.Log("Cannot place item here");
                    }
                }
                else
                {
                    icModel.transform.position = GameObjectPool;
                }
                break;
            }
        }
    }
コード例 #2
0
    private void PlaceAction()
    {
        if (ic != null && (ic.IcType == ICType.breadboard || ic.IcType == ICType.powerrail))
        {
            PlaceActionBreadBoard();
            return;
        }

        int layer_mask = LayerMask.GetMask("Pin");
        Ray ray        = Camera.main.ScreenPointToRay(Input.mousePosition);

        if (Physics.Raycast(ray, out RaycastHit hit, 500, layer_mask) && !EventSystem.current.IsPointerOverGameObject())
        {
            if (ic != null && icModel != null)
            {
                string nodeId = hit.transform.gameObject.name;
                int    index  = CircuitHelper.GetIndexFromNode(nodeId, hit.point);

                int x = Mathf.RoundToInt(hit.point.x);
                int z = Mathf.RoundToInt(hit.point.z);
                icModel.transform.position = new Vector3(x, 0, z);

                if (circuitPool.CanPlace(ic.IcType, ic.Pins, nodeId, index))
                {
                    PlaceComponent(nodeId, index, new Vector3(x, 0, z));
                }
                else
                {
                    Debug.Log("Cannot place item here");
                }
            }
        }