コード例 #1
0
    void OnGUI()
    {
        EditorGUILayout.BeginVertical();

        EditorGUILayout.Separator();

        GUIStyle helpStyle = new GUIStyle(GUI.skin.label);
        helpStyle.wordWrap = true;
        helpStyle.alignment = TextAnchor.UpperLeft;
        EditorGUILayout.LabelField("This window can be use to create Puzzle Maker file that can be used to load puzzle maker class data from file, or you can save only puzzle pieces images created by puzzle maker", helpStyle);

        EditorGUILayout.Separator();
        EditorGUILayout.Separator();

        _piecesInRow = EditorGUILayout.IntSlider("Pieces in row : ",_piecesInRow, 2, 10);

        _piecesInCol = EditorGUILayout.IntSlider("Pieces in col : ", _piecesInCol, 2, 10);

        _selectedTexture = (Texture2D)EditorGUILayout.ObjectField("Puzzle Image", _selectedTexture, typeof(Texture2D), false);

        EditorGUILayout.Separator();

        _noOfJointMasks = EditorGUILayout.IntField("Joints Mask Images", _noOfJointMasks);

        if (_pieceJointMaskImages.Length != _noOfJointMasks)
            _pieceJointMaskImages = new Texture2D[_noOfJointMasks];

        for ( int i=0; i<_noOfJointMasks; i++ )
            _pieceJointMaskImages[i] = (Texture2D)EditorGUILayout.ObjectField("Joint Mask Image " + (i+1).ToString(), 
                                            _pieceJointMaskImages[i], typeof(Texture2D), false);

        EditorGUILayout.Separator();



        _pmFileName = EditorGUILayout.TextField("Enter PM Filename" , _pmFileName);

        EditorGUILayout.Separator();
        EditorGUILayout.Separator();



        if ( GUILayout.Button("Generate File", GUILayout.Height(45)) )
        {
            bool JointMaskNull = false;

            for (int i = 0; i < _pieceJointMaskImages.Length; i++)
            {
                if (_pieceJointMaskImages[i] == null)
                {
                    JointMaskNull = true;
                    break;
                }
            }


            if (JointMaskNull)
            {
                EditorUtility.DisplayDialog("Error", "You must select all Joint Mask Images", "OK");
            }
            else if (_selectedTexture == null)
            {
                EditorUtility.DisplayDialog("Error", "You must select puzzle image", "OK");
            }
            else
            {
                //string FilePath = EditorUtility.SaveFilePanel("Select file path", "c:\\", "PmFile.pm", "pm");

                if (!System.IO.Directory.Exists(Application.streamingAssetsPath))
                    System.IO.Directory.CreateDirectory(Application.streamingAssetsPath);

                if (_pmFileName == "" || _pmFileName.Length <= 3)
                {
                    EditorUtility.DisplayDialog("Filename Error", "Filename cannot be empty", "Let me change");
                }
                else
                {
                    Debug.Log(_pmFileName.Substring(_pmFileName.Length - 3, 3));

                    string FileName = _pmFileName.Substring(_pmFileName.Length - 3, 3) != ".pm" ?
                                                _pmFileName + ".pm" : _pmFileName;

                    //Check if file already exists
                    if (System.IO.File.Exists(Application.streamingAssetsPath + "/" + FileName))
                    {
                        EditorUtility.DisplayDialog("File creation error", "File with name" + FileName + " already exists", "Let me change");
                    }
                    else
                    {
                        try
                        {
                            PuzzlePieceMaker Temp = new PuzzlePieceMaker(_selectedTexture, _pieceJointMaskImages,
                                                                _piecesInRow, _piecesInCol);

                            Temp.SaveData(Application.streamingAssetsPath + "/" + FileName);

                            Debug.Log(FileName);

                            EditorUtility.DisplayDialog("Success", "File created succesfully", "Ok");
                            AssetDatabase.Refresh();
                        }
                        catch (UnityException ex)
                        {
                            EditorUtility.DisplayDialog("Failed", "File creation failed :" + ex.Message, "Ok");
                        }
                    }
                }

            }


        }
        

        EditorGUILayout.EndVertical();
    }
