100 lines
2.1 KiB
C#
100 lines
2.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using OHM.UnityToolkit.Vibration;
|
|
|
|
public class VisualPlayerRichPoor : CoreBehaviour
|
|
{
|
|
public List<ListOfTypeElement> listTypeItem;
|
|
|
|
public PlayerGauge playerGauge;
|
|
|
|
private TypeRich _lastTypeRich;
|
|
|
|
private int _lastChange;
|
|
|
|
private RichLevelObject[] _levelObjects;
|
|
|
|
public event Action<TypeRich, Color> onChangeStatus;
|
|
|
|
public event Action<bool> onChangeCloth;
|
|
|
|
private RichLevelObject[] LevelsObjets
|
|
{
|
|
get
|
|
{
|
|
if (_levelObjects == null)
|
|
{
|
|
_levelObjects = GetComponentsInChildren<RichLevelObject>(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);
|
|
}
|
|
}
|
|
}
|