unity3d 九宫格拼图_unity九宫格拼图 - CSDN
  • UNITY3D九宫拼图心得

    2015-12-08 21:14:39
    自学Unity3d其实已经有1年多了,一直在练习,没有一个完整的游戏,最近花了4天来完成一个小游戏,九宫拼图,游戏很简单,代码其实1天半就写完了,主要是美工,不想搞的太粗糙,从网上下了的素材PS了一下。...

     自学Unity3d其实已经有1年多了,一直在练习,没有一个完整的游戏,最近花了4天来完成一个小游戏,九宫拼图,游戏很简单,代码其实1天半就写完了,主要是美工,不想搞的太粗糙,从网上下了的素材PS了一下。

      总结一下,格子是3*3的,但是要考虑要二维数组循环的方便不越界,用5*5的,两边去掉墙壁来判断。空格子的ID是-1,小拼图弄个从1---8的ID,墙壁是0  。UI用的UGUI,屏幕适应比NGUI感觉要方便点。格子的移动要用GetComponent<RectTransform>().anchoredPosition3D 来移动。其他都很好做。


    展开全文
  • Unity 图片切割九宫格

    2020-04-21 11:59:05
    将图片一张图切割成多个小图,不仅仅是九宫格 效果如图所示 我这里直接把切割后的图片付给了Button 被切割的图片属性要做一下设置 脚本如下: using System.Collections; using System.Collections....

     将图片一张图切割成多个小图,不仅仅是九宫格

    效果如图所示

    我这里直接把切割后的图片付给了Button

    被切割的图片属性要做一下设置

     

    脚本如下: 

     

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.UI;
    
    public class SixImage : MonoBehaviour
    {
    
        //小图的宽和高
        public int m_iMinWidth;
        public int m_iMinHeight;
        //一行有多少个小图
        public int m_iMinPicRowCount = 3;
        //一列有多少个小图
        public int m_iMinPicColumnCount = 3;
        //需要切割的大图
        public Texture2D m_texPlayer;
        //小图数组
        private Texture2D[,] m_texPlayers;
    
        //切割后的图片
        public Transform transforms;
    
        void Start()
        {
            m_iMinPicRowCount = 3;
            m_iMinPicColumnCount = 3;
            m_texPlayers = new Texture2D[m_iMinPicRowCount, m_iMinPicColumnCount];
    
        }
    
        // Update is called once per frame
        void Update()
        {
    
        }
    
        /// <summary>
        /// 切图
        /// </summary>
        /// <param name="i"></param>
        /// <param name="j"></param>
        //切图
        public void DePackTexture(int i, int j)
        {
            //通过大图宽高计算出每次切图的大小
            m_iMinHeight = m_texPlayer.height / m_iMinPicColumnCount;
            m_iMinWidth = m_texPlayer.width / m_iMinPicRowCount;
    
            int cur_x = i * m_iMinWidth;
            int cur_y = j * m_iMinHeight;
            Texture2D newTexture = new Texture2D(m_iMinWidth, m_iMinHeight);
            for (int m = cur_y; m < cur_y + m_iMinHeight; m++)
            {
                for (int n = cur_x; n < cur_x + m_iMinWidth; n++)
                {
                    //核心 通过从大图拿到的像素点赋值给小图
                    newTexture.SetPixel(n - cur_x, m - cur_y, m_texPlayer.GetPixel(n, m));
                }
            }
            //Apply一下 更新贴图
            newTexture.Apply();
            //储存到数组
            m_texPlayers[i, j] = newTexture;
    
        }
    
        public void button() 
        {
            //切割图片
            for (int i = 0; i < m_iMinPicRowCount; i++)
            {
                for (int j = 0; j < m_iMinPicColumnCount; j++)
                {
                    DePackTexture(i, j);
                }
            }
    
    
            
            for (int i = 2; i >= 0; i--)
            {
                for (int j= 0; j < 3; j++)
                {
                    
                    Sprite sprite = Sprite.Create(m_texPlayers[j, i], new Rect(0, 0, m_texPlayers[i, j].width, m_texPlayers[i, j].height), Vector2.zero);
                    GameObject go = Resources.Load<GameObject>("Image");
                    GameObject g = Instantiate(go);
                    g.GetComponent<Image>().sprite = sprite;
                    g.transform.SetParent(transforms);
    
                }
            }
    
    
        }
       
    }
    

    @Liam:有用→收藏→关注   听说长得好看的人都这么做!

    展开全文
  • 本文为原创,如需转载请... 最近一直在使用Unity,对它有了一些小的使用心得 今天写一个简单的拼图游戏实例来和大家分享一下Unity中material.mainTextureOffset和material.mainTextureScale的作用和用法 m

    本文为原创,如需转载请注明原址:http://blog.csdn.net/cube454517408/article/details/7907247


    最近一直在使用Unity,对它有了一些小的使用心得

    今天写一个简单的拼图游戏实例来和大家分享一下Unity中material.mainTextureOffsetmaterial.mainTextureScale的作用和用法


    mainTextureOffsetmainTextureScale是Material类中的两个方法

    mainTextureOffset指的是主纹理偏移

    mainTextureScale指的是主纹理缩放

    默认一个material的mainTextureOffset是0,0,mainTextureScale是1,1

    表示原图正常显示,没有缩放,如下图

    当我们改变mainTextureScale的值时纹理只会显示一部分,其范围是[0,1];

    如我们将mainTextureScale.x设置为0.5时,可以看到纹理只显示u方向的50%


    同理,我们将mainTextureScale.y设置为0.5时,可以看到纹理只显示v方向的50%


    mainTextureOffset属性表示纹理的起始偏移为0时没有偏移,mainTextureOffset.x指u方向的偏移量,mainTextureOffset.y指v方向的偏移量。其范围也是[0,1]。这里要注意:偏移的起点在图像的左下角

    我们设置mainTextureOffset.x为0.2,如下图:

    可以看到纹理向左偏移了20%


    我们设置mainTextureOffset.y为0.2,如下图:

    可以看到纹理向下偏移了20%


    应用这两个属性,我们可以只截取图片的一部分来显示,如:

    mainTextureOffset = new Vector2(0.5, 0.5)

    mainTextureScale= new Vector2(0.5, 0.5)

    将只显示原图的右上角1/4区域,如下图:


    有了对以上两个属性的了解,我们可以来制作一个简单的拼图游戏

    思路:

           1.将一张图片切分为raw*volumn的raw*volumn张碎片

           2.每一张碎片只显示图片的一部分

           3.将它们按一个顺序和位置排列,使其看起来像一张完整的图片

    玩法:

            点击Start按钮后,开始游戏。选中碎片并将其拖放在正确的位置上,如放置正确则不可再被拖动。直到所有碎片放置正确。

            点击Next Texture按钮可切换背景和碎片显示的图片


    制作流程:

    新建一个游戏场景Test,设置摄像机属性如下(采用正交摄像机(2D)将其标签设置MainCamera):

    创建两个plane,其中一个改名为Background并为其选择一个材质;另一个plane也选择一个材质要和前一个不同,选择shader为Unlit/Transparent (自发光),将其设为不可见。创建一个空对象,起名为Body,如下图:

    创建一个c#脚本main.cs,绑定在Body对象下Inspector设置如下:

    main.cs脚本如下:

    using UnityEngine;
    using System.Collections;

    public class main : MonoBehaviour {

        public GameObject _plane;        //用来实例碎片的对象
        public GameObject _planeParent; //碎片对象所要绑定的父节点
        public GameObject _background;    //显示暗色的背景图
        public Texture2D[] _texAll;        //用来更换的纹理
        public Vector3[] _RandomPos;    //开始时, 碎片随机分布的位置
        public int raw = 3;                //图形切分的行数
        public int volumn = 3;            //图形切分的列数
        public float factor = 0.25f;    //一个范围比例因子, 用来判断碎片是否在正确位置范围内
        
        GameObject[] _tempPlaneAll;        
        
        float sideLength = 0;            //背景图的边长(正方形)
        
        int finishCount = 0;            //完成的碎片数量
        int _index = 0;
        
        Vector2 originPoint;            //第一个碎片的位置
        Vector2 space;                    //碎片与碎片之间的间隔(中心距x,y)
        
        void Start()
        {
            sideLength = _background.transform.localScale.x;
            space.x = sideLength / volumn;
            space.y = sideLength / raw;
            originPoint.x = -((volumn - 1) * space.x) / 2;
            originPoint.y = ((raw - 1) * space.y) / 2;
            Vector2 range;
            range.x = space.x * factor * 10f;
            range.y = space.y * factor * 10f;
            
            _tempPlaneAll = new GameObject[raw * volumn];
            int k = 0;
            //完成所有碎片的有序排列位置和uv纹理的截取
            for(int i = 0 ; i != raw ; ++i)
            {
                for(int j = 0 ; j != volumn ; ++j)
                {
                    GameObject tempObj = (GameObject)Instantiate(_plane);
                    tempObj.name = "Item" + k;
                    tempObj.transform.parent = _planeParent.transform;
                    tempObj.transform.localPosition = new Vector3((originPoint.x + space.x * j) * 10f, (originPoint.y - space.y * i) * 10f, 0);
                    tempObj.transform.localScale = new Vector3(space.x, 1f, space.y);
                    Vector2 tempPos = new Vector2(originPoint.x + space.x * j, originPoint.y - space.y * i);
                    
                    float offset_x = (tempPos.x <= 0 + Mathf.Epsilon) ? (0.5f - Mathf.Abs((tempPos.x - space.x / 2) / sideLength)) : (0.5f + (tempPos.x - space.x / 2) / sideLength);
                    float offset_y = (tempPos.y <= 0 + Mathf.Epsilon) ? (0.5f - Mathf.Abs((tempPos.y - space.y / 2) / sideLength)) : (0.5f + (tempPos.y - space.y / 2) / sideLength);
                    
                    float scale_x = Mathf.Abs(space.x / sideLength);
                    float scale_y = Mathf.Abs(space.y / sideLength);
                    
                    tempObj.renderer.material.mainTextureOffset = new Vector2(offset_x, offset_y);
                    tempObj.renderer.material.mainTextureScale = new Vector2(scale_x, scale_y);
                    tempObj.SendMessage("SetRange", range);
                    
                    _tempPlaneAll[k] = tempObj;
                    ++k;
                }
            }
        }
        
        void OnGUI()
        {
            //开始游戏
            if(GUI.Button(new Rect(10, 10, 100, 30), "Play"))
                StartGame();
            //更换纹理
            if(GUI.Button(new Rect(10, 80, 100, 30), "Next Textrue"))
                ChangeTex();
        }
        
        void StartGame()
        {
            //将所有碎片随机分布在左右两边
            for(int i = 0 ; i != _tempPlaneAll.Length ; ++i)
            {
                int tempRank = Random.Range(0, _RandomPos.Length);
                _tempPlaneAll[i].transform.localPosition = new Vector3(_RandomPos[tempRank].x, _RandomPos[tempRank].y, 0f);
            }
            //通知所有子对象, 开始游戏
            gameObject.BroadcastMessage("Play");
        }
        
        void SetIsMoveFale()
        {
            gameObject.BroadcastMessage("IsMoveFalse");
        }
        
        void IsFinish()
        {
            //计算放置正确的碎片数量
            ++finishCount;
            if(finishCount == raw * volumn)
                Debug.Log("Finish!");
        }
        
        void ChangeTex()
        {
            _background.renderer.material.mainTexture = _texAll[_index];
            gameObject.BroadcastMessage("SetTexture", _texAll[_index++]);
            if(_index > _texAll.Length - 1)
                _index = 0;
        }
        
    }


    再创建一个c#脚本为plane.cs,绑定在Plane对象下。Inspector设置如下:

    注意:要为Plane对象添加一个Collider组件,因为Plane对象的scale与Unity的基本单位(米)的比例为10:1,因此这里Collider的Size要设置为10

    plane.cs脚本如下:

    using UnityEngine;
    using System.Collections;

    public class plane : MonoBehaviour {
        
        Transform mTransform;
        
        Vector3 offsetPos;                    //鼠标点与所选位置的偏移
        Vector3 finishPos = Vector3.zero;    //当前碎片的正确位置
        
        Vector2 range;                        //碎片正确位置的范围, 由SetRange函数设置
        
        float z = 0;
        
        bool isPlay = false;                //是否进行游戏?
        bool isMove = false;                //当前碎片是否跟随鼠标移动
        
        void Start()
        {
            mTransform = transform;
            finishPos = mTransform.localPosition;
        }
        
        void Update()
        {
            if(!isPlay)
                return ;
            
            //当鼠标进入碎片中按下时, 记录与碎片中心位置的偏差; 并使碎片跟随鼠标移动(多张碎片叠在一起时,只选其中一张跟随)
            Vector3 tempMousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            if(Input.GetMouseButtonDown(0) && tempMousePos.x > collider.bounds.min.x && tempMousePos.x < collider.bounds.max.x
                && tempMousePos.y > collider.bounds.min.y && tempMousePos.y < collider.bounds.max.y)
            {
                mTransform.parent.SendMessage("SetIsMoveFale");
                offsetPos = mTransform.position - tempMousePos;
                z = mTransform.position.z;
                isMove = true;
            }
            
            //跟随鼠标移动
            if(isMove && Input.GetMouseButton(0))
            {
                tempMousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                mTransform.position = new Vector3(tempMousePos.x + offsetPos.x, tempMousePos.y + offsetPos.y, z - 0.1f);
            }
            
            //鼠标放开后停止跟随
            if(Input.GetMouseButtonUp(0))
            {
                mTransform.position = new Vector3(mTransform.position.x, mTransform.position.y, z);
                isMove = false;
            }
            
            //判断是否到达正确位置(如进入正确位置范围, 碎片自动设置在正确位置, 并不可被再移动)
            IsFinish();
        }
        
        void IsFinish()
        {
            if(mTransform.localPosition.x > finishPos.x - range.x && mTransform.localPosition.x < finishPos.x + range.x
                && mTransform.localPosition.y > finishPos.y - range.y && mTransform.localPosition.y < finishPos.y + range.y)
            {
                isPlay = false;
                mTransform.localPosition = finishPos;
                mTransform.parent.SendMessage("IsFinish");
            }
        }
        
        //开始游戏
        void Play()
        {
            isPlay = true;
        }
        
        void IsMoveFalse()
        {
            isMove = false;
        }
        
        void SetRange(Vector2 _range)
        {
            range = _range;
        }
        
        //更换纹理
        void SetTexture(Texture2D _tex)
        {
            mTransform.renderer.material.mainTexture = _tex;
        }
    }


    现在可以开始游戏了,如下图:





    程序源码及打包文件在此下载:http://download.csdn.net/detail/cube454517408/4525682

    使用方法:打开一个空Unity场景,点击Assets->Import Package->Custom Package导入即可。注意:不要有中文路径




    展开全文
  • Unity拼图小游戏

    2019-06-20 14:54:13
    目前做了一款拼图小游戏,不规则的图形,自由拖拽,网上其他拼图大部分都是基于九宫格的类似华容道拼图模式,我做的时候没有找到我这种类型的相关的项目代码(有一付费下载,然后发现是用3d实现碰撞,然后正交相机来...

    Unity拼图小游戏的实现

    目前做了一款拼图小游戏,不规则的图形,自由拖拽,网上其他拼图大部分都是基于九宫格的类似华容道拼图模式,我做的时候没有找到我这种类型的相关的项目代码(有一付费下载,然后发现是用3d实现碰撞,然后正交相机来模拟2d),所以现在来记录一下自己的完成思路。
    下附一张效果截图。
    完成以后的效果

    一、主要难点

    1.不规则图形的显示和碰撞

    2.拼图自动生成

    3.拼图拼合移动

    二、难点思路

    1.显示和碰撞

    我之前是一直卡在不规则图形的显示和碰撞上,找了很多资料,基本要切成上图的样子只有用算法。(这里是一个基于算法实现凹凸拼图切割的博客) 很强大,很正统,正确思路应该就是这么做,但是我不会,所以没有用,以后再啃吧。我的实现思路就很简单,用unity自带的mask遮罩,附一张我的思路图。凹凸拼图分解效果图
    这里我把完整拼图切成216(18×12)小块,然后分成,3×4,4×3,3×5,5×3的不等小块,再用四种mask,旋转再各自匹配以后,基本就得到了这类拼图游戏的所有拼图模板,如下。
    2019.6.20更新
    这里我把完整拼图切成216(18×12)小块,然后分成,3×4,4×3,3×5,5×3的4种小块,然后配合14种mask,来得到我这个模式下所有的14种拼图基类,所有mask样式如下。之所以要有这么多mask,是为了后面射线检测的的时候能用统一的代码来控制(旋转后个体的坐标轴会变,目前我无法解决,故用这个笨方法)。
    在这里插入图片描述

    然后为了更加规格化,我加入了插入点和重心点的概念,加入以后分解图如下
    在这里插入图片描述
    白色点是每块拼图的插入点,因为每块拼图是由一个图片组构成的,每次生成需要加载一组sprite依次放入模板的image里。比如左上角第一块3×4,插入点为1的拼图,他要加载的sprite组是:
    1,2,3,
    19,20,21,
    37,38,39,
    55,56,57
    这一组sprite,当把加载方法封装好以后,调用只需要传入插入点位置的sprite编号,就可以创建一块完成拼图出来了
    ~
    2019.6.20更新
    第二个版本我换了切图的方法,切完以后子图片的顺序变成了,从下往上,从左往右,
    3 6 9
    2 5 8
    1 4 7
    就是上面的结构,于是对插入点做了调整,简单来说就是从左上调整到了左下,比如左下角第一块4×3,插入点为1的拼图,他要加载的sprite组就变成了:
    3 15 27 39
    2 14 26 38
    1 13 25 37

    黑色点是每块拼图的重心点用来挂上碰撞检测的脚本,这样每块拼图之间的距离检测就一样了,也是为了更加的。。简单?随他去吧,我是懒得一个个设置碰撞距离,想到了这个偷懒的方法 = =。
    然后我设定,只有鼠标选择的拼图块才激活碰撞检测脚本,避免bug,碰撞以后把碰撞的两个拼图放到一个父级下面实现拼好一起移动的功能。
    最后加入插入点以后,拼图模板有六个,分别是,(拼图大小,插入点)(3×4,1),(3×4,2),(4×3,4),(4×3,1),(5×3,4),(3×5,2)。
    2019.6.20更新
    重心点概念还是这样,只是调整了代码结构以后,射线检测脚本也挂到了mask物体上,不再额外挂到子图片上。

    2.拼图的生成

    显示和碰撞搞定了,剩下就是如何自动生成每块拼图了,首先,准备一张图,然后切成216块(18×12),这里用unity自带的处理方法就好,sprite mode 设置成multiple以后打开sprite Editor,设置如下
    单个拼图的加载基本就是这样,调用图片模板,加载并根据插入点传入sprite组,给重心点的图片加载碰撞检测脚本,然后加载mask,完成

    2019.6.20更新
    因为被要求代码动态切图,所以弃用sprite Editor切图,改用SetPixel方法来切图,这个方法网上有大量的实例,这里不再说明,只是说一下这个方法得到的子图片是从左到右,从下往上排列的,和像素点的排列顺序一样

    3.拼图拼合移动

    2019.6.20更新
    这点在之前是没有的,我只是把拼合好的拼图放到一个父级下面实现共同移动,后面遇到了很多bug,于是想了一个思路。

    拼图的拼合,现在是每块拼图会记录它上下左右其他拼图和它自身的一个偏移量,如果检测以后是正确的碰撞,就把该拼图的位置设置为当前拼图的位置+这个偏移量。、

    现在的拼图从开始到结束全在一个父级下面,每个拼图会记录一个list和一个transform,list里面是所有跟它拼合的拼图,transform是记录的当前鼠标进入的拼图,当拖动的时候,list里所有拼图和transform计算一个偏移量,然后所有拼图的位置就等于鼠标移动的实时位置+这个偏移量,这就实现了一个“虚拟父级”的概念,完成了拼合好的拼图一起移动的功能。

    对于拼图旋转,设定一个整型数值用来记录旋转次数,有这么几种0,1,2,3,超过4次就重新从0开始,然后射线检测的时候加个检测双方这个数值是否相等的语句,即可分离不同旋转次数的拼图的碰撞检测。

    三、Show me the code

    2019.6.20更新
    几乎更新了所有代码,现在还是把主要的代码放出来,工程在下面。

    1.生成拼图的GameStart 类

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.UI;
    
    public class GameStart : MonoBehaviour
    {
        //切完的小图
        private List<Texture2D> textureList = new List<Texture2D>();
        //要切的大图
        private Texture2D mCurTexture;
        //14种mask
        private List<GameObject> maskList = new List<GameObject>();
        //拼图生成在jps下,存在jigsawPuzzleList里
        private Transform jps;
        private List<GameObject> jigsawPuzzleList = new List<GameObject>();
    
        void Start()
        {
            InIt();
        }
        //初始化
        private void InIt()
        {
            jps = GameObject.Find("JPs").transform;
            //切图
            mCurTexture = Resources.Load<Texture2D>("Textures/ow");
            textureList = DePackTexture(GameManager.Instance.lieNum * 3, GameManager.Instance.hangNum * 3, GameManager.Instance.SideLength, mCurTexture);
            //读取14种mask预制体
            for (int i = 0; i < 14; i++)
            {
                maskList.Add(Resources.Load<GameObject>("Prefabs/Mask/mask" + (i + 1)));
            }
            CreateJigsawPuzzle(GameManager.Instance.hangNum, GameManager.Instance.lieNum);
            //随机位置
            for (int i = 0; i < jigsawPuzzleList.Count; i++)
            {
                int posX = Random.Range(-300, 350);
                int posY = Random.Range(600, -200);
                jigsawPuzzleList[i].transform.localPosition = new Vector3(posX, posY, 0f);
                jigsawPuzzleList[i].AddComponent<SingleJigsawPuzzle>();
            }
            Debug.Log("拼图生成完毕");
        }
        //列数,行数,小图的长宽
        private List<Texture2D> DePackTexture(int PicColumnCount, int PicRowCount, int SideLength, Texture2D CurTexture)
        {
            List<Texture2D> newTList = new List<Texture2D>();
            for (int i = 0; i < PicColumnCount; ++i)
            {
                for (int j = 0; j < PicRowCount; ++j)
                {
                    int curX = i * SideLength;
                    int curY = j * SideLength;
                    Texture2D newTexture = new Texture2D(SideLength, SideLength);
                    for (int m = curY; m < curY + SideLength; ++m)
                    {
                        for (int n = curX; n < curX + SideLength; ++n)
                        {
                            newTexture.SetPixel(n - curX, m - curY, CurTexture.GetPixel(n, m));
                        }
                    }
                    newTexture.Apply();
                    newTList.Add(newTexture);
                }
            }
            return newTList;
        }
    
        //5*3,插入点为4
        private void FiveThreeIndex4(int Index, Transform Parent)
        {
            List<Texture2D> ttList = new List<Texture2D>();
            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    ttList.Add(textureList[Index - GameManager.Instance.hangNum * 3 + j + i * GameManager.Instance.hangNum*3]);
                }
            }
            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    GameObject go = new GameObject();
                    go.AddComponent<Image>();
                    go.transform.SetParent(Parent);
                    go.transform.localPosition = new Vector3(60f + i * 30f, 30f + j * 30f, 0f);
                    Image ie = go.GetComponent<Image>();
                    ie.rectTransform.sizeDelta = new Vector2(30f, 30f);
                    ie.sprite = Sprite.Create(ttList[i * 3 + j], new Rect(0, 0, ttList[i * 3 + j].width, ttList[i * 3 + j].height), new Vector2(0.5f, 0.5f));
                }
            }
        }
        //3*5,插入点为2
        private void ThreeFiveIndex2(int Index, Transform Parent)
        {
            List<Texture2D> ttList = new List<Texture2D>();
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 5; j++)
                {
                    ttList.Add(textureList[Index - 1 + j + i * GameManager.Instance.hangNum*3]);
                }
            }
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 5; j++)
                {
                    GameObject go = new GameObject();
                    go.AddComponent<Image>();
                    go.transform.SetParent(Parent);
                    go.transform.localPosition = new Vector3(-30f + i * 30f, -60f + j * 30f, 0f);
                    Image ie = go.GetComponent<Image>();
                    ie.rectTransform.sizeDelta = new Vector2(30f, 30f);
                    ie.sprite = Sprite.Create(ttList[i * 5 + j], new Rect(0, 0, ttList[i * 5 + j].width, ttList[i * 5 + j].height), new Vector2(0.5f, 0.5f));
                }
            }
        }
        //3*4,插入点为1
        private void ThreeFourIndex1(int Index, Transform Parent)
        {
            List<Texture2D> ttList = new List<Texture2D>();
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    ttList.Add(textureList[Index + j + i * GameManager.Instance.hangNum*3]);
                }
            }
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    GameObject go = new GameObject();
                    go.AddComponent<Image>();
                    go.transform.SetParent(Parent);
                    go.transform.localPosition = new Vector3(-60f + i * 30f, -60f + j * 30f, 0f);
                    Image ie = go.GetComponent<Image>();
                    ie.rectTransform.sizeDelta = new Vector2(30f, 30f);
                    ie.sprite = Sprite.Create(ttList[i * 4 + j], new Rect(0, 0, ttList[i * 4 + j].width, ttList[i * 4 + j].height), new Vector2(0.5f, 0.5f));
                }
            }
        }
        //3*4,插入点为2
        private void ThreeFourIndex2(int Index, Transform Parent)
        {
            List<Texture2D> ttList = new List<Texture2D>();
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    ttList.Add(textureList[Index - 1 + j + i * GameManager.Instance.hangNum*3]);
                }
            }
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    GameObject go = new GameObject();
                    go.AddComponent<Image>();
                    go.transform.SetParent(Parent);
                    go.transform.localPosition = new Vector3(-60f + i * 30f, -60f + j * 30f, 0f);
                    Image ie = go.GetComponent<Image>();
                    ie.rectTransform.sizeDelta = new Vector2(30f, 30f);
                    ie.sprite = Sprite.Create(ttList[i * 4 + j], new Rect(0, 0, ttList[i * 4 + j].width, ttList[i * 4 + j].height), new Vector2(0.5f, 0.5f));
                }
            }
        }
        //4*3,插入点为1
        private void FourThreeIndex1(int Index, Transform Parent)
        {
            List<Texture2D> ttList = new List<Texture2D>();
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    ttList.Add(textureList[Index + j + i * GameManager.Instance.hangNum*3]);
    
                }
            }
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    GameObject go = new GameObject();
                    go.AddComponent<Image>();
                    go.transform.SetParent(Parent);
                    go.transform.localPosition = new Vector3(-60f + i * 30f, -30f + j * 30f, 0f);
                    Image ie = go.GetComponent<Image>();
                    ie.rectTransform.sizeDelta = new Vector2(30f, 30f);
                    ie.sprite = Sprite.Create(ttList[i * 3 + j], new Rect(0, 0, ttList[i * 3 + j].width, ttList[i * 3 + j].height), new Vector2(0.5f, 0.5f));
                }
            }
        }
        //4*3,插入点为4
        private void FourThreeIndex4(int Index, Transform Parent)
        {
            List<Texture2D> ttList = new List<Texture2D>();
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    ttList.Add(textureList[Index - GameManager.Instance.hangNum * 3 + j + i * GameManager.Instance.hangNum*3]);
                }
            }
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    GameObject go = new GameObject();
                    go.AddComponent<Image>();
                    go.transform.SetParent(Parent);
                    go.transform.localPosition = new Vector3(-60f + i * 30f, -30f + j * 30f, 0f);
                    Image ie = go.GetComponent<Image>();
                    ie.rectTransform.sizeDelta = new Vector2(30f, 30f);
                    ie.sprite = Sprite.Create(ttList[i * 3 + j], new Rect(0, 0, ttList[i * 3 + j].width, ttList[i * 3 + j].height), new Vector2(0.5f, 0.5f));
                }
            }
        }
    
        //生成拼图hangNum*lieNum
        private void CreateJigsawPuzzle(int hangNum, int lieNum)
        {
            int index = 0;
            int nameNum = 0;
            for (int i = 0; i < lieNum; i++)
            {
                for (int j = 0; j < hangNum; j++)
                {
                    index = j * 3 + i * 9 * hangNum;
                    nameNum = j + i * hangNum;
                    //边框
                    //左下角
                    if (i == 0 && j == 0)
                    {
                        GameObject goMask = Instantiate<GameObject>(maskList[2]);
                        goMask.transform.SetParent(jps);
                        goMask.name = "JP-" + nameNum;
                        GameObject go1 = new GameObject();
                        FourThreeIndex1(index, go1.transform);
                        go1.transform.SetParent(goMask.transform);
                        go1.transform.localPosition = new Vector3(15f, 0f, 0f);
                        jigsawPuzzleList.Add(goMask);
                    }
                    //左上角
                    else if (i == 0 && j == hangNum - 1)
                    {
                        GameObject goMask = Instantiate<GameObject>(maskList[3]);
                        goMask.transform.SetParent(jps);
                        goMask.name = "JP-" + nameNum;
                        GameObject go1 = new GameObject();
                        ThreeFourIndex2(index, go1.transform);
                        go1.transform.SetParent(goMask.transform);
                        go1.transform.localPosition = new Vector3(30f, 15f, 0f);
                        jigsawPuzzleList.Add(goMask);
                    }
                    //右下角
                    else if (i == lieNum - 1 && j == 0)
                    {
                        GameObject goMask = Instantiate<GameObject>(maskList[1]);
                        goMask.transform.SetParent(jps);
                        goMask.name = "JP-" + nameNum;
                        GameObject go1 = new GameObject();
                        ThreeFourIndex1(index, go1.transform);
                        go1.transform.SetParent(goMask.transform);
                        go1.transform.localPosition = new Vector3(30f, 15f, 0f);
                        jigsawPuzzleList.Add(goMask);
    
                    }
                    //右上角
                    else if (i == lieNum - 1 && j == hangNum - 1)
                    {
                        GameObject goMask = Instantiate<GameObject>(maskList[0]);
                        goMask.transform.SetParent(jps);
                        goMask.name = "JP-" + nameNum;
                        GameObject go1 = new GameObject();
                        FourThreeIndex4(index, go1.transform);
                        go1.transform.SetParent(goMask.transform);
                        go1.transform.localPosition = new Vector3(15f, 0f, 0f);
                        jigsawPuzzleList.Add(goMask);
                    }
                    //第一列
                    else if (i == 0)
                    {
                        //偶数行
                        if (j % 2 == 0)
                        {
                            GameObject goMask = Instantiate<GameObject>(maskList[9]);
                            goMask.transform.SetParent(jps);
                            goMask.name = "JP-" + nameNum;
                            GameObject go1 = new GameObject();
                            FourThreeIndex1(index, go1.transform);
                            go1.transform.SetParent(goMask.transform);
                            go1.transform.localPosition = new Vector3(15f, 0f, 0f);
                            jigsawPuzzleList.Add(goMask);
    
                        }
                        //奇数行
                        else if (j % 2 != 0)
                        {
                            GameObject goMask = Instantiate<GameObject>(maskList[7]);
                            goMask.transform.SetParent(jps);
                            goMask.name = "JP-" + nameNum;
                            GameObject go1 = new GameObject();
                            ThreeFiveIndex2(index, go1.transform);
                            go1.transform.SetParent(goMask.transform);
                            go1.transform.localPosition = new Vector3(0f, 0f, 0f);
                            jigsawPuzzleList.Add(goMask);
                        }
                    }
                    //最后一列
                    else if (i == lieNum - 1)
                    {
                        //偶数行
                        if (j % 2 == 0)
                        {
                            GameObject goMask = Instantiate<GameObject>(maskList[6]);
                            goMask.transform.SetParent(jps);
                            goMask.name = "JP-" + nameNum;
                            GameObject go1 = new GameObject();
                            ThreeFiveIndex2(index, go1.transform);
                            go1.transform.SetParent(goMask.transform);
                            go1.transform.localPosition = new Vector3(0f, 0f, 0f);
                            jigsawPuzzleList.Add(goMask);
                        }
                        //奇数行
                        else if (j % 2 != 0)
                        {
                            GameObject goMask = Instantiate<GameObject>(maskList[8]);
                            goMask.transform.SetParent(jps);
                            goMask.name = "JP-" + nameNum;
                            GameObject go1 = new GameObject();
                            FourThreeIndex4(index, go1.transform);
                            go1.transform.SetParent(goMask.transform);
                            go1.transform.localPosition = new Vector3(15f, 0f, 0f);
                            jigsawPuzzleList.Add(goMask);
                        }
                    }
                    //第一行
                    else if (j == 0)
                    {
                        //奇数列
                        if (i % 2 != 0)
                        {
                            GameObject goMask = Instantiate<GameObject>(maskList[10]);
                            goMask.transform.SetParent(jps);
                            goMask.name = "JP-" + nameNum;
                            GameObject go1 = new GameObject();
                            ThreeFourIndex1(index, go1.transform);
                            go1.transform.SetParent(goMask.transform);
                            go1.transform.localPosition = new Vector3(30f, 15f, 0f);
                            jigsawPuzzleList.Add(goMask);
                        }
                        //偶数列
                        else if (i % 2 == 0)
                        {
                            GameObject goMask = Instantiate<GameObject>(maskList[4]);
                            goMask.transform.SetParent(jps);
                            goMask.name = "JP-" + nameNum;
                            GameObject go1 = new GameObject();
                            FiveThreeIndex4(index, go1.transform);
                            go1.transform.SetParent(goMask.transform);
                            go1.transform.localPosition = new Vector3(-120f, -60f, 0f);
                            jigsawPuzzleList.Add(goMask);
                        }
                    }
                    //最后一行
                    else if (j == hangNum - 1)
                    {
                        //奇数列
                        if (i % 2 != 0)
                        {
                            GameObject goMask = Instantiate<GameObject>(maskList[5]);
                            goMask.transform.SetParent(jps);
                            goMask.name = "JP-" + nameNum;
                            GameObject go1 = new GameObject();
                            FiveThreeIndex4(index, go1.transform);
                            go1.transform.SetParent(goMask.transform);
                            go1.transform.localPosition = new Vector3(-120f, -60f, 0f);
                            jigsawPuzzleList.Add(goMask);
                        }
                        //偶数列
                        else if (i % 2 == 0)
                        {
                            GameObject goMask = Instantiate<GameObject>(maskList[11]);
                            goMask.transform.SetParent(jps);
                            goMask.name = "JP-" + nameNum;
                            GameObject go1 = new GameObject();
                            ThreeFourIndex2(index, go1.transform);
                            go1.transform.SetParent(goMask.transform);
                            go1.transform.localPosition = new Vector3(30f, 15f, 0f);
                            jigsawPuzzleList.Add(goMask);
                        }
                    }
                    //内部
                    //奇数列
                    else if (i % 2 != 0)
                    {
                        //偶数行
                        if (j % 2 == 0)
                        {
                            GameObject goMask = Instantiate<GameObject>(maskList[13]);
                            goMask.transform.SetParent(jps);
                            goMask.name = "JP-" + nameNum;
                            GameObject go1 = new GameObject();
                            ThreeFiveIndex2(index, go1.transform);
                            go1.transform.SetParent(goMask.transform);
                            go1.transform.localPosition = new Vector3(0f, 0f, 0f);
                            jigsawPuzzleList.Add(goMask);
                        }
                        //奇数行
                        else if (j % 2 != 0)
                        {
                            GameObject goMask = Instantiate<GameObject>(maskList[12]);
                            goMask.transform.SetParent(jps);
                            goMask.name = "JP-" + nameNum;
                            GameObject go1 = new GameObject();
                            FiveThreeIndex4(index, go1.transform);
                            go1.transform.SetParent(goMask.transform);
                            go1.transform.localPosition = new Vector3(-120f, -60f, 0f);
                            jigsawPuzzleList.Add(goMask);
                        }
                    }
                    //偶数列
                    else if (i % 2 == 0)
                    {
                        //偶数行
                        if (j % 2 == 0)
                        {
                            GameObject goMask = Instantiate<GameObject>(maskList[12]);
                            goMask.transform.SetParent(jps);
                            goMask.name = "JP-" + nameNum;
                            GameObject go1 = new GameObject();
                            FiveThreeIndex4(index, go1.transform);
                            go1.transform.SetParent(goMask.transform);
                            go1.transform.localPosition = new Vector3(-120f, -60f, 0f);
                            jigsawPuzzleList.Add(goMask);
                        }
                        //奇数行
                        else if (j % 2 != 0)
                        {
                            GameObject goMask = Instantiate<GameObject>(maskList[13]);
                            goMask.transform.SetParent(jps);
                            goMask.name = "JP-" + nameNum;
                            GameObject go1 = new GameObject();
                            ThreeFiveIndex2(index, go1.transform);
                            go1.transform.SetParent(goMask.transform);
                            go1.transform.localPosition = new Vector3(0f, 0f, 0f);
                            jigsawPuzzleList.Add(goMask);
                        }
                    }
                }
            }
        }
    }
    

    2.单个拼图功能SingleJigsawPuzzle类

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.EventSystems;
    using UnityEngine.UI;
    
    public class SingleJigsawPuzzle : MonoBehaviour,IPointerEnterHandler, IPointerExitHandler, IBeginDragHandler, IDragHandler, IEndDragHandler
    {
        private bool mouseEnter = false;
        private RectTransform curRtTrans;
        //拖拽开始时,图片-鼠标的位置差
        public Vector3 offsetPos = new Vector3(0, 0, 0);
        public int rotateNum=0;
        public int maskNum=-1;
    
        private static float distance = 95f;
        private int mIndex;
        private int hangNum;
        private int lieNum;
        private int curHang;
        private int curLie;
        //逻辑父级
        public int parentNum;
        public List<Transform> jpList = new List<Transform>();
        private RectTransform followParent;
        //旋转需要
        private RectTransform mRotate;
        //碰撞开关
        public bool isCollision = false;
        // Use this for initialization
        void Start()
        {
            InIt();
        }
    
        // Update is called once per frame
        void Update()
        {
            RotateAndMove();
            JudgeWin();
        }
        private void LateUpdate()
        {
            if (isCollision)
            {
                JudgeCollision();
            }
        }
        private void InIt()
        {
            hangNum = GameManager.Instance.hangNum;
            lieNum = GameManager.Instance.lieNum;
            //获得当前拼图的正确序位
            mIndex = int.Parse(transform.name.Split('-')[1]);
            //得到当前拼图所在行列数
            curLie = mIndex / hangNum;
            curHang = mIndex % hangNum;
            //Debug.Log("" + mIndex + "  lie " + curLie + "hang " + curHang);
            mRotate = GameObject.Find("Rotate").GetComponent<RectTransform>();
            maskNum = int.Parse(gameObject.GetComponent<Image>().sprite.name.Split('k')[1]);
            jpList.Add(transform);
            parentNum = mIndex;
            GameManager.Instance.jpParentDic.Add(transform.name, gameObject);
            followParent = gameObject.GetComponent<RectTransform>();
        }
        //鼠标进入
        public void OnPointerEnter(PointerEventData eventData)
        {
            mouseEnter = true;
            foreach (Transform tf in jpList)
            {
                tf.GetComponent<SingleJigsawPuzzle>().isCollision = true;
            }
        }
        public void OnPointerExit(PointerEventData eventData)
        {
            mouseEnter = false;
            foreach (Transform tf in jpList)
            {
                tf.GetComponent<SingleJigsawPuzzle>().isCollision = false;
            }
        }
        //拖拽
        public void OnBeginDrag(PointerEventData eventData)
        {
            curRtTrans = GetComponent<RectTransform>();
            foreach (Transform tf in jpList)
            {
                tf.SetAsLastSibling();
                tf.GetComponent<SingleJigsawPuzzle>().followParent = transform.GetComponent<RectTransform>();
                tf.GetComponent<SingleJigsawPuzzle>().offsetPos = tf.GetComponent<RectTransform>().position - tf.GetComponent<SingleJigsawPuzzle>().followParent.position;
            }
            offsetPos = curRtTrans.position - Input.mousePosition;
        }
        public void OnDrag(PointerEventData eventData)
        {
            if (eventData != null)
            {
                curRtTrans.position = new Vector3(eventData.position.x, eventData.position.y, 0) + offsetPos;
            }
        }
        public void OnEndDrag(PointerEventData eventData)
        {
            //Debug.Log("OnEndDrag");
        }
        //旋转和移动跟随
        private void RotateAndMove()
        {
            if (followParent.name != transform.name)
            {
                transform.GetComponent<RectTransform>().position = new Vector3(followParent.position.x, followParent.position.y, 0) + offsetPos;
            }
            if (rotateNum == 4)
            {
                rotateNum = 0;
            }
            if (mouseEnter == true)
            {
                if (Input.GetKeyDown(KeyCode.Space))
                {
                    foreach (Transform tf in jpList)
                    {
                        tf.GetComponent<RectTransform>().SetParent(mRotate);
                        tf.GetComponent<SingleJigsawPuzzle>().followParent = tf.GetComponent<RectTransform>();
                    }
                    mRotate.RotateAround(Input.mousePosition, new Vector3(0, 0, 1), 90f);
                    foreach (Transform tf in jpList)
                    {
                        tf.GetComponent<SingleJigsawPuzzle>().rotateNum++;
                        tf.GetComponent<RectTransform>().SetParent(mRotate.parent);
                    }
                }
            }
        }
        //结束判断
        private void JudgeWin()
        {
            if (jpList.Count == GameManager.Instance.lieNum * GameManager.Instance.hangNum)
            {
                GameManager.Instance.isWin = true;
            }
        }
        //拼合检测
        private void CollisionFromRight(Vector3 Offset,int Dvalue)
        {
            RaycastHit2D infoRight = Physics2D.Raycast(transform.position, transform.right, distance);
            if (infoRight.collider != null && infoRight.transform.name == "JP-" + Dvalue && rotateNum ==infoRight.transform.GetComponent<SingleJigsawPuzzle>().rotateNum)
            {
                SingleJigsawPuzzle infoSJP = infoRight.transform.GetComponent<SingleJigsawPuzzle>();
                if (parentNum != infoSJP.parentNum)
                {
                    if (Input.GetMouseButtonUp(0) && Vector3.Distance(transform.GetComponent<RectTransform>().position, infoRight.transform.GetComponent<RectTransform>().position) < 105f)
                    {
                        foreach (Transform tf in jpList)
                        {
                            tf.GetComponent<SingleJigsawPuzzle>().followParent = transform.GetComponent<RectTransform>();
                            tf.GetComponent<SingleJigsawPuzzle>().offsetPos = tf.GetComponent<RectTransform>().position - tf.GetComponent<SingleJigsawPuzzle>().followParent.position;
                        }
                        transform.GetComponent<RectTransform>().position = infoRight.transform.GetComponent<RectTransform>().position + Offset;
                        foreach (Transform tf in jpList)
                        {
                            tf.GetComponent<SingleJigsawPuzzle>().parentNum = infoSJP.parentNum;
                            tf.GetComponent<SingleJigsawPuzzle>().jpList = infoSJP.jpList;
                            infoSJP.jpList.Add(tf);
                        }
                    }
                }
                else
                {
                    return;
                }
            }
        }
        private void CollisionFromLeft(Vector3 Offset,int Dvalue)
        {
            RaycastHit2D infoLeft = Physics2D.Raycast(transform.position, -transform.right, distance);
            if (infoLeft.collider != null && infoLeft.transform.name == "JP-" + Dvalue && rotateNum == infoLeft.transform.GetComponent<SingleJigsawPuzzle>().rotateNum)
            {
                SingleJigsawPuzzle infoSJP = infoLeft.transform.GetComponent<SingleJigsawPuzzle>();
                if (parentNum != infoSJP.parentNum)
                {
                    if (Input.GetMouseButtonUp(0) && Vector3.Distance(transform.GetComponent<RectTransform>().position, infoLeft.transform.GetComponent<RectTransform>().position) < 105f)
                    {
    
                        foreach (Transform tf in jpList)
                        {
                            tf.GetComponent<SingleJigsawPuzzle>().followParent = transform.GetComponent<RectTransform>();
                            tf.GetComponent<SingleJigsawPuzzle>().offsetPos = tf.GetComponent<RectTransform>().position - tf.GetComponent<SingleJigsawPuzzle>().followParent.position;
                        }
                        transform.GetComponent<RectTransform>().position = infoLeft.transform.GetComponent<RectTransform>().position + Offset;
                        foreach (Transform tf in jpList)
                        {
                            tf.GetComponent<SingleJigsawPuzzle>().parentNum = infoSJP.parentNum;
                            tf.GetComponent<SingleJigsawPuzzle>().jpList = infoSJP.jpList;
                            infoSJP.jpList.Add(tf);
                        }
                    }
                }
                else
                {
                    return;
                }
            }
        }
        private void CollisionFromUp(Vector3 Offset,int Dvalue)
        {
            RaycastHit2D infoUp = Physics2D.Raycast(transform.position, transform.up, distance);
            if (infoUp.collider != null && infoUp.transform.name == "JP-" + Dvalue && rotateNum == infoUp.transform.GetComponent<SingleJigsawPuzzle>().rotateNum)
            {
                SingleJigsawPuzzle infoSJP = infoUp.transform.GetComponent<SingleJigsawPuzzle>();
                if (parentNum != infoSJP.parentNum)
                {
                    if (Input.GetMouseButtonUp(0) && Vector3.Distance(transform.GetComponent<RectTransform>().position, infoUp.transform.GetComponent<RectTransform>().position) < 105f)
                    {
    
                        foreach (Transform tf in jpList)
                        {
                            tf.GetComponent<SingleJigsawPuzzle>().followParent = transform.GetComponent<RectTransform>();
                            tf.GetComponent<SingleJigsawPuzzle>().offsetPos = tf.GetComponent<RectTransform>().position - tf.GetComponent<SingleJigsawPuzzle>().followParent.position;
                        }
                        transform.GetComponent<RectTransform>().position = infoUp.transform.GetComponent<RectTransform>().position + Offset;
                        foreach (Transform tf in jpList)
                        {
                            tf.GetComponent<SingleJigsawPuzzle>().parentNum = infoSJP.parentNum;
                            tf.GetComponent<SingleJigsawPuzzle>().jpList = infoSJP.jpList;
                            infoSJP.jpList.Add(tf);
                        }
                    }
                }
                else
                {
                    return;
                }
            }
        }
        private void CollisionFromDown(Vector3 Offset, int Dvalue)
        {
            RaycastHit2D infoDown = Physics2D.Raycast(transform.position, -transform.up, distance);
            if (infoDown.collider != null && infoDown.transform.name == "JP-" + Dvalue && rotateNum == infoDown.transform.GetComponent<SingleJigsawPuzzle>().rotateNum)
            {
                SingleJigsawPuzzle infoSJP = infoDown.transform.GetComponent<SingleJigsawPuzzle>();
                if (parentNum != infoSJP.parentNum)
                {
                    if (Input.GetMouseButtonUp(0) && Vector3.Distance(transform.GetComponent<RectTransform>().position, infoDown.transform.GetComponent<RectTransform>().position) < 105f)
                    {
                        foreach (Transform tf in jpList)
                        {
                            tf.GetComponent<SingleJigsawPuzzle>().followParent = transform.GetComponent<RectTransform>();
                            tf.GetComponent<SingleJigsawPuzzle>().offsetPos = tf.GetComponent<RectTransform>().position - tf.GetComponent<SingleJigsawPuzzle>().followParent.position;
                        }
                        transform.GetComponent<RectTransform>().position = infoDown.transform.GetComponent<RectTransform>().position + Offset;
                        foreach (Transform tf in jpList)
                        {
                            tf.GetComponent<SingleJigsawPuzzle>().parentNum = infoSJP.parentNum;
                            tf.GetComponent<SingleJigsawPuzzle>().jpList = infoSJP.jpList;
                            infoSJP.jpList.Add(tf);
                        }
                    }
                }
                else
                {
                    return;
                }
            }
        }
        private void JudgeCollision()
        {
            switch (maskNum)
            {
                case 0:
                    if (rotateNum == 0)
                    {
                        CollisionFromLeft(new Vector3(75f,15f,0f),mIndex-hangNum);
                        CollisionFromDown(new Vector3(-15f,90f,0f),mIndex-1);
                    }
                    else if (rotateNum == 1)
                    {
                        CollisionFromLeft(new Vector3(-15f,75f,0f), mIndex - hangNum);
                        CollisionFromDown(new Vector3(-90f,-15f,0f), mIndex - 1);
                    }
                    else if (rotateNum == 2)
                    {
                        CollisionFromLeft(new Vector3(-75f, -15f, 0f), mIndex - hangNum);
                        CollisionFromDown(new Vector3(15f, -90f, 0f), mIndex - 1);
                    }
                    else if (rotateNum == 3)
                    {
                        CollisionFromLeft(new Vector3(15f, -75f, 0f), mIndex - hangNum);
                        CollisionFromDown(new Vector3(90f, 15f, 0f), mIndex - 1);
                    }
                    break;
                case 1:
                    if (rotateNum == 0)
                    {
                        CollisionFromUp(new Vector3(15f,-75f,0f),mIndex+1);
                        CollisionFromLeft(new Vector3(90f,15f,0f),mIndex-hangNum);
                    }
                    else if (rotateNum == 1)
                    {
                        CollisionFromUp(new Vector3(75f,15f,0f),mIndex+1);
                        CollisionFromLeft(new Vector3(-15f,90f,0f),mIndex-hangNum);
                    }
                    else if (rotateNum == 2)
                    {
                        CollisionFromUp(new Vector3(-15f, 75f, 0f), mIndex + 1);
                        CollisionFromLeft(new Vector3(-90f, -15f, 0f), mIndex - hangNum);
                    }
                    else if (rotateNum == 3)
                    {
                        CollisionFromUp(new Vector3(-75f, -15f, 0f), mIndex + 1);
                        CollisionFromLeft(new Vector3(15f, -90f, 0f), mIndex - hangNum);
                    }
                    break;
                case 2:
                    if (rotateNum == 0)
                    {
                        CollisionFromUp(new Vector3(15f, -90f, 0f), mIndex + 1);
                        CollisionFromRight(new Vector3(-75f, -15f, 0f), mIndex + hangNum);
                    }
                    else if (rotateNum == 1)
                    {
                        CollisionFromUp(new Vector3(90f, 15f, 0f), mIndex + 1);
                        CollisionFromRight(new Vector3(15f, -75f, 0f), mIndex + hangNum);
                    }
                    else if (rotateNum == 2)
                    {
                        CollisionFromUp(new Vector3(-15f, 90f, 0f), mIndex + 1);
                        CollisionFromRight(new Vector3(75f, 15f, 0f), mIndex + hangNum);
                    }
                    else if (rotateNum == 3)
                    {
                        CollisionFromUp(new Vector3(-90f, -15f, 0f), mIndex + 1);
                        CollisionFromRight(new Vector3(-15f, 75f, 0f), mIndex + hangNum);
                    }
                    break;
                case 3:
                    if (rotateNum == 0)
                    {
                        CollisionFromRight(new Vector3(-90f, -15f, 0f), mIndex + hangNum);
                        CollisionFromDown(new Vector3(-15f, 75f, 0f), mIndex - 1);
                    }
                    else if (rotateNum == 1)
                    {
                        CollisionFromRight(new Vector3(15f, -90f, 0f), mIndex + hangNum);
                        CollisionFromDown(new Vector3(-75f, -15f, 0f), mIndex - 1);
                    }
                    else if (rotateNum == 2)
                    {
                        CollisionFromRight(new Vector3(90f, 15f, 0f), mIndex + hangNum);
                        CollisionFromDown(new Vector3(15f, -75f, 0f), mIndex - 1);
                    }
                    else if (rotateNum == 3)
                    {
                        CollisionFromRight(new Vector3(-15f, 90f, 0f), mIndex + hangNum);
                        CollisionFromDown(new Vector3(75f, 15f, 0f), mIndex - 1);
                    }
                    break;
                case 4:
                    if (rotateNum == 0)
                    {
                        CollisionFromRight(new Vector3(-90f, 0f, 0f), mIndex + hangNum);
                        CollisionFromUp(new Vector3(-15f, -90f, 0f), mIndex + 1);
                        CollisionFromDown(new Vector3(-15f, 90f, 0f), mIndex - 1);
                    }
                    else if (rotateNum == 1)
                    {
                        CollisionFromRight(new Vector3(0f,-90f,0f),mIndex+hangNum);
                        CollisionFromUp(new Vector3(90f,-15f,0f),mIndex+1);
                        CollisionFromDown(new Vector3(-90f,-15f,0f),mIndex-1);
                    }
                    else if (rotateNum == 2)
                    {
                        CollisionFromRight(new Vector3(90f, 0f, 0f), mIndex + hangNum);
                        CollisionFromUp(new Vector3(15f, 90f, 0f), mIndex + 1);
                        CollisionFromDown(new Vector3(15f, -90f, 0f), mIndex - 1);
                    }
                    else if (rotateNum == 3)
                    {
                        CollisionFromRight(new Vector3(0f, 90f, 0f), mIndex + hangNum);
                        CollisionFromUp(new Vector3(-90f, 15f, 0f), mIndex + 1);
                        CollisionFromDown(new Vector3(90f, 15f, 0f), mIndex - 1);
                    }
                    break;
                case 5:
                    if (rotateNum == 0)
                    {
                        if (curLie == 1)
                        {
                            CollisionFromLeft(new Vector3(75f,15f,0f),mIndex-hangNum);
                        }
                        else
                        {
                            CollisionFromLeft(new Vector3(90f, 15f, 0f), mIndex - hangNum);
                        }
                        CollisionFromRight(new Vector3(-90f, 15f, 0f), mIndex + hangNum);
                        CollisionFromUp(new Vector3(0f, -75f, 0f), mIndex + 1);
                    }
                    else if (rotateNum == 1)
                    {
                        if (curLie == 1)
                        {
                            CollisionFromLeft(new Vector3(-15f, 75f, 0f), mIndex - hangNum);
                        }
                        else
                        {
                            CollisionFromLeft(new Vector3(-15f, 90f, 0f), mIndex - hangNum);
                        }
                        CollisionFromRight(new Vector3(-15f,-90f,0f),mIndex+hangNum);
                        CollisionFromUp(new Vector3(75f,0f,0f),mIndex+1);
                    }
                    else if (rotateNum == 2)
                    {
                        if (curLie == 1)
                        {
                            CollisionFromLeft(new Vector3(-75f, -15f, 0f), mIndex - hangNum);
                        }
                        else
                        {
                            CollisionFromLeft(new Vector3(-90f, -15f, 0f), mIndex - hangNum);
                        }
                        CollisionFromRight(new Vector3(90f, -15f, 0f), mIndex + hangNum);
                        CollisionFromUp(new Vector3(0f, 75f, 0f), mIndex + 1);
                    }
                    else if (rotateNum == 3)
                    {
                        if (curLie == 1)
                        {
                            CollisionFromLeft(new Vector3(15f, -75f, 0f), mIndex - hangNum);
                        }
                        else
                        {
                            CollisionFromLeft(new Vector3(15f, -90f, 0f), mIndex - hangNum);
                        }
                        CollisionFromRight(new Vector3(15f, 90f, 0f), mIndex + hangNum);
                        CollisionFromUp(new Vector3(-75f, 0f, 0f), mIndex + 1);
                    }
                    break;
                case 6:
                    if (rotateNum == 0)
                    {
                        if (curHang == hangNum - 2)
                        {
                            CollisionFromUp(new Vector3(15f,-75f,0f),mIndex+1);
                        }
                        else
                        {
                            CollisionFromUp(new Vector3(15f, -90f, 0f), mIndex + 1);
                        }
                        CollisionFromDown(new Vector3(15f, 90f, 0f), mIndex - 1);
                        CollisionFromRight(new Vector3(-75f, 0f, 0f), mIndex + hangNum);
                    }
                    else if (rotateNum == 1)
                    {
                        if (curHang == hangNum - 2)
                        {
                            CollisionFromUp(new Vector3(75f, 15f, 0f), mIndex + 1);
                        }
                        else
                        {
                            CollisionFromUp(new Vector3(90f, 15f, 0f), mIndex + 1);
                        }
                        CollisionFromDown(new Vector3(-90f,15f,0f),mIndex-1);
                        CollisionFromRight(new Vector3(0f,-75f,0f),mIndex+hangNum);
                    }
                    else if (rotateNum == 2)
                    {
                        if (curHang == hangNum - 2)
                        {
                            CollisionFromUp(new Vector3(-15f, 75f, 0f), mIndex + 1);
                        }
                        else
                        {
                            CollisionFromUp(new Vector3(-15f, 90f, 0f), mIndex + 1);
                        }
                        CollisionFromDown(new Vector3(-15f, -90f, 0f), mIndex - 1);
                        CollisionFromRight(new Vector3(75f, 0f, 0f), mIndex + hangNum);
                    }
                    else if (rotateNum == 3)
                    {
                        if (curHang == hangNum - 2)
                        {
                            CollisionFromUp(new Vector3(-75f, -15f, 0f), mIndex + 1);
                        }
                        else
                        {
                            CollisionFromUp(new Vector3(-90f, -15f, 0f), mIndex + 1);
                        }
                        CollisionFromDown(new Vector3(90f, -15f, 0f), mIndex - 1);
                        CollisionFromRight(new Vector3(0f, 75f, 0f), mIndex + hangNum);
                    }
                    break;
                case 7:
                    if (rotateNum == 0)
                    {
                        if (curLie == lieNum - 2)
                        {
                            CollisionFromRight(new Vector3(-75f,-15f,0f),mIndex+hangNum);
                        }
                        else
                        {
                            CollisionFromRight(new Vector3(-90f, -15f, 0f), mIndex + hangNum);
                        }
                        CollisionFromDown(new Vector3(0f, 75f, 0f), mIndex - 1);
                        CollisionFromLeft(new Vector3(90f, -15f, 0f), mIndex - hangNum);
                    }
                    else if (rotateNum == 1)
                    {
                        if (curLie == lieNum - 2)
                        {
                            CollisionFromRight(new Vector3(15f, -75f, 0f), mIndex + hangNum);
                        }
                        else
                        {
                            CollisionFromRight(new Vector3(15f, -90f, 0f), mIndex + hangNum);
                        }
                        CollisionFromDown(new Vector3(-75f,0f,0f),mIndex-1);
                        CollisionFromLeft(new Vector3(15f,90f,0f),mIndex-hangNum);
                    }
                    else if (rotateNum == 2)
                    {
                        if (curLie == lieNum - 2)
                        {
                            CollisionFromRight(new Vector3(75f, 15f, 0f), mIndex + hangNum);
                        }
                        else
                        {
                            CollisionFromRight(new Vector3(90f, 15f, 0f), mIndex + hangNum);
                        }
                        CollisionFromDown(new Vector3(0f, -75f, 0f), mIndex - 1);
                        CollisionFromLeft(new Vector3(-90f, 15f, 0f), mIndex - hangNum);
                    }
                    else if (rotateNum == 3)
                    {
                        if (curLie == lieNum - 2)
                        {
                            CollisionFromRight(new Vector3(-15f, 75f, 0f), mIndex + hangNum);
                        }
                        else
                        {
                            CollisionFromRight(new Vector3(-15f, 90f, 0f), mIndex + hangNum);
                        }
                        CollisionFromDown(new Vector3(75f, 0f, 0f), mIndex - 1);
                        CollisionFromLeft(new Vector3(-15f, -90f, 0f), mIndex - hangNum);
                    }
                    break;
                case 8:
                    if (rotateNum == 0)
                    {
                        CollisionFromLeft(new Vector3(90f,0f,0f),mIndex-hangNum);
                        CollisionFromUp(new Vector3(15f,-90f,0f),mIndex+1);
                        CollisionFromDown(new Vector3(15f,90f,0f),mIndex-1);
                    }
                    else if (rotateNum == 1)
                    {
                        CollisionFromDown(new Vector3(-90f,15f,0f),mIndex-1);
                        CollisionFromUp(new Vector3(90f,15f,0f),mIndex+1);
                        CollisionFromLeft(new Vector3(0f,90f,0f),mIndex-hangNum);
                    }
                    else if (rotateNum == 2)
                    {
                        CollisionFromDown(new Vector3(-15f, -90f, 0f), mIndex - 1);
                        CollisionFromUp(new Vector3(-15f, 90f, 0f), mIndex + 1);
                        CollisionFromLeft(new Vector3(-90f, 0f, 0f), mIndex - hangNum);
                    }
                    else if (rotateNum == 3)
                    {
                        CollisionFromDown(new Vector3(90f, -15f, 0f), mIndex - 1);
                        CollisionFromUp(new Vector3(-90f, -15f, 0f), mIndex + 1);
                        CollisionFromLeft(new Vector3(0f, -90f, 0f), mIndex - hangNum);
                    }
                    break;
                case 9:
                    if (rotateNum == 0)
                    {
                        CollisionFromLeft(new Vector3(90f,-15f,0f),mIndex-hangNum);
                        CollisionFromRight(new Vector3(-90f,-15f,0f),mIndex+hangNum);
                        CollisionFromUp(new Vector3(0f,-90f,0f),mIndex+1);
                    }
                    else if (rotateNum == 1)
                    {
                        CollisionFromRight(new Vector3(15f,-90f,0f),mIndex+hangNum);
                        CollisionFromLeft(new Vector3(15f,90f,0f),mIndex-hangNum);
                        CollisionFromUp(new Vector3(90f,0f,0f),mIndex+1);
                    }
                    else if (rotateNum == 2)
                    {
                        CollisionFromRight(new Vector3(90f, 15f, 0f), mIndex + hangNum);
                        CollisionFromLeft(new Vector3(-90f, 15f, 0f), mIndex - hangNum);
                        CollisionFromUp(new Vector3(0f, 90f, 0f), mIndex + 1);
                    }
                    else if (rotateNum == 3)
                    {
                        CollisionFromRight(new Vector3(-15f, 90f, 0f), mIndex + hangNum);
                        CollisionFromLeft(new Vector3(-15f, -90f, 0f), mIndex - hangNum);
                        CollisionFromUp(new Vector3(-90f, 0f, 0f), mIndex + 1);
                    }
                    break;
                case 10:
                    if (rotateNum == 0)
                    {
                        CollisionFromLeft(new Vector3(90f,15f,0f),mIndex-hangNum);
                        CollisionFromRight(new Vector3(-90f,15f,0f),mIndex+hangNum);
                        CollisionFromDown(new Vector3(0f,90f,0f),mIndex-1);
                    }
                    else if (rotateNum == 1)
                    {
                        CollisionFromRight(new Vector3(-15f,-90f,0f),mIndex+hangNum);
                        CollisionFromLeft(new Vector3(-15f,90f,0f),mIndex-hangNum);
                        CollisionFromDown(new Vector3(-90f,0f,0f),mIndex-1);
                    }
                    else if (rotateNum == 2)
                    {
                        CollisionFromLeft(new Vector3(-90f, -15f, 0f), mIndex - hangNum);
                        CollisionFromRight(new Vector3(90f, -15f, 0f), mIndex + hangNum);
                        CollisionFromDown(new Vector3(0f, -90f, 0f), mIndex - 1);
                    }
                    else if (rotateNum == 3)
                    {
                        CollisionFromLeft(new Vector3(15f, -90f, 0f), mIndex - hangNum);
                        CollisionFromRight(new Vector3(15f, 90f, 0f), mIndex + hangNum);
                        CollisionFromDown(new Vector3(90f, 0f, 0f), mIndex - 1);
                    }
                    break;
                case 11:
                    if (rotateNum == 0)
                    {
                        if (curLie == 1)
                        {
                            CollisionFromLeft(new Vector3(75f, 0f, 0f), mIndex - hangNum);
                            CollisionFromRight(new Vector3(-90f, 0f, 0f), mIndex + hangNum);
                        }
                        else if (curLie == lieNum - 2)
                        {
                            CollisionFromRight(new Vector3(-75f, 0f, 0f), mIndex + hangNum);
                            CollisionFromLeft(new Vector3(90f, 0f, 0f), mIndex - hangNum);
                        }
                        else
                        {
                            CollisionFromRight(new Vector3(-90f, 0f, 0f), mIndex + hangNum);
                            CollisionFromLeft(new Vector3(90f, 0f, 0f), mIndex - hangNum);
                        }
                        CollisionFromUp(new Vector3(0f,-90f,0f),mIndex+1);
                        CollisionFromDown(new Vector3(0f,90f,0f),mIndex-1);
                    }
                    else if (rotateNum == 1)
                    {
                        if (curLie == 1)
                        {
                            CollisionFromRight(new Vector3(0f, -90f, 0f), mIndex + hangNum);
                            CollisionFromLeft(new Vector3(0f, 75f, 0f), mIndex - hangNum);
                        }
                        else if (curLie == lieNum - 2)
                        {
                            CollisionFromRight(new Vector3(0f, -75f, 0f), mIndex + hangNum);
                            CollisionFromLeft(new Vector3(0f, 90f, 0f), mIndex - hangNum);
                        }
                        else
                        {
                            CollisionFromRight(new Vector3(0f, -90f, 0f), mIndex + hangNum);
                            CollisionFromLeft(new Vector3(0f,90f, 0f), mIndex - hangNum);
                        }
                        CollisionFromUp(new Vector3(90f,0f,0f),mIndex+1);
                        CollisionFromDown(new Vector3(-90f,0f,0f),mIndex-1);
                    }
                    else if (rotateNum == 2)
                    {
                        if (curLie == 1)
                        {
                            CollisionFromRight(new Vector3(90f, 0f, 0f), mIndex + hangNum);
                            CollisionFromLeft(new Vector3(-90f, 0f, 0f), mIndex - hangNum);
                        }
                        else if (curLie == lieNum - 2)
                        {
                            CollisionFromRight(new Vector3(75f, 0f, 0f), mIndex + hangNum);
                            CollisionFromLeft(new Vector3(-90f, 0f, 0f), mIndex - hangNum);
                        }
                        else
                        {
                            CollisionFromRight(new Vector3(90f, 0f, 0f), mIndex + hangNum);
                            CollisionFromLeft(new Vector3(-90f, 0f, 0f), mIndex - hangNum);
                        }
                        CollisionFromUp(new Vector3(0f, 90f, 0f), mIndex + 1);
                        CollisionFromDown(new Vector3(0f, -90f, 0f), mIndex - 1);
                    }
                    else if (rotateNum == 3)
                    {
                        if (curLie == 1)
                        {
                            CollisionFromRight(new Vector3(0f, 90f, 0f), mIndex + hangNum);
                            CollisionFromLeft(new Vector3(0f, -75f, 0f), mIndex - hangNum);
                        }
                        else if (curLie == lieNum - 2)
                        {
                            CollisionFromRight(new Vector3(0f, 75f, 0f), mIndex + hangNum);
                            CollisionFromLeft(new Vector3(0f, -90f, 0f), mIndex - hangNum);
                        }
                        else
                        {
                            CollisionFromRight(new Vector3(0f, 90f, 0f), mIndex + hangNum);
                            CollisionFromLeft(new Vector3(0f, -90f, 0f), mIndex - hangNum);
                        }
                        CollisionFromUp(new Vector3(-90f, 0f, 0f), mIndex + 1);
                        CollisionFromDown(new Vector3(90f, 0f, 0f), mIndex - 1);
                    }
                    break;
                case 12:
                    if (rotateNum == 0)
                    {
                        if (curHang == 1)
                        {
                            CollisionFromUp(new Vector3(0f,-90f,0f),mIndex+1);
                            CollisionFromDown(new Vector3(0f,75f,0f),mIndex-1);
                        }
                        else if (curHang == hangNum - 2)
                        {
                            CollisionFromUp(new Vector3(0f,-75f,0f),mIndex+1);
                            CollisionFromDown(new Vector3(0f,90f,0f),mIndex-1);
                        }
                        else
                        {
                            CollisionFromUp(new Vector3(0f, -90f, 0f), mIndex + 1);
                            CollisionFromDown(new Vector3(0f, 90f, 0f), mIndex - 1);
                        }
                        CollisionFromLeft(new Vector3(90f,0f,0f),mIndex-hangNum);
                        CollisionFromRight(new Vector3(-90f,0f,0f),mIndex+hangNum);
                    }
                    else if (rotateNum == 1)
                    {
                        if (curHang == 1)
                        {
                            CollisionFromUp(new Vector3(90f, 0f, 0f), mIndex + 1);
                            CollisionFromDown(new Vector3(-75f, 0f, 0f), mIndex - 1);
                        }
                        else if (curHang == hangNum - 2)
                        {
                            CollisionFromUp(new Vector3(75f, 0f, 0f), mIndex + 1);
                            CollisionFromDown(new Vector3(-90f, 0f, 0f), mIndex - 1);
                        }
                        else
                        {
                            CollisionFromUp(new Vector3(90f, 0f, 0f), mIndex + 1);
                            CollisionFromDown(new Vector3(-90f, 0f, 0f), mIndex - 1);
                        }
                        CollisionFromRight(new Vector3(0f,-90f,0f),mIndex+hangNum);
                        CollisionFromLeft(new Vector3(0f,90f,0f),mIndex-hangNum);
                    }
                    else if (rotateNum == 2)
                    {
                        if (curHang == 1)
                        {
                            CollisionFromUp(new Vector3(0f, 90f, 0f), mIndex + 1);
                            CollisionFromDown(new Vector3(0f, -75f, 0f), mIndex - 1);
                        }
                        else if (curHang == hangNum - 2)
                        {
                            CollisionFromUp(new Vector3(0f, 75f, 0f), mIndex + 1);
                            CollisionFromDown(new Vector3(0f, -90f, 0f), mIndex - 1);
                        }
                        else
                        {
                            CollisionFromUp(new Vector3(0f, 90f, 0f), mIndex + 1);
                            CollisionFromDown(new Vector3(0f, -90f, 0f), mIndex - 1);
                        }
                        CollisionFromRight(new Vector3(90f, 0f, 0f), mIndex + hangNum);
                        CollisionFromLeft(new Vector3(-90f,0f, 0f), mIndex - hangNum);
                    }
                    else if (rotateNum == 3)
                    {
                        if (curHang == 1)
                        {
                            CollisionFromUp(new Vector3(-90f, 0f, 0f), mIndex + 1);
                            CollisionFromDown(new Vector3(75f, 0f, 0f), mIndex - 1);
                        }
                        else if (curHang == hangNum - 2)
                        {
                            CollisionFromUp(new Vector3(-75f, 0f, 0f), mIndex + 1);
                            CollisionFromDown(new Vector3(90f, 0f, 0f), mIndex - 1);
                        }
                        else
                        {
                            CollisionFromUp(new Vector3(-90f, 0f, 0f), mIndex + 1);
                            CollisionFromDown(new Vector3(90f, 0f, 0f), mIndex - 1);
                        }
                        CollisionFromRight(new Vector3(0f, 90f, 0f), mIndex + hangNum);
                        CollisionFromLeft(new Vector3(0f, -90f, 0f), mIndex - hangNum);
                    }
                    break;
                case 13:
                    if (rotateNum == 0)
                    {
                        if (curHang == 1)
                        {
                            CollisionFromDown(new Vector3(-15f,75f,0f),mIndex-1);
                        }
                        else
                        {
                            CollisionFromDown(new Vector3(-15f, 90f, 0f), mIndex - 1);
                        }
                        CollisionFromUp(new Vector3(-15f, -90f, 0f), mIndex + 1);
                        CollisionFromLeft(new Vector3(75f,0f,0f),mIndex-hangNum);
                    }
                    else if (rotateNum == 1)
                    {
                        if (curHang == 1)
                        {
                            CollisionFromDown(new Vector3(-75f, -15f, 0f), mIndex - 1);
                        }
                        else
                        {
                            CollisionFromDown(new Vector3(-90f, -15f, 0f), mIndex - 1);
                        }
                        CollisionFromUp(new Vector3(90f,-15f,0f),mIndex+1);
                        CollisionFromLeft(new Vector3(0f,75f,0f),mIndex-hangNum);
                    }
                    else if (rotateNum == 2)
                    {
                        if (curHang == 1)
                        {
                            CollisionFromDown(new Vector3(15f, -75f, 0f), mIndex - 1);
                        }
                        else
                        {
                            CollisionFromDown(new Vector3(15f, -90f, 0f), mIndex - 1);
                        }
                        CollisionFromUp(new Vector3(15f, 90f, 0f), mIndex + 1);
                        CollisionFromLeft(new Vector3(-75f, 0f, 0f), mIndex - hangNum);
                    }
                    else if (rotateNum == 3)
                    {
                        if (curHang == 1)
                        {
                            CollisionFromDown(new Vector3(75f, 15f, 0f), mIndex - 1);
                        }
                        else
                        {
                            CollisionFromDown(new Vector3(90f, 15f, 0f), mIndex - 1);
                        }
                        CollisionFromUp(new Vector3(-90f, 15f, 0f), mIndex + 1);
                        CollisionFromLeft(new Vector3(0f, -75f, 0f), mIndex - hangNum);
                    }
                    break;
                default:
                    Debug.Log("maskNum is err");
                    break;
            }
        }
    }
    
    
    

    4.游戏管理GameManager类

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class GameManager : Singleton<GameManager>
    {
        //lieNum=m,hangNum=n
    
        public int hangNum = 4;
        public int lieNum = 6;
        public bool isWin = false;
        public Dictionary<string, GameObject> jpParentDic;
        public int SideLength;
        public void InIt()
        {
            jpParentDic = new Dictionary<string, GameObject>();
        }
    }
    
    

    5.扩展功能GamingUI类

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.UI;
    
    public class GamingUI : UIBase
    {
        private Button help;
        private Button shadow;
        private Button showFrame;
        private Button showAll;
        private Button pingpu;
        private Text showTime;
        private GameObject shadowPic;
        private List<GameObject> jpList = new List<GameObject>();
        //计时器部分
        private int second = 0;
        private int minute = 0;
        private int hour = 0;
        private string s;
        private string m;
        private string h;
        private float time;
        private GameObject uibg;
    
        // Use this for initialization
        void Start()
        {
            InIt();
        }
    
        // Update is called once per frame
        void Update()
        {
            Timer();
            IsWin();
        }
        private void InIt()
        {
            showTime = GameObject.Find("time").GetComponent<Text>();
            shadowPic = GameObject.Instantiate<GameObject>(Resources.Load<GameObject>("Prefabs/Textures/shadowImage"));
            shadowPic.transform.SetParent(GameObject.Find("UIRoot").transform);
            shadowPic.transform.localPosition = new Vector3(40, 0, 0);
            shadowPic.transform.SetAsFirstSibling();
            uibg = GameObject.Find("UIbg");
            uibg.transform.SetAsFirstSibling();
            shadowPic.GetComponent<RectTransform>().sizeDelta = new Vector2(30 * GameManager.Instance.lieNum * 3,
                30 * GameManager.Instance.hangNum * 3);
            shadowPic.SetActive(false);
            help = GameObject.Find("help").GetComponent<Button>();
            shadow = GameObject.Find("shadow").GetComponent<Button>();
            showFrame = GameObject.Find("showFrame").GetComponent<Button>();
            showAll = GameObject.Find("showAll").GetComponent<Button>();
            showAll.gameObject.SetActive(false);
            pingpu = GameObject.Find("pingpu").GetComponent<Button>();
            help.onClick.AddListener(OnHelpClicked);
            shadow.onClick.AddListener(OnShadowClicked);
            showFrame.onClick.AddListener(OnShowFrameClicked);
            showAll.onClick.AddListener(OnShowAllClicked);
            pingpu.onClick.AddListener(OnPingpuClicked);
            for (int i = 0; i < GameManager.Instance.hangNum * GameManager.Instance.lieNum; i++)
            {
                jpList.Add(GameObject.Find("JP-" + i));
            }
        }
        private void OnHelpClicked()
        {
            Debug.Log("没得帮助,这就一凑数的");
        }
        //显示影子图
        private void OnShadowClicked()
        {
            if (shadowPic.activeSelf == false)
            {
                shadowPic.SetActive(true);
            }
            else
            {
                shadowPic.SetActive(false);
            }
        }
        //只显示边框的拼图,隐藏内部
        private void OnShowFrameClicked()
        {
            showAll.gameObject.SetActive(true);
            showFrame.gameObject.SetActive(false);
    
            for (int i = 0; i < jpList.Count; i++)
            {
                string[] names = jpList[i].transform.name.Split('-');
                int jpIndex = int.Parse(names[1]);
                if (jpIndex % GameManager.Instance.hangNum != 0 && jpIndex % GameManager.Instance.hangNum != GameManager.Instance.hangNum - 1
                    && jpIndex > GameManager.Instance.hangNum && jpIndex < GameManager.Instance.hangNum * (GameManager.Instance.lieNum - 1))
                {
                    jpList[jpIndex].SetActive(false);
                }
            }
        }
        //全部显示
        private void OnShowAllClicked()
        {
            showAll.gameObject.SetActive(false);
            showFrame.gameObject.SetActive(true);
            foreach (GameObject go in jpList)
            {
                if (go.activeSelf == false)
                {
                    go.SetActive(true);
                }
            }
        }
        //平铺拼图,每个的位置随机
        private void OnPingpuClicked()
        {
            int posX = -200;
            int posY = 500;
            List<int> indexList = new List<int>();
            for (int i = 0; i < jpList.Count; i++)
            {
                indexList.Add(i);
            }
            for (int i = 0; i < jpList.Count; i++)
            {
                int index = Random.Range(0, indexList.Count);
                jpList[indexList[index]].transform.localPosition = new Vector3(posX, posY, 0);
                indexList.RemoveAt(index);
                posX += 110;
                if ((i + 1) % GameManager.Instance.lieNum == 0 && i != 0)
                {
                    posY -= 130;
                    posX = -210;
                }
            }
    
        }
        //计时器
        private void Timer()
        {
            time += Time.deltaTime;
            if (time >= 1)
            {
                second++;
                time -= 1;
            }
            if (second == 60)
            {
                minute++;
                second = 0;
            }
            if (minute == 60)
            {
                hour++;
                minute = 0;
            }
            if (second < 10)
            {
                s = "0" + second;
            }
            else
            {
                s = "" + second;
            }
            if (minute < 10)
            {
                m = "0" + minute;
            }
            else
            {
                m = "" + minute;
            }
            if (hour < 10)
            {
                h = "0" + hour;
            }
            else
            {
                h = "" + hour;
            }
            showTime.text = h + ":" + m + ":" + s;
        }
        //结束判定
        private void IsWin()
        {
            if (GameManager.Instance.isWin == true)
            {
                UIManager.Instance.Close("GamingUI");
                shadowPic.SetActive(true);
                shadowPic.GetComponent<Image>().color = new Color(1.0f, 1.0f, 1.0f, 1.0f);
                for (int i = 0; i < jpList.Count; i++)
                {
                    Destroy(jpList[i]);
                }
                Debug.Log("拼图完成");
            }
        }
    }
    
    

    四、工程包

    1.0 https://download.csdn.net/download/weixin_44927626/11223891
    2019.6.20更新
    2.0 https://download.csdn.net/download/weixin_44927626/11250296
    第一版的工程包已经改为私密,现在放出第二版的工程压缩包下载,屏幕设为1920×1080即可,基本应该是最后一次更新了,因为,我考核过关了~哈哈哈哈
    捧场的可以投币下一下,主体代码基本都在上面了,不下问题也不大。

    展开全文
  • 今天给大家分享一个小游戏,应公司需求今天花了点时间做了个华容道拼图小游戏,请大家多少指点,直接上代码 using UnityEngine; using DG.Tweening; using UnityEngine.UI; using System.Collections....
  • 算法老师给了一份关于九宫拼图的算法过程用C++写的,让我们自己封装,成为一个有图形界面的工程,我接触过android,c++的mfc,Java的图形界面JUI,网页的css、html、javascript,Unity3D;但感觉最熟悉的还是利用...
  • PintuGame2.0.zip

    2020-07-18 23:32:32
    目前做了一款拼图小游戏,不规则的图形,自由拖拽,网上其他拼图大部分都是基于九宫格的类似华容道拼图模式,我做的时候没有找到我这种类型的相关的项目代码(有一付费下载,然后发现是用3d实现碰撞,然后正交相机来...
  • 下载地址 最后更新共计113个分类5177套源码...│ ├─3D标签云卡片热门 │ │ Android TagCloudView云标签的灵活运用.rar │ │ Android 实现 标签 拖动 改变位置.rar │ │ android 流式布局和热门标签.zip │ │ ...
  • 从工作了近四年的公司离职了,这四年主要做广告平台SDK开发,也做过不短时间的应用开发,帮公司维护过Unity3D开发的游戏,也维护过Cocos2d-x开发的游戏。自学过Unity3D、Cocos2d-x、SpriteKit游戏引擎并发布过多款...
  • 下载 2019.06.13更新 21.0 GB共4,071 个文件,27 个文件夹。(解压后的) 文件夹 PATH 列表 卷序列号为 0FEA-0BC6 E:. │ 003树结构文件列表生成.bat │ 目录列表_树2019.06.13更新.txt ...├─【01】精选:应用源码 ...
  • 一年又一年,时间过得很快,2016年结束了。过去的一年中最大的事,莫过于12月份的离职,从工作了将近四年的广告平台离职了。  2016年工作方面主要是两方面。一方面是畅思自己的广告平台,主要是将原普通广告SDK与...
  • 目录视图 摘要视图 订阅 赠书 | 异步2周年,技术图书免费选程序员8月书讯项目管理+代码托管+文档协作,开发更流畅 [置顶]android项目大全,总有你所需的 ...2014-04-29 09:012591...
1
收藏数 14
精华内容 5
关键字:

unity3d 九宫格拼图