コード例 #2
0
	IEnumerator Start () {
        
        if (!UseFilePath)
        {
            _PuzzleMaker = new PuzzlePieceMaker(PuzzleImage, JointMaskImage, PiecesInRow, PiecesInCol);

            //Enable below code and provide a file path to save data created by _puzzlemaker class using provided image
            //_PuzzleMaker.SaveData("File Path here e.g c:\\Images\\Temp.pm");
        }
        else
        {

            if (PuzzlePieceMaker.IsPMFileSupportedPlatform())
            {
                try
                {
                    _PuzzleMaker = new PuzzlePieceMaker(PMFilePath);
                    PiecesInCol = _PuzzleMaker.NoOfPiecesInCol;
                    PiecesInRow = _PuzzleMaker.NoOfPiecesInRow;
                    _isFileLoadingComplete = true;
                }
                catch (System.Exception e)
                {
                    Debug.LogError("Please check if you have provided correct file path : " + e.Message);
                    Destroy(gameObject);
                    yield break;
                }

            }
            else if ( Application.platform == RuntimePlatform.WebGLPlayer ||
                        Application.platform == RuntimePlatform.WindowsWebPlayer )
            {
                WebPmFileLoader Temp = GetComponent<WebPmFileLoader>();

                if (Temp != null)
                {
                    yield return StartCoroutine(Temp.LoadFileToStream(PMFilePath));

                    if (Temp.PMFileStream != null)
                    {
                        _PuzzleMaker = new PuzzlePieceMaker(Temp.PMFileStream);
                        PiecesInCol = _PuzzleMaker.NoOfPiecesInCol;
                        PiecesInRow = _PuzzleMaker.NoOfPiecesInRow;
                        _isFileLoadingComplete = true;
                    }
                    else
                    {
                        Debug.LogError("File loading failed");
                        yield break;
                    }
                }
                else
                {
                    Debug.LogError("Prefab not set correctly");
                }    
            }


        }

        yield return new WaitForEndOfFrame();

        //Get main instance of puzzle piece
        _jpPuzzlePieceInst = gameObject.transform.FindChild("JPPiece").gameObject;

        //Seperate from cam for cam resizing to adjust whole puzzle in cam view
        Transform parentCamTransform = gameObject.transform.parent;
        Camera parentCam = parentCamTransform.GetComponent<Camera>();
        gameObject.transform.parent = null;


        //Set background
        if (DisplayCompletedImage)
        {
            GetComponent<Renderer>().enabled = true;
            GetComponent<Renderer>().material.mainTexture = _PuzzleMaker.CreatedBackgroundImage;
        }

        //Resize gameobject to match size for pieces
        transform.localScale = new Vector3((float)PiecesInRow, (PiecesInCol * ((float)PuzzleImage.height / (float)PuzzleImage.width)), 1f);

        
        //Translate to zero
        transform.position = new Vector3(0,0,0);
        transform.rotation = Quaternion.Euler(Vector3.zero);


#region "Pieces Initialization And Placement"

        //Initialize all pieces resize them and place them on screen randomly
        _PuzzlePieces = new GameObject[PiecesInRow * PiecesInCol];

        Random.seed = System.DateTime.Now.Millisecond;

        for (int RowTrav = 0; RowTrav < PiecesInCol; RowTrav++)
        {
            for (int ColTrav = 0; ColTrav < PiecesInRow; ColTrav++)
            {
                GameObject Temp = Object.Instantiate(_jpPuzzlePieceInst) as GameObject;

                //AudioSettings name for this piece
                Temp.name = "Piece" + ((RowTrav * PiecesInRow) + ColTrav).ToString();


                Texture2D Img = _PuzzleMaker._CreatedImagePiecesData[RowTrav, ColTrav].PieceImage;

                float PieceScaleX = (float)Img.width / (float)_PuzzleMaker.PieceWidthWithoutJoint;
                float PieceScaleY = this.PieceHeightInWorld * ((float)Img.height / (float)_PuzzleMaker.PieceHeightWithoutJoint);


                JPPieceController TempPieceControllerInst = Temp.GetComponent<JPPieceController>();
                TempPieceControllerInst.JpPuzzleControllerInstance = this;


                //Get this piece information
                SPieceInfo ThisPieceData = _PuzzleMaker._CreatedImagePiecesData[RowTrav, ColTrav].PieceMetaData.MakeCopy();
                TempPieceControllerInst.ThisPieceData = ThisPieceData;

                //Assign image to piece
                Temp.GetComponent<Renderer>().material.mainTexture = Img;

                //Resize piece in world
                Temp.transform.localScale = new Vector3(PieceScaleX, PieceScaleY, 1);

                
                //Position pieces randomly on screen
                Vector3 CalcPosition = Camera.main.ScreenToWorldPoint(
                    new Vector3(Random.Range(_PuzzleMaker.PieceWidthWithoutJoint, Screen.width - _PuzzleMaker.PieceWidthWithoutJoint),
                                Random.Range(_PuzzleMaker.PieceHeightWithoutJoint, Screen.height - _PuzzleMaker.PieceHeightWithoutJoint),
                                0) );
                CalcPosition.z = transform.position.z - 0.4f;

                Temp.transform.position = CalcPosition;


                //Enable collider for this piece
                Temp.GetComponent<BoxCollider>().enabled = true;
                TempPieceControllerInst.enabled = true;

                //Enable piece
                Temp.SetActive(true);

                _PuzzlePieces[(RowTrav * PiecesInRow) + ColTrav] = Temp;
            }
        }

#endregion

        //If have to display single mesh on puzzle completion set that mesh
        if (ActualImageOnPuzzleComplete)
        {
            GameObject ActualImagePrefab = Resources.Load("TestBackgroundImage", typeof(GameObject)) as GameObject;

            _actualImageGameObject = Instantiate(ActualImagePrefab);
            //_actualImageGameObject = GameObject.CreatePrimitive(PrimitiveType.Quad);
            _actualImageGameObject.transform.position = transform.position;
            _actualImageGameObject.transform.position =
            _actualImageGameObject.transform.localScale = transform.localScale;

            _actualImageGameObject.AddComponent<ActualImageObjController>();

            _actualImageGameObject.name = "ActualPuzzleImage";

            _actualImageGameObject.GetComponent<Renderer>().material.mainTexture = _PuzzleMaker.Image;

            _actualImageGameObject.transform.position = _PuzzlePieces[0].transform.position;

            _actualImageGameObject.AddComponent<BoxCollider>();

            _actualImageGameObject.SetActive(false);
        }

#region "Camera Resizing And Placement"

        //Resize camera to display whole puzzle in camera view
        float widthToBeSeen = PiecesInRow * PieceWidthInWorld;
        float heightToBeSeen = PiecesInCol * PieceHeightInWorld;

        parentCam.orthographicSize = widthToBeSeen > heightToBeSeen ? widthToBeSeen * 0.4f : heightToBeSeen * 0.4f;

        //Position camera in centre of puzzle
        //float CalcCameraX = ;
        //float CalcCameraY = ;

        //parentCamTransform.position = new Vector3(CalcCameraX, CalcCameraY, _pieceInstances[1][0].transform.position.z - 3);
        parentCamTransform.position = new Vector3(0,0,transform.position.z - 10 ) ;

#endregion

        
	}
