Esempio n. 1
0
    /// <summary>
    /// Called when piece is colliding from its right side
    /// </summary>
    /// <param name="CollidingPieceId">Id of piece colliding with</param>
    /// <param name="ColP">Instance of piece colliding with</param>
    /// <param name="ColPPieceData">Metadata of piece colliding with</param>
    /// <param name="ColObjController">JPPieceController instance of piece colliding with</param>
    void OnRightCollision(int CollidingPieceId, GameObject ColP, SPieceInfo ColPPieceData, JPPieceController ColObjController)
    {
        //Check if this is child of current holding piece then apply collision logic
        bool IsChildOfHoldingPiece = false;

        JPPieceController[] ChildrenControllers = transform.GetComponentsInChildren <JPPieceController>();
        foreach (JPPieceController item in ChildrenControllers)
        {
            if (ThisPieceData.ID == item.ThisPieceData.ID)
            {
                IsChildOfHoldingPiece = true;
                break;
            }
        }


        if (ThisPieceData.ID == JpPuzzleControllerInstance.HoldingPieceID() || IsChildOfHoldingPiece)
        {
            if (ThisPieceData.ID == CollidingPieceId - 1)
            {
                //If is child of holding piece make it parent
                //Make this piece parent of all
                Transform Temp = transform.root;
                transform.parent = null;
                Temp.parent      = transform;

                JpPuzzleControllerInstance.UnholdPiece();

                transform.position = new Vector3(ColP.transform.position.x - JpPuzzleControllerInstance.PieceWidthInWorld,
                                                 ColP.transform.position.y, ColP.transform.position.z);

                ColP.transform.root.parent = transform;

                OnPieceJoined();

                CheckForPuzzleComplete(transform);
            }
        }
        else
        {
            //Wrong Piece
        }
    }
Esempio n. 2
0
    void OnRightCollision(int CollidingPieceId, GameObject ColP, SPieceInfo ColPPieceData, JPPieceController ColObjController)
    {
        //Check if this is child of current holding piece then apply collision logic
        bool IsChildOfHoldingPiece = false;

        JPPieceController[] ChildrenControllers = transform.GetComponentsInChildren <JPPieceController>();
        foreach (JPPieceController item in ChildrenControllers)
        {
            if (ThisPieceData.ID == item.ThisPieceData.ID)
            {
                IsChildOfHoldingPiece = true;
                break;
            }
        }


        if (ThisPieceData.ID == JpPuzzleControllerInstance.HoldingPieceID() || IsChildOfHoldingPiece)
        {
            if (ThisPieceData.ID == CollidingPieceId - 1)
            {
                //If is child of holding piece make it parent
                //Make this piece parent of all
                Transform Temp = transform.root;
                transform.parent = null;
                Temp.parent      = transform;



                JpPuzzleControllerInstance.UnholdPiece();

                Vector3 CalculatedPos = new Vector3();


                float LeftJointWorldScale  = 0;
                float RightJointWorldScale = 0;
                float TopJointWorldScale   = 0;
                float BotJointWorldScale   = 0;

                float ColPLeftJointWorldScale  = 0;
                float ColPRightJointWorldScale = 0;
                float ColPTopJointWorldScale   = 0;
                float ColPBotJointWorldScale   = 0;


                //Calculate required data
                CalculateDataForCollisionPlacement(ColPPieceData, out ColPLeftJointWorldScale, out ColPRightJointWorldScale,
                                                   out ColPTopJointWorldScale, out ColPBotJointWorldScale);
                CalculateDataForCollisionPlacement(ThisPieceData, out LeftJointWorldScale, out RightJointWorldScale,
                                                   out TopJointWorldScale, out BotJointWorldScale);


                //Calculate X
                //Calculated X without joints
                float CalcXWJ = ColP.transform.position.x - JpPuzzleControllerInstance.PieceWidthInWorld;


                CalculatedPos.x = CalcXWJ - (ColPRightJointWorldScale / 2) + (ColPLeftJointWorldScale / 2) +
                                  (RightJointWorldScale / 2) - (LeftJointWorldScale / 2);



                //Calculate Y
                CalculatedPos.y = ColP.transform.position.y + (TopJointWorldScale / 2) - (BotJointWorldScale / 2)
                                  - (ColPTopJointWorldScale / 2) + (ColPBotJointWorldScale / 2);



                CalculatedPos.z = transform.position.z;

                transform.position = CalculatedPos;

                ColP.transform.root.parent = transform;

                CheckForPuzzleComplete(transform);
            }
        }
    }