public void Z_UpdateAllStats(C_GameUnit.EmptyClass curStats) { Z_UpdateUnitBars(curStats); if ( curStats.GetType() == typeof(C_Hero.CurrentStats) ) { C_Hero.CurrentStats stats = (C_Hero.CurrentStats) curStats; Z_UpdateEnergy(stats.energy); // update only for this player if (!_gmClass) _gmClass = GameObject.Find("Game Manager").GetComponent<C_GameManager>(); if (_gmClass.z_thisPlayerGO != _gameObject) return; _show_attackText.text = "Attack: " + stats.attackPower; _show_rangeText.text = "Range: " + stats.attackRange; _show_defenseText.text = "Defense: " + stats.defensePercent + "%"; _show_movementText.text = "Movement: " + stats.movementSpeed; Z_UpdateMainBars(stats); } }
public void Z_UpdateUnitBars(C_GameUnit.EmptyClass curStats) { if (!_hpUnitTex) { _hpUnitTex = GameObject.Find(name + " Overhead/HP Bar").GetComponent<GUITexture>(); m_unitBarSize = GameObject.Find(name + " Overhead/Background").GetComponent<GUITexture>().pixelInset.width; } if (!_mpUnitTex) { GameObject hasMP = GameObject.Find(name + " Overhead/MP Bar"); if (hasMP) _mpUnitTex = hasMP.GetComponent<GUITexture>(); } float hp, maxhp, mp, maxmp; hp = maxhp = maxmp = mp = 1f; if ( curStats.GetType() == typeof(C_Hero.CurrentStats) ) { hp = ((C_Hero.CurrentStats) curStats).HP; maxhp = ((C_Hero.CurrentStats) curStats).maxHP; mp = ((C_Hero.CurrentStats) curStats).MP; maxmp = ((C_Hero.CurrentStats) curStats).maxMP; } if ( curStats.GetType() == typeof(C_Tower.CurrentStats) ) { hp = ((C_Tower.CurrentStats) curStats).HP; maxhp = ((C_Tower.CurrentStats) curStats).maxHP; } int barSize = Mathf.FloorToInt( m_unitBarSize * (hp / maxhp) ); Rect pix = _hpUnitTex.pixelInset; _hpUnitTex.pixelInset = new Rect(pix.x, pix.y, barSize, pix.height); if (_mpUnitTex) { barSize = Mathf.FloorToInt( m_unitBarSize * (mp / maxmp) ); pix = _mpUnitTex.pixelInset; _mpUnitTex.pixelInset = new Rect(pix.x, pix.y, barSize, pix.height); } }