コード例 #3
0
    /// <summary>
    /// Generates jigsaw puzzle and initialize pieces with data according to user selected options
    /// </summary>
    /// <returns>Coroutine</returns>
    public virtual IEnumerator Start()
    {
        if (!UseFilePath)
        {
            _puzzlePieceMaker = new PuzzlePieceMaker(PuzzleImage, JointMaskImage, PiecesInRow, PiecesInCol);

            //Enable below code and provide a file path to save data created by _puzzlemaker class using provided image
            //_PuzzleMaker.SaveData("File Path here e.g c:\\Images\\Temp.pm");
        }
        else
        {

            if (PuzzlePieceMaker.IsPMFileSupportedPlatform())
            {
                try
                {
                    _puzzlePieceMaker = new PuzzlePieceMaker(PMFilePath);
                    PiecesInCol = _puzzlePieceMaker.NoOfPiecesInCol;
                    PiecesInRow = _puzzlePieceMaker.NoOfPiecesInRow;
                    _isFileLoadingComplete = true;
                }
                catch (System.Exception e)
                {
                    Debug.LogError("Please check if you have provided correct file path : " + e.Message);
                    Destroy(gameObject);
                    yield break;
                }

            }
            else if (Application.platform == RuntimePlatform.WebGLPlayer ||
                        Application.platform == RuntimePlatform.WindowsWebPlayer)
            {
                WebPmFileLoader Temp = GetComponent<WebPmFileLoader>();

                if (Temp != null)
                {
                    yield return StartCoroutine(Temp.LoadFileToStream(PMFilePath));

                    if (Temp.PMFileStream != null)
                    {
                        _puzzlePieceMaker = new PuzzlePieceMaker(Temp.PMFileStream);
                        PiecesInCol = _puzzlePieceMaker.NoOfPiecesInCol;
                        PiecesInRow = _puzzlePieceMaker.NoOfPiecesInRow;
                        _isFileLoadingComplete = true;
                    }
                    else
                    {
                        Debug.LogError("File loading failed");
                        yield break;
                    }
                }
                else
                {
                    Debug.LogError("Prefab not set correctly");
                }
            }


        }

        
        yield return new WaitForEndOfFrame();

        
        //Get main instance of puzzle piece
        _puzzlePieceInst = gameObject.transform.FindChild("Piece").gameObject;

        //Set puzzle image to Puzzle piece instance
        _puzzlePieceInst.GetComponent<Renderer>().material.mainTexture = _puzzlePieceMaker.PuzzleImage;

        //Seperate from cam for cam resizing to adjust whole puzzle in cam view
        parentCamTransform = gameObject.transform.parent;
        parentCam = parentCamTransform.GetComponent<Camera>();
        gameObject.transform.parent = null;


        //Set background
        if (DisplayCompletedImage)
        {
            GetComponent<Renderer>().enabled = true;
            GetComponent<Renderer>().material.mainTexture = _puzzlePieceMaker.CreatedBackgroundImage;
        }

        //Resize gameobject to match size for pieces
        transform.localScale = new Vector3((float)PiecesInRow, (PiecesInCol * ((float)PuzzleImage.height / (float)PuzzleImage.width)), 1f);


        //Translate to zero
        transform.position = Vector3.zero;
        transform.rotation = Quaternion.Euler(Vector3.zero);

        
        //Initialize all pieces and joints resize them and place them on screen randomly
        _puzzlePieces = new GameObject[PiecesInRow * PiecesInCol];

        
        //Scale piece according to puzzle
        float PieceScaleX = 1;
        float PieceScaleY = 1 * ((float)_puzzlePieceMaker.PuzzleImageHeight / (float)_puzzlePieceMaker.PuzzleImageWidth);
        _puzzlePieceInst.transform.localScale = new Vector3(PieceScaleX, PieceScaleY, 1);


        //Create joints instances for each side from _puzzle piece
        GameObject _leftJointInst = Object.Instantiate(_puzzlePieceInst) as GameObject;
        Component[] AllCompoenents = _leftJointInst.GetComponents<Component>();
        foreach (Component item in AllCompoenents)
            if (!(item is Renderer || item is Transform || item is MeshFilter))
                Destroy(item);

        yield return new WaitForEndOfFrame();

        GameObject _rightJointInst = Object.Instantiate(_leftJointInst) as GameObject;
        GameObject _topJointInst = Object.Instantiate(_leftJointInst) as GameObject;
        GameObject _bottomJointInst = Object.Instantiate(_leftJointInst) as GameObject;


        //Initialize joints instances
        _leftJointInst.GetComponent<Renderer>().material.mainTexture = _puzzlePieceMaker.LeftJointsMaskImage;
        _rightJointInst.GetComponent<Renderer>().material.mainTexture = _puzzlePieceMaker.RightJointsMaskImage;
        _topJointInst.GetComponent<Renderer>().material.mainTexture = _puzzlePieceMaker.TopJointsMaskImage;
        _bottomJointInst.GetComponent<Renderer>().material.mainTexture = _puzzlePieceMaker.BotJointsMaskImage;

        //Name joints
        _leftJointInst.name = "LeftJoint";
        _rightJointInst.name = "RightJoint";
        _topJointInst.name = "TopJoint";
        _bottomJointInst.name = "BottomJoint";

        //Position joints
        float JointWidth = _leftJointInst.transform.localScale.x;
        float JointHeight = _leftJointInst.transform.localScale.y;
        

        //Make joints child of piece
        _leftJointInst.transform.parent = _puzzlePieceInst.transform;
        _leftJointInst.transform.localScale = Vector3.one;
        _leftJointInst.SetActive(true);

        _rightJointInst.transform.parent = _puzzlePieceInst.transform;
        _rightJointInst.transform.localScale = Vector3.one;
        _rightJointInst.SetActive(true);

        _topJointInst.transform.parent = _puzzlePieceInst.transform;
        _topJointInst.transform.localScale = Vector3.one;
        _topJointInst.SetActive(true);

        _bottomJointInst.transform.parent = _puzzlePieceInst.transform;
        _bottomJointInst.transform.localScale = Vector3.one;
        _bottomJointInst.SetActive(true);


        //Position joints
        _leftJointInst.transform.localPosition = new Vector3(-1, 0, 0);
        _rightJointInst.transform.localPosition = new Vector3(1, 0, 0);
        _topJointInst.transform.localPosition = new Vector3(0, 1, 0);
        _bottomJointInst.transform.localPosition = new Vector3(0, -1, 0);
        

        //Initialize pieces
        for (int RowTrav = 0; RowTrav < PiecesInCol; RowTrav++)
        {
            for (int ColTrav = 0; ColTrav < PiecesInRow; ColTrav++)
            {
                GameObject Temp = Object.Instantiate(_puzzlePieceInst) as GameObject;
                
                
                //Name for this piece
                Temp.name = "Piece" + ((RowTrav * PiecesInRow) + ColTrav).ToString();
                
                SetPuzzlePieceUV(Temp, ColTrav, RowTrav, PiecesInCol, PiecesInRow);

                //Enable piece
                Temp.SetActive(true);

                SPieceInfo ThisPieceData = _puzzlePieceMaker._CreatedPiecesData[RowTrav,ColTrav];
                bool TempOut = false;

                bool HaveTopJoint = ThisPieceData.HaveJoint(EJointPosition.Top);
                if (HaveTopJoint) 
                    HaveTopJoint = ThisPieceData.GetJoint(EJointPosition.Top, out TempOut).JointType != EJointType.Female;

                bool HaveBotJoint = ThisPieceData.HaveJoint(EJointPosition.Bottom);
                if (HaveBotJoint)
                    HaveBotJoint = ThisPieceData.GetJoint(EJointPosition.Bottom, out TempOut).JointType != EJointType.Female;

                bool HaveLeftJoint = ThisPieceData.HaveJoint(EJointPosition.Left);
                if (HaveLeftJoint)
                    HaveLeftJoint = ThisPieceData.GetJoint(EJointPosition.Left, out TempOut).JointType != EJointType.Female;

                bool HaveRightJoint = ThisPieceData.HaveJoint(EJointPosition.Right);
                if (HaveRightJoint)
                    HaveRightJoint = ThisPieceData.GetJoint(EJointPosition.Right, out TempOut).JointType != EJointType.Female;



                //Set joints uvs
                Transform LeftJoint = Temp.transform.FindChild("LeftJoint");
                if (HaveLeftJoint && ColTrav > 0)
                        SetPuzzlePieceUV(LeftJoint.gameObject, ColTrav - 1, RowTrav, PiecesInCol, PiecesInRow);
                else
                    LeftJoint.gameObject.SetActive(false);


                Transform RightJoint = Temp.transform.FindChild("RightJoint");
                if (HaveRightJoint && ColTrav < PiecesInCol - 1)
                    SetPuzzlePieceUV(RightJoint.gameObject, ColTrav + 1, RowTrav, PiecesInCol, PiecesInRow);
                else
                    RightJoint.gameObject.SetActive(false);


                Transform TopJoint = Temp.transform.FindChild("TopJoint");
                if ( HaveTopJoint && RowTrav < PiecesInRow - 1)
                    SetPuzzlePieceUV(TopJoint.gameObject, ColTrav, RowTrav + 1, PiecesInCol, PiecesInRow);
                else
                    TopJoint.gameObject.SetActive(false);


                Transform BotJoint = Temp.transform.FindChild("BottomJoint");
                if ( HaveBotJoint && RowTrav >0)
                    SetPuzzlePieceUV(BotJoint.gameObject, ColTrav, RowTrav - 1, PiecesInCol, PiecesInRow);
                else
                    BotJoint.gameObject.SetActive(false);


                _puzzlePieces[(RowTrav * PiecesInRow) + ColTrav] = Temp;
            }
        }

    }
