コード例 #1
0
 // examines top block from towerFrom parameter and transfers it to this tower's stack if move is valid
 public void AttemptBlockTransferFrom(Transform towerFrom)
 {
     if (towerFrom)
     {
         if (towerFrom != this.transform)
         {
             TowerStack towerStackFrom = towerFrom.GetComponent <TowerStack> ();
             Transform  topBlock       = towerStackFrom.GetTopBlock();
             if (topBlock)
             {
                 if (this.CanSupportNewTopBlock(topBlock))
                 {
                     // block transfer is valid; commence transfer procedure
                     topBlock = towerStackFrom.PopTopBlock();
                     this.PushTopBlock(topBlock);
                 }
                 else
                 {
                     towerFrom.GetComponent <EventBus> ().EmitTopBlockKeepEvent(towerFrom);
                     this.eventBus.EmitTopBlockMissEvent(this.transform);
                 }
             }
         }
         else
         {
             towerFrom.GetComponent <EventBus> ().EmitTopBlockKeepEvent(towerFrom);
         }
     }
 }
コード例 #2
0
    // show shadow of where block came from on fromTower
    void ShowFromShadow(Transform fromTower)
    {
        // find toTower slot and place toShadow block inside it
        TowerStack fromTowerStack = fromTower.GetComponent <TowerStack> ();
        Transform  fromBlock      = fromTowerStack.GetTopBlock();

        if (fromBlock)
        {
            Transform fromSlot = fromTowerStack.GetTopBlockSlot();
            if (fromSlot)
            {
                this.fromShadow.transform.SetParent(fromSlot);
                this.fromShadow.SetActive(true);
            }

            // Adjust shadow's size and color
            Block fromShadowData = this.fromShadow.GetComponent <Block> ();
            fromShadowData.ResetPosition();
            fromShadowData.SetColor(new Color(0f, 0f, 0f, 0.6f));   //black shadow
            int blockNum = fromBlock.GetComponent <Block> ().blockNum;
            fromShadowData.SetBlockNum(blockNum);
        }
    }