private void transferCoin(Transaction trans) { CoinBankAccount sendAcct = getAccount(trans.sendAccount); CoinBankAccount receiveAcct = getAccount(trans.receiveAccount); Vector3 sendVector = (trans.sendAccount == CUSTOM ? trans.custom : sendAcct.getVector()); Vector3 receiveVector = (trans.receiveAccount == CUSTOM ? trans.custom : receiveAcct.getVector()); // Only actually remove coin from transfer account if this is a transfer, otherwise just gain coin at main account if (sendAcct != null) { aq.Add(() => { sendAcct.value -= 1; updateText(sendAcct); }); } aq.Instantiate(coinPrefab, sendVector); // will select object aq.Add(() => { aq.Pause(); StartCoroutine(aq.selectedGameObject.transform.LerpPosition(receiveVector, animDuration, null, (tf) => aq.Resume())); }); // aq.Log("Coin from " + sendAcct.name + " arrived at " + receiveAcct.name); if (receiveAcct != null) { aq.Add(() => { receiveAcct.value += 1; updateText(receiveAcct); }); } aq.Destroy(); }
public void updateText(CoinBankAccount acct) { if (acct.text == null) { return; } acct.text.text = acct.value.ToString(); }
public CoinBankAccount getAccount(string accountName) { if (accountName == CUSTOM) { return(null); } CoinBankAccount acct = accounts.Find((a) => a.name == accountName); if (acct == null) { throw new UnityException("Cannot find " + accountName); } return(acct); }
public void onTransaction(Transaction trans) { switch (trans.type) { case TransactionType.Transfer: transferCoins(trans); break; case TransactionType.Update: CoinBankAccount account = getAccount(trans.receiveAccount); account.value = trans.amount; updateText(account); break; } }