コード例 #4
0
	public IEnumerator Start () {

		if (!UseFilePath)
		{
			_PuzzleMaker = new PuzzlePieceMaker(PuzzleImage, JointMaskImage, PiecesInRow, PiecesInCol);

			//Enable below code and provide a file path to save data created by _puzzlemaker class using provided image
			//_PuzzleMaker.SaveData("File Path here e.g c:\\Images\\Temp.pm");
		}
		else
		{
			if (PuzzlePieceMaker.IsPMFileSupportedPlatform())
			{
				try
				{
					_PuzzleMaker = new PuzzlePieceMaker(PMFilePath);
					PiecesInRow = _PuzzleMaker.NoOfPiecesInRow;
					PiecesInCol = _PuzzleMaker.NoOfPiecesInCol;
					_isFileLoadingComplete = true;
				}
				catch (System.Exception e)
				{
					Debug.LogError("Please check if you have provided correct file path :" + e.Message);
					Destroy(gameObject);
					yield break;
				}
			}
			else if (Application.platform == RuntimePlatform.WebGLPlayer ||
				Application.platform == RuntimePlatform.WindowsWebPlayer)
			{
				WebPmFileLoader Temp = GetComponent<WebPmFileLoader>();

				if (Temp != null)
				{
					yield return StartCoroutine(Temp.LoadFileToStream(PMFilePath));

					if (Temp.PMFileStream != null)
					{

						_PuzzleMaker = new PuzzlePieceMaker(Temp.PMFileStream);
						PiecesInCol = _PuzzleMaker.NoOfPiecesInCol;
						PiecesInRow = _PuzzleMaker.NoOfPiecesInRow;
						_isFileLoadingComplete = true;
					}
					else
					{
						Debug.LogError("File loading failed");
						yield break;
					}
				}
				else
				{
					Debug.LogError("Prefab not set correctly");
				}
			}
		}

		yield return new WaitForEndOfFrame();

		//Get main instance of puzzle piece
		PuzzlePiecePrefab = gameObject.transform.FindChild("PPPiece").gameObject;

		//Seperate from cam for cam resizing to adjust whole puzzle in cam view
	//	Transform parentCamTransform = gameObject.transform.parent;
	//	Camera parentCam = parentCamTransform.GetComponent<Camera>();
		gameObject.transform.parent = null;

		//Store current transform and translate to origin for everythings placement
		Vector3 OrigionalPosition = transform.position;
		Vector3 OrigionalRotation = transform.localRotation.eulerAngles;


		//Set background
		GetComponent<Renderer>().material.mainTexture = _PuzzleMaker.CreatedBackgroundImage;

		//Resize gameobject to match size for pieces
		transform.localScale = new Vector3((float)PiecesInRow, (PiecesInCol * ( (float)PuzzleImage.height / (float)PuzzleImage.width ) ), 1f);

		//Translate to zero
		transform.position = Vector3.zero;
		transform.rotation = Quaternion.Euler( Vector3.zero );


		//Initialize and set Colliders to detect piece in place

		//Get child colider object
		GameObject _ChildCollider = gameObject.transform.FindChild("Collider").gameObject;

		//Instantiate required number of childcollider objects
		_ChildColliders = new GameObject[PiecesInCol * PiecesInRow];

		//Hold created puzzle pieces instances
		_PuzzlePieces = new GameObject[PiecesInCol * PiecesInRow];

		//Holds initial positions for puzzle pieces
		_PuzzlePiecesOrigPos = new Vector3[_PuzzlePieces.Length];


		float PieceWidthInBackground = 1;
		float PieceHeightInBackground = ((float)PuzzleImage.height / (float)PuzzleImage.width);


		for (int CCArray = 0; CCArray < PiecesInCol * PiecesInRow; CCArray++)
		{
			_ChildColliders[CCArray] = Object.Instantiate(_ChildCollider) as GameObject;

			//Assign this class instance
			_ChildColliders[CCArray].GetComponent<PPPiecePositionDetection>().PPPuzzleControlerInstance = this;

			BoxCollider CollisionDetector = _ChildColliders[CCArray].GetComponent<BoxCollider>();

			//Set colliders size
			CollisionDetector.size = new Vector3(0.2f, ((float)PuzzleImage.height / (float)PuzzleImage.width) * 0.2f, 1f);

			_ChildColliders[CCArray].name = "BackgroundCollider" + CCArray.ToString();


			float CalculatedX = transform.position.x - (transform.localScale.x / 2) + 
				PieceWidthInBackground * Mathf.Repeat(CCArray, PiecesInRow) + (PieceWidthInBackground/2);
			float CalculatedY = transform.position.y - (transform.localScale.y/2) + 
				(PieceHeightInBackground * (CCArray/PiecesInRow)) + (PieceHeightInBackground/2);


			_ChildColliders[CCArray].transform.position = new Vector3( CalculatedX, CalculatedY, transform.position.z - 0.1f );
			_ChildColliders[CCArray].transform.parent = transform;

		}

		Destroy(_ChildCollider);



		#region "Pieces Initialization And Placement"

		float PieceZ = transform.position.z - (PiecesInRow * PiecesInCol) * 0.01f;
		float PieceX = transform.position.x - (transform.localScale.x/2) - PieceWidthInBackground;
		float PieceY = transform.position.y - (transform.localScale.y / 2) + PieceHeightInBackground;

		for (int RowTrav = 0; RowTrav < PiecesInCol; RowTrav++)
		{
			for (int ColTrav = 0; ColTrav < PiecesInRow; ColTrav++, PieceZ -= 0.1f)
			{
				Texture2D Img = _PuzzleMaker._CreatedImagePiecesData[RowTrav, ColTrav].PieceImage;

				float PieceScaleX = (float)Img.width / (float)_PuzzleMaker.PieceWidthWithoutJoint;
				float PieceScaleY = PieceHeightInBackground * ((float)Img.height / (float)_PuzzleMaker.PieceHeightWithoutJoint );


				//Initialize all pieces with images and resize appropriately
				GameObject Temp = Instantiate(PuzzlePiecePrefab) as GameObject;
				Temp.GetComponent<Renderer>().material.mainTexture = Img;

				Temp.transform.localScale = new Vector3(PieceScaleX, PieceScaleY, 1);

				//Place pieces
				Temp.transform.position = new Vector3(PieceX, PieceY, PieceZ);

				//Assign name
				Temp.name = "Piece" + ((RowTrav * PiecesInRow) + ColTrav).ToString();

				//Enable piece
				Temp.SetActive(true);

				_PuzzlePieces[(RowTrav * PiecesInRow) + ColTrav] = Temp;

				//Piece display mode setting
				if (PiecesDisplayMode == EPieceDisplayMode.ShowOnePieceAtATime)
				{
					if ((RowTrav * PiecesInRow) + ColTrav > 0)
						Temp.SetActive(false);
				}

			}
		}


		#endregion



		#region "Piece Shuffling"

		if (ShufflePieces)
		{
			//Shuffle pieces position using Fisher-Yates shuffle algorithm
			Vector3[] TempPosHolder = new Vector3[_PuzzlePieces.Length];

			for (int i = 0; i < _PuzzlePieces.Length; i++)
				TempPosHolder[i] = _PuzzlePieces[i].transform.position;

			Random.seed = System.DateTime.Now.Second;

			for (int i = _PuzzlePieces.Length - 1; i > 0; i--)
			{
				int RndPos = Random.Range(0, i - 1);

				Vector3 Swapvar = TempPosHolder[i];
				TempPosHolder[i] = TempPosHolder[RndPos];
				TempPosHolder[RndPos] = Swapvar;

				//Apply changed location to piece
				_PuzzlePieces[i].transform.position = TempPosHolder[i];

			}

		}

		#endregion

		#region "Make arrangements for ShowAllSelectTop mode"

		//Make arrangement for ShowAllSelectTop mode
		if (PiecesDisplayMode == EPieceDisplayMode.ShowAllSelectTop)
		{
			//Sort pieces in _PuzzlePieces according to their position
			GameObject GSwapvar = null;

			for (int i = 0; i < _PuzzlePieces.Length; i++)
			{
				for (int j = 0; j < _PuzzlePieces.Length - 1; j++)
				{
					if (_PuzzlePieces[j].transform.position.z < _PuzzlePieces[j + 1].transform.position.z)
					{
						GSwapvar = _PuzzlePieces[j + 1];
						_PuzzlePieces[j + 1] = _PuzzlePieces[j];
						_PuzzlePieces[j] = GSwapvar;
					}
				}
			}

			//Enable only top most piece for selection
			for (int i = 0; i < _PuzzlePieces.Length - 1; i++)
				_PuzzlePieces[i].GetComponent<CharacterController>().enabled = false;
		}

		#endregion


		//Make all puzzle pieces child of gameobjects
		for (int i = 0; i < _PuzzlePieces.Length; i++)
		{
			_PuzzlePieces[i].transform.parent = transform;

			//Hold positions for pieces
			_PuzzlePiecesOrigPos[i] = _PuzzlePieces[i].transform.localPosition;

		}


		//Translate everything back to its origional position
		transform.position = OrigionalPosition;
		transform.rotation = Quaternion.Euler( OrigionalRotation );

		//If have to display single mesh on puzzle completion set that mesh
		if (ActualImageOnPuzzleComplete)
		{
			GameObject ActualImagePrefab = Resources.Load("TestBackgroundImage", typeof(GameObject)) as GameObject;

			_actualImageGameObject = Instantiate(ActualImagePrefab);

			//_actualImageGameObject = GameObject.CreatePrimitive(PrimitiveType.Quad);

			_actualImageGameObject.transform.position = new Vector3( transform.position.x,
				transform.position.y, transform.position.z-1);
			_actualImageGameObject.transform.localScale = transform.localScale;

			_actualImageGameObject.name = "ActualPuzzleImage";

			_actualImageGameObject.GetComponent<Renderer>().material.mainTexture = _PuzzleMaker.Image;


			_actualImageGameObject.AddComponent<BoxCollider>();

			_actualImageGameObject.SetActive(false);
		}

		gameObject.GetComponent<Renderer>().enabled = true;


		#region "Camera  Resizing And Placement"

		//Resize camera to display whole puzzle in camera view
		//        float widthToBeSeen = gameObject.GetComponent<Renderer>().bounds.size.x + PieceWidthInBackground * 1.35f;
		//        float heightToBeSeen = gameObject.GetComponent<Renderer>().bounds.size.y;
		//
		//        parentCam.orthographicSize = widthToBeSeen > heightToBeSeen ? widthToBeSeen * 0.4f : heightToBeSeen * 0.4f;
		//
		//
		//        //parentCamTransform.position = new Vector3(CalcCameraX, CalcCameraY, _pieceInstances[1][0].transform.position.z - 3);
		//        parentCamTransform.position = new Vector3(0.28f, 0, transform.position.z - 10);


		#endregion

	}