Esempio n. 1
0
    /// <summary>
    /// 交换两个块
    /// </summary>
    /// <param 块1="item1"></param>
    /// <param 块2="item2"></param>
    void SwapTwoBlock(BlockObject block1, BlockObject block2)
    {
        ColumnScript firstColumn  = block1.GetComponent <BlockObject>().myColumnScript;
        ColumnScript secondColumn = block2.GetComponent <BlockObject>().myColumnScript;

        block1.transform.parent = block2.transform.parent;
        block2.transform.parent = firstColumn.transform;

        block1.myColumnScript = secondColumn;
        block2.myColumnScript = firstColumn;

        firstColumn.BlockObjectsScriptList.RemoveAt(block1.GetComponent <BlockObject>().ColumnNumber);
        firstColumn.BlockObjectsScriptList.Insert(block1.GetComponent <BlockObject>().ColumnNumber, block2.GetComponent <BlockObject>());

        secondColumn.BlockObjectsScriptList.RemoveAt(block2.GetComponent <BlockObject>().ColumnNumber);
        secondColumn.BlockObjectsScriptList.Insert(block2.GetComponent <BlockObject>().ColumnNumber, block1.GetComponent <BlockObject>());

        int tempIndex = block1.ColumnNumber;

        block1.ColumnNumber = block2.ColumnNumber;
        block2.ColumnNumber = tempIndex;
        //交换完就重新分配邻居
        GameManager.Instance.AssignNeighbours(0f);
    }
Esempio n. 2
0
    void UseBlock(int iIndex)
    {
        GameObject BlockObject;

        if (BlockModels_[iIndex] == null)
        {
            BlockObject = GameObject.Instantiate(BlockModel) as GameObject;

            BlockObject.transform.SetParent(this.transform);
            int iX = 0, iY = 0, iZ = 0;
            GetCoordsOut(iIndex, out iX, out iY, out iZ);
            BlockObject.transform.localPosition = GetPositionFromCoords(iX, iY, iZ);
            var blockColor = new Color(iX / (float)iXMax_, iY / (float)iYMax_, iZ / (float)iZMax_);
            materialPropBlock.SetColor("_Color", blockColor);
            BlockObject.GetComponent <MeshRenderer>().SetPropertyBlock(materialPropBlock);
            BlockModels_[iIndex] = BlockObject;
        }
        else
        {
            BlockObject = BlockModels_[iIndex];
        }
        BlockObject.GetComponent <Renderer>().enabled = true;


        /*GameObject BlockObject;
         * if (iBlockQueueIndex_ == 1) {
         *      if (UseBlockList2_.Count > 0) {
         *              BlockObject = UseBlockList2_.Dequeue();
         *              UseBlockList1_.Enqueue(BlockObject);
         *      }
         *      else if (UnusedBlockQueue_.Count > 0) {
         *              BlockObject = UnusedBlockQueue_.Dequeue();
         *              UseBlockList1_.Enqueue(BlockObject);
         *      }
         *      else {
         *              BlockObject = GameObject.Instantiate(BlockModel) as GameObject;
         *              UseBlockList1_.Enqueue(BlockObject);
         *      }
         * }
         * else if (iBlockQueueIndex_ == 2) {
         *      if (UseBlockList1_.Count > 0) {
         *              BlockObject = UseBlockList1_.Dequeue();
         *              UseBlockList2_.Enqueue(BlockObject);
         *      }
         *      else if (UnusedBlockQueue_.Count > 0) {
         *              BlockObject = UnusedBlockQueue_.Dequeue();
         *              UseBlockList2_.Enqueue(BlockObject);
         *      }
         *      else {
         *              BlockObject = GameObject.Instantiate(BlockModel) as GameObject;
         *              UseBlockList2_.Enqueue(BlockObject);
         *      }
         * }
         * else  {
         * //			throw System.Exception("Bad");
         *      BlockObject = GameObject.Instantiate(BlockModel) as GameObject;
         *      UnusedBlockQueue_.Enqueue(BlockObject);
         * }
         *
         * BlockObject.renderer.enabled = true;
         * int iX = 0, iY = 0, iZ = 0;
         * GetCoordsOut(iIndex, out iX, out iY, out iZ);
         * BlockObject.transform.position = GetPositionFromCoords(iX, iY, iZ);
         * BlockObject.renderer.material.color = new Color(iX / (float)iXMax_,
         *                                              iY / (float)iYMax_,
         *                                              iZ / (float)iZMax_);*/
    }