Ejemplo n.º 1
0
    private void handleFirstTouchBegin(Touch touch){
        bool isPlacementCorrecting = activePiece != null && activePiece.GetComponent<PiecePrefabBehaviour>().isPlacementCorrecting();
        if(!resetButtonScript.getResettable() && !isPlacementCorrecting){ // don't want to detect piece touches while the machine is resettable or while placement correction is occurrring
            GameObject hitObject = getSignificant3DObjectHit(touch);
            if(hitObject != null){ // raycast hit a piece
                currTouchAction = TouchAction.MovingPiece;
                hitObject.GetComponent<PiecePrefabBehaviour>().OnPieceTouchBegin();
                return;
            }
        }

        // check if user touched any Canvas objects
        if(hitCanvasElement(touch)){
            return; // user touched something on the canvas, so don't bother with rotation/zooming/panning
        }

        // user didn't touch anything (e.g. buttons, scroll bar) on the canvas. 
        // Since we already know user didn't touch a significant 3D piece either, we'll assume they were either starting to rotate the camera or touching the screen to clear their piece selection. 
        // Either way, clear their piece selection and begin rotation
        ClearActivePiece();
        currTouchAction = TouchAction.RotatingCamera;
        prevFrameFirstTouchPosition = touch.position;
    }
    public void removeActivePiece()
    {
        GameObject           activePiece       = raycastingScript.activePiece;
        PiecePrefabBehaviour activePieceScript = activePiece.GetComponent <PiecePrefabBehaviour>();

        // mark the snap-to target GameObject that the piece is currrently occupying, if there is one, as unoccupied
        GameObject target = activePieceScript.currOccupiedSnapToTarget;

        if (target != null)
        {
            target.GetComponent <SnapToTargetBehaviour>().occupied = false;
        }

        // remove activePiece's colliders from the collidersInContact lists of any other GameObjects in contact with activePiece
        foreach (Collider colliderInContact in activePieceScript.collidersInContact) // for each collider in contact with activePiece
        {
            Transform parent = colliderInContact.gameObject.transform.parent;
            if (parent == null || parent.gameObject.name != "Workspace Boundaries")                                                               // presumably, therefore, the collider in question belongs to a machine piece that's in contact with activePiece
            {
                PiecePrefabBehaviour pieceInContactScript = getCompletePiece(colliderInContact.gameObject).GetComponent <PiecePrefabBehaviour>(); // get that collider's piece and its script
                int lastIndex = pieceInContactScript.collidersInContact.Count - 1;
                for (int i = lastIndex; i >= 0; i--)                                                                                              // for each collider in contact with the piece in question
                {
                    Collider colliderInContactWithOtherPiece = pieceInContactScript.collidersInContact[i];
                    if (isDescendent(colliderInContactWithOtherPiece.gameObject.transform, activePiece.transform)) // if the collider belongs to activePiece
                    // remove the collider from the collidersInContact list of the piece in question
                    {
                        pieceInContactScript.collidersInContact.RemoveAt(i);
                    }
                }
            }
        }

        // finally, actually take care of removing the piece
        if (resetButtonScript.getResettable())
        {
            raycastingScript.piecesRemovedWhileResettable.Add(activePiece);
            activePiece.SetActive(false);
        }
        else
        {
            Destroy(activePiece);
        }
        raycastingScript.pieces.Remove(activePiece); // needs to be before the call to clearActivePiece
        raycastingScript.ClearActivePiece();
    }