Example #1
0
    /// <summary>
    /// Called when piece is colliding from its top 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 OnTopCollision(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)
        {
            //Debug.Log(CollidingPieceId + "," + ThisPieceData.ID + " Top Collision");

            //Get colliding piece position in grid
            int CPElementRow = -1;
            int CPElementCol = -1;
            PPPuzzleController.ArrayPosToRC(CollidingPieceId, JpPuzzleControllerInstance.PiecesInCol,
                                            JpPuzzleControllerInstance.PiecesInRow, out CPElementRow, out CPElementCol);



            //Get this piece position in grid
            int PElementRow = -1;
            int PElementCol = -1;
            PPPuzzleController.ArrayPosToRC(ThisPieceData.ID, JpPuzzleControllerInstance.PiecesInCol,
                                            JpPuzzleControllerInstance.PiecesInRow, out PElementRow, out PElementCol);

            if (ThisPieceData.ID < CollidingPieceId && PElementCol == CPElementCol && PElementRow == CPElementRow - 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,
                                                 ColP.transform.position.y - JpPuzzleControllerInstance.PieceHeightInWorld, ColP.transform.position.z);

                ColP.transform.root.parent = transform;

                OnPieceJoined();

                CheckForPuzzleComplete(transform);
            }
        }
    }
    public override void OnInspectorGUI()
    {
        PPPuzzleController myTarget = (PPPuzzleController)target;

        EditorGUILayout.Space();

        myTarget.UseFilePath = EditorGUILayout.Toggle("Use file", myTarget.UseFilePath);

        if (myTarget.UseFilePath)
        {
            //Populate files data in combobox

            if (FileNames == null)
            {
                EditorGUILayout.HelpBox("Currently no file present, please create file using PMFileCreator from Window->PuzzleMaker->CreatePMFile", MessageType.Error);
            }
            else if (FileNames.Length == 0)
            {
                EditorGUILayout.HelpBox("Currently no file present, please create file using PMFileCreator from Window->PuzzleMaker->CreatePMFile", MessageType.Error);
            }
            else if (FileNames.Length > 0)
            {
                GUIContent[] _contentList = new GUIContent[FileNames.Length];

                for (int i = 0; i < FileNames.Length; i++)
                {
                    _contentList[i] = new GUIContent(System.IO.Path.GetFileName(FileNames[i]));
                }

                myTarget._selectedFileIndex = EditorGUILayout.Popup(new GUIContent("PM File"), myTarget._selectedFileIndex, _contentList);

                myTarget.PMFilePath = FileNames[myTarget._selectedFileIndex];
            }
        }
        else
        {
            base.OnInspectorGUI();
        }



        EditorUtility.SetDirty(target);
    }
