private void _updateView() { BattleHeroModel model = _model; HeroModel heroModel = model.getHeroModel(); Image head = UITools.createBallImg(model); if (head == null) { string img = heroModel.getBodyImg(); Sprite bodySprite = Resources.Load <Sprite> (img); bodyImg.sprite = bodySprite; } else { bodyImg.gameObject.SetActive(false); bodyImg = head; bodyImg.transform.SetParent(bodyImgContainer.transform); } hpSlider.maxValue = heroModel.getHp(); hpSlider.value = _model.getHp(); }
public static Image createBallImg(BattleHeroModel model) { int configId = model.getHeroModel().getConfigId(); Object ballObject = Resources.Load <Image> (DEFAULT_BATTLE_BALL + configId); if (ballObject == null) { return(null); } Image ball = MonoBehaviour.Instantiate(ballObject) as Image; return(ball); }
public static Image createActionHead(BattleHeroModel model) { HeroModel hModel = model.getHeroModel(); int configId = hModel.getConfigId(); Object obj = Resources.Load <Image> (DEFAULT_ACTION_HEAD_BG + configId); if (obj == null) { return(null); } Image head = MonoBehaviour.Instantiate(obj) as Image; return(head); }
// void OnDestroy(){ // _bhModel.HP_REDUCED -= _updateHp; // } public void setHeroModel(BattleHeroModel model) { model.HP_REDUCED += _updateHp; model.HERO_DIED += _onDied; _bhModel = model; mpBar.gameObject.SetActive(false); HeroModel heroModel = model.getHeroModel(); hpBar.setMaxValue(heroModel.getHp()); string img = heroModel.getBodyImg(); Sprite bodySprite = Resources.Load <Sprite> (img); headImg.sprite = bodySprite; _updateView(); }
private void _updateView() { BattleHeroModel model = _model; Image head = UITools.createActionHead(model); if (head == null) { string img = model.getHeroModel().getBodyImg(); Sprite bodySprite = Resources.Load <Sprite> (img); headImg.sprite = bodySprite; } else { headImg.gameObject.SetActive(false); headImg = head; headImg.transform.SetParent(headContainer.transform); headImg.transform.localEulerAngles = new Vector3(0, 0, 0); } }