public void SellAction(bool isall) { if (haveCount <= 0) { UIMgr.ChangeTips("你都没有卖个锤子呢?"); Debug.LogError("你都没有卖个锤子呢?"); return; } if (curprice <= 0)//0元保护 { UIMgr.ChangeTips("0元禁止出售或购买?"); Debug.LogError("0元禁止出售或购买"); return; } string m_tips = isall ? "全卖了割肉!" : "卖一次"; UIMgr.ChangeTips(m_tips); UIMgr uiMgr = Object.FindObjectOfType <UIMgr>(); int nowsellCount = isall ? haveCount : 1; float nowsellPrice = curprice; haveCount -= nowsellCount; curmoney += nowsellCount * nowsellPrice; uiMgr.m_count.text = haveCount.ToString(); uiMgr.m_money.text = curmoney.ToString("f2"); uiMgr.m_avg.text = haveCount == 0 ? "0" : avgPrice.ToString("f2"); }
public void BuyAction(bool isall) { if (curprice <= 0)//0元保护 { UIMgr.ChangeTips("0元禁止出售或购买?"); Debug.LogError("0元禁止出售或购买"); return; } UIMgr uiMgr = Object.FindObjectOfType <UIMgr>(); int nowbuyCount = isall ? (int)(curmoney / curprice) : 1; float nowbuyPrice = curprice; int oldcount = haveCount; haveCount += nowbuyCount; curmoney -= nowbuyCount * nowbuyPrice; avgPrice = (avgPrice * oldcount + nowbuyCount * nowbuyPrice) / haveCount; uiMgr.m_count.text = haveCount.ToString(); uiMgr.m_money.text = curmoney.ToString("f2"); uiMgr.m_avg.text = avgPrice.ToString("f2"); }