Example #3
0
    public override void OnInspectorGUI()
    {
        PPPuzzleController myTarget = (PPPuzzleController)target;

        EditorGUILayout.Space();

        myTarget.PiecesDisplayMode = (EPieceDisplayMode)EditorGUILayout.EnumPopup("Pieces Display Mode", myTarget.PiecesDisplayMode);

        myTarget.UseFilePath = EditorGUILayout.Toggle("Use file", myTarget.UseFilePath);

        if (myTarget.UseFilePath)
        {
            //Populate files data in combobox

            if (FileNames == null)
            {
                EditorGUILayout.HelpBox("Currently no file present, please create file using PMFileCreator from Window->PuzzleMaker->CreatePMFile", MessageType.Error);
            }
            else if (FileNames.Length == 0)
            {
                EditorGUILayout.HelpBox("Currently no file present, please create file using PMFileCreator from Window->PuzzleMaker->CreatePMFile", MessageType.Error);
            }
            else if (FileNames.Length > 0)
            {
                GUIContent[] _contentList = new GUIContent[FileNames.Length];

                for (int i = 0; i < FileNames.Length; i++)
                {
                    _contentList[i] = new GUIContent(System.IO.Path.GetFileName(FileNames[i]));
                }

                myTarget._selectedFileIndex = EditorGUILayout.Popup(new GUIContent("PM File"), myTarget._selectedFileIndex, _contentList);

                myTarget.PMFilePath = FileNames[myTarget._selectedFileIndex];
            }
        }
        else
        {
            if (myTarget.JointMaskImage == null)
            {
                EditorGUILayout.HelpBox("You should provide atleast 1 joint mask image", MessageType.Error);
            }
            else if (myTarget.JointMaskImage.Length == 0)
            {
                EditorGUILayout.HelpBox("You should provide atleast 1 joint mask image", MessageType.Error);
            }

            base.OnInspectorGUI();
        }


        EditorGUILayout.Space();
        myTarget.AnimateColorOnWrongPiece = EditorGUILayout.Toggle("AnimateColorOnWrongPiece ", myTarget.AnimateColorOnWrongPiece);

        if (myTarget.AnimateColorOnWrongPiece)
        {
            myTarget.WrongPieceAnimationColor = EditorGUILayout.ColorField("Animation Color", myTarget.WrongPieceAnimationColor);
            myTarget.NoOfTimesToBlink         = EditorGUILayout.IntSlider("No Of Times To Blink", myTarget.NoOfTimesToBlink,
                                                                          1, 5);
            myTarget.BlinkSpeed = ((float)EditorGUILayout.IntSlider("Effect speed", (int)(myTarget.BlinkSpeed * 100f), 1, 300)) / 100;
        }


        EditorGUILayout.Space();
        myTarget.ShufflePieces = EditorGUILayout.Toggle("Shuffle pieces ", myTarget.ShufflePieces);
        myTarget.ActualImageOnPuzzleComplete = EditorGUILayout.Toggle("Actual Image On Puzzle Complete", myTarget.ActualImageOnPuzzleComplete);

        EditorGUILayout.Space();
        EditorGUILayout.Space();
        EditorGUILayout.HelpBox("Leave empty if you dont want to play audio", MessageType.Info);
        myTarget.PiecePlacedSound      = (AudioClip)EditorGUILayout.ObjectField("Piece Placed Sound ", myTarget.PiecePlacedSound, typeof(AudioClip));
        myTarget.WrongPlacementSound   = (AudioClip)EditorGUILayout.ObjectField("Wrong Placement Sound ", myTarget.WrongPlacementSound, typeof(AudioClip));
        myTarget.PiecePickupSound      = (AudioClip)EditorGUILayout.ObjectField("Piece Pickup Sound ", myTarget.PiecePickupSound, typeof(AudioClip));
        myTarget.PuzzleCompletionSound = (AudioClip)EditorGUILayout.ObjectField("Puzzle Completion Sound ", myTarget.PuzzleCompletionSound, typeof(AudioClip));
        myTarget.BackgroundMusic       = (AudioClip)EditorGUILayout.ObjectField("Background Music ", myTarget.BackgroundMusic, typeof(AudioClip));


        EditorGUILayout.Space();
        EditorGUILayout.Space();
        EditorGUILayout.Space();
        SerializedProperty sprop = serializedObject.FindProperty("OnPuzzleComplete");

        EditorGUILayout.PropertyField(sprop);

        sprop = serializedObject.FindProperty("OnPiecePlaced");
        EditorGUILayout.PropertyField(sprop);

        serializedObject.ApplyModifiedProperties();

        EditorUtility.SetDirty(target);
    }
    void OnBottomCollision(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)
        {
            //Get colliding piece position in grid
            int CPElementRow = 0;
            int CPElementCol = 0;
            PPPuzzleController.ArrayPosToRC(CollidingPieceId, JpPuzzleControllerInstance.PiecesInCol,
                                            JpPuzzleControllerInstance.PiecesInRow, out CPElementRow, out CPElementCol);


            //Get this piece position in grid
            int PElementRow = 0;
            int PElementCol = 0;
            PPPuzzleController.ArrayPosToRC(ThisPieceData.ID, JpPuzzleControllerInstance.PiecesInCol,
                                            JpPuzzleControllerInstance.PiecesInRow, out PElementRow, out PElementCol);


            if (ThisPieceData.ID > CollidingPieceId && PElementCol == CPElementCol && PElementRow == CPElementRow + 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
                CalculatedPos.x = ColP.transform.position.x - (ColPRightJointWorldScale / 2) + (ColPLeftJointWorldScale / 2) +
                                  (RightJointWorldScale / 2) - (LeftJointWorldScale / 2);

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


                CalculatedPos.z = transform.position.z;

                transform.position = CalculatedPos;

                ColP.transform.root.parent = transform;

                CheckForPuzzleComplete(transform);
            }
        }
    }