using System; using System.Collections.Generic; using UnityEngine; using OHM.UnityToolkit.Vibration; public class VisualPlayerRichPoor : CoreBehaviour { public List listTypeItem; public PlayerGauge playerGauge; private TypeRich _lastTypeRich; private int _lastChange; private RichLevelObject[] _levelObjects; public event Action onChangeStatus; public event Action onChangeCloth; private RichLevelObject[] LevelsObjets { get { if (_levelObjects == null) { _levelObjects = GetComponentsInChildren(true); } return _levelObjects; } } public void ForceGaugeValue(int v) { playerGauge.UpdateGauge(v, force: true); } public void UpdateRichPoorValue(int v, bool init, bool isForce = false) { ChangeStatus(v, init); if (init) { _lastChange = v; } TypeRich typeRich = base.CoreDef.GetTextRich(v); RichLevelObject[] levelsObjets = LevelsObjets; for (int i = 0; i < levelsObjets.Length; i++) { RichLevelObject o = levelsObjets[i]; o.gameObject.SetActive(typeRich.text == o.level); } } private void ChangeStatus(int v, bool force = false) { playerGauge.UpdateGauge(v, force); TypeRich typeRich = base.CoreDef.GetTextRich(v); if (force) { playerGauge.ChangeStatus(typeRich.locKey, typeRich.color); _lastTypeRich = typeRich; return; } if (typeRich == _lastTypeRich) { return; } if (this.onChangeCloth != null) { this.onChangeCloth(_lastChange <= v); } _lastChange = v; playerGauge.ChangeStatus(typeRich.locKey, typeRich.color); _lastTypeRich = typeRich; VibrationManager.Vibrate(VibrationManager.VibrationType.MEDIUM); if (this.onChangeStatus != null) { this.onChangeStatus(typeRich, typeRich.color); } } private void SetItem(ItemOnPlayerElement item, bool active, bool force) { item.isActive = active; if (item.skinnedMeshRenderer != null && active) { item.skinnedMeshRenderer.sharedMesh = item.mesh; } else if (item.element != null) { item.element.SetActive(active); } if (item.fxToPlay != null && active) { item.fxToPlay.PlayInstance(null, null); } } }