Beispiel #1
0
    /// <summary>
    /// 方块落地触发效果
    /// </summary>
    public void BlockLand()
    {
        //关闭协程
        StopAllCoroutines();
        //关闭方块组的控制组件
        this.GetComponent <BlockGroupControl>().enabled = false;

        //将子物体移到堆积方块框架下
        Transform newParent = myGridManager.transform;

        foreach (var son in transform.GetComponentsInChildren <MeshFilter>())
        {
            //将方块对应位置的索引值置为1
            Vector2 index = MyGridManager.TransformConvertToIndex(son.transform);
            int     x     = (int)index.x;
            int     y     = (int)index.y;
            try {
                myGridManager.myGrid[x, y] = 1;
                myGridManager.gridBlocks[y].Add(son.transform);
                son.transform.SetParent(newParent, true);
            } catch (Exception e) {
                print(e);
            }
        }
        Destroy(this.gameObject);
    }
Beispiel #2
0
 /// <summary>
 /// 检测方块组所在的位置是否已有方块
 /// </summary>
 /// <param name="parent"></param>
 /// <returns></returns>
 public bool NextHasBlock(Transform parent)
 {
     foreach (var son in parent.GetComponentsInChildren <Transform>(true))
     {
         if (son == parent)
         {
             continue;
         }
         Vector2 index = MyGridManager.TransformConvertToIndex(son);
         try {
             if (myGrid[(int)index.x, (int)index.y] == 1)    // 位置被占用
             {
                 return(true);
             }
         }
         catch (System.Exception e) {
             print(e);
         }
     }
     return(false);
 }
 // Use this for initialization
 void Update()
 {
     ui.text = "" + MyGridManager.TransformConvertToIndex(transform.parent